Пример #1
0
/*
============
Cbuf_InsertText

Adds command text immediately after the current command
Adds a \n to the text
FIXME: actually change the command buffer to do less copying
============
*/
void Cbuf_InsertText (const char *text)
{
	char	*temp;
	int		templen;

// copy off any commands still remaining in the exec buffer
	templen = cmd_text.cursize;
	if (templen)
	{
		temp = (char *) Z_Malloc (templen, Z_MAINZONE);
		memcpy (temp, cmd_text.data, templen);
		SZ_Clear (&cmd_text);
	}
	else
		temp = NULL;	// shut up compiler

// add the entire text of the file
	Cbuf_AddText (text);
	SZ_Write (&cmd_text, "\n", 1);
// add the copied off data
	if (templen)
	{
		SZ_Write (&cmd_text, temp, templen);
		Z_Free (temp);
	}
}
Пример #2
0
void ClientReliableWrite_SZ(client_t *cl, void *data, int len)
{
	if (cl->num_backbuf) {
		SZ_Write(&cl->backbuf, data, len);
		ClientReliable_FinishWrite(cl);
	} else
		SZ_Write(&cl->netchan.message, data, len);
}
Пример #3
0
// flush data from client's reliable buffers to netchan
void SV_FlushBackbuf (client_t *cl)
{
	int i;

	// check to see if we have a backbuf to stick into the reliable
	if (cl->num_backbuf) {
		// will it fit?
		if (cl->netchan.message.cursize + cl->backbuf_size[0] <
			cl->netchan.message.maxsize) {

			Com_DPrintf ("%s: backbuf %d bytes\n",
				cl->name, cl->backbuf_size[0]);

			// it'll fit
			SZ_Write (&cl->netchan.message, cl->backbuf_data[0],
				cl->backbuf_size[0]);
			
			// move along, move along
			for (i = 1; i < cl->num_backbuf; i++) {
				memcpy(cl->backbuf_data[i - 1], cl->backbuf_data[i],
					cl->backbuf_size[i]);
				cl->backbuf_size[i - 1] = cl->backbuf_size[i];
			}

			cl->num_backbuf--;
			if (cl->num_backbuf) {
				SZ_Init (&cl->backbuf, cl->backbuf_data[cl->num_backbuf - 1],
					sizeof(cl->backbuf_data[cl->num_backbuf - 1]));
				cl->backbuf.cursize = cl->backbuf_size[cl->num_backbuf - 1];
			}
		}
	}
}
Пример #4
0
/*
==================
SV_NextDownload_f
==================
*/
void SV_NextDownload_f(void){
	int	percent, size, r;

	if(!sv_client->download)
		return;

	r = sv_client->downloadsize - sv_client->downloadcount;
	if(r > 1024)
		r = 1024;

	MSG_WriteByte(&sv_client->netchan.message, svc_download);
	MSG_WriteShort(&sv_client->netchan.message, r);

	sv_client->downloadcount += r;
	size = sv_client->downloadsize;
	if(!size)
		size = 1;
	percent = sv_client->downloadcount * 100 / size;
	MSG_WriteByte(&sv_client->netchan.message, percent);
	SZ_Write(&sv_client->netchan.message,
			  sv_client->download + sv_client->downloadcount - r, r);

	if(sv_client->downloadcount != sv_client->downloadsize)
		return;

	FS_FreeFile(sv_client->download);
	sv_client->download = NULL;
}
Пример #5
0
/*
==================
SV_NextDownload_f
==================
*/
static void SV_NextDownload_f (void)
{
	byte	buffer[1024];
	int		r;
	int		percent;
	int		size;

	if (!host_client->download)
		return;

	r = host_client->downloadsize - host_client->downloadcount;
	if (r > 1024)
		r = 1024;
	r = fread (buffer, 1, r, host_client->download);
	MSG_WriteByte (&host_client->netchan.message, svc_download);
	MSG_WriteShort (&host_client->netchan.message, r);

	host_client->downloadcount += r;
	size = host_client->downloadsize;
	if (!size)
		size = 1;
	percent = host_client->downloadcount*100/size;
	MSG_WriteByte (&host_client->netchan.message, percent);
	SZ_Write (&host_client->netchan.message, buffer, r);

	if (host_client->downloadcount != host_client->downloadsize)
		return;

	fclose (host_client->download);
	host_client->download = NULL;
}
Пример #6
0
/**
 * @brief Adds command text immediately after the current command
 * @note Adds a @c \\n to the text
 * @todo actually change the command buffer to do less copying
 */
