Exemplo n.º 1
0
Arquivo: query.c Projeto: deurk/qwfwd
void SVC_QRY_PingStatus(void)
{
	static sizebuf_t buf; // static  - so it not allocated each time
	static byte		buf_data[MSG_BUF_SIZE]; // static  - so it not allocated each time

	server_t		*sv;

	SZ_InitEx(&buf, buf_data, sizeof(buf_data), true);

	MSG_WriteLong(&buf, -1);	// -1 sequence means out of band
	MSG_WriteChar(&buf, A2C_PRINT);

	// if we does not query masters then we can't proved reliable info, so do not send servers list
	if (masters_query->integer)
	{
		for (sv = servers; sv; sv = sv->next)
		{
			MSG_WriteLong(&buf, *(int *)&sv->addr.sin_addr);
			MSG_WriteShort(&buf, (short)ntohs(sv->addr.sin_port));
			MSG_WriteShort(&buf, (short)sv->ping);
		}
	}

	if (buf.overflowed)
	{
		Sys_Printf("SVC_QRY_PingStatus: overflow\n");
		return; // overflowed
	}

	// send the datagram
	NET_SendPacket(net_from_socket, buf.cursize, buf.data, &net_from);
}
Exemplo n.º 2
0
Arquivo: clc.c Projeto: deurk/qwfwd
static void CL_SendConnectPacket_Q3(peer_t *p) 
{
	char tmp[128];
	char data[2048];
	byte msg_data[2048];
	char biguserinfo[MAX_INFO_STRING + 100];
	sizebuf_t msg;

	if (p->ps != ps_challenge)
		return;

	// add challenge to the temporary userinfo
	strlcpy (biguserinfo, p->userinfo, sizeof (biguserinfo));
	snprintf(tmp, sizeof(tmp), "%d", p->challenge);
	Info_SetValueForKey(biguserinfo, "challenge", tmp, sizeof(biguserinfo));
	// make string
	snprintf(data, sizeof(data), "\xff\xff\xff\xff" "connect \"%s\"", biguserinfo);	
	// init msg
	SZ_InitEx(&msg, msg_data, sizeof(msg_data), true);
	SZ_Print(&msg, data);
	// god damn compress it
	Huff_EncryptPacket(&msg, 12);

	// ok, send it!
	NET_SendPacket(net_from_socket, msg.cursize, msg.data, &net_from);
}
Exemplo n.º 3
0
Arquivo: net.c Projeto: deurk/qwfwd
/*
====================
NET_Init
====================
*/
void NET_Init (void)
{
	char *ip = (*ps.params.ip) ? ps.params.ip : "0.0.0.0";
	char port[64] = {0};

	snprintf(port, sizeof(port), "%d", 	ps.params.port ? ps.params.port : QWFWD_DEFAULT_PORT);

	if (*ps.params.ip) // if cmd line - force it, so we have priority over cfg
		net_ip	 = Cvar_FullSet("net_ip", ip, CVAR_NOSET);
	else
		net_ip	 = Cvar_Get("net_ip",	  ip, CVAR_NOSET);

	if (ps.params.port) // if cmd line - force it, so we have priority over cfg
		net_port = Cvar_FullSet("net_port",	port, CVAR_NOSET);
	else
		net_port = Cvar_Get("net_port",		port, CVAR_NOSET);

#ifdef _WIN32
	{
		WSADATA		winsockdata;

		if (WSAStartup(MAKEWORD (2, 1), &winsockdata))
			Sys_Error("WinSock initialization failed");
	}
#endif

	if ((net_socket = NET_UDP_OpenSocket(net_ip->string, net_port->integer, true)) == INVALID_SOCKET)
		Sys_Error("NET_Init: failed to initialize socket");

	// init the message buffer
	SZ_InitEx(&net_message, net_message_buffer, sizeof(net_message_buffer), false);

	Sys_DPrintf("UDP Initialized\n");
}
Exemplo n.º 4
0
Arquivo: net.c Projeto: deurk/qwfwd
/*
===============
Netchan_OutOfBand

Sends an out-of-band datagram
================
*/
void Netchan_OutOfBand(int s, struct sockaddr_in *adr, int length, byte *data)
{
	sizebuf_t send1;
	byte send_buf[MAX_MSGLEN + PACKET_HEADER];

	SZ_InitEx(&send1, send_buf, sizeof(send_buf), true);

	// write the packet header
	MSG_WriteLong(&send1, -1);	// -1 sequence means out of band
	// write data
	SZ_Write(&send1, data, length);

	if (send1.overflowed)
	{
		Sys_Printf("Netchan_OutOfBand: overflowed\n");
		return; // ah, should not happens
	}

	// send the datagram
	NET_SendPacket(s, send1.cursize, send1.data, adr);
}
Exemplo n.º 5
0
Arquivo: peer.c Projeto: deurk/qwfwd
static void FWD_check_timeout(void)
{
	byte msg_data[6];
	sizebuf_t msg;
	time_t cur_time;
	double d_cur_time;
	peer_t *p;

	SZ_InitEx(&msg, msg_data, sizeof(msg_data), true);

	cur_time = time(NULL);
	d_cur_time = Sys_DoubleTime();

	for (p = peers; p; p = p->next)
	{
		// this is helper for q3 to guess disconnect asap
		if (p->proto == pr_q3)
		{
			if (cur_time - p->last > 1 && d_cur_time - p->q3_disconnect_check > 0.05 && p->ps == ps_connected)
			{
				p->q3_disconnect_check = d_cur_time;
				SZ_Clear(&msg);
				MSG_WriteLong(&msg, 0);
				MSG_WriteShort(&msg, p->qport);
				NET_SendPacket(p->s, msg.cursize, msg.data, &p->to);
			}
		}

		if (cur_time - p->last < 15) // few seconds timeout
			continue;

		Sys_DPrintf("peer %s:%d timed out\n", inet_ntoa(p->from.sin_addr), (int)ntohs(p->from.sin_port));

		p->ps = ps_drop;
	}
}
Exemplo n.º 6
0
void SZ_Init (sizebuf_t *buf, byte *data, int length)
{
	SZ_InitEx (buf, data, length, false);
}