示例#1
0
文件: sv_nchan.c 项目: jogi1/camquake
// check to see if client block will fit, if not, rotate buffers
void ClientReliableCheckBlock(client_t *cl, int maxsize)
{
	if (cl->num_backbuf ||
		cl->netchan.message.cursize > 
		cl->netchan.message.maxsize - maxsize - 1) {
		// we would probably overflow the buffer, save it for next
		if (!cl->num_backbuf) {
			SZ_Init (&cl->backbuf, cl->backbuf_data[0], sizeof(cl->backbuf_data[0]));
			cl->backbuf.allowoverflow = true;
			cl->backbuf_size[0] = 0;
			cl->num_backbuf++;
		}

		if (cl->backbuf.cursize > cl->backbuf.maxsize - maxsize - 1) {
			if (cl->num_backbuf == MAX_BACK_BUFFERS) {
				Com_Printf ("WARNING: MAX_BACK_BUFFERS for %s\n", cl->name);
				cl->backbuf.cursize = 0; // don't overflow without allowoverflow set
				cl->netchan.message.overflowed = true; // this will drop the client
				return;
			}
			SZ_Init (&cl->backbuf, cl->backbuf_data[cl->num_backbuf], sizeof(cl->backbuf_data[cl->num_backbuf]));
			cl->backbuf.allowoverflow = true;
			cl->backbuf_size[cl->num_backbuf] = 0;
			cl->num_backbuf++;
		}
	}
}
示例#2
0
/*
==============
Netchan_Setup

called to open a channel to a remote system
==============
*/
void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t *adr, int protocol, int qport, unsigned msglen)
{
	memset (chan, 0, sizeof(*chan));
	
	chan->sock = sock;
	chan->remote_address = *adr;

	if (protocol == PROTOCOL_R1Q2)
	{
		if (msglen)
		{
			if (msglen > MAX_USABLEMSG)
				Com_Error (ERR_DROP, "msglen > MAX_USABLEMSG");
			SZ_Init (&chan->message, chan->message_buf, msglen);
		}
		else
		{
			SZ_Init (&chan->message, chan->message_buf, MAX_USABLEMSG);	//fragmentation allows this
		}
	}
	else
	{
		SZ_Init (&chan->message, chan->message_buf, 1390);			//traditional limit
	}

	chan->qport = qport;
	chan->protocol = protocol;
	chan->last_received = curtime;
	chan->incoming_sequence = 0;
	chan->outgoing_sequence = 1;
	chan->message.allowoverflow = true;
}
示例#3
0
文件: sv_nchan.c 项目: matatk/agrip
// 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_Init

