2010-06-18 16:07:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
2010-06-18 16:07:51 +00:00
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2010-06-18 16:07:51 +00:00
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
2010-06-18 16:07:51 +00:00
|
|
|
*
|
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* This file implements generic network functions
|
|
|
|
*
|
|
|
|
* =======================================================================
|
2012-04-29 13:57:33 +00:00
|
|
|
*/
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
#include "header/client.h"
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void CL_ParseStatusMessage(void);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
extern cvar_t *msg;
|
|
|
|
extern cvar_t *rcon_client_password;
|
|
|
|
extern cvar_t *rcon_address;
|
|
|
|
extern cvar_t *cl_timeout;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* adds the current command line as a clc_stringcmd to the client
|
|
|
|
* message. things like godmode, noclip, etc, are commands directed to
|
|
|
|
* the server, so when they are typed in at the console, they will need
|
|
|
|
* to be forwarded.
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
Cmd_ForwardToServer(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
char *cmd;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
cmd = Cmd_Argv(0);
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((cls.state <= ca_connected) || (*cmd == '-') || (*cmd == '+'))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Unknown command \"%s\"\n", cmd);
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
MSG_WriteByte(&cls.netchan.message, clc_stringcmd);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
SZ_Print(&cls.netchan.message, cmd);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc() > 1)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
SZ_Print(&cls.netchan.message, " ");
|
|
|
|
SZ_Print(&cls.netchan.message, Cmd_Args());
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-29 13:57:33 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ForwardToServer_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((cls.state != ca_connected) && (cls.state != ca_active))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Can't \"%s\", not connected\n", Cmd_Argv(0));
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't forward the first argument */
|
|
|
|
if (Cmd_Argc() > 1)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
MSG_WriteByte(&cls.netchan.message, clc_stringcmd);
|
|
|
|
SZ_Print(&cls.netchan.message, Cmd_Args());
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called after an ERR_DROP was thrown
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Drop(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
|
|
|
if (cls.state == ca_uninitialized)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (cls.state == ca_disconnected)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_Disconnect();
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
/* drop loading plaque unless this is the initial game start */
|
|
|
|
if (cls.disable_servercount != -1)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
SCR_EndLoadingPlaque(); /* get rid of loading plaque */
|
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have gotten a challenge from the server, so try and
|
|
|
|
* connect.
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_SendConnectPacket(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
netadr_t adr;
|
|
|
|
int port;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
memset(&adr, 0, sizeof(adr));
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!NET_StringToAdr(cls.servername, &adr))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Bad server address\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
cls.connect_time = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adr.port == 0)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
adr.port = BigShort(PORT_SERVER);
|
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
port = Cvar_VariableValue("qport");
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
userinfo_modified = false;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, adr, "connect %i %i %i \"%s\"\n",
|
|
|
|
PROTOCOL_VERSION, port, cls.challenge, Cvar_Userinfo());
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resend a connect message if the last one has timed out
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_CheckForResend(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
netadr_t adr;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
/* if the local server is running and we aren't just connect */
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((cls.state == ca_disconnected) && Com_ServerState())
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
|
|
|
cls.state = ca_connecting;
|
2013-05-11 12:44:36 +00:00
|
|
|
Q_strlcpy(cls.servername, "localhost", sizeof(cls.servername));
|
2010-06-18 16:07:51 +00:00
|
|
|
/* we don't need a challenge on the localhost */
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_SendConnectPacket();
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* resend if we haven't gotten a reply yet */
|
|
|
|
if (cls.state != ca_connecting)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (cls.realtime - cls.connect_time < 3000)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!NET_StringToAdr(cls.servername, &adr))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Bad server address\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
cls.state = ca_disconnected;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adr.port == 0)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
adr.port = BigShort(PORT_SERVER);
|
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
cls.connect_time = cls.realtime;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Connecting to %s...\n", cls.servername);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, adr, "getchallenge\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Connect_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
char *server;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc() != 2)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("usage: connect <server>\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (Com_ServerState())
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2013-05-01 19:12:38 +00:00
|
|
|
/* if running a local server, kill it and reissue
|
2012-07-22 13:34:45 +00:00
|
|
|
note: this is connect with the save game system */
|
|
|
|
SV_Shutdown(va("Server quit\n", msg), false);
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_Disconnect();
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
server = Cmd_Argv(1);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
NET_Config(true); /* allow remote */
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_Disconnect();
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
cls.state = ca_connecting;
|
2013-05-11 12:44:36 +00:00
|
|
|
Q_strlcpy(cls.servername, server, sizeof(cls.servername));
|
2010-06-18 16:07:51 +00:00
|
|
|
cls.connect_time = -99999; /* HACK: CL_CheckForResend() will fire immediately */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the rest of the command line over as
|
|
|
|
* an unconnected command.
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Rcon_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
char message[1024];
|
|
|
|
int i;
|
|
|
|
netadr_t to;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (!rcon_client_password->string)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("You must set 'rcon_password' before\n"
|
|
|
|
"issuing an rcon command.\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&to, 0, sizeof(to));
|
|
|
|
|
|
|
|
message[0] = (char)255;
|
|
|
|
message[1] = (char)255;
|
|
|
|
message[2] = (char)255;
|
|
|
|
message[3] = (char)255;
|
|
|
|
message[4] = 0;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
NET_Config(true); /* allow remote */
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2013-05-18 16:59:12 +00:00
|
|
|
strcat(message, "rcon ");
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2013-05-18 16:59:12 +00:00
|
|
|
strcat(message, rcon_client_password->string);
|
|
|
|
strcat(message, " ");
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 1; i < Cmd_Argc(); i++)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2013-05-18 16:59:12 +00:00
|
|
|
strcat(message, Cmd_Argv(i));
|
|
|
|
strcat(message, " ");
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cls.state >= ca_connected)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
to = cls.netchan.remote_address;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!strlen(rcon_address->string))
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("You must either be connected,\n"
|
|
|
|
"or set the 'rcon_address' cvar\n"
|
|
|
|
"to issue rcon commands\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
NET_StringToAdr(rcon_address->string, &to);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (to.port == 0)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
to.port = BigShort(PORT_SERVER);
|
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
NET_SendPacket(NS_CLIENT, strlen(message) + 1, message, to);
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
2012-07-22 13:34:45 +00:00
|
|
|
|
|
|
|
/*
|
2013-05-01 19:12:38 +00:00
|
|
|
* Goes from a connected state to full screen
|
2012-07-22 13:34:45 +00:00
|
|
|
* console state Sends a disconnect message to
|
|
|
|
* the server This is also called on Com_Error, so
|
2010-06-18 16:07:51 +00:00
|
|
|
* it shouldn't cause any errors
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Disconnect(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
byte final[32];
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (cls.state == ca_disconnected)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (cl_timedemo && cl_timedemo->value)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
int time;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
time = Sys_Milliseconds() - cl.timedemo_start;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (time > 0)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
Com_Printf("%i frames, %3.1f seconds: %3.1f fps\n",
|
|
|
|
cl.timedemo_frames, time / 1000.0,
|
|
|
|
cl.timedemo_frames * 1000.0 / time);
|
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
VectorClear(cl.refdef.blend);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2013-05-01 19:12:38 +00:00
|
|
|
R_SetPalette(NULL);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
M_ForceMenuOff();
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
cls.connect_time = 0;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_StopCinematic();
|
2012-04-25 08:24:38 +00:00
|
|
|
#ifdef OGG
|
2010-10-14 07:33:20 +00:00
|
|
|
OGG_Stop();
|
2012-04-25 08:24:38 +00:00
|
|
|
#endif
|
2012-04-25 08:53:25 +00:00
|
|
|
#ifdef CDA
|
2010-10-14 07:33:20 +00:00
|
|
|
CDAudio_Stop();
|
2012-04-25 08:53:25 +00:00
|
|
|
#endif
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (cls.demorecording)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
CL_Stop_f();
|
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
/* send a disconnect message to the server */
|
|
|
|
final[0] = clc_stringcmd;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
strcpy((char *)final + 1, "disconnect");
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_Transmit(&cls.netchan, strlen((const char *)final), final);
|
|
|
|
Netchan_Transmit(&cls.netchan, strlen((const char *)final), final);
|
|
|
|
Netchan_Transmit(&cls.netchan, strlen((const char *)final), final);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_ClearState();
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
/* stop file download */
|
|
|
|
if (cls.download)
|
|
|
|
{
|
|
|
|
fclose(cls.download);
|
|
|
|
cls.download = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cls.state = ca_disconnected;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Disconnect_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Error(ERR_DROP, "Disconnected from server");
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* packet <destination> <contents>
|
|
|
|
*
|
|
|
|
* Contents allows \n escape character
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Packet_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
char send[2048];
|
|
|
|
int i, l;
|
|
|
|
char *in, *out;
|
|
|
|
netadr_t adr;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc() != 3)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("packet <destination> <contents>\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
NET_Config(true); /* allow remote */
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!NET_StringToAdr(Cmd_Argv(1), &adr))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Bad address\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!adr.port)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
|
|
|
adr.port = BigShort(PORT_SERVER);
|
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
in = Cmd_Argv(2);
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
out = send + 4;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
send[0] = send[1] = send[2] = send[3] = (char)0xff;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
l = strlen(in);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < l; i++)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((in[i] == '\\') && (in[i + 1] == 'n'))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
|
|
|
*out++ = '\n';
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
*out++ = in[i];
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*out = 0;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
NET_SendPacket(NS_CLIENT, out - send, send, adr);
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just sent as a hint to the client that they should
|
|
|
|
* drop to full console
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Changing_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
|
|
|
/* if we are downloading, we don't change!
|
|
|
|
This so we don't suddenly stop downloading a map */
|
|
|
|
if (cls.download)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
SCR_BeginLoadingPlaque();
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
cls.state = ca_connected; /* not active anymore, but not disconnected */
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("\nChanging map...\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The server is changing levels
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_Reconnect_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
|
|
|
/* if we are downloading, we don't change!
|
|
|
|
This so we don't suddenly stop downloading a map */
|
|
|
|
if (cls.download)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
S_StopAllSounds();
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (cls.state == ca_connected)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("reconnecting...\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
cls.state = ca_connected;
|
2012-07-22 13:34:45 +00:00
|
|
|
MSG_WriteChar(&cls.netchan.message, clc_stringcmd);
|
|
|
|
MSG_WriteString(&cls.netchan.message, "new");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cls.servername)
|
|
|
|
{
|
|
|
|
if (cls.state >= ca_connected)
|
|
|
|
{
|
|
|
|
CL_Disconnect();
|
|
|
|
cls.connect_time = cls.realtime - 1500;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
cls.connect_time = -99999; /* Hack: fire immediately */
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
cls.state = ca_connecting;
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("reconnecting...\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_PingServers_f(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
int i;
|
|
|
|
netadr_t adr;
|
|
|
|
char name[32];
|
|
|
|
char *adrstring;
|
|
|
|
cvar_t *noudp;
|
|
|
|
cvar_t *noipx;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
NET_Config(true); /* allow remote but do we even need lokal pings? */
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
/* send a broadcast packet */
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("pinging broadcast...\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
noudp = Cvar_Get("noudp", "0", CVAR_NOSET);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (!noudp->value)
|
|
|
|
{
|
|
|
|
adr.type = NA_BROADCAST;
|
|
|
|
adr.port = BigShort(PORT_SERVER);
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, adr, va("info %i", PROTOCOL_VERSION));
|
2011-10-15 16:18:26 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("pinging multicast...\n");
|
2011-10-15 16:18:26 +00:00
|
|
|
adr.type = NA_MULTICAST6;
|
|
|
|
adr.port = BigShort(PORT_SERVER);
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, adr, va("info %i", PROTOCOL_VERSION));
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
noipx = Cvar_Get("noipx", "0", CVAR_NOSET);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (!noipx->value)
|
|
|
|
{
|
|
|
|
adr.type = NA_BROADCAST_IPX;
|
|
|
|
adr.port = BigShort(PORT_SERVER);
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, adr, va("info %i", PROTOCOL_VERSION));
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send a packet to each address book entry */
|
2012-07-22 13:34:45 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_sprintf(name, sizeof(name), "adr%i", i);
|
|
|
|
adrstring = (char *)Cvar_VariableString(name);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (!adrstring || !adrstring[0])
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
continue;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("pinging %s...\n", adrstring);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!NET_StringToAdr(adrstring, &adr))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Bad address: %s\n", adrstring);
|
2010-06-18 16:07:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!adr.port)
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
adr.port = BigShort(PORT_SERVER);
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, adr, va("info %i", PROTOCOL_VERSION));
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Responses to broadcasts, etc
|
|
|
|
*/
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ConnectionlessPacket(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
char *s;
|
|
|
|
char *c;
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
MSG_BeginReading(&net_message);
|
|
|
|
MSG_ReadLong(&net_message); /* skip the -1 */
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
s = MSG_ReadStringLine(&net_message);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Cmd_TokenizeString(s, false);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
c = Cmd_Argv(0);
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("%s: %s\n", NET_AdrToString(net_from), c);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
/* server connection */
|
|
|
|
if (!strcmp(c, "client_connect"))
|
|
|
|
{
|
|
|
|
if (cls.state == ca_connected)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Dup connect received. Ignored.\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_Setup(NS_CLIENT, &cls.netchan, net_from, cls.quakePort);
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
MSG_WriteChar(&cls.netchan.message, clc_stringcmd);
|
|
|
|
MSG_WriteString(&cls.netchan.message, "new");
|
2010-06-18 16:07:51 +00:00
|
|
|
cls.state = ca_connected;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* server responding to a status broadcast */
|
|
|
|
if (!strcmp(c, "info"))
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_ParseStatusMessage();
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remote command from gui front end */
|
|
|
|
if (!strcmp(c, "cmd"))
|
|
|
|
{
|
|
|
|
if (!NET_IsLocalAddress(net_from))
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Command packet from remote host. Ignored.\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
s = MSG_ReadString(&net_message);
|
|
|
|
Cbuf_AddText(s);
|
|
|
|
Cbuf_AddText("\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print command from somewhere */
|
|
|
|
if (!strcmp(c, "print"))
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
s = MSG_ReadString(&net_message);
|
|
|
|
Com_Printf("%s", s);
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ping from somewhere */
|
|
|
|
if (!strcmp(c, "ping"))
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, net_from, "ack");
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* challenge from the server we are connecting to */
|
|
|
|
if (!strcmp(c, "challenge"))
|
|
|
|
{
|
2012-06-02 07:31:27 +00:00
|
|
|
cls.challenge = (int)strtol(Cmd_Argv(1), (char **)NULL, 10);
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_SendConnectPacket();
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* echo request from server */
|
|
|
|
if (!strcmp(c, "echo"))
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Netchan_OutOfBandPrint(NS_CLIENT, net_from, "%s", Cmd_Argv(1));
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("Unknown command.\n");
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
void
|
|
|
|
CL_ReadPackets(void)
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
while (NET_GetPacket(NS_CLIENT, &net_from, &net_message))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
|
|
|
/* remote command packet */
|
|
|
|
if (*(int *)net_message.data == -1)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_ConnectionlessPacket();
|
2010-06-18 16:07:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((cls.state == ca_disconnected) || (cls.state == ca_connecting))
|
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
continue; /* dump it if not connected */
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
|
|
|
if (net_message.cursize < 8)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("%s: Runt packet\n", NET_AdrToString(net_from));
|
2010-06-18 16:07:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* packet from server */
|
2012-07-22 13:34:45 +00:00
|
|
|
if (!NET_CompareAdr(net_from, cls.netchan.remote_address))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_DPrintf("%s:sequenced packet without connection\n",
|
|
|
|
NET_AdrToString(net_from));
|
2010-06-18 16:07:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Netchan_Process(&cls.netchan, &net_message))
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 19:47:24 +00:00
|
|
|
continue; /* wasn't accepted for some reason */
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
|
2012-07-22 13:34:45 +00:00
|
|
|
CL_ParseServerMessage();
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check timeout */
|
2012-07-22 13:34:45 +00:00
|
|
|
if ((cls.state >= ca_connected) &&
|
|
|
|
(cls.realtime - cls.netchan.last_received > cl_timeout->value * 1000))
|
2010-06-18 16:07:51 +00:00
|
|
|
{
|
|
|
|
if (++cl.timeoutcount > 5)
|
|
|
|
{
|
2012-07-22 13:34:45 +00:00
|
|
|
Com_Printf("\nServer connection timed out.\n");
|
|
|
|
CL_Disconnect();
|
2010-06-18 16:07:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2012-07-22 13:34:45 +00:00
|
|
|
{
|
2010-06-18 16:07:51 +00:00
|
|
|
cl.timeoutcount = 0;
|
2012-07-22 13:34:45 +00:00
|
|
|
}
|
2010-06-18 16:07:51 +00:00
|
|
|
}
|
2012-07-22 13:34:45 +00:00
|
|
|
|