<commit_before>//
//  Created by Nextpeer development team.
//  Copyright (c) 2013 Nextpeer, Inc. All rights reserved.
//

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

#import "Nextpeer_iOSDelegate.h"

#include "NextpeerNotifier.h"
#include "NextpeerPlayer.h"
#include "cocos2d.h"

using namespace nextpeer;

static Nextpeer_iOSDelegate* _nextpeer_ios_delegate_instance = nil;

@interface Nextpeer_iOSDelegate ()
-(TournamentP2PData*)generateP2PStructForChannel:(NextpeerDataChannel)channel andMessage:(NPTournamentCustomMessageBaseContainer*)message;
@end

@implementation Nextpeer_iOSDelegate

+(Nextpeer_iOSDelegate*)sharedInstance
{
    if (!_nextpeer_ios_delegate_instance) {
        _nextpeer_ios_delegate_instance = [[Nextpeer_iOSDelegate alloc] init];
    }
    
    return _nextpeer_ios_delegate_instance;
}

// NextpeerDelegate methods

-(void)nextpeerDidTournamentStartWithDetails:(NPTournamentStartDataContainer *)tournamentContainer
{
    TournamentStartData* startData = new TournamentStartData();
    startData->tournamentUuid = string([tournamentContainer.tournamentUuid UTF8String]);
    startData->tournamentName = string([tournamentContainer.tournamentName UTF8String]);
    startData->tournamentTimeInSeconds = tournamentContainer.tournamentTimeSeconds;
    startData->tournamentRandomSeed = tournamentContainer.tournamentRandomSeed;
    startData->isGameControlled = tournamentContainer.tournamentIsGameControlled;
    startData->numberOfPlayers = tournamentContainer.numberOfPlayers;
    
    // Convert the opponents objects
    CCArray* players = CCArray::createWithCapacity([tournamentContainer.opponents count]);
    for (NPTournamentPlayer* player in tournamentContainer.opponents) {
        string playerName([player.playerName UTF8String]);
        string playerId([player.playerId UTF8String]);
        string playerImageUrl([player.playerImageUrl UTF8String]);
        bool isRecording = player.playerIsBot;
        
        players->addObject(NextpeerPlayer::create(playerName, playerId, playerImageUrl, isRecording));
    }
    
    players->retain();
    startData->players = players;
    
    startData->autorelease();
    NextpeerNotifier::getInstance()->broadcastTournamentStarted(startData);
}

-(void)nextpeerDidTournamentEnd
{
    NextpeerNotifier::getInstance()->broadcastTournamentEnded();
}

-(void)nextpeerDashboardDidAppear
{
    NextpeerNotifier::getInstance()->broadcastDashboardDidAppear();
}

-(void)nextpeerDashboardDidDisappear
{
    NextpeerNotifier::getInstance()->broadcastDashboardDidDisappear();
}

-(void)nextpeerDashboardWillAppear
{
    NextpeerNotifier::getInstance()->broadcastDashboardWillAppear();
}<commit_msg>Added fix for the early callback issue<commit_after>//
//  Created by Nextpeer development team.
//  Copyright (c) 2013 Nextpeer, Inc. All rights reserved.
//

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

#import "Nextpeer_iOSDelegate.h"

#include "NextpeerNotifier.h"
#include "NextpeerPlayer.h"
#include "cocos2d.h"

using namespace nextpeer;

static Nextpeer_iOSDelegate* _nextpeer_ios_delegate_instance = nil;

@interface Nextpeer_iOSDelegate ()
-(TournamentP2PData*)generateP2PStructForChannel:(NextpeerDataChannel)channel andMessage:(NPTournamentCustomMessageBaseContainer*)message;
@end

@implementation Nextpeer_iOSDelegate

+(Nextpeer_iOSDelegate*)sharedInstance
{
    if (!_nextpeer_ios_delegate_instance) {
        _nextpeer_ios_delegate_instance = [[Nextpeer_iOSDelegate alloc] init];
    }
    
    return _nextpeer_ios_delegate_instance;
}

// NextpeerDelegate methods

-(void)nextpeerWillTournamentStartWithDetails:(NPTournamentStartDataContainer *)tournamentContainer
{
    TournamentStartData* startData = new TournamentStartData();
    startData->tournamentUuid = string([tournamentContainer.tournamentUuid UTF8String]);
    startData->tournamentName = string([tournamentContainer.tournamentName UTF8String]);
    startData->tournamentTimeInSeconds = tournamentContainer.tournamentTimeSeconds;
    startData->tournamentRandomSeed = tournamentContainer.tournamentRandomSeed;
    startData->isGameControlled = tournamentContainer.tournamentIsGameControlled;
    startData->numberOfPlayers = tournamentContainer.numberOfPlayers;
    
    // Convert the opponents objects
    CCArray* players = CCArray::createWithCapacity([tournamentContainer.opponents count]);
    for (NPTournamentPlayer* player in tournamentContainer.opponents) {
        string playerName([player.playerName UTF8String]);
        string playerId([player.playerId UTF8String]);
        string playerImageUrl([player.playerImageUrl UTF8String]);
        bool isRecording = player.playerIsBot;
        
        players->addObject(NextpeerPlayer::create(playerName, playerId, playerImageUrl, isRecording));
    }
    
    players->retain();
    startData->players = players;
    
    startData->autorelease();
    NextpeerNotifier::getInstance()->broadcastTournamentStarted(startData);
}

-(void)nextpeerDidTournamentStartWithDetails:(NPTournamentStartDataContainer *)tournamentContainer
{
    // Left empty on purpose -> all logic done in nextpeerWillTournamentStartWithDetails due to a
    // Nextpeer bug that allows P2P packets between the "will" and "did" callbacks.
}

-(void)nextpeerDidTournamentEnd
{
    NextpeerNotifier::getInstance()->broadcastTournamentEnded();
}

-(void)nextpeerDashboardDidAppear
{
    NextpeerNotifier::getInstance()->broadcastDashboardDidAppear();
}

-(void)nextpeerDashboardDidDisappear
{
    NextpeerNotifier::getInstance()->broadcastDashboardDidDisappear();
}

-(void)nextpeerDashboardWillAppear
{
    NextpeerNotifier::getInstance()->broadcastDashboardWillAppear();
}
{'fraction_non_alphanumeric': 0.09575971731448764, 'fraction_numerical': 0.00441696113074205, 'mean_word_length': 5.971674876847291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3945759', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1607, 'n_words': 256}