void UPendingNetGame::NotifyControlMessage(UNetConnection* Connection, uint8 MessageType, class FInBunch& Bunch) { check(Connection==NetDriver->ServerConnection); #if !UE_BUILD_SHIPPING UE_LOG(LogNet, Verbose, TEXT("PendingLevel received: %s"), FNetControlMessageInfo::GetName(MessageType)); #endif // This client got a response from the server. switch (MessageType) { case NMT_Upgrade: // Report mismatch. uint32 RemoteNetworkVersion; FNetControlMessage<NMT_Upgrade>::Receive(Bunch, RemoteNetworkVersion); // Upgrade ConnectionError = NSLOCTEXT("Engine", "ClientOutdated", "The match you are trying to join is running an incompatible version of the game. Please try upgrading your game version.").ToString(); GEngine->BroadcastNetworkFailure(NULL, NetDriver, ENetworkFailure::OutdatedClient, ConnectionError); break; case NMT_Failure: { // our connection attempt failed for some reason, for example a synchronization mismatch (bad GUID, etc) or because the server rejected our join attempt (too many players, etc) // here we can further parse the string to determine the reason that the server closed our connection and present it to the user FString ErrorMsg; FNetControlMessage<NMT_Failure>::Receive(Bunch, ErrorMsg); if (ErrorMsg.IsEmpty()) { ErrorMsg = NSLOCTEXT("NetworkErrors", "GenericPendingConnectionFailed", "Pending Connection Failed.").ToString(); } // This error will be resolved in TickWorldTravel() ConnectionError = ErrorMsg; // Force close the session UE_LOG(LogNet, Log, TEXT("NetConnection::Close() [%s] [%s] [%s] from NMT_Failure %s"), Connection->Driver ? *Connection->Driver->NetDriverName.ToString() : TEXT("NULL"), Connection->PlayerController ? *Connection->PlayerController->GetName() : TEXT("NoPC"), Connection->OwningActor ? *Connection->OwningActor->GetName() : TEXT("No Owner"), *ConnectionError); Connection->Close(); break; } case NMT_Challenge: { // Challenged by server. FNetControlMessage<NMT_Challenge>::Receive(Bunch, Connection->Challenge); FURL PartialURL(URL); PartialURL.Host = TEXT(""); PartialURL.Port = PartialURL.UrlConfig.DefaultPort; // HACK: Need to fix URL parsing for (int32 i = URL.Op.Num() - 1; i >= 0; i--) { if (URL.Op[i].Left(5) == TEXT("game=")) { URL.Op.RemoveAt(i); } } FUniqueNetIdRepl UniqueIdRepl; ULocalPlayer* LocalPlayer = GEngine->GetFirstGamePlayer(this); if (LocalPlayer) { // Send the player nickname if available FString OverrideName = LocalPlayer->GetNickname(); if (OverrideName.Len() > 0) { PartialURL.AddOption(*FString::Printf(TEXT("Name=%s"), *OverrideName)); } // Send any game-specific url options for this player FString GameUrlOptions = LocalPlayer->GetGameLoginOptions(); if (GameUrlOptions.Len() > 0) { PartialURL.AddOption(*FString::Printf(TEXT("%s"), *GameUrlOptions)); } // Send the player unique Id at login UniqueIdRepl = LocalPlayer->GetPreferredUniqueNetId(); } Connection->ClientResponse = TEXT("0"); FString URLString(PartialURL.ToString()); FNetControlMessage<NMT_Login>::Send(Connection, Connection->ClientResponse, URLString, UniqueIdRepl); NetDriver->ServerConnection->FlushNet(); break; } case NMT_Welcome: { // Server accepted connection. FString GameName; FString RedirectURL; FNetControlMessage<NMT_Welcome>::Receive(Bunch, URL.Map, GameName, RedirectURL); //GEngine->NetworkRemapPath(this, URL.Map); UE_LOG(LogNet, Log, TEXT("Welcomed by server (Level: %s, Game: %s)"), *URL.Map, *GameName); // extract map name and options { FURL DefaultURL; FURL TempURL( &DefaultURL, *URL.Map, TRAVEL_Partial ); URL.Map = TempURL.Map; URL.RedirectURL = RedirectURL; URL.Op.Append(TempURL.Op); } if (GameName.Len() > 0) { URL.AddOption(*FString::Printf(TEXT("game=%s"), *GameName)); } // Send out netspeed now that we're connected FNetControlMessage<NMT_Netspeed>::Send(Connection, Connection->CurrentNetSpeed); // We have successfully connected. bSuccessfullyConnected = true; break; } case NMT_NetGUIDAssign: { FNetworkGUID NetGUID; FString Path; FNetControlMessage<NMT_NetGUIDAssign>::Receive(Bunch, NetGUID, Path); NetDriver->ServerConnection->PackageMap->ResolvePathAndAssignNetGUID(NetGUID, Path); break; } default: UE_LOG(LogNet, Log, TEXT(" --- Unknown/unexpected message for pending level")); break; } }
void AOnlineBeaconClient::NotifyControlMessage(UNetConnection* Connection, uint8 MessageType, class FInBunch& Bunch) { if(NetDriver->ServerConnection) { check(Connection == NetDriver->ServerConnection); // We are the client #if !(UE_BUILD_SHIPPING && WITH_EDITOR) UE_LOG(LogBeacon, Log, TEXT("%s[%s] Client received: %s"), *GetName(), *Connection->GetName(), FNetControlMessageInfo::GetName(MessageType)); #endif switch (MessageType) { case NMT_BeaconWelcome: { Connection->ClientResponse = TEXT("0"); FNetControlMessage<NMT_Netspeed>::Send(Connection, Connection->CurrentNetSpeed); FString BeaconType = GetBeaconType(); if (!BeaconType.IsEmpty()) { FUniqueNetIdRepl UniqueIdRepl; ULocalPlayer* LocalPlayer = GEngine->GetFirstGamePlayer(GetWorld()); if (LocalPlayer) { // Send the player unique Id at login UniqueIdRepl = LocalPlayer->GetPreferredUniqueNetId(); } FNetControlMessage<NMT_BeaconJoin>::Send(Connection, BeaconType, UniqueIdRepl); NetDriver->ServerConnection->FlushNet(); } else { // Force close the session UE_LOG(LogBeacon, Log, TEXT("Beacon close from invalid beacon type")); OnFailure(); } break; } case NMT_BeaconAssignGUID: { FNetworkGUID NetGUID; FNetControlMessage<NMT_BeaconAssignGUID>::Receive(Bunch, NetGUID); if (NetGUID.IsValid()) { Connection->Driver->GuidCache->RegisterNetGUID_Client( NetGUID, this ); FString BeaconType = GetBeaconType(); FNetControlMessage<NMT_BeaconNetGUIDAck>::Send(Connection, BeaconType); // Server will send ClientOnConnected() when it gets this control message // Fail safe for connection to server but no client connection RPC FTimerDelegate TimerDelegate = FTimerDelegate::CreateUObject(this, &AOnlineBeaconClient::OnFailure); GetWorldTimerManager().SetTimer(TimerHandle_OnFailure, TimerDelegate, BEACON_RPC_TIMEOUT, false); } else { // Force close the session UE_LOG(LogBeacon, Log, TEXT("Beacon close from invalid NetGUID")); OnFailure(); } break; } case NMT_Upgrade: { // Report mismatch. uint32 RemoteNetworkVersion; FNetControlMessage<NMT_Upgrade>::Receive(Bunch, RemoteNetworkVersion); // Upgrade const FString ConnectionError = NSLOCTEXT("Engine", "ClientOutdated", "The match you are trying to join is running an incompatible version of the game. Please try upgrading your game version.").ToString(); GEngine->BroadcastNetworkFailure(GetWorld(), NetDriver, ENetworkFailure::OutdatedClient, ConnectionError); break; } case NMT_Failure: { FString ErrorMsg; FNetControlMessage<NMT_Failure>::Receive(Bunch, ErrorMsg); if (ErrorMsg.IsEmpty()) { ErrorMsg = NSLOCTEXT("NetworkErrors", "GenericBeaconConnectionFailed", "Beacon Connection Failed.").ToString(); } // Force close the session UE_LOG(LogBeacon, Log, TEXT("Beacon close from NMT_Failure %s"), *ErrorMsg); OnFailure(); break; } case NMT_BeaconJoin: case NMT_BeaconNetGUIDAck: default: { // Force close the session UE_LOG(LogBeacon, Log, TEXT("Beacon close from unexpected control message")); OnFailure(); break; } } } }