本文整理汇总了C++中BitStream::WriteCompressed方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::WriteCompressed方法的具体用法?C++ BitStream::WriteCompressed怎么用?C++ BitStream::WriteCompressed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitStream
的用法示例。
在下文中一共展示了BitStream::WriteCompressed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoDeathCheck
void CLocalPlayer::DoDeathCheck()
{
// Have we not yet processed the death and is the local player dead?
if(!CLocalPlayer::m_bIsDead && IsDead())
{
// Get the kill info
EntityId playerId = INVALID_ENTITY_ID;
EntityId vehicleId = INVALID_ENTITY_ID;
EntityId weaponId = INVALID_ENTITY_ID;
GetKillInfo(&playerId, &vehicleId,&weaponId);
CLogFile::Printf("HandleDeath(LocalPlayer, %d, %d, %d)", playerId, vehicleId, weaponId);
g_pCore->GetChat()->Outputf(false, "HandleDeath(LocalPlayer, %d, %d, %d)", playerId, vehicleId, weaponId);
// Send the death notification to the server
BitStream bsSend;
bsSend.WriteCompressed(playerId);
bsSend.WriteCompressed(vehicleId);
bsSend.WriteCompressed(weaponId);
g_pCore->GetNetworkManager()->Call(GET_RPC_CODEX(RPC_PLAYER_DEATH), &bsSend, HIGH_PRIORITY, RELIABLE_ORDERED, true);
// Mark ourselves as dead
CLocalPlayer::m_bIsDead = true;
// Delete the object
CIVScript::DeleteObject(&m_pObj);
// Reset vehicle entry/exit flags
SetExitFlag(true);
ResetVehicleEnterExit();
// Get current day time so we don't have to set the time always..
CGameFunction::GetTime(&m_iRespawnTime[0], &m_iRespawnTime[1]);
}
}
示例2: OnJoinGroupRequestFromClient
void RelayPlugin::OnJoinGroupRequestFromClient(Packet *packet)
{
BitStream bsIn(packet->data, packet->length, false);
bsIn.IgnoreBytes(sizeof(MessageID)*2);
RakString groupName;
bsIn.ReadCompressed(groupName);
RelayPlugin::RP_Group *groupJoined = JoinGroup(packet->guid, groupName);
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
if (groupJoined)
{
bsOut.WriteCasted<MessageID>(RPE_JOIN_GROUP_SUCCESS);
bsOut.WriteCasted<uint16_t>(groupJoined->usersInRoom.Size());
for (unsigned int i=0; i < groupJoined->usersInRoom.Size(); i++)
{
bsOut.WriteCompressed(groupJoined->usersInRoom[i].str);
}
}
else
{
bsOut.WriteCasted<MessageID>(RPE_JOIN_GROUP_FAILURE);
}
SendUnified(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->guid, false);
}
示例3: SendMessageToRoom
void RelayPlugin::SendMessageToRoom(StrAndGuidAndRoom **strAndGuidSender, BitStream* message)
{
if ((*strAndGuidSender)->currentRoom.IsEmpty())
return;
for (unsigned int i=0; i < chatRooms.Size(); i++)
{
if (chatRooms[i]->roomName==(*strAndGuidSender)->currentRoom)
{
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
bsOut.WriteCasted<MessageID>(RPE_GROUP_MSG_FROM_SERVER);
message->ResetReadPointer();
bsOut.WriteCompressed((*strAndGuidSender)->str);
bsOut.AlignWriteToByteBoundary();
bsOut.Write(message);
RP_Group *room = chatRooms[i];
for (unsigned int i=0; i < room->usersInRoom.Size(); i++)
{
if (room->usersInRoom[i].guid!=(*strAndGuidSender)->guid)
SendUnified(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, room->usersInRoom[i].guid, false);
}
break;
}
}
}
示例4: AddParticipantRequestFromClient
void RelayPlugin::AddParticipantRequestFromClient(const RakString &key, const RakNetGUID &relayPluginServerGuid)
{
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
bsOut.WriteCasted<MessageID>(RPE_ADD_CLIENT_REQUEST_FROM_CLIENT);
bsOut.WriteCompressed(key);
SendUnified(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, relayPluginServerGuid, false);
}
示例5: JoinGroupRequest
void RelayPlugin::JoinGroupRequest(const RakNetGUID &relayPluginServerGuid, RakString groupName)
{
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
bsOut.WriteCasted<MessageID>(RPE_JOIN_GROUP_REQUEST_FROM_CLIENT);
bsOut.WriteCompressed(groupName);
SendUnified(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, relayPluginServerGuid, false);
}
示例6: SendToParticipant
// Send a message to a server running RelayPlugin, to forward a message to the system identified by \a key
void RelayPlugin::SendToParticipant(const RakNetGUID &relayPluginServerGuid, const RakString &key, BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel)
{
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
bsOut.WriteCasted<MessageID>(RPE_MESSAGE_TO_SERVER_FROM_CLIENT);
bsOut.WriteCasted<unsigned char>(priority);
bsOut.WriteCasted<unsigned char>(reliability);
bsOut.Write(orderingChannel);
bsOut.WriteCompressed(key);
bsOut.Write(bitStream);
SendUnified(&bsOut, priority, reliability, orderingChannel, relayPluginServerGuid, false);
}
示例7: NotifyUsersInRoom
void RelayPlugin::NotifyUsersInRoom(RP_Group *room, int msg, const RakString& message)
{
for (unsigned int i=0; i < room->usersInRoom.Size(); i++)
{
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
bsOut.WriteCasted<MessageID>(msg);
bsOut.WriteCompressed(message);
SendUnified(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, room->usersInRoom[i].guid, false);
}
}
示例8: SendChatRoomsList
void RelayPlugin::SendChatRoomsList(RakNetGUID target)
{
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
bsOut.WriteCasted<MessageID>(RPE_GET_GROUP_LIST_REPLY_FROM_SERVER);
bsOut.WriteCasted<uint16_t>(chatRooms.Size());
for (unsigned int i=0; i < chatRooms.Size(); i++)
{
bsOut.WriteCompressed(chatRooms[i]->roomName);
bsOut.WriteCasted<uint16_t>(chatRooms[i]->usersInRoom.Size());
}
SendUnified(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, target, false);
}
示例9: OnAutopatcherRequestFiles
void AutoPatcher::OnAutopatcherRequestFiles( Packet *packet )
{
assert( rakPeerInterface || rakClientInterface || rakServerInterface );
BitStream serializedFileDescriptor( ( char* ) packet->data, packet->length, false );
BitStream outputBitStream;
DownloadableFileDescriptor dfd;
unsigned int numberOfFilesRequested;
unsigned index, downloadableFilesIndex;
unsigned char packetID;
// Holds a copy of the pointers. Don't deallocate them!
BasicDataStructures::List<DownloadableFileDescriptor*> sendList;
// Ignore ID_AUTOPATCHER_REQUEST_FILES
serializedFileDescriptor.IgnoreBits( sizeof( unsigned char ) * 8 );
if ( serializedFileDescriptor.ReadCompressed( numberOfFilesRequested ) == false )
{
// Invalid packet format. Should never get this unless it's a bug or someone is hacking
#ifdef _DEBUG
assert( 0 );
#endif
return ;
}
// Go through all the files requested in the packet.
// If we allow download of it, add the descriptor to a send list which we
// serialize and send back to the sender telling them what files they will get.
// This is necessary because it is possible that cheaters will request files
// not in the list or that files will be removed from downloadable status after an initial
// successful request for it
for ( index = 0; index < numberOfFilesRequested; index++ )
{
dfd.Clear();
if ( dfd.DeserializeHeader( &serializedFileDescriptor ) == false )
{
assert( 0 ); // Error in packet header. Should only get this from hackers or bugs
return ;
}
for ( downloadableFilesIndex = 0; downloadableFilesIndex < downloadableFiles.size(); downloadableFilesIndex++ )
{
if ( strcmp( downloadableFiles[ downloadableFilesIndex ] ->filename, dfd.filename ) == 0 )
{
// Record that we are going to send this file to system requesting it
sendList.insert( downloadableFiles[ downloadableFilesIndex ] );
break;
}
}
}
packetID = ID_AUTOPATCHER_SET_DOWNLOAD_LIST;
// Serialize the list of files we will send
outputBitStream.Write( packetID );
outputBitStream.WriteCompressed( sendList.size() );
for ( index = 0; index < sendList.size(); index++ )
sendList[ index ] ->SerializeHeader( &outputBitStream );
// Send the list of files
if ( rakServerInterface )
rakServerInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
if ( rakPeerInterface )
rakPeerInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
rakClientInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream );
// The next step is to send the actual files. We already know what files need to be sent -
// The files specified by the descriptors in sendList.
packetID = ID_AUTOPATCHER_WRITE_FILE;
for ( index = 0; index < sendList.size(); index++ )
{
// We used outputBitStream earlier so don't forget to reset it
outputBitStream.Reset();
outputBitStream.Write( packetID );
sendList[ index ] ->SerializeHeader( &outputBitStream );
sendList[ index ] ->SerializeFileData( &outputBitStream );
if ( rakServerInterface )
rakServerInterface->Send( &outputBitStream, LOW_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
if ( rakPeerInterface )
rakPeerInterface->Send( &outputBitStream, LOW_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
rakClientInterface->Send( &outputBitStream, LOW_PRIORITY, RELIABLE_ORDERED, orderingStream );
}
}
示例10: OnAutopatcherFileList
//.........这里部分代码省略.........
{
// Invalid packet format. Should never get this unless it's a bug or someone is hacking
#ifdef _DEBUG
assert( 0 );
#endif
return ;
}
dfd = 0;
for ( index = 0; index < numberOfDownloadableFiles; index++ )
{
if ( dfd == 0 )
dfd = new DownloadableFileDescriptor;
else
dfd->Clear();
if ( dfd->DeserializeHeader( &serializedFileDescriptor ) == false )
{
assert( 0 ); // Error in packet header. Should only get this from hackers or bugs
delete dfd;
for ( index = 0; index < downloadingFiles.size(); index++ )
delete downloadingFiles[ index ];
downloadingFiles.clear();
return ;
}
if ( dfd->DeserializeSHA1( &serializedFileDescriptor ) == false )
{
assert( 0 ); // Error in packet header. Should only get this from hackers or bugs
delete dfd;
for ( index = 0; index < downloadingFiles.size(); index++ )
delete downloadingFiles[ index ];
downloadingFiles.clear();
return ;
}
// Check to see if we have the file specified in the file descriptor.
// If we don't have it, or the SHA1 doesn't match, then request to download it
if ( downloadPrefix )
{
filePath = new char[ strlen( downloadPrefix ) + strlen( dfd->filename ) + 1 ];
strcpy( filePath, downloadPrefix );
strcat( filePath, dfd->filename );
allocatedFilePath = true;
}
else
{
filePath = dfd->filename;
allocatedFilePath = false;
}
// Just a guess - if the server uses a different compressionBoundary
// then it will be a wrong guess
dfd->fileDataIsCompressed = dfd->fileLength >= compressionBoundary ? true : false;
if ( GenerateSHA1( filePath, SHA1Code ) == false ||
memcmp( SHA1Code, dfd->SHA1Code, SHA1_LENGTH * sizeof( char ) ) != 0 )
{
// Don't have the file, or SHA1 doesn't match.
// Add dfd to the list of files to download
downloadingFiles.insert( dfd );
dfd = 0;
}
if ( allocatedFilePath )
delete [] filePath;
}
if ( dfd )
delete dfd;
// At this point downloadingFiles is probably what we will get back, in that order.
// However, if the server rejects to send something then it will be changed by a later packet.
if ( downloadingFiles.size() > 0 )
{
packetID = ID_AUTOPATCHER_REQUEST_FILES;
outputBitStream.Write( packetID );
outputBitStream.WriteCompressed( downloadingFiles.size() );
for ( index = 0; index < downloadingFiles.size(); index++ )
downloadingFiles[ index ] ->SerializeHeader( &outputBitStream );
if ( rakServerInterface )
rakServerInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
if ( rakPeerInterface )
rakPeerInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream, packet->playerId, false );
else
rakClientInterface->Send( &outputBitStream, MEDIUM_PRIORITY, RELIABLE_ORDERED, orderingStream );
}
}
示例11: OnReceive
PluginReceiveResult RelayPlugin::OnReceive(Packet *packet)
{
if (packet->data[0]==ID_RELAY_PLUGIN)
{
switch (packet->data[1])
{
case RPE_MESSAGE_TO_SERVER_FROM_CLIENT:
{
BitStream bsIn(packet->data, packet->length, false);
bsIn.IgnoreBytes(sizeof(MessageID)*2);
PacketPriority priority;
PacketReliability reliability;
char orderingChannel;
unsigned char cIn;
bsIn.Read(cIn);
priority = (PacketPriority) cIn;
bsIn.Read(cIn);
reliability = (PacketReliability) cIn;
bsIn.Read(orderingChannel);
RakString key;
bsIn.ReadCompressed(key);
BitStream bsData;
bsIn.Read(&bsData);
StrAndGuidAndRoom **strAndGuid = strToGuidHash.Peek(key);
StrAndGuidAndRoom **strAndGuidSender = guidToStrHash.Peek(packet->guid);
if (strAndGuid && strAndGuidSender)
{
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
bsOut.WriteCasted<MessageID>(RPE_MESSAGE_TO_CLIENT_FROM_SERVER);
bsOut.WriteCompressed( (*strAndGuidSender)->str );
bsOut.AlignWriteToByteBoundary();
bsOut.Write(bsData);
SendUnified(&bsOut, priority, reliability, orderingChannel, (*strAndGuid)->guid, false);
}
return RR_STOP_PROCESSING_AND_DEALLOCATE;
}
case RPE_ADD_CLIENT_REQUEST_FROM_CLIENT:
{
BitStream bsIn(packet->data, packet->length, false);
bsIn.IgnoreBytes(sizeof(MessageID)*2);
RakString key;
bsIn.ReadCompressed(key);
BitStream bsOut;
bsOut.WriteCasted<MessageID>(ID_RELAY_PLUGIN);
if (acceptAddParticipantRequests)
bsOut.WriteCasted<MessageID>(AddParticipantOnServer(key, packet->guid));
else
bsOut.WriteCasted<MessageID>(RPE_ADD_CLIENT_NOT_ALLOWED);
bsOut.WriteCompressed(key);
SendUnified(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false);
return RR_STOP_PROCESSING_AND_DEALLOCATE;
}
case RPE_REMOVE_CLIENT_REQUEST_FROM_CLIENT:
{
RemoveParticipantOnServer(packet->guid);
}
return RR_STOP_PROCESSING_AND_DEALLOCATE;
case RPE_GROUP_MESSAGE_FROM_CLIENT:
{
OnGroupMessageFromClient(packet);
}
return RR_STOP_PROCESSING_AND_DEALLOCATE;
case RPE_JOIN_GROUP_REQUEST_FROM_CLIENT:
{
OnJoinGroupRequestFromClient(packet);
}
return RR_STOP_PROCESSING_AND_DEALLOCATE;
case RPE_LEAVE_GROUP_REQUEST_FROM_CLIENT:
{
OnLeaveGroupRequestFromClient(packet);
}
return RR_STOP_PROCESSING_AND_DEALLOCATE;
case RPE_GET_GROUP_LIST_REQUEST_FROM_CLIENT:
{
SendChatRoomsList(packet->guid);
}
return RR_STOP_PROCESSING_AND_DEALLOCATE;
}
}
return RR_CONTINUE_PROCESSING;
}
示例12: main
int main(void)
{
printf("Tests the RelayPlugin as a server.\n");
printf("Difficulty: Beginner\n\n");
char str[64], str2[64];
RakNet::RakPeerInterface *peer=RakNet::RakPeerInterface::GetInstance();
RelayPlugin *relayPlugin = RelayPlugin::GetInstance();
peer->AttachPlugin(relayPlugin);
// Get our input
char ip[64], serverPort[30], listenPort[30];
puts("Enter the port to listen on");
Gets(listenPort,sizeof(listenPort));
if (listenPort[0]==0)
strcpy(listenPort, "1234");
relayPlugin->SetAcceptAddParticipantRequests(true);
// Connecting the client is very simple. 0 means we don't care about
// a connectionValidationInteger, and false for low priority threads
RakNet::SocketDescriptor socketDescriptor(atoi(listenPort),0);
socketDescriptor.socketFamily=AF_INET;
peer->Startup(8,&socketDescriptor, 1);
peer->SetMaximumIncomingConnections(8);
peer->SetOccasionalPing(true);
puts("Enter IP to connect to, or enter for none");
Gets(ip, sizeof(ip));
peer->AllowConnectionResponseIPMigration(false);
if (ip[0])
{
puts("Enter the port to connect to");
Gets(serverPort,sizeof(serverPort));
if (serverPort[0]==0)
strcpy(serverPort, "1234");
RakNet::ConnectionAttemptResult car = peer->Connect(ip, atoi(serverPort), 0, 0);
RakAssert(car==RakNet::CONNECTION_ATTEMPT_STARTED);
}
peer->SetTimeoutTime(30000, UNASSIGNED_SYSTEM_ADDRESS);
peer->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS).ToString(str);
printf("My GUID is %s\n", str);
printf("(A)ddParticipantRequestFromClient\n");
printf("(R)emoveParticipantRequestFromClient\n");
printf("SendTo(P)articipant\n");
printf("(S)endGroupMessage\n");
printf("(J)oinGroupRequest\n");
printf("(L)eaveGroup\n");
printf("(G)etGroupList\n");
printf("(Q)uit\n");
char name[128];
while (1)
{
if (kbhit())
{
char ch = getch();
if (ch=='a' || ch=='A')
{
printf("Enter name of participant: ");
Gets(name, sizeof(name));
if (name[0])
{
relayPlugin->AddParticipantRequestFromClient(name,peer->GetGUIDFromIndex(0));
printf("Done\n");
}
else
{
printf("Operation aborted\n");
}
}
else if (ch=='r' || ch=='R')
{
relayPlugin->RemoveParticipantRequestFromClient(peer->GetGUIDFromIndex(0));
printf("Done\n");
}
else if (ch=='p' || ch=='P')
{
char name[128];
printf("Enter name of participant: ");
Gets(name, sizeof(name));
if (name[0])
{
printf("Enter message to send: ");
char msg[256];
Gets(msg, sizeof(msg));
RakString msgRs = msg;
BitStream msgBs;
msgBs.WriteCompressed(msgRs);
relayPlugin->SendToParticipant(peer->GetGUIDFromIndex(0), name, &msgBs, HIGH_PRIORITY, RELIABLE_ORDERED, 0 );
printf("Done\n");
}
else
{
printf("Operation aborted\n");
//.........这里部分代码省略.........
示例13: HandleQuery
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);
}