Beispiel #1
0
/*
 * =================
 * UI_PushMenu
 * =================
 */
void UI_PushMenu(void (*draw)(void), const char *(*key)(int k))
{
    int i;

    if ((Cvar_VariableValue("maxclients") == 1) && Com_ServerState() && !cls.consoleActive)     // Knightmare added
    {
        Cvar_Set("paused", "1");
    }

    // Knightmare- if just opened menu, and ingame and not DM, grab screen first
    if ((cls.key_dest != key_menu) && !Cvar_VariableValue("deathmatch") &&
        (Com_ServerState() == 2))          //ss_game
    {           //&& !cl.cinematictime && Com_ServerState())
        R_GrabScreen();
    }

    // if this menu is already present, drop back to that level
    // to avoid stacking menus by hotkeys
    for (i = 0; i < m_menudepth; i++)
    {
        if ((m_layers[i].draw == draw) &&
            (m_layers[i].key == key))
        {
            m_menudepth = i;
        }
    }

    if (i == m_menudepth)
    {
        if (m_menudepth >= MAX_MENU_DEPTH)
        {
            Com_Error(ERR_FATAL, "UI_PushMenu: MAX_MENU_DEPTH");
        }
        m_layers[m_menudepth].draw = m_drawfunc;
        m_layers[m_menudepth].key  = m_keyfunc;
        m_menudepth++;
    }

    m_drawfunc = draw;
    m_keyfunc  = key;

    m_entersound = true;

    // Knightmare- added Psychospaz's mouse support
    UI_RefreshCursorLink();
    UI_RefreshCursorButtons();

    cls.key_dest = key_menu;
}
Beispiel #2
0
void CL_Connect_f(void)
{
  char *server;

  if (Cmd_Argc() != 2) {
    Com_Printf("usage: connect <server>\n");
    return;
  }

  if (Com_ServerState()) {
    /* if running a local server, kill it and reissue
       note: this is connect with the save game system */
    SV_Shutdown("Server quit\n", false);
  } else {
    CL_Disconnect();
  }

  server = Cmd_Argv(1);

  NET_Config(true); /* allow remote */

  CL_Disconnect();

  cls.state = ca_connecting;
  Q_strlcpy(cls.servername, server, sizeof(cls.servername));
  cls.connect_time = -99999; /* HACK: CL_CheckForResend() will fire immediately */
}
Beispiel #3
0
/**
 * @brief Search the index in the config strings relative to a given start
 * @param name The value of the config string to search the index for
 * @param start The relative start point for the search
 * @param max The max. searched entries in the config string before giving up
 * @param create if @c true the value will get written into the config strings (appended)
 * @return @c 0 if not found
 */
static unsigned int SV_FindIndex (const char *name, int start, int max, qboolean create)
{
	int i;

	if (!name || !name[0])
		return 0;

	for (i = 1; i < max && SV_GetConfigString(start + i)[0] != '\0'; i++) {
		const char *configString = SV_GetConfigString(start + i);
		if (Q_streq(configString, name))
			return i;
	}

	if (!create)
		return 0;

	if (i == max)
		Com_Error(ERR_DROP, "*Index: overflow '%s' start: %i, max: %i", name, start, max);

	SV_SetConfigString(start + i, name);

	if (Com_ServerState() != ss_loading) {	/* send the update to everyone */
		struct dbuffer *msg = new_dbuffer();
		NET_WriteByte(msg, svc_configstring);
		NET_WriteShort(msg, start + i);
		NET_WriteString(msg, name);
		SV_Multicast(~0, msg);
	}

	return i;
}
Beispiel #4
0
/**
 * @brief Reset cheat cvar values to default
 * @sa CL_SendCommand
 */
void Cvar_FixCheatVars (void)
{
	if (!(Com_ServerState() && !Cvar_GetInteger("sv_cheats")))
		return;

	for (cvar_t* var = cvarVars; var; var = var->next) {
		if (!(var->flags & CVAR_CHEAT))
			continue;

		if (!var->defaultString) {
			Com_Printf("Cheat cvars: Cvar %s has no default value\n", var->name);
			continue;
		}

		if (Q_streq(var->string, var->defaultString))
			continue;

		/* also remove the oldString value here */
		Mem_Free(var->oldString);
		var->oldString = nullptr;
		Mem_Free(var->string);
		var->string = Mem_PoolStrDup(var->defaultString, com_cvarSysPool, 0);
		var->value = atof(var->string);
		var->integer = atoi(var->string);

		Com_Printf("'%s' is a cheat cvar - activate sv_cheats to use it.\n", var->name);
	}
}
Beispiel #5
0
/**
 * @brief Sets the @c cls.state to @c ca_disconnected and informs the server
 * @sa CL_Drop
 * @note Goes from a connected state to disconnected state
 * Sends a disconnect message to the server
 * This is also called on @c Com_Error, so it shouldn't cause any errors
 */
