[TUTORIAL] Basics of packet creation

Results 1 to 3 of 3
  1. #1
    Member juunr95 is offline
    MemberRank
    Nov 2015 Join Date
    97Posts

    [TUTORIAL] Basics of packet creation


    RaGEZONE Recommends

    RaGEZONE Recommends

    Hey guys, how are you ?
    Well, i've been worked for a long time in my client, and there is some peoples saying that is not my client.. as well, i've decided to make a tutorial to explain about how packets works, and how make your own packets. All this to show that i have conhecimento, ok ?

    So, let's started..

    1 - Structs
    Firstly, you need to thing what info you need to send, if this info will or not saved on database, and the info sended back from server
    I'll give an example: When players hit a button, server sends a message for him.
    This functio can be do only client-side, but i'll made Client/Server to show how its works.
    So, the struct will look like that:
    Code:
    struct CQ_Message
    : public CPacket
    {    
               enum {s_nCode = s_nPlayerCode + 31 };   
              void    Set(const char* i_strNick)
              {                int i;        
                    for( i = 0; i < 40; i++ )       
                    {            
                        m_strNick[ i ]    = i_strNick[ i ];            
                        if( m_strNick[ i ] == '\0' ) 
                       {                
                           break;            
                       }        
                     }        
                     m_strNick[ 41 - 1 ] = '\0';
    private:               
                   char  m_strNick[40];
    };
    This code can be placed in any .h file inside Lib_Packets/Service

    2 - Function
    Here we need to create a func in client, that will send the packet to our server.
    In this case, we will use this functions : CNetwork::EnviarMsg(int nUserNumero)
    So, go to Network.h and put this inside class CNetwork:

    Code:
     
    void                EnviarMgs(const char* lpszNick)
    and this inside typedef struct _tagPACKET :
    Code:
     
               __P_PR::CQ_Message CS_Mensagem;
    and in Network.cpp , put this in any place:
    Code:
     void               CNetwork::EnviarMsg(const char* lpszNick)
    {
        m_Packets.CS_Mensagem.Set(lpszNick);
        SendPacket( &m_Packets.CS_Mensagem);
    }
    still in network.cpp find for SetPacketValue, and inside this function add:
    Code:
       
    m_Packets.CS_Mensagem.SetCommand( m_Packets.CS_Mensagem.s_nCode);    m_Packets.CS_Mensagem..SetLength( sizeof(m_Packets.CS_Mensagem.) );
    Att: YOU NEED TO MAKE ALL THIS STEPS TO YOUR PACKET WORKS. IF YOU MISS ANY PART PACKET WILL NOT WORK.
    With all that ready, you just need to call the g_Network.EnviarMsg(g_GameDoc.GetUserNick()) in your button.

    Our client side is ready.. In next tutorial we will made server side. Later


  2. #2
    Registered sa2017 is offline
    MemberRank
    Jul 2017 Join Date
    9Posts

    Re: [TUTORIAL] Basics of packet creation

    very nice juunr95

  3. #3
    Newbie vyda is offline
    MemberRank
    Jan 2018 Join Date
    4Posts

    Re: [TUTORIAL] Basics of packet creation

    Hello, could you tell me the IDE what u using ?




Advertisement