internal P2PSessionState(P2PSessionState_t s)
 {
     this.ConnectionActive     = s.ConnectionActive;
     this.Connecting           = s.Connecting;
     this.P2PSessionError      = (P2PSessionError)s.P2PSessionError;
     this.UsingRelay           = s.UsingRelay;
     this.BytesQueuedForSend   = s.BytesQueuedForSend;
     this.PacketsQueuedForSend = s.PacketsQueuedForSend;
     this.RemoteIP             = s.RemoteIP;
     this.RemotePort           = s.RemotePort;
 }
        private void OnP2PConnectionFailed(SteamId id, P2PSessionError error)
        {
            if (error == P2PSessionError.NoRightsToApp)
            {
                MelonModLogger.LogError("You don't own the game on Steam.");
            }
            else if (error == P2PSessionError.NotRunningApp)
            {
                // Probably a leaver
                if (smallPlayerIds.ContainsKey(id))
                {
                    MelonModLogger.Log("Player left with SteamID: " + id);
                    byte smallId = smallPlayerIds[id];

                    P2PMessage disconnectMsg = new P2PMessage();
                    disconnectMsg.WriteByte((byte)MessageType.Disconnect);
                    disconnectMsg.WriteByte(smallId);

                    foreach (SteamId p in players)
                    {
                        SteamNetworking.SendP2PPacket(p, disconnectMsg.GetBytes(), -1, 0, P2PSend.Reliable);
                    }

                    playerObjects[smallId].Destroy();
                    playerObjects.Remove(smallId);
                    players.RemoveAll((ulong val) => val == id);
                    smallPlayerIds.Remove(id);
                }
            }
            else if (error == P2PSessionError.Timeout)
            {
                MelonModLogger.LogError("Connection with " + id + "timed out.");

                byte smallId = smallPlayerIds[id];

                P2PMessage disconnectMsg = new P2PMessage();
                disconnectMsg.WriteByte((byte)MessageType.Disconnect);
                disconnectMsg.WriteByte(smallId);

                foreach (SteamId p in players)
                {
                    SteamNetworking.SendP2PPacket(p, disconnectMsg.GetBytes(), -1, 0, P2PSend.Reliable);
                }

                playerObjects[smallId].Destroy();
                playerObjects.Remove(smallId);
                players.RemoveAll((ulong val) => val == id);
                smallPlayerIds.Remove(id);
            }
            else
            {
                MelonModLogger.LogError("Unhandled P2P error: " + error.ToString());
            }
        }
Beispiel #3
0
 private void OnP2PConnectionFailed(SteamId id, P2PSessionError err)
 {
     if (id == ServerId)
     {
         MelonModLogger.LogError("Got P2P connection error " + err.ToString());
         foreach (PlayerRep pr in playerObjects.Values)
         {
             pr.Destroy();
         }
     }
 }
        private ConnectionClosedReason GetConnectionClosedReason(P2PSessionError error)
        {
            switch (error)
            {
            case P2PSessionError.NoRightsToApp:
            case P2PSessionError.DestinationNotLoggedIn:
                return(ConnectionClosedReason.Other);

            case P2PSessionError.NotRunningApp:
                return(ConnectionClosedReason.ClosedByRemote);

            case P2PSessionError.Timeout:
                return(ConnectionClosedReason.Timeout);

            default:
                return(ConnectionClosedReason.Other);
            }
        }
