当前位置: 首页>>代码示例>>C++>>正文


C++ SystemAddress::GetPort方法代码示例

本文整理汇总了C++中SystemAddress::GetPort方法的典型用法代码示例。如果您正苦于以下问题:C++ SystemAddress::GetPort方法的具体用法?C++ SystemAddress::GetPort怎么用?C++ SystemAddress::GetPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SystemAddress的用法示例。


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

示例1: SendOutOfBand

void NatPunchthroughClient::SendOutOfBand(SystemAddress sa, MessageID oobId)
{
	if (sa==UNASSIGNED_SYSTEM_ADDRESS)
		return;
	if (sa.GetPort()==0)
		return;

	RakNet::BitStream oob;
	oob.Write(oobId);
	oob.Write(sp.sessionId);
//	RakAssert(sp.sessionId<100);
	if (oobId==ID_NAT_ESTABLISH_BIDIRECTIONAL)
		oob.Write(sa.GetPort());
	char ipAddressString[32];
	sa.ToString(false, ipAddressString);
	rakPeerInterface->SendOutOfBand((const char*) ipAddressString,sa.GetPort(),(const char*) oob.GetData(),oob.GetNumberOfBytesUsed());

	if (natPunchthroughDebugInterface)
	{
		sa.ToString(true,ipAddressString);
		char guidString[128];
		sp.targetGuid.ToString(guidString);

		// server - diff = my time
		// server = myTime + diff
		RakNet::Time clockDifferential = rakPeerInterface->GetClockDifferential(sp.facilitator);
		RakNet::Time serverTime = RakNet::GetTime() + clockDifferential;

		if (oobId==ID_NAT_ESTABLISH_UNIDIRECTIONAL)
			natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("%I64d: %s: OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid %s, system address %s.\n", serverTime, TestModeToString(sp.testMode), guidString, ipAddressString));
		else
			natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("%I64d: %s: OOB ID_NAT_ESTABLISH_BIDIRECTIONAL to guid %s, system address %s.\n", serverTime, TestModeToString(sp.testMode), guidString, ipAddressString));
	}
}
开发者ID:Razish,项目名称:RakNet,代码行数:34,代码来源:NatPunchthroughClient.cpp

示例2: SendOutOfBand

void NatPunchthroughClient::SendOutOfBand(SystemAddress sa, MessageID oobId)
{
	if (sa==UNASSIGNED_SYSTEM_ADDRESS)
		return;
	if (sa.GetPort()==0)
		return;

	RakNet::BitStream oob;
	oob.Write(oobId);
	oob.Write(sp.sessionId);
//	RakAssert(sp.sessionId<100);
	if (oobId==ID_NAT_ESTABLISH_BIDIRECTIONAL)
		oob.Write(sa.GetPort());
	char ipAddressString[32];
	sa.ToString(false, ipAddressString);
	rakPeerInterface->SendOutOfBand((const char*) ipAddressString,sa.GetPort(),(const char*) oob.GetData(),oob.GetNumberOfBytesUsed());

	if (natPunchthroughDebugInterface)
	{
		sa.ToString(true,ipAddressString);
		char guidString[128];
		sp.targetGuid.ToString(guidString);

		if (oobId==ID_NAT_ESTABLISH_UNIDIRECTIONAL)
			natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("Sent OOB ID_NAT_ESTABLISH_UNIDIRECTIONAL to guid %s, system address %s.", guidString, ipAddressString));
		else
			natPunchthroughDebugInterface->OnClientMessage(RakNet::RakString("Sent OOB ID_NAT_ESTABLISH_BIDIRECTIONAL to guid %s, system address %s.", guidString, ipAddressString));
	}
}
开发者ID:DarkSlim,项目名称:IVMultiplayer-1,代码行数:29,代码来源:NatPunchthroughClient.cpp

示例3: SendTTL

void NatPunchthroughClient::SendTTL(const SystemAddress &sa)
{
	if (sa==UNASSIGNED_SYSTEM_ADDRESS)
		return;
	if (sa.GetPort()==0)
		return;

	char ipAddressString[32];
	sa.ToString(false, ipAddressString);
	// TTL of 1 doesn't get past the router, 2 might hit the other system on a LAN
	rakPeerInterface->SendTTL(ipAddressString,sa.GetPort(), 2);
}
开发者ID:DarkSlim,项目名称:IVMultiplayer-1,代码行数:12,代码来源:NatPunchthroughClient.cpp

