예제 #1
0
bool PPatchServer::ProcessClient(PClient *Client, PPatchState *State)
{
	static const u8 HANDSHAKE0A[6]={0xfe, 0x03, 0x00, 0x80, 0x03, 0x6b};

	if(!State)
	{
		PatchStateMap::iterator node = ClientStates.find(Client);
		if(node == ClientStates.end())
			return false;

		State = node->second;
	}

	ConnectionTCP *Socket = Client->getTCPConn();

	if(State->mWaitSend && Socket->getSendBufferSize()==0)
		return false;

	if(State->mState==PPatchState::PS_CONNECTED)
	{
	    Console->Print("Sending Handshake 0A");
		Socket->write(HANDSHAKE0A, sizeof(HANDSHAKE0A));
		//short unsigned int packet = (short unsigned int) HANDSHAKE0A;
		//Socket->write(htons(packet));
		State->mState = PPatchState::PS_HANDSHAKE0;
		Socket->flushSendBuffer();
	}

	int PacketSize=0;
	const u8 *Packet = Socket->read(&PacketSize);
	if(PacketSize > 0)
	{
		switch(State->mState)
		{
			case PPatchState::PS_HANDSHAKE1 :
			case PPatchState::PS_HANDSHAKE0 :
                Console->Print("Handling Handshake 0 and 1");
				return HandleHandshake(Client, State, Packet, PacketSize);

			case PPatchState::PS_VERSIONREQUEST :
                Console->Print("Handling Client Versionsrequest");
				return HandleVersionRequest(Client, State, Packet, PacketSize);

			case PPatchState::PS_GETPATCHORFILE :
			case PPatchState::PS_SENDPATCH :
			case PPatchState::PS_SENDFILE :
                Console->Print("Getpatchforfile, sendpatch, sendfile");
				return HandleFileRequests(Client, State, Packet, PacketSize);
			default:
				break;
		}
	}
	return true;
}
예제 #2
0
bool PGameServer::ProcessClient( PClient *Client, PGameState *State )
{
  static const u8 HANDSHAKE0A[6] = {0xfe, 0x03, 0x00, 0x80, 0x01, 0x66};

  if ( !State )
  {
    GameStateMap::iterator node = ClientStates.find( Client );
    if ( node == ClientStates.end() )
      return ( false );

    State = node->second;
  }

  ConnectionTCP *Socket = Client->getTCPConn();
  if ( !Socket ) Console->Print( RED, BLACK, "PANIC: Client %d : TCP Socket is NULL !!!", Client->GetID() );
  if ( State->TCP.mWaitSend && Socket->getSendBufferSize() == 0 )
    return ( false );

  if ( State->TCP.mState == PGameState::TCP::GS_CONNECTED )
  {
    Socket->write( HANDSHAKE0A, 6 );
    State->TCP.mState = PGameState::TCP::GS_HANDSHAKE0;
  }

  if ( State->TCP.mState == PGameState::TCP::GS_INGAME )
  {
    return ( HandleGame( Client, State ) );
  }
  else
  {
    int PacketSize = 0;
    const u8 *Packet = Socket->read( &PacketSize );

    if ( PacketSize > 0 )
    {
      switch ( State->TCP.mState )
      {
        case PGameState::TCP::GS_HANDSHAKE0:
          return ( HandleHandshake( State, Packet, PacketSize ) );

        case PGameState::TCP::GS_AUTHENTICATE:
          return ( HandleAuthenticate( Client, State, Packet, PacketSize ) );

        case PGameState::TCP::GS_GAMEDATA:
          return ( HandleGameData( Client, State, Packet ) );

        case PGameState::TCP::GS_REQUESTCHARS:
          return ( HandleRequestChars( Client, State, Packet ) );

        case PGameState::TCP::GS_CHARLIST:
          return ( HandleCharList( Client, State, Packet, PacketSize ) );

        case PGameState::TCP::GS_GETSTATUS:
          return ( HandleGetStatus( Client, State, Packet ) );

        case PGameState::TCP::GS_GAMEINFO:
          return ( HandleGameInfo( Client, State, Packet ) );
        default:
          break;
      }
    }
  }

  return ( true );
}