void CL_Disconnect (void)
{
	if (cls.state < ca_connecting)
		return;

	Com_Printf("Disconnecting...\n");

	/* send a disconnect message to the server */
	if (!Com_ServerState()) {
		dbuffer msg;
		NET_WriteByte(&msg, clc_stringcmd);
		NET_WriteString(&msg, NET_STATE_DISCONNECT "\n");
		NET_WriteMsg(cls.netStream, msg);
		/* make sure, that this is send */
		NET_Wait(0);
	}

	NET_StreamFinished(cls.netStream);
	cls.netStream = nullptr;

	CL_ClearState();

	S_Stop();

	R_ShutdownModels(false);
	R_FreeWorldImages();

	CL_SetClientState(ca_disconnected);
	CL_ClearBattlescapeEvents();
	GAME_EndBattlescape();
}
/**
 * @brief Updates needed cvar for loading screens
 * @param[in] mapString The mapstring of the map that is currently loaded
 * @note If @c mapString is NULL the @c sv_mapname cvar is used
 * @return The loading/background pic path
 */
static const image_t* SCR_SetLoadingBackground (const char *mapString)
{
	const char *mapname;
	image_t* image;

	if (!mapString || Com_ServerState())
		mapname = Cvar_GetString("sv_mapname");
	else {
		mapname = mapString;
		Cvar_Set("sv_mapname", mapString);
	}

	/* we will try to load the random map shots by just removing the + from the beginning */
	if (mapname[0] == '+')
		mapname++;

	image = R_FindImage(va("pics/maps/loading/%s", mapname), it_worldrelated);
	if (image == r_noTexture)
		image = R_FindImage("pics/maps/loading/default", it_pic);

	/* strip away the pics/ part */
	Cvar_Set("mn_mappicbig", image->name + 5);

	return image;
}
Beispiel #7
0
void M_PushMenu ( menuframework_s *menu )
{
	int		i;

	if (Cvar_VariableIntValue ("maxclients") == 1 
		&& Com_ServerState () && !cl_paused->integer)
		Cvar_Set ("paused", "1");

	// if this menu is already present, drop back to that level
	// to avoid stacking menus by hotkeys
	for( i=0 ; i<m_menudepth ; i++ ) {
		if( m_layers[i] == menu ) {
			break;
		}
	}

	if (i == m_menudepth)
	{
		if (m_menudepth >= MAX_MENU_DEPTH)
			Com_Error (ERR_FATAL, "M_PushMenu: MAX_MENU_DEPTH");
		m_layers[m_menudepth++] = menu;
	}
	else {
		m_menudepth = i+1;
	}

	m_active = menu;

	m_entersound = true;

	cls.key_dest = key_menu;
}
Beispiel #8
0
/**
 * @brief
 * @note Called after precache was sent from the server
 * @sa SV_Configstrings_f
 * @sa CL_Precache_f
 */