示例4: OnNewConnection

void NatPunchthroughClient::OnNewConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
{
	(void) rakNetGUID;
	(void) isIncoming;

	// Try to track new port mappings on the router. Not reliable, but better than nothing.
	SystemAddress ourExternalId = rakPeerInterface->GetExternalID(systemAddress);
	if (ourExternalId!=UNASSIGNED_SYSTEM_ADDRESS && nextExternalPort==0)
		nextExternalPort=ourExternalId.GetPort();

	/*
	unsigned int i;
	i=0;
	while (i < groupRequestsInProgress.Size())
	{
		if (groupRequestsInProgress[i].guid==rakNetGUID)
		{
			groupRequestsInProgress.RemoveAtIndexFast(i);
		}
		else
		{
			i++;
		}
	}
	*/
}
开发者ID:DarkSlim,项目名称:IVMultiplayer-1,代码行数:26,代码来源:NatPunchthroughClient.cpp

示例5:

ACTIONSCRIPT_CALLABLE_FUNCTION(RoomsBrowserGFx3_RakNet, f2c_JoinByFilter)
{
	if (pparams.GetArgCount()<1)
		return;

	RakNet::JoinByFilter_Func func;
	func.userName=loginUsername;
	func.gameIdentifier=titleName;
	func.roomMemberMode=RMM_ANY_PLAYABLE;

	bool roomIsFromServer=pparams[0].GetBool();
	double roomGuid=pparams[1].GetNumber();

	if (roomIsFromServer)
	{
		// See RoomTypes.h for other default columns
		func.query.AddQuery_NUMERIC( DefaultRoomColumns::GetColumnName(DefaultRoomColumns::TC_ROOM_ID), roomGuid);
		roomsPlugin->ExecuteFunc(&func);
	}
	else
	{
		SystemAddress sa;
		sa.FromString(pparams[2].GetString());
		char ipPart[32];
		sa.ToString(false,ipPart);
		rakPeer->Connect(ipPart,sa.GetPort(),0,0);
	}

}
开发者ID:dream7w,项目名称:ZRKServer,代码行数:29,代码来源:RoomsBrowserGFx3_RakNet.cpp

示例6: ReturnResult

void CommandParserInterface::ReturnResult(SystemAddress res, const char *command, TransportInterface *transport, const SystemAddress &systemAddress)
{
	char addr[128];
	systemAddress.ToString(false,addr,static_cast<size_t>(128));
	char addr2[128];
	res.ToString(false,addr2,static_cast<size_t>(128));
	transport->Send(systemAddress, "%s returned %s %s:%i\r\n", command,addr,addr2,res.GetPort());
}
开发者ID:TrevorCash,项目名称:Urho3D,代码行数:8,代码来源:CommandParserInterface.cpp

示例7:

void Router2::SendOOBFromRakNetPort(OutOfBandIdentifiers oob, BitStream *extraData, SystemAddress sa)
{
	RakNet::BitStream oobBs;
	oobBs.Write((unsigned char)oob);
	if (extraData)
	{
		extraData->ResetReadPointer();
		oobBs.Write(*extraData);
	}
	char ipAddressString[32];
	sa.ToString(false, ipAddressString);
	rakPeerInterface->SendOutOfBand((const char*) ipAddressString,sa.GetPort(),(const char*) oobBs.GetData(),oobBs.GetNumberOfBytesUsed());
}
开发者ID:BillXu,项目名称:Project,代码行数:13,代码来源:Router2.cpp

示例8: bsIn

void FullyConnectedMesh2::ConnectToRemoteNewIncomingConnections(Packet *packet)
{
	unsigned int count;
	RakNet::BitStream bsIn(packet->data, packet->length, false);
	bsIn.IgnoreBytes(sizeof(MessageID));
	bsIn.Read(count);
	SystemAddress remoteAddress;
	RakNetGUID remoteGuid;
	char str[64];
	for (unsigned int i=0; i < count; i++)
	{
		bsIn.Read(remoteAddress);
		bsIn.Read(remoteGuid);
		remoteAddress.ToString(false,str);
		rakPeerInterface->Connect(str,remoteAddress.GetPort(),connectionPassword.C_String(),(int) connectionPassword.GetLength());
	}
}
开发者ID:Arkamarante,项目名称:collision-domain,代码行数:17,代码来源:FullyConnectedMesh2.cpp