Only called at quake2.exe startup, not for each game
===============
*/
void SV_Init(void)
{
    SV_InitOperatorCommands();

    rcon_password = Cvar_Get("rcon_password", "", 0);
    Cvar_Get("skill", "1", 0);
    Cvar_Get("deathmatch", "0", CVAR_LATCH);
    Cvar_Get("coop", "0", CVAR_LATCH);
    Cvar_Get("dmflags", va("%i", DF_INSTANT_ITEMS), CVAR_SERVERINFO);
    Cvar_Get("fraglimit", "0", CVAR_SERVERINFO);
    Cvar_Get("timelimit", "0", CVAR_SERVERINFO);
    Cvar_Get("cheats", "0", CVAR_SERVERINFO | CVAR_LATCH);
    Cvar_Get("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO | CVAR_NOSET);

    maxclients = Cvar_Get("maxclients", "1", CVAR_SERVERINFO | CVAR_LATCH);
    hostname = Cvar_Get("hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE);
    timeout = Cvar_Get("timeout", "125", 0);
    zombietime = Cvar_Get("zombietime", "2", 0);
    sv_showclamp = Cvar_Get("showclamp", "0", 0);
    sv_paused = Cvar_Get("paused", "0", 0);
    sv_timedemo = Cvar_Get("timedemo", "0", 0);
    sv_enforcetime = Cvar_Get("sv_enforcetime", "0", 0);
    allow_download = Cvar_Get("allow_download", "0", CVAR_ARCHIVE);
    allow_download_players = Cvar_Get("allow_download_players", "0", CVAR_ARCHIVE);
    allow_download_models = Cvar_Get("allow_download_models", "1", CVAR_ARCHIVE);
    allow_download_sounds = Cvar_Get("allow_download_sounds", "1", CVAR_ARCHIVE);
    allow_download_maps = Cvar_Get("allow_download_maps", "1", CVAR_ARCHIVE);

    sv_noreload = Cvar_Get("sv_noreload", "0", 0);
    sv_airaccelerate = Cvar_Get("sv_airaccelerate", "0", CVAR_LATCH);
    public_server = Cvar_Get("public", "0", 0);
    sv_reconnect_limit = Cvar_Get("sv_reconnect_limit", "3", CVAR_ARCHIVE);

    SZ_Init(&net_message, net_message_buffer, sizeof(net_message_buffer));
}
示例#5
0
void NET_InitClient(void)
{
	int port = PORT_CLIENT;
	int p;

	p = COM_CheckParm ("-clientport");
	if (p && p < COM_Argc()) {
		port = atoi(COM_Argv(p+1));
	}

	if (cls.socketip == INVALID_SOCKET)
		cls.socketip = UDP_OpenSocket (port);

	if (cls.socketip == INVALID_SOCKET)
		cls.socketip = UDP_OpenSocket (PORT_ANY); // any dynamic port

	if (cls.socketip == INVALID_SOCKET)
		Sys_Error ("Couldn't allocate client socket");

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

	// determine my name & address
	NET_GetLocalAddress (cls.socketip, &net_local_cl_ipadr);

	Com_Printf_State (PRINT_OK, "Client port Initialized\n");
}
示例#6
0
文件: sv_nchan.c 项目: matatk/agrip
void ClientReliableWrite_Begin0 (client_t *cl)
{
	assert (!backbuf_write_started);
	backbuf_write_started = true;
	backbuf_dest = cl;
	SZ_Init (&backbuf, backbuf_data, sizeof(backbuf_data));
}
示例#7
0
文件: save.c 项目: jdolan/q2pro
static int read_binary_file(const char *name)
{
    qhandle_t f;
    size_t len;

    len = FS_FOpenFile(name, &f, FS_MODE_READ | FS_TYPE_REAL | FS_PATH_GAME);
    if (!f)
        return -1;

    if (len > MAX_MSGLEN)
        goto fail;

    if (FS_Read(msg_read_buffer, len, f) != len)
        goto fail;

    SZ_Init(&msg_read, msg_read_buffer, len);
    msg_read.cursize = len;

    FS_FCloseFile(f);
    return 0;

fail:
    FS_FCloseFile(f);
    return -1;
}
示例#8
0
文件: cl_parse.c 项目: Slipyx/r1q2
void CL_ParseZPacket (void)
{
#ifndef NO_ZLIB
	byte buff_in[MAX_MSGLEN];
	byte buff_out[0xFFFF];

	sizebuf_t sb, old;

	int16 compressed_len = (int16)MSG_ReadShort (&net_message);
	int16 uncompressed_len = (int16)MSG_ReadShort (&net_message);
	
	if (uncompressed_len <= 0)
		Com_Error (ERR_DROP, "CL_ParseZPacket: uncompressed_len <= 0");

	if (compressed_len <= 0)
		Com_Error (ERR_DROP, "CL_ParseZPacket: compressed_len <= 0");

	MSG_ReadData (&net_message, buff_in, compressed_len);

	SZ_Init (&sb, buff_out, uncompressed_len);
	sb.cursize = ZLibDecompress (buff_in, compressed_len, buff_out, uncompressed_len, -15);

	old = net_message;
	net_message = sb;
	CL_ParseServerMessage ();
	net_message = old;

	Com_DPrintf ("Got a ZPacket, %d->%d\n", uncompressed_len + 4, compressed_len);
#else
	Com_Error (ERR_DROP, "Receied a zPacket but no zlib in this binary");
#endif
}
示例#9
0
/*
===============
SV_Init

Only called at quake2.exe startup, not for each game
===============
*/
void SV_Init (void)
{
    Q_STInit(&packet_stable, packet_stable.size, 8, TAG_SERVER);
    s_ping = Q_STAutoRegister(&packet_stable, "ping");
    s_ack = Q_STAutoRegister(&packet_stable, "ack");
    s_status = Q_STAutoRegister(&packet_stable, "status");
    s_info = Q_STAutoRegister(&packet_stable, "info");
    s_getchallenge = Q_STAutoRegister(&packet_stable, "getchallenge");
    s_connect = Q_STAutoRegister(&packet_stable, "connect");
    s_rcon = Q_STAutoRegister(&packet_stable, "rcon");
    Q_STAutoPack(&packet_stable);

    SV_InitOperatorCommands	();

    rcon_password = Cvar_Get ("rcon_password", "", 0);
    Cvar_Get ("skill", "1", 0);
    Cvar_Get ("deathmatch", "0", CVAR_LATCH);
    Cvar_Get ("coop", "0", CVAR_LATCH);
    Cvar_Get ("dmflags", va("%i", DF_INSTANT_ITEMS), CVAR_SERVERINFO);
    Cvar_Get ("fraglimit", "0", CVAR_SERVERINFO);
    Cvar_Get ("timelimit", "0", CVAR_SERVERINFO);
    Cvar_Get ("cheats", "0", CVAR_SERVERINFO|CVAR_LATCH);
    Cvar_Get ("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO|CVAR_NOSET);;
    maxclients = Cvar_Get ("maxclients", "1", CVAR_SERVERINFO | CVAR_LATCH);
    hostname = Cvar_Get ("hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE);
    timeout = Cvar_Get ("timeout", "125", 0);
    zombietime = Cvar_Get ("zombietime", "2", 0);
    sv_showclamp = Cvar_Get ("showclamp", "0", 0);
    sv_paused = Cvar_Get ("paused", "0", 0);
    sv_timedemo = Cvar_Get ("timedemo", "0", 0);
    sv_enforcetime = Cvar_Get ("sv_enforcetime", "0", 0);
    allow_download = Cvar_Get ("allow_download", "1", CVAR_ARCHIVE);
    allow_download_players  = Cvar_Get ("allow_download_players", "0", CVAR_ARCHIVE);
    allow_download_models = Cvar_Get ("allow_download_models", "1", CVAR_ARCHIVE);
    allow_download_sounds = Cvar_Get ("allow_download_sounds", "1", CVAR_ARCHIVE);
    allow_download_maps	  = Cvar_Get ("allow_download_maps", "1", CVAR_ARCHIVE);
    allow_download_pics  = Cvar_Get ("allow_download_pics", "1", CVAR_ARCHIVE);
    allow_download_textures  = Cvar_Get ("allow_download_textures", "1", CVAR_ARCHIVE);
    // Knightmare- whether to allow downloading 24-bit textures
    allow_download_textures_24bit = Cvar_Get ("allow_download_textures_24bit", "0", CVAR_ARCHIVE);

    sv_noreload = Cvar_Get ("sv_noreload", "0", 0);

    sv_airaccelerate = Cvar_Get("sv_airaccelerate", "0", CVAR_LATCH);

    public_server = Cvar_Get ("public", "0", 0);

    sv_iplimit = Cvar_Get ("sv_iplimit", "3", 0);	// r1ch: limit connections per ip address (stop zombie dos/flood)

    sv_reconnect_limit = Cvar_Get ("sv_reconnect_limit", "3", CVAR_ARCHIVE);

    sv_entfile = Cvar_Get ("sv_entfile", "1", CVAR_ARCHIVE); // whether to use .ent file

    sv_legacy_libraries = Cvar_Get("sv_legacy_libraries", "0", CVAR_CLIENT); // disable loading legacy game libraries by default

    SZ_Init (&net_message, net_message_buffer, sizeof(net_message_buffer));

    SV_InitClientCommands();
}
示例#10
0
int main (int argc, char *argv[]){
	int i, j, k, error = 0;
	double A[N][N], B[N][N], C[N][N], D[N][N], sum;
	double A1[N][N];
	double C1[N][N];
	double time1, time2;
	int P;
	int blksz;
	
	SZ_Init (P);
	
	if (N % P != 0) printf ("Error -- N/P must be an integer\n");
	
	for (i = 0; i < N; ++i)
		for (j = 0; j < N; ++j)
			A[i][j] = j * 1; B[i][j] = i * j + 2;
			
	for (i = 0; i < N; ++i)
		for (j = 0; j < N; ++j){
			sum = 0;
			for (k = 0; k < N; ++k)
				sum += A[i][k] * B[k][i];
			D[i][j] = sum;
		}
		
	time1 = SZ_Wtime ();
	SZ_Parallel_begin
		SZ_Scatter (A, A1);
		SZ_Broadcast (B);
		
		blksz = N/P;
		for (i = 0; i < N; ++i){
			for (j = 0; j < N; ++j){
				sum = 0;
				for (k = 0; k < N; ++k){
					sum += A1[i][k] * B[k][j];
				}
				C1[i][j] = sum;
			}
		}
		
		SZ_Gather (C1, C);
	SZ_Parallel_end;
	time2 = SZ_Wtime ();
	
	int error = 0;
	for (i = 0; i < N; ++i)
		for (j = 0; j < N; ++j)
			if ((C[i][j] - D[i][j] > 0.001) || (D[i][j] - C[i][j] > 0.001)) error = -1;
			
	if (error == -1) printf ("ERROR, sequential and parallel code give different answers.\n");
	else printf ("Sequential and parallel code give same answers.\n");
	
	printf ("elapsed_time = %f (seconds)\n", time2 - time1);
	
	SZ_Finalize ();
	return 0;
}
示例#11
0
文件: sv_main.c 项目: matatk/agrip
/*
===================
SV_FullClientUpdateToClient

Writes all update values to a client's reliable stream
===================
*/
void SV_FullClientUpdateToClient (client_t *client, client_t *cl)
{
	byte data[MAX_MSGLEN];
	sizebuf_t buf;
	
	SZ_Init (&buf, data, sizeof(data));
	SV_FullClientUpdate (client, &buf);
	SV_AddToReliable (cl, buf.data, buf.cursize);
}
示例#12
0
//special notice: all the function names in this file must be lower-cases!!
void sz_init_c_(char *configFile,int *len,int *ierr)
{
    int i;
    char s2[*len+1];
    for(i=0;i<*len;i++)
        s2[i]=configFile[i];
    s2[*len]='\0';
 //   printf("sconfigFile=%s\n",configFile);
    *ierr = SZ_Init(s2);
}
示例#13
0
文件: netchan.c 项目: axltxl/hecatomb
 /*
  * 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 );
 }
示例#14
0
文件: netchan.c 项目: axltxl/hecatomb
 /*
  * called to open a channel to a remote system
  */
 void
 Netchan_Setup ( netsrc_t sock, netchan_t *chan, netadr_t adr, q_int32_t qport )
 {
   memset ( chan, 0, sizeof ( *chan ) );
   chan->sock = sock;
   chan->remote_address = adr;
   chan->qport = qport;
   chan->last_received = curtime;
   chan->incoming_sequence = 0;
   chan->outgoing_sequence = 1;
   SZ_Init ( &chan->message, chan->message_buf, sizeof ( chan->message_buf ) );
   chan->message.allowoverflow = true;
 }
示例#15
0
void QTV_ForwardToServerEx (qbool skip_if_no_params, qbool use_first_argument)
{
	char data[1024 + 100] = {0}, text[1024], *s;
	sizebuf_t buf;

	if (    cls.mvdplayback != QTV_PLAYBACK
		|| !playbackfile /* || cls.qtv_ezquake_ext & QTV_EZQUAKE_EXT_CLC_STRINGCMD ???*/
	   )
		return;

	if (skip_if_no_params)
		if (Cmd_Argc() < 2)
			return;

	// lowercase command
	for (s = Cmd_Argv(0); *s; s++)
		*s = (char) tolower(*s);

	if (cls.state == ca_disconnected) {
		Com_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0));
		return;
	}

	if (strcmp(Cmd_Argv(0), "say_team") == 0 && !qtv_say_team.integer) {
		Com_Printf("Cannot send team messages. Use qtv_say_team 1 to override.\n");
		return;
	}

	SZ_Init(&buf, (byte*) data, sizeof(data));

	s = TP_ParseMacroString (Cmd_Args());
	s = TP_ParseFunChars (s, true);

	text[0] = 0; // *cat is dangerous, ensure we empty buffer before use it

	if (use_first_argument)
		strlcat(text, Cmd_Argv(0), sizeof(text));

	if (s[0])
	{
		strlcat(text, " ", sizeof(text));
		strlcat(text, s,   sizeof(text));
	}

	MSG_WriteShort  (&buf, 2 + 1 + strlen(text) + 1); // short + byte + null terminated string
	MSG_WriteByte   (&buf, qtv_clc_stringcmd);
	MSG_WriteString (&buf, text);

	VFS_WRITE(playbackfile, buf.data, buf.cursize);
}
示例#16
0
文件: sv_nchan.c 项目: matatk/agrip
static void SV_AddToBackbuf (client_t *cl, const byte *data, int size)
{
	if (!cl->num_backbuf) {
		SZ_Init (&cl->backbuf, cl->backbuf_data[0], sizeof(cl->backbuf_data[0]));
		cl->backbuf_size[0] = 0;
		cl->num_backbuf++;
	}

	if (cl->backbuf.cursize + size > cl->backbuf.maxsize) {
		if (cl->num_backbuf == MAX_BACK_BUFFERS) {
			Com_Printf ("WARNING: MAX_BACK_BUFFERS for %s\n", cl->name);
			cl->backbuf.cursize = 0; // don't overflow without allowoverflow set
			cl->netchan.message.overflowed = true; // this will drop the client
			return;
		}
		SZ_Init (&cl->backbuf, cl->backbuf_data[cl->num_backbuf], sizeof(cl->backbuf_data[cl->num_backbuf]));
		cl->backbuf_size[cl->num_backbuf] = 0;
		cl->num_backbuf++;
	}

	// write it to the backbuf
	SZ_Write (&cl->backbuf, data, size);
	cl->backbuf_size[cl->num_backbuf-1] = cl->backbuf.cursize;
}
示例#17
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);
}
示例#18
0
/*
 * ===============
 * SV_Init
 *
 * Only called at quake2.exe startup, not for each game
 * ===============
 */
