Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[TUTORIAL] Basics of packet creation

Newbie Spellweaver
Joined
Nov 25, 2015
Messages
97
Reaction score
2
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
 
Initiate Mage
Joined
Jan 12, 2018
Messages
4
Reaction score
0
Hello, could you tell me the IDE what u using ?
 
Back
Top