예제 #1
0
파일: cvar.c 프로젝트: turol/webquake2
/*
============
Cvar_GetLatchedVars

Any variables with latched values will now be updated
============
*/
void Cvar_GetLatchedVars (void)
{
	cvar_t	*var;
	char	*old_string;

	for (var = cvar_vars ; var ; var = var->next)
	{
		if (!var->latched_string)
			continue;

		old_string = var->string;

		var->string = var->latched_string;
		var->latched_string = NULL;
		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 (var->changed)
			var->changed (var, old_string, var->string);

		Z_Free (old_string);

		if (!strcmp(var->name, "game"))
		{
			FS_SetGamedir (var->string);
			if (!Cvar_IntValue ("dedicated"))
				FS_ExecConfig ("autoexec.cfg");
		}
	}
}
예제 #2
0
파일: cvar.c 프로젝트: turol/webquake2
/*
============
Cvar_GameGet
============
R1CH: Use as a wrapper to cvars requested by the mod. Can then apply filtering
to them such as disallowing serverinfo set by mod.
*/
cvar_t * EXPORT Cvar_GameGet (const char *var_name, const char *var_value, int flags)
{
	if (Cvar_IntValue("sv_no_game_serverinfo"))
		flags &= ~CVAR_SERVERINFO;

	return Cvar_Get (var_name, var_value, flags);
}
예제 #3
0
/*
====================
NET_OpenIP
====================
*/
void NET_OpenIP (int flags)
{
	cvar_t	*ip;
	int		port;
	int		dedicated;

	net_total_in = net_packets_in = net_total_out = net_packets_out = 0;
	net_inittime = (unsigned int)time(NULL);

	ip = Cvar_Get ("ip", "localhost", CVAR_NOSET);

	dedicated = Cvar_IntValue ("dedicated");

	if (flags & NET_SERVER)
	{
		if (!ip_sockets[NS_SERVER])
		{
			port = Cvar_Get("ip_hostport", "0", CVAR_NOSET)->intvalue;
			if (!port)
			{
				port = Cvar_Get("hostport", "0", CVAR_NOSET)->intvalue;
				if (!port)
				{
					port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->intvalue;
				}
			}
			server_port = port;
			ip_sockets[NS_SERVER] = NET_IPSocket (ip->string, port);
			if (!ip_sockets[NS_SERVER] && dedicated)
				Com_Error (ERR_FATAL, "Couldn't allocate dedicated server IP port on %s:%d. Another application is probably using it.", ip->string, port);
		}
	}

	// dedicated servers don't need client ports
	if (dedicated)
		return;

	if (!ip_sockets[NS_CLIENT])
	{
		int newport = (int)(random() * 64000 + 1024);
		port = Cvar_Get("ip_clientport", va("%i", newport), CVAR_NOSET)->intvalue;
		if (!port)
		{
			
			port = Cvar_Get("clientport", va("%i", newport) , CVAR_NOSET)->intvalue;
			if (!port) {
				port = PORT_ANY;
				Cvar_Set ("clientport", va ("%d", newport));
			}
		}

		ip_sockets[NS_CLIENT] = NET_IPSocket (ip->string, newport);
		if (!ip_sockets[NS_CLIENT])
			ip_sockets[NS_CLIENT] = NET_IPSocket (ip->string, PORT_ANY);
	}

	if (!ip_sockets[NS_CLIENT])
		Com_Error (ERR_DROP, "Couldn't allocate client IP port.");
}
예제 #4
0
파일: cl_parse.c 프로젝트: Slipyx/r1q2
void CL_Passive_f (void)
{
	if (cls.state != ca_disconnected) {
		Com_Printf ("Passive mode can only be modified when you are disconnected.\n", LOG_CLIENT);
	} else {
		cls.passivemode = !cls.passivemode;

		if (cls.passivemode) {
			NET_Config (NET_CLIENT);
			Com_Printf ("Listening for passive connections on port %d\n", LOG_CLIENT, Cvar_IntValue ("ip_clientport"));
		} else {
			Com_Printf ("No longer listening for passive connections.\n", LOG_CLIENT);
		}
	}
}
예제 #5
0
파일: cvar.c 프로젝트: turol/webquake2
/*
============
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;
}
예제 #6
0
/*
====================
NET_Config

A single player game will only use the loopback code
====================
*/
int	NET_Config (int toOpen)
{
	static	int	old_config;

	int i = old_config;

	if (old_config == toOpen)
		return i;

	old_config |= toOpen;

	if (toOpen == NET_NONE)
	{
		if (wsState) {
			websocketShutdown();
			assert(!wsState);
		}

		server_port = 0;

		old_config = NET_NONE;

		return i;
	}

	int flags = toOpen;

	net_total_in = net_packets_in = net_total_out = net_packets_out = 0;
	net_inittime = (unsigned int)time(NULL);

	cvar_t	*ip = Cvar_Get ("ip", "localhost", CVAR_NOSET);

	int dedicated = Cvar_IntValue ("dedicated");

	int		port;
	if (flags & NET_SERVER)
	{
		{
			port = Cvar_Get("ip_hostport", "0", CVAR_NOSET)->intvalue;
			if (!port)
			{
				port = Cvar_Get("hostport", "0", CVAR_NOSET)->intvalue;
				if (!port)
				{
					port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->intvalue;
				}
			}
			server_port = port;

			bool failed = false;
			// shut down old context
			if (wsState) {
				websocketShutdown();
				assert(!wsState);
			}

			if (!createWebsocketContext(port)) {
				failed = true;
				server_port = 0;
			}

			if (failed && dedicated)
				Com_Error (ERR_FATAL, "Couldn't allocate dedicated server IP port on %s:%d. Another application is probably using it.", ip->string, port);
		}
	}

	// dedicated servers don't need client ports
	if (dedicated)
		return i;

	bool failed = false;
	if (!wsState) {
		failed = !createWebsocketContext(PORT_ANY);
	}

	if (failed)
		Com_Error (ERR_DROP, "Couldn't allocate client IP port.");

	return i;
}