void SV_Init(void)
{
    SV_InitOperatorCommands();

    rcon_password = Cvar_Get("rcon_password", "", 0);
    Cvar_Get("skill", "1", 0);
    Cvar_Get("deathmatch", "0", CVAR_LATCH);
    Cvar_Get("coop", "0", CVAR_LATCH);
    Cvar_Get("dmflags", va("%i", DF_INSTANT_ITEMS), CVAR_SERVERINFO);
    Cvar_Get("fraglimit", "0", CVAR_SERVERINFO);
    Cvar_Get("timelimit", "0", CVAR_SERVERINFO);
    Cvar_Get("cheats", "0", CVAR_SERVERINFO | CVAR_LATCH);
    Cvar_Get("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO | CVAR_NOSET);
    maxclients              = Cvar_Get("maxclients", "1", CVAR_SERVERINFO | CVAR_LATCH);
    hostname                = Cvar_Get("hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE);
    timeout                 = Cvar_Get("timeout", "125", 0);
    zombietime              = Cvar_Get("zombietime", "2", 0);
    sv_showclamp            = Cvar_Get("showclamp", "0", 0);
    sv_paused               = Cvar_Get("paused", "0", 0);
    sv_timedemo             = Cvar_Get("timedemo", "0", 0);
    sv_enforcetime          = Cvar_Get("sv_enforcetime", "0", 0);
    allow_download          = Cvar_Get("allow_download", "1", CVAR_ARCHIVE);
    allow_download_players  = Cvar_Get("allow_download_players", "0", CVAR_ARCHIVE);
    allow_download_models   = Cvar_Get("allow_download_models", "1", CVAR_ARCHIVE);
    allow_download_sounds   = Cvar_Get("allow_download_sounds", "1", CVAR_ARCHIVE);
    allow_download_maps     = Cvar_Get("allow_download_maps", "1", CVAR_ARCHIVE);
    allow_download_pics     = Cvar_Get("allow_download_pics", "1", CVAR_ARCHIVE);
    allow_download_textures = Cvar_Get("allow_download_textures", "1", CVAR_ARCHIVE);
    // Knightmare- whether to allow downloading 24-bit textures
    allow_download_textures_24bit = Cvar_Get("allow_download_textures_24bit", "0", CVAR_ARCHIVE);

    sv_noreload = Cvar_Get("sv_noreload", "0", 0);

    sv_airaccelerate = Cvar_Get("sv_airaccelerate", "0", CVAR_LATCH);

    public_server = Cvar_Get("public", "0", 0);

    sv_iplimit = Cvar_Get("sv_iplimit", "3", 0);        // r1ch: limit connections per ip address (stop zombie dos/flood)

    sv_reconnect_limit = Cvar_Get("sv_reconnect_limit", "3", CVAR_ARCHIVE);

    sv_entfile = Cvar_Get("sv_entfile", "1", CVAR_ARCHIVE);      // whether to use .ent file

    SZ_Init(&net_message, net_message_buffer, sizeof(net_message_buffer));
}
示例#19
0
文件: sv_bot.cpp 项目: luaman/zq
edict_t *SV_CreateBot ()
{
	int			i, numclients;
	client_t	*cl, *newcl;
	edict_t		*ent;

	numclients = 0;
	newcl = NULL;

	for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) {
		if (cl->state == cs_free) {
			if (!newcl)
				newcl = cl;
			continue;
		}
		if (!cl->spectator)
			numclients++;
	}

	if (numclients >= maxclients.value || !newcl)
		return sv.edicts;		// all player spots full, return world

	newcl->clear();
	newcl->state = cs_spawned;
	newcl->bot = true;
	newcl->userid = SV_GenerateUserID();
	newcl->extensions = CLIENT_EXTENSIONS;	// bots always use latest ZQuake :-)

	// init a bogus network connection
	SZ_Init (&newcl->datagram, newcl->datagram_buf, sizeof(newcl->datagram_buf));
	newcl->datagram.allowoverflow = true;
	Netchan_Setup (NS_SERVER, &newcl->netchan, net_null, 0);

	// set up the edict
	ent = EDICT_NUM((newcl - svs.clients) + 1);
	newcl->edict = ent;

//	Com_DPrintf ("Bot %s connected\n", newcl->name.c_str());

	SetUpClientEdict (newcl, ent);

	return ent;
}
示例#20
0
void NET_Init (void)
{
#ifdef _WIN32
	WORD wVersionRequested;
	int r;

	wVersionRequested = MAKEWORD(1, 1);
	r = WSAStartup (wVersionRequested, &winsockdata);
	if (r)
		Sys_Error ("Winsock initialization failed.");
#endif

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

	Con_DPrintf("UDP Initialized\n");

#ifndef SERVERONLY
	cls.socketip = INVALID_SOCKET;
// TCPCONNECT -->
	cls.sockettcp = INVALID_SOCKET;
// <--TCPCONNECT
#endif

#ifndef CLIENTONLY
	Cvar_Register (&sv_local_addr);

	svs.socketip = INVALID_SOCKET;
// TCPCONNECT -->
	svs.sockettcp = INVALID_SOCKET;
// <--TCPCONNECT
#endif

#ifdef SERVERONLY
	// As client+server we init it in SV_SpawnServer().
	// As serveronly we do it here.
	NET_InitServer();
#endif
}
示例#21
0
int H5Z_SZ_Init(char* cfgFile) 
{ 
	herr_t ret;
	//printf("start in H5Z_SZ_Init, load_conffile_flag = %d\n", load_conffile_flag);
	if(load_conffile_flag==0)
	{
		load_conffile_flag = 1;
		int status = SZ_Init(cfgFile);
		//printf("cfgFile=%s\n", cfgFile);
		//printf("szMode=%d, errorBoundMode=%d, relBoundRatio=%f\n", szMode, errorBoundMode, relBoundRatio);
		if(status == SZ_NSCS)
			return SZ_NSCS;
		else
			return SZ_SCES;		
	}

	ret = H5Zregister(H5Z_SZ); 
	if(ret < 0)
		return SZ_NSCS;
	else
		return SZ_SCES;
}
示例#22
0
void CL_ParseZPacket (sizebuf_t *msg)
{
	byte buff_in[MAX_MSGLEN];
	byte buff_out[0xFFFF];
	sizebuf_t sb;
	uint16 compressed_len = MSG_ReadShort (msg);
	uint16 uncompressed_len = MSG_ReadShort (msg);
	
	if (uncompressed_len <= 0)
		Com_Error (ERR_DROP, "CL_ParseZPacket: uncompressed_len <= 0");

	if (compressed_len <= 0)
		Com_Error (ERR_DROP, "CL_ParseZPacket: compressed_len <= 0");

	MSG_ReadData (msg, buff_in, compressed_len);

	SZ_Init (&sb, buff_out, uncompressed_len);
	sb.cursize = ZLibDecompress (buff_in, compressed_len, buff_out, uncompressed_len, -15);

	CL_ParseServerMessage(&sb);

	Com_DPrintf ("Got a ZPacket, %d->%d\n", uncompressed_len + 4, compressed_len);
}
示例#23
0
void NET_InitServer (void)
{
	int port = PORT_SERVER;
	int p;

	p = COM_CheckParm ("-port");
	if (p && p < COM_Argc()) {
		port = atoi(COM_Argv(p+1));
	}

	if (svs.socketip == INVALID_SOCKET) {
		svs.socketip = UDP_OpenSocket (port);
	}

	if (svs.socketip != INVALID_SOCKET) {
		NET_GetLocalAddress (svs.socketip, &net_local_sv_ipadr);
		Cvar_SetROM (&sv_local_addr, NET_AdrToString (net_local_sv_ipadr));
	}
	else {
		// FIXME: is it right???
		Cvar_SetROM (&sv_local_addr, "");
	}

	if (svs.socketip == INVALID_SOCKET) {
#ifdef SERVERONLY
		Sys_Error
#else
		Con_Printf
#endif
			("WARNING: Couldn't allocate server socket\n");
	}

#ifndef SERVERONLY
	// init the message buffer
	SZ_Init (&net_message, net_message_buffer, sizeof(net_message_buffer));
#endif
}
示例#24
0
/*
================
SV_SpawnServer

Change the server to a new map, taking all connected
clients along with it.

================
*/
void SV_SpawnServer (char *server, char *spawnpoint, server_state_t serverstate, qboolean attractloop, qboolean loadgame)
{
	int			i;
	unsigned	checksum;

	if (attractloop)
		Cvar_Set ("paused", "0");

	Com_Printf ("------- Server Initialization -------\n");

	Com_DPrintf ("SpawnServer: %s\n",server);
	if (sv.demofile)
		fclose (sv.demofile);

	svs.spawncount++;		// any partially connected client will be
							// restarted
	sv.state = ss_dead;
	Com_SetServerState (sv.state);

	// wipe the entire per-level structure
	memset (&sv, 0, sizeof(sv));
	svs.realtime = 0;
	sv.loadgame = loadgame;
	sv.attractloop = attractloop;

	// save name for levels that don't set message
	strcpy (sv.configstrings[CS_NAME], server);
	if (Cvar_VariableValue ("deathmatch"))
	{
		sprintf(sv.configstrings[CS_AIRACCEL], "%g", sv_airaccelerate->value);
		pm_airaccelerate = sv_airaccelerate->value;
	}
	else
	{
		strcpy(sv.configstrings[CS_AIRACCEL], "0");
		pm_airaccelerate = 0;
	}

	SZ_Init (&sv.multicast, sv.multicast_buf, sizeof(sv.multicast_buf));

	strcpy (sv.name, server);

	// leave slots at start for clients only
	for (i=0 ; i<maxclients->value ; i++)
	{
		// needs to reconnect
		if (svs.clients[i].state > cs_connected)
			svs.clients[i].state = cs_connected;
		svs.clients[i].lastframe = -1;
	}

	sv.time = 1000;
	
	strcpy (sv.name, server);
	strcpy (sv.configstrings[CS_NAME], server);

	if (serverstate != ss_game)
	{
		sv.models[1] = CM_LoadMap ("", false, &checksum);	// no real map
	}
	else
	{
		Com_sprintf (sv.configstrings[CS_MODELS+1],sizeof(sv.configstrings[CS_MODELS+1]),
			"maps/%s.bsp", server);
		sv.models[1] = CM_LoadMap (sv.configstrings[CS_MODELS+1], false, &checksum);
	}
	Com_sprintf (sv.configstrings[CS_MAPCHECKSUM],sizeof(sv.configstrings[CS_MAPCHECKSUM]),
		"%i", checksum);

	//
	// clear physics interaction links
	//
	SV_ClearWorld ();
	
	for (i=1 ; i< CM_NumInlineModels() ; i++)
	{
		Com_sprintf (sv.configstrings[CS_MODELS+1+i], sizeof(sv.configstrings[CS_MODELS+1+i]),
			"*%i", i);
		sv.models[i+1] = CM_InlineModel (sv.configstrings[CS_MODELS+1+i]);
	}

	//
	// spawn the rest of the entities on the map
	//	

	// precache and static commands can be issued during
	// map initialization
	sv.state = ss_loading;
	Com_SetServerState (sv.state);

	// load and spawn all other entities
	ge->SpawnEntities ( sv.name, CM_EntityString(), spawnpoint );

	// run two frames to allow everything to settle
	ge->RunFrame ();
	ge->RunFrame ();

	// all precaches are complete
	sv.state = serverstate;
	Com_SetServerState (sv.state);
	
	// create a baseline for more efficient communications
	SV_CreateBaseline ();

	// check for a savegame
	SV_CheckForSavegame ();

	// set serverinfo variable
	Cvar_FullSet ("mapname", sv.name, CVAR_SERVERINFO | CVAR_NOSET);

	Com_Printf ("-------------------------------------\n");
}
示例#25
0
int main (int argc, char *argv[]){
	double t;
	double T;
	double A[6][5] = {{25.0, 400.0, 400.0, 0.0, 0.0}, {20.0, 200.0, 400.0, 3.0, 4.0}, {30.0, 50.0, 600.0, 1.0, 0.0},
				   {50.0, 400.0, 200.0, 1.0, 0.0}, {40.0, 700.0, 700.0, -1.0, 0.0}, {70.0, 200.0, 100.0, -1.0, 0.0}};
	int N = 6;
	double x_diff, y_diff, r, F, Fx[N], Fy[N], new_x[N], new_y[N];
	int i, j, a;
	int P;
	
	SZ_Init (P);
	
	printf ("Number of time intervals?\n");
	scanf ("%lf", &T);
	
	printf ("Length of time interval?\n");
	scanf ("%lf", &t);
	
	printf ("\n");
	printf ("Mass\tx pos\ty pos\tx vel\t y vel\n");
	
	for (i = 0; i < 6; ++i){
		for (j = 0; j < 5; ++j){
			printf ("%.2f\t", A[i][j]);
		}
		printf ("\n");
	}
	
	SZ_Parallel_begin
		SZ_Broadcast (&T);
		SZ_Broadcast (&t);
		for (i = 0; i < T; ++i){
			SZ_Broadcast (A);
		
			a = SZ_Get_process_num();
			Fx[a] = A[a][3];
			Fy[a] = A[a][4];
	
			for (j = 0; j < N; ++j){
				if (a != j){
					x_diff = A[j][1] - A[a][1];
					y_diff = A[j][2] - A[a][2];
					r = sqrt ((x_diff * x_diff) + (y_diff * y_diff));
					F = (G * A[a][0] * A[j][0]) / (r * r);
					Fx[a] += F * ((A[a][3] - A[j][3]) / r);
					Fy[a] += F * ((A[a][4] - A[j][4]) / r);
			
					if (((A[a][0] + A[j][0]) / 2) > r){
						A[a][0] = 0.0;
						A[j][0] = 0.0;
					}
				}
			}
	
			new_x[a] = (Fx[a] * t) + A[a][1];
			new_y[a] = (Fy[a] * t) + A[a][2];
	
			if (new_x[a] > 1000.0){
				new_x[a] = 1000.0 - (new_x[a] - 1000.0);
			} else if (new_x[a] < 0){
				new_x[a] = new_x[a] * -1; 
			}
	
			if (new_y[a] > 1000.0){
				new_y[a] = 1000.0 - (new_y[a] - 1000.0);
			} else if (new_y[a] < 0){
				new_y[a] = new_y[a] * -1;  
			}
	
			A[a][3] = Fx[a];
			A[a][4] = Fy[a];
			A[a][1] = new_x[a];
			A[a][2] = new_y[a];
		
			SZ_AllBroadcast (A);
		}
	SZ_Parallel_end;
	
	printf ("\n");
	printf ("Mass\tx pos\ty pos\tx vel\t y vel\n");
	
	for (i = 0; i < 6; ++i){
		for (j = 0; j < 5; ++j){
			printf ("%.2f\t", A[i][j]);
		}
		printf ("\n");
	}
	
	SZ_Finalize();
	return 0; 
}
示例#26
0
文件: sv_main.c 项目: matatk/agrip
/*
==================
SVC_DirectConnect

A connection request that did not come from the master
==================
*/
void SVC_DirectConnect (void)
{
	char		userinfo[1024];
	netadr_t	adr;
	int			i;
	client_t	*cl, *newcl;
	edict_t		*ent;
	int			edictnum;
	char		*s;
	int			clients, spectators;
	qbool		spectator;
	int			qport;
	int			version;
	int			challenge;

	version = atoi(Cmd_Argv(1));
	if (version != PROTOCOL_VERSION)
	{
		Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nServer is version %4.2f.\n", A2C_PRINT, QW_VERSION);
		Com_Printf ("* rejected connect from version %i\n", version);
		return;
	}

	qport = atoi(Cmd_Argv(2));
	challenge = atoi(Cmd_Argv(3));

	// note an extra byte is needed to replace spectator key
	strlcpy (userinfo, Cmd_Argv(4), sizeof(userinfo)-1);

	// see if the challenge is valid
	if (net_from.type != NA_LOOPBACK)
	{
		for (i=0 ; i<MAX_CHALLENGES ; i++)
		{
			if (NET_CompareBaseAdr (net_from, svs.challenges[i].adr))
			{
				if (challenge == svs.challenges[i].challenge)
					break;		// good
				Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nBad challenge.\n", A2C_PRINT);
				return;
			}
		}
		if (i == MAX_CHALLENGES)
		{
			Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nNo challenge for address.\n", A2C_PRINT);
			return;
		}
	}

	// check for password or spectator_password
	s = Info_ValueForKey (userinfo, "spectator");
	if (s[0] && strcmp(s, "0"))
	{
		if (sv_spectatorPassword.string[0] && 
			Q_stricmp(sv_spectatorPassword.string, "none") &&
			strcmp(sv_spectatorPassword.string, s) )
		{	// failed
			Com_Printf ("%s:spectator password failed\n", NET_AdrToString (net_from));
			Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nrequires a spectator password\n\n", A2C_PRINT);
			return;
		}
		Info_RemoveKey (userinfo, "spectator");
		Info_SetValueForStarKey (userinfo, "*spectator", "1", MAX_INFO_STRING);
		spectator = true;
	}
	else
	{
		s = Info_ValueForKey (userinfo, "password");
		if (sv_password.string[0] && 
			Q_stricmp(sv_password.string, "none") &&
			strcmp(sv_password.string, s) )
		{
			Com_Printf ("%s:password failed\n", NET_AdrToString (net_from));
			Netchan_OutOfBandPrint (NS_SERVER, net_from, "%c\nserver requires a password\n\n", A2C_PRINT);
			return;
		}
		spectator = false;
		Info_RemoveKey (userinfo, "password");
	}

#ifdef MAUTH
    // Check that the client is allowed to connect...
	if( net_from.type != NA_LOOPBACK && !COM_CheckParm("-nomauth") )
    {
        authclient_t *authclient;
    
        // Try the auth token queue first...
        authclient = SV_AuthListFind(&authtokq, Info_ValueForKey(userinfo, "name"));
        if( authclient == NULL )
        {
            // Fall back to checking if they had already connected and are in the
            // client queue already (i.e. were on here before a map change)...
            authclient = SV_AuthListFind(&authclientq, Info_ValueForKey(userinfo, "name"));
            if( authclient == NULL )
            {
                // FIXME drop with reason
                Com_Printf ("MAUTH: Client %s not in a queue; connect refused.\n", Info_ValueForKey(userinfo, "name"));
                return;
            }
        }
        else
        {
            // They're valid, so move them to the main client queue from the
            // auth cache queue...
            SV_AuthListMove(&authtokq, &authclientq, authclient);
        }

        // Move to auth'd clients queue if they're valid...
        if( !authclient->valid )
        {
            // FIXME drop with reason
            Com_Printf ("MAUTH: Client %s not validated yet; connect refused.\n", Info_ValueForKey(userinfo, "name"));
            return;
        }
        
        //SV_AuthListPrint(&authtokq);
        //SV_AuthListPrint(&authclientq);
        
        Com_Printf ("MAUTH: Client %s connection allowed.\n", Info_ValueForKey(userinfo, "name"));
    }
    else
    {
        Com_Printf("MAUTH: loopback or disabled; allowing client connection.\n");
    }
#endif

	adr = net_from;

	// if there is already a slot for this ip, reuse it
	for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++)
	{
		if (cl->state == cs_free)
			continue;
		if (NET_CompareBaseAdr (adr, cl->netchan.remote_address)
			&& ( cl->netchan.qport == qport 
			|| adr.port == cl->netchan.remote_address.port ))
		{
			if (cl->state == cs_connected) {
				Com_Printf ("%s:dup connect\n", NET_AdrToString (adr));
				return;
			}

			Com_Printf ("%s:reconnect\n", NET_AdrToString (adr));
			if (cl->state == cs_spawned)
			{
				SV_DropClient (cl);
				SV_ClearReliable (cl);	// don't send the disconnect
			}
			cl->state = cs_free;
			break;
		}
	}

	// count up the clients and spectators and find an empty client slot
	clients = spectators = 0;
	newcl = NULL;
	for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++,cl++)
	{
		if (cl->state == cs_free) {
			if (!newcl)
				newcl = cl;		// grab first available slot
			continue;
		}
		if (cl->spectator)
			spectators++;
		else
			clients++;
	}

	// if at server limits, refuse connection
	if ( (spectator && spectators >= (int)maxspectators.value)
		|| (!spectator && clients >= (int)maxclients.value)
		|| !newcl)
	{
		Com_Printf ("%s:full connect\n", NET_AdrToString (adr));
		Netchan_OutOfBandPrint (NS_SERVER, adr, "%c\nserver is full\n\n", A2C_PRINT);
		return;
	}

	// build a new connection
	// accept the new client
	// this is the only place a client_t is ever initialized
	memset (newcl, 0, sizeof(*newcl));
	newcl->userid = SV_GenerateUserID();

	strlcpy (newcl->userinfo, userinfo, sizeof(newcl->userinfo));

	Netchan_OutOfBandPrint (NS_SERVER, adr, "%c", S2C_CONNECTION );

	Netchan_Setup (NS_SERVER, &newcl->netchan, adr, qport);

	newcl->state = cs_connected;

	SZ_Init (&newcl->datagram, newcl->datagram_buf, sizeof(newcl->datagram_buf));
	newcl->datagram.allowoverflow = true;

	// spectator mode can ONLY be set at join time
	newcl->spectator = spectator;

	// extract extensions bits
	newcl->extensions = atoi(Info_ValueForKey(newcl->userinfo, "*z_ext"));
	Info_RemoveKey (newcl->userinfo, "*z_ext");

