Пример #1
0
/**
 * @brief
 */
void Cl_Ping_f(void) {
	net_addr_t addr;
	cl_server_info_t *server;

	if (Cmd_Argc() != 2) {
		Com_Print("Usage: %s <address>\n", Cmd_Argv(0));
		return;
	}

	server = NULL;

	if (!Net_StringToNetaddr(Cmd_Argv(1), &addr)) {
		Com_Print("Invalid address\n");
		return;
	}

	if (!addr.port) { // use default
		addr.port = (uint16_t) htons(PORT_SERVER);
	}

	server = Cl_ServerForNetaddr(&addr);

	if (!server) { // add it
		server = Cl_AddServer(&addr);
		server->source = SERVER_SOURCE_USER;
	}

	server->ping_time = quetoo.ticks;
	server->ping = 999;

	Com_Print("Pinging %s\n", Net_NetaddrToString(&server->addr));

	Netchan_OutOfBandPrint(NS_UDP_CLIENT, &server->addr, "info %i", PROTOCOL_MAJOR);
}
Пример #2
0
/*
 * Cl_Ping_f
 */
void Cl_Ping_f(void) {
	net_addr_t addr;
	cl_server_info_t *server;

	if (Cmd_Argc() != 2) {
		Com_Print("Usage: %s <address>\n", Cmd_Argv(0));
		return;
	}

	server = NULL;

	if (!Net_StringToNetaddr(Cmd_Argv(1), &addr)) {
		Com_Print("Invalid address\n");
		return;
	}

	if (!addr.port) // use default
		addr.port = (unsigned short) BigShort(PORT_SERVER);

	server = Cl_ServerForNetaddr(&addr);

	if (!server) { // add it
		server = Cl_AddServer(&addr);
		server->source = SERVER_SOURCE_USER;
	}

	server->ping_time = cls.real_time;
	server->ping = 0;

	Com_Print("Pinging %s\n", Net_NetaddrToString(server->addr));

	Netchan_OutOfBandPrint(NS_CLIENT, server->addr, "info %i", PROTOCOL);
}
Пример #3
0
/*
 * @brief
 */
