virtual void ReceivePacket(cDataPacket* packet, cPeer* peer, size_t channel){
		
		switch(packet->GetID()){
			case(1):// chat message. I assume the chat message is formated correctly. In a real application, you should check the data to ensure it is valid and check to make sure the user is actually loged in before assuming to process the message
				return ProcessChatMessage(packet, peer);
			default:
			std::cout<<"Received a packet that was unrecognized... ignoring"<<std::endl;
		};

	}
	virtual void ReceivePacket(cDataPacket* packet, cPeer* peer, size_t channel){

		// the compiler will generate a jump table once the switch becomes large enough. This is extremly fast . . .
		switch(packet->GetID()){
			case(0):// login packet
				return ProcessLoginRequest(packet, peer);
			case(1):// chat message. I assume the chat message is formated correctly. In a real application, you should check the data to ensure it is valid and check to make sure the user is actually loged in before assuming to process the message
				return ProcessChatMessage(packet, peer);
			default:
				std::cout<<"packet type was unrecognized... ignoring"<<std::endl;
		};
	}
예제 #3
0
void wxMainFrame::ProcessMessage(wxString msg)
{
  wxStringTokenizer msgtok;
  wxString tok;

  msgtok=wxStringTokenizer(msg);
  if (msgtok.HasMoreTokens()==FALSE)
  {
    ::wxLogFatalError(_("Error en la respuesta del servidor."));
    return;
  }
  tok=msgtok.GetNextToken();
  // MESSAGE CODES WE CAN RECEIVE IN NEUTRAL MODE
  if (tok==_T("CE"))
  {
    ProcessChatEnter(msg);
  }
  else if (tok==_T("EE"))
  {
    ProcessDeckEdit(msg);
  }
  // MESSAGE CODES WE CAN RECEIVE IN CHAT MODE
  else if (tok==_T("GS"))
  {
    ProcessGameStart(msg);
  }
  else if (tok==_T("CX"))
  {
    ProcessChatExit(msg);
  }
  else if (tok==_T("CM"))
  {
    ProcessChatMessage(msg);
  }
  else if (tok==_T("DH"))
  {
    ProcessDuelChallenged(msg);
  }
  else if (tok==_T("DC"))
  {
    ProcessDuelCancelled(msg);
  }
  else if (tok==_T("CU"))
  {
    ProcessChatUser(msg);
  }
  // MESSAGE CODES WE CAN RECEIVE IN DECK MODE
  else if (tok==_T("EL"))
  {
    ProcessDeckList(msg);
  }
  else if (tok==_T("ED"))
  {
    ProcessDeckDescribe(msg);
  }
  // THIS COMMAND IS NOT GOING TO BE IMPLEMENTED
  // USERS MUST HAVE A FRESH COPY OF CARDS ON DISK
/*
  else if (tok==_T("EC"))
  {
    ProcessDeckCard(msg);
  }
*/
  else if (tok==_T("EN"))
  {
    ProcessDeckNew(msg);
  }
  else if (tok==_T("EM"))
  {
    ProcessDeckMove(msg);
  }
  else if (tok==_T("EK"))
  {
    ProcessDeckClear(msg);
  }
  else if (tok==_T("ER"))
  {
    ProcessDeckRename(msg);
  }
  else if (tok==_T("EA"))
  {
    ProcessDeckActive(msg);
  }
  else if (tok==_T("EG"))
  {
    ProcessDeckGet(msg);
  }
  else if (tok==_T("EX"))
  {
    ProcessDeckExit(msg);
  }
  // MESSAGE CODES WE CAN RECEIVE IN DUEL MODE
  else if (tok==_T("GZ"))
  {
    ProcessGameFinish(msg);
  }
  else if (tok==_T("GX"))
  {
    ProcessGameExit(msg);
  }
  else if (tok==_T("GI"))
  {
    ProcessGameInfo(msg);
  }
  else if (tok==_T("GF"))
  {
    ProcessGamePhase(msg);
  }
  else if (tok==_T("GC"))
  {
    ProcessGameCard(msg);
  }
  else if (tok==_T("GT"))
  {
    ProcessGameText(msg);
  }
  else if (tok==_T("GE"))
  {
    ProcessGameSelect(msg);
  }
  else if (tok==_T("GU"))
  {
    ProcessGameUse(msg);
  }
  else
  {
    ProcessUnknownMessage(msg);
  }
}