#ifdef VWEP_TEST
	newcl->extensions |= atoi(Info_ValueForKey(newcl->userinfo, "*vwtest")) ? Z_EXT_VWEP : 0;
	Info_RemoveKey (newcl->userinfo, "*vwtest");
#endif

	// See if the client is using a proxy. The best test I can come up with for now...
	newcl->uses_proxy = *Info_ValueForKey(newcl->userinfo, "Qizmo") ? true : false;

	edictnum = (newcl - svs.clients) + 1;
	ent = EDICT_NUM(edictnum);	
	ent->inuse = true;
	newcl->edict = ent;
	
	// parse some info from the info strings
	SV_ExtractFromUserinfo (newcl);

	// JACK: Init the floodprot stuff.
	for (i=0; i<10; i++)
		newcl->whensaid[i] = 0.0;
	newcl->whensaidhead = 0;
	newcl->lockedtill = 0;

	// call the progs to get default spawn parms for the new client
	PR_ExecuteProgram (pr_global_struct->SetNewParms);
	for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
		newcl->spawn_parms[i] = (&pr_global_struct->parm1)[i];

	if (newcl->spectator)
		Com_Printf ("Spectator %s connected\n", newcl->name);
	else
		Com_DPrintf ("Client %s connected\n", newcl->name);

	newcl->sendinfo = true;
}
示例#27
0
文件: sv_main.c 项目: matatk/agrip
/*
===============
SV_InitLocal
===============
*/
void SV_InitLocal (void)
{
	int		i;
	extern cvar_t	sv_spectalk;
	extern cvar_t	sv_mapcheck;
	extern cvar_t	sv_minping;
	extern cvar_t	sv_maxpitch;
	extern cvar_t	sv_minpitch;
	extern cvar_t	sv_nailhack;
	extern cvar_t	sv_loadentfiles;
	extern cvar_t	sv_maxvelocity;
	extern cvar_t	sv_gravity;
	extern cvar_t	pm_stopspeed;
	extern cvar_t	pm_spectatormaxspeed;
	extern cvar_t	pm_accelerate;
	extern cvar_t	pm_airaccelerate;
	extern cvar_t	pm_wateraccelerate;
	extern cvar_t	pm_friction;
	extern cvar_t	pm_waterfriction;
	extern cvar_t	pm_bunnyspeedcap;
	extern cvar_t	pm_ktjump;
	extern cvar_t	pm_slidefix;
	extern cvar_t	pm_airstep;
	extern cvar_t	pm_pground;
	packet_t		*packet_freeblock;	// initialise delayed packet free block

	SV_InitOperatorCommands	();

	Cvar_Register (&sv_rconPassword);
	Cvar_Register (&sv_password);
	Cvar_Register (&sv_spectatorPassword);

	Cvar_Register (&sv_phs);
	Cvar_Register (&sv_paused);
	Cvar_Register (&sv_pausable);
	Cmd_AddLegacyCommand ("pausable", "sv_pausable");
	Cvar_Register (&sv_nailhack);
	Cvar_Register (&sv_maxrate);
	Cvar_Register (&sv_fastconnect);
	Cvar_Register (&sv_loadentfiles);
	if (!dedicated)
		sv_mintic.string = "0";		// a value of 0 will tie physics tics to screen updates
	Cvar_Register (&sv_mintic);
	Cvar_Register (&sv_maxtic);
	Cvar_Register (&sv_timeout);
	Cmd_AddLegacyCommand ("timeout", "sv_timeout");
	Cvar_Register (&sv_zombietime);
	Cmd_AddLegacyCommand ("zombietime", "sv_zombietime");
	Cvar_Register (&sv_spectalk);
	Cvar_Register (&sv_mapcheck);
	if (dedicated)
		Cvar_Register (&sv_minping);
	Cvar_Register (&sv_maxpitch);
	Cvar_Register (&sv_minpitch);

	Cvar_Register (&deathmatch);
	Cvar_Register (&teamplay);
	Cvar_Register (&skill);
	Cvar_Register (&coop);
	Cvar_Register (&fraglimit);
	Cvar_Register (&timelimit);
	Cvar_Register (&samelevel);
	Cvar_Register (&maxclients);
	Cvar_Register (&maxspectators);
	Cvar_Register (&hostname);
	Cvar_Register (&watervis);

	Cvar_Register (&sv_maxvelocity);
	Cvar_Register (&sv_gravity);
	Cvar_Register (&pm_stopspeed);
	Cvar_Register (&pm_maxspeed);
	Cvar_Register (&pm_spectatormaxspeed);
	Cvar_Register (&pm_accelerate);
	Cvar_Register (&pm_airaccelerate);
	Cvar_Register (&pm_wateraccelerate);
	Cvar_Register (&pm_friction);
	Cvar_Register (&pm_waterfriction);
	Cvar_Register (&pm_bunnyspeedcap);
	Cvar_Register (&pm_ktjump);
	Cvar_Register (&pm_slidefix);
	Cvar_Register (&pm_airstep);
	Cvar_Register (&pm_pground);

	Cvar_Register (&allow_download);
	Cvar_Register (&allow_download_skins);
	Cvar_Register (&allow_download_models);
	Cvar_Register (&allow_download_sounds);
	Cvar_Register (&allow_download_maps);
	Cvar_Register (&allow_download_pakmaps);
	Cvar_Register (&allow_download_gfx);
	Cvar_Register (&allow_download_other);

	Cvar_Register (&filterban);
	Cmd_AddCommand ("addip", SV_AddIP_f);
	Cmd_AddCommand ("removeip", SV_RemoveIP_f);
	Cmd_AddCommand ("listip", SV_ListIP_f);
	Cmd_AddCommand ("writeip", SV_WriteIP_f);

	for (i=1 ; i<MAX_MODELS ; i++)
		sprintf (localmodels[i], "*%i", i);

	Info_SetValueForStarKey (svs.info, "*version", va(PROGRAM " %s", VersionString()), MAX_SERVERINFO_STRING);
	Info_SetValueForStarKey (svs.info, "*z_ext", va("%i", SUPPORTED_EXTENSIONS), MAX_SERVERINFO_STRING);
#ifdef VWEP_TEST
	Info_SetValueForStarKey (svs.info, "*vwtest", "1", MAX_SERVERINFO_STRING);
#endif

	if (strcmp(com_gamedirfile, "qw"))
		Info_SetValueForStarKey (svs.info, "*gamedir", com_gamedirfile, MAX_SERVERINFO_STRING);

	// init fraglog stuff
	svs.logsequence = 1;
	svs.logtime = svs.realtime;
	SZ_Init (&svs.log[0], svs.log_buf[0], sizeof(svs.log_buf[0]));
	svs.log[0].allowoverflow = true;

	SZ_Init (&svs.log[1], svs.log_buf[1], sizeof(svs.log_buf[1]));
	svs.log[1].allowoverflow = true;

	packet_freeblock = Hunk_AllocName(MAX_DELAYED_PACKETS * sizeof(packet_t), "delayed_packets");

	for (i = 0; i < MAX_DELAYED_PACKETS; i++) {
		SZ_Init (&packet_freeblock[i].msg, packet_freeblock[i].buf, sizeof(packet_freeblock[i].buf));
		packet_freeblock[i].next = &packet_freeblock[i + 1];
	}
	packet_freeblock[MAX_DELAYED_PACKETS - 1].next = NULL;
	svs.free_packets = &packet_freeblock[0];

#ifdef MAUTH
    // Set up queues for temporary auth tokens and auth'd clients...
    authtokq.maxlen = MAX_AUTH_TOK_QUEUE;
    authtokq.curlen = 0;
    authtokq.start = NULL;
    authclientq.maxlen = MAX_AUTH_CLIENT_QUEUE;
    authclientq.curlen = 0;
    authclientq.start = NULL;
#endif
}
示例#28
0
void CL_SendCmd (void)
{
	sizebuf_t buf;
	byte data[128];
	usercmd_t *cmd, *oldcmd;
	int i, checksumIndex, lost;
	qbool dontdrop;
	static float pps_balance = 0;
	static int dropcount = 0;

	if (cls.demoplayback && !cls.mvdplayback)
		return; // sendcmds come from the demo

	#ifdef FTE_PEXT_CHUNKEDDOWNLOADS
	CL_SendChunkDownloadReq();
	#endif

	// save this command off for prediction
	i = cls.netchan.outgoing_sequence & UPDATE_MASK;
	cmd = &cl.frames[i].cmd;
	cl.frames[i].senttime = cls.realtime;
	cl.frames[i].receivedtime = -1;		// we haven't gotten a reply yet

	// update network stats table
	i = cls.netchan.outgoing_sequence&NETWORK_STATS_MASK;
	network_stats[i].delta = 0;     // filled-in later
	network_stats[i].sentsize = 0;  // filled-in later
	network_stats[i].senttime = cls.realtime;
	network_stats[i].receivedtime = -1;

	// get basic movement from keyboard
	CL_BaseMove (cmd);

	// allow mice or other external controllers to add to the move

	if (cl_independentPhysics.value == 0 || (physframe && cl_independentPhysics.value != 0))
	{
		IN_Move(cmd);
	}

	// if we are spectator, try autocam
	if (cl.spectator)
		Cam_Track(cmd);

	CL_FinishMove(cmd);
	cmdtime_msec += cmd->msec;

	Cam_FinishMove(cmd);

	if (cls.mvdplayback)
	{
		CL_CalcPlayerFPS(&cl.players[cl.playernum], cmd->msec);
        cls.netchan.outgoing_sequence++;
		return;
	}

	SZ_Init (&buf, data, sizeof(data));

	SZ_Write (&buf, cls.cmdmsg.data, cls.cmdmsg.cursize);
	if (cls.cmdmsg.overflowed)
		Com_DPrintf("cls.cmdmsg overflowed\n");
	SZ_Clear (&cls.cmdmsg);

	// begin a client move command
	MSG_WriteByte (&buf, clc_move);

	// save the position for a checksum byte
	checksumIndex = buf.cursize;
	MSG_WriteByte (&buf, 0);

	// write our lossage percentage
	lost = CL_CalcNet();
	MSG_WriteByte (&buf, (byte)lost);

	// send this and the previous two cmds in the message, so if the last packet was dropped, it can be recovered
	dontdrop = false;

	i = (cls.netchan.outgoing_sequence - 2) & UPDATE_MASK;
	cmd = &cl.frames[i].cmd;
	if (cl_c2sImpulseBackup.value >= 2)
		dontdrop = dontdrop || cmd->impulse;
	MSG_WriteDeltaUsercmd (&buf, &nullcmd, cmd);
	oldcmd = cmd;

	i = (cls.netchan.outgoing_sequence - 1) & UPDATE_MASK;
	cmd = &cl.frames[i].cmd;
	if (cl_c2sImpulseBackup.value >= 3)
		dontdrop = dontdrop || cmd->impulse;
	MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd);
	oldcmd = cmd;

	i = (cls.netchan.outgoing_sequence) & UPDATE_MASK;
	cmd = &cl.frames[i].cmd;
	if (cl_c2sImpulseBackup.value >= 1)
		dontdrop = dontdrop || cmd->impulse;
	MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd);

	// calculate a checksum over the move commands
	buf.data[checksumIndex] = COM_BlockSequenceCRCByte(
		buf.data + checksumIndex + 1, buf.cursize - checksumIndex - 1,
		cls.netchan.outgoing_sequence);

	// request delta compression of entities
	if (cls.netchan.outgoing_sequence - cl.validsequence >= UPDATE_BACKUP - 1)
	{
		cl.validsequence = 0;
		cl.delta_sequence = 0;
	}

	if (cl.delta_sequence && !cl_nodelta.value && cls.state == ca_active)
	{
		cl.frames[cls.netchan.outgoing_sequence & UPDATE_MASK].delta_sequence = cl.delta_sequence;
		MSG_WriteByte (&buf, clc_delta);
		MSG_WriteByte (&buf, cl.delta_sequence & 255);

		// network stats table
		network_stats[cls.netchan.outgoing_sequence&NETWORK_STATS_MASK].delta = 1;
	}
	else
	{
		cl.frames[cls.netchan.outgoing_sequence & UPDATE_MASK].delta_sequence = -1;
	}

	if (cls.demorecording)
		CL_WriteDemoCmd (cmd);

	if (cl_c2spps.value)
	{
		pps_balance += cls.frametime;
		// never drop more than 2 messages in a row -- that'll cause PL
		// and don't drop if one of the last two movemessages have an impulse
		if (pps_balance > 0 || dropcount >= 2 || dontdrop)
		{
			float	pps;
			pps = cl_c2spps.value;
			if (pps < 10) pps = 10;
			if (pps > 72) pps = 72;
			pps_balance -= 1 / pps;
			// bound pps_balance. FIXME: is there a better way?
			if (pps_balance > 0.1) pps_balance = 0.1;
			if (pps_balance < -0.1) pps_balance = -0.1;
			dropcount = 0;
		}
		else
		{
			// don't count this message when calculating PL
			cl.frames[i].receivedtime = -3;
			// drop this message
			cls.netchan.outgoing_sequence++;
			dropcount++;
			return;
		}
	}
	else
	{
		pps_balance = 0;
		dropcount = 0;
	}

