示例#1
0
void SV_NocPacket(netadr_t from, msg_t *msg) { //Not connected packet (Server is not running)
	char* s;
	char* c;
	if(msg->cursize >= 4) {
		if(*(int*)msg->data == -1) {
			#if 1
			int CSteamServer_HandleIncomingPacket(const void* pData, int cbData, unsigned int srcIP, unsigned short srcPort);
			if(!CSteamServer_HandleIncomingPacket((const void*)msg->data, msg->cursize, from._ip, from.port));
			#endif
		} else if(*(int*)msg->data == -2) {	
			MSG_BeginReading(msg);
			MSG_ReadLong(msg);
			
			s = MSG_ReadStringLine(msg);
			
			Cmd_TokenizeString(s);
			
			c = Cmd_Argv(0);
			
			if(!Q_stricmp(c, "serverversionresponse")) {
				if(!NET_CompareBaseAdr(from, x_master))
					return;
			} else if(!Q_stricmp(c, "clientversionresponse")) {
				if(!NET_CompareBaseAdr(from, x_master))
					return;
				clientversion = atoi( Cmd_Argv(1) );
			}
		}
	}
}
示例#2
0
// unused function
void CL_ServerlistPacket (netadr_t net_from, const char *sRandStr, sizebuf_t *net_message)
{
	char *sServerIP;
	int i = 1;

	if (!Q_streq(sRandStr, g_szRandomServerlistString))
		return; // malicious packet?  Whatever, just ignore it.

	while ((sServerIP = MSG_ReadStringLine(net_message)) && *sServerIP) // not threadsafe!
	{
		if (*sServerIP == '*')
		{
			if (memcmp(sServerIP, "*continue:", sizeof("*continue")) == 0)
			{
				int nStart;

				// serverlist did not fit in one packet, we need another to resume it.
				// actually, we'll probably never use this -- just have the server send all packets.
				nStart = atoi(sServerIP + sizeof("*continue:"));
				M_ServerlistUpdateUDP(nStart);
				break;
			}

			continue; // not a serverlist ip, special line.
		}

		CL_PingServerlistServer(sServerIP);
	}
}
示例#3
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
	char	*s;
	char	*c;
	#ifdef USE_AUTH
	netadr_t	authServerIP;
	#endif

	MSG_BeginReadingOOB( msg );
	MSG_ReadLong( msg );		// skip the -1 marker

	if (!Q_strncmp("connect", (char *) &msg->data[4], 7)) {
		Huff_Decompress(msg, 12);
	}

	s = MSG_ReadStringLine( msg );
	Cmd_TokenizeString( s );

	c = Cmd_Argv(0);
	Com_DPrintf ("SV packet %s : %s\n", NET_AdrToString(from), c);

	if (!Q_stricmp(c, "getstatus")) {
		if (SV_CheckDRDoS(from)) { return; }
		SVC_Status( from  );
  } else if (!Q_stricmp(c, "getinfo")) {
		if (SV_CheckDRDoS(from)) { return; }
		SVC_Info( from );
	} else if (!Q_stricmp(c, "getchallenge")) {
		SV_GetChallenge( from );
	} else if (!Q_stricmp(c, "connect")) {
		SV_DirectConnect( from );
	} else if (!Q_stricmp(c, "ipAuthorize")) {
		SV_AuthorizeIpPacket( from );
	}
	#ifdef USE_AUTH
	// @Barbatos @Kalish
	else if ( (!Q_stricmp(c, "AUTH:SV")))
	{
		NET_StringToAdr(sv_authServerIP->string, &authServerIP);
		
		if ( !NET_CompareBaseAdr( from, authServerIP ) ) {
			Com_Printf( "AUTH not from the Auth Server\n" );
			return;
		}
		VM_Call(gvm, GAME_AUTHSERVER_PACKET);
	}
	#endif
	
	else if (!Q_stricmp(c, "rcon")) {
		SVC_RemoteCommand( from, msg );
	}else if (!Q_stricmp(c, "rconRecovery")) {
		SVC_RconRecoveryRemoteCommand( from, msg );
	} else if (!Q_stricmp(c, "disconnect")) {
		// if a client starts up a local server, we may see some spurious
		// server disconnect messages when their new server sees our final
		// sequenced messages to the old client
	} else {
		Com_DPrintf ("bad connectionless packet from %s:\n%s\n"
		, NET_AdrToString (from), s);
	}
}
示例#4
0
/*
* SV_ConnectionlessPacket
* 
* A connectionless packet has four leading 0xff
* characters to distinguish it from a game channel.
* Clients that are in the game can still send
* connectionless packets.
*/
void SV_ConnectionlessPacket( const socket_t *socket, const netadr_t *address, msg_t *msg )
{
	connectionless_cmd_t *cmd;
	char *s, *c;

	MSG_BeginReading( msg );
	MSG_ReadLong( msg );    // skip the -1 marker

	s = MSG_ReadStringLine( msg );

	Cmd_TokenizeString( s );

	c = Cmd_Argv( 0 );
	Com_DPrintf( "Packet %s : %s\n", NET_AddressToString( address ), c );

	for( cmd = connectionless_cmds; cmd->name; cmd++ )
	{
		if( !strcmp( c, cmd->name ) )
		{
			cmd->func( socket, address );
			return;
		}
	}

	Com_DPrintf( "Bad connectionless packet from %s:\n%s\n", NET_AddressToString( address ), s );
}
示例#5
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
void SV_ConnectionlessPacket(void)
{
    const char * s;
    const char * c;

    MSG_BeginReading(&net_message);
    MSG_ReadLong(&net_message); // skip the -1 marker

    s = MSG_ReadStringLine(&net_message);

    Cmd_TokenizeString(s, false);

    c = Cmd_Argv(0);
    Com_DPrintf("Packet %s : %s\n", NET_AdrToString(net_from), c);

    if (!strcmp(c, "ping"))
        SVC_Ping();
    else if (!strcmp(c, "ack"))
        SVC_Ack();
    else if (!strcmp(c, "status"))
        SVC_Status();
    else if (!strcmp(c, "info"))
        SVC_Info();
    else if (!strcmp(c, "getchallenge"))
        SVC_GetChallenge();
    else if (!strcmp(c, "connect"))
        SVC_DirectConnect();
    else if (!strcmp(c, "rcon"))
        SVC_RemoteCommand();
    else
        Com_Printf("bad connectionless packet from %s:\n%s\n", NET_AdrToString(net_from), s);
}
示例#6
0
/*
* TV_Downstream_UpstreamlessPacket
*/
void TV_Downstream_UpstreamlessPacket( const socket_t *socket, const netadr_t *address, msg_t *msg )
{
	upstreamless_cmd_t *cmd;
	char *s, *c;

	MSG_BeginReading( msg );
	MSG_ReadLong( msg );    // skip the -1 marker

	s = MSG_ReadStringLine( msg );

	if( TV_Downstream_SteamServerQuery( s, socket, address, msg ) )
		return;

	Cmd_TokenizeString( s );
	c = Cmd_Argv( 0 );

	for( cmd = upstreamless_cmds; cmd->name; cmd++ )
	{
		if( !strcmp( c, cmd->name ) )
		{
			cmd->func( socket, address );
			return;
		}
	}

	Com_DPrintf( "Bad downstream connectionless packet from %s:\n%s\n", NET_AddressToString( address ), s );
}
示例#7
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
static void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
	char	*s;
	char	*c;

	MSG_BeginReading( msg );
	MSG_ReadLong( msg );		// skip the -1 marker

	s = MSG_ReadStringLine( msg );

	Cmd_TokenizeString( s );

	c = Cmd_Argv(0);
	Com_DPrintf ("SV packet %s : %s\n", NET_AdrToString(from), c);

	if (!strcmp(c,"getstatus")) {
		SVC_Status( from  );
	} else if (!strcmp(c,"getinfo")) {
		SVC_Info( from );
	} else if (!strcmp(c,"connect")) {
		SV_DirectConnect( from );
	} else if (!strcmp(c,"disconnect")) {
		// if a client starts up a local server, we may see some spurious
		// server disconnect messages when their new server sees our final
		// sequenced messages to the old client
	} else {
		Com_DPrintf ("bad connectionless packet from %s:\n%s\n"
		, NET_AdrToString (from), s);
	}
}
示例#8
0
/*
 * =================
 * SV_ConnectionlessPacket
 *
 * A connectionless packet has four leading 0xff
 * characters to distinguish it from a game channel.
 * Clients that are in the game can still send
 * connectionless packets.
 * =================
 */
