本文整理汇总了C++中NetClient::GetID方法的典型用法代码示例。如果您正苦于以下问题:C++ NetClient::GetID方法的具体用法?C++ NetClient::GetID怎么用?C++ NetClient::GetID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetClient
的用法示例。
在下文中一共展示了NetClient::GetID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ServerUpdate
//--------------------------------------
void ServerUpdate( float dt )
{
NetClient client;
uint32 commands_in;
uint32 commands_out;
Player* player;
Bullet* b;
// Advance time
gClock->AdvanceTime( dt );
// Update players
UpdatePlayers( gPlayers, dt );
// Update network
gSession->OnUpdate();
// Check packets
while ( gServer.IsDataReady() )
{
// Get next packet
gServer.ReceiveData( gReader, client );
// Get player for this client
player = GetPlayerByID( gPlayers, client.GetID() );
// This client didn't connect correctly!
if ( !player )
{
ConsolePrintf( CONSOLE_WARNING, "Server : Unknown client %u\n", client.GetID() );
continue;
}
// Read commands
commands_in = gReader.Read< uint32 >();
commands_out = 0;
// Client id message
if ( commands_in & NC_HELLO )
{
commands_out |= NC_PLAYER_ID;
commands_out |= NC_ADD;
}
// Client name message
if ( commands_in & NC_NAME )
{
gReader.ReadString( player->name, MAX_NAME_LEN );
ConsolePrintf( "Got name msg: %s\n", player->name );
}
// Client position update
if ( commands_in & NC_LOCATION )
{
player->pos = gReader.Read< Vec2f >();
player->rotation = gReader.Read< float >();
// Replicate location message to other clients
gWriter.Write( (uint32) NC_LOCATION );
gWriter.Write( 1 );
gWriter.Write( player->index );
gWriter.Write( player->pos );
gWriter.Write( player->rotation );
for ( int i = 0; i < MAX_PLAYERS; ++i )
{
if ( gPlayers[i].active && i != player->index )
{
gServer.SendData( PacketWriter( gWriter ), gPlayers[i].address );
}
}
gWriter.Clear();
}
// Client requesting to fire
if ( commands_in & NC_FIRE )
{
// ConsolePrintf( "Server : Got fire command from %u\n", client.GetID() );
b = ServerFire( player );
if ( b )
{
// Replicate fire message to other clients
gWriter.Write( (uint32) NC_FIRE );
gWriter.Write( player->index );
gWriter.Write( b->index );
gWriter.Write( b->vel );
for ( int i = 0; i < MAX_PLAYERS; ++i )
{
if ( gPlayers[i].active )
{
gServer.SendData( PacketWriter( gWriter ), gPlayers[i].address );
}
}
gWriter.Clear();
}
}
// Send commands back to client
if ( commands_out )
{
//.........这里部分代码省略.........