1

Topic: Client -> server

Hi!
Its again me

How to send variable from client and receive it by server?
I wrote in gameclient.cpp
::OnNewSnapshot()

CMsgPacker Msg(123);
Msg.AddInt(1);
Client()->SendMsg(&Msg, MSGFLAG_VITAL);

And gamecontext.cpp

else if(MsgID == 123)
{     
     int w= pUnpacker->GetInt();

     if (pUnpacker->Error())
          pPlayer->m_MyVar= false;
     else if(w)
          pPlayer->m_MyVar= true;
     else
          pPlayer->m_MyVar = false;
}

It doesnt work. Im newbie with Client -> Server Msgs, pls explain in detail smile

2

Re: Client -> server

My english its too bad for explain... sry :\

BUT... i can tell you where you need touch (ouch!)

First, need use BAM (for this stuff exists it big_smile)
Add you messages in:

datasrc/network.py

Ok! now teeworlds source knows your intentions ¬¬
The next step is send the message from client to server... bam generate for you a 'CNetMsg_*' struct (if you want give it a couple of euros to it). Whit this you have all that you need:

CNetMsg_<Your Message> Msg;
Msg.<Attribute A> = <Data For Attribute A>;
Msg.<Attribute B> = <Data For Attribute B>;

Client()->SendPackMsg(&Msg, MSGFLAG_VITAL);

Available Flags:

MSGFLAG_VITAL  -> If necessary, forwards packet
MSGFLAG_FLUSH -> Send the stack of packets
MSGFLAG_NORECORD -> Server not record it (For Demos)
MSGFLAG_RECORD -> Record message in client side (For Demos)
MSGFLAG_NOSEND -> The package is not actually sent (Idk why exists this.. perhaps testing stuff? Or rare stuff with client demos...)

And in server side you need add a control for you message in the file 'src/game/server/gamecontext.cpp'... search the method 'OnMessage'.. see how it works wink

And that its all!

3

Re: Client -> server

Thanks!
I will try smile