drop some of the spawn code, ping code
parent
afba5940ef
commit
5639030b5f
|
@ -42,8 +42,6 @@ namespace game
|
||||||
cmode = NULL;
|
cmode = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastping = 0;
|
|
||||||
|
|
||||||
bool connected = false, remote = false;
|
bool connected = false, remote = false;
|
||||||
int sessionid = 0;
|
int sessionid = 0;
|
||||||
string servdesc = "", servauth = "";
|
string servdesc = "", servauth = "";
|
||||||
|
@ -229,12 +227,6 @@ namespace game
|
||||||
messagereliable = false;
|
messagereliable = false;
|
||||||
messagecn = -1;
|
messagecn = -1;
|
||||||
}
|
}
|
||||||
if(totalmillis-lastping>250)
|
|
||||||
{
|
|
||||||
putint(p, N_PING);
|
|
||||||
putint(p, totalmillis);
|
|
||||||
lastping = totalmillis;
|
|
||||||
}
|
|
||||||
sendclientpacket(p.finalize(), 1);
|
sendclientpacket(p.finalize(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,27 +300,6 @@ namespace game
|
||||||
changemapserv(text, 0);
|
changemapserv(text, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case N_INITCLIENT: // another client either connected or changed name/team
|
|
||||||
{
|
|
||||||
int cn = getint(p);
|
|
||||||
gameent *d = newclient(cn);
|
|
||||||
if(!d)
|
|
||||||
{
|
|
||||||
getstring(text, p);
|
|
||||||
getstring(text, p);
|
|
||||||
getint(p);
|
|
||||||
getint(p);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
getstring(text, p);
|
|
||||||
filtertext(text, text, false, false, MAXNAMELEN);
|
|
||||||
if(!text[0]) copystring(text, "unnamed");
|
|
||||||
copystring(d->name, text, MAXNAMELEN+1);
|
|
||||||
d->playermodel = 0;
|
|
||||||
d->playercolor = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case N_CDIS:
|
case N_CDIS:
|
||||||
clientdisconnected(getint(p));
|
clientdisconnected(getint(p));
|
||||||
break;
|
break;
|
||||||
|
@ -347,51 +318,6 @@ namespace game
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case N_SPAWNSTATE:
|
|
||||||
{
|
|
||||||
int scn = getint(p);
|
|
||||||
gameent *s = getclient(scn);
|
|
||||||
if(!s) { parsestate(NULL, p); break; }
|
|
||||||
if(s==player1)
|
|
||||||
{
|
|
||||||
if(editmode) toggleedit();
|
|
||||||
}
|
|
||||||
s->respawn();
|
|
||||||
parsestate(s, p);
|
|
||||||
s->state = CS_ALIVE;
|
|
||||||
if(cmode) cmode->pickspawn(s);
|
|
||||||
else findplayerspawn(s, -1, 0);
|
|
||||||
if(s == player1)
|
|
||||||
{
|
|
||||||
lasthit = 0;
|
|
||||||
}
|
|
||||||
if(cmode) cmode->respawned(s);
|
|
||||||
checkfollow();
|
|
||||||
addmsg(N_SPAWN, "rci", s, s->lifesequence);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case N_RESUME:
|
|
||||||
{
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
int cn = getint(p);
|
|
||||||
if(p.overread() || cn<0) break;
|
|
||||||
gameent *d = (cn == player1->clientnum ? player1 : newclient(cn));
|
|
||||||
parsestate(d, p, true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case N_PONG:
|
|
||||||
addmsg(N_CLIENTPING, "i", player1->ping = (player1->ping*5+totalmillis-getint(p))/6);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case N_CLIENTPING:
|
|
||||||
if(!d) return;
|
|
||||||
d->ping = getint(p);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case N_NEWMAP:
|
case N_NEWMAP:
|
||||||
{
|
{
|
||||||
int size = getint(p);
|
int size = getint(p);
|
||||||
|
|
|
@ -99,24 +99,20 @@ enum
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
N_CONNECT = 0, N_SERVINFO, N_WELCOME, N_INITCLIENT, N_CDIS,
|
N_CONNECT = 0, N_SERVINFO, N_WELCOME, N_CDIS,
|
||||||
N_TRYSPAWN, N_SPAWNSTATE, N_SPAWN,
|
N_SPAWN,
|
||||||
N_MAPCHANGE,
|
N_MAPCHANGE,
|
||||||
N_PING, N_PONG, N_CLIENTPING,
|
|
||||||
N_NEWMAP,
|
N_NEWMAP,
|
||||||
N_RESUME,
|
|
||||||
N_CLIENT,
|
N_CLIENT,
|
||||||
NUMMSG
|
NUMMSG
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int msgsizes[] = // size inclusive message token, 0 for variable or not-checked sizes
|
static const int msgsizes[] = // size inclusive message token, 0 for variable or not-checked sizes
|
||||||
{
|
{
|
||||||
N_CONNECT, 0, N_SERVINFO, 0, N_WELCOME, 1, N_INITCLIENT, 0, N_CDIS, 2,
|
N_CONNECT, 0, N_SERVINFO, 0, N_WELCOME, 1, N_CDIS, 2,
|
||||||
N_TRYSPAWN, 1, N_SPAWNSTATE, 8, N_SPAWN, 2,
|
N_SPAWN, 2,
|
||||||
N_MAPCHANGE, 0,
|
N_MAPCHANGE, 0,
|
||||||
N_PING, 2, N_PONG, 2, N_CLIENTPING, 2,
|
|
||||||
N_NEWMAP, 2,
|
N_NEWMAP, 2,
|
||||||
N_RESUME, 0,
|
|
||||||
N_CLIENT, 0,
|
N_CLIENT, 0,
|
||||||
-1
|
-1
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,7 +63,6 @@ namespace server
|
||||||
vector<uchar> messages;
|
vector<uchar> messages;
|
||||||
uchar *wsdata;
|
uchar *wsdata;
|
||||||
int wslen;
|
int wslen;
|
||||||
int ping;
|
|
||||||
string clientmap;
|
string clientmap;
|
||||||
bool warned;
|
bool warned;
|
||||||
|
|
||||||
|
@ -89,7 +88,6 @@ namespace server
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
connected = local = false;
|
connected = local = false;
|
||||||
messages.setsize(0);
|
messages.setsize(0);
|
||||||
ping = 0;
|
|
||||||
mapchange();
|
mapchange();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -305,15 +303,6 @@ namespace server
|
||||||
gs.lifesequence = (gs.lifesequence + 1)&0x7F;
|
gs.lifesequence = (gs.lifesequence + 1)&0x7F;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendspawn(clientinfo *ci)
|
|
||||||
{
|
|
||||||
servstate &gs = ci->state;
|
|
||||||
spawnstate(ci);
|
|
||||||
sendf(ci->ownernum, 1, "rii4", N_SPAWNSTATE, ci->clientnum, gs.lifesequence,
|
|
||||||
1, 1);
|
|
||||||
gs.lastspawn = gamemillis;
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendwelcome(clientinfo *ci)
|
void sendwelcome(clientinfo *ci)
|
||||||
{
|
{
|
||||||
packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
|
packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
|
||||||
|
@ -321,24 +310,6 @@ namespace server
|
||||||
sendpacket(ci->clientnum, chan, p.finalize());
|
sendpacket(ci->clientnum, chan, p.finalize());
|
||||||
}
|
}
|
||||||
|
|
||||||
void putinitclient(clientinfo *ci, packetbuf &p)
|
|
||||||
{
|
|
||||||
putint(p, N_INITCLIENT);
|
|
||||||
putint(p, ci->clientnum);
|
|
||||||
sendstring(ci->name, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void welcomeinitclient(packetbuf &p, int exclude = -1)
|
|
||||||
{
|
|
||||||
loopv(clients)
|
|
||||||
{
|
|
||||||
clientinfo *ci = clients[i];
|
|
||||||
if(!ci->connected || ci->clientnum == exclude) continue;
|
|
||||||
|
|
||||||
putinitclient(ci, p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasmap(clientinfo *ci)
|
bool hasmap(clientinfo *ci)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -349,30 +320,9 @@ namespace server
|
||||||
putint(p, N_WELCOME);
|
putint(p, N_WELCOME);
|
||||||
putint(p, N_MAPCHANGE);
|
putint(p, N_MAPCHANGE);
|
||||||
sendstring(smapname, p);
|
sendstring(smapname, p);
|
||||||
if(!ci || clients.length()>1)
|
|
||||||
{
|
|
||||||
putint(p, N_RESUME);
|
|
||||||
loopv(clients)
|
|
||||||
{
|
|
||||||
clientinfo *oi = clients[i];
|
|
||||||
if(ci && oi->clientnum==ci->clientnum) continue;
|
|
||||||
putint(p, oi->clientnum);
|
|
||||||
putint(p, oi->state.state);
|
|
||||||
sendstate(oi->state, p);
|
|
||||||
}
|
|
||||||
putint(p, -1);
|
|
||||||
welcomeinitclient(p, ci ? ci->clientnum : -1);
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendinitclient(clientinfo *ci)
|
|
||||||
{
|
|
||||||
packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
|
|
||||||
putinitclient(ci, p);
|
|
||||||
sendpacket(-1, 1, p.finalize(), ci->clientnum);
|
|
||||||
}
|
|
||||||
|
|
||||||
void changemap(const char *s, int mode)
|
void changemap(const char *s, int mode)
|
||||||
{
|
{
|
||||||
gamemillis = 0;
|
gamemillis = 0;
|
||||||
|
@ -494,7 +444,6 @@ namespace server
|
||||||
ci->state.lasttimeplayed = lastmillis;
|
ci->state.lasttimeplayed = lastmillis;
|
||||||
|
|
||||||
sendwelcome(ci);
|
sendwelcome(ci);
|
||||||
sendinitclient(ci);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void parsepacket(int sender, int chan, packetbuf &p) // has to parse exactly each byte of the packet
|
void parsepacket(int sender, int chan, packetbuf &p) // has to parse exactly each byte of the packet
|
||||||
|
@ -519,10 +468,6 @@ namespace server
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case N_PING:
|
|
||||||
getint(p);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
disconnect_client(sender, DISC_MSGERR);
|
disconnect_client(sender, DISC_MSGERR);
|
||||||
return;
|
return;
|
||||||
|
@ -551,11 +496,6 @@ namespace server
|
||||||
int curmsg;
|
int curmsg;
|
||||||
while((curmsg = p.length()) < p.maxlen) switch(type = checktype(getint(p), ci))
|
while((curmsg = p.length()) < p.maxlen) switch(type = checktype(getint(p), ci))
|
||||||
{
|
{
|
||||||
case N_TRYSPAWN:
|
|
||||||
if(!ci || !cq || cq->state.state!=CS_DEAD || cq->state.lastspawn>=0) break;
|
|
||||||
sendspawn(cq);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case N_SPAWN:
|
case N_SPAWN:
|
||||||
{
|
{
|
||||||
int ls = getint(p);
|
int ls = getint(p);
|
||||||
|
@ -570,21 +510,6 @@ namespace server
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case N_PING:
|
|
||||||
sendf(sender, 1, "i2", N_PONG, getint(p));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case N_CLIENTPING:
|
|
||||||
{
|
|
||||||
int ping = getint(p);
|
|
||||||
if(ci)
|
|
||||||
{
|
|
||||||
ci->ping = ping;
|
|
||||||
}
|
|
||||||
QUEUE_MSG;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case N_NEWMAP:
|
case N_NEWMAP:
|
||||||
{
|
{
|
||||||
int size = getint(p);
|
int size = getint(p);
|
||||||
|
|
Loading…
Reference in New Issue