#ifdef FTE_PEXT2_VOICECHAT
	S_Voip_Transmit(clc_voicechat, &buf);
#endif

	cl.frames[cls.netchan.outgoing_sequence&UPDATE_MASK].sentsize = buf.cursize + 8;    // 8 = PACKET_HEADER
	// network stats table
	network_stats[cls.netchan.outgoing_sequence&NETWORK_STATS_MASK].sentsize = buf.cursize + 8;

	// deliver the message
	Netchan_Transmit (&cls.netchan, buf.cursize, buf.data);
}
示例#29
0
文件: cmd.c 项目: raynorpat/quake2
/*
============
Cbuf_Init
============
*/
void Cbuf_Init (void)
{
	SZ_Init (&cmd_text, cmd_text_buf, sizeof(cmd_text_buf));
}
示例#30
0
文件: sv_ccmds.c 项目: mattx86/aprq2
/*
==============
SV_ServerRecord_f

Begins server demo recording.  Every entity and every message will be
recorded, but no playerinfo will be stored.  Primarily for demo merging.
==============
*/
static void SV_ServerRecord_f (void)
{
	char	name[MAX_OSPATH];
	byte	buf_data[32768];
	sizebuf_t	buf;
	int		len;
	int		i;
	size_t	size;

	if (Cmd_Argc() != 2) {
		Com_Printf ("serverrecord <demoname>\n");
		return;
	}

	if (svs.demofile) {
		Com_Printf ("Already recording.\n");
		return;
	}

	if (sv.state != ss_game) {
		Com_Printf ("You must be in a level to record.\n");
		return;
	}

	//
	// open the demo file
	//
	Com_sprintf (name, sizeof(name), "%s/demos/%s.dm2", FS_Gamedir(), Cmd_Argv(1));

	FS_CreatePath(name);
	svs.demofile = fopen (name, "wb");
	if (!svs.demofile) {
		Com_Printf ("ERROR: couldn't open.\n");
		return;
	}

	Com_Printf ("recording to %s.\n", name);

	// setup a buffer to catch all multicasts
	SZ_Init (&svs.demo_multicast, svs.demo_multicast_buf, sizeof(svs.demo_multicast_buf));

	//
	// write a single giant fake message with all the startup info
	//
	SZ_Init (&buf, buf_data, sizeof(buf_data));

	//
	// serverdata needs to go over for all types of servers
	// to make sure the protocol is right, and to set the gamedir
	//
	// send the serverdata
	MSG_WriteByte (&buf, svc_serverdata);
	MSG_WriteLong (&buf, PROTOCOL_VERSION_DEFAULT);
	MSG_WriteLong (&buf, svs.spawncount);
	// 2 means server demo
	MSG_WriteByte (&buf, 2);	// demos are always attract loops
	MSG_WriteString (&buf, Cvar_VariableString ("gamedir"));
	MSG_WriteShort (&buf, -1);
	// send full levelname
	MSG_WriteString (&buf, sv.configstrings[CS_NAME]);

	for (i=0 ; i<MAX_CONFIGSTRINGS ; i++)
		if (sv.configstrings[i][0])
		{
			MSG_WriteByte (&buf, svc_configstring);
			MSG_WriteShort (&buf, i);
			MSG_WriteString (&buf, sv.configstrings[i]);
		}

	// write it to the demo file
	Com_DPrintf ("signon message length: %i\n", buf.cursize);
	len = LittleLong (buf.cursize);
	size = fwrite (&len, 4, 1, svs.demofile);
	size = fwrite (buf.data, buf.cursize, 1, svs.demofile);

	// the rest of the demo file will be individual frames
}