void CL_RequestNextDownload (void)
{
	if (cls.state != ca_connected) {
		Com_Printf("CL_RequestNextDownload: Not connected (%i)\n", cls.state);
		return;
	}

	/* Use the map data from the server */
	cl.mapTiles = SV_GetMapTiles();
	cl.mapData = SV_GetMapData();

	/* as a multiplayer client we have to load the map here and
	 * check the compatibility with the server */
	if (!Com_ServerState() && !CL_CanMultiplayerStart())
		return;

	CL_ViewLoadMedia();

	dbuffer msg(7);
	/* send begin */
	/* this will activate the render process (see client state ca_active) */
	NET_WriteByte(&msg, clc_stringcmd);
	/* see CL_StartGame */
	NET_WriteString(&msg, NET_STATE_BEGIN "\n");
	NET_WriteMsg(cls.netStream, msg);

	cls.waitingForStart = CL_Milliseconds();

	S_MumbleLink();
}
Beispiel #9
0
/*
================
CL_Connect_f

================
*/
void CL_Connect_f (void)
{
	char	*server;

	if (Cmd_Argc() != 2)
	{
		Com_Printf ("usage: connect <server>\n");
		return;	
	}
	
	if (Com_ServerState ())
	{	// if running a local server, kill it and reissue
		SV_Shutdown (va("Server quit\n", msg), false);
	}
	else
	{
		CL_Disconnect ();
	}

	server = Cmd_Argv (1);

	NET_Config (true);		// allow remote

	CL_Disconnect ();

	cls.state = ca_connecting;
	strncpy (cls.servername, server, sizeof(cls.servername)-1);
	cls.connect_time = -99999;	// CL_CheckForResend() will fire immediately
}
Beispiel #10
0
void StartServerActionFunc (void *self)
{
	char	startmap[1024];
    float timelimit;
    float fraglimit;
    float maxclients;
	char	*spot;

	strcpy (startmap, strchr (mapnames[s_startmap_list.curvalue], '\n') + 1);

    maxclients = (float)strtod(s_maxclients_field.buffer, (char **)NULL);
    timelimit = (float)strtod(s_timelimit_field.buffer, (char **)NULL);
    fraglimit = (float)strtod(s_fraglimit_field.buffer, (char **)NULL);

	Cvar_SetValue ("maxclients", Q_Clamp (0, maxclients, maxclients));
	Cvar_SetValue ("timelimit", Q_Clamp (0, timelimit, timelimit));
	Cvar_SetValue ("fraglimit", Q_Clamp (0, fraglimit, fraglimit));
	Cvar_Set ("hostname", s_hostname_field.buffer);

	Cvar_SetValue ("deathmatch", (float)!s_rules_box.curvalue);
	Cvar_SetValue ("coop", (float)s_rules_box.curvalue);

	spot = NULL;

	// coop spawns
	if (s_rules_box.curvalue == 1)
	{
		if (Q_stricmp (startmap, "bunk1") == 0)
			spot = "start";
		else if (Q_stricmp (startmap, "mintro") == 0)
			spot = "start";
		else if (Q_stricmp (startmap, "fact1") == 0)
			spot = "start";
		else if (Q_stricmp (startmap, "power1") == 0)
			spot = "pstart";
		else if (Q_stricmp (startmap, "biggun") == 0)
			spot = "bstart";
		else if (Q_stricmp (startmap, "hangar1") == 0)
			spot = "unitstart";
		else if (Q_stricmp (startmap, "city1") == 0)
			spot = "unitstart";
		else if (Q_stricmp (startmap, "boss1") == 0)
			spot = "bosstart";
	}

	if (spot)
	{
		if (Com_ServerState())
			Cbuf_AddText ("disconnect\n");

		Cbuf_AddText (va ("gamemap \"*%s$%s\"\n", startmap, spot));
	}
	else
	{
		Cbuf_AddText (va ("map %s\n", startmap));
	}

	M_ForceMenuOff ();
}
Beispiel #11
0
/*
==================
CL_ParseServerData
==================
*/
void CL_ParseServerData(void)
{
    extern cvar_t * fs_gamedirvar;
    char * str;
    int i;

    Com_DPrintf("Serverdata packet received.\n");
    //
    // wipe the client_state_t struct
    //
    CL_ClearState();
    cls.state = ca_connected;

    // parse protocol version number
    i = MSG_ReadLong(&net_message);
    cls.serverProtocol = i;

    // BIG HACK to let demos from release work with the 3.0x patch!!!
    if (Com_ServerState() && PROTOCOL_VERSION == 34)
    {
    }
    else if (i != PROTOCOL_VERSION)
    {
        Com_Error(ERR_DROP, "Server returned version %i, not %i", i, PROTOCOL_VERSION);
    }

    cl.servercount = MSG_ReadLong(&net_message);
    cl.attractloop = MSG_ReadByte(&net_message);

    // game directory
    str = MSG_ReadString(&net_message);
    strncpy(cl.gamedir, str, sizeof(cl.gamedir) - 1);

    // set gamedir
    if ((*str && (!fs_gamedirvar->string || !*fs_gamedirvar->string || strcmp(fs_gamedirvar->string, str))) || (!*str && (fs_gamedirvar->string || *fs_gamedirvar->string)))
        Cvar_Set("game", str);

    // parse player entity number
    cl.playernum = MSG_ReadShort(&net_message);

    // get the full level name
    str = MSG_ReadString(&net_message);

    if (cl.playernum == -1)
    {
        // playing a cinematic or showing a pic, not a level
        SCR_PlayCinematic(str);
    }
    else
    {
        // separate the printfs so the server message can have a color
        Com_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n");
        Com_Printf("%c%s\n", 2, str);

        // need to prep refresh at next opportunity
        cl.refresh_prepped = false;
    }
}
Beispiel #12
0
void M_Menu_SaveGame_f (void)
{
	if (!Com_ServerState())
		return;		// not playing a game

	SaveGame_MenuInit();
	M_PushMenu( &s_savegame_menu );
	Create_Savestrings ();
}
Beispiel #13
0
/*
==================
LegacyProtocol
A utility function that determines
if parsing of old protocol should be used.
==================
*/
qboolean LegacyProtocol (void)
{
	//if (dedicated->value)	// Server always uses new protocol
	//	return false;
	if ( (Com_ServerState() && cls.serverProtocol <= OLD_PROTOCOL_VERSION)
		|| (cls.serverProtocol == OLD_PROTOCOL_VERSION) )
		return true;
	return false;
}
Beispiel #14
0
void M_Menu_SaveGame_f(void)
{
    if (!Com_ServerState())
    {
        return;                 // not playing a game
    }
    SaveGame_MenuInit();
    UI_PushMenu(SaveGame_MenuDraw, SaveGame_MenuKey);
    Create_Savestrings();
}
Beispiel #15
0
/*
==================
CL_Pause_f
==================
*/
void CL_Pause_f (void)
{
	// never pause in multiplayer
	if (Cvar_VariableValue ("maxclients") > 1 || !Com_ServerState ())
	{
		Cvar_SetValue ("paused", 0);
		return;
	}

	Cvar_SetValue ("paused", !cl_paused->value);
}
/**
 * @brief Check whether we are in a tactical mission as server or as client. But this
 * only means that we are able to render the map - not that the game is running (the
 * team can still be missing - see @c CL_BattlescapeRunning)
 * @note handles multiplayer and singleplayer
 * @sa CL_BattlescapeRunning
 * @return true when we are in battlefield
 */
