06-29-2022, 12:44 AM
2 hours ago, Andrein95 said:
Wich was the problem in the code above?
2 things...
1) I were trying to send an unregistered package.
2) I did not indicate at any time the size of the package.
This is an example of sending a previously defined packet (both server and client) from the server to the client
CNetMsg::SP rmsg(new CNetMsg);
MsgMessageBox(rmsg, MSG_EX_MSGBOX_INVEN_FULL);
SEND_Q(rmsg, ch->m_desc);
As long as the package is registered on the server and client, there would be no problem.
In case of sending values such as item id or some type of data that is not a simple client server trigger or vice versa, the easiest way is to define a structure (Table or array as you prefer to call it), fill it with information, calculate the size and finally send the package...
Example using pTypeBase (Server Side):
// Create Simple array with pTypeBase (There's more to it than just pTypeBase, you can see them defined next to pTypeBase)
struct MyArray : public pTypeBase{
int lastDate;
}
///////////////////////////////////////////////////////////////
CNetMsg::SP rmsg(new CNetMsg);
MyArray* packet = reinterpret_cast<MyArray*>(rmsg->m_buf);
// pTypeBase Requires 2 minimum values (type & subType), then you can add whatever you want.
// Logically you must declare these packages
packet->type = MSG_UPDATE_DATA_FOR_CLIENT; // In my case i take advantage of this previously defined message.
packet->subType = MSG_SUB_UPDATE_DAILYREWARD; // And I define this to trigger my custom action on the client side.
// Finally our data, in this case an int type without more
packet->lastDate = last_date;
// Indicate the size of the package/message to be sent
rmsg->setSize(sizeof(MyArray));
// And push it
SEND_Q(rmsg, ch->m_desc);
Cliente Side:
As I said take advantage of 'MSG_UPDATE_DATA_FOR_CLIENT' so i made usage of 'REG_PACKET_R' to associate the packages 'MSG_UPDATE_DATA_FOR_CLIENT' & 'MSG_SUB_UPDATE_DAILYREWARD' to a function that ultimately executes what i want
REG_PACKET_R(MSG_UPDATE_DATA_FOR_CLIENT, MSG_SUB_UPDATE_DAILYREWARD, updateDailyReward);
Example:
void CSessionState::updateDailyReward(CNetworkMessage* istr){
CUIManager* pUIManager = CUIManager::getSingleton();
DailyRewardListRes* pPack = reinterpret_cast<DailyRewardListRes*>(istr->GetBuffer());
switch(pPack->subType){
case MSG_SUB_UPDATE_DAILYREWARD:
pUIManager->GetDailyReward()->ReceiveList(istr);
break;
default:
CUIMsgBox_Info MsgBoxInfo;
MsgBoxInfo.SetMsgBoxInfo(_s("Daily Reward System"), UMBS_OK, UI_NONE, MSGCMD_NULL);
MsgBoxInfo.AddString(_s("MSG FROM SERVER RECEIVED: unknown"));
pUIManager->CreateMessageBox(MsgBoxInfo);
break;
}
}
final results xd
p.s: this is just a hobby, sorry if I use wrong words or if my explanations lack technicalities

