Esempio n. 1
0
/**
 * @sa gi.AbortEvents
 */
static void SV_AbortEvents (void)
{
	pending_event_t *p = &sv->pendingEvent;

	if (!p->pending)
		return;

	p->pending = qfalse;
	free_dbuffer(p->buf);
	p->buf = NULL;
}
Esempio n. 2
0
static void testDBufferNetHandling (void)
{
	dbuffer* buf = new_dbuffer();
	NET_WriteByte(buf, 'b');
	CU_ASSERT_EQUAL(1, dbuffer_len(buf));
	NET_WriteShort(buf, 128);
	CU_ASSERT_EQUAL(3, dbuffer_len(buf));
	NET_WriteLong(buf, 128);
	CU_ASSERT_EQUAL(7, dbuffer_len(buf));
	free_dbuffer(buf);
}
Esempio n. 3
0
static void testDBuffer (void)
{
	int i;
	const int size = 10000000;
	dbuffer* buf = new_dbuffer();
	char data[128];
	size_t dataSize = sizeof(data);
	for (i = 0; i < size; i++)
		dbuffer_add(buf, "b", 1);
	CU_ASSERT_EQUAL(size, dbuffer_len(buf));

	CU_ASSERT_EQUAL(dataSize, dbuffer_get(buf, data, dataSize));
	CU_ASSERT_EQUAL(size, dbuffer_len(buf));

	CU_ASSERT_EQUAL(dataSize, dbuffer_extract(buf, data, dataSize));
	CU_ASSERT_EQUAL(size - dataSize, dbuffer_len(buf));

	free_dbuffer(buf);

	buf = new_dbuffer();
	dbuffer_add(buf, "b", 1);
	CU_ASSERT_EQUAL(1, dbuffer_len(buf));

	CU_ASSERT_EQUAL(1, dbuffer_get(buf, data, dataSize));
	CU_ASSERT_EQUAL(1, dbuffer_len(buf));

	CU_ASSERT_EQUAL(1, dbuffer_extract(buf, data, dataSize));
	CU_ASSERT_EQUAL(0, dbuffer_len(buf));

	buf = dbuffer_dup(buf);
	CU_ASSERT_EQUAL(0, dbuffer_len(buf));

	for (i = 0; i <= dataSize; i++)
		dbuffer_add(buf, "b", 1);
	CU_ASSERT_EQUAL(dataSize + 1, dbuffer_len(buf));

	CU_ASSERT_EQUAL(dataSize, dbuffer_extract(buf, data, dataSize));
	CU_ASSERT_EQUAL(1, dbuffer_len(buf));

	CU_ASSERT_EQUAL(1, dbuffer_remove(buf, 1));
	CU_ASSERT_EQUAL(0, dbuffer_len(buf));

	CU_ASSERT_EQUAL(0, dbuffer_remove(buf, 1));

	CU_ASSERT_EQUAL(0, dbuffer_get_at(buf, 1, data, dataSize));

	for (i = 0; i <= dataSize; i++)
		dbuffer_add(buf, "b", 1);
	CU_ASSERT_EQUAL(dataSize + 1, dbuffer_len(buf));

	CU_ASSERT_EQUAL(dataSize, dbuffer_get_at(buf, 1, data, dataSize));
	CU_ASSERT_EQUAL(dataSize + 1, dbuffer_len(buf));
}
Esempio n. 4
0
static void testDBufferBigData (void)
{
	int i;
	int count = 100;
	byte *data;
	/* this entity string may not contain any inline models, we don't have the bsp tree loaded here */
	const int size = FS_LoadFile("game/entity.txt", &data);
	dbuffer* buf = new_dbuffer();

	for (i = 0; i < count; i++) {
		dbuffer_add(buf, (char *)data, size);
	}

	CU_ASSERT_EQUAL(size * count, dbuffer_len(buf));
	free_dbuffer(buf);
	FS_FreeFile(data);
}
Esempio n. 5
0
/**
 * @sa CL_ReadPacket
 * @sa NET_ReadMsg
 * @sa SV_Start
 */
void SV_ReadPacket (struct net_stream *s)
{
	client_t *cl = (client_t *)NET_StreamGetData(s);
	struct dbuffer *msg;

	while ((msg = NET_ReadMsg(s))) {
		const int cmd = NET_ReadByte(msg);

		if (cmd == clc_oob)
			SV_ConnectionlessPacket(s, msg);
		else if (cl)
			SV_ExecuteClientMessage(cl, cmd, msg);
		else
			NET_StreamFree(s);

		free_dbuffer(msg);
	}
}
Esempio n. 6
0
/**
 * @brief Sends text to all active clients
 */
void SV_BroadcastPrintf (int level, const char *fmt, ...)
{
	va_list argptr;
	struct dbuffer *msg;
	client_t *cl;
	char str[1024];

	msg = new_dbuffer();
	NET_WriteByte(msg, svc_print);
	NET_WriteByte(msg, level);

	va_start(argptr, fmt);
	NET_VPrintf(msg, fmt, argptr, str, sizeof(str));
	va_end(argptr);

	/* echo to console */
	if (sv_dedicated->integer) {
		char copy[1024];
		int i;
		const int length = sizeof(copy) - 1;

		va_start(argptr, fmt);
		Q_vsnprintf(copy, sizeof(copy), fmt, argptr);
		va_end(argptr);

		/* mask off high bits */
		for (i = 0; i < length && copy[i]; i++)
			copy[i] = copy[i] & 127;
		copy[i] = '\0';
		Com_Printf("%s", copy);
	}

	cl = NULL;
	while ((cl = SV_GetNextClient(cl)) != NULL) {
		if (level > cl->messagelevel)
			continue;
		if (cl->state < cs_connected)
			continue;
		NET_WriteConstMsg(cl->stream, msg);
	}

	free_dbuffer(msg);
}
Esempio n. 7
0
/**
 * @brief Sends the contents of msg to a subset of the clients, then frees msg
 * @param[in] mask Bitmask of the players to send the multicast to
 * @param[in,out] msg The message to send to the clients
 */
void SV_Multicast (int mask, struct dbuffer *msg)
{
	client_t *cl;
	int j;

	/* send the data to all relevant clients */
	cl = NULL;
	j = -1;
	while ((cl = SV_GetNextClient(cl)) != NULL) {
		j++;
		if (cl->state < cs_connected)
			continue;
		if (!(mask & (1 << j)))
			continue;

		/* write the message */
		NET_WriteConstMsg(cl->stream, msg);
	}

	free_dbuffer(msg);
}
Esempio n. 8
0
/**
 * @brief Used by SV_Shutdown to send a final message to all
 * connected clients before the server goes down.
 * @sa SV_Shutdown
 */
static void SV_FinalMessage (const char *message, qboolean reconnect)
{
	client_t *cl;
	struct dbuffer *msg = new_dbuffer();

	if (reconnect)
		NET_WriteByte(msg, svc_reconnect);
	else
		NET_WriteByte(msg, svc_disconnect);
	NET_WriteString(msg, message);

	cl = NULL;
	while ((cl = SV_GetNextClient(cl)) != NULL)
		if (cl->state >= cs_connected) {
			NET_WriteConstMsg(cl->stream, msg);
			NET_StreamFinished(cl->stream);
			cl->stream = NULL;
		}

	/* make sure, that this is send */
	NET_Wait(0);

	free_dbuffer(msg);
}