void Cl_ParseServers(void) {
	cl_server_info_t *server;

	byte *buffptr = net_message.data + 12;
	byte *buffend = buffptr + net_message.size - 12;

	// parse the list
	while (buffptr + 1 < buffend) {
		net_addr_t addr;
		byte ip[4];

		ip[0] = *buffptr++; // parse the address
		ip[1] = *buffptr++;
		ip[2] = *buffptr++;
		ip[3] = *buffptr++;

		uint16_t port = (*buffptr++) << 8; // and the port
		port += *buffptr++;

		char s[32];
		g_snprintf(s, sizeof(s), "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], port);

		Com_Debug("Parsed %s\n", s);

		if (!Net_StringToNetaddr(s, &addr)) { // make sure it's valid
			Com_Warn("Invalid address: %s\n", s);
			break;
		}

		if (!addr.port) // 0's mean we're done
			break;

		server = Cl_ServerForNetaddr(&addr);

		if (!server)
			server = Cl_AddServer(&addr);

		server->source = SERVER_SOURCE_INTERNET;
	}

	net_message.read = net_message.size;

	// then ping them

	GList *e = cls.servers;

	while (e) {
		server = (cl_server_info_t *) e->data;

		if (server->source == SERVER_SOURCE_INTERNET) {
			server->ping_time = cls.real_time;
			server->ping = 0;

			Netchan_OutOfBandPrint(NS_UDP_CLIENT, &server->addr, "info %i", PROTOCOL_MAJOR);
		}

		e = e->next;
	}
}
Пример #4
0
/*
 * @brief
 */
void Sv_InitMasters(void) {

	memset(&svs.masters, 0, sizeof(svs.masters));

	// set default master server
	Net_StringToNetaddr(HOST_MASTER, &svs.masters[0]);
	svs.masters[0].port = htons(PORT_MASTER);
}
Пример #5
0
/*
 * Sv_InitMasters
 */
static void Sv_InitMasters(void) {

	memset(&svs.masters, 0, sizeof(svs.masters));

	// set default master server
	Net_StringToNetaddr(IP_MASTER, &svs.masters[0]);
	svs.masters[0].port = BigShort(PORT_MASTER);
}
Пример #6
0
/*
 * Cl_ParseServersList
 */
void Cl_ParseServersList(void) {
	byte *buffptr;
	byte *buffend;
	byte ip[4];
	unsigned short port;
	net_addr_t addr;
	cl_server_info_t *server;
	char s[32];

	buffptr = net_message.data + 12;
	buffend = buffptr + net_message.size - 12;

	// parse the list
	while (buffptr + 1 < buffend) {

		ip[0] = *buffptr++; // parse the address
		ip[1] = *buffptr++;
		ip[2] = *buffptr++;
		ip[3] = *buffptr++;

		port = (*buffptr++) << 8; // and the port
		port += *buffptr++;

		snprintf(s, sizeof(s), "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], port);

		if (!Net_StringToNetaddr(s, &addr)) { // make sure it's valid
			Com_Warn("Cl_ParseServersList: Invalid address: %s.\n", s);
			break;
		}

		if (!addr.port) // 0's mean we're done
			break;

		server = Cl_ServerForNetaddr(&addr);

		if (!server)
			server = Cl_AddServer(&addr);

		server->source = SERVER_SOURCE_INTERNET;
	}

	net_message.read = net_message.size;

	// then ping them
	server = cls.servers;

	while (server) {

		if (server->source == SERVER_SOURCE_INTERNET) {
			server->ping_time = cls.real_time;
			server->ping = 0;

			Netchan_OutOfBandPrint(NS_CLIENT, server->addr, "info %i", PROTOCOL);
		}

		server = server->next;
	}
}
Пример #7
0
/*
 * Cl_Servers_f
 */
void Cl_Servers_f(void) {
	net_addr_t addr;

	if (!Net_StringToNetaddr(IP_MASTER, &addr)) {
		Com_Print("Failed to resolve %s\n", IP_MASTER);
		return;
	}

	Com_Print("Refreshing servers.\n");

	addr.type = NA_IP;
	addr.port = (unsigned short) BigShort(PORT_MASTER);
	Netchan_OutOfBandPrint(NS_CLIENT, addr, "getservers");

	Cl_SendBroadcast();
}
Пример #8
0
/*
 * @brief Send the rest of the command line over as an unconnected command.
 */
static void Cl_Rcon_f(void) {
	char message[1024];
	int32_t i;
	net_addr_t to;

	if (!rcon_password->string) {
		Com_Print("No rcon_password set\n");
		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;

	strcat(message, "rcon ");
	strcat(message, rcon_password->string);
	strcat(message, " ");

	for (i = 1; i < Cmd_Argc(); i++) {
		strcat(message, Cmd_Argv(i));
		strcat(message, " ");
	}

	if (cls.state >= CL_CONNECTED)
		to = cls.net_chan.remote_address;
	else {
		if (*rcon_address->string == '\0') {
			Com_Print("Not connected and no rcon_address set\n");
			return;
		}

		if (!Net_StringToNetaddr(rcon_address->string, &to)) {
			Com_Warn("Invalid rcon_address: %s\n", rcon_address->string);
			return;
		}

		if (to.port == 0)
			to.port = htons(PORT_SERVER);
	}

	Net_SendDatagram(NS_UDP_CLIENT, &to, message, strlen(message) + 1);
}
Пример #9
0
/**
 * @brief
 */
void Cl_Servers_f(void) {
	net_addr_t addr;

	if (!Net_StringToNetaddr(HOST_MASTER, &addr)) {
		Com_Print("Failed to resolve %s\n", HOST_MASTER);
		return;
	}

	Com_Print("Refreshing servers\n");

	addr.type = NA_DATAGRAM;
	addr.port = htons(PORT_MASTER);

	Netchan_OutOfBandPrint(NS_UDP_CLIENT, &addr, "getservers");

	Cl_SendBroadcast();
}
Пример #10
0
/*
 * @brief Re-send a connect message if the last one has timed out.
 */
static void Cl_CheckForResend(void) {

	// if the local server is running and we aren't then connect
	if (Com_WasInit(QUETOO_SERVER) && g_strcmp0(cls.server_name, "localhost")) {

		if (cls.state > CL_DISCONNECTED) {
			Cl_Disconnect();
		}

		g_strlcpy(cls.server_name, "localhost", sizeof(cls.server_name));

		cls.state = CL_CONNECTING;
		cls.connect_time = 0;
	}

	// re-send if we haven't received a reply yet
	if (cls.state != CL_CONNECTING)
		return;

	// don't flood connection packets
	if (cls.connect_time && (quetoo.time - cls.connect_time < 1000))
		return;

	net_addr_t addr;

	if (!Net_StringToNetaddr(cls.server_name, &addr)) {
		Com_Print("Bad server address\n");
		cls.state = CL_DISCONNECTED;
		return;
	}

	if (addr.port == 0)
		addr.port = htons(PORT_SERVER);

	cls.connect_time = quetoo.time; // for retransmit requests

	const char *s = Net_NetaddrToString(&addr);
	if (g_strcmp0(cls.server_name, s)) {
		Com_Print("Connecting to %s (%s)...\n", cls.server_name, s);
	} else {
		Com_Print("Connecting to %s...\n", cls.server_name);
	}

	Netchan_OutOfBandPrint(NS_UDP_CLIENT, &addr, "get_challenge\n");
}
Пример #11
0
/*
 * @brief We have gotten a challenge from the server, so try and connect.
 */
static void Cl_SendConnect(void) {
	net_addr_t addr;

	memset(&addr, 0, sizeof(addr));

	if (!Net_StringToNetaddr(cls.server_name, &addr)) {
		Com_Print("Bad server address\n");
		cls.connect_time = 0;
		return;
	}

	if (addr.port == 0) // use default port
		addr.port = htons(PORT_SERVER);

	Netchan_OutOfBandPrint(NS_UDP_CLIENT, &addr, "connect %i %i %u \"%s\"\n", PROTOCOL_MAJOR,
			qport->integer, cls.challenge, Cvar_UserInfo());

	cvar_user_info_modified = false;
}