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:
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:
and this inside typedef struct _tagPACKET :
and in Network.cpp , put this in any place:
still in network.cpp find for SetPacketValue, and inside this function add:
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
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)
Code:
__P_PR::CQ_Message CS_Mensagem;
Code:
void CNetwork::EnviarMsg(const char* lpszNick)
{
m_Packets.CS_Mensagem.Set(lpszNick);
SendPacket( &m_Packets.CS_Mensagem);
}
Code:
m_Packets.CS_Mensagem.SetCommand( m_Packets.CS_Mensagem.s_nCode); m_Packets.CS_Mensagem..SetLength( sizeof(m_Packets.CS_Mensagem.) );
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