示例9: if

int Lobby2Client_Steam_Impl::RakNetSendTo( const char *data, int length, const SystemAddress &systemAddress )
{
	bool objectExists;
	unsigned int i = roomMembersByAddr.GetIndexFromKey(systemAddress, &objectExists);
	if (objectExists)
	{
		if (SteamNetworking()->SendP2PPacket(roomMembersByAddr[i].steamIDRemote, data, length, k_EP2PSendUnreliable))
			return length;
		else
			return 0;
	}
	else if (systemAddress.GetPort()!=STEAM_UNUSED_PORT)
	{
	//	return SocketLayer::SendTo_PC(s,data,length,systemAddress,_FILE_AND_LINE_);
		return -1;
	}
	return 0;
}
开发者ID:dream7w,项目名称:ZRKServer,代码行数:18,代码来源:Lobby2Client_Steam_Impl.cpp

示例10: UpdateThreaded


//.........这里部分代码省略.........
				DWORD dwIOError = WSAGetLastError();

				if (dwIOError!=WSAECONNRESET && dwIOError!=WSAEINTR && dwIOError!=WSAETIMEDOUT)
				{
					LPVOID messageBuffer;
					FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
						NULL, dwIOError, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),  // Default language
						( LPTSTR ) & messageBuffer, 0, NULL );
					// something has gone wrong here...
					RAKNET_DEBUG_PRINTF( "recvfrom failed:Error code - %d\n%s", dwIOError, messageBuffer );

					//Free the buffer.
					LocalFree( messageBuffer );
				}