Beispiel #5
0
        private void OnConnectFail(SteamId id, P2PSessionError err)
        {
            switch (err)
            {
            case P2PSessionError.NotRunningApp:
                throw new Exception("Connection failed: The target user is not running the same game.");

            case P2PSessionError.NoRightsToApp:
                throw new Exception("Connection failed: The local user doesn't own the app that is running.");

            case P2PSessionError.DestinationNotLoggedIn:
                throw new Exception("Connection failed: Target user isn't connected to Steam.");

            case P2PSessionError.Timeout:
                throw new Exception("Connection failed: The connection timed out because the target user didn't respond.");

            default:
                throw new Exception("Connection failed: Unknown error.");
            }
        }
        protected override void HandleConnectionFailed(SteamId id, P2PSessionError error)
        {
            try
            {
                if (!id.IsValid)
                {
                    throw new Exception("An invalid SteamId is reporting connection failure");
                }

                if (!PlayerRegistry.Contains(id))
                {
                    throw new Exception("Received connection failure message from a peer that isn't in the player registry");
                }

                int conn = PlayerRegistry.GetConnId(id);

                // If no connection id could be found for that SteamId
                if (conn == -1)
                {
                    throw new Exception($"Invalid connection id for SteamId {id}, can't disconnect");
                }

                string info = P2PErrorToString(error);

                Exception ex = new Exception($"Connection failed with host {id} ({info})");
                Output.LogError(ex.Message);

                PlayerRegistry.Remove(id);
                CloseSessionWithUser(id);

                // Raise OnError event
                OnError?.Invoke(conn, ex);
            }
            catch (Exception e)
            {
                Output.LogWarning($"{Name}: Exception in Server.HandleConnectionFailed ({e.Message})");
                return;
            }
        }
        /// <summary>
        /// Convert a P2PSessionError to a string
        /// </summary>
        public static string P2PErrorToString(P2PSessionError e)
        {
            string error;

            switch (e)
            {
            case P2PSessionError.None:
                error = "None";
                break;

            case P2PSessionError.NotRunningApp:
                error = "Not running app";
                break;

            case P2PSessionError.NoRightsToApp:
                error = "No rights to app";
                break;

            case P2PSessionError.DestinationNotLoggedIn:
                error = "Destination not logged in";
                break;

            case P2PSessionError.Timeout:
                error = "Timeout";
                break;

            case P2PSessionError.Max:
                error = "Max";
                break;

            default:
                error = "Unknown error";
                break;
            }

            return(error);
        }
Beispiel #8
0
        protected override void HandleConnectionFailed(SteamId id, P2PSessionError error)
        {
            try
            {
                if (!id.IsValid)
                {
                    throw new Exception("An invalid SteamId is reporting connection failure");
                }

                if (!HostId.IsValid)
                {
                    throw new Exception($"Connection failed with {id}, but we didn't have a host anyway...");
                }

                if (id != HostId)
                {
                    throw new Exception($"Connection failed with {id}, but they weren't our host");
                }

                string info = P2PErrorToString(error);

                Exception ex = new Exception($"Connection failed with host {id} ({info})");
                Output.LogError(ex.Message);

                _host = new SteamId();
                CloseSessionWithUser(id);
                ResetStatus();

                // Raise OnError event
                OnError?.Invoke(ex);
            }
            catch (Exception e)
            {
                Output.LogWarning($"{Name}: Exception in Client.HandleConnectionFailed ({e.Message})");
                return;
            }
        }
 private void ListenOnP2PConnectionFailed(SteamId id, P2PSessionError error)
 {
     OnConnectionClosed(connections[id], GetConnectionClosedReason(error));
     connections.Remove(id);
 }
Beispiel #10
0
 void OnP2PSessionConnectFail(SteamId id, P2PSessionError error)
 {
     // TODO(james7132): Implement Properly
     Debug.LogError($"[Steam] Failed to connect to remote user {id}: {error}");
 }
 protected abstract void HandleConnectionFailed(SteamId id, P2PSessionError error);
 /// <summary>
 /// Called from SteamNetworking callback
 /// </summary>
 public void OnConnectionFailed(SteamId id, P2PSessionError error)
 {
     HandleConnectionFailed(id, error);
 }
Beispiel #13
0
 protected virtual void OnConnectFail(SteamId id, P2PSessionError error)
 {
     Debug.Log("OnConnectFail " + id + " " + error);
     throw new Exception("Failed to connect");
 }
Beispiel #14
0
 private void OnP2PSessionConnectFail(SteamId connectionAttemptFailedClientId, P2PSessionError request)
 {
     if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
     {
         NetworkLog.LogInfo("SteamP2PTransport - OnP2PSessionConnectFail - m_steamIDRemote: " + connectionAttemptFailedClientId + " Error: " + request.ToString());
     }
     connectionAttemptFailed = true;
     this.connectionAttemptFailedClientId = connectionAttemptFailedClientId;
 }
Beispiel #15
0
 private void ClientOnP2PSessionConnectFail(SteamId connectionAttemptFailedClientId, P2PSessionError request, SocketTask task)
 {
     OnP2PSessionConnectFail(connectionAttemptFailedClientId, request);
     task.IsDone        = true;
     task.Success       = false;
     task.TransportCode = (int)request;
 }