diff --git a/source/src/client.cpp b/source/src/client.cpp index 0ae294ed..da990e7d 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -240,7 +240,7 @@ void addmsg(int type, const char *fmt, ...) loopi(len) messages.add(buf[i]); } -static int lastupdate = 0, lastping = 0, laststate = -1; +static int lastupdate = 0, lastping = 0; bool senditemstoserver = false; // after a map change, since server doesn't have map data void sendpackettoserv(int chan, ENetPacket *packet) @@ -261,35 +261,32 @@ void c2sinfo(playerent *d) // send update to the server if(d->clientnum<0) return; // we haven't had a welcome message from the server yet if(lastmillis-lastupdate<40) return; // don't update faster than 25fps - bool hasmsg = senditemstoserver || !c2sinit || messages.length() || lastmillis-lastping>250; - // limit updates for dead players to the ping rate of 4fps, as above - if(!hasmsg && laststate==CS_DEAD && player1->state==CS_DEAD) return; - - laststate = player1->state; - - ENetPacket *packet = enet_packet_create(NULL, 100, 0); - ucharbuf q(packet->data, packet->dataLength); - - putint(q, SV_POS); - putint(q, d->clientnum); - putuint(q, (int)(d->o.x*DMF)); // quantize coordinates to 1/16th of a cube, between 1 and 3 bytes - putuint(q, (int)(d->o.y*DMF)); - putuint(q, (int)(d->o.z*DMF)); - putuint(q, (int)d->yaw); - putint(q, (int)d->pitch); - putint(q, (int)d->roll); - putint(q, (int)(d->vel.x*DVELF)); - putint(q, (int)(d->vel.y*DVELF)); - putint(q, (int)(d->vel.z*DVELF)); - // pack rest in 1 int: strafe:2, move:2, onfloor:1, onladder: 1 - putint(q, (d->strafe&3) | ((d->move&3)<<2) | (((int)d->onfloor)<<4) | (((int)d->onladder)<<5) ); - - enet_packet_resize(packet, q.length()); - sendpackettoserv(0, packet); - - if(hasmsg) + if(d->state==CS_ALIVE || d->state==CS_EDITING) { - packet = enet_packet_create (NULL, MAXTRANS, 0); + ENetPacket *packet = enet_packet_create(NULL, 100, 0); + ucharbuf q(packet->data, packet->dataLength); + + putint(q, SV_POS); + putint(q, d->clientnum); + putuint(q, (int)(d->o.x*DMF)); // quantize coordinates to 1/16th of a cube, between 1 and 3 bytes + putuint(q, (int)(d->o.y*DMF)); + putuint(q, (int)(d->o.z*DMF)); + putuint(q, (int)d->yaw); + putint(q, (int)d->pitch); + putint(q, (int)d->roll); + putint(q, (int)(d->vel.x*DVELF)); + putint(q, (int)(d->vel.y*DVELF)); + putint(q, (int)(d->vel.z*DVELF)); + // pack rest in 1 int: strafe:2, move:2, onfloor:1, onladder: 1 + putint(q, (d->strafe&3) | ((d->move&3)<<2) | (((int)d->onfloor)<<4) | (((int)d->onladder)<<5) ); + + enet_packet_resize(packet, q.length()); + sendpackettoserv(0, packet); + } + + if(senditemstoserver || !c2sinit || messages.length() || lastmillis-lastping>250) + { + ENetPacket *packet = enet_packet_create (NULL, MAXTRANS, 0); ucharbuf p(packet->data, packet->dataLength); if(!c2sinit) // tell other clients who I am @@ -332,6 +329,7 @@ void c2sinfo(playerent *d) // send update to the server sendpackettoserv(1, packet); } } + if(clienthost) enet_host_flush(clienthost); lastupdate = lastmillis; } diff --git a/source/src/server.cpp b/source/src/server.cpp index 4529696a..3efd5a0e 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -723,6 +723,7 @@ void serverdamage(client *target, client *actor, int damage, int gun, bool gib, if(target!=actor && !isteam(target->team, actor->team)) actor->state.frags += gib ? 2 : 1; else actor->state.frags--; sendf(-1, 1, "ri4", gib ? SV_GIBDIED : SV_DIED, target->clientnum, actor->clientnum, actor->state.frags); + target->position.setsizenodelete(0); ts.state = CS_DEAD; ts.lastdeath = gamemillis; // don't issue respawn yet until DEATHMILLIS has elapsed @@ -814,6 +815,7 @@ void processevent(client *c, suicideevent &e) if(gs.state!=CS_ALIVE) return; gs.frags--; sendf(-1, 1, "ri4", SV_DIED, c->clientnum, c->clientnum, gs.frags); + c->position.setsizenodelete(0); gs.state = CS_DEAD; gs.respawn(); } @@ -1545,7 +1547,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 loopi(3) clients[cn]->state.o[i] = getuint(p)/DMF; getuint(p); loopi(6) getint(p); - if(cl->type==ST_TCPIP) + if(cl->type==ST_TCPIP && (cl->state.state==CS_ALIVE || cl->state.state==CS_EDITING)) { cl->position.setsizenodelete(0); while(curmsgposition.add(p.buf[curmsg++]);