void SV_ConnectionlessPacket(void)
{
    char *s;
    char *c;

    // r1ch fix: make sure we never talk to ourselves
//	if (NET_IsLocalAddress (net_from.ip[0] == 127) && !NET_IsLocalHost(net_from) && ShortSwap(net_from.port) == server_port)

/*	if ( (net_from.ip[0] == 127) && (net_from.type != NA_LOOPBACK) && (ShortSwap(net_from.port) == server_port) )
 *      {
 *              Com_DPrintf ("dropped %d byte connectionless packet from self! (spoofing attack?)\n", net_message.cursize);
 *              return;
 *      }*/

    MSG_BeginReading(&net_message);
    MSG_ReadLong(&net_message);                 // skip the -1 marker

    s = MSG_ReadStringLine(&net_message);

    Cmd_TokenizeString(s, false);

    c = Cmd_Argv(0);
    Com_DPrintf("Packet %s : %s\n", NET_AdrToString(net_from), c);

    if (!strcmp(c, "ping"))
    {
        SVC_Ping();
    }
    else if (!strcmp(c, "ack"))
    {
        SVC_Ack();
    }
    else if (!strcmp(c, "status"))
    {
        SVC_Status();
    }
    else if (!strcmp(c, "info"))
    {
        SVC_Info();
    }
    else if (!strcmp(c, "getchallenge"))
    {
        SVC_GetChallenge();
    }
    else if (!strcmp(c, "connect"))
    {
        SVC_DirectConnect();
    }
    else if (!strcmp(c, "rcon"))
    {
        SVC_RemoteCommand();
    }
    else
    {
        Com_Printf("bad connectionless packet from %s:\n%s\n"
                   , NET_AdrToString(net_from), s);
    }
}
示例#9
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
void SV_ConnectionlessPacket( netadr_t from, msg_t *msg )
{
	char *s;
	char *c;

	MSG_BeginReadingOOB( msg );
	MSG_ReadLong( msg );  // skip the -1 marker

	if ( !Q_strncmp( "connect", ( char * ) &msg->data[ 4 ], 7 ) )
	{
		Huff_Decompress( msg, 12 );
	}

	s = MSG_ReadStringLine( msg );

	Cmd_TokenizeString( s );

	c = Cmd_Argv( 0 );
	Com_DPrintf( "SV packet %s : %s\n", NET_AdrToString( from ), c );

	if ( !Q_stricmp( c, "getstatus" ) )
	{
		if ( SV_CheckDRDoS( from ) ) { return; }

		SVC_Status( from );
	}
	else if ( !Q_stricmp( c, "getinfo" ) )
	{
		if ( SV_CheckDRDoS( from ) ) { return; }

		SVC_Info( from );
	}
	else if ( !Q_stricmp( c, "getchallenge" ) )
	{
		SV_GetChallenge( from );
	}
	else if ( !Q_stricmp( c, "connect" ) )
	{
		SV_DirectConnect( from );
	}
	else if ( !Q_stricmp( c, "rcon" ) )
	{
		SVC_RemoteCommand( from, msg );
	}
	else if ( !Q_stricmp( c, "disconnect" ) )
	{
		// if a client starts up a local server, we may see some spurious
		// server disconnect messages when their new server sees our final
		// sequenced messages to the old client
	}
	else
	{
		Com_DPrintf( "bad connectionless packet from %s:\n%s\n", NET_AdrToString( from ), s );
	}
}
示例#10
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
	char    *s;
	const char    *c;

	MSG_BeginReadingOOB( msg );
	MSG_ReadLong( msg );        // skip the -1 marker

#if !defined RTCW_SP
	if ( !Q_strncmp( "connect", reinterpret_cast<const char*> (&msg->data[4]), 7 ) ) {
		Huff_Decompress( msg, 12 );
	}
