void Directory::GetDataDArray ( const char *dataName, DArray<int> *darray ) const { AppAssert( dataName ); AppAssert( darray ); // // First try to find a directory representing this DArray Directory *dir = GetDirectory( dataName ); if ( !dir ) { AppReleaseAssert(false, "Failed to find DArray named %s", dataName ); return; } // // Get info about the DArray char *tID = dir->GetDataString("tID"); int size = dir->GetDataInt("Size"); if ( strcmp(tID, "DArray<int>") != 0 || size == DIRECTORY_SAFEINT) { AppDebugOut("Found object %s but it doesn't appear to be a DArray\n" ); } // // Iterate through it, loading data darray->SetSize( size ); for ( int i = 0; i < size; ++i ) { char indexName[16]; sprintf ( indexName, "[i %d]", i ); Directory *thisIndex = dir->GetDirectory( indexName ); if ( !thisIndex ) { AppDebugOut("Error loading DArray %s : index %d is missing\n", dataName, i ); } else { bool used = thisIndex->GetDataBool("[Used]"); if ( !used ) { if ( darray->ValidIndex(i) ) darray->RemoveData(i); } else { int theData = thisIndex->GetDataInt("[Data]"); darray->PutData( theData, i ); } } } }
void Directory::GetDataLList ( const char *dataName, LList<Directory *> *llist ) const { AppAssert( dataName ); AppAssert( llist ); // // First try to find a directory representing this LList Directory *dir = GetDirectory( dataName ); if ( !dir ) { AppDebugOut("Failed to find LList named %s\n", dataName); return; } // // Get info about the LList char *tID = dir->GetDataString("tID"); int size = dir->GetDataInt("Size"); if ( strcmp(tID, "LList<Directory *>") != 0 || size == DIRECTORY_SAFEINT) { AppDebugOut("Found object %s but it doesn't appear to be a LList\n"); } // // Iterate through it, loading data for ( int i = 0; i < size; ++i ) { char indexName[16]; sprintf ( indexName, "[i %d]", i ); Directory *thisIndex = dir->GetDirectory( indexName ); if ( !thisIndex ) { AppDebugOut("Error loading LList %s : index %d is missing\n", dataName, i); } else { if( thisIndex->m_subDirectories.ValidIndex(0) ) { Directory *theDir = thisIndex->m_subDirectories[0]; llist->PutData( theDir ); } else { AppDebugOut("Error loading LList %s : could not find directory in index %d\n", dataName, i); } } } }
void Directory::GetDataLList( const char *dataName, LList<int> *llist ) const { AppAssert( dataName ); AppAssert( llist ); // // First try to find a directory representing this LList Directory *dir = GetDirectory( dataName ); if ( !dir ) { AppDebugOut("Failed to find LList %s\n", dataName); return; } // // Get info about the LList char *tID = dir->GetDataString("tID"); int size = dir->GetDataInt("Size"); if ( strcmp(tID, "LList<int>") != 0 || size == DIRECTORY_SAFEINT) { AppDebugOut("Found object %s but it doesn't appear to be a LList\n"); } // // Iterate through it, loading data for ( int i = 0; i < size; ++i ) { char indexName[16]; sprintf ( indexName, "[i %d]", i ); int theData = dir->GetDataInt("indexName"); llist->PutDataAtEnd( theData ); } }
static NetCallBackRetType RequestIdentityThread(void *ignored) { #ifdef WAN_PLAY_ENABLED NetSocketListener *listener = (NetSocketListener *) ignored; int listenerIndex = GetListenerIndex(listener); AppAssert( listenerIndex > -1 ); s_listenersMutex.Lock(); MatchMakerListener *_listener = s_listeners[listenerIndex]; AppAssert(_listener); s_listenersMutex.Unlock(); // // Generate a uniqueID for this request // So we can tell the replies apart s_uniqueRequestMutex.Lock(); int uniqueId = s_uniqueRequestid; ++s_uniqueRequestid; s_uniqueRequestMutex.Unlock(); _listener->m_uniqueId = uniqueId; // // Build our request and convert to a byte stream // (only need to do this once and keep re-sending) Directory request; request.SetName( NET_MATCHMAKER_MESSAGE ); request.CreateData( NET_METASERVER_COMMAND, NET_MATCHMAKER_REQUEST_IDENTITY ); request.CreateData( NET_MATCHMAKER_UNIQUEID, uniqueId ); // // Open a connection to the MatchMaker service // Start sending requests for our ID every few seconds // to ensure the connection stays open in the NAT NetSocketSession socket( *listener, s_matchMakerIp, s_matchMakerPort ); while( true ) { // // Stop if We've been asked to if( _listener->m_shutDown ) { break; } // // Update the request with the latest auth data Directory *clientProps = MetaServer_GetClientProperties(); request.CreateData( NET_METASERVER_GAMENAME, clientProps->GetDataString(NET_METASERVER_GAMENAME) ); request.CreateData( NET_METASERVER_GAMEVERSION, clientProps->GetDataString(NET_METASERVER_GAMEVERSION) ); request.CreateData( NET_METASERVER_AUTHKEY, clientProps->GetDataString(NET_METASERVER_AUTHKEY) ); delete clientProps; int requestSize = 0; char *requestByteStream = request.Write(requestSize); // // Send the request int numBytesWritten = 0; NetRetCode result = socket.WriteData( requestByteStream, requestSize, &numBytesWritten ); delete [] requestByteStream; if( result != NetOk || numBytesWritten != requestSize ) { AppDebugOut( "MatchMaker encountered error sending data\n" ); break; } NetSleep( PERIOD_MATCHMAKER_REQUESTID ); } // // Shut down the request s_listenersMutex.Lock(); if( s_listeners.ValidIndex(listenerIndex) && s_listeners[listenerIndex] == _listener ) { s_listeners.RemoveData(listenerIndex); } s_listenersMutex.Unlock(); delete _listener; #endif return 0; }