]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host_cmd.c
fixed reconnect command which was being ignored by the client (forgot that it doesn...
[xonotic/darkplaces.git] / host_cmd.c
index 7ded7c4787ef1f0bd4e1b835564f0d45f9d6e61d..9a0cc2a0c99c620ba0b053161ffc1e5563e03274 100644 (file)
@@ -50,6 +50,7 @@ Host_Status_f
 */
 void Host_Status_f (void)
 {
+       const char *protocolname;
        client_t *client;
        int seconds, minutes, hours = 0, j, players;
        void (*print) (const char *fmt, ...);
@@ -71,6 +72,17 @@ void Host_Status_f (void)
                        players++;
        print ("host:    %s\n", Cvar_VariableString ("hostname"));
        print ("version: %s build %s\n", gamename, buildstring);
+       switch(sv.protocol)
+       {
+               case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
+               case PROTOCOL_DARKPLACES1: protocolname = "PROTOCOL_DARKPLACES1";break;
+               case PROTOCOL_DARKPLACES2: protocolname = "PROTOCOL_DARKPLACES2";break;
+               case PROTOCOL_DARKPLACES3: protocolname = "PROTOCOL_DARKPLACES3";break;
+               case PROTOCOL_DARKPLACES4: protocolname = "PROTOCOL_DARKPLACES4";break;
+               case PROTOCOL_DARKPLACES5: protocolname = "PROTOCOL_DARKPLACES5";break;
+               default: protocolname = "PROTOCOL_UNKNOWN";break;
+       }
+       print ("protocol: %i (%s)\n", sv.protocol, protocolname);
        print ("map:     %s\n", sv.name);
        print ("players: %i active (%i max)\n\n", players, svs.maxclients);
        for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
@@ -271,16 +283,24 @@ void Host_Map_f (void)
 {
        char level[MAX_QPATH];
 
+       if (Cmd_Argc() != 2)
+       {
+               Con_Print("map <levelname> : start a new game (kicks off all players)\n");
+               return;
+       }
+
        if (cmd_source != src_command)
                return;
 
+       SCR_BeginLoadingPlaque ();
        cls.demonum = -1;               // stop demo loop in case this fails
 
        CL_Disconnect ();
        Host_ShutdownServer(false);
 
-       key_dest = key_game;                    // remove console or menu
-       SCR_BeginLoadingPlaque ();
+       // remove console or menu
+       key_dest = key_game;
+       key_consoleactive = 0;
 
        svs.serverflags = 0;                    // haven't completed an episode yet
        allowcheats = sv_cheats.integer != 0;
@@ -311,7 +331,15 @@ void Host_Changelevel_f (void)
                Con_Print("Only the server may changelevel\n");
                return;
        }
+       if (cmd_source != src_command)
+               return;
+
+       // remove console or menu
+       key_dest = key_game;
+       key_consoleactive = 0;
+
        SV_SaveSpawnparms ();
+       SCR_BeginLoadingPlaque();
        allowcheats = sv_cheats.integer != 0;
        strcpy(level, Cmd_Argv(1));
        SV_SpawnServer(level);
@@ -330,11 +358,24 @@ void Host_Restart_f (void)
 {
        char mapname[MAX_QPATH];
        
-       if (cls.demoplayback || !sv.active)
+       if (Cmd_Argc() != 1)
+       {
+               Con_Print("restart : restart current level\n");
                return;
-
+       }
+       if (!sv.active || cls.demoplayback)
+       {
+               Con_Print("Only the server may restart\n");
+               return;
+       }
        if (cmd_source != src_command)
                return;
+
+       // remove console or menu
+       key_dest = key_game;
+       key_consoleactive = 0;
+
+       SCR_BeginLoadingPlaque();
        allowcheats = sv_cheats.integer != 0;
        strcpy(mapname, sv.name);
        SV_SpawnServer(mapname);
@@ -352,6 +393,16 @@ This is sent just before a server changes levels
 */
 void Host_Reconnect_f (void)
 {
+       if (Cmd_Argc() != 1)
+       {
+               Con_Print("reconnect : wait for signon messages again\n");
+               return;
+       }
+       if (!cls.signon)
+       {
+               Con_Print("reconnect: no signon, ignoring reconnect\n");
+               return;
+       }
        SCR_BeginLoadingPlaque();
        cls.signon = 0;         // need new connection messages
 }
@@ -365,6 +416,11 @@ User command to connect to server
 */
 void Host_Connect_f (void)
 {
+       if (Cmd_Argc() != 2)
+       {
+               Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
+               return;
+       }
        CL_EstablishConnection(Cmd_Argv(1));
 }
 
@@ -731,7 +787,7 @@ void Host_Say(qboolean teamonly)
 {
        client_t *save;
        int j;
-       const char *p1, *p2;
+       const char *p1;
        // LordHavoc: 256 char say messages
        unsigned char text[256];
        qboolean fromServer = false;
@@ -753,39 +809,20 @@ void Host_Say(qboolean teamonly)
        if (Cmd_Argc () < 2)
                return;
 
-       save = host_client;
+       if (!teamplay.integer)
+               teamonly = false;
 
 // turn on color set 1
+       p1 = Cmd_Args();
        if (!fromServer)
-               sprintf (text, "%c%s: ", 1, host_client->name);
+               snprintf (text, sizeof(text), "%c%s: %s\n", 1, host_client->name, p1);
        else
-               sprintf (text, "%c<%s> ", 1, hostname.string);
-
-       p1 = Cmd_Args();
-       p2 = p1 + strlen(p1);
-       // remove trailing newlines
-       while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
-               p2--;
-       // remove quotes if present
-       if (*p1 == '"')
-       {
-               p1++;
-               if (p2[-1] == '"')
-                       p2--;
-               else if (fromServer)
-                       Con_Print("Host_Say: missing end quote\n");
-               else
-                       SV_ClientPrint("Host_Say: missing end quote\n");
-       }
-       while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
-               p2--;
-       for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
-               text[j++] = *p1++;
-       text[j++] = '\n';
-       text[j++] = 0;
+               snprintf (text, sizeof(text), "%c<%s> %s\n", 1, hostname.string, p1);
 
+       // note: save is not a valid edict if fromServer is true
+       save = host_client;
        for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
-               if (host_client->spawned && (!teamplay.integer || host_client->edict->v->team == save->edict->v->team))
+               if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
                        SV_ClientPrint(text);
        host_client = save;
 
@@ -921,7 +958,7 @@ void Host_Color_f(void)
                pr_global_struct->time = sv.time;
                pr_globals[OFS_PARM0] = playercolor;
                pr_global_struct->self = EDICT_TO_PROG(sv_player);
-               PR_ExecuteProgram (SV_ChangeTeam, "");
+               PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
        }
        else
        {
@@ -943,10 +980,9 @@ void Host_Color_f(void)
 }
 
 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
-cvar_t sv_maxrate = {CVAR_SAVE | CVAR_NOTIFY, "sv_maxrate", "10000"};
 void Host_Rate_f(void)
 {
-       int rate, maxrate;
+       int rate;
 
        if (Cmd_Argc() != 2)
        {
@@ -965,12 +1001,7 @@ void Host_Rate_f(void)
                return;
        }
 
-       maxrate = bound(NET_MINRATE, sv_maxrate.integer, NET_MAXRATE);
-       if (sv_maxrate.integer != maxrate)
-               Cvar_SetValueQuick(&sv_maxrate, maxrate);
-
-       if (LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
-               host_client->netconnection->rate = bound(NET_MINRATE, rate, maxrate);
+       host_client->netconnection->rate = rate;
 }
 
 /*
@@ -1134,7 +1165,7 @@ void Host_Spawn_f (void)
                        Con_DPrint("Calling RestoreGame\n");
                        pr_global_struct->time = sv.time;
                        pr_global_struct->self = EDICT_TO_PROG(sv_player);
-                       PR_ExecuteProgram (RestoreGame, "");
+                       PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
                }
        }
        else
@@ -1210,9 +1241,9 @@ void Host_Spawn_f (void)
        // and it won't happen if the game was just loaded, so you wind up
        // with a permanent head tilt
        MSG_WriteByte (&host_client->message, svc_setangle);
-       for (i=0 ; i < 2 ; i++)
-               MSG_WriteAngle (&host_client->message, sv_player->v->angles[i] );
-       MSG_WriteAngle (&host_client->message, 0 );
+       MSG_WriteAngle (&host_client->message, sv_player->v->angles[0], sv.protocol);
+       MSG_WriteAngle (&host_client->message, sv_player->v->angles[1], sv.protocol);
+       MSG_WriteAngle (&host_client->message, 0, sv.protocol);
 
        SV_WriteClientdataToMessage (sv_player, &host_client->message);
 
@@ -1778,7 +1809,6 @@ void Host_InitCommands (void)
        Cmd_AddCommand ("color", Host_Color_f);
        Cvar_RegisterVariable (&cl_rate);
        Cmd_AddCommand ("rate", Host_Rate_f);
-       Cvar_RegisterVariable (&sv_maxrate);
        if (gamemode == GAME_NEHAHRA)
        {
                Cvar_RegisterVariable (&cl_pmodel);