#endif // RTCW_XX

	s = MSG_ReadStringLine( msg );

	Cmd_TokenizeString( s );

	c = Cmd_Argv( 0 );
	Com_DPrintf( "SV packet %s : %s\n", NET_AdrToString( from ), c );

	if ( !Q_stricmp( c,"getstatus" ) ) {
		SVC_Status( from  );
	} else if ( !Q_stricmp( c,"getinfo" ) ) {
		SVC_Info( from );
	} else if ( !Q_stricmp( c,"getchallenge" ) ) {
		SV_GetChallenge( from );
	} else if ( !Q_stricmp( c,"connect" ) ) {
		SV_DirectConnect( from );

#if !defined RTCW_ET || (defined RTCW_ET && AUTHORIZE_SUPPORT)
	} else if ( !Q_stricmp( c,"ipAuthorize" ) ) {
		SV_AuthorizeIpPacket( from );
#endif // RTCW_XX

	} else if ( !Q_stricmp( c, "rcon" ) ) {
		SVC_RemoteCommand( from, msg );

#if defined RTCW_MP
// DHM - Nerve
#ifdef UPDATE_SERVER
	} else if ( !Q_stricmp( c, "getUpdateInfo" ) ) {
		SVC_GetUpdateInfo( from );
#endif
// DHM - Nerve
#endif // RTCW_XX

	} else if ( !Q_stricmp( c,"disconnect" ) ) {
		// if a client starts up a local server, we may see some spurious
		// server disconnect messages when their new server sees our final
		// sequenced messages to the old client
	} else {
		Com_DPrintf( "bad connectionless packet from %s:\n%s\n"
					 , NET_AdrToString( from ), s );
	}
}
示例#11
0
/*
* TV_Upstream_Reject
*/
static void TV_Upstream_Reject_f( upstream_t *upstream, msg_t *msg ) {
	int rejecttype, rejectflag;
	char rejectmessage[MAX_STRING_CHARS];

	rejecttype = atoi( MSG_ReadStringLine( msg ) );
	if( rejecttype < 0 || rejecttype >= DROP_TYPE_TOTAL ) {
		rejecttype = DROP_TYPE_GENERAL;
	}

	rejectflag = atoi( MSG_ReadStringLine( msg ) );

	Q_strncpyz( rejectmessage, MSG_ReadStringLine( msg ), sizeof( rejectmessage ) );

	Com_Printf( "%s" S_COLOR_WHITE ": Upstream refused: %s\n", upstream->name, rejectmessage );
	if( rejectflag & DROP_FLAG_AUTORECONNECT ) {
		Com_Printf( "Automatic reconnecting allowed.\n" );
	} else {
		Com_Printf( "Automatic reconnecting not allowed.\n" );
	}

	TV_Upstream_Error( upstream, "Upstream refused: %s", rejectmessage );
}
示例#12
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
	char	*s;
	char	*c;

	MSG_BeginReadingOOB( msg );
	MSG_ReadLong( msg );		// skip the -1 marker

	if (!Q_strncmp("connect", (char *) &msg->data[4], 7)) {
		Huff_Decompress(msg, 12);
	}

	s = MSG_ReadStringLine( msg );
	Cmd_TokenizeString( s );

	c = Cmd_Argv(0);

	if (!Q_stricmp(c, "getstatus")) {
		if (SV_CheckDRDoS(from)) { return; }
		SVC_Status( from  );
  } else if (!Q_stricmp(c, "getinfo")) {
		if (SV_CheckDRDoS(from)) { return; }
		SVC_Info( from );
	} else if (!Q_stricmp(c, "getchallenge")) {
		SV_GetChallenge( from );
	} else if (!Q_stricmp(c, "connect")) {
		SV_DirectConnect( from );
	/*
	} else if (!Q_stricmp(c, "ipAuthorize")) {
		SV_AuthorizeIpPacket( from );
	*/
	} else if (!Q_stricmp(c, "rcon")) {
		SVC_RemoteCommand( from, msg );
	////////////////////////////////////////////////
	// separator for ip2loc.patch and playerdb.patch
	////////////////////////////////////////////////
	} else if (!Q_stricmp(c, "disconnect")) {
		// if a client starts up a local server, we may see some spurious
		// server disconnect messages when their new server sees our final
		// sequenced messages to the old client
	} else {
		Com_DPrintf ("bad connectionless packet from %s:\n%s\n"
		, NET_AdrToString (from), s);
	}

	// We moved this from the top of this function to the bottom.
	// During a DRDoS attack we get thousands of lines of packets
	// that just garble the screen.  Since we return from this
	// function early if a DRDoS is detected, we don't print a line
	// for each attacking packet anymore.
	Com_DPrintf ("SV packet %s : %s\n", NET_AdrToString(from), c);
}
示例#13
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
static void SV_ConnectionlessPacket (void)
{
	const char	*s;
	const char	*c;

	MSG_BeginReading ();
	MSG_ReadLong ();	// skip the -1 marker

	s = MSG_ReadStringLine ();

	Cmd_TokenizeString (s);

	c = Cmd_Argv(0);

	if (!strcmp(c, "ping") || ( c[0] == A2A_PING && (c[1] == 0 || c[1] == '\n')) )
	{
		SVC_Ping ();
		return;
	}
	if (c[0] == A2A_ACK && (c[1] == 0 || c[1] == '\n') )
	{
		Con_Printf ("A2A_ACK from %s\n", NET_AdrToString (net_from));
		return;
	}
	else if (c[0] == A2S_ECHO)
	{
		NET_SendPacket (net_message.cursize, net_message.data, net_from);
		return;
	}
	else if (!strcmp(c,"status"))
	{
		SVC_Status ();
		return;
	}
	else if (!strcmp(c,"log"))
	{
		SVC_Log ();
		return;
	}
	else if (!strcmp(c,"connect"))
	{
		SVC_DirectConnect ();
		return;
	}
	else if (!strcmp(c, "rcon"))
		SVC_RemoteCommand ();
	else
		Con_Printf ("bad connectionless packet from %s:\n%s\n", NET_AdrToString (net_from), s);
}
示例#14
0
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
void SV_ConnectionlessPacket (void)
{
    char	*s;
    char	*c;
    int s_token = 0;
    // r1ch fix: make sure we never talk to ourselves
//	if (NET_IsLocalAddress (net_from.ip[0] == 127) && !NET_IsLocalHost(net_from) && ShortSwap(net_from.port) == server_port)
    /*	if ( (net_from.ip[0] == 127) && (net_from.type != NA_LOOPBACK) && (ShortSwap(net_from.port) == server_port) )
    	{
    		Com_DPrintf ("dropped %d byte connectionless packet from self! (spoofing attack?)\n", net_message.cursize);
    		return;
    	}*/

    MSG_BeginReading (&net_message);
    MSG_ReadLong (&net_message);		// skip the -1 marker

    s = MSG_ReadStringLine (&net_message);

    Cmd_TokenizeString (s, false);

    c = Cmd_Argv(0);
    Com_DPrintf ("Packet %s : %s\n", NET_AdrToString(net_from), c);

    if ((s_token = Q_STLookup(&packet_stable, c)) != -1) {
        if (s_token == s_ping)
            SVC_Ping ();
        else if (s_token == s_ack)
            SVC_Ack ();
        else if (s_token == s_status)
            SVC_Status ();
        else if (s_token == s_info)
            SVC_Info ();
        else if (s_token == s_getchallenge)
            SVC_GetChallenge ();
        else if (s_token == s_connect)
            SVC_DirectConnect ();
        else if (s_token == s_rcon)
            SVC_RemoteCommand ();
    } else
        Com_Printf ("bad connectionless packet from %s:\n%s\n"
                    , NET_AdrToString (net_from), s);
}
示例#15
0
/*
* TV_Upstream_ConnectionlessPacket
*/
void TV_Upstream_ConnectionlessPacket( upstream_t *upstream, msg_t *msg ) {
	upstreamless_cmd_t *cmd;
	char *s, *c;

	MSG_BeginReading( msg );
	MSG_ReadInt32( msg );    // skip the -1 marker

	s = MSG_ReadStringLine( msg );
	Cmd_TokenizeString( s );
	c = Cmd_Argv( 0 );

	for( cmd = upstream_upstreamless_cmds; cmd->name; cmd++ ) {
		if( !strcmp( c, cmd->name ) ) {
			cmd->func( upstream, msg );
			return;
		}
	}

	Com_DPrintf( "%s" S_COLOR_WHITE ": Bad upstream connectionless packet: %s\n", upstream->name, c );
}
示例#16
0
/* Detecting the clientside protocol and process the 1st chunk of data if it is a http client */
tcpclientstate_t HTTPServer_AuthEvent(netadr_t* from, msg_t* msg, int *connectionId)
{
	
	ftRequest_t* request;
	*connectionId = 0;
	
	char protocol[MAX_STRING_CHARS];
	char* line;
	
	MSG_BeginReading(msg);
	
	line = MSG_ReadStringLine(msg, protocol, sizeof(protocol));
	if (line != NULL) {
		if ( Q_strncmp(line, "GET", 3) && Q_strncmp(line, "POST", 4) && Q_strncmp(line, "HEAD", 4) ) {
			return TCP_AUTHNOTME;
		}
		if( strstr(line, "HTTP/1.0") == NULL && strstr(line, "HTTP/1.1") == NULL )
		{
			/* Is not a HTTP client */
			return TCP_AUTHNOTME;
		}
	}
	
	request = FT_CreateRequest(NULL, NULL);
	
	if(request == NULL)
		return TCP_AUTHBAD;
	
	*connectionId = (int)request;

	
	if (HTTPServer_Event(from, msg, *connectionId) == qtrue)
	{
		return TCP_AUTHBAD;
	}	

	return TCP_AUTHSUCCESSFULL;
}
示例#17
0
文件: sv_main.c 项目: matatk/agrip
/*
=================
SV_ConnectionlessPacket

A connectionless packet has four leading 0xff
characters to distinguish it from a game channel.
Clients that are in the game can still send
connectionless packets.
=================
*/
void SV_ConnectionlessPacket (void)
{
	char	*s;
	char	*c;

	MSG_BeginReading ();
	MSG_ReadLong ();		// skip the -1 marker

	s = MSG_ReadStringLine ();
	s[1023] = 0;

	Cmd_TokenizeString (s);

	c = Cmd_Argv(0);

	if (!strcmp(c, "ping") || ( c[0] == A2A_PING && (c[1] == 0 || c[1] == '\n')) )
	{
		SVC_Ping ();
		return;
	}
	if (c[0] == A2A_ACK && (c[1] == 0 || c[1] == '\n') )
	{
		Com_Printf ("A2A_ACK from %s\n", NET_AdrToString (net_from));
		return;
	}
	else if (!strcmp(c,"status"))
	{
		SVC_Status ();
		return;
	}
	else if (!strcmp(c,"log"))
	{
		SVC_Log ();
		return;
	}
	else if (!strcmp(c,"connect"))
	{
		SVC_DirectConnect ();
		return;
	}
#ifdef MAUTH
	else if (c[0] == M2S_AUTH_TOK && (c[1] == 0 || c[1] == '\n') )
	{
        Com_Printf("MAUTH: Adding token from %s to auth queue\n", NET_AdrToString(net_from));
        // Provisionally add auth record...
        if (SV_AuthListAdd(&authtokq))
        {
            //SV_AuthListPrint(&authtokq);
            //SV_AuthListPrint(&authclientq);
            // Send S2M_AUTH_TOK_CHK as a spoofing check...
            Master_AuthTokChk(authtokq.start->name, authtokq.start->hash);
        }
        else
        {
            Com_Printf("MAUTH: Failure to add token from %s -- already added?\n", NET_AdrToString(net_from));
            // FIXME Send S2M_AUTH_TOK_NACK
        }
		return;
	}
	else if (c[0] == M2S_AUTH_TOK_ACK && (c[1] == 0 || c[1] == '\n') )
	{
        // The master is sending us the correct name and hash;
        // check that what we've got agrees with this.

        // FIXME do we trust this packet?
       
        char tok_ack = S2C_AUTH_TOK_ACK;
        authclient_t *newclient = NULL;
        qbool result;
        result = SV_AuthListValidate(&authtokq, &newclient);
        //SV_AuthListPrint(&authtokq);
        //SV_AuthListPrint(&authclientq);

        // Check the client is valid...
        if( !result )
        {
            Com_Printf("MAUTH: Client is not valid!\n");
            return;
        }
        
        // Tell client they can connect...
        Com_Printf("MAUTH: Telling client %s on %s to connect...\n", newclient->name, NET_AdrToString(newclient->client_addr));
		NET_SendPacket (NS_SERVER, 1, &tok_ack, newclient->client_addr);
		return;
	}
	/*else if (c[0] == M2S_AUTH_TOK_NACK && (c[1] == 0 || c[1] == '\n') )
    {
        // Master said this token not valid -- FIXME how can we trust this?
        // FIXME remove player details from auth queue.
        Com_Printf("MAUTH: Player invalid!\n");
    }*/
#endif
	else if (!strcmp(c,"getchallenge"))
	{
		SVC_GetChallenge ();
		return;
	}
	else if (!strcmp(c, "rcon"))
		SVC_RemoteCommand ();
	else
		Com_Printf ("bad connectionless packet from %s:\n%s\n"
		, NET_AdrToString (net_from), s);
}
示例#18
0
static int HTTP_SendReceiveData(ftRequest_t* request)
{
	char* line;
	int status, i;
	qboolean gotheader;
	char stringlinebuf[MAX_STRING_CHARS];
	
	if (request->sendmsg.cursize > 0) {
		status = FT_SendData(request);
		
		if(status < 0)
			return -1;
		return 0;
	}

	status = FT_ReceiveData(request);
	
	if (status == -1) {
		return -1;
	}else if (status == 0) {
		return 0;
	}
	
	if(request->finallen == -1)
	{
		gotheader = qfalse;
		/* 1st check if the header is complete */
		while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' )
		{
			if(line[0] == '\r')
			{
				gotheader = qtrue;
				break;
			}
		}
		if(gotheader == qfalse)
		{
			return 0;
		}
		MSG_BeginReading(&request->recvmsg);
		
		line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf));
		if(Q_stricmpn(line,"HTTP/1.",7) || isInteger(line + 7, 2) == qfalse || isInteger(line + 9, 4) == qfalse)
		{
			Com_PrintError("HTTP_ReceiveData: Packet is corrupt!\nDebug: %s\n", line);
			
			return -1;
		}
		
		request->version = atoi(line + 7);
		if (request->version != 0 && request->version != 1)
		{
			Com_PrintError("HTTP_ReceiveData: Packet has unknown HTTP version 1.%d !\n", request->version);
			
			return -1;			
		}
		
		request->code = atoi(line + 9);
		i = 0;
		while (line[i +9] != ' ' && line[i +9] != '\0')
		{
			i++;
		}
		
		if(line[i +9] != '\0')
		{
			Q_strncpyz(request->status, &line[i +9], sizeof(request->status));
		}else{
			Q_strncpyz(request->status, "N/A", sizeof(request->status));
		}
		
		request->contentLength = 0;
		
		while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' && line[0] != '\r')
		{
			if(!Q_stricmpn("Content-Length:", line, 15))
			{
				if(isInteger(line + 15, 0) == qfalse)
				{
					Com_PrintError("Sec_GetHTTPPacket: Packet is corrupt!\nDebug: %s\n", line);
					return -1;
				}
				request->contentLength = atoi(line + 15);
				if(request->contentLength < 0)
				{
					request->contentLength = 0;
					return -1;
				}
			}
			
		}
		if(line[0] == '\0')
			return -1;
		
		request->headerLength = request->recvmsg.readcount;		
		request->finallen = request->contentLength + request->headerLength;

		if(request->finallen > 1024*1024*640)
		{
			request->finallen = request->headerLength;
		}

	}
	if(request->recvmsg.maxsize == request->finallen)
		request->transferactive = qtrue;

	
	if (request->recvmsg.cursize < request->finallen) {
	/* Still needing bytes... */
		return 0;
	}
	/* Received full message */
	return 1;
	
}
示例#19
0
/*
=================
CL_ConnectionlessPacket

Responses to broadcasts, etc
=================
*/
void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
	char	*s;
	char	*c;
	
	MSG_BeginReading( msg );
	MSG_ReadLong( msg );	// skip the -1

	s = MSG_ReadStringLine( msg );

	Cmd_TokenizeString( s );

	c = Cmd_Argv(0);

	Com_DPrintf ("CL packet %s: %s\n", NET_AdrToString(from), c);

	// challenge from the server we are connecting to
	if ( !strcmp(c, "challengeResponse") ) {
		if ( cls.state != CA_CONNECTING ) {
			Com_Printf( "Unwanted challenge response received.  Ignored.\n" );
		} else {
			// start sending challenge repsonse instead of challenge request packets
			clc.challenge = atoi(Cmd_Argv(1));
			cls.state = CA_CHALLENGING;
			clc.connectPacketCount = 0;
			clc.connectTime = -99999;

			// take this address as the new server address.  This allows
			// a server proxy to hand off connections to multiple servers
			clc.serverAddress = from;
		}
		return;
	}

	// server connection
	if ( !strcmp(c, "connectResponse") ) {
		if ( cls.state >= CA_CONNECTED ) {
			Com_Printf ("Dup connect received.  Ignored.\n");
			return;
		}
		if ( cls.state != CA_CHALLENGING ) {
			Com_Printf ("connectResponse packet while not connecting.  Ignored.\n");
			return;
		}
		if ( !NET_CompareBaseAdr( from, clc.serverAddress ) ) {
			Com_Printf( "connectResponse from a different address.  Ignored.\n" );
			Com_Printf( "%s should have been %s\n", NET_AdrToString( from ), 
				NET_AdrToString( clc.serverAddress ) );
			return;
		}
		Netchan_Setup (NS_CLIENT, &clc.netchan, from, Cvar_VariableIntegerValue( "qport" ) );
		cls.state = CA_CONNECTED;
		clc.lastPacketSentTime = -9999;		// send first packet immediately
		return;
	}

	// a disconnect message from the server, which will happen if the server
	// dropped the connection but it is still getting packets from us
	if (!strcmp(c, "disconnect")) {
		CL_DisconnectPacket( from );
		return;
	}

	// echo request from server
	if ( !strcmp(c, "echo") ) {
		NET_OutOfBandPrint( NS_CLIENT, from, "%s", Cmd_Argv(1) );
		return;
	}

	// print request from server
	if ( !strcmp(c, "print") ) {
		s = MSG_ReadString( msg );
		UI_UpdateConnectionMessageString( s );
		Com_Printf( "%s", s );
		return;
	}


	Com_DPrintf ("Unknown connectionless packet command.\n");
}
示例#20
0
char* EXT_FUNC MSG_ReadStringLine_api() {
	return MSG_ReadStringLine();
}
示例#21
0
static int FTP_SendReceiveData(ftRequest_t* request)
{
	char* line;
	char command[MAX_STRING_CHARS];
	int status, bytes;
	byte* buf;
	netadr_t pasvadr;
	char stringlinebuf[MAX_STRING_CHARS];

	status = FT_ReceiveData(request);
	
	if (status == -1 && request->stage < 9999) {
		return -1;
	}
	if(status == 0 && request->stage < 9999)
	{
		status = FT_SendData(request);
	}
	if (status == -1 && request->stage < 9999) {
		return -1;
	}
	
	while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' )
	{	
		if(isNumeric(line, 0) == qfalse)
			continue;
		
		request->code = atoi(line);
		
		if(request->stage > 60)
			Com_DPrintf("\n");
	
		Com_DPrintf("Response Code = %d\n", request->code);
		
		if (request->stage < 0)
		{
			continue;
		}
		
		switch (request->code)
		{
				
			case 220:
				if(request->stage == 0)
				{
					// Initial OK response received /
					Com_DPrintf("FTP_SendReceiveData: Inital OK response received\n");
					request->stage = 1;
				}else {
					Com_PrintWarning("\nFTP_SendReceiveData: Received: %s - Should not happen!\n", line);
				}
				break;
			case 202:
				if(request->stage < 21 && request->stage > 10)
				{
					request->stage = 21;
				}else {
					Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line);
					request->stage = -20;
				}
				break;								
			case 331:
				if(request->stage == 10)
				{
					Com_DPrintf("FTP_SendReceiveData: Need Password\n");
					request->stage = 11;
					
				}else if(request->stage == 16){
					Com_DPrintf("FTP_SendReceiveData: Need Password\n");
					request->stage = 17;
				}else {
					Com_Printf("FTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line);
					request->stage = -20;
				}
				break;
			case 332:
				if(request->stage == 10 || request->stage == 12)
				{
					Com_DPrintf("FTP_SendReceiveData: Need Account\n");
					request->stage = 15;
				}else {
					Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line);
					request->stage = -20;
				}
				break;				
			case 230:
				if (request->stage <= 20)
				{
					Com_DPrintf("FTP_SendReceiveData: Logged in OK\n");
					request->stage = 21;
				}else {
					Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line);
					request->stage = -20;
				}
				break;
			case 227:
				if(request->stage == 36)
				{
					FTP_GetPassiveAddress(line, &pasvadr);
					if(pasvadr.type == NA_IP)
					{
						Com_DPrintf("FTP_SendReceiveData: Entering Passive Mode at %s OK\n", NET_AdrToString(&pasvadr));
						request->transfersocket = NET_TcpClientConnect(NET_AdrToString(&pasvadr));
						if(request->transfersocket < 0)
						{	
							request->transfersocket = -1;
							return -1;
						}
						request->stage = 41;
					}else {
						Com_PrintWarning("FTP_SendReceiveData: Couldn't read the address/port of passive mode response\n");
						return -1;
					}
	
				}else {
					Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line);
					request->stage = -20;
				}
				break;
			case 229:
				if(request->stage == 32)
				{
					FTP_GetExtendedPassiveAddress(line, request->address, &pasvadr);
					if(pasvadr.type == NA_IP || pasvadr.type == NA_IP6)
					{
						Com_DPrintf("FTP_SendReceiveData: Entering Extended Passive Mode at %s OK\n", NET_AdrToString(&pasvadr));
						request->transfersocket = NET_TcpClientConnect(NET_AdrToString(&pasvadr));
						if(request->transfersocket < 0)
						{	
							request->transfersocket = -1;
							return -1;
						}
						request->stage = 41;
					}else {
						Com_PrintWarning("FTP_SendReceiveData: Couldn't read the address/port of passive mode response\n");
						return -1;
					}
					
				}else {
					Com_Printf("\nFTP_SendReceiveData: Received unexpected response: %s - Will abort!\n", line);
					request->stage = -20;
				}
				break;			
			case 213:
				if(request->stage == 50)
				{	
					bytes = atoi(&line[4]);
					Com_DPrintf("FTP_SendReceiveData: Requested file will have %d bytes\n", bytes);
					if(bytes < 1 || bytes > 1024*1024*1024)
					{
						Com_PrintWarning("FTP_SendReceiveData: Requested file would exceed %d bytes. Will not download!\n", 1024*1024*1024);
				
					}
					buf = Z_Malloc(bytes);
					if( buf == NULL)
					{
						Com_PrintWarning("FTP_SendReceiveData: Failed to allocate %d bytes for download file!\n", bytes);
						return -1;
					}
					MSG_Init(&request->transfermsg, buf, bytes);
					request->stage = 51;
				}
				break;
			case 150:
			case 125:
				if (request->stage == 60) {
					request->stage = 61;
					Com_DPrintf("FTP_SendReceiveData: Begin File Transfer\n");
				}
				break;
			case 226:
				/* File transfer is completed from the servers view */
				if(request->stage < 9999) 
					request->stage = 9999;
				break;
			case 221:
				if(request->stage < 10000)
				{
					Com_Printf("\nThe FTP server closed the control connection before the transfer was completed!\n");
					request->stage = -1;
				}
				break;
			case 228:
				Com_Printf( "\nLong Passive Mode not supported and not requested!\n" );
				request->stage = -20;
				break;
				
			case 120:
				Com_Printf( "The FTP server is not ready at the moment!\n" );
				request->stage = -20;
				break;
			case 231:
				if(request->stage < 10000)
				{
					Com_Printf("\nThe FTP server logged us out before the transfer was completed!\n");
					request->stage = -20;
				}
				break;
			case 350:
				if(request->stage < 10000)
				{
					Com_Printf("\nThe FTP server returned \'%s\' before the transfer was completed. Must not happen!\n", line);
					request->stage = -20;
				}
				break;
			case 421:
				request->stage = -1;
				break;
			case 500:
			case 501:
			case 502:
			case 503:
				if (request->stage == 32) {
					request->stage = 35;
					Com_DPrintf("FTP_SendReceiveData: Command EPSV is not implemented on FTP server. Trying PASV...\n");
					break;
				}else if (request->stage == 36) {
					Com_Printf("FTP_SendReceiveData: FTP Server does not support passive mode. Request failed!\n");
					request->stage = -10;
				} 
			default:
				if (request->code >= 200 && request->code < 300 && request->stage >= 30){
					Com_DPrintf("\n");
					Com_DPrintf("FTP_SendReceiveData: %s\n", line);					
					request->stage ++;
					break;
				}else if (request->code >= 400) {
					Com_Printf("\nThe FTP server connection got ended with the message: %s\n", line);
					request->stage = -20;
				}
				break;
		}
	}
	
	
	switch(request->stage)
	{
		case 1:
			/* Waiting for OK response code (220) */
			Com_sprintf(command, sizeof(command), "USER %s\r\n", "anonymous");
			FT_AddData(request, command, strlen(command));
			request->stage = 10;
			break;
		case 11:
			Com_sprintf(command, sizeof(command), "PASS %s\r\n", "*****@*****.**");
			FT_AddData(request, command, strlen(command));
			request->stage = 12;
			break;
		case 15:
			Com_sprintf(command, sizeof(command), "ACCT %s\r\n", "nil");
			FT_AddData(request, command, strlen(command));
			request->stage = 16;
			break;
		case 17:
			Com_sprintf(command, sizeof(command), "PASS %s\r\n", "*****@*****.**");
			FT_AddData(request, command, strlen(command));
			request->stage = 20;
			break;			
		case 21:
			Com_sprintf(command, sizeof(command), "TYPE I\r\n");
			FT_AddData(request, command, strlen(command));
			request->stage = 30;
			break;
		case 31:
			Com_sprintf(command, sizeof(command), "EPSV\r\n");
			FT_AddData(request, command, strlen(command));
			request->stage = 32;
			break;
		case 35:
			Com_sprintf(command, sizeof(command), "PASV\r\n");
			FT_AddData(request, command, strlen(command));
			request->stage = 36;
			break;
		case 41:
			Com_sprintf(command, sizeof(command), "SIZE %s\r\n", request->url);
			FT_AddData(request, command, strlen(command));
			request->stage = 50;
			break;
		case 51:
			Com_sprintf(command, sizeof(command), "RETR %s\r\n", request->url);
			FT_AddData(request, command, strlen(command));
			request->stage = 60;
			break;			

		case 61:
			/* Receive new bytes */
			request->transferactive = qtrue;
			status = NET_ReceiveData(request->transfersocket, &request->transfermsg);
			
			if (status == -1){

				request->transfersocket = -1;
				
			}else if(status == -2){
				
				request->transfersocket = -1;			
			}
			if(request->transfermsg.cursize == request->transfermsg.maxsize && request->transfermsg.maxsize != 0)
			{
				/* Comple file retrived */
				request->stage = 9999;
				break;
			}else if(request->transfersocket == -1){
				request->stage = -20;
			}
			break;
			
		case 9999:
			
			status = -1;
			request->transferactive = qfalse;
			
			if(request->transfersocket >= 0)
				status = NET_ReceiveData(request->transfersocket, &request->transfermsg);
			
			if (status == -1 || status == -2){
				request->transfersocket = -1;
			}
			if(request->transfermsg.cursize == request->transfermsg.maxsize && request->transfermsg.maxsize != 0)
			{
				/* Comple file retrived */
				Com_sprintf(command, sizeof(command), "QUIT\r\n");
				FT_AddData(request, command, strlen(command));
				request->stage = 10000;
				break;
			}else {
				Com_Printf("\nThe FTP server closed the data connection before the transfer was completed!\n");
				request->stage = -20;
				break;
			}
		case -20:
			request->transferactive = qfalse;
			Com_Printf("\nFTP File Transfer has failed!\n");
		case -10:
			request->transferactive = qfalse;
			if(request->socket >= 0 )
			{
				Com_sprintf(command, sizeof(command), "QUIT\r\n", request->url);
				FT_AddData(request, command, strlen(command));
			}
			request->stage = -1;
			break;

		case -1:
			Com_Printf("\n");
			return -1;
			break;
			
		case 10000:
			request->transferactive = qfalse;

			if(request->socket >= 0)
			{
				NET_TcpCloseSocket(request->socket);
				request->socket = -1;
			}
			if(request->transfersocket >= 0)
			{
				NET_TcpCloseSocket(request->transfersocket);
				request->transfersocket = -1;
			}
			if(request->recvmsg.data != NULL)
			{
				Z_Free(request->recvmsg.data);
				request->recvmsg.data = NULL;
			}
			if(request->transfermsg.data == NULL)
			{
				request->stage = -1;
				Com_PrintError("\nReceived complete message but message buffer is NULL!\n");
				break;
			}
			Com_Memcpy(&request->recvmsg, &request->transfermsg, sizeof(msg_t));
			Com_Memset(&request->transfermsg, 0, sizeof(msg_t));
			request->contentLength = request->recvmsg.cursize;
			request->headerLength = 0;
			request->stage = 10001;
			request->code = 200;
			Q_strncpyz(request->status, "OK", sizeof(request->status));
			break;
		case 10001:
			Com_Printf("\n");
			return 1;
		default:
			return 0;
	}
	return 0;
	
}
tcpclientstate_t HL2Rcon_SourceRconAuth(netadr_t *from, msg_t *msg, int *connectionId){

	int packetlen;
	int packettype;
	int packetid;
	char* loginstring;
	char* username;
	char* password;
	byte msgbuf[32];
	msg_t sendmsg;
	rconUser_t* user;
	int i;
	char buf[MAX_STRING_CHARS];
	char stringlinebuf[MAX_STRING_CHARS];

	MSG_BeginReading(msg);
	packetlen = MSG_ReadLong(msg);

	if(packetlen != msg->cursize - 4){//Not a source rcon packet

		Com_Printf("Not a source rcon packet: len %d size %d\n", packetlen, msg->cursize);

		return TCP_AUTHNOTME;
	}
	packetid = MSG_ReadLong(msg);

	packettype = MSG_ReadLong(msg);

	if(packettype != SERVERDATA_AUTH)//Not a source rcon auth-packet
		return TCP_AUTHNOTME;

	if(SV_PlayerBannedByip(from, buf, sizeof(buf))){
		return TCP_AUTHBAD;
	}
	
	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);
	MSG_WriteLong(&sendmsg, 0);
	MSG_WriteLong(&sendmsg, SERVERDATA_RESPONSE_VALUE);
	MSG_WriteShort(&sendmsg, 0);
	if(NET_SendData(from->sock, &sendmsg) < 1)
	{
		return TCP_AUTHBAD;
	}

	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);

	loginstring = MSG_ReadStringLine(msg, stringlinebuf, sizeof(stringlinebuf));

	Cmd_TokenizeString(loginstring);

	if(Cmd_Argc() != 2){
		goto badrcon;
	}
	username = Cmd_Argv(0);
	password = Cmd_Argv(1);

	if(strlen(password) < 6){
		goto badrcon;
	}

	if(Auth_Authorize(username, password) < 0)
	{
		goto badrcon;
	}

	Com_Printf("Rcon login from: %s Name: %s\n", NET_AdrToString (from), username);

	Cmd_EndTokenizedString();

	for(i = 0, user = sourceRcon.activeRconUsers; i < MAX_RCONUSERS; i++, user++){
		if(user->remote.type == NA_BAD)
			break;
	}

	if(i == MAX_RCONUSERS){
		return TCP_AUTHBAD; //Close connection
	}


	user->remote = *from;
	user->uid = Auth_GetUID(username);