void Cbuf_InsertText (const char *text)
{
	char *temp;
	int templen;

	if (!text || !*text)
		return;

	/* copy off any commands still remaining in the exec buffer */
	templen = cmd_text.cursize;
	if (templen) {
		temp = (char *)Mem_Alloc(templen);
		memcpy(temp, cmd_text.data, templen);
		SZ_Clear(&cmd_text);
	} else
		temp = NULL;			/* shut up compiler */

	/* add the entire text of the file */
	Cbuf_AddText(text);

	/* add the copied off data */
	if (templen) {
		SZ_Write(&cmd_text, temp, templen);
		Mem_Free(temp);
	}
}
Пример #7
0
void CConsole::AddCommandToHead(char *sCommand)
{
	char	*temp;
	int	templen;

	// skopiuj wszystkie czekajace komendy
	templen = m_CmdText.cursize;
	if ( templen )
	{
		temp = (char *)new char[ templen ];
		memcpy( temp, m_CmdText.data, templen );
		SZ_Clear( &m_CmdText );
	}
	else
		temp = NULL;

	// najpier dodajemy zadana komende
	AddCommand( sCommand );

	// a potem skopiowana reszte
	if (templen)
	{
		SZ_Write( &m_CmdText, temp, templen );
		delete[] temp;
	}	
}
Пример #8
0
/*
 * Adds command text immediately after the current command
 * Adds a \n to the text
 */
