本文整理汇总了C++中raknet::BitStream::GetData方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::GetData方法的具体用法?C++ BitStream::GetData怎么用?C++ BitStream::GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raknet::BitStream
的用法示例。
在下文中一共展示了BitStream::GetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdatePingResponse
void Server::UpdatePingResponse()
{
ECS::Entity* serverInfoEntity = m_world->GetTagManager()->GetEntityByTag("ServerInformation");
Network::ServerInformationComponent* serverInfo = m_world->GetEntityManager()->GetComponent<Network::ServerInformationComponent>(serverInfoEntity);
RakNet::BitStream bs;
serverInfo->Information.Serialize(true, &bs);
const unsigned char* data = bs.GetData();
unsigned int size = bs.GetNumberOfBytesUsed();
m_peer->SetOfflinePingResponse((const char*)bs.GetData(), bs.GetNumberOfBytesUsed());
}
示例2: EncodeString
void StringCompressor::EncodeString( const char *input, int maxCharsToWrite, RakNet::BitStream *output, int languageID )
{
HuffmanEncodingTree *huffmanEncodingTree;
if (huffmanEncodingTrees.Has(languageID)==false)
return;
huffmanEncodingTree=huffmanEncodingTrees.Get(languageID);
if ( input == 0 )
{
output->WriteCompressed( (unsigned short) 0 );
return;
}
RakNet::BitStream encodedBitStream;
unsigned short stringBitLength;
int charsToWrite;
if ( maxCharsToWrite<=0 || ( int ) strlen( input ) < maxCharsToWrite )
charsToWrite = ( int ) strlen( input );
else
charsToWrite = maxCharsToWrite - 1;
huffmanEncodingTree->EncodeArray( ( unsigned char* ) input, charsToWrite, &encodedBitStream );
stringBitLength = ( unsigned short ) encodedBitStream.GetNumberOfBitsUsed();
output->WriteCompressed( stringBitLength );
output->WriteBits( encodedBitStream.GetData(), stringBitLength );
}
示例3: EncodeClassName
void EncodeClassName( char *name, char *identifier )
{
RakNet::BitStream bitStream;
int index = 0;
unsigned char byte;
while ( index < MAXIMUM_CLASS_IDENTIFIER_LENGTH - 1 )
{
if ( name[ index ] == 0 )
break;
// This should generate a unique identifier for any realistic class name that is 5/8th the length of the actual name and weakly encrypts and compresses it
if ( name[ index ] >= 'a' && name[ index ] <= 'z' )
byte = name[ index ] - 'a';
else if ( name[ index ] >= 'A' && name[ index ] <= 'Z' )
byte = name[ index ] - 'A';
else if ( name[ index ] >= '0' && name[ index ] <= '9' )
byte = name[ index ] - '0';
else
byte = name[ index ] << 3;
bitStream.WriteBits( ( unsigned char* ) & byte, 5 );
index++;
}
#ifdef _DEBUG
memset( identifier, 0, MAXIMUM_CLASS_IDENTIFIER_LENGTH );
#endif
identifier[ 0 ] = ( char ) ( bitStream.GetNumberOfBytesUsed() );
memcpy( identifier + 1, bitStream.GetData(), bitStream.GetNumberOfBytesUsed() );
}
示例4: UploadInstanceToCloud
void UploadInstanceToCloud(RakNet::CloudClient *cloudClient, RakNet::RakNetGUID serverGuid)
{
RakNet::CloudKey cloudKey(CLOUD_CLIENT_PRIMARY_KEY,0);
RakNet::BitStream bs;
bs.Write("Hello World"); // This could be anything such as player list, game name, etc.
cloudClient->Post(&cloudKey, bs.GetData(), bs.GetNumberOfBytesUsed(), serverGuid);
}
示例5:
void Router2::SendOOBFromSpecifiedSocket(OutOfBandIdentifiers oob, SystemAddress sa, SOCKET socket)
{
RakNet::BitStream bs;
rakPeerInterface->WriteOutOfBandHeader(&bs);
bs.Write((unsigned char) oob);
SocketLayer::SendTo_PC( socket, (const char*) bs.GetData(), bs.GetNumberOfBytesUsed(), sa, __FILE__, __LINE__ );
}
示例6: SendOutOfBand
void NatPunchthroughClient::SendOutOfBand(SystemAddress sa, MessageID oobId)
{
if (sa==UNASSIGNED_SYSTEM_ADDRESS)
return;
if (sa.port==0)
return;
RakNet::BitStream oob;
oob.Write(oobId);
oob.Write(sp.sessionId);
// RakAssert(sp.sessionId<100);
if (oobId==ID_NAT_ESTABLISH_BIDIRECTIONAL)
oob.Write(sa.port);
char ipAddressString[32];
sa.ToString(false, ipAddressString);
rakPeerInterface->SendOutOfBand((const char*) ipAddressString,sa.port,(const char*) oob.GetData(),oob.GetNumberOfBytesUsed());
if (natPunchthroughDebugInterface)
{
sa.ToString(true,ipAddressString);
char guidString[128];
sp.targetGuid.ToString(guidString);
if (oobId==ID_NAT_ESTABLISH_UNIDIRECTIONAL)
natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("Sent OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid %s, system address %s.", guidString, ipAddressString));
else
natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("Sent OOB ID_NAT_ESTABLISH_BIDIRECTIONAL to guid %s, system address %s.", guidString, ipAddressString));
}
}
示例7: OnTestPortRestricted
void NatTypeDetectionClient::OnTestPortRestricted(Packet *packet)
{
RakNet::BitStream bsIn(packet->data,packet->length,false);
bsIn.IgnoreBytes(sizeof(MessageID));
RakNet::RakString s3p4StrAddress;
bsIn.Read(s3p4StrAddress);
unsigned short s3p4Port;
bsIn.Read(s3p4Port);
DataStructures::List<RakNetSocket2* > sockets;
rakPeerInterface->GetSockets(sockets);
SystemAddress s3p4Addr = sockets[0]->GetBoundAddress();
s3p4Addr.FromStringExplicitPort(s3p4StrAddress.C_String(), s3p4Port);
// Send off the RakNet socket to the specified address, message is unformatted
// Server does this twice, so don't have to unduly worry about packetloss
RakNet::BitStream bsOut;
bsOut.Write((MessageID) NAT_TYPE_PORT_RESTRICTED);
bsOut.Write(rakPeerInterface->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS));
// SocketLayer::SendTo_PC( sockets[0], (const char*) bsOut.GetData(), bsOut.GetNumberOfBytesUsed(), s3p4Addr, __FILE__, __LINE__ );
RNS2_SendParameters bsp;
bsp.data = (char*) bsOut.GetData();
bsp.length = bsOut.GetNumberOfBytesUsed();
bsp.systemAddress=s3p4Addr;
sockets[0]->Send(&bsp, _FILE_AND_LINE_);
}
示例8: PushReference
void FileListTransfer::PushReference(SystemAddress systemAddress)
{
// Was previously using GetStatistics to get outgoing buffer size, but TCP with UnifiedSend doesn't have this
unsigned int i=0;
unsigned int bytesRead;
char *dataBlocks[2];
int lengths[2];
RakNet::BitStream outBitstream;
while (i < filesToPush.Size())
{
if (filesToPush[i].systemAddress==systemAddress)
{
outBitstream.Reset();
outBitstream.Write((MessageID)ID_FILE_LIST_REFERENCE_PUSH);
outBitstream.Write(filesToPush[i].fileListNode.context);
outBitstream.Write(filesToPush[i].setID);
stringCompressor->EncodeString(filesToPush[i].fileListNode.filename, 512, &outBitstream);
outBitstream.WriteCompressed(filesToPush[i].setIndex);
outBitstream.WriteCompressed(filesToPush[i].fileListNode.dataLengthBytes); // Original length in bytes
// Read and send chunk. If done, delete at this index
void *buff = rakMalloc_Ex(filesToPush[i].chunkSize, __FILE__, __LINE__);
if (buff==0)
{
notifyOutOfMemory(__FILE__, __LINE__);
continue;
}
bytesRead=filesToPush[i].incrementalReadInterface->GetFilePart(filesToPush[i].fileListNode.fullPathToFile, filesToPush[i].currentOffset, filesToPush[i].chunkSize, buff, filesToPush[i].fileListNode.context);
outBitstream.WriteCompressed(filesToPush[i].currentOffset);
filesToPush[i].currentOffset+=bytesRead;
outBitstream.WriteCompressed(bytesRead);
bool done = bytesRead!=filesToPush[i].chunkSize;
outBitstream.Write(done);
if (callback)
{
callback->OnFilePush(filesToPush[i].fileListNode.filename, filesToPush[i].fileListNode.fileLengthBytes, filesToPush[i].currentOffset-bytesRead, bytesRead, done, filesToPush[i].systemAddress);
}
dataBlocks[0]=(char*) outBitstream.GetData();
lengths[0]=outBitstream.GetNumberOfBytesUsed();
dataBlocks[1]=(char*) buff;
lengths[1]=bytesRead;
//rakPeerInterface->SendList(dataBlocks,lengths,2,filesToPush[i].packetPriority, RELIABLE_ORDERED, filesToPush[i].orderingChannel, filesToPush[i].systemAddress, false);
SendListUnified(dataBlocks,lengths,2,filesToPush[i].packetPriority, RELIABLE_ORDERED, filesToPush[i].orderingChannel, filesToPush[i].systemAddress, false);
if (done)
{
// Done
RakNet::OP_DELETE_ARRAY(filesToPush[i].fileListNode.filename, __FILE__, __LINE__);
filesToPush.RemoveAtIndex(i);
}
rakFree_Ex(buff, __FILE__, __LINE__ );
return;
}
else
i++;
}
}
示例9: OnConnectionCountChange
void CloudServerHelper::OnConnectionCountChange(RakPeerInterface *rakPeer, CloudClient *cloudClient)
{
RakNet::BitStream bs;
CloudKey cloudKey(CLOUD_SERVER_CONNECTION_COUNT_PRIMARY_KEY,0);
unsigned short numberOfSystems;
rakPeer->GetConnectionList(0, &numberOfSystems);
bs.Write(numberOfSystems);
cloudClient->Post(&cloudKey, bs.GetData(), bs.GetNumberOfBytesUsed(), rakPeer->GetMyGUID());
}
示例10: updatePingResponse
void NetworkEngine::updatePingResponse()
{
RakNet::BitStream data;
if(isLobby())
{
data.Write1();
unsigned char numPlayers = (unsigned char) peer->NumberOfConnections();
data.Write(numPlayers);
std::cout << "Total players: " << (unsigned int) numPlayers << std::endl;
peer->SetOfflinePingResponse((char *)data.GetData(), data.GetNumberOfBytesUsed());
} else
{
data.Write0();
}
peer->SetOfflinePingResponse((char *)data.GetData(), data.GetNumberOfBytesUsed());
}
示例11: Save
bool SystemAddressList::Save(const char *filename)
{
RakNet::BitStream temp;
Serialize(&temp);
FILE *fp = fopen(filename, "wb");
if (fp)
{
fwrite(temp.GetData(), (size_t) temp.GetNumberOfBytesUsed(), 1, fp);
fclose(fp);
return true;
}
return false;
}
示例12: PushToUser
void TwoWayAuthentication::PushToUser(MessageID messageId, RakNet::RakString password, RakNet::AddressOrGUID remoteSystem)
{
RakNet::BitStream output;
output.Write(messageId);
if (password.IsEmpty()==false)
output.Write(password);
Packet *p = AllocatePacketUnified(output.GetNumberOfBytesUsed());
p->systemAddress=remoteSystem.systemAddress;
p->systemAddress.systemIndex=(SystemIndex)-1;
p->guid=remoteSystem.rakNetGuid;
p->wasGeneratedLocally=true;
memcpy(p->data, output.GetData(), output.GetNumberOfBytesUsed());
rakPeerInterface->PushBackPacket(p, true);
}
示例13: ExecStatementThread
SQLite3ServerPlugin::SQLExecThreadOutput ExecStatementThread(SQLite3ServerPlugin::SQLExecThreadInput threadInput, bool *returnOutput, void* perThreadData)
{
unsigned int queryId;
RakNet::RakString dbIdentifier;
RakNet::RakString inputStatement;
RakNet::BitStream bsIn((unsigned char*) threadInput.data, threadInput.length, false);
bsIn.IgnoreBytes(sizeof(MessageID));
bsIn.Read(queryId);
bsIn.Read(dbIdentifier);
bsIn.Read(inputStatement);
// bool isRequest;
// bsIn.Read(isRequest);
bsIn.IgnoreBits(1);
char *errorMsg;
RakNet::RakString errorMsgStr;
SQLite3Table outputTable;
sqlite3_exec(threadInput.dbHandle, inputStatement.C_String(), PerRowCallback, &outputTable, &errorMsg);
if (errorMsg)
{
errorMsgStr=errorMsg;
sqlite3_free(errorMsg);
}
RakNet::BitStream bsOut;
bsOut.Write((MessageID)ID_SQLite3_EXEC);
bsOut.Write(queryId);
bsOut.Write(dbIdentifier);
bsOut.Write(inputStatement);
bsOut.Write(false);
bsOut.Write(errorMsgStr);
outputTable.Serialize(&bsOut);
// Free input data
rakFree_Ex(threadInput.data,__FILE__,__LINE__);
// Copy to output data
SQLite3ServerPlugin::SQLExecThreadOutput threadOutput;
threadOutput.data=(char*) rakMalloc_Ex(bsOut.GetNumberOfBytesUsed(),__FILE__,__LINE__);
memcpy(threadOutput.data,bsOut.GetData(),bsOut.GetNumberOfBytesUsed());
threadOutput.length=bsOut.GetNumberOfBytesUsed();
threadOutput.sender=threadInput.sender;
// SendUnified(&bsOut, MEDIUM_PRIORITY,RELIABLE_ORDERED,0,packet->systemAddress,false);
*returnOutput=true;
return threadOutput;
}
示例14: SetLoopbackMode
void RakVoice::SetLoopbackMode(bool enabled)
{
if (enabled)
{
Packet p;
RakNet::BitStream out;
out.Write((unsigned char)ID_RAKVOICE_OPEN_CHANNEL_REQUEST);
out.Write((int32_t)sampleRate);
p.data=out.GetData();
p.systemAddress=UNASSIGNED_SYSTEM_ADDRESS;
p.guid=UNASSIGNED_RAKNET_GUID;
p.length=out.GetNumberOfBytesUsed();
OpenChannel(&p);
}
else
{
FreeChannelMemory(UNASSIGNED_RAKNET_GUID);
}
loopbackMode=enabled;
}
示例15: OnTestPortRestricted
void NatTypeDetectionClient::OnTestPortRestricted(Packet *packet)
{
RakNet::BitStream bsIn(packet->data,packet->length,false);
bsIn.IgnoreBytes(sizeof(MessageID));
RakNet::RakString s3p4StrAddress;
bsIn.Read(s3p4StrAddress);
unsigned short s3p4Port;
bsIn.Read(s3p4Port);
SystemAddress s3p4Addr(s3p4StrAddress.C_String(), s3p4Port);
DataStructures::List<RakNetSmartPtr<RakNetSocket> > sockets;
rakPeerInterface->GetSockets(sockets);
// Send off the RakNet socket to the specified address, message is unformatted
// Server does this twice, so don't have to unduly worry about packetloss
RakNet::BitStream bsOut;
bsOut.Write((MessageID) NAT_TYPE_PORT_RESTRICTED);
bsOut.Write(rakPeerInterface->GetGuidFromSystemAddress(UNASSIGNED_SYSTEM_ADDRESS));
SocketLayer::Instance()->SendTo_PC( sockets[0]->s, (const char*) bsOut.GetData(), bsOut.GetNumberOfBytesUsed(), s3p4Addr.binaryAddress, s3p4Addr.port);
}