From 389542fda7ec02a954bfdb49314393648fc0e598 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 3 Mar 2003 17:08:45 +0000 Subject: [PATCH] first step in creating an interface for the snagging of client slots by the progs --- qw/include/server.h | 1 + qw/source/sv_ccmds.c | 22 +++++++++++++++------- qw/source/sv_gib.c | 6 +++--- qw/source/sv_main.c | 20 +++++++++----------- qw/source/sv_send.c | 6 +++--- qw/source/sv_user.c | 4 ++-- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/qw/include/server.h b/qw/include/server.h index c0c52f228..f9173a2e2 100644 --- a/qw/include/server.h +++ b/qw/include/server.h @@ -120,6 +120,7 @@ typedef struct typedef enum { cs_free, // can be reused for a new connection + cs_server, // client is grabbed by the server for its own purposes cs_zombie, // client has been disconnected, but don't reuse // connection for a couple seconds cs_connected, // has been assigned to a client_t, but not in game yet diff --git a/qw/source/sv_ccmds.c b/qw/source/sv_ccmds.c index 63ebb1900..82b5a1156 100644 --- a/qw/source/sv_ccmds.c +++ b/qw/source/sv_ccmds.c @@ -103,7 +103,7 @@ SV_Match_User (const char *substr) if (!*str) { for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->state) + if (cl->state < cs_zombie) continue; if (cl->userid == uid) { SV_Printf ("User %04d matches with name: %s\n", @@ -116,7 +116,7 @@ SV_Match_User (const char *substr) } for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->state) + if (cl->state < cs_zombie) continue; for (str = cl->name; *str && !match_char (*str, substr[0]); str++) ; @@ -230,7 +230,7 @@ SV_SetPlayer (void) idnum = atoi (Cmd_Argv (1)); for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->state) + if (cl->state < cs_zombie) continue; if (cl->userid == idnum) { host_client = cl; @@ -496,6 +496,10 @@ SV_Status_f (void) SV_Printf ("ZOMBIE\n"); continue; } + if (cl->state == cs_server) { + SV_Printf ("SERVER\n"); + continue; + } SV_Printf ("%4i %4i %5.2f\n", (int) (1000 * cl->netchan.frame_rate), (int) SV_CalcPing (cl), @@ -527,6 +531,10 @@ SV_Status_f (void) SV_Printf ("ZOMBIE\n"); continue; } + if (cl->state == cs_server) { + SV_Printf ("SERVER\n"); + continue; + } SV_Printf ("%4i %4i %3.1f %4i", (int) (1000 * cl->netchan.frame_rate), (int) SV_CalcPing (cl), @@ -582,7 +590,7 @@ SV_Cuff_f (void) } if (all) { for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->state) + if (cl->state < cs_zombie) continue; cl->cuff_time = realtime + mins*60.0; done = true; @@ -644,7 +652,7 @@ SV_Mute_f (void) } if (all) { for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->state) + if (cl->state < cs_zombie) continue; cl->lockedtill = realtime + mins*60.0; done = true; @@ -766,7 +774,7 @@ SV_ConSay (const char *prefix) text[j++] |= 0x80; // non-bold text for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) { - if (client->state != cs_spawned) // kk just has !client->state + if (client->state < cs_zombie) continue; SV_ClientPrintf (1, client, PRINT_HIGH, "%s\n", text); if (*prefix != 'I') // beep, except for Info says @@ -1045,7 +1053,7 @@ SV_Snap (int uid) int i; for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->state) + if (cl->state < cs_zombie) continue; if (cl->userid == uid) break; diff --git a/qw/source/sv_gib.c b/qw/source/sv_gib.c index c5b6a993c..636b11233 100644 --- a/qw/source/sv_gib.c +++ b/qw/source/sv_gib.c @@ -59,7 +59,7 @@ SV_GIB_GetClient (int uid) int i; for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) - if (cl->state && cl->userid == uid) + if (cl->state >= cs_connected && cl->userid == uid) return cl; return 0; } @@ -74,7 +74,7 @@ SV_GIB_Client_GetList_f (void) GIB_USAGE(""); else if (GIB_CanReturn()) for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) - if (cl->state) + if (cl->state >= cs_connected) dsprintf (GIB_Return(0), "%i", cl->userid); } @@ -131,7 +131,7 @@ SV_GIB_Client_Print_All_f (void) if (GIB_Argc() != 2) GIB_USAGE("message"); else for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) - if (cl->state) + if (cl->state >= cs_connected) SV_ClientPrintf (0, cl, level, "%s", GIB_Argv(1)); } diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index 3e7fe6e2b..8abec4189 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -321,7 +321,7 @@ SV_FinalMessage (const char *message) MSG_WriteByte (net_message->message, svc_disconnect); for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) - if (cl->state >= cs_spawned) + if (cl->state >= cs_connected) Netchan_Transmit (&cl->netchan, net_message->message->cursize, net_message->message->data); } @@ -571,8 +571,7 @@ SVC_Status (void) SV_Printf ("%s\n", Info_MakeString (svs.info, 0)); for (i = 0; i < MAX_CLIENTS; i++) { cl = &svs.clients[i]; - if ((cl->state == cs_connected || cl->state == cs_spawned) - && !cl->spectator) { + if ((cl->state >= cs_connected) && !cl->spectator) { top = atoi (Info_ValueForKey (cl->userinfo, "topcolor")); bottom = atoi (Info_ValueForKey (cl->userinfo, "bottomcolor")); top = (top < 0) ? 0 : ((top > 13) ? 13 : top); @@ -840,7 +839,7 @@ SVC_DirectConnect (void) // if there is already a slot for this ip, drop it for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (cl->state == cs_free) + if (cl->state < cs_zombie) continue; if (NET_CompareBaseAdr (adr, cl->netchan.remote_address) && (cl->netchan.qport == qport @@ -974,7 +973,7 @@ Name_of_sender (void) int i; for (i=0, cl=svs.clients ; istate == cs_free) + if (cl->state < cs_zombie) continue; if (!NET_CompareBaseAdr(net_from, cl->netchan.remote_address)) continue; @@ -1435,7 +1434,7 @@ SV_AddIP_f (void) const char *typestr; char timestr[1024]; - if (cl->state == cs_free) + if (cl->state < cs_zombie) continue; if (SV_MaskIPCompare (cl->netchan.remote_address.ip, @@ -1781,7 +1780,7 @@ SV_ReadPackets (void) // check for packets from connected clients for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (cl->state == cs_free) + if (cl->state < cs_zombie) continue; if (!NET_CompareBaseAdr (net_from, cl->netchan.remote_address)) continue; @@ -1833,7 +1832,7 @@ SV_CheckTimeouts (void) nclients = 0; for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (cl->state == cs_connected || cl->state == cs_spawned) { + if (cl->state >= cs_connected) { if (!cl->spectator) nclients++; if (cl->netchan.last_received < droptime) { @@ -2244,8 +2243,8 @@ Master_Heartbeat (void) // count active users active = 0; for (i = 0; i < MAX_CLIENTS; i++) - if (svs.clients[i].state == cs_connected || - svs.clients[i].state == cs_spawned) active++; + if (svs.clients[i].state >= cs_connected) + active++; svs.heartbeat_sequence++; snprintf (string, sizeof (string), "%c\n%i\n%i\n", S2M_HEARTBEAT, @@ -2362,7 +2361,6 @@ SV_ExtractFromUserinfo (client_t *cl) } // finally, report it to all our friends -// if (cl->state >= cs_spawned && !cl->spectator) if (*cl->name) SV_BroadcastPrintf (PRINT_HIGH, "%s changed name to %s\n", cl->name, newname); diff --git a/qw/source/sv_send.c b/qw/source/sv_send.c index e6a60d739..40c1b53d2 100644 --- a/qw/source/sv_send.c +++ b/qw/source/sv_send.c @@ -294,7 +294,7 @@ SV_BroadcastPrintf (int level, const char *fmt, ...) for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { if (level < cl->messagelevel) continue; - if (!cl->state) + if (cl->state < cs_zombie) continue; SV_PrintToClient (cl, level, string); @@ -807,7 +807,7 @@ SV_SendClientMessages (void) // build individual updates for (i = 0, c = svs.clients; i < MAX_CLIENTS; i++, c++) { - if (!c->state) + if (c->state < cs_zombie) continue; if (c->drop) { @@ -1012,7 +1012,7 @@ SV_SendMessagesToAll (void) int i; for (i = 0, c = svs.clients; i < MAX_CLIENTS; i++, c++) - if (c->state) // FIXME: should this only send to active? + if (c->state < cs_zombie) // FIXME: should this only send to active? c->send_message = true; SV_SendClientMessages (); diff --git a/qw/source/sv_user.c b/qw/source/sv_user.c index bbfed26db..1e2feb4f8 100644 --- a/qw/source/sv_user.c +++ b/qw/source/sv_user.c @@ -456,7 +456,7 @@ SV_Begin_f (ucmd_t *cmd) unsigned int pmodel = 0, emodel = 0; int i; - if (host_client->state == cs_spawned) + if (host_client->state != cs_connected) return; // don't begin again host_client->state = cs_spawned; @@ -946,7 +946,7 @@ SV_TogglePause (const char *msg) // send notification to all clients for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->state) + if (cl->state < cs_zombie) continue; ClientReliableWrite_Begin (cl, svc_setpause, 2); ClientReliableWrite_Byte (cl, sv.paused);