void
Cbuf_InsertText(char *text)
{
    char *temp;
    int templen;

    /* copy off any commands still remaining in the exec buffer */
    templen = cmd_text.cursize;

    if (templen)
    {
        temp = Z_Malloc(templen);
        memcpy(temp, cmd_text.data, templen);
        SZ_Clear(&cmd_text);
    }
    else
    {
        temp = NULL;
    }

    /* add the entire text of the file */
    Cbuf_AddText(text);

    /* add the copied off data */
    if (templen)
    {
        SZ_Write(&cmd_text, temp, templen);
        Z_Free(temp);
    }
}
Пример #9
0
Файл: cmd.c Проект: Slipyx/r1q2
/*
============
Cbuf_AddText

Adds command text at the end of the buffer
============
*/
void EXPORT Cbuf_AddText (const char *text)
{
	int		l;

	if (!text[0])
		return;
	
	l = (int)strlen (text);

/*	if (commandsource == pendingcommands[pendingcommandindex].source)
		cmd_text = pendingcommands[pendingcommandindex].buffer;
	else
		pendingcommandindex++;

		if (pendingcommandindex == MAX_PENDING_BUFFERS-1)
		{
			Com_Printf ("Cbuf_AddText: no free buffers\n", LOG_GENERAL);
			return;
		}
*/

	if (cmd_text.cursize + l >= cmd_text.maxsize)
	{
		Com_Printf ("Cbuf_AddText: overflow\n", LOG_GENERAL);
		return;
	}
	SZ_Write (&cmd_text, text, l);
	//Com_DPrintf ("Wrote %d bytes to cmd_text: %s\n", l, text);
}
Пример #10
0
int Loop_GetMessage (qsocket_t *sock)
{
	int		ret;
	int		length;

	if (sock->receiveMessageLength == 0)
		return 0;

	ret = sock->receiveMessage[0];
	length = sock->receiveMessage[1] + (sock->receiveMessage[2] << 8);
	// alignment byte skipped here
	SZ_Clear (&net_message);
	SZ_Write (&net_message, &sock->receiveMessage[4], length);

	length = IntAlign(length + 4);
	sock->receiveMessageLength -= length;

	if (sock->receiveMessageLength)
		Q_memcpy(sock->receiveMessage, &sock->receiveMessage[length], sock->receiveMessageLength);

	if (sock->driverdata && ret == 1)
		((qsocket_t *)sock->driverdata)->canSend = TRUE;

	return ret;
}
Пример #11
0
void MSG_WriteBuf(sizebuf_t *sb, int len, const void *buf) {

   if(buf == NULL) {
      Con_Printf("MSG_WriteBuf: Passed null buffer");
      return;
   }
   SZ_Write(sb, buf, len);
}
Пример #12
0
//
// SV_AcknowledgePacket
//
void SV_AcknowledgePacket(player_t &player)
{
	client_t *cl = &player.client;

	int sequence = MSG_ReadLong();

	cl->compressor.packet_acked(sequence);

	// packet is missed
	if (sequence - cl->last_sequence > 1)
	{
		// resend
		for (int seq = cl->last_sequence+1; seq < sequence; seq++)
		{
			int  n;
			bool needfullupdate = true;

			for (n=0; n<256; n++)
				if (cl->packetseq[n] == seq)
				{
					needfullupdate = false;
					break;
				}

			if  (needfullupdate)
			{
				// do full update
				Printf(PRINT_HIGH, "need full update\n");
				cl->last_sequence = sequence;
				return;
			}

			MSG_WriteMarker(&cl->reliablebuf, svc_missedpacket);
			MSG_WriteLong(&cl->reliablebuf, seq);
			MSG_WriteShort(&cl->reliablebuf, cl->packetsize[n]);
			if (cl->packetsize[n])
				SZ_Write (&cl->reliablebuf, cl->relpackets.data, 
					cl->packetbegin[n], cl->packetsize[n]);

			if (cl->reliablebuf.overflowed)
			{
				// do full update
				Printf(PRINT_HIGH, "reliablebuf overflowed, need full update\n");
				cl->last_sequence = sequence;
				return;
			}

			if (cl->reliablebuf.cursize > 600)
				SV_SendPacket(player);

		}
	}

	cl->last_sequence = sequence;
}
Пример #13
0
/*
============
Cbuf_AddText

Adds command text at the end of the buffer
============
*/
void Cbuf_AddText(const char * text)
{
    int l;
    l = strlen(text);

    if (cmd_text.cursize + l >= cmd_text.maxsize)
    {
        Com_Printf("Cbuf_AddText: overflow\n");
        return;
    }
    SZ_Write(&cmd_text, text, strlen(text));
}
Пример #14
0
// As new commands are generated from the console or keybindings,
// the text is added to the end of the command buffer.
void Cbuf_AddText(char *text)
{
	int len = Q_strlen(text);

	if (cmd_text.cursize + len >= cmd_text.maxsize)
	{
		Con_Printf(__FUNCTION__ ": overflow\n");
		return;
	}

	SZ_Write(&cmd_text, text, len);
}
Пример #15
0
 /*
  * Sends an out-of-band datagram
  */
 void
 Netchan_OutOfBand ( q_int32_t net_socket, netadr_t adr, q_int32_t length, byte *data )
 {
   sizebuf_t send;
   byte send_buf[MAX_MSGLEN];
   /* write the packet header */
   SZ_Init ( &send, send_buf, sizeof ( send_buf ) );
   MSG_WriteLong ( &send, -1 ); /* -1 sequence means out of band */
   SZ_Write ( &send, data, length );
   /* send the datagram */
   NET_SendPacket ( net_socket, send.cursize, send.data, adr );
 }
