fix userid setup

This commit is contained in:
Bill Currie 2003-03-04 16:00:57 +00:00
parent e131ec5885
commit 2310e94df8
2 changed files with 67 additions and 45 deletions

View file

@ -751,7 +751,9 @@ SV_AllocClient (int spectator, int server)
for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) {
if (cl->state == cs_free) { if (cl->state == cs_free) {
svs.num_clients++; svs.num_clients++;
memset (cl, 0, sizeof (client_t));
cl->userid = userid++; // so every client gets a unique id cl->userid = userid++; // so every client gets a unique id
cl->edict = EDICT_NUM (&sv_pr_state, (cl - svs.clients) + 1);
return cl; return cl;
} }
} }
@ -770,9 +772,7 @@ SVC_DirectConnect (void)
info_t *userinfo = 0; info_t *userinfo = 0;
const char *s; const char *s;
client_t *cl, *newcl; client_t *cl, *newcl;
client_t temp; int challenge, qport, version, i;
edict_t *ent;
int challenge, edictnum, qport, version, i;
netadr_t adr; netadr_t adr;
qboolean spectator; qboolean spectator;
@ -866,11 +866,6 @@ SVC_DirectConnect (void)
adr = net_from; adr = net_from;
newcl = &temp;
memset (newcl, 0, sizeof (client_t));
newcl->userinfo = userinfo;
// if there is already a slot for this ip, drop it // if there is already a slot for this ip, drop it
for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) {
if (cl->state < cs_zombie) if (cl->state < cs_zombie)
@ -893,10 +888,10 @@ SVC_DirectConnect (void)
Netchan_OutOfBandPrint (adr, "%c\nserver is full\n\n", A2C_PRINT); Netchan_OutOfBandPrint (adr, "%c\nserver is full\n\n", A2C_PRINT);
return; return;
} }
newcl->userinfo = userinfo;
// build a new connection // build a new connection
// accept the new client // accept the new client
// this is the only place a client_t is ever initialized // this is the only place a client_t is ever initialized
*newcl = temp;
for (i = 0; i < UPDATE_BACKUP; i++) { for (i = 0; i < UPDATE_BACKUP; i++) {
newcl->frames[i].entities.entities = cl_entities[newcl-svs.clients][i]; newcl->frames[i].entities.entities = cl_entities[newcl-svs.clients][i];
memset (cl_entities[newcl-svs.clients][i], 0, memset (cl_entities[newcl-svs.clients][i], 0,
@ -905,8 +900,6 @@ SVC_DirectConnect (void)
Netchan_OutOfBandPrint (adr, "%c", S2C_CONNECTION); Netchan_OutOfBandPrint (adr, "%c", S2C_CONNECTION);
edictnum = (newcl - svs.clients) + 1;
Netchan_Setup (&newcl->netchan, adr, qport); Netchan_Setup (&newcl->netchan, adr, qport);
newcl->state = cs_connected; newcl->state = cs_connected;
@ -920,9 +913,6 @@ SVC_DirectConnect (void)
// spectator mode can ONLY be set at join time // spectator mode can ONLY be set at join time
newcl->spectator = spectator; newcl->spectator = spectator;
ent = EDICT_NUM (&sv_pr_state, edictnum);
newcl->edict = ent;
// parse some info from the info strings // parse some info from the info strings
SV_ExtractFromUserinfo (newcl); SV_ExtractFromUserinfo (newcl);

View file

@ -237,8 +237,6 @@ PF_sprint (progs_t *pr)
entnum = P_EDICTNUM (pr, 0); entnum = P_EDICTNUM (pr, 0);
level = P_FLOAT (pr, 1); level = P_FLOAT (pr, 1);
s = PF_VarString (pr, 2);
if (entnum < 1 || entnum > MAX_CLIENTS) { if (entnum < 1 || entnum > MAX_CLIENTS) {
SV_Printf ("tried to sprint to a non-client\n"); SV_Printf ("tried to sprint to a non-client\n");
return; return;
@ -246,6 +244,11 @@ PF_sprint (progs_t *pr)
client = &svs.clients[entnum - 1]; client = &svs.clients[entnum - 1];
if (client->state == cs_server)
return;
s = PF_VarString (pr, 2);
SV_ClientPrintf (1, client, level, "%s", s); SV_ClientPrintf (1, client, level, "%s", s);
} }
@ -264,7 +267,6 @@ PF_centerprint (progs_t *pr)
int entnum; int entnum;
entnum = P_EDICTNUM (pr, 0); entnum = P_EDICTNUM (pr, 0);
s = PF_VarString (pr, 1);
if (entnum < 1 || entnum > MAX_CLIENTS) { if (entnum < 1 || entnum > MAX_CLIENTS) {
SV_Printf ("tried to sprint to a non-client\n"); SV_Printf ("tried to sprint to a non-client\n");
@ -273,6 +275,11 @@ PF_centerprint (progs_t *pr)
cl = &svs.clients[entnum - 1]; cl = &svs.clients[entnum - 1];
if (cl->state == cs_server)
return;
s = PF_VarString (pr, 1);
ClientReliableWrite_Begin (cl, svc_centerprint, 2 + strlen (s)); ClientReliableWrite_Begin (cl, svc_centerprint, 2 + strlen (s));
ClientReliableWrite_String (cl, s); ClientReliableWrite_String (cl, s);
@ -555,10 +562,14 @@ PF_stuffcmd (progs_t *pr)
entnum = P_EDICTNUM (pr, 0); entnum = P_EDICTNUM (pr, 0);
if (entnum < 1 || entnum > MAX_CLIENTS) if (entnum < 1 || entnum > MAX_CLIENTS)
PR_RunError (pr, "Parm 0 not a client"); PR_RunError (pr, "Parm 0 not a client");
str = P_STRING (pr, 1);
cl = &svs.clients[entnum - 1]; cl = &svs.clients[entnum - 1];
if (cl->state == cs_server)
return;
str = P_STRING (pr, 1);
buf = cl->stufftext_buf; buf = cl->stufftext_buf;
if (strlen (buf) + strlen (str) >= MAX_STUFFTEXT) if (strlen (buf) + strlen (str) >= MAX_STUFFTEXT)
PR_RunError (pr, "stufftext buffer overflow"); PR_RunError (pr, "stufftext buffer overflow");
@ -1078,11 +1089,13 @@ PF_WriteBytes (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server)
ClientReliableCheckBlock (cl, pr->pr_argc); ClientReliableCheckBlock (cl, pr->pr_argc);
if (sv.demorecording) if (sv.demorecording)
DemoWrite_Begin (dem_single, cl - svs.clients, pr->pr_argc); DemoWrite_Begin (dem_single, cl - svs.clients, pr->pr_argc);
for (i = 1; i < pr->pr_argc; i++) { for (i = 1; i < pr->pr_argc; i++) {
p = G_FLOAT (pr, OFS_PARM0 + i * (OFS_PARM1 - OFS_PARM0)); p = G_FLOAT (pr, OFS_PARM0 + i * (OFS_PARM1 - OFS_PARM0));
if (cl->state != cs_server)
ClientReliableWrite_Byte (cl, p); ClientReliableWrite_Byte (cl, p);
if (sv.demorecording) if (sv.demorecording)
MSG_WriteByte (&demo.dbuf->sz, p); MSG_WriteByte (&demo.dbuf->sz, p);
@ -1102,8 +1115,10 @@ PF_WriteByte (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 1); ClientReliableCheckBlock (cl, 1);
ClientReliableWrite_Byte (cl, P_FLOAT (pr, 1)); ClientReliableWrite_Byte (cl, P_FLOAT (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 1); DemoWrite_Begin (dem_single, cl - svs.clients, 1);
MSG_WriteByte (&demo.dbuf->sz, P_FLOAT (pr, 1)); MSG_WriteByte (&demo.dbuf->sz, P_FLOAT (pr, 1));
@ -1118,8 +1133,10 @@ PF_WriteChar (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 1); ClientReliableCheckBlock (cl, 1);
ClientReliableWrite_Char (cl, P_FLOAT (pr, 1)); ClientReliableWrite_Char (cl, P_FLOAT (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 1); DemoWrite_Begin (dem_single, cl - svs.clients, 1);
MSG_WriteByte (&demo.dbuf->sz, P_FLOAT (pr, 1)); MSG_WriteByte (&demo.dbuf->sz, P_FLOAT (pr, 1));
@ -1134,8 +1151,10 @@ PF_WriteShort (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 2); ClientReliableCheckBlock (cl, 2);
ClientReliableWrite_Short (cl, P_FLOAT (pr, 1)); ClientReliableWrite_Short (cl, P_FLOAT (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 2); DemoWrite_Begin (dem_single, cl - svs.clients, 2);
MSG_WriteShort (&demo.dbuf->sz, P_FLOAT (pr, 1)); MSG_WriteShort (&demo.dbuf->sz, P_FLOAT (pr, 1));
@ -1150,8 +1169,10 @@ PF_WriteLong (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 4); ClientReliableCheckBlock (cl, 4);
ClientReliableWrite_Long (cl, P_FLOAT (pr, 1)); ClientReliableWrite_Long (cl, P_FLOAT (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 4); DemoWrite_Begin (dem_single, cl - svs.clients, 4);
MSG_WriteLong (&demo.dbuf->sz, P_FLOAT (pr, 1)); MSG_WriteLong (&demo.dbuf->sz, P_FLOAT (pr, 1));
@ -1166,8 +1187,10 @@ PF_WriteAngle (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 1); ClientReliableCheckBlock (cl, 1);
ClientReliableWrite_Angle (cl, P_FLOAT (pr, 1)); ClientReliableWrite_Angle (cl, P_FLOAT (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 1); DemoWrite_Begin (dem_single, cl - svs.clients, 1);
MSG_WriteAngle (&demo.dbuf->sz, P_FLOAT (pr, 1)); MSG_WriteAngle (&demo.dbuf->sz, P_FLOAT (pr, 1));
@ -1182,8 +1205,10 @@ PF_WriteCoord (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 2); ClientReliableCheckBlock (cl, 2);
ClientReliableWrite_Coord (cl, P_FLOAT (pr, 1)); ClientReliableWrite_Coord (cl, P_FLOAT (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 2); DemoWrite_Begin (dem_single, cl - svs.clients, 2);
MSG_WriteCoord (&demo.dbuf->sz, P_FLOAT (pr, 1)); MSG_WriteCoord (&demo.dbuf->sz, P_FLOAT (pr, 1));
@ -1200,8 +1225,10 @@ PF_WriteAngleV (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 1); ClientReliableCheckBlock (cl, 1);
ClientReliableWrite_AngleV (cl, ang); ClientReliableWrite_AngleV (cl, ang);
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 1); DemoWrite_Begin (dem_single, cl - svs.clients, 1);
MSG_WriteAngleV (&demo.dbuf->sz, ang); MSG_WriteAngleV (&demo.dbuf->sz, ang);
@ -1218,8 +1245,10 @@ PF_WriteCoordV (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 2); ClientReliableCheckBlock (cl, 2);
ClientReliableWrite_CoordV (cl, coord); ClientReliableWrite_CoordV (cl, coord);
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 2); DemoWrite_Begin (dem_single, cl - svs.clients, 2);
MSG_WriteCoordV (&demo.dbuf->sz, coord); MSG_WriteCoordV (&demo.dbuf->sz, coord);
@ -1234,8 +1263,10 @@ PF_WriteString (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 1 + strlen (P_STRING (pr, 1))); ClientReliableCheckBlock (cl, 1 + strlen (P_STRING (pr, 1)));
ClientReliableWrite_String (cl, P_STRING (pr, 1)); ClientReliableWrite_String (cl, P_STRING (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, DemoWrite_Begin (dem_single, cl - svs.clients,
1 + strlen (P_STRING (pr, 1))); 1 + strlen (P_STRING (pr, 1)));
@ -1251,8 +1282,10 @@ PF_WriteEntity (progs_t *pr)
if (P_FLOAT (pr, 0) == MSG_ONE) { if (P_FLOAT (pr, 0) == MSG_ONE) {
client_t *cl = Write_GetClient (pr); client_t *cl = Write_GetClient (pr);
if (cl->state != cs_server) {
ClientReliableCheckBlock (cl, 2); ClientReliableCheckBlock (cl, 2);
ClientReliableWrite_Short (cl, P_EDICTNUM (pr, 1)); ClientReliableWrite_Short (cl, P_EDICTNUM (pr, 1));
}
if (sv.demorecording) { if (sv.demorecording) {
DemoWrite_Begin (dem_single, cl - svs.clients, 2); DemoWrite_Begin (dem_single, cl - svs.clients, 2);
MSG_WriteShort (&demo.dbuf->sz, P_EDICTNUM (pr, 1)); MSG_WriteShort (&demo.dbuf->sz, P_EDICTNUM (pr, 1));
@ -1303,6 +1336,9 @@ PF_setspawnparms (progs_t *pr)
// copy spawn parms out of the client_t // copy spawn parms out of the client_t
client = svs.clients + (i - 1); client = svs.clients + (i - 1);
if (client->state == cs_server)
return;
for (i = 0; i < NUM_SPAWN_PARMS; i++) for (i = 0; i < NUM_SPAWN_PARMS; i++)
sv_globals.parms[i] = client->spawn_parms[i]; sv_globals.parms[i] = client->spawn_parms[i];
} }
@ -1723,22 +1759,18 @@ static void
PF_SV_AllocClient (progs_t *pr) PF_SV_AllocClient (progs_t *pr)
{ {
client_t *cl = SV_AllocClient (0, 1); client_t *cl = SV_AllocClient (0, 1);
edict_t *ent;
if (!cl) { if (!cl) {
R_var (pr, entity) = 0; R_var (pr, entity) = 0;
return; return;
} }
ent = EDICT_NUM (&sv_pr_state, (cl - svs.clients) + 1);
memset (cl, 0, sizeof (*cl));
cl->userinfo = Info_ParseString ("", 1023, !sv_highchars->int_val); cl->userinfo = Info_ParseString ("", 1023, !sv_highchars->int_val);
//XXX netchan? Netchan_Setup (&newcl->netchan, adr, qport); //XXX netchan? Netchan_Setup (&newcl->netchan, adr, qport);
cl->state = cs_server; cl->state = cs_server;
cl->spectator = 0; cl->spectator = 0;
cl->edict = ent;
//SV_ExtractFromUserinfo (cl); //SV_ExtractFromUserinfo (cl);
RETURN_EDICT (pr, ent); RETURN_EDICT (pr, cl->edict);
} }
static void static void