bool CL_OnBattlescape (void)
{
	/* server_state is set to zero (ss_dead) on every battlefield shutdown */
	if (Com_ServerState())
		return true; /* server */

	/* client */
	if (cls.state >= ca_connected)
		return true;

	return false;
}
Beispiel #17
0
/*
=================
UI_ForceMenuOff
=================
*/
void UI_ForceMenuOff (void)
{
	// Knightmare- added Psychospaz's mouse support
	UI_RefreshCursorLink();
	m_drawfunc = 0;
	m_keyfunc = 0;
	cls.key_dest = key_game;
	m_menudepth = 0;
	Key_ClearStates ();
	if (!cls.consoleActive && Cvar_VariableValue ("maxclients") == 1 && Com_ServerState()) // Knightmare added
		Cvar_Set ("paused", "0");
}
Beispiel #18
0
/*
 * Resend a connect message if the last one has timed out
 */
void
CL_CheckForResend(void)
{
	netadr_t adr;

	/* if the local server is running and we aren't just connect */
	if ((cls.state == ca_disconnected) && Com_ServerState())
	{
		cls.state = ca_connecting;
		Q_strlcpy(cls.servername, "localhost", sizeof(cls.servername));
		/* we don't need a challenge on the localhost */
		CL_SendConnectPacket();
		return;
	}

	/* resend if we haven't gotten a reply yet */
	if (cls.state != ca_connecting)
	{
		return;
	}

	if (cls.realtime - cls.connect_time < 3000)
	{
		return;
	}

	if (!NET_StringToAdr(cls.servername, &adr))
	{
		Com_Printf("Bad server address\n");
		cls.state = ca_disconnected;
		return;
	}

	if (adr.port == 0)
	{
		adr.port = BigShort(PORT_SERVER);
	}

	cls.connect_time = cls.realtime;

	Com_Printf("Connecting to %s...\n", cls.servername);

	Netchan_OutOfBandPrint(NS_CLIENT, adr, "getchallenge\n");
}
Beispiel #19
0
/**
 * @sa CL_Frame
 */
static void CL_SendCommand (void)
{
	/* get new key events */
	IN_SendKeyEvents();

	/* process console commands */
	Cbuf_Execute();

	/* send intentions now */
	CL_SendChangedUserinfos();

	/* fix any cheating cvars */
	Cvar_FixCheatVars();

	switch (cls.state) {
	case ca_disconnected:
		/* if the local server is running and we aren't connected then connect */
		if (Com_ServerState()) {
			cls.servername[0] = '\0';
			cls.serverport[0] = '\0';
			CL_SetClientState(ca_connecting);
			return;
		}
		break;
	case ca_connecting:
		if (CL_Milliseconds() - cls.connectTime > cl_connecttimeout->integer) {
			if (GAME_IsMultiplayer())
				Com_Error(ERR_DROP, "Server is not reachable");
		}
		break;
	case ca_connected:
		if (cls.waitingForStart) {
			if (CL_Milliseconds() - cls.waitingForStart > cl_connecttimeout->integer) {
				Com_Error(ERR_DROP, "Server aborted connection - the server didn't response in %is. You can try to increase the cvar cl_connecttimeout",
						cl_connecttimeout->integer / 1000);
			} else {
				SCR_DrawLoading(100);
			}
		}
		break;
	default:
		break;
	}
}
Beispiel #20
0
/**
 * @sa SV_ExecuteClientMessage
 */
