void MasterClient::PostRule(char *ruleIdentifier, char *stringData, int intData) { if (ruleIdentifier) { if (IsReservedRuleIdentifier(ruleIdentifier)) return; localServerModified |= UpdateServerRule(&localServer, ruleIdentifier, stringData, intData); } }
void MasterClient::AddQueryRule(char *ruleIdentifier) { if (ruleIdentifier && IsReservedRuleIdentifier(ruleIdentifier)==false) stringCompressor->EncodeString(ruleIdentifier, 256, &ruleIdentifierList); }
void MasterServer::HandleQuery(Packet *packet) { DataStructures::List<GameServer*> serversWithKeysList; char ruleIdentifier[256]; unsigned index, serverIndex; int key; bool queryAll; BitStream outputBitStream; BitStream compressedString(packet->data, packet->length, false); compressedString.IgnoreBits(8*sizeof(unsigned char)); queryAll=true; while (compressedString.GetNumberOfUnreadBits()>0) { // Generate a list of the indices of the servers that have one or more of the specified keys. stringCompressor->DecodeString(ruleIdentifier, 256, &compressedString); if (ruleIdentifier[0]==0) // If we fail to read the first string, queryAll remains true. break; queryAll=false; if (IsReservedRuleIdentifier(ruleIdentifier)) continue; for (index=0; index < gameServerList.serverList.Size(); index++) { if (gameServerList.serverList[index]->connectionIdentifier==UNASSIGNED_PLAYER_ID) continue; if (gameServerList.serverList[index]->FindKey(ruleIdentifier)) { serverIndex=serversWithKeysList.GetIndexOf(gameServerList.serverList[index]); if (serverIndex==MAX_UNSIGNED_LONG) { gameServerList.serverList[index]->numberOfKeysFound=1; serversWithKeysList.Insert(gameServerList.serverList[index]); } else { serversWithKeysList[serverIndex]->numberOfKeysFound++; } } } } // Write the packet id if (queryAll) outputBitStream.Write((unsigned char) ID_MASTER_SERVER_SET_SERVER); else outputBitStream.Write((unsigned char) ID_MASTER_SERVER_UPDATE_SERVER); if (queryAll) { // Write the number of servers outputBitStream.WriteCompressed((unsigned short)gameServerList.serverList.Size()); for (index=0; index < gameServerList.serverList.Size(); index++) { // Write the whole server SerializeServer(gameServerList.serverList[index], &outputBitStream); } } else { compressedString.ResetReadPointer(); compressedString.IgnoreBits(8*sizeof(unsigned char)); // Write the number of servers with requested keys outputBitStream.WriteCompressed((unsigned short)serversWithKeysList.Size()); // For each server, write the header which consists of the IP/PORT. // Then go through the list of requested keys and write those for (index=0; index < serversWithKeysList.Size(); index++) { SerializePlayerID(&(serversWithKeysList[index]->connectionIdentifier), &outputBitStream); outputBitStream.WriteCompressed((unsigned short)serversWithKeysList[index]->numberOfKeysFound); while (compressedString.GetNumberOfUnreadBits()>0) { // Generate a list of the indices of the servers that have one or more of the specified keys. stringCompressor->DecodeString(ruleIdentifier, 256, &compressedString); if (ruleIdentifier[0]==0) break; if (IsReservedRuleIdentifier(ruleIdentifier)) continue; serversWithKeysList[index]->FindKey(ruleIdentifier); key=serversWithKeysList[index]->keyIndex; if (key>=0) SerializeRule(serversWithKeysList[index]->serverRules[key], &outputBitStream); } } } rakPeer->Send(&outputBitStream, MEDIUM_PRIORITY, RELIABLE, 0, packet->playerId, false); }