diff --git a/source/src/client.cpp b/source/src/client.cpp index 754f54ba..eedf5cab 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -113,7 +113,7 @@ void connects(char *servername, char *password) if(clienthost) { - enet_host_connect(clienthost, &address, 4); + enet_host_connect(clienthost, &address, 3); enet_host_flush(clienthost); connecting = lastmillis; connattempts = 0; @@ -290,6 +290,16 @@ void c2sinfo(dynent *d) // send update to the server sendstring(clientpassword, p); clientpassword[0] = 0; }; + if(!c2sinit) // tell other clients who I am + { + packet->flags = ENET_PACKET_FLAG_RELIABLE; + c2sinit = true; + putint(p, SV_INITC2S); + sendstring(player1->name, p); + sendstring(player1->team, p); + putint(p, player1->skin); + putint(p, player1->lifesequence); + }; if(gun_changed) { packet->flags = ENET_PACKET_FLAG_RELIABLE; @@ -306,16 +316,6 @@ void c2sinfo(dynent *d) // send update to the server senditemstoserver = false; serveriteminitdone = true; }; - if(!c2sinit) // tell other clients who I am - { - packet->flags = ENET_PACKET_FLAG_RELIABLE; - c2sinit = true; - putint(p, SV_INITC2S); - sendstring(player1->name, p); - sendstring(player1->team, p); - putint(p, player1->skin); - putint(p, player1->lifesequence); - }; int i = 0; while(i < messages.length()) // send messages collected during the previous frames { diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 4c092c7c..7dc5107b 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -123,6 +123,14 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) break; }; + case SV_CLIENT: + { + int cn = getint(p), len = getuint(p); + ucharbuf q = p.subbuf(len); + parsemessages(cn, getclient(cn), q); + break; + }; + case SV_SOUND: if(!d) return; playsound(getint(p), &d->o); @@ -476,20 +484,8 @@ void localservertoclient(int chan, uchar *buf, int len) // processes any updat switch(chan) { case 0: parsepositions(p); break; - case 1: parsemessages(-1, NULL, p); break; - case 2: - while(p.remaining()) - { - int cn = p.get(); - playerent *d = getclient(cn); - int len = p.get(); - len += p.get()<<8; - ucharbuf q(&p.buf[p.len], min(len, p.maxlen-p.len)); - parsemessages(cn, d, q); - p.len += min(len, p.maxlen-p.len); - }; - break; - case 3: parsemessages(-1, NULL, p); break; + case 1: + case 2: parsemessages(-1, NULL, p); break; case 42: // player1 demo data only extern int democlientnum; parsemessages(democlientnum, getclient(democlientnum), p); diff --git a/source/src/protocol.h b/source/src/protocol.h index 1ec4c8d0..b1688d87 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -3,8 +3,8 @@ #define MAXTRANS 5000 // max amount of data to swallow in 1 go #define CUBE_SERVER_PORT 28763 #define CUBE_SERVINFO_PORT 28764 -#define PROTOCOL_VERSION 1123 // bump when protocol changes -#define SAVEGAMEVERSION 1006 // bump if dynent/netprotocol changes or any other savegame/demo data bumped from 5 +#define PROTOCOL_VERSION 1124 // bump when protocol changes +#define SAVEGAMEVERSION 1007 // bump if dynent/netprotocol changes or any other savegame/demo data bumped from 5 // network messages codes, c2s, c2c, s2c enum @@ -20,7 +20,7 @@ enum SV_FLAGPICKUP, SV_FLAGDROP, SV_FLAGRETURN, SV_FLAGSCORE, SV_FLAGINFO, SV_FLAGS, //EDIT: AH SV_GETMASTER, SV_MASTERCMD, SV_PWD, - SV_EXT, + SV_CLIENT, }; enum { MCMD_KICK = 0, MCMD_BAN, MCMD_REMBANS }; diff --git a/source/src/savegamedemo.cpp b/source/src/savegamedemo.cpp index 306b596d..9e1d3f64 100644 --- a/source/src/savegamedemo.cpp +++ b/source/src/savegamedemo.cpp @@ -212,7 +212,7 @@ void startdemo() demoplayback = true; starttime = lastmillis; conoutf("now playing demo"); - dynent *d = getclient(democlientnum); + dynent *d = newclient(democlientnum); ASSERT(d); *d = *player1; readdemotime(); diff --git a/source/src/server.cpp b/source/src/server.cpp index b83818ce..5204cecc 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -120,9 +120,11 @@ bool buildworldstate() else { c.messageoffset = ws.messages.length(); - ws.messages.add(c.clientnum); - ws.messages.add(c.messages.length()&0xFF); - ws.messages.add(c.messages.length()>>8); + ucharbuf p = ws.messages.reserve(16); + putint(p, SV_CLIENT); + putint(p, c.clientnum); + putuint(p, c.messages.length()); + ws.messages.addbuf(p); loopvj(c.messages) ws.messages.add(c.messages[j]); }; }; @@ -151,7 +153,7 @@ bool buildworldstate() packet = enet_packet_create(&ws.messages[c.messageoffset<0 ? 0 : c.messageoffset+3+c.messages.length()], c.messageoffset<0 ? msize : msize-3-c.messages.length(), (reliablemessages ? ENET_PACKET_FLAG_RELIABLE : 0) | ENET_PACKET_FLAG_NO_ALLOCATE); - sendpacket(c.clientnum, 2, packet); + sendpacket(c.clientnum, 1, packet); if(!packet->referenceCount) enet_packet_destroy(packet); else { ++ws.uses; packet->freeCallback = cleanworldstate; }; }; @@ -666,7 +668,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 case SV_RECVMAP: { ENetPacket *mappacket = recvmap(sender); - if(mappacket) sendpacket(sender, 3, mappacket); + if(mappacket) sendpacket(sender, 2, mappacket); else sendservmsg("no map to get", sender); break; }; diff --git a/source/src/serverutil.cpp b/source/src/serverutil.cpp index 20bcdc81..e500e0c9 100644 --- a/source/src/serverutil.cpp +++ b/source/src/serverutil.cpp @@ -96,7 +96,7 @@ char msgsizesl[] = // size inclusive message token, 0 for variable SV_FLAGPICKUP, 2, SV_FLAGDROP, 2, SV_FLAGRETURN, 2, SV_FLAGSCORE, 2, SV_FLAGINFO, 0, SV_FLAGS, 2, // EDIT: AH SV_GETMASTER, 0, SV_MASTERCMD, 3, SV_PWD, 0, - SV_EXT, 0, + SV_CLIENT, 0, -1 }; diff --git a/source/src/tools.h b/source/src/tools.h index ffac7b13..2e99e61e 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -114,6 +114,65 @@ extern uint randomMT(void); #define loopvk(v) if(false) {} else for(int k = 0; k<(v).length(); k++) #define loopvrev(v) if(false) {} else for(int i = (v).length()-1; i>=0; i--) +template +struct databuf +{ + enum + { + OVERREAD = 1<<0, + OVERWROTE = 1<<1 + }; + + T *buf; + int len, maxlen; + uchar flags; + + template + databuf(T *buf, U maxlen) : buf(buf), len(0), maxlen((int)maxlen), flags(0) {}; + + const T &get() + { + static T overreadval; + if(len charbuf; +typedef databuf ucharbuf; + template struct vector { T *buf; @@ -202,6 +261,17 @@ template struct vector buf = (T *)_realloc(buf, olen*sizeof(T), (alen *= 2)*sizeof(T)); }; + ucharbuf reserve(int sz) + { + while(alen-ulen(&buf[ulen], sz); + }; + + void addbuf(const databuf &p) + { + ulen += p.length(); + }; + void remove(int i, int n) { for(int p = i+n; p -struct databuf -{ - enum - { - OVERREAD = 1<<0, - OVERWROTE = 1<<1 - }; - - T *buf; - int len, maxlen; - uchar flags; - - template - databuf(T *buf, U maxlen) : buf(buf), len(0), maxlen((int)maxlen), flags(0) {}; - - const T &get() - { - static T overreadval; - if(len charbuf; -typedef databuf ucharbuf; - #endif