#endif
				continue;
			}

			if (their_addr.ss_family==AF_INET)
			{
				sockAddrIn=(sockaddr_in *)&their_addr;
				sockAddrIn6=0;
				memcpy(&receivedAddr.address.addr4,sockAddrIn,sizeof(sockaddr_in));
			//	receivedAddr.address.addr4.sin_port=ntohs( sockAddrIn->sin_port );
			}
			else
			{
				sockAddrIn=0;
				sockAddrIn6=(sockaddr_in6 *)&their_addr;
				memcpy(&receivedAddr.address.addr6,sockAddrIn6,sizeof(sockaddr_in6));
			//	receivedAddr.address.addr6.sin6_port=ntohs( sockAddrIn6->sin6_port );
			}
			
			if (forwardEntry->srcAndDest.source.EqualsExcludingPort(receivedAddr) && forwardEntry->updatedSourcePort==false && forwardEntry->srcAndDest.dest.GetPort()!=receivedAddr.GetPort())
			{
				forwardEntry->updatedSourcePort=true;

				if (forwardEntry->srcAndDest.source.GetPort()!=receivedAddr.GetPort())
				{
					DataStructures::DefaultIndexType index;
					SrcAndDest srcAndDest(forwardEntry->srcAndDest.dest, forwardEntry->srcAndDest.source);
					index=forwardList.GetIndexOf(srcAndDest);
					forwardList.RemoveAtIndex(index,_FILE_AND_LINE_);
					forwardEntry->srcAndDest.source.SetPort(receivedAddr.GetPort());
					forwardList.Push(forwardEntry,forwardEntry->srcAndDest,_FILE_AND_LINE_);
				}
			}
			
			if (forwardEntry->srcAndDest.source.EqualsExcludingPort(receivedAddr) && forwardEntry->srcAndDest.source.GetPort()==receivedAddr.GetPort())
			{
				// Forward to dest
				len=0;

				if (forwardEntry->srcAndDest.dest.address.addr4.sin_family==AF_INET)
				{
					do
					{
						len = sendto( forwardEntry->socket, data, receivedDataLen, 0, ( const sockaddr* ) & forwardEntry->srcAndDest.dest.address.addr4, sizeof( sockaddr_in ) );
					}
					while ( len == 0 );
				}
				else
				{
					do
					{
						len = sendto( forwardEntry->socket, data, receivedDataLen, 0, ( const sockaddr* ) & forwardEntry->srcAndDest.dest.address.addr6, sizeof( sockaddr_in ) );
开发者ID:lbird1992,项目名称:OfficeAutomation,代码行数:67,代码来源:UDPForwarder.cpp

示例11: bs

PluginReceiveResult Router2::OnReceive(Packet *packet)
{
	SystemAddress sa;
	RakNet::BitStream bs(packet->data,packet->length,false);
	if (packet->data[0]==ID_ROUTER_2_INTERNAL)
	{
		switch (packet->data[1])
		{
		case ID_ROUTER_2_QUERY_FORWARDING:
			{
				OnQueryForwarding(packet);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
			}
		case ID_ROUTER_2_REPLY_FORWARDING:
			{
				OnQueryForwardingReply(packet);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
			}
		case ID_ROUTER_2_REQUEST_FORWARDING:
			{

                if (debugInterface)
                {
                    char buff[512];
                    char buff2[32];
                    packet->systemAddress.ToString(true,buff2);
                    debugInterface->ShowDiagnostic(FormatStringTS(buff,"Got ID_ROUTER_2_REQUEST_FORWARDING on ip %s from %I64d, ",
                        buff2,packet->guid.g));
                }

				OnRequestForwarding(packet);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
			}
		case ID_ROUTER_2_INCREASE_TIMEOUT:
			{
				/// The routed system wants more time to stay alive on no communication, in case the router drops or crashes
				rakPeerInterface->SetTimeoutTime(rakPeerInterface->GetTimeoutTime(packet->systemAddress)+10000, packet->systemAddress);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
			}
		}
	}
	else if (packet->data[0]==ID_OUT_OF_BAND_INTERNAL && packet->length>=2)
	{
		switch (packet->data[1])
		{
			case ID_ROUTER_2_REPLY_TO_SENDER_PORT:
				{
					RakNet::BitStream bsOut;
					bsOut.Write(packet->guid);
					SendOOBFromRakNetPort(ID_ROUTER_2_MINI_PUNCH_REPLY, &bsOut, packet->systemAddress);

					if (debugInterface)
					{
						char buff[512];
						char buff2[32];
						sa.ToString(false,buff2);
						debugInterface->ShowDiagnostic(FormatStringTS(buff,"Got ID_ROUTER_2_REPLY_TO_SENDER_PORT %i on address %s, replying with ID_ROUTER_2_MINI_PUNCH_REPLY at %s:%i\n", sa.GetPort(), buff2, _FILE_AND_LINE_));

//						packet->systemAddress.ToString(true,buff2);
//						debugInterface->ShowDiagnostic(FormatStringTS(buff,"Got ID_ROUTER_2_REPLY_TO_SENDER_PORT on address %s (%I64d), "
//                                       "replying with ID_ROUTER_2_MINI_PUNCH_REPLY at %s:%i\n", buff2,packet->guid.g, __FILE__, __LINE__));
					}

					return RR_STOP_PROCESSING_AND_DEALLOCATE;
				}
			case ID_ROUTER_2_REPLY_TO_SPECIFIED_PORT:
				{
					RakNet::BitStream bsOut;
					bsOut.Write(packet->guid);
					bs.IgnoreBytes(2);
					sa=packet->systemAddress;
					unsigned short port;
					bs.Read(port);
					sa.SetPort(port);
					RakAssert(sa.GetPort()!=0);
					SendOOBFromRakNetPort(ID_ROUTER_2_MINI_PUNCH_REPLY, &bsOut, sa);

					if (debugInterface)
					{
						char buff[512];
						char buff2[32];
						sa.ToString(false,buff2);
						debugInterface->ShowDiagnostic(FormatStringTS(buff,"Got ID_ROUTER_2_REPLY_TO_SPECIFIED_PORT %i on address %s, "
                                        "replying with ID_ROUTER_2_MINI_PUNCH_REPLY at %s:%i\n", sa.GetPort(), buff2, __FILE__, __LINE__));
					}

					return RR_STOP_PROCESSING_AND_DEALLOCATE;
				}
			case ID_ROUTER_2_MINI_PUNCH_REPLY:
				OnMiniPunchReply(packet);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
			case ID_ROUTER_2_MINI_PUNCH_REPLY_BOUNCE:
				OnMiniPunchReplyBounce(packet);
				return RR_STOP_PROCESSING_AND_DEALLOCATE;
		}
	}
	else if (packet->data[0]==ID_ROUTER_2_FORWARDING_ESTABLISHED)
	{
//		printf("Got ID_ROUTER_2_FORWARDING_ESTABLISHED\n");
		if (OnForwardingSuccess(packet)==false)
//.........这里部分代码省略.........
开发者ID:BillXu,项目名称:Project,代码行数:101,代码来源:Router2.cpp

示例12: InitializeVaultMP

void Bethesda::InitializeVaultMP(RakPeerInterface* peer, SystemAddress server, const string& name, const string& pwd, bool multiinst, unsigned int inittime)
{
	Bethesda::password = pwd;
	Bethesda::multiinst = multiinst;
	Bethesda::inittime = inittime;
	Bethesda::modfiles.clear();
	initialized = false;

#ifdef VAULTMP_DEBUG
	Debug::SetDebugHandler("vaultmp");
	debug.note("Vault-Tec Multiplayer Mod client debug log (", CLIENT_VERSION, ")");
	debug.note("Connecting to server: ", server.ToString(), " (name: ", name.c_str(), ", password: ", pwd.c_str());
	debug.note("Visit www.vaultmp.com for help and upload this log if you experience problems with the mod.");
	debug.note("-----------------------------------------------------------------------------------------------------");
#endif

	GameFactory::Initialize();
	API::Initialize();

	GameFactory::Operate<Player>(GameFactory::Create<Player>(PLAYER_REFERENCE, PLAYER_BASE), [&name](Player* player) {
		player->SetEnabled(true);
		player->SetName(name);
	});

	Network::Flush();
	Network::ToggleDequeue(true);

	try
	{
		if (peer->Connect(server.ToString(false), server.GetPort(), DEDICATED_VERSION, sizeof(DEDICATED_VERSION), 0, 0, 3, 500, 0) == CONNECTION_ATTEMPT_STARTED)
		{
			bool query = true;

			while (query)
			{
				while (Network::Dispatch(peer));

				for (Packet* packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
				{
					if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION)
						query = false;
					else if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED)
						Game::server = peer->GetGuidFromSystemAddress(server);

					try
					{
						Network::Dispatch(peer, NetworkClient::ProcessPacket(packet));
					}
					catch (...)
					{
						peer->DeallocatePacket(packet);
						Network::Dispatch(peer, NetworkClient::ProcessEvent(ID_EVENT_CLIENT_ERROR));
						peer->CloseConnection(server, true, CHANNEL_SYSTEM, HIGH_PRIORITY);
						throw;
					}
				}

				if (!query)
					throw VaultException("Server closed connection").stacktrace();

				if (initialized && !Interface::IsAvailable())
				{
					Network::Dispatch(peer, NetworkClient::ProcessEvent(ID_EVENT_INTERFACE_LOST));
					peer->CloseConnection(server, true, CHANNEL_SYSTEM, HIGH_PRIORITY);
					query = false;

					if (!Interface::HasShutdown())
						throw VaultException("Interface lost, game closed unexpectedly").stacktrace();
				}

				this_thread::sleep_for(chrono::milliseconds(1));
			}
		}
		else
			throw VaultException("Could not establish connection to server").stacktrace();
	}
	catch (...)
	{
		Bethesda::Terminate(peer);

#ifdef VAULTMP_DEBUG
		debug.print("Network thread is going to terminate (ERROR)");
#endif
		throw;
	}

	Bethesda::Terminate(peer);

#ifdef VAULTMP_DEBUG
	debug.print("Network thread is going to terminate (no error occured)");
#endif
}
开发者ID:nuLLWire,项目名称:vaultmp,代码行数:92,代码来源:Bethesda.cpp

示例13: GetLocalPort

unsigned short SocketLayer::GetLocalPort(SOCKET s)
{
	SystemAddress sa;
	GetSystemAddress(s,&sa);
	return sa.GetPort();
}
开发者ID:BillXu,项目名称:Project,代码行数:6,代码来源:SocketLayer.cpp

示例14: InitializeVaultMP

void Bethesda::InitializeVaultMP(RakPeerInterface* peer, SystemAddress server, string name, string pwd, unsigned char game, bool multiinst, bool steam)
{
	Bethesda::game = game;
	Bethesda::password = pwd;
	Bethesda::multiinst = multiinst;
	Bethesda::steam = steam;
	Bethesda::savegame = Savegame();
	Bethesda::modfiles.clear();
	ZeroMemory(module, sizeof(module));
	Game::game = game;
	initialized = false;

#ifdef VAULTMP_DEBUG
	debug = new Debug((char*) "vaultmp");
	debug->PrintFormat("Vault-Tec Multiplayer Mod client debug log (%s)", false, CLIENT_VERSION);
	debug->PrintFormat("Connecting to server: %s (name: %s, password: %s, game: %s)", false, server.ToString(), name.c_str(), pwd.c_str(), game == FALLOUT3 ? (char*) "Fallout 3" : (char*) "Fallout New Vegas");
	debug->Print("Visit www.vaultmp.com for help and upload this log if you experience problems with the mod.", false);
	debug->Print("-----------------------------------------------------------------------------------------------------", false);
	//debug->PrintSystem();
	API::SetDebugHandler(debug);
	VaultException::SetDebugHandler(debug);
	NetworkClient::SetDebugHandler(debug);
	Interface::SetDebugHandler(debug);
	Lockable::SetDebugHandler(debug);
	Reference::SetDebugHandler(debug);
	Object::SetDebugHandler(debug);
	Item::SetDebugHandler(debug);
	Container::SetDebugHandler(debug);
	Actor::SetDebugHandler(debug);
	Player::SetDebugHandler(debug);
	Game::SetDebugHandler(debug);
	GameFactory::SetDebugHandler(debug);
	//Network::SetDebugHandler(debug);
#endif

	GameFactory::Initialize(game);
	API::Initialize(game);

	NetworkID id = GameFactory::CreateInstance(ID_PLAYER, PLAYER_REFERENCE, PLAYER_BASE);
	FactoryObject reference = GameFactory::GetObject(id);
	Player* self = vaultcast<Player>(reference);
	self->SetEnabled(true);
	self->SetName(name);
	GameFactory::LeaveReference(reference);

	Network::Flush();
	Network::ToggleDequeue(true);

	try
	{
		if (peer->Connect(server.ToString(false), server.GetPort(), DEDICATED_VERSION, sizeof(DEDICATED_VERSION), 0, 0, 3, 500, 0) == CONNECTION_ATTEMPT_STARTED)
		{
			bool query = true;
			Packet* packet;

			while (query)
			{
				while (Network::Dispatch(peer));

				for (packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
				{
					if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION)
						query = false;

					else if (packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED)
						Game::server = peer->GetGuidFromSystemAddress(server);

					try
					{
						Network::Dispatch(peer, NetworkClient::ProcessPacket(packet));
					}
					catch (...)
					{
						peer->DeallocatePacket(packet);
						Network::Dispatch(peer, NetworkClient::ProcessEvent(ID_EVENT_CLIENT_ERROR));
						peer->CloseConnection(server, true, CHANNEL_SYSTEM, HIGH_PRIORITY);
						throw;
					}
				}

				if (!query)
					throw VaultException("Server closed connection");

				if (initialized && !Interface::IsAvailable())
				{
					Network::Dispatch(peer, NetworkClient::ProcessEvent(ID_EVENT_INTERFACE_LOST));
					peer->CloseConnection(server, true, CHANNEL_SYSTEM, HIGH_PRIORITY);
					query = false;
				}

				this_thread::sleep_for(chrono::milliseconds(1));
			}
		}

		else
			throw VaultException("Could not establish connection to server");
	}

	catch (...)
	{
//.........这里部分代码省略.........
开发者ID:TheMw3Wolv,项目名称:Vault-Tec-Multiplayer-Mod,代码行数:101,代码来源:Bethesda.cpp

示例15: InitializeVaultMP

void Bethesda::InitializeVaultMP( RakPeerInterface* peer, SystemAddress server, string name, string pwd, unsigned char game )
{
	Bethesda::game = game;
	Bethesda::password = pwd;
	Bethesda::savegame = Savegame();
	Bethesda::modfiles.clear();
	Game::game = game;
	initialized = false;

#ifdef VAULTMP_DEBUG
	debug = new Debug( ( char* ) "vaultmp" );
	debug->PrintFormat( "Vault-Tec Multiplayer Mod client debug log (%s)", false, CLIENT_VERSION );
	debug->PrintFormat( "Connecting to server: %s (name: %s, password: %s, game: %s)", false, server.ToString(), name.c_str(), pwd.c_str(), game == FALLOUT3 ? ( char* ) "Fallout 3" : game == NEWVEGAS ? ( char* ) "Fallout New Vegas" : ( char* ) "TES Oblivion" );
	debug->Print( "Visit www.vaultmp.com for help and upload this log if you experience problems with the mod.", false );
	debug->Print( "-----------------------------------------------------------------------------------------------------", false );
	//debug->PrintSystem();
	API::SetDebugHandler( debug );
	VaultException::SetDebugHandler( debug );
	CriticalSection::SetDebugHandler( debug );
	NetworkClient::SetDebugHandler( debug );
	Interface::SetDebugHandler( debug );
	Lockable::SetDebugHandler( debug );
	Object::SetDebugHandler( debug );
	Item::SetDebugHandler( debug );
	Container::SetDebugHandler( debug );
	Actor::SetDebugHandler( debug );
	Player::SetDebugHandler( debug );
	Game::SetDebugHandler( debug );
	GameFactory::SetDebugHandler( debug );
#endif

	GameFactory::Initialize( game );
	API::Initialize( game );

	NetworkID id = GameFactory::CreateInstance( ID_PLAYER, PLAYER_REFERENCE, PLAYER_BASE );
	FactoryObject reference = GameFactory::GetObject( id );
	Player* self = vaultcast<Player>( reference );
	self->SetEnabled( true );
	self->SetName( name );
	GameFactory::LeaveReference( reference );
	self = NULL; // lets make sure that we dont use this by accident somewhere (old version code did so)

	Network::Flush();

	try
	{
		if ( peer->Connect( server.ToString( false ), server.GetPort(), DEDICATED_VERSION, sizeof( DEDICATED_VERSION ), 0, 0, 3, 500, 0 ) == CONNECTION_ATTEMPT_STARTED )
		{
			bool query = true;
			Packet* packet;

			while ( query )
			{
				NetworkResponse response;

				while ( ( response = Network::Next() ).size() )
					Network::Dispatch( peer, response );

				for ( packet = peer->Receive(); packet; peer->DeallocatePacket( packet ), packet = peer->Receive() )
				{
					if ( packet->data[0] == ID_DISCONNECTION_NOTIFICATION )
						query = false;

					else if ( packet->data[0] == ID_CONNECTION_REQUEST_ACCEPTED )
						Game::server = peer->GetGuidFromSystemAddress( server );

					try
					{
						response = NetworkClient::ProcessPacket( packet );
						Network::Dispatch( peer, response );
					}

					catch ( ... )
					{
						peer->DeallocatePacket( packet );
						response = NetworkClient::ProcessEvent( ID_EVENT_CLIENT_ERROR );
						Network::Dispatch( peer, response );
						peer->CloseConnection( server, true, CHANNEL_SYSTEM, HIGH_PRIORITY );
						throw;
					}
				}

				if ( initialized && !Interface::IsAvailable() )
				{
					NetworkResponse response = NetworkClient::ProcessEvent( ID_EVENT_INTERFACE_LOST );
					Network::Dispatch( peer, response );
					peer->CloseConnection( server, true, CHANNEL_SYSTEM, HIGH_PRIORITY );
					throw VaultException( "Lost connection to interface" );
				}

				RakSleep( 2 );
			}
		}

		else
			throw VaultException( "Could not establish connection to server" );
	}

	catch ( ... )
	{
//.........这里部分代码省略.........
开发者ID:CmaThomas,项目名称:Vault-Tec-Multiplayer-Mod,代码行数:101,代码来源:Bethesda.cpp


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