Пример #16
0
/*
============
Cbuf_AddText

Adds command text at the end of the buffer
============
*/
void Cbuf_AddText (const char *text)
{
	int		l;

	l = strlen (text);

	if (cmd_text.cursize + l >= cmd_text.maxsize)
	{
		Con_Printf ("%s: overflow\n", __thisfunc__);
		return;
	}
	SZ_Write (&cmd_text, text, l);
}
Пример #17
0
/* <5c15> ../engine/cmd.c:1181 */
qboolean Cmd_ForwardToServerInternal(sizebuf_t *pBuf)
{
	const char *cmd_name = Cmd_Argv(0);

	if (g_pcls.state <= ca_disconnected)
	{
		if (Q_stricmp(cmd_name, "setinfo"))
		{
			Con_Printf("Can't \"%s\", not connected\n", cmd_name);
		}

		return FALSE;
	}

	if (g_pcls.demoplayback || g_bIsDedicatedServer)
	{
		return FALSE;
	}

	char tempData[4096];
	sizebuf_t tempBuf;

	tempBuf.buffername = __FUNCTION__ "::tempBuf";
	tempBuf.data = (byte *)tempData;
	tempBuf.maxsize = 4096;
	tempBuf.cursize = 0;
	tempBuf.flags = SIZEBUF_ALLOW_OVERFLOW;

	MSG_WriteByte(&tempBuf, clc_stringcmd);

	if (Q_stricmp(cmd_name, "cmd"))
	{
		SZ_Print(&tempBuf, cmd_name);
		SZ_Print(&tempBuf, " ");
	}

	SZ_Print(&tempBuf, Cmd_Argc() <= 1 ? "\n" : Cmd_Args());

	if (tempBuf.flags & SIZEBUF_OVERFLOWED)
	{
		return FALSE;
	}

	if (tempBuf.cursize + pBuf->cursize <= pBuf->maxsize)
	{
		SZ_Write(pBuf, tempBuf.data, tempBuf.cursize);
		return TRUE;
	}

	return FALSE;
}
Пример #18
0
/*
-----------------------------------------------------------------------------
 Function: Cbuf_AddText -Adds command text at the end of the buffer.
 
 Parameters: text -[in] Ponter to NUL-terminated string.
 
 Returns: Nothing.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PUBLIC void Cbuf_AddText( const char *text )
{
	W32	length;
	
	length = strlen( text );

	if( cmd_text.cursize + length >= cmd_text.maxsize )
	{
		Com_Printf( "Cbuf_AddText: overflow\n" );
		return;
	}
	
	SZ_Write( &cmd_text, (void *)text, length );
}
Пример #19
0
/*
===============
Netchan_OutOfBandProxy

Sends an out-of-band datagram
================
*/
void Netchan_OutOfBandProxy (netsrc_t net_socket, netadr_t *adr, int length, const byte *data)
{
	sizebuf_t	send;
	byte		send_buf[MAX_MSGLEN];
	//byte		send_buf[MAX_MSGLEN*4+32];

// write the packet header
	SZ_Init (&send, send_buf, sizeof(send_buf));
	
	SZ_WriteLong (&send, -2);	// -1 sequence means out of band
	SZ_Write (&send, data, length);

// send the datagram
	NET_SendPacket (net_socket, send.cursize, send.data, adr);
}
Пример #20
0
void CConsole::AddCommand(char *sCommand)
{
	int 	l;

	l = strlen (sCommand);

	// jesli overflow, napisz w konsoli
	if (m_CmdText.cursize + l >= m_CmdText.maxsize)
	{
		//Con_Printf ("Cbuf_AddText: overflow");
		return;
	}
	
	// dodaj na koniec
	SZ_Write( &m_CmdText, sCommand, strlen (sCommand) );
}
Пример #21
0
void SV_AddToReliable (client_t *cl, const byte *data, int size)
{
	/* +1 is so that there's always space for the disconnect message (FIXME) */

	if (!cl->num_backbuf &&
		cl->netchan.message.cursize + size + 1 <= cl->netchan.message.maxsize)
	{
		// it will fit into the current message
		SZ_Write (&cl->netchan.message, data, size);
	}
	else
	{
		// save it for next
		SV_AddToBackbuf (cl, data, size);
	}
}
Пример #22
0
static void
Host_PreSpawn_f (void)
{
	if (cmd_source == src_command) {
		Sys_Printf ("prespawn is not valid from the console\n");
		return;
	}

	if (host_client->spawned) {
		Sys_Printf ("prespawn not valid -- already spawned\n");
		return;
	}

	SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
	MSG_WriteByte (&host_client->message, svc_signonnum);
	MSG_WriteByte (&host_client->message, 2);
	host_client->sendsignon = true;
}
Пример #23
0
/* <4f05> ../engine/cmd.c:148 */
void Cbuf_InsertTextLines(char *text)
{
	int addLen = Q_strlen(text);
	int currLen = cmd_text.cursize;

	if (cmd_text.cursize + addLen + 2 >= cmd_text.maxsize)
	{
		Con_Printf(__FUNCTION__ ": overflow\n");
		return;
	}

#ifdef REHLDS_FIXES
	if (currLen)
		Q_memmove(cmd_text.data + addLen + 1, cmd_text.data, currLen);
	
	cmd_text.data[0] = '\n'; // TODO: Why we need leading \n, if there is no commands in the start?
	Q_memcpy(&cmd_text.data[1], text, addLen);
	cmd_text.data[addLen + 1] = '\n';

	cmd_text.cursize += addLen + 2;

#else

	char *temp = NULL;
	if (currLen)
	{
		
		temp = (char *)Z_Malloc(currLen);
		Q_memcpy(temp, cmd_text.data, currLen);
		SZ_Clear(&cmd_text);
	}

	Cbuf_AddText("\n");	// TODO: Why we need leading \n, if there is no commands in the start?
	Cbuf_AddText(text);
	Cbuf_AddText("\n");

	if (currLen)
	{
		SZ_Write(&cmd_text, temp, currLen);
		Z_Free(temp);
	}
#endif // REHLDS_FIXES
}
Пример #24
0
/*
	Netchan_OutOfBand

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

	// write the packet header
	send.data = send_buf;
	send.maxsize = sizeof (send_buf);
	send.cursize = 0;

	MSG_WriteLong (&send, -1);			// -1 sequence means out of band
	SZ_Write (&send, data, length);

	// send the datagram
	// zoid, no input in demo playback mode
	if (!net_blocksend)
		Netchan_SendPacket (send.cursize, send.data, adr);
}
Пример #25
0
/* <66786> ../engine/net_chan.c:1723 */
qboolean Netchan_CopyNormalFragments(netchan_t *chan)
{
	fragbuf_t *p, *n;

	if (!chan->incomingready[FRAG_NORMAL_STREAM])
		return FALSE;

	if (!chan->incomingbufs[FRAG_NORMAL_STREAM])
	{
		Con_Printf("Netchan_CopyNormalFragments:  Called with no fragments readied\n");
		chan->incomingready[FRAG_NORMAL_STREAM] = FALSE;
		return FALSE;
	}

	p = chan->incomingbufs[FRAG_NORMAL_STREAM];

	SZ_Clear(&net_message);
	MSG_BeginReading();

	while (p)
	{
		n = p->next;

		SZ_Write(&net_message, p->frag_message.data, p->frag_message.cursize);

		Mem_Free(p);
		p = n;
	}

	if (*(uint32 *)net_message.data == MAKEID('B', 'Z', '2', '\0'))
	{
		char uncompressed[65536];
		unsigned int uncompressedSize = 65536;
		BZ2_bzBuffToBuffDecompress(uncompressed, &uncompressedSize, (char*)net_message.data + 4, net_message.cursize - 4, 1, 0);
		Q_memcpy(net_message.data, uncompressed, uncompressedSize);
		net_message.cursize = uncompressedSize;
	}

	chan->incomingbufs[FRAG_NORMAL_STREAM] = NULL;
	chan->incomingready[FRAG_NORMAL_STREAM] = false;

	return TRUE;
}
Пример #26
0
static void
write_msg (sizebuf_t *msg, int type, int to, float time, sizebuf_t *dst)
{
	int         msec;
	static double prevtime;

	msec = (time - prevtime) * 1000;
	prevtime += msec * 0.001;
	if (msec > 255)
		msec = 255;
	if (msec < 2)
		msec = 0;

	MSG_WriteByte (dst, msec);

	if (rec.lasttype != type || rec.lastto != to) {
		rec.lasttype = type;
		rec.lastto = to;
		switch (rec.lasttype) {
			case dem_all:
				MSG_WriteByte (dst, dem_all);
				break;
			case dem_multiple:
				MSG_WriteByte (dst, dem_multiple);
				MSG_WriteLong (dst, rec.lastto);
				break;
			case dem_single:
			case dem_stats:
				MSG_WriteByte (dst, rec.lasttype | (rec.lastto << 3));
				break;
			default:
				while (sv.recorders)
					SVR_RemoveUser (sv.recorders);
				Sys_Printf ("bad demo message type:%d", type);
				return;
		}
	} else {
		MSG_WriteByte (dst, dem_read);
	}

	MSG_WriteLong (dst, msg->cursize);
	SZ_Write (dst, msg->data, msg->cursize);
}
Пример #27
0
void Netchan_OutOfBand(netsrc_t sock, netadr_t adr, int length, byte *data)
{
	sizebuf_t send;
	byte send_buf[NET_MAX_PAYLOAD];

	send.buffername = "Netchan_OutOfBand";
	send.data = send_buf;
	send.maxsize = sizeof(send_buf);
	send.cursize = 0;
	send.flags = SIZEBUF_ALLOW_OVERFLOW;

	MSG_WriteLong(&send, -1);
	SZ_Write(&send, data, length);

	if (!g_pcls.demoplayback)
	{
		NET_SendPacket(sock, send.cursize, send.data, adr);
	}
}
Пример #28
0
// Sends resource to all other players, optionally skipping originating player.
void SV_Customization(client_t *pPlayer, resource_t *pResource, qboolean bSkipPlayer)
{
	int i;
	int nPlayerNumber;
	client_t *pHost;

	// Get originating player id
	for (i = 0, pHost = g_psvs.clients; i < g_psvs.maxclients; i++, pHost++)
	{
		if (pHost == pPlayer)
			break;
	}
	if (i == g_psvs.maxclients)
	{
		Sys_Error("Couldn't find player index for customization.");
	}

	nPlayerNumber = i;

	// Send resource to all other active players
	for (i = 0, pHost = g_psvs.clients; i < g_psvs.maxclients; i++, pHost++)
	{
		if (!pHost->active && !pHost->spawned || pHost->fakeclient)
			continue;

		if (pHost == pPlayer && bSkipPlayer)
			continue;

		MSG_WriteByte(&pHost->netchan.message, svc_customization);
		MSG_WriteByte(&pHost->netchan.message, nPlayerNumber);
		MSG_WriteByte(&pHost->netchan.message, pResource->type);
		MSG_WriteString(&pHost->netchan.message, pResource->szFileName);
		MSG_WriteShort(&pHost->netchan.message, pResource->nIndex);
		MSG_WriteLong(&pHost->netchan.message, pResource->nDownloadSize);
		MSG_WriteByte(&pHost->netchan.message, pResource->ucFlags);
		if (pResource->ucFlags & RES_CUSTOM)
		{
			SZ_Write(&pHost->netchan.message, pResource->rgucMD5_hash, 16);
		}
	}
}
Пример #29
0
/**
 * @brief Adds command text at the end of the buffer
 * @note Normally when a command is generate from the console or keyBindings, it will be added to the end of the command buffer.
 */
void Cbuf_AddText (const char *text)
{
	int l;

	if (cmdClosed) {
		text = strstr(text, "cmdopen");
		if (text == NULL) {
			Com_DPrintf(DEBUG_COMMANDS, "Cbuf_AddText: currently closed\n");
			return;
		}
	}

	l = strlen(text);

	if (cmd_text.cursize + l >= cmd_text.maxsize) {
		Com_Printf("Cbuf_AddText: overflow (%i) (%s)\n", cmd_text.maxsize, text);
		Com_Printf("buffer content: %s\n", cmd_text_buf);
		return;
	}
	SZ_Write(&cmd_text, text, l);
}
Пример #30
0
Файл: net.c Проект: 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);
}