//	user->rconPower = login->power;
	Q_strncpyz(user->rconUsername, username, sizeof(user->rconUsername));
	user->streamchat = 0;
	user->streamlog = 0;
	user->lastpacketid = packetid;
	*connectionId = i;

	MSG_WriteLong(&sendmsg, user->lastpacketid);
	MSG_WriteLong(&sendmsg, SERVERDATA_AUTH_RESPONSE);
	MSG_WriteShort(&sendmsg, 0);
	if(NET_SendData(from->sock, &sendmsg) < 1)
	{
		return TCP_AUTHBAD;
	}

	return TCP_AUTHSUCCESSFULL;


badrcon:
	Cmd_EndTokenizedString();
	Com_Printf ("Bad rcon from %s (TCP)\n", NET_AdrToString (from) );
	//Don't allow another attempt for 20 seconds
	SV_PlayerAddBanByip(from, "Bad rcon", 0, NULL, 0, Com_GetRealtime() + 20);

	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);
	MSG_WriteLong(&sendmsg, -1);
	MSG_WriteLong(&sendmsg, SERVERDATA_AUTH_RESPONSE);
	MSG_WriteShort(&sendmsg, 0);
	NET_SendData(from->sock, &sendmsg);
	return TCP_AUTHBAD;

}
示例#23
0
int HTTPServer_ReadMessage(netadr_t* from, msg_t* msg, ftRequest_t* request)
{
	
	char stringlinebuf[MAX_STRING_CHARS];
	byte* newbuf;
	char* line;
	int newsize, i;
	qboolean gotheader;
	
	if (request->recvmsg.maxsize - request->recvmsg.cursize < msg->cursize) 
	{
		if(request->finallen != -1)
		{
			newsize = request->finallen;
		}else {
			newsize = 2 * request->recvmsg.maxsize + msg->cursize;
		}
		
		newbuf = Z_Malloc(newsize);
		if(newbuf == NULL)
		{
			return -1;
		}
		
		Com_Memcpy(newbuf, request->recvmsg.data, request->recvmsg.cursize);
		
		Z_Free(request->recvmsg.data);
		request->recvmsg.data = newbuf;
		request->recvmsg.maxsize = newsize;
		
	}

	Com_Memcpy(&request->recvmsg.data[request->recvmsg.cursize], msg->data, msg->cursize);

	request->recvmsg.cursize += msg->cursize;

	/* Is header complete ? */
	if(request->finallen == -1)
	{
		gotheader = qfalse;
		/* 1st check if the header is complete */
		while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' )
		{
			if(line[0] == '\r')
			{
				gotheader = qtrue;
				break;
			}
		}
		if(gotheader == qfalse)
		{
			return 0;
		}
		MSG_BeginReading(&request->recvmsg);
		
		line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf));
		if (!Q_strncmp(line, "HEAD", 4)) {
			request->mode = HTTP_HEAD;
			line += 5;
		}else if (!Q_strncmp(line, "POST", 4)) {
			request->mode = HTTP_POST;
			line += 5;
		}else if (!Q_strncmp(line, "GET", 3)) {
			request->mode = HTTP_GET;
			line += 4;
		}else {
			Com_DPrintf("Invalid HTTP method from %s\n", NET_AdrToString(from));
			return -1;
		}
		
		i = 0;
		while (*line != ' ' && *line != '\r' && *line)
		{
			request->url[i] = *line;
			i++;
			line++;
		}
		
		if(*line == ' ')
		{
			line++;
		}
		
		if(Q_stricmpn(line,"HTTP/1.",7) || isInteger(line + 7, 2) == qfalse || isInteger(line + 9, 4) == qfalse)
		{
			Com_PrintError("HTTP_ReceiveData: Packet is corrupt!\nDebug: %s\n", line);
			
			return -1;
		}
		
		request->version = atoi(line + 7);
		if (request->version != 0 && request->version != 1)
		{
			Com_PrintError("HTTP_ReceiveData: Packet has unknown HTTP version 1.%d !\n", request->version);
			
			return -1;			
		}
		
		
		request->contentLength = 0;
		
		while ((line = MSG_ReadStringLine(&request->recvmsg, stringlinebuf, sizeof(stringlinebuf))) && line[0] != '\0' && line[0] != '\r')
		{
			if(!Q_stricmpn("Content-Length:", line, 15))
			{
				if(isInteger(line + 15, 0) == qfalse)
				{
					Com_PrintError("Sec_GetHTTPPacket: Packet is corrupt!\nDebug: %s\n", line);
					return -1;
				}
				request->contentLength = atoi(line + 15);
				if(request->contentLength < 0)
				{
					request->contentLength = 0;
					return -1;
				}
			}
			else if(!Q_stricmpn("Content-Type:", line, 13))
			{

				if(line[13] == ' ')
				{
					Q_strncpyz(request->contentType, &line[14], sizeof(request->contentType));
				}else{
					Q_strncpyz(request->contentType, &line[13], sizeof(request->contentType));
				}

			}
			else if(!Q_stricmpn("Cookie:", line, 7))
			{
				
				if(line[7] == ' ')
				{
					Q_strncpyz(request->cookie, &line[8], sizeof(request->cookie));
				}else{
					Q_strncpyz(request->cookie, &line[7], sizeof(request->cookie));
				}
				
			}				
		}
		if(line[0] == '\0')
			return -1;
		
		request->headerLength = request->recvmsg.readcount;		
		request->finallen = request->contentLength + request->headerLength;
		
		if(request->finallen > 1024*1024*640)
		{
			request->finallen = request->headerLength;
		}
		
	}
	if(request->recvmsg.maxsize == request->finallen)
	request->transferactive = qtrue;


	if (request->recvmsg.cursize < request->finallen) {
		/* Still needing bytes... */
		return 0;
	}
