Example #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);
}
Example #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);
}
Example #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;
	}
}
Example #4
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;
	}
}
Example #5
0
/**
 * @brief
 */
void Cl_ParseServerInfo(void) {
	char info[MAX_MSG_SIZE];

	cl_server_info_t *server = Cl_ServerForNetaddr(&net_from);
	if (!server) { // unknown server, assumed response to broadcast

		server = Cl_AddServer(&net_from);

		server->source = SERVER_SOURCE_BCAST;
		server->ping_time = cls.broadcast_time;
	}

	// try to parse the info string
	g_strlcpy(info, Net_ReadString(&net_message), sizeof(info));
	if (sscanf(info, "%63c\\%31c\\%31c\\%hu\\%hu", server->hostname, server->name,
	           server->gameplay, &server->clients, &server->max_clients) != 5) {

		Com_Debug(DEBUG_CLIENT, "Failed to parse info \"%s\" for %s\n", info, Net_NetaddrToString(&server->addr));

		server->hostname[0] = '\0';
		server->name[0] = '\0';
		server->gameplay[0] = '\0';
		server->clients = 0;
		server->max_clients = 0;

		return;
	}

	g_strchomp(server->hostname);
	g_strchomp(server->name);
	g_strchomp(server->gameplay);

	server->hostname[sizeof(server->hostname) - 1] = '\0';
	server->name[sizeof(server->name) - 1] = '\0';
	server->gameplay[sizeof(server->name) - 1] = '\0';

	server->ping = Clamp(quetoo.ticks - server->ping_time, 1u, 999u);

	Ui_UpdateBindings();
}
Example #6
0
/*
 * Cl_ParseStatusMessage
 */
void Cl_ParseStatusMessage(void) {
	extern void Ui_NewServer(void);
	cl_server_info_t *server;
	char info[MAX_MSG_SIZE];

	server = Cl_ServerForNetaddr(&net_from);

	if (!server) { // unknown server, assumed response to broadcast

		server = Cl_AddServer(&net_from);

		server->source = SERVER_SOURCE_BCAST;
		server->ping_time = cls.broadcast_time;
	}

	// try to parse the info string
	strncpy(info, Msg_ReadString(&net_message), sizeof(info) - 1);
	info[sizeof(info) - 1] = '\0';
	if (sscanf(info, "%63c\\%31c\\%31c\\%hu\\%hu", server->hostname,
			server->name, server->gameplay, &server->clients,
			&server->max_clients) != 5) {

		strcpy(server->hostname, Net_NetaddrToString(server->addr));
		server->name[0] = '\0';
		server->gameplay[0] = '\0';
		server->clients = 0;
		server->max_clients = 0;
	}
	server->hostname[63] = '\0';
	server->name[31] = '\0';
	server->gameplay[31] = '\0';

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

	if (server->ping > 1000) // clamp the ping
		server->ping = 999;

	Ui_NewServer();
}