static void NickErrorCallback ( PEER peer, int type, const gsi_char * badNick, int numSuggestedNicks, const gsi_char ** suggestedNicks, void * param ) { static int errCount; if(errCount < 20) { _tsnprintf(nick,NICK_SIZE,_T("peerc%u"),(unsigned int)current_time()); nick[NICK_SIZE - 1] = '\0'; peerRetryWithNick(peer, nick); } else { //peerDisconnect(peer); peerRetryWithNick(peer, NULL); } errCount++; GSI_UNUSED(type); GSI_UNUSED(badNick); GSI_UNUSED(suggestedNicks); GSI_UNUSED(numSuggestedNicks); GSI_UNUSED(param); }
void AppenderFile::_write(LogMessage& message) { if (dynamicName) { _tchar namebuf[DEF_PATH_MAX]; _tsnprintf(namebuf, DEF_PATH_MAX, filename.c_str()); logfile = OpenFile(namebuf, mode, backup); } if (logfile) { std::string text; std::string prefix; text=message.text; prefix=message.prefix; fprintf(logfile,"%s%s",prefix.c_str(),text.c_str()); fflush(logfile); if (dynamicName) { fclose(logfile); logfile = NULL; } } }
int test_main(int argc, char **argv) { PEER peer; // peer object (initialized with peerInitialize /* peerInitialize */ PEERCallbacks callbacks; // we will need to add all of the supported callbacks /* peerSetTitle parameters */ gsi_char secret_key[9]; // your title's assigned secret key int maxUpdates = 10; // max server queries the SDK will send out at a time PEERBool natNeg = PEERFalse; // nat negotiation will not be supported PEERBool pingRooms[NumRooms]; PEERBool crossPingRooms[NumRooms]; /* peerConnect parameters */ int profileID = 0; // we will not be using gp accounts, so this will be ignored void * userData = NULL; // optional data passed to peerConnectCallback PEERBool blocking = PEERTrue; // true means function runs synchronously PEERBool non_blocking = PEERFalse; // false means function runs asynchronously int newbiesGroupID = 2; gsi_char * serverName = _T("UberNoobServer"); int maxPlayers = 2; gsi_char * noPassword = _T(""); GSIACResult result; // used for backend availability check gsi_time startTime; // set our nickname to a random string so that we'll have different nicks when running multiple instances of peerc _tsnprintf(nick,NICK_SIZE,_T("peerc%u"),(unsigned int)current_time()); nick[NICK_SIZE - 1] = '\0'; // set the secret key, in a semi-obfuscated manner secret_key[0] = 'H'; secret_key[1] = 'A'; secret_key[2] = '6'; secret_key[3] = 'z'; secret_key[4] = 'k'; secret_key[5] = 'S'; secret_key[6] = '\0'; // check that the game's backend is available GSIStartAvailableCheck(_T("gmtest")); while((result = GSIAvailableCheckThink()) == GSIACWaiting) msleep(5); if(result != GSIACAvailable) { _tprintf(_T("The backend is not available\n")); return 1; } // set the callbacks memset(&callbacks, 0, sizeof(PEERCallbacks)); callbacks.disconnected = DisconnectedCallback; //callbacks.qrNatNegotiateCallback callbacks.gameStarted = GameStartedCallback; callbacks.playerChangedNick = PlayerChangedNickCallback; callbacks.playerJoined = PlayerJoinedCallback; callbacks.playerLeft = PlayerLeftCallback; callbacks.readyChanged = ReadyChangedCallback; callbacks.roomMessage = RoomMessageCallback; callbacks.playerMessage = PlayerMessageCallback; callbacks.roomUTM = RoomUTMCallback; callbacks.roomKeyChanged = RoomKeyChangedCallback; callbacks.qrKeyList = QRKeyListCallback; callbacks.qrServerKey = QRServerKeyCallback; callbacks.param = NULL; // initialize peer object, specifying the supported callbacks peer = peerInitialize(&callbacks); if(!peer) { _tprintf(_T("Failed to init\n")); return 1; } // ping/cross-ping in every room pingRooms[TitleRoom] = PEERTrue; pingRooms[GroupRoom] = PEERTrue; pingRooms[StagingRoom] = PEERTrue; crossPingRooms[TitleRoom] = PEERTrue; crossPingRooms[GroupRoom] = PEERTrue; crossPingRooms[StagingRoom] = PEERTrue; // set the title if(!peerSetTitle(peer, TITLE, secret_key, TITLE, secret_key, 0, maxUpdates, natNeg, pingRooms, crossPingRooms)) { peerShutdown(peer); _tprintf(_T("Failed to set the title\n")); return 1; } // connect to the chat server _tprintf(_T("Connecting as %s..."), nick); peerConnect(peer, nick, profileID, NickErrorCallback, ConnectCallback, userData, blocking); if(!connectSuccess) { peerShutdown(peer); _tprintf(_T("Failed to connect\n")); return 1; } printf("Connected\n\n"); // join the title room printf("Joining title room..."); peerJoinTitleRoom(peer, NULL, JoinCallback, NULL, PEERTrue); if(!joinSuccess) { peerDisconnect(peer); peerShutdown(peer); _tprintf(_T("Failed to join the title room\n")); return 1; } printf("Joined\n\n"); // list the group rooms printf("Listing group rooms:\n"); peerListGroupRooms(peer, _T(""), ListGroupRoomsCallback, userData, non_blocking); while (!groupRoomCallbackDone) { peerThink(peer); msleep(10); } // send a chat message to the room printf("\nSending message to the Title Room...\n"); peerMessageRoom(peer, TitleRoom, _T("Hi everyone in the Title Room!\n"), NormalMessage); // Loop for a while startTime = current_time(); while((current_time() - startTime) < (1000)) { peerThink(peer); msleep(10); } _tprintf(_T("\nJoining Group Room 'Newbies'...")); peerJoinGroupRoom(peer, newbiesGroupID, JoinRoomCallback, userData, blocking); _tprintf(_T("\nPlayers in Group Room: \n")); peerEnumPlayers(peer, GroupRoom, EnumPlayersCallback, NULL); _tprintf(_T("Hosting Staging Room...\n")); peerCreateStagingRoom(peer, serverName, maxPlayers, noPassword, CreateStagingRoomCallback, userData, blocking); // Loop for a while startTime = current_time(); while((current_time() - startTime) < (1000)) { peerThink(peer); msleep(10); } //peerStartAutoMatch(peer, 3, _T(""), AutoMatchStatusCallback, AutoMatchRateCallback, NULL, PEERFalse); //peerStopListingGames(peer); // Leave the title room peerLeaveRoom(peer, TitleRoom, NULL); // Stop auto match if it's in progress //peerStopAutoMatch(peer); // disconnect local client from chat server (peerShutdown must still be called) peerDisconnect(peer); peerShutdown(peer); // clean up (free internal sdk memory) GSI_UNUSED(argc); GSI_UNUSED(argv); return 0; }