#1 2016-01-08 17:48:07

gaya
Member

addmsg?

What's the purpose of the addmsg function? Maybe someone can explain to be this signature?

addmsg(N_SWITCHNAME, "rs", player1->name);

Why am i sending an int, and then "rs" and then the player name? Is there a central place where client/server communication takes place, or is it all mixed up?

Offline

#2 2016-01-09 08:33:13

chasester
Member

Re: addmsg?

addmsg is the way the buffer gets created for client/server interactions. Well chase how does this work?

Thanks for asking ;)

Basically you send a long byte data (1 and 0's) to the server (and from the server), this data is not formated, meaning the reciever has no clue what this data is or how it operates. This type of data is called a buffer.

So how does the receiver read this message? Well simple, it assumes that the data the sender put is the same data the receiver is pulling out. So what happens if its not? you get a bad communication error, and you are instantly disconnected from the server (this rarely happens unless you screwed up your code).

So what is addmsg and how does it work.

So first parameter of addmsg is a N_ message type, basically this tells the reciever what kinda of data is being sent. The second parameter is the setup of this message:

  • r - Reliable data    + adds the client number so the receiver knows who sent this data

  • c - unreliable data + adds the client number so the receiver knows who sent this data

  • v - vector (uses all the rest of the data in the buffer so should be defined last)

  • i - int

  • f - float

  • s - string

  • 1-9 - repeat the previous one # times; so i5 is 5 ints but f5i is five floats and one int

3-N parameters are pass in variables following the above formating.

So if i were to create a new N_ message say to environmental damage a player (cuz you cant do that right now).

I would first find the Client N_ enum and find a new fancy name like N_ENVIRO  I would add this in game.h in the two spots (probably at the end cuz why not).

Then I would go to some were in the game.cpp file and add the functionality (like what to do when the functions is called) so something like:

void enviromentaldam(fpsent d, int dam, bool local)
{
       damaged(dam, d, d, local) //from game.cpp  this does the effects, particles and changes the health for us
    if(local) addmsg(N_ENVIRO, "ri" dam); //i'm not 100% on this look at damaged() its pretty simple to follow in there
}

Now that we have done all the cool effects subtracted the damage and told the server, we need a reason to call this function 0.0 How about the player falling too far.

There is a physics trigger that fires when the player falls from a far height (makes a thud instead of a pmp) let's use that to add damage.

 void physicstrigger(...)
{
...
else if(floorlevel<0) { if(d==player1 || d->type!=ENT_PLAYER || ((gameent *)d)->ai)
    {
    msgsound(S_LAND, d); 
//now lets add a check
    if(d->timeinair > 1000) enviromentaldamage((timeinair -1000)*0.01, true);
    }
}

ok now we need to do the server side :)

In void parsepacket() add a new N_ENVIRO parsemessage. Now the best way to set this up (and probably correct way) event called environment event (look at shotevent). Then just do the damage, check the validity of the call, and tell all the clients the new health using sendf(). Then check to see if the damaged player is dead, if so sendf() again to kill the player.

WHy should you use events. LAG, basically a message is received with a "game Time" that they happen then the server determines what order those events should be triggered. Example: if a player is falling with one health, and if he hits the ground he will take 10 damage, but some one shoots a rocket at the ground under him. Does he die form the player or from the ground? Well the server hast to make this call based on the game time, and the position of the rocket/player (maybe even other elements. So setting up this into an event system will help improve accuracy immensely.

If you have further question just ask, Ive done a lot of server/client modding so I understand most of it.

chasester

PS: As always this code is probably super buggy, Hopefully this proves the concept, you will need to do a lil work improving this code. (Also IDR if tesseract has a timeinair variables, if not you should add it to the physent struct as an int, and then increase it in moveplayer.

PSS: Ive  done this environment damage before in sauerbraten so it is fairly easy, But I would add a new gun type called GUN_ENVIROMENT, so you can set a different message if they die from falling or burning or what ever other type of environment damage you want to add.

Last edited by chasester (2016-01-09 09:14:32)

Offline

#3 2016-01-09 19:48:36

gaya
Member

Re: addmsg?

Thanks a lot, dude. Your effort in sharing all this amazing knowledge is priceless for the community.

Last edited by gaya (2016-01-09 19:48:43)

Offline

#4 2016-01-09 19:52:13

chasester
Member

Re: addmsg?

thanx  :)

Offline

Board footer