static void SV_ExecuteUserCommand (client_t * cl, const char *s)
{
	const ucmd_t *u;

	Cmd_TokenizeString(s, qfalse);

	for (u = ucmds; u->name; u++)
		if (Q_streq(Cmd_Argv(0), u->name)) {
			Com_DPrintf(DEBUG_SERVER, "SV_ExecuteUserCommand: %s\n", s);
			u->func(cl);
			return;
		}

	if (Com_ServerState() == ss_game) {
		Com_DPrintf(DEBUG_SERVER, "SV_ExecuteUserCommand: client command: %s\n", s);
		TH_MutexLock(svs.serverMutex);
		svs.ge->ClientCommand(cl->player);
		TH_MutexUnlock(svs.serverMutex);
	}
}
Beispiel #21
0
static void CL_GridRecalcRouting (const le_t* le)
{
	/* We ALWAYS check against a model, even if it isn't in use.
	 * An unused model is NOT included in the inline list, so it doesn't get
	 * traced against. */
	if (!le->model1 || le->inlineModelName[0] != '*')
		return;

	if (Com_ServerState())
		return;

	const cBspModel_t* model = CM_InlineModel(cl.mapTiles, le->inlineModelName);
	if (!model) {
		return;
	}
	AABB absBox(model->cbmBox);
	absBox.shift(model->origin);
	GridBox rerouteBox(absBox);

	Grid_RecalcRouting(cl.mapTiles, cl.mapData->routing, le->inlineModelName, rerouteBox, cl.leInlineModelList);
}
Beispiel #22
0
/*
=================
CL_CheckForResend

Resend a connect message if the last one has timed out
=================
*/
void CL_CheckForResend (void)
{
	netadr_t	adr;

	// if the local server is running and we aren't
	// then connect
	if (cls.state == ca_disconnected && Com_ServerState() )
	{
		cls.state = ca_connecting;
		strncpy (cls.servername, "localhost", sizeof(cls.servername)-1);
		// we don't need a challenge on the localhost
		CL_SendConnectPacket ();
		return;
//		cls.connect_time = -99999;	// CL_CheckForResend() will fire immediately
	}

	// resend if we haven't gotten a reply yet
	if (cls.state != ca_connecting)
		return;

	if (cls.realtime - cls.connect_time < 3000)
		return;

	if (!NET_StringToAdr (cls.servername, &adr))
	{
		Com_Printf ("Bad server address\n");
		cls.state = ca_disconnected;
		return;
	}
	if (adr.port == 0)
		adr.port = BigShort (PORT_SERVER);

	cls.connect_time = cls.realtime;	// for retransmit requests

	Com_Printf ("Connecting to %s...\n", cls.servername);

	Netchan_OutOfBandPrint (NS_CLIENT, adr, "getchallenge\n");
}
Beispiel #23
0
/**
 * @sa CL_ParseConfigString
 */
static void SV_Configstring (int index, const char *fmt, ...)
{
	char val[MAX_TOKEN_CHARS * MAX_TILESTRINGS];
	va_list argptr;

	if (!Com_CheckConfigStringIndex(index))
		SV_error("configstring: bad index %i", index);

	va_start(argptr, fmt);
	Q_vsnprintf(val, sizeof(val), fmt, argptr);
	va_end(argptr);

	SV_SetConfigString(index, val);

	if (Com_ServerState() != ss_loading) { /* send the update to everyone */
		dbuffer msg(4 + strlen(val));
		NET_WriteByte(&msg, svc_configstring);
		NET_WriteShort(&msg, index);
		NET_WriteString(&msg, val);

		/* send to all clients */
		SV_Multicast(~0, msg);
	}
}
Beispiel #24
0
/**
 * @sa CL_ParseConfigString
 */
static void SV_Configstring (int index, const char *fmt, ...)
{
	char val[MAX_TOKEN_CHARS * MAX_TILESTRINGS];
	va_list argptr;

	if (index < 0 || index >= MAX_CONFIGSTRINGS)
		Com_Error(ERR_DROP, "configstring: bad index %i", index);

	va_start(argptr, fmt);
	Q_vsnprintf(val, sizeof(val), fmt, argptr);
	va_end(argptr);

	SV_SetConfigString(index, val);

	if (Com_ServerState() != ss_loading) { /* send the update to everyone */
		struct dbuffer *msg = new_dbuffer();
		NET_WriteByte(msg, svc_configstring);
		NET_WriteShort(msg, index);
		NET_WriteString(msg, val);

		/* send to all clients */
		SV_Multicast(~0, msg);
	}
}
Beispiel #25
0
/**
 * @brief Sends the first message from the server to a connected client.
 * This will be sent on the initial connection and upon each server load.
 * Client reads via CL_ParseServerData in cl_parse.c
 * @sa CL_Reconnect_f
 * @sa CL_ConnectionlessPacket
 */
