本文整理汇总了C++中raknet::BitStream::GetNumberOfBytesUsed方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::GetNumberOfBytesUsed方法的具体用法?C++ BitStream::GetNumberOfBytesUsed怎么用?C++ BitStream::GetNumberOfBytesUsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raknet::BitStream
的用法示例。
在下文中一共展示了BitStream::GetNumberOfBytesUsed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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() );
}
示例2: 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());
}
示例3: 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);
}
示例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: send_input
void Network::send_input(){
if(status=="client"){
if(game.in_progress){
if(commands_this_second<rate_commands && ++counter_commands>=(uint32_t)ceil(UPDATE_RATE/(double)rate_commands)){
counter_commands=0;
commands_this_second++;
RakNet::BitStream bitstream;
bitstream.Write((RakNet::MessageID)ID_GAME_INPUT);
bitstream.WriteCompressed((int)command_buffer.size());
for(int i=0;i<command_buffer.size();i++){
bitstream.WriteCompressed((RakNet::RakString)command_buffer[i].c_str());
}
command_buffer.clear();
bitstream.WriteCompressed((int)game.command_states.size());
for(int i=0;i<game.command_states.size();i++){
bitstream.WriteCompressed((RakNet::RakString)game.command_states[i].c_str());
}
stat_counter_bytes_sent+=bitstream.GetNumberOfBytesUsed();
peer->Send(&bitstream,HIGH_PRIORITY,RELIABLE_ORDERED,ORDERING_CHANNEL_INPUT,server_id,false);
}
}
}
}
示例6: 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_);
}
示例7:
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__ );
}
示例8: 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;
}
示例9: writeToBitstream
void ServerInfo::writeToBitstream(RakNet::BitStream& stream)
{
stream.Write(activegames);
stream.Write(name, sizeof(name));
stream.Write(waitingplayers);
stream.Write(description, sizeof(description));
assert( stream.GetNumberOfBytesUsed() == BLOBBY_SERVER_PRESENT_PACKET_SIZE);
}
示例10: 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++;
}
}
示例11: send_connected
void Network::send_connected(){
if(status=="client"){
RakNet::BitStream bitstream;
bitstream.Write((RakNet::MessageID)ID_GAME_CONNECTED);
stat_counter_bytes_sent+=bitstream.GetNumberOfBytesUsed();
peer->Send(&bitstream,MEDIUM_PRIORITY,RELIABLE_ORDERED,ORDERING_CHANNEL_CONNECTION,server_id,false);
}
}
示例12: 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());
}
示例13: 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());
}
示例14: SqlLog
SQLLogResult SQLiteClientLoggerPlugin::SqlLog( bool isFunctionCall, const char *tableName, const char *columnNames, const char *file, const int line, const ParameterListHelper ¶meterList )
{
if (recursiveCheck==true)
return SQLLR_RECURSION;
recursiveCheck=true;
RakNet::BitStream bitStream;
SerializeHeader(&bitStream, isFunctionCall, tableName, columnNames, file, line, parameterList.paramCount);
// int i;
//for (i=0; i < parameterList.paramCount; i++)
// parameterList.parms[i].Serialize(&bitStream);
if (parameterList.paramCount>=1)
parameterList.p0.Serialize(&bitStream);
if (parameterList.paramCount>=2)
parameterList.p1.Serialize(&bitStream);
if (parameterList.paramCount>=3)
parameterList.p2.Serialize(&bitStream);
if (parameterList.paramCount>=4)
parameterList.p3.Serialize(&bitStream);
if (parameterList.paramCount>=5)
parameterList.p4.Serialize(&bitStream);
if (parameterList.paramCount>=6)
parameterList.p5.Serialize(&bitStream);
if (parameterList.paramCount>=7)
parameterList.p6.Serialize(&bitStream);
if (parameterList.paramCount>=8)
parameterList.p7.Serialize(&bitStream);
if (parameterList.paramCount>=9)
parameterList.p8.Serialize(&bitStream);
if (parameterList.paramCount>=10)
parameterList.p9.Serialize(&bitStream);
if (parameterList.paramCount>=11)
parameterList.p10.Serialize(&bitStream);
if (parameterList.paramCount>=12)
parameterList.p11.Serialize(&bitStream);
if (parameterList.paramCount>=13)
parameterList.p12.Serialize(&bitStream);
if (parameterList.paramCount>=14)
parameterList.p13.Serialize(&bitStream);
if (parameterList.paramCount>=15)
parameterList.p14.Serialize(&bitStream);
if (memoryConstraint!=0 && tcpInterface)
{
if (tcpInterface->GetOutgoingDataBufferSize(serverAddress)+bitStream.GetNumberOfBytesUsed()>=memoryConstraint)
{
recursiveCheck=false;
return SQLLR_WOULD_EXCEED_MEMORY_CONSTRAINT;
}
}
SendUnified(&bitStream, LOW_PRIORITY, RELIABLE_ORDERED, 1, serverAddress, false);
recursiveCheck=false;
return SQLLR_OK;
}
示例15: 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;
}