Ejemplo n.º 1
0
void CL_SendCmd(void) {
	usercmd_t cmd;

	if (cls.state != ca_connected)
		return;

	if (cls.signon == SIGNONS) {
		// get basic movement from keyboard
		CL_BaseMove(&cmd);
		// allow mice or other external controllers to add to the move
		IN_Move(&cmd);
		// send the unreliable message
		CL_SendMove(&cmd);

	}

	if (cls.demoplayback) {
		SZ_Clear(&cls.message);
		return;
	}

	// send the reliable message
	if (!cls.message.cursize)
		return; // no message at all

	if (!NET_CanSendMessage(cls.netcon)) {
		Con_DPrintf("CL_WriteToServer: can't send\n");
		return;
	}

	if (NET_SendMessage(cls.netcon, &cls.message) == -1)
		Host_Error("CL_WriteToServer: lost server connection");

	SZ_Clear(&cls.message);
}
Ejemplo n.º 2
0
/*
==================
Host_ShutdownServer

This only happens at the end of a game, not between levels
==================
*/
void
Host_ShutdownServer(qboolean crash)
{
    int i;
    int count;
    sizebuf_t buf;
    byte message[4];
    double start;

    if (!sv.active)
	return;

    sv.active = false;

// stop all client sounds immediately
    if (cls.state >= ca_connected)
	CL_Disconnect();

// flush any pending messages - like the score!!!
    start = Sys_DoubleTime();
    do {
	count = 0;
	for (i = 0, host_client = svs.clients; i < svs.maxclients;
	     i++, host_client++) {
	    if (host_client->active && host_client->message.cursize) {
		if (NET_CanSendMessage(host_client->netconnection)) {
		    NET_SendMessage(host_client->netconnection,
				    &host_client->message);
		    SZ_Clear(&host_client->message);
		} else {
		    NET_GetMessage(host_client->netconnection);
		    count++;
		}
	    }
	}
	if ((Sys_DoubleTime() - start) > 3.0)
	    break;
    } while (count);

// make sure all the clients know we're disconnecting
    buf.data = message;
    buf.maxsize = 4;
    buf.cursize = 0;
    MSG_WriteByte(&buf, svc_disconnect);
    count = NET_SendToAll(&buf, 5);
    if (count)
	Con_Printf("%s: NET_SendToAll failed for %u clients\n", __func__,
		   count);

    for (i = 0, host_client = svs.clients; i < svs.maxclients;
	 i++, host_client++)
	if (host_client->active)
	    SV_DropClient(crash);

//
// clear structures
//
    memset(&sv, 0, sizeof(sv));
    memset(svs.clients, 0, svs.maxclientslimit * sizeof(client_t));
}
Ejemplo n.º 3
0
/*
=====================
SV_DropClient

Called when the player is getting totally kicked off the host
if (crash = true), don't bother sending signofs
=====================
*/
void SV_DropClient (bool crash)
{
	int		saveSelf;
	int		i;
	client_t *client;

	if (!host_client->active)
		return;

	if (!crash)
	{
		// send any final messages (don't check for errors)
		if (NET_CanSendMessage (host_client->netconnection))
		{
			MSG_WriteByte (&host_client->message, svc_disconnect);
			NET_SendMessage (host_client->netconnection, &host_client->message);
		}

		if (host_client->edict && host_client->spawned)
		{
		// call the prog function for removing a client
		// this will set the body to a dead frame, among other things
			saveSelf = pr_global_struct->self;
			pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
			PR_ExecuteProgram (pr_global_struct->ClientDisconnect);
			pr_global_struct->self = saveSelf;
		}

		Sys_Printf ("Client %s removed\n",host_client->name);
	}

	/*if (host_client->netconnection->proquake_connection == MOD_QSMACK)
		qsmackActive = false;*/

// break the net connection
	NET_Close (host_client->netconnection);
	host_client->netconnection = NULL;

// free the client (the body stays around)
	host_client->active = false;
	host_client->name[0] = 0;
	host_client->old_frags = -999999;
	net_activeconnections--;

// send notification to all clients
	for (i=0, client = svs.clients ; i<svs.maxclients ; i++, client++)
	{
		if (!client->active)
			continue;
		MSG_WriteByte (&client->message, svc_updatename);
		MSG_WriteByte (&client->message, host_client - svs.clients);
		MSG_WriteString (&client->message, "");
		MSG_WriteByte (&client->message, svc_updatefrags);
		MSG_WriteByte (&client->message, host_client - svs.clients);
		MSG_WriteShort (&client->message, 0);
		MSG_WriteByte (&client->message, svc_updatecolors);
		MSG_WriteByte (&client->message, host_client - svs.clients);
		MSG_WriteByte (&client->message, 0);
	}
}
Ejemplo n.º 4
0
int NET_SendToAll(sizebuf_t *data, int blocktime)
{
	double		start;
	int			i;
	int			count = 0;
	qboolean	state1 [MAX_SCOREBOARD];
	qboolean	state2 [MAX_SCOREBOARD];

	for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
	{
		if (!host_client->netconnection)
			continue;
		if (host_client->active)
		{
			if (host_client->netconnection->driver == 0)
			{
				NET_SendMessage(host_client->netconnection, data);
				state1[i] = true;
				state2[i] = true;
				continue;
			}
			count++;
			state1[i] = false;
			state2[i] = false;
		}
		else
		{
			state1[i] = true;
			state2[i] = true;
		}
	}

	start = Sys_FloatTime();
	while (count)
	{
		count = 0;
		for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
		{
			if (! state1[i])
			{
				if (NET_CanSendMessage (host_client->netconnection))
				{
					state1[i] = true;
					NET_SendMessage(host_client->netconnection, data);
				}
				else
				{
					NET_GetMessage (host_client->netconnection);
				}
				count++;
				continue;
			}

			if (! state2[i])
			{
				if (NET_CanSendMessage (host_client->netconnection))
				{
					state2[i] = true;
				}
				else
				{
					NET_GetMessage (host_client->netconnection);
				}
				count++;
				continue;
			}
		}
		if ((Sys_FloatTime() - start) > blocktime)
			break;
	}
	return count;
}
Ejemplo n.º 5
0
int
NET_SendToAll(sizebuf_t *data, double blocktime)
{
    double start;
    int i;
    int count = 0;
    qboolean msg_init[MAX_SCOREBOARD]; /* data written */
    qboolean msg_sent[MAX_SCOREBOARD]; /* send completed */

    for (i = 0, host_client = svs.clients; i < svs.maxclients;
	 i++, host_client++) {
	if (host_client->netconnection && host_client->active) {
	    /*
	     * Loopback driver guarantees delivery, skip checks
	     */
	    if (IS_LOOP_DRIVER(host_client->netconnection->driver)) {
		NET_SendMessage(host_client->netconnection, data);
		msg_init[i] = true;
		msg_sent[i] = true;
		continue;
	    }
	    count++;
	    msg_init[i] = false;
	    msg_sent[i] = false;
	} else {
	    msg_init[i] = true;
	    msg_sent[i] = true;
	}
    }

    start = Sys_DoubleTime();
    while (count) {
	count = 0;
	for (i = 0, host_client = svs.clients; i < svs.maxclients;
	     i++, host_client++) {
	    if (!msg_init[i]) {
		if (NET_CanSendMessage(host_client->netconnection)) {
		    msg_init[i] = true;
		    NET_SendMessage(host_client->netconnection, data);
		} else {
		    NET_GetMessage(host_client->netconnection);
		}
		count++;
		continue;
	    }

	    if (!msg_sent[i]) {
		if (NET_CanSendMessage(host_client->netconnection)) {
		    msg_sent[i] = true;
		} else {
		    NET_GetMessage(host_client->netconnection);
		}
		count++;
		continue;
	    }
	}
	if ((Sys_DoubleTime() - start) > blocktime)
	    break;
    }
    return count;
}
Ejemplo n.º 6
0
/*
=====================
SV_DropClient

Called when the player is getting totally kicked off the host
if (crash = true), don't bother sending signofs
=====================
*/
void SV_DropClient (qboolean crash)
{
	int		saveSelf;
	int		i;
	client_t *client;

	// JPG 3.00 - don't drop a client that's already been dropped!
	if (!host_client->active)
		return;

	if (!crash)
	{
		// send any final messages (don't check for errors)
		if (NET_CanSendMessage (host_client->netconnection))
		{
			MSG_WriteByte (&host_client->message, svc_disconnect);
			NET_SendMessage (host_client->netconnection, &host_client->message);
		}

		if (host_client->edict && host_client->spawned)
		{
		// call the prog function for removing a client
		// this will set the body to a dead frame, among other things
			saveSelf = pr_global_struct->self;
			pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
			PR_ExecuteProgram (pr_global_struct->ClientDisconnect);
			pr_global_struct->self = saveSelf;
		}

        // Slot Zero 3.50-2  Added edict to client removed message.
        if (pq_showedict.value)
			    Sys_Printf("#%d ", NUM_FOR_EDICT(host_client->edict));

		Sys_Printf ("Client %s removed\n",host_client->name);
	}

	// JPG 3.00 - check to see if it's a qsmack client
	if (host_client->netconnection->mod == MOD_QSMACK)
		qsmackActive = false;

// break the net connection
	NET_Close (host_client->netconnection);
	host_client->netconnection = NULL;

// free the client (the body stays around)
	host_client->active = false;
	host_client->name[0] = 0;
	host_client->old_frags = -999999;
	net_activeconnections--;

// send notification to all clients
	for (i=0, client = svs.clients ; i<svs.maxclients ; i++, client++)
	{
		if (!client->active)
			continue;
		MSG_WriteByte (&client->message, svc_updatename);
		MSG_WriteByte (&client->message, host_client - svs.clients);
		MSG_WriteString (&client->message, "");
		MSG_WriteByte (&client->message, svc_updatefrags);
		MSG_WriteByte (&client->message, host_client - svs.clients);
		MSG_WriteShort (&client->message, 0);
		MSG_WriteByte (&client->message, svc_updatecolors);
		MSG_WriteByte (&client->message, host_client - svs.clients);
		MSG_WriteByte (&client->message, 0);
	}
}
Ejemplo n.º 7
0
int NET_SendToAll (sizebuf_t *data, double blocktime)
{
	double		start;
	int			i;
	int			count = 0;
	qboolean	msg_init[MAX_CLIENTS];	/* did we write the message to the client's connection	*/
	qboolean	msg_sent[MAX_CLIENTS];	/* did the msg arrive its destination (canSend state).	*/

	for (i = 0, host_client = svs.clients; i < svs.maxclients; i++, host_client++)
	{
		if (host_client->netconnection && host_client->active)
		{
			count++;
			msg_init[i] = false;
			msg_sent[i] = false;
		}
		else
		{
			msg_init[i] = true;
			msg_sent[i] = true;
		}
	}

	start = Sys_DoubleTime();
	while (count)
	{
		count = 0;
		for (i = 0, host_client = svs.clients; i < svs.maxclients; i++, host_client++)
		{
			if (! msg_init[i])
			{
				if (NET_CanSendMessage (host_client->netconnection))
				{
					msg_init[i] = true;
					NET_SendMessage(host_client->netconnection, data);
				}
				else
				{
					NET_GetMessage (host_client->netconnection);
				}
				count++;
				continue;
			}

			if (! msg_sent[i])
			{
				if (NET_CanSendMessage (host_client->netconnection))
				{
					msg_sent[i] = true;
				}
				else
				{
					NET_GetMessage (host_client->netconnection);
				}
				count++;
				continue;
			}
		}
		if ((Sys_DoubleTime() - start) > blocktime)
			break;
	}
	return count;
}