void FileUpdater::OnSuccess() { // Do nothing if GSFileUpdateCheck is no longer the current state - this means we chose // to skip this check. // TODO if (TheGame::Instance()->GetState() != TheGSFileUpdateCheck::Instance()) { std::cout << "SKIPPED FILE UPDATE CHECK, SO IGNORING SERVER RESPONSE!!\n"; return; } PXml p = m_xml.getChildNode(1); if (SafeStrCmp(p.getName(), "files")) { #ifdef XML_DEBUG std::cout << "Found files element\n"; #endif // Get children - each child is of form <file>$filename</file>. Delete each file(!) int num = p.nChildNode(); std::cout << num << "children\n"; for (int i = 0; i < num; i++) { PXml child = p.getChildNode(i); if (!SafeStrCmp(child.getName(), "file")) { std::cout << "Got 'files' but no 'file' child\n"; OnFailure(); } std::string f = child.getText(); std::string full = File::GetRoot() + f; std::cout << "DELETE THIS FILE: \"" << full << "\"\n"; if (AmjuDeleteFile(full)) { std::cout << " -- succeeded!\n"; } else { std::cout << " -- failed!\n"; } // TODO and tell ObjectManager/ObjectUpdater to remove info about this file from their caches! } // Done - now prod ObjectManager to get new files std::cout << "Have finished deleting updated files, now need to download new versions!\n"; TheGSFileUpdateCheck::Instance()->OnFinishedChecking(m_timestamp); } else { OnFailure(); } }
void AOnlineBeacon::HandleNetworkFailure(UWorld *World, UNetDriver *InNetDriver, ENetworkFailure::Type FailureType, const FString& ErrorString) { if (InNetDriver && InNetDriver->NetDriverName == NetDriverName) { OnFailure(); } }
bool APartyBeaconClient::RequestReservation(const FOnlineSessionSearchResult& DesiredHost, const FUniqueNetIdRepl& RequestingPartyLeader, const TArray<FPlayerReservation>& PartyMembers) { bool bSuccess = false; if (DesiredHost.IsValid()) { UWorld* World = GetWorld(); IOnlineSubsystem* OnlineSub = Online::GetSubsystem(World); if (OnlineSub) { IOnlineSessionPtr SessionInt = OnlineSub->GetSessionInterface(); if (SessionInt.IsValid()) { FString ConnectInfo; if (SessionInt->GetResolvedConnectString(DesiredHost, BeaconPort, ConnectInfo)) { FString SessionId = DesiredHost.Session.SessionInfo->GetSessionId().ToString(); return RequestReservation(ConnectInfo, SessionId, RequestingPartyLeader, PartyMembers); } } } } if (!bSuccess) { OnFailure(); } return bSuccess; }
void APartyBeaconClient::OnConnected() { if (!bCancelReservation) { if (RequestType == EClientRequestType::ExistingSessionReservation) { UE_LOG(LogBeacon, Verbose, TEXT("Party beacon connection established, sending join reservation request.")); ServerReservationRequest(DestSessionId, PendingReservation); bPendingReservationSent = true; } else if (RequestType == EClientRequestType::ReservationUpdate) { UE_LOG(LogBeacon, Verbose, TEXT("Party beacon connection established, sending reservation update request.")); ServerUpdateReservationRequest(DestSessionId, PendingReservation); bPendingReservationSent = true; } else { UE_LOG(LogBeacon, Warning, TEXT("Failed to handle reservation request type %s"), ToString(RequestType)); OnFailure(); } } else { UE_LOG(LogBeacon, Verbose, TEXT("Reservation request previously canceled, aborting reservation request.")); ReservationRequestComplete.ExecuteIfBound(EPartyReservationResult::ReservationRequestCanceled); RequestType = EClientRequestType::NonePending; } }
bool APartyBeaconClient::RequestReservation(const FString& ConnectInfoStr, const FString& InSessionId, const FUniqueNetIdRepl& RequestingPartyLeader, const TArray<FPlayerReservation>& PartyMembers) { bool bSuccess = false; FURL ConnectURL(NULL, *ConnectInfoStr, TRAVEL_Absolute); if (InitClient(ConnectURL)) { DestSessionId = InSessionId; PendingReservation.PartyLeader = RequestingPartyLeader; PendingReservation.PartyMembers = PartyMembers; bPendingReservationSent = false; RequestType = EClientRequestType::ExistingSessionReservation; bSuccess = true; } else { UE_LOG_ONLINE(Warning, TEXT("RequestReservation: Failure to init client beacon with %s."), *ConnectURL.ToString()); RequestType = EClientRequestType::NonePending; } if (!bSuccess) { OnFailure(); } return bSuccess; }
void AOnlineBeacon::HandleNetworkFailure(UWorld *World, UNetDriver *InNetDriver, ENetworkFailure::Type FailureType, const FString& ErrorString) { if (InNetDriver && InNetDriver->NetDriverName == NetDriverName) { UE_LOG(LogBeacon, Verbose, TEXT("NetworkFailure %s: %s"), *GetName(), ENetworkFailure::ToString(FailureType)); OnFailure(); } }
xUnitFailure Assert::True(bool b, LineInfo &&lineInfo) const { if (!b) { return OnFailure(std::move(xUnitAssert(callPrefix + "True", std::move(lineInfo)).Expected("true").Actual("false"))); } return OnSuccess(); }
void TraversalClient::ResendPacket(OutgoingTraversalPacketInfo* info) { info->sendTime = enet_time_get(); info->tries++; ENetBuffer buf; buf.data = &info->packet; buf.dataLength = sizeof(info->packet); if (enet_socket_send(m_NetHost->socket, &m_ServerAddress, &buf, 1) == -1) OnFailure(SocketSendError); }
xUnitFailure Assert::Contains(const std::string &actualString, const std::string &value, LineInfo &&lineInfo) const { if (actualString.find(value) == std::string::npos) { return OnFailure(std::move(xUnitAssert(callPrefix + "Contains", std::move(lineInfo)) .Expected(std::string(value)) // can't assume actualString or value can be moved .Actual(std::string(actualString)))); } return OnSuccess(); }
xUnitFailure Assert::DoesNotContain(const std::string &actualString, const std::string &value, LineInfo &&lineInfo) const { auto found = actualString.find(value); if (found != std::string::npos) { return OnFailure(std::move(xUnitAssert(callPrefix + "DoesNotContain", std::move(lineInfo)) .CustomMessage("Found: \"" + value + "\" at position " + ToString(found) + "."))); } return OnSuccess(); }
xUnitFailure Assert::NotEqual(const std::string &expected, const std::string &actual, LineInfo &&lineInfo) const { if (expected == actual) { return OnFailure(std::move(xUnitAssert(callPrefix + "NotEqual", std::move(lineInfo)) .Expected(std::string(expected)) // can't assume expected or actual are allowed to be moved .Actual(std::string(actual)))); } return OnSuccess(); }
bool AOnlineBeaconClient::InitClient(FURL& URL) { bool bSuccess = false; if(URL.Valid) { if (InitBase() && NetDriver) { FString Error; if (NetDriver->InitConnect(this, URL, Error)) { BeaconConnection = NetDriver->ServerConnection; // Kick off the connection handshake if (BeaconConnection->StatelessConnectComponent.IsValid()) { BeaconConnection->StatelessConnectComponent.Pin()->SendInitialConnect(); } SetConnectionState(EBeaconConnectionState::Pending); NetDriver->SetWorld(GetWorld()); NetDriver->Notify = this; NetDriver->InitialConnectTimeout = BeaconConnectionInitialTimeout; NetDriver->ConnectionTimeout = BeaconConnectionTimeout; // Send initial message. uint8 IsLittleEndian = uint8(PLATFORM_LITTLE_ENDIAN); check(IsLittleEndian == !!IsLittleEndian); // should only be one or zero uint32 LocalNetworkVersion = FNetworkVersion::GetLocalNetworkVersion(); FNetControlMessage<NMT_Hello>::Send(NetDriver->ServerConnection, IsLittleEndian, LocalNetworkVersion); NetDriver->ServerConnection->FlushNet(); bSuccess = true; } else { // error initializing the network stack... UE_LOG(LogBeacon, Log, TEXT("AOnlineBeaconClient::InitClient failed")); SetConnectionState(EBeaconConnectionState::Invalid); OnFailure(); } } } return bSuccess; }
void TraversalClient::ReconnectToServer() { if (enet_address_set_host(&m_ServerAddress, m_Server.c_str())) { OnFailure(BadHost); return; } m_ServerAddress.port = m_port; m_State = Connecting; TraversalPacket hello = {}; hello.type = TraversalPacketHelloFromClient; hello.helloFromClient.protoVersion = TraversalProtoVersion; SendTraversalPacket(hello); if (m_Client) m_Client->OnTraversalStateChanged(); }
void TraversalClient::HandleResends() { enet_uint32 now = enet_time_get(); for (auto& tpi : m_OutgoingTraversalPackets) { if (now - tpi.sendTime >= (u32)(300 * tpi.tries)) { if (tpi.tries >= 5) { OnFailure(ResendTimeout); m_OutgoingTraversalPackets.clear(); break; } else { ResendPacket(&tpi); } } } HandlePing(); }
bool AOnlineBeaconHost::InitHost() { FURL URL(NULL, TEXT(""), TRAVEL_Absolute); // Allow the command line to override the default port int32 PortOverride; if (FParse::Value(FCommandLine::Get(), TEXT("BeaconPort="), PortOverride) && PortOverride != 0) { ListenPort = PortOverride; } URL.Port = ListenPort; if(URL.Valid) { if (InitBase() && NetDriver) { FString Error; if (NetDriver->InitListen(this, URL, false, Error)) { ListenPort = URL.Port; NetDriver->SetWorld(GetWorld()); NetDriver->Notify = this; NetDriver->InitialConnectTimeout = BEACON_CONNECTION_TIMEOUT; NetDriver->ConnectionTimeout = BEACON_CONNECTION_TIMEOUT; return true; } else { // error initializing the network stack... UE_LOG(LogNet, Log, TEXT("AOnlineBeaconHost::InitHost failed")); OnFailure(); } } } return false; }
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("Client received: %s"), 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()) { FNetControlMessage<NMT_BeaconJoin>::Send(Connection, BeaconType); 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; } } } }
void TraversalClient::HandleServerPacket(TraversalPacket* packet) { u8 ok = 1; switch (packet->type) { case TraversalPacketAck: if (!packet->ack.ok) { OnFailure(ServerForgotAboutUs); break; } for (auto it = m_OutgoingTraversalPackets.begin(); it != m_OutgoingTraversalPackets.end(); ++it) { if (it->packet.requestId == packet->requestId) { m_OutgoingTraversalPackets.erase(it); break; } } break; case TraversalPacketHelloFromServer: if (m_State != Connecting) break; if (!packet->helloFromServer.ok) { OnFailure(VersionTooOld); break; } m_HostId = packet->helloFromServer.yourHostId; m_State = Connected; if (m_Client) m_Client->OnTraversalStateChanged(); break; case TraversalPacketPleaseSendPacket: { // security is overrated. ENetAddress addr = MakeENetAddress(&packet->pleaseSendPacket.address); if (addr.port != 0) { char message[] = "Hello from Dolphin Netplay..."; ENetBuffer buf; buf.data = message; buf.dataLength = sizeof(message) - 1; enet_socket_send(m_NetHost->socket, &addr, &buf, 1); } else { // invalid IPV6 ok = 0; } break; } case TraversalPacketConnectReady: case TraversalPacketConnectFailed: { if (!m_PendingConnect || packet->connectReady.requestId != m_ConnectRequestId) break; m_PendingConnect = false; if (!m_Client) break; if (packet->type == TraversalPacketConnectReady) m_Client->OnConnectReady(MakeENetAddress(&packet->connectReady.address)); else m_Client->OnConnectFailed(packet->connectFailed.reason); break; } default: WARN_LOG(NETPLAY, "Received unknown packet with type %d", packet->type); break; } if (packet->type != TraversalPacketAck) { TraversalPacket ack = {}; ack.type = TraversalPacketAck; ack.requestId = packet->requestId; ack.ack.ok = ok; ENetBuffer buf; buf.data = &ack; buf.dataLength = sizeof(ack); if (enet_socket_send(m_NetHost->socket, &m_ServerAddress, &buf, 1) == -1) OnFailure(SocketSendError); } }
xUnitFailure Assert::Fail(LineInfo &&lineInfo) const { return OnFailure(std::move(xUnitAssert(callPrefix + "Fail", std::move(lineInfo)))); }
void Ve1Req::HandleResult() { m_errorStr.clear(); bool success = false; const HttpResult& res = GetResult(); if (res.GetSuccess()) { const std::string& str = res.GetString(); m_xml = ParseXml(str.c_str()); // For all responses, Child 0 is current server time PXml p = m_xml.getChildNode(0); if (SafeStrCmp(p.getName(), "now")) { m_timestamp = p.getText(); // TODO More checking success = true; } else { // TODO Get HTTP code m_errorStr = m_name + ": Didn't get time stamp in result: " + str; } if (m_xml.nChildNode() > 1) { p = m_xml.getChildNode(1); if (SafeStrCmp(p.getName(), "error")) { m_errorStr = p.getText(); success = false; } m_errorCode = ""; // Check for <errorcode> if (m_xml.nChildNode() > 2) { p = m_xml.getChildNode(1); if (SafeStrCmp(p.getName(), "errorcode")) { m_errorCode = p.getText(); } } } } else { //m_errorStr = res.GetErrorString(); m_errorStr = "I don't seem to be able to go online. Is your internet connection working?"; } if (success) { OnSuccess(); } else { OnFailure(); } }