Shadowrun: Awakened 29 September 2011 - Build 871
SraPacket.cpp
Go to the documentation of this file.
00001 #include "SraPacket.h"
00002 #include "SraNetworkShared.h"
00003 #include "LoginPacket.h"
00004 
00005 namespace SraNetwork
00006 {
00011     void SraPacket::Serialize(RakNet::BitStream* target)
00012     {
00013         target->Write<unsigned char>(opCode);
00014     }
00015     
00020     void SraPacket::Deserialize(RakNet::BitStream* source)
00021     {
00022         source->Read<unsigned char>(opCode);
00023     }
00024 
00025     SraPacket* SraPacket::GetPacketFromData(char* dataBuffer)
00026     {
00027         // We only need to check for the first element here
00028         // all the other checks will be made by the corresponding
00029         // derived class.       
00030         if ( dataBuffer == 0 )
00031         {
00032             return 0;
00033         }
00034 
00035         // First, read the opcode:
00036         int opCode = dataBuffer[0];
00037 
00038         // Just to be sure we don't forget to remove the opcode ;)
00039         char* truncBuffer = dataBuffer + 1;
00040 
00041         // Now find the correct class for this code:
00042         // TODO: Create a more elegant solution with a ptr list 
00043         SraPacket* packet = 0;
00044         switch (opCode)
00045         {
00046             case ID_LOGIN_REQ :
00047                 packet = new LoginPacket(); 
00048                 //packet->Deserialize(truncBuffer);
00049                 break;
00050             case ID_LOGIN_REP :
00051                 break;
00052             case ID_QUIT :
00053                 break;
00054             case ID_GET_SRVLIST :
00055                 break;
00056             case ID_CONNECT_TO_SRV :
00057                 break;
00058             case ID_GET_CLIENT_CHARS :
00059                 break;
00060             case ID_CREATE_CHAR :
00061                 break;
00062             case ID_CREATE_CHAR_REP :
00063                 break;
00064             case ID_CHAT_MSG_REQUEST_PENDING :
00065                 break;
00066             case ID_CHAT_CHANNEL_REGISTER :
00067                 break;
00068             case ID_CHAT_CHANNEL_UNREGISTER :
00069                 break;
00070             case ID_IAM_ALIVE :
00071                 break;
00072         }
00073         
00074         return packet;
00075     }
00076 }

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net