- Cmd_AddCommand ("god", Host_God_f);
- Cmd_AddCommand ("notarget", Host_Notarget_f);
- Cmd_AddCommand ("fly", Host_Fly_f);
- Cmd_AddCommand ("noclip", Host_Noclip_f);
- Cmd_AddCommand ("give", Host_Give_f);
- }
- Cmd_AddCommand ("map", Host_Map_f);
- Cmd_AddCommand ("restart", Host_Restart_f);
- Cmd_AddCommand ("changelevel", Host_Changelevel_f);
- Cmd_AddCommand ("connect", Host_Connect_f);
- Cmd_AddCommand ("reconnect", Host_Reconnect_f);
- Cmd_AddCommand ("version", Host_Version_f);
- Cmd_AddCommand ("say", Host_Say_f);
- Cmd_AddCommand ("say_team", Host_Say_Team_f);
- Cmd_AddCommand ("tell", Host_Tell_f);
- Cmd_AddCommand ("kill", Host_Kill_f);
- Cmd_AddCommand ("pause", Host_Pause_f);
- Cmd_AddCommand ("kick", Host_Kick_f);
- Cmd_AddCommand ("ping", Host_Ping_f);
- Cmd_AddCommand ("load", Host_Loadgame_f);
- Cmd_AddCommand ("save", Host_Savegame_f);
-
- Cmd_AddCommand ("startdemos", Host_Startdemos_f);
- Cmd_AddCommand ("demos", Host_Demos_f);
- Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
-
- Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
- Cmd_AddCommand ("viewframe", Host_Viewframe_f);
- Cmd_AddCommand ("viewnext", Host_Viewnext_f);
- Cmd_AddCommand ("viewprev", Host_Viewprev_f);
+ Con_Printf ("Bad address\n");
+ return;
+ }
+
+ in = Cmd_Argv(2);
+ out = send+4;
+ send[0] = send[1] = send[2] = send[3] = -1;
+
+ l = (int)strlen (in);
+ for (i=0 ; i<l ; i++)
+ {
+ if (out >= send + sizeof(send) - 1)
+ break;
+ if (in[i] == '\\' && in[i+1] == 'n')
+ {
+ *out++ = '\n';
+ i++;
+ }
+ else if (in[i] == '\\' && in[i+1] == '0')
+ {
+ *out++ = '\0';
+ i++;
+ }
+ else if (in[i] == '\\' && in[i+1] == 't')
+ {
+ *out++ = '\t';
+ i++;
+ }
+ else if (in[i] == '\\' && in[i+1] == 'r')
+ {
+ *out++ = '\r';
+ i++;
+ }
+ else if (in[i] == '\\' && in[i+1] == '"')
+ {
+ *out++ = '\"';
+ i++;
+ }
+ else
+ *out++ = in[i];
+ }
+
+ mysocket = NetConn_ChooseClientSocketForAddress(&address);
+ if (!mysocket)
+ mysocket = NetConn_ChooseServerSocketForAddress(&address);
+ if (mysocket)
+ NetConn_Write(mysocket, send, out - send, &address);
+}
+
+/*
+====================
+Host_Pings_f
+
+Send back ping and packet loss update for all current players to this player
+====================
+*/
+void Host_Pings_f (void)
+{
+ int i, j, ping, packetloss, movementloss;
+ char temp[128];
+
+ if (!host_client->netconnection)
+ return;
+
+ if (sv.protocol != PROTOCOL_QUAKEWORLD)
+ {
+ MSG_WriteByte(&host_client->netconnection->message, svc_stufftext);
+ MSG_WriteUnterminatedString(&host_client->netconnection->message, "pingplreport");
+ }
+ for (i = 0;i < svs.maxclients;i++)
+ {
+ packetloss = 0;
+ movementloss = 0;
+ if (svs.clients[i].netconnection)
+ {
+ for (j = 0;j < NETGRAPH_PACKETS;j++)
+ if (svs.clients[i].netconnection->incoming_netgraph[j].unreliablebytes == NETGRAPH_LOSTPACKET)
+ packetloss++;
+ for (j = 0;j < NETGRAPH_PACKETS;j++)
+ if (svs.clients[i].movement_count[j] < 0)
+ movementloss++;
+ }
+ packetloss = (packetloss * 100 + NETGRAPH_PACKETS - 1) / NETGRAPH_PACKETS;
+ movementloss = (movementloss * 100 + NETGRAPH_PACKETS - 1) / NETGRAPH_PACKETS;
+ ping = (int)floor(svs.clients[i].ping*1000+0.5);
+ ping = bound(0, ping, 9999);
+ if (sv.protocol == PROTOCOL_QUAKEWORLD)
+ {
+ // send qw_svc_updateping and qw_svc_updatepl messages
+ MSG_WriteByte(&host_client->netconnection->message, qw_svc_updateping);
+ MSG_WriteShort(&host_client->netconnection->message, ping);
+ MSG_WriteByte(&host_client->netconnection->message, qw_svc_updatepl);
+ MSG_WriteByte(&host_client->netconnection->message, packetloss);
+ }
+ else
+ {
+ // write the string into the packet as multiple unterminated strings to avoid needing a local buffer
+ if(movementloss)
+ dpsnprintf(temp, sizeof(temp), " %d %d,%d", ping, packetloss, movementloss);
+ else
+ dpsnprintf(temp, sizeof(temp), " %d %d", ping, packetloss);
+ MSG_WriteUnterminatedString(&host_client->netconnection->message, temp);
+ }
+ }
+ if (sv.protocol != PROTOCOL_QUAKEWORLD)
+ MSG_WriteString(&host_client->netconnection->message, "\n");
+}
+
+static void Host_PingPLReport_f(void)
+{
+ char *errbyte;
+ int i;
+ int l = Cmd_Argc();
+ if (l > cl.maxclients)
+ l = cl.maxclients;
+ for (i = 0;i < l;i++)
+ {
+ cl.scores[i].qw_ping = atoi(Cmd_Argv(1+i*2));
+ cl.scores[i].qw_packetloss = strtol(Cmd_Argv(1+i*2+1), &errbyte, 0);
+ if(errbyte && *errbyte == ',')
+ cl.scores[i].qw_movementloss = atoi(errbyte + 1);
+ else
+ cl.scores[i].qw_movementloss = 0;
+ }
+}
+
+//=============================================================================
+
+/*
+==================
+Host_InitCommands
+==================
+*/
+void Host_InitCommands (void)
+{
+ dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp");
+
+ Cmd_AddCommand_WithClientCommand ("status", Host_Status_f, Host_Status_f, "print server status information");
+ Cmd_AddCommand ("quit", Host_Quit_f, "quit the game");
+ Cmd_AddCommand_WithClientCommand ("god", NULL, Host_God_f, "god mode (invulnerability)");
+ Cmd_AddCommand_WithClientCommand ("notarget", NULL, Host_Notarget_f, "notarget mode (monsters do not see you)");
+ Cmd_AddCommand_WithClientCommand ("fly", NULL, Host_Fly_f, "fly mode (flight)");
+ Cmd_AddCommand_WithClientCommand ("noclip", NULL, Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
+ Cmd_AddCommand_WithClientCommand ("give", NULL, Host_Give_f, "alter inventory");
+ Cmd_AddCommand ("map", Host_Map_f, "kick everyone off the server and start a new level");
+ Cmd_AddCommand ("restart", Host_Restart_f, "restart current level");
+ Cmd_AddCommand ("changelevel", Host_Changelevel_f, "change to another level, bringing along all connected clients");
+ Cmd_AddCommand ("connect", Host_Connect_f, "connect to a server by IP address or hostname");
+ Cmd_AddCommand ("reconnect", Host_Reconnect_f, "reconnect to the last server you were on, or resets a quakeworld connection (do not use if currently playing on a netquake server)");
+ Cmd_AddCommand ("version", Host_Version_f, "print engine version");
+ Cmd_AddCommand_WithClientCommand ("say", Host_Say_f, Host_Say_f, "send a chat message to everyone on the server");
+ Cmd_AddCommand_WithClientCommand ("say_team", Host_Say_Team_f, Host_Say_Team_f, "send a chat message to your team on the server");
+ Cmd_AddCommand_WithClientCommand ("tell", Host_Tell_f, Host_Tell_f, "send a chat message to only one person on the server");
+ Cmd_AddCommand_WithClientCommand ("kill", NULL, Host_Kill_f, "die instantly");
+ Cmd_AddCommand_WithClientCommand ("pause", Host_Pause_f, Host_Pause_f, "pause the game (if the server allows pausing)");
+ Cmd_AddCommand ("kick", Host_Kick_f, "kick a player off the server by number or name");
+ Cmd_AddCommand_WithClientCommand ("ping", Host_Ping_f, Host_Ping_f, "print ping times of all players on the server");
+ Cmd_AddCommand ("load", Host_Loadgame_f, "load a saved game file");
+ Cmd_AddCommand ("save", Host_Savegame_f, "save the game to a file");
+
+ Cmd_AddCommand ("startdemos", Host_Startdemos_f, "start playing back the selected demos sequentially (used at end of startup script)");
+ Cmd_AddCommand ("demos", Host_Demos_f, "restart looping demos defined by the last startdemos command");
+ Cmd_AddCommand ("stopdemo", Host_Stopdemo_f, "stop playing or recording demo (like stop command) and return to looping demos");
+
+ Cmd_AddCommand ("viewmodel", Host_Viewmodel_f, "change model of viewthing entity in current level");
+ Cmd_AddCommand ("viewframe", Host_Viewframe_f, "change animation frame of viewthing entity in current level");
+ Cmd_AddCommand ("viewnext", Host_Viewnext_f, "change to next animation frame of viewthing entity in current level");
+ Cmd_AddCommand ("viewprev", Host_Viewprev_f, "change to previous animation frame of viewthing entity in current level");