static void SV_New_f (client_t *cl)
{
	Com_DPrintf(DEBUG_SERVER, "New() from %s\n", cl->name);

	if (cl->state != cs_connected) {
		if (cl->state == cs_spawning) {
			/* client typed 'reconnect/new' while connecting. */
			Com_Printf("SV_New_f: client typed 'reconnect/new' while connecting\n");
			SV_ClientCommand(cl, "\ndisconnect\nreconnect\n");
			SV_DropClient(cl, "");
		} else
			Com_DPrintf(DEBUG_SERVER, "WARNING: Illegal 'new' from %s, client state %d. This shouldn't happen...\n", cl->name, cl->state);
		return;
	}

	/* client state to prevent multiple new from causing high cpu / overflows. */
	SV_SetClientState(cl, cs_spawning);

	/* serverdata needs to go over for all types of servers
	 * to make sure the protocol is right, and to set the gamedir */

	/* send the serverdata */
	{
		const int playernum = cl - SV_GetClient(0);
		struct dbuffer *msg = new_dbuffer();
		NET_WriteByte(msg, svc_serverdata);
		NET_WriteLong(msg, PROTOCOL_VERSION);

		NET_WriteShort(msg, playernum);

		/* send full levelname */
		NET_WriteString(msg, SV_GetConfigString(CS_NAME));

		NET_WriteMsg(cl->stream, msg);
	}

	/* game server */
	if (Com_ServerState() == ss_game) {
		int i;
		for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
			const char *configString;
			/* CS_TILES and CS_POSITIONS can stretch over multiple configstrings,
			 * so don't send the middle parts again. */
			if (i > CS_TILES && i < CS_POSITIONS)
				continue;
			if (i > CS_POSITIONS && i < CS_MODELS)
				continue;

			configString = SV_GetConfigString(i);
			if (configString[0] != '\0') {
				struct dbuffer *msg = new_dbuffer();
				Com_DPrintf(DEBUG_SERVER, "sending configstring %d: %s\n", i, configString);
				NET_WriteByte(msg, svc_configstring);
				NET_WriteShort(msg, i);
				NET_WriteString(msg, configString);
				/* enqueue and free msg */
				NET_WriteMsg(cl->stream, msg);
			}
		}
	}

	SV_ClientCommand(cl, "precache\n");
}
Beispiel #26
0
void
CL_ParseServerData(void)
{
    extern cvar_t *fs_gamedirvar;
    char *str;
    int i;

    Com_DPrintf("Serverdata packet received.\n");

    /* wipe the client_state_t struct */
    CL_ClearState();
    cls.state = ca_connected;

    /* parse protocol version number */
    i = MSG_ReadLong(&net_message);
    cls.serverProtocol = i;

    /* another demo hack */
    if (Com_ServerState() && (PROTOCOL_VERSION == 34))
    {
    }
    else if (i != PROTOCOL_VERSION)
    {
        Com_Error(ERR_DROP, "Server returned version %i, not %i",
                  i, PROTOCOL_VERSION);
    }

    cl.servercount = MSG_ReadLong(&net_message);
    cl.attractloop = MSG_ReadByte(&net_message);

    /* game directory */
    str = MSG_ReadString(&net_message);
    Q_strlcpy(cl.gamedir, str, sizeof(cl.gamedir));

    /* set gamedir */
    if ((*str && (!fs_gamedirvar->string || !*fs_gamedirvar->string ||
                  strcmp(fs_gamedirvar->string, str))) ||
            (!*str && (fs_gamedirvar->string || *fs_gamedirvar->string)))
    {
        Cvar_Set("game", str);
    }

    /* parse player entity number */
    cl.playernum = MSG_ReadShort(&net_message);

    /* get the full level name */
    str = MSG_ReadString(&net_message);

    if (cl.playernum == -1)
    {
        /* playing a cinematic or showing a pic, not a level */
        SCR_PlayCinematic(str);
    }
    else
    {
        /* seperate the printfs so the server
         * message can have a color */
        Com_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n");
        Com_Printf("%c%s\n", 2, str);

        /* need to prep refresh at next oportunity */
        cl.refresh_prepped = false;
    }
}
Beispiel #27
0
/*
============
Cvar_Set2
============
*/
static cvar_t *Cvar_Set2 (const char *var_name, const char *value, qboolean force)
{
	cvar_t	*var;
	char *old_string;

	Q_assert (var_name != NULL);
	Q_assert (value != NULL);
	
	if (var_name[0] == '$' && !force)
	{
		Com_Printf ("%s is write protected.\n", LOG_GENERAL, var_name);
		return NULL;
	}

	var = Cvar_FindVar (var_name);
	if (!var)
	{	// create it
		return Cvar_Get (var_name, value, 0);
	}

	if (var->flags & (CVAR_USERINFO | CVAR_SERVERINFO))
	{
		if (!Cvar_InfoValidate (value))
		{
			Com_Printf("invalid info cvar value\n", LOG_GENERAL);
			return var;
		}
	}

	if (!force)
	{
#ifdef _DEBUG
		if (var->flags & CVAR_NOSET && !Cvar_IntValue ("developer"))
#else
		if (var->flags & CVAR_NOSET)
#endif
		{
			Com_Printf ("%s is write protected.\n", LOG_GENERAL, var_name);
			return var;
		}

		if (var->flags & CVAR_LATCH)
		{
			if (var->latched_string)
			{
				if (strcmp(value, var->latched_string) == 0)
					return var;
				Z_Free (var->latched_string);
			}
			else
			{
				if (strcmp(value, var->string) == 0)
					return var;
			}

			if (Com_ServerState())
			{
				Com_Printf ("%s will be changed for next map.\n", LOG_GENERAL, var_name);
				var->latched_string = CopyString(value, TAGMALLOC_CVAR);
			}
			else
			{
				//memleak fix, thanks Maniac-
				Z_Free (var->string);
				var->string = CopyString(value, TAGMALLOC_CVAR);
				var->value = (float)atof (var->string);
				var->intvalue = (int)var->value;

				//r1: fix 0 case
				if (!var->intvalue && FLOAT_NE_ZERO(var->value))
					var->intvalue = 1;

				if (!strcmp(var->name, "game"))
				{
					FS_SetGamedir (var->string);
					if (!Cvar_IntValue ("dedicated"))
						FS_ExecConfig ("autoexec.cfg");
				}
			}
			return var;
		}
	}
	else
	{
		if (var->latched_string)
		{
			Z_Free (var->latched_string);
			var->latched_string = NULL;
		}
	}

	if (!strcmp(value, var->string))
		return var;		// not changed

	old_string = var->string;
	var->string = CopyString(value, TAGMALLOC_CVAR);

	var->value = (float)atof (var->string);
	var->intvalue = (int)var->value;

	//r1: fix 0 case
	if (!var->intvalue && FLOAT_NE_ZERO(var->value))
		var->intvalue = 1;

	var->modified = true;

	if (var->changed)
		var->changed (var, old_string, var->string);

	if (var->flags & CVAR_USERINFO)
		userinfo_modified = true;	// transmit at next oportunity
	
	Z_Free (old_string);	// free the old value string

	return var;
}
Beispiel #28
0
/**
 * @brief Sets a cvar values
 * Handles write protection and latched cvars as expected
 * @param[in] varName Which cvar
 * @param[in] value Set the cvar to the value specified by 'value'
 * @param[in] force Force the update of the cvar
 */
