static void Host_Pause_f (void) { if (cmd_source == src_command) { CL_Cmd_ForwardToServer (); return; } if (!pausable->int_val) SV_ClientPrintf ("Pause not allowed.\n"); else { sv.paused ^= 1; if (sv.paused) { SV_BroadcastPrintf ("%s paused the game\n", PR_GetString (&sv_pr_state, SVstring (sv_player, netname))); } else { SV_BroadcastPrintf ("%s unpaused the game\n", PR_GetString (&sv_pr_state, SVstring (sv_player, netname))); } // send notification to all clients MSG_WriteByte (&sv.reliable_datagram, svc_setpause); MSG_WriteByte (&sv.reliable_datagram, sv.paused); } }
static void Host_Name_f (void) { const char *newName; if (Cmd_Argc () == 1) { Sys_Printf ("\"name\" is \"%s\"\n", cl_name->string); return; } if (Cmd_Argc () == 2) newName = Cmd_Argv (1); else newName = Cmd_Args (1); if (cmd_source == src_command) { if (strcmp (cl_name->string, newName) == 0) return; Cvar_Set (cl_name, va ("%.15s", newName)); if (cls.state >= ca_connected) CL_Cmd_ForwardToServer (); return; } if (host_client->name[0] && strcmp (host_client->name, "unconnected")) if (strcmp (host_client->name, newName) != 0) Sys_Printf ("%s renamed to %s\n", host_client->name, newName); strcpy (host_client->name, newName); SVstring (host_client->edict, netname) = PR_SetString (&sv_pr_state, host_client->name); // send notification to all clients MSG_WriteByte (&sv.reliable_datagram, svc_updatename); MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients); MSG_WriteString (&sv.reliable_datagram, host_client->name); }
static edict_t * FindViewthing (void) { int i; edict_t *e; for (i = 0; i < sv.num_edicts; i++) { e = EDICT_NUM (&sv_pr_state, i); if (!strcmp (PR_GetString (&sv_pr_state, SVstring (e, classname)), "viewthing")) return e; } Sys_Printf ("No viewthing on map\n"); return NULL; }
/* Host_Map_f handle a map <servername> command from the console. Active clients are kicked off. */ static void Host_Map_f (void) { char name[MAX_QPATH]; const char *expanded; QFile *f; if (cmd_source != src_command) return; if (Cmd_Argc () > 2) { Sys_Printf ("map <levelname> : continue game on a new level\n"); return; } if (Cmd_Argc () == 1) { Sys_Printf ("map is %s \"%s\" (%s)\n", sv.name, PR_GetString (&sv_pr_state, SVstring (sv.edicts, message)), nice_time (sv.time)); return; } // check to make sure the level exists expanded = va ("maps/%s.bsp", Cmd_Argv (1)); QFS_FOpenFile (expanded, &f); if (!f) { Sys_Printf ("Can't find %s\n", expanded); return; } Qclose (f); cls.demonum = -1; // stop demo loop in case this fails CL_Disconnect (); Host_ShutdownServer (false); cl.loading = true; CL_UpdateScreen (cl.time); svs.serverflags = 0; // haven't completed an episode yet strcpy (name, Cmd_Argv (1)); SV_SpawnServer (name); if (!sv.active) return; if (cls.state != ca_dedicated) { Cmd_ExecuteString ("connect local", src_command); } }
/* SV_Map_f handle a map <mapname> command from the console or progs. */ static void SV_Map_f (void) { const char *level; char *expanded; QFile *f; if (!curlevel) curlevel = dstring_newstr (); if (Cmd_Argc () > 2) { SV_Printf ("map <levelname> : continue game on a new level\n"); return; } if (Cmd_Argc () == 1) { SV_Printf ("map is %s \"%s\" (%s)\n", curlevel->str, PR_GetString (&sv_pr_state, SVstring (sv.edicts, message)), nice_time (sv.time)); return; } level = Cmd_Argv (1); // check to make sure the level exists expanded = nva ("maps/%s.bsp", level); f = QFS_FOpenFile (expanded); if (!f) { SV_Printf ("Can't find %s\n", expanded); free (expanded); return; } Qclose (f); free (expanded); if (sv.recording_demo) SV_Stop (0); SV_qtvChanging (); SV_BroadcastCommand ("changing\n"); SV_SendMessagesToAll (); dstring_copystr (curlevel, level); SV_SpawnServer (level); SV_qtvReconnect (); SV_BroadcastCommand ("reconnect\n"); }
static void Host_Spawn_f (void) { int i; client_t *client; edict_t *ent; float *sendangles; if (cmd_source == src_command) { Sys_Printf ("spawn is not valid from the console\n"); return; } if (host_client->spawned) { Sys_Printf ("Spawn not valid -- already spawned\n"); return; } // run the entrance script if (sv.loadgame) { // loaded games are fully inited already // if this is the last client to be connected, unpause sv.paused = false; } else { // set up the edict ent = host_client->edict; memset (&ent->v, 0, sv_pr_state.progs->entityfields * 4); SVfloat (ent, colormap) = NUM_FOR_EDICT (&sv_pr_state, ent); SVfloat (ent, team) = (host_client->colors & 15) + 1; SVstring (ent, netname) = PR_SetString (&sv_pr_state, host_client->name); // copy spawn parms out of the client_t for (i = 0; i < NUM_SPAWN_PARMS; i++) sv_globals.parms[i] = host_client->spawn_parms[i]; // call the spawn function *sv_globals.time = sv.time; *sv_globals.self = EDICT_TO_PROG (&sv_pr_state, sv_player); PR_ExecuteProgram (&sv_pr_state, sv_funcs.ClientConnect); if ((Sys_DoubleTime () - host_client->netconnection->connecttime) <= sv.time) Sys_Printf ("%s entered the game\n", host_client->name); PR_ExecuteProgram (&sv_pr_state, sv_funcs.PutClientInServer); } // send all current names, colors, and frag counts SZ_Clear (&host_client->message); // send time of update MSG_WriteByte (&host_client->message, svc_time); MSG_WriteFloat (&host_client->message, sv.time); for (i = 0, client = svs.clients; i < svs.maxclients; i++, client++) { MSG_WriteByte (&host_client->message, svc_updatename); MSG_WriteByte (&host_client->message, i); MSG_WriteString (&host_client->message, client->name); MSG_WriteByte (&host_client->message, svc_updatefrags); MSG_WriteByte (&host_client->message, i); MSG_WriteShort (&host_client->message, client->old_frags); MSG_WriteByte (&host_client->message, svc_updatecolors); MSG_WriteByte (&host_client->message, i); MSG_WriteByte (&host_client->message, client->colors); } // send all current light styles for (i = 0; i < MAX_LIGHTSTYLES; i++) { MSG_WriteByte (&host_client->message, svc_lightstyle); MSG_WriteByte (&host_client->message, (char) i); MSG_WriteString (&host_client->message, sv.lightstyles[i]); } // send some stats MSG_WriteByte (&host_client->message, svc_updatestat); MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS); MSG_WriteLong (&host_client->message, *sv_globals.total_secrets); MSG_WriteByte (&host_client->message, svc_updatestat); MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS); MSG_WriteLong (&host_client->message, *sv_globals.total_monsters); MSG_WriteByte (&host_client->message, svc_updatestat); MSG_WriteByte (&host_client->message, STAT_SECRETS); MSG_WriteLong (&host_client->message, *sv_globals.found_secrets); MSG_WriteByte (&host_client->message, svc_updatestat); MSG_WriteByte (&host_client->message, STAT_MONSTERS); MSG_WriteLong (&host_client->message, *sv_globals.killed_monsters); // send a fixangle // Never send a roll angle, because savegames can catch the server // in a state where it is expecting the client to correct the angle // and it won't happen if the game was just loaded, so you wind up // with a permanent head tilt ent = EDICT_NUM (&sv_pr_state, 1 + (host_client - svs.clients)); MSG_WriteByte (&host_client->message, svc_setangle); sendangles = sv.loadgame ? SVvector (ent, v_angle): SVvector (ent, angles); MSG_WriteAngle (&host_client->message, sendangles[0]); MSG_WriteAngle (&host_client->message, sendangles[1]); MSG_WriteAngle (&host_client->message, 0); SV_WriteClientdataToMessage (sv_player, &host_client->message); MSG_WriteByte (&host_client->message, svc_signonnum); MSG_WriteByte (&host_client->message, 3); host_client->sendsignon = true; }