• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ NET_AddressToString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中NET_AddressToString函数的典型用法代码示例。如果您正苦于以下问题:C++ NET_AddressToString函数的具体用法?C++ NET_AddressToString怎么用?C++ NET_AddressToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NET_AddressToString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: TV_Upstream_ServerReconnect_f

/*
* TV_Upstream_ServerReconnect_f
* 
* The server is changing levels
*/
static void TV_Upstream_ServerReconnect_f( upstream_t *upstream )
{
	if( upstream->demo.playing )
		return;

	if( upstream->state < CA_CONNECTED )
	{
		Com_Printf( "%s: reconnect request while not connected\n", NET_AddressToString( &upstream->serveraddress ) );
		return;
	}

	if( upstream->demo.recording )
		TV_Upstream_StopDemoRecord( upstream, upstream->demo.autorecording, qfalse );

	Com_Printf( "%s: reconnecting...\n", NET_AddressToString( &upstream->serveraddress ) );

	upstream->connect_count = 0;
	upstream->rejected = 0;
#ifdef TCP_ALLOW_CONNECT
	upstream->connect_time = tvs.realtime;
#else
	upstream->connect_time = tvs.realtime - 1500;
#endif
	upstream->state = CA_HANDSHAKE;
	TV_Upstream_AddReliableCommand( upstream, "new" );
}
开发者ID:codetwister,项目名称:qfusion,代码行数:31,代码来源:tv_upstream_svcmd.c


示例2: SV_ConnectionlessPacket

/*
* 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 );
}
开发者ID:codetwister,项目名称:qfusion,代码行数:34,代码来源:sv_oob.c


示例3: TV_Upstream_Status_f

/*
* TV_Upstream_Status_f
*/
static void TV_Upstream_Status_f( void )
{
	int i;
	qboolean none;
	client_t *client;
	upstream_t *upstream;

	if( !TV_UpstreamForText( Cmd_Argv( 1 ), &upstream ) )
	{
		Com_Printf( "No such connection\n" );
		return;
	}

	if( upstream )
	{
		Com_Printf( "%s" S_COLOR_WHITE ": %s\n", upstream->name, NET_AddressToString( &upstream->serveraddress ) );
		Com_Printf( "Server name: %s\n", upstream->servername );
		Com_Printf( "Connection: %s\n", TV_ConnstateToString( upstream->state ) );
		Com_Printf( "Relay: %s\n", TV_ConnstateToString( upstream->relay.state ) );
	}
	else
	{
		Com_Printf( "lobby\n" );
	}

	Com_Printf( "Downstream connections:\n" );
	none = qtrue;
	for( i = 0; i < tv_maxclients->integer; i++ )
	{
		client = &tvs.clients[i];

		if( client->state == CS_FREE || client->state == CS_ZOMBIE )
			continue;
		if( !client->relay )
		{
			if( upstream )
				continue;
		}
		else
		{
			if( client->relay->upstream != upstream )
				continue;
		}

		Com_Printf( "%3i: %s" S_COLOR_WHITE " (%s)\n", i, client->name, NET_AddressToString( &client->netchan.remoteAddress ) );
		none = qfalse;
	}
	if( none )
		Com_Printf( "- No downstream connections\n" );
}
开发者ID:codetwister,项目名称:qfusion,代码行数:53,代码来源:tv_cmds.c


示例4: CL_MM_Connect