//	Com_Printf("^6HTTP-Message is complete!\n");
//	Com_Printf("^6Received: Version: HTTP/1.%d   Method: %d   Content-Length: %d   URL: %s\n", request->version, request->mode, request->contentLength, request->url);
	return 1;
}
示例#24
0
void CL_ServerStatusResponse( const netadr_t& from, msg_t *msg )
{
	char	info[MAX_INFO_STRING];
	int		i, l, score, ping;
	int		len;

	serverStatus_t* serverStatus = NULL;
	for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) {
		if ( NET_CompareAdr( from, cl_serverStatusList[i].address ) ) {
			serverStatus = &cl_serverStatusList[i];
			break;
		}
	}
	// if we didn't request this server status
	if (!serverStatus) {
		return;
	}

	const char* s = MSG_ReadStringLine( msg );

	len = 0;
	Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "%s", s);

	if (serverStatus->print) {
		Com_Printf("Server settings:\n");
		// print cvars
		while (*s) {
			for (i = 0; i < 2 && *s; i++) {
				if (*s == '\\')
					s++;
				l = 0;
				while (*s) {
					info[l++] = *s;
					if (l >= MAX_INFO_STRING-1)
						break;
					s++;
					if (*s == '\\') {
						break;
					}
				}
				info[l] = '\0';
				if (i) {
					Com_Printf("%s\n", info);
				}
				else {
					Com_Printf("%-24s", info);
				}
			}
		}
	}

	len = strlen(serverStatus->string);
	Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "\\");

	if (serverStatus->print) {
		Com_Printf("\nPlayers:\n");
		Com_Printf("num: score: ping: name:\n");
	}
	for (i = 0, s = MSG_ReadStringLine( msg ); *s; s = MSG_ReadStringLine( msg ), i++) {

		len = strlen(serverStatus->string);
		Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "\\%s", s);

		if (serverStatus->print) {
			score = ping = 0;
			sscanf(s, "%d %d", &score, &ping);
			s = strchr(s, ' ');
			if (s)
				s = strchr(s+1, ' ');
			if (s)
				s++;
			else
				s = "unknown";
			Com_Printf("%-2d   %-3d    %-3d   %s\n", i, score, ping, s );
		}
	}
	len = strlen(serverStatus->string);
	Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "\\");

	serverStatus->time = Com_Milliseconds();
	serverStatus->address = from;
	serverStatus->pending = qfalse;
	if (serverStatus->print) {
		serverStatus->retrieved = qtrue;
	}
}
示例#25
0
文件: clc.c 项目: deurk/qwfwd
static qbool CL_ConnectionlessPacket_Q3 (peer_t *p) 
{
	char	*s, buf[] = "xxx.xxx.xxx.xxx:xxxxx";
	char	*c;
	qbool need_forward = false;
	
    MSG_BeginReading();
    MSG_ReadLong();	// Skip the -1

	s = MSG_ReadStringLine();
	Cmd_TokenizeString( s );
	c = Cmd_Argv(0);

	if ( developer->integer )
	{
		Sys_DPrintf ("CL packet %s: %s\n", NET_AdrToString(&net_from, buf, sizeof(buf)), s);
	}

	// challenge from the server we are connecting to
	if ( !stricmp(c, "challengeResponse") )
	{
		if ( p->ps != ps_challenge )
		{
			Sys_DPrintf( "Unwanted challenge response received.  Ignored.\n" );
		}
		else
		{
			// start sending connect requests instead of challenge request packets
			p->challenge = atoi(Cmd_Argv(1));

			// take this address as the new server address.  This allows
			// a server proxy to hand off connections to multiple servers
//			clc.serverAddress = from;

			Sys_DPrintf ("challengeResponse: %d\n", p->challenge);

			CL_SendConnectPacket_Q3( p );
		}

		return need_forward;
	}

	// server connection
	if ( !stricmp(c, "connectResponse") )
	{
		if ( p->ps >= ps_connected )
		{
			Sys_DPrintf ("Dup connect received.  Ignored.\n");
			return need_forward;
		}

		if ( p->ps != ps_challenge )
		{
			Sys_DPrintf ("connectResponse packet while not connecting.  Ignored.\n");
			return need_forward;
		}

		Sys_DPrintf ("connectResponse\n");

		// we are connected now
		p->ps = ps_connected;

// possibile to lost this message, so moved to the other place where it sended time to time
//		Netchan_OutOfBandPrint(net_socket, &p->from, "print\n" "/reconnect ASAP!\n");

		return need_forward;
	}

	// a disconnect message from the server, which will happen if the server
	// dropped the connection but it is still getting packets from us
	if ( !stricmp(c, "disconnect") )
	{
//		CL_DisconnectPacket( from );
		p->ps = ps_drop; // drop this peer
		return need_forward = true; // so client have chance to see what server trying to say
	}

	// echo request from server
	if ( !stricmp(c, "print") )
	{
		Sys_DPrintf( "%s", MSG_ReadString() );
		return need_forward = true; // so client have chance to see what server trying to say
	}

	return need_forward;
}
示例#26
0
void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
	char* s;
	char* c;
	
	MSG_BeginReading(msg);
	MSG_ReadLong(msg);
	
	#if CODPATCH == 5
	
	void (*SV_Netchan_AddOOBProfilePacket)(int);
	*(int*)&SV_Netchan_AddOOBProfilePacket = 0x8094928;
	SV_Netchan_AddOOBProfilePacket(msg->cursize);
	
	#endif
	
	//dumpbase((int*)msg, sizeof(msg_t));
	
	if ( !Q_strncmp( "connect", (char*)&msg->data[4], 7 ) )
		Huff_Decompress( msg, 12 );
	
	s = MSG_ReadStringLine(msg);
	
	Cmd_TokenizeString(s);
	
	c = Cmd_Argv(0);
	
	if ( !Q_stricmp( c,"getstatus" ) ) {
		SVC_Status( &from  );
	} else if ( !Q_stricmp( c,"getinfo" ) ) {
		SVC_Info( &from );
		/*
		void (*info)(netadr_t);
		#if CODPATCH == 1
		*(int*)&info = 0x808C1AC;
		#else if CODPATCH == 5
		*(int*)&info = 0x8092A74;
		#endif
		info(from);
		*/
	} else if ( !Q_stricmp( c,"getchallenge" ) ) {
		SV_GetChallenge( &from );
	} else if ( !Q_stricmp( c,"connect" ) ) {
		SV_DirectConnect( from );
	} else if ( !Q_stricmp( c,"ipAuthorize" ) ) {
		SV_AuthorizeIpPacket( from );
	} else if(!Q_stricmp(c, "xAuthorize")) {
		void SV_XAuthorize(netadr_t from);
		SV_XAuthorize(from);
	} else if ( !Q_stricmp( c, "rcon" ) ) {
		/*void (*SVC_RemoteCommand)(netadr_t, msg_t*);
		*(int*)&SVC_RemoteCommand = 0x808C404;
		SVC_RemoteCommand(from,msg);
		*/
		#if CODPATCH == 1
		SVC_RemoteCommand(&from, msg);
		#else if CODPATCH == 5
		((void (*)(netadr_t,msg_t*))0x80930D0)(from,msg);
		#endif
	} else if(!Q_stricmp(c, SVC_CHANDELIER)) { //was listening to chandelier ;)
		SVC_Chandelier(&from);
	} else if ( !Q_stricmp( c,"disconnect" ) ) {
		// if a client starts up a local server, we may see some spurious
		// server disconnect messages when their new server sees our final
		// sequenced messages to the old client*/
	} else {
		Com_DPrintf( "bad connectionless packet '%s' from %s.\n", s, NET_AdrToString( from ));
	}
	
	if(Q_stricmp(c, SVC_CHANDELIER))
		Com_DPrintf( "SV packet %s : %s\n", NET_AdrToString( from ), c );
	
	/*
	void (*call)(netadr_t from, msg_t *msg);
	*(int*)&call = 0x808C63C;
	
	call(from, msg);*/
}