static cvar_t* Cvar_Set2 (const char* varName, const char* value, bool force)
{
	cvar_t* var;

	if (!value)
		return nullptr;

	var = Cvar_FindVar(varName);
	/* create it */
	if (!var)
		return Cvar_GetOrCreate(varName, value);

	if (var->flags & (CVAR_USERINFO | CVAR_SERVERINFO)) {
		if (!Cvar_InfoValidate(value)) {
			Com_Printf("invalid info cvar value '%s' of cvar '%s'\n", value, varName);
			return var;
		}
	}

	if (!force) {
		if (var->flags & CVAR_NOSET) {
			Com_Printf("%s is write protected.\n", varName);
			return var;
		}
#ifndef DEBUG
		if (var->flags & CVAR_DEVELOPER) {
			Com_Printf("%s is a developer cvar.\n", varName);
			return var;
		}
#endif

		if (var->flags & CVAR_LATCH) {
			if (var->latchedString) {
				if (Q_streq(value, var->latchedString))
					return var;
				Mem_Free(var->latchedString);
				var->latchedString = nullptr;
			} else {
				if (Q_streq(value, var->string))
					return var;
			}

			/* if we are running a server */
			if (Com_ServerState()) {
				Com_Printf("%s will be changed for next game.\n", varName);
				var->latchedString = Mem_PoolStrDup(value, com_cvarSysPool, 0);
			} else {
				Mem_Free(var->oldString);
				var->oldString = var->string;
				var->string = Mem_PoolStrDup(value, com_cvarSysPool, 0);
				var->value = atof(var->string);
				var->integer = atoi(var->string);
			}

			if (var->check && var->check(var))
				Com_Printf("Invalid value for cvar %s\n", varName);

			return var;
		}
	} else {
		Mem_Free(var->latchedString);
		var->latchedString = nullptr;
	}

	if (Q_streq(value, var->string))
		return var;				/* not changed */

	if (var->flags & CVAR_R_MASK)
		Com_SetRenderModified(true);

	Mem_Free(var->oldString);		/* free the old value string */
	var->oldString = var->string;
	var->modified = true;

	if (var->flags & CVAR_USERINFO)
		Com_SetUserinfoModified(true);	/* transmit at next opportunity */

	var->string = Mem_PoolStrDup(value, com_cvarSysPool, 0);
	var->value = atof(var->string);
	var->integer = atoi(var->string);

	if (var->check && var->check(var)) {
		Com_Printf("Invalid value for cvar %s\n", varName);
		return var;
	}

	Cvar_ExecuteChangeListener(var);

	return var;
}
Beispiel #29
0
Datei: cmd.c Projekt: Slipyx/r1q2
/*
===============
Cmd_Exec_f
===============
*/
void Cmd_Exec_f (void)
{
	const char *path;
	char	*f, *p;
	int	len;
	char	f2[COMMAND_BUFFER_SIZE+2];

	if (Cmd_Argc () != 2)
	{
		Com_Printf ("exec <filename> : execute a config file\n", LOG_GENERAL);
		return;
	}

	path = Cmd_Argv(1);

	//r1: normalize
	while ((p = strchr (path, '\\')) != NULL)
		p[0] = '/';

	//r1: deny traversing outside the q2 directory
	p = strstr (path, "../");
	if (p)
	{
		p += 3;
		if (strstr (p, "../"))
		{
			Com_Printf ("WARNING: Illegal config path '%s'\n", LOG_GENERAL, path);
			return;
		}
	}

	//r1: sanity check length first so people don't exec pak0.pak and eat 300MB ram
	len = FS_LoadFile (path, NULL);
	if (len > COMMAND_BUFFER_SIZE - 2)
	{
		Com_Printf ("WARNING: %s exceeds maximum config file length\n", LOG_GENERAL, Cmd_Argv(1));
		len = COMMAND_BUFFER_SIZE - 2;
	}

	len = FS_LoadFile (path, (void **)&f);
	if (!f || len <= 0)
	{
		//ugly hack to avoid printing missing config errors before startup finishes
		if (q2_initialized)
			Com_Printf ("couldn't exec %s\n", LOG_GENERAL, path);
		return;
	}

#ifndef DEDICATED_ONLY
	if (Com_ServerState())
#endif
		Com_Printf ("execing %s\n", LOG_GENERAL, path);
#ifndef DEDICATED_ONLY
	else
		Com_DPrintf ("execing %s\n",path);
#endif

	// the file doesn't have a trailing 0, so we need to copy it off
	//f2 = Z_TagMalloc(len+2, TAGMALLOC_CMDBUFF);
	//f2 = alloca (len+2);
	memcpy (f2, f, len);

	//r1: fix for "no trailing newline = 'u or s'" bug.
	f2[len] = '\n';
	f2[len+1] = 0;

	if ((p = strchr(f2, '\r')) != NULL && *(p+1) != '\n')
		Com_Printf ("WARNING: Raw \\r found in config file %s\n", LOG_GENERAL|LOG_WARNING, path);

	Cbuf_InsertText (f2);

	//Z_Free (f2);
	FS_FreeFile (f);
}
Beispiel #30
0
/*
============
Cvar_Set2
============
*/
cvar_t *Cvar_Set2 (char *var_name, char *value, qboolean force)
{
	cvar_t	*var;

	var = Cvar_FindVar (var_name);
	if (!var)
	{	// create it
		return Cvar_Get (var_name, value, 0);
	}

	if (var->flags & (CVAR_USERINFO | CVAR_SERVERINFO))
	{
		if (!Cvar_InfoValidate (value))
		{
			Com_Printf("invalid info cvar value\n");
			return var;
		}
	}

	if (!force)
	{
		if (var->flags & CVAR_NOSET)
		{
			Com_Printf ("%s is write protected.\n", var_name);
			return var;
		}

		if (var->flags & CVAR_LATCH)
		{
			if (var->latched_string)
			{
				if (strcmp(value, var->latched_string) == 0)
					return var;
				Z_Free (var->latched_string);
			}
			else
			{
				if (strcmp(value, var->string) == 0)
					return var;
			}

			if (Com_ServerState())
			{
				Com_Printf ("%s will be changed for next game.\n", var_name);
				var->latched_string = CopyString(value);
			}
			else
			{
				var->string = CopyString(value);
				var->value = atof (var->string);
				if (!strcmp(var->name, "game"))
				{
					FS_SetGame(var->string);
					FS_ExecAutoexec ();
				}
			}
			return var;
		}
	}
	else
	{
		if (var->latched_string)
		{
			Z_Free (var->latched_string);
			var->latched_string = NULL;
		}
	}

	if (!strcmp(value, var->string))
		return var;		// not changed

	var->modified = true;

	if (var->flags & CVAR_USERINFO)
		userinfo_modified = true;	// transmit at next oportunity
	
	Z_Free (var->string);	// free the old value string
	
	var->string = CopyString(value);
	var->value = atof (var->string);

	return var;
}