qboolean CL_MM_Connect( const netadr_t *address )
{
	/*
	* ch : this here sends a ticket request to MM.
	* upon response we can set the client state to CA_CONNECTING
	* and actually connect to the gameserver
	*/
	stat_query_t *query;

	// Com_Printf("CL_MM_Connect %s\n", NET_AddressToString( address ) );

	cls.mm_ticket = 0;

	// TODO: if not logged in, force login
	if( !cl_mm_enabled )
		return qfalse;

	// TODO: validate the parameters
	query = sq_api->CreateQuery( "ccc", qfalse );
	if( query == NULL )
		return qfalse;

	// TODO: put the session in a cookie
	sq_api->SetField( query, "csession", va( "%d", cls.mm_session ) );
	// we may have ipv4 or ipv6 in here, and MM currently on supports ipv4..
	sq_api->SetField( query, "saddr", NET_AddressToString( address ) );
	sq_api->SetCallback( query, cl_mm_connect_done, NULL );
	sq_api->Send( query );

	return qtrue;
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:31,代码来源:cl_mm.c


示例5: SV_SendClientsFragments

/*
* SV_SendClientsFragments
*/
bool SV_SendClientsFragments( void )
{
	client_t *client;
	int i;
	bool sent = false;

	// send a message to each connected client
	for( i = 0, client = svs.clients; i < sv_maxclients->integer; i++, client++ )
	{
		if( client->state == CS_FREE || client->state == CS_ZOMBIE )
			continue;
		if( client->edict && ( client->edict->r.svflags & SVF_FAKECLIENT ) )
			continue;
		if( !client->netchan.unsentFragments )
			continue;

		if( !Netchan_TransmitNextFragment( &client->netchan ) )
		{
			Com_Printf( "Error sending fragment to %s: %s\n", NET_AddressToString( &client->netchan.remoteAddress ),
				NET_ErrorString() );
			if( client->reliable )
				SV_DropClient( client, DROP_TYPE_GENERAL, "Error sending fragment: %s\n", NET_ErrorString() );
			continue;
		}

		sent = true;
	}

	return sent;
}
开发者ID:Clever-Boy,项目名称:qfusion,代码行数:33,代码来源:sv_send.c


示例6: MM_MatchList

//================
// MM_MatchesList
// Prints the list of matches to console
//================
void MM_MatchList( void )
{
	int i = 0, count = 0;
	mm_match_t *match;

	for( match = mms.matches ; match ; match = match->next )
	{
		Com_Printf( "Match id: %d\n ping type: %s\n gametype: %s\n skill type: %s\n clients:\n",
		            match->id,
		            match->pingtype == TYPE_ANY ? "any" : "dependent",
		            match->gametype,
		            match->skilltype == TYPE_ANY ? "any" : "dependent" );

		for( i = 0; i < match->maxclients; i++ )
		{
			if( match->clients[i] )
				Com_Printf( "  %s %s (%d): %s\n",
				           match->clients[i]->userid < 1 ? "U" : "R", // registered or not
				           match->clients[i]->nickname,
				           match->clients[i]->userid,
				           NET_AddressToString( &match->clients[i]->connection->address ) );
		}

		count++;
	}

	Com_Printf( "%d match(s)\n", count );
}
开发者ID:Racenet,项目名称:racesow,代码行数:32,代码来源:mm_matches.c


示例7: TV_Downstream_UpstreamlessPacket

/*
* 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 );
}
开发者ID:Clever-Boy,项目名称:qfusion,代码行数:30,代码来源:tv_downstream_oob.c


示例8: TV_Downstream_MasterHeartbeat

/*
* TV_Downstream_MasterHeartbeat
* Send a message to the master every few minutes to
* let it know we are alive, and log information
*/
void TV_Downstream_MasterHeartbeat( void )
{
	int i;
	const socket_t *socket;

	tvs.lobby.last_heartbeat -= tvs.lobby.snapFrameTime;
	if( tvs.lobby.last_heartbeat > 0 )
		return;

	tvs.lobby.last_heartbeat = HEARTBEAT_SECONDS * 1000;

	if( !tv_public->integer )
		return;

	// send to group master
	for( i = 0; i < MAX_MASTERS; i++ )
	{
		if( tv_master_adr[i].type != NA_NOTRANSMIT )
		{
			Com_Printf( "Sending heartbeat to %s\n", NET_AddressToString( &tv_master_adr[i] ) );

			socket = ( tv_master_adr[i].type == NA_IP6 ? &tvs.socket_udp6 : &tvs.socket_udp );

			// warning: "DarkPlaces" is a protocol name here, not a game name. Do not replace it.
			Netchan_OutOfBandPrint( socket, &tv_master_adr[i], "heartbeat %s\n", "DarkPlaces" );
		}
	}
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:33,代码来源:tv_downstream.c


示例9: SV_MasterSendQuit

/*
* SV_MasterSendQuit
* Notifies Steam master servers that the server is shutting down.
*/
void SV_MasterSendQuit( void )
{
	int i;
	const char quitMessage[] = "b\n";

	if( !sv_public->integer || ( sv_maxclients->integer == 1 ) )
		return;

	// never go public when not acting as a game server
	if( sv.state > ss_game )
		return;

	// send to group master
	for( i = 0; i < MAX_MASTERS; i++ )
	{
		sv_master_t *master = &sv_masters[i];

		if( master->steam && ( master->address.type != NA_NOTRANSMIT ) )
		{
			socket_t *socket = ( master->address.type == NA_IP6 ? &svs.socket_udp6 : &svs.socket_udp );

			if( dedicated && dedicated->integer )
				Com_Printf( "Sending quit to %s\n", NET_AddressToString( &master->address ) );

			NET_SendPacket( socket, ( const uint8_t * )quitMessage, sizeof( quitMessage ), &master->address );
		}
	}
}
开发者ID:futurepneu,项目名称:racemod,代码行数:32,代码来源:sv_oob.c


示例10: CL_ParseStatusMessage

/*
* CL_ParseStatusMessage
* Handle a reply from a ping
*/
void CL_ParseStatusMessage( const socket_t *socket, const netadr_t *address, msg_t *msg )
{
	char *s = MSG_ReadString( msg );
	serverlist_t *pingserver;
	char adrString[64];

	Com_DPrintf( "%s\n", s );

	Q_strncpyz( adrString, NET_AddressToString( address ), sizeof( adrString ) );

	// ping response
	pingserver = CL_ServerFindInList( masterList, adrString );
	if( !pingserver )
		pingserver = CL_ServerFindInList( favoritesList, adrString );

	if( pingserver && pingserver->pingTimeStamp ) // valid ping
	{
		unsigned int ping = Sys_Milliseconds() - pingserver->pingTimeStamp;
		CL_UIModule_AddToServerList( adrString, va( "\\\\ping\\\\%i%s", ping, s ) );
		pingserver->pingTimeStamp = 0;
		pingserver->lastValidPing = Com_DaysSince1900();
		return;
	}

	// assume LAN response
	if( NET_IsLANAddress( address ) && ( localQueryTimeStamp + LAN_SERVER_PINGING_TIMEOUT > Sys_Milliseconds() ) ) {
		unsigned int ping = Sys_Milliseconds() - localQueryTimeStamp;
		CL_UIModule_AddToServerList( adrString, va( "\\\\ping\\\\%i%s", ping, s ) );
		return;
	}

	// add the server info, but ignore the ping, cause it's not valid
	CL_UIModule_AddToServerList( adrString, s );
}
开发者ID:codetwister,项目名称:qfusion,代码行数:38,代码来源:cl_serverlist.c


示例11: NET_SendPacket

/*
 ==================
 NET_SendPacket
 ==================
*/
void NET_SendPacket (netSrc_t sock, const netAdr_t to, const void *data, int length){

	struct sockaddr	adr;
	int				result, error;

	if (NET_SendLoopPacket(sock, to, data, length))
		return;

	if (to.type != NA_BROADCAST && to.type != NA_IP)
		Com_Error(ERR_FATAL, "NET_SendPacket: bad address type");

	if (net.sockets[sock] == INVALID_SOCKET)
		return;

	NET_NetAdrToSockAdr(&to, &adr);

	result = sendto(net.sockets[sock], (const char *)data, length, 0, &adr, sizeof(adr));

	if (result == SOCKET_ERROR){
		error = WSAGetLastError();

		// WSAEWOULDBLOCK is silent
		if (error == WSAEWOULDBLOCK)
			return;

		// Some PPP links don't allow broadcasts
		if (error == WSAEADDRNOTAVAIL && to.type == NA_BROADCAST)
			return;

		Com_Printf(S_COLOR_RED "NET_SendPacket: %s to %s\n", NET_ErrorString(), NET_AddressToString(to));
	}

	net.packetsSent[sock]++;
	net.bytesSent[sock] += result;
}
开发者ID:Mirrorman95,项目名称:quake-2-evolved,代码行数:40,代码来源:win_network.c


示例12: TV_Downstream_AddMaster_f

/*
* TV_Downstream_AddMaster_f
* Add a master server to the list
*/
static void TV_Downstream_AddMaster_f( const char *master )
{
	int i;

	if( !master || !master[0] )
		return;

	if( !tv_public->integer )
	{
		Com_Printf( "'TV_Downstream_AddMaster_f' Only public servers use masters.\n" );
		return;
	}

	for( i = 0; i < MAX_MASTERS; i++ )
	{
		if( tv_master_adr[i].type != NA_NOTRANSMIT )
			continue;

		if( !NET_StringToAddress( master, &tv_master_adr[i] ) )
		{
			Com_Printf( "'SV_AddMaster_f' Bad Master server address: %s\n", master );
			return;
		}
		if( NET_GetAddressPort( &tv_master_adr[i] ) == 0 )
			NET_SetAddressPort( &tv_master_adr[i], PORT_MASTER );

		Com_Printf( "Added new master server #%i at %s\n", i, NET_AddressToString( &tv_master_adr[i] ) );
		return;
	}

	Com_Printf( "'TV_Downstream_AddMaster_f' List of master servers is already full\n" );
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:36,代码来源:tv_downstream.c


示例13: SVC_GetChallenge

/*
* SVC_GetChallenge
* 
* Returns a challenge number that can be used
* in a subsequent client_connect command.
* We do this to prevent denial of service attacks that
* flood the server with invalid connection IPs.  With a
* challenge, they must give a valid IP address.
*/
static void SVC_GetChallenge( const socket_t *socket, const netadr_t *address )
{
	int i;
	int oldest;
	int oldestTime;

	oldest = 0;
	oldestTime = 0x7fffffff;

	if( sv_showChallenge->integer )
		Com_Printf( "Challenge Packet %s\n", NET_AddressToString( address ) );

	// see if we already have a challenge for this ip
	for( i = 0; i < MAX_CHALLENGES; i++ )
	{
		if( NET_CompareBaseAddress( address, &svs.challenges[i].adr ) )
			break;
		if( svs.challenges[i].time < oldestTime )
		{
			oldestTime = svs.challenges[i].time;
			oldest = i;
		}
	}

	if( i == MAX_CHALLENGES )
	{
		// overwrite the oldest
		svs.challenges[oldest].challenge = rand() & 0x7fff;
		svs.challenges[oldest].adr = *address;
		svs.challenges[oldest].time = Sys_Milliseconds();
		i = oldest;
	}

	Netchan_OutOfBandPrint( socket, address, "challenge %i", svs.challenges[i].challenge );
}
开发者ID:codetwister,项目名称:qfusion,代码行数:44,代码来源:sv_oob.c


示例14: SV_MasterHeartbeat

/*
* SV_MasterHeartbeat
* Send a message to the master every few minutes to
* let it know we are alive, and log information
*/
void SV_MasterHeartbeat( void )
{
	int i;

	svc.lastHeartbeat -= svc.snapFrameTime;
	if( svc.lastHeartbeat > 0 )
		return;

	svc.lastHeartbeat = HEARTBEAT_SECONDS * 1000;

	if( !sv_public->integer )
		return;

	// never go public when not acting as a game server
	if( sv.state > ss_game )
		return;

	// send to group master
	for( i = 0; i < MAX_MASTERS; i++ )
	{
		if( master_adr[i].type != NA_NOTRANSMIT )
		{
			socket_t *socket;

			if( dedicated && dedicated->integer )
				Com_Printf( "Sending heartbeat to %s\n", NET_AddressToString( &master_adr[i] ) );

			socket = ( master_adr[i].type == NA_IP6 ? &svs.socket_udp6 : &svs.socket_udp );

			// warning: "DarkPlaces" is a protocol name here, not a game name. Do not replace it.
			Netchan_OutOfBandPrint( socket, &master_adr[i], "heartbeat DarkPlaces\n" );
		}
	}
}
开发者ID:codetwister,项目名称:qfusion,代码行数:39,代码来源:sv_oob.c


示例15: CL_Mumble_Update

/*
* CL_Mumble_Update
*/
void CL_Mumble_Update( const vec3_t origin, const vec3_t forward, const vec3_t right, const vec3_t up, const char *identity )
{
	vec3_t mp, mf, mt;
	char context[256];

	if( !cl_mumble->integer )
		return;
	if( !identity )
		return;

	VectorScale( origin, cl_mumble_scale->value, mp );
	VectorSet( mf, forward[0], forward[2], forward[1] );
	VectorSet( mt, up[0], up[2], up[1] );

	if( cl_mumble->integer == 2 )
		Com_Printf( "MumbleUpdate:\n%f, %f, %f\n%f, %f, %f\n%f, %f, %f", mp[0], mp[1], mp[2], mf[0], mf[1], mf[2], mt[0], mt[1], mt[2] );

	mumble_update_coordinates( mp, mf, mt );

	// for Mumble 1.2+  http://mumble.sourceforge.net/Link
	mumble_set_identity( identity );

	// TODO: add team to context?
	Q_strncpyz( context, NET_AddressToString( &cls.serveraddress ), sizeof( context ) );
	mumble_set_context( ( const unsigned char * )context, strlen( context ) + 1 );
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:29,代码来源:cl_sound.c


示例16: SVC_SendInfoString

/*
* SVC_SendInfoString
*/
static void SVC_SendInfoString( const socket_t *socket, const netadr_t *address, const char *requestType, const char *responseType, qboolean fullStatus )
{
	char *string;

	if( sv_showInfoQueries->integer )
		Com_Printf( "%s Packet %s\n", requestType, NET_AddressToString( address ) );

	// KoFFiE: When not public and coming from a LAN address
	//         assume broadcast and respond anyway, otherwise ignore
	if( ( ( !sv_public->integer ) && ( !NET_IsLANAddress( address ) ) ) ||
		( sv_maxclients->integer == 1 ) )
	{
		return;
	}

	// ignore when in invalid server state
	if( sv.state < ss_loading || sv.state > ss_game )
		return;

	// don't reply when we are locked for mm
	// if( SV_MM_IsLocked() )
	//	return;

	// send the same string that we would give for a status OOB command
	string = SV_LongInfoString( fullStatus );
	if( string )
		Netchan_OutOfBandPrint( socket, address, "%s\n\\challenge\\%s%s", responseType, Cmd_Argv( 1 ), string );
}
开发者ID:codetwister,项目名称:qfusion,代码行数:31,代码来源:sv_oob.c


示例17: SV_MM_ClientConnect

int SV_MM_ClientConnect( const netadr_t *address, char *userinfo, unsigned int ticket_id, int session_id )
{
	/*
	* what crizis did.. push a query after checking that ticket id and session id
	* at least aren't null and if server expects login-only clients
	*
	* ahem, figure out how to handle anonymous players. currently this will bug out so that
	* session_id is 0 -> request receives zero id's and freaks out. generate a session_id
	* here and return it.
	*
	* ok done. so this function receives session_id = 0 if we are dealing with 'anonymous'
	* player and this here generates local session-id for the client
	*/
	stat_query_t *query;

	// return of -1 is not an error, it just marks a dummy local session
	if( !sv_mm_initialized || !sv_mm_session )
		return -1;

	// accept only players that are logged in (session_id <= 0 ??)
	if( sv_mm_loginonly->integer && session_id == 0 )
	{
		Com_Printf("SV_MM_ClientConnect: Login-only\n");
		return 0;
	}

	// expect a ticket for logged-in client (rly?) session_id > 0
	// we should force local session in here
	if( ticket_id == 0 && session_id != 0 )
	{
		Com_Printf( "SV_MM_ClientConnect: Logged-in client didnt declare ticket, marking as anonymous\n" );
		session_id = 0;
	}

	if( session_id == 0 )
	{
		// WMM doesnt care about anonymous players
		session_id = SV_MM_GenerateLocalSession();
		Com_Printf("SV_MM_ClientConnect: Generated local session %d\n", session_id );
		return session_id;
	}

	// push a request
	query = sq_api->CreateQuery( "scc", qfalse );
	if( query == NULL )
		return 0;

	// servers own session (TODO: put this to a cookie or smth)
	sq_api->SetField( query, "ssession", va("%d", sv_mm_session ) );

	// clients attributes (nickname here?)
	sq_api->SetField( query, "cticket", va("%u", ticket_id ) );
	sq_api->SetField( query, "csession", va("%d", session_id ) );
	sq_api->SetField( query, "cip", NET_AddressToString( address ) );

	sq_api->SetCallback( query, sv_mm_clientconnect_done, (void*)session_id );
	sq_api->Send( query );

	return session_id;
}
开发者ID:Kaperstone,项目名称:warsow,代码行数:60,代码来源:sv_mm.c


示例18: SVC_RemoteCommand

/*
* SVC_RemoteCommand
* 
* A client issued an rcon command.
* Shift down the remaining args
* Redirect all printfs
*/
static void SVC_RemoteCommand( const socket_t *socket, const netadr_t *address )
{
	int i;
	char remaining[1024];
	flush_params_t extra;

	i = Rcon_Validate();

	if( i == 0 )
		Com_Printf( "Bad rcon from %s:\n%s\n", NET_AddressToString( address ), Cmd_Args() );
	else
		Com_Printf( "Rcon from %s:\n%s\n", NET_AddressToString( address ), Cmd_Args() );

	extra.socket = socket;
	extra.address = address;
	Com_BeginRedirect( RD_PACKET, sv_outputbuf, SV_OUTPUTBUF_LENGTH, SV_FlushRedirect, ( const void * )&extra );

	if( sv_showRcon->integer )
		Com_Printf( "Rcon Packet %s\n", NET_AddressToString( address ) );

	if( !Rcon_Validate() )
	{
		Com_Printf( "Bad rcon_password.\n" );
	}
	else
	{
		remaining[0] = 0;

		for( i = 2; i < Cmd_Argc(); i++ )
		{
			Q_strncatz( remaining, "\"", sizeof( remaining ) );
			Q_strncatz( remaining, Cmd_Argv( i ), sizeof( remaining ) );
			Q_strncatz( remaining, "\" ", sizeof( remaining ) );
		}

		Cmd_ExecuteString( remaining );
	}

	Com_EndRedirect();
}
开发者ID:codetwister,项目名称:qfusion,代码行数:47,代码来源:sv_oob.c


示例19: NET_GetPacket

/*
 ==================
 NET_GetPacket
 ==================
*/
bool NET_GetPacket (netSrc_t sock, netAdr_t *from, msg_t *msg){

	struct sockaddr	adr;
	int				adrLen = sizeof(adr);
	int 			result, error;

	if (NET_GetLoopPacket(sock, from, msg))
		return true;

	if (net.sockets[sock] == INVALID_SOCKET)
		return false;

	result = recvfrom(net.sockets[sock], (char *)msg->data, msg->maxSize, 0, (struct sockaddr *)&adr, &adrLen);

	NET_SockAdrToNetAdr(&adr, from);

	if (result == SOCKET_ERROR){
		error = WSAGetLastError();

		// WSAEWOULDBLOCK and WSAECONNRESET are silent
		if (error == WSAEWOULDBLOCK || error == WSAECONNRESET)
			return false;

		Com_Printf(S_COLOR_RED "NET_GetPacket: %s from %s\n", NET_ErrorString(), NET_AddressToString(*from));
		return false;
	}

	if (result == msg->maxSize){
		Com_Printf(S_COLOR_RED "NET_GetPacket: oversize packet from %s\n", NET_AddressToString(*from));
		return false;
	}

	msg->curSize = result;

	net.packetsReceived[sock]++;
	net.bytesReceived[sock] += result;

	return true;
}
开发者ID:Mirrorman95,项目名称:quake-2-evolved,代码行数:44,代码来源:win_network.c


示例20: SV_MasterHeartbeat

/*
* SV_MasterHeartbeat
* Send a message to the master every few minutes to
* let it know we are alive, and log information
*/
void SV_MasterHeartbeat( void )
{
	unsigned int time = Sys_Milliseconds();
	int i;

	if( svc.nextHeartbeat > time )
		return;

	svc.nextHeartbeat = time + HEARTBEAT_SECONDS * 1000;

	if( !sv_public->integer || ( sv_maxclients->integer == 1 ) )
		return;

	// never go public when not acting as a game server
	if( sv.state > ss_game )
		return;

	// send to group master
	for( i = 0; i < MAX_MASTERS; i++ )
	{
		sv_master_t *master = &sv_masters[i];

		if( master->address.type != NA_NOTRANSMIT )
		{
			socket_t *socket;

			if( dedicated && dedicated->integer )
				Com_Printf( "Sending heartbeat to %s\n", NET_AddressToString( &master->address ) );

			socket = ( master->address.type == NA_IP6 ? &svs.socket_udp6 : &svs.socket_udp );

			if( master->steam )
			{
				uint8_t steamHeartbeat = 'q';
				NET_SendPacket( socket, &steamHeartbeat, sizeof( steamHeartbeat ), &master->address );
			}
			else
			{
				// warning: "DarkPlaces" is a protocol name here, not a game name. Do not replace it.
				Netchan_OutOfBandPrint( socket, &master->address, "heartbeat DarkPlaces\n" );
			}
		}
	}
}
开发者ID:futurepneu,项目名称:racemod,代码行数:49,代码来源:sv_oob.c



注:本文中的NET_AddressToString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NET_CompareAdr函数代码示例发布时间:2022-05-30
下一篇:
C++ NETWORK_GetState函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap