示例#1
0
void PGameServer::Update()
{
  if ( ServerSock->newConnection() )
  {
    int clid = Server->NewClient();
    if ( clid != -1 )
    {
      Console->Print( GREEN, BLACK, "[Info] Gameserver: client [%i] connected", clid );
      PClient *Client = Server->GetClient( clid );
      if ( Client->getTCPConn() ) Console->Print( RED, BLACK, "WARNING: Client %d : TCP Socket NOT NULL before allocation.", Client->GetID() );
      ConnectionTCP* tcpConn = ServerSock->getTCPConnection();
      Client->setTCPConnection( tcpConn );

      //ConnectionUDP* udpConn = ServerSock->getUDPConnection();
      //Client->setUDPConnection(udpConn);

      Console->Print( "Client address: %s", Client->GetAddress() );
      ++mNumClients;

      PGameState *state = new PGameState();
      ClientStates.insert( std::make_pair( Client, state ) );
      state->TCP.mState = PGameState::TCP::GS_CONNECTED;

      // add the new connected client to the global clientmanager for further use in chat, etc...
      ClientManager->addClientToList( Client );
    }
    else
    {
      Console->Print( YELLOW, BLACK, "[Notice] Gameserver: Client connection refused (server full?)" );
    }
  }

  /*** temp check ***/
  for ( PClientMap::iterator it = ClientManager->getClientListBegin(); it != ClientManager->getClientListEnd(); it++ )
  {
    if ( !it->second )
    {
      Console->Print( RED, BLACK, "PANIC: NULL Client found in ClientManager Clients Map." );
    }
  }
  /*** end temp check ***/

  for ( GameStateMap::iterator i = ClientStates.begin(); i != ClientStates.end(); )
  {
    PClient *Client = i->first;
    PGameState *State = i->second;
    // node gets erased in FinalizeClient, increment iterator now
    ++i;
    if ( !ProcessClient( Client, State ) )
      FinalizeClient( Client, State );
  }
}
示例#2
0
void PPatchServer::Update()
{
    //ServerSock->update();

	if(ServerSock->newConnection())
	{
		int clid = Server->NewClient();
		if(clid!=-1)
		{
			Console->Print(GREEN, BLACK, "Patchserver: client [%i] connected", clid);
			PClient *Client = Server->GetClient(clid);

			ConnectionTCP* tcpConn = ServerSock->getTCPConnection();
			Client->setTCPConnection(tcpConn);

			Console->Print("Client address: %s", Client->GetAddress());
			//++mNumClients;

			PPatchState *state = new PPatchState();
			ClientStates.insert(std::make_pair(Client, state));
			state->mState = PPatchState::PS_CONNECTED;
		} else
		{
			Console->Print("Patchserver: Client connection refused (server full?)");
		}
	}

	for(PatchStateMap::iterator i=ClientStates.begin(); i!=ClientStates.end();)
	{
		PClient *Client = i->first;
		PPatchState *State = i->second;
		// node gets erased in FinalizeClient, increment iterator now
		++i;
		if(!ProcessClient(Client, State))
		{
			FinalizeClient(Client, State);
		}
	}
}