Exemplo n.º 1
0
        private void OpenSteamDebug()
        {
            var text = new StringBuilder();

            if (Multiplayer.session != null)
            {
                foreach (var remote in Multiplayer.session.knownUsers)
                {
                    text.AppendLine(SteamFriends.GetFriendPersonaName(remote));
                    text.AppendLine(remote.ToString());

                    if (SteamNetworking.GetP2PSessionState(remote, out P2PSessionState_t state))
                    {
                        text.AppendLine($"Active: {state.m_bConnectionActive}");
                        text.AppendLine($"Connecting: {state.m_bConnecting}");
                        text.AppendLine($"Error: {state.m_eP2PSessionError}");
                        text.AppendLine($"Using relay: {state.m_bUsingRelay}");
                        text.AppendLine($"Bytes to send: {state.m_nBytesQueuedForSend}");
                        text.AppendLine($"Packets to send: {state.m_nPacketsQueuedForSend}");
                        text.AppendLine($"Remote IP: {state.m_nRemoteIP}");
                        text.AppendLine($"Remote port: {state.m_nRemotePort}");
                    }
                    else
                    {
                        text.AppendLine("No connection");
                    }

                    text.AppendLine();
                }
            }

            Find.WindowStack.Add(new DebugTextWindow(text.ToString()));
        }
Exemplo n.º 2
0
 private static void P2PSessionConnectFail(P2PSessionConnectFail_t param)
 {
     Debug.LogError(string.Concat(new object[]
     {
         "P2PSessionConnectFail: error=",
         param.m_eP2PSessionError,
         ", remoteId=",
         param.m_steamIDRemote
     }));
     if (CoopLobby.Instance != null && CoopLobby.Instance.Info != null)
     {
         Debug.LogError("P2PSessionConnectFail: ServerId=" + CoopLobby.Instance.Info.ServerId);
         P2PSessionState_t s;
         if (SteamNetworking.GetP2PSessionState(CoopLobby.Instance.Info.ServerId, out s))
         {
             CoopSteamManager.Dump("Server", s);
         }
         Debug.LogError("P2PSessionConnectFail: OwnerSteamId=" + CoopLobby.Instance.Info.OwnerSteamId);
         if (SteamNetworking.GetP2PSessionState(CoopLobby.Instance.Info.OwnerSteamId, out s))
         {
             CoopSteamManager.Dump("Lobby Owner", s);
         }
     }
     else
     {
         Debug.LogError("P2PSessionConnectFail dump error: " + ((CoopLobby.Instance != null) ? "'CoopLobby.Instance.Info' is null" : "'CoopLobby.Instance' is null"));
     }
 }
Exemplo n.º 3
0
        // Token: 0x06000B45 RID: 2885 RVA: 0x003CD544 File Offset: 0x003CB744
        private void OnP2PSessionRequest(P2PSessionRequest_t result)
        {
            CSteamID steamIDRemote = result.m_steamIDRemote;

            if (this._connectionStateMap.ContainsKey(steamIDRemote) && this._connectionStateMap[steamIDRemote] != NetSocialModule.ConnectionState.Inactive)
            {
                SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
                return;
            }
            if (!this._acceptingClients)
            {
                return;
            }
            if (!this._mode.HasFlag(ServerMode.FriendsOfFriends) && SteamFriends.GetFriendRelationship(steamIDRemote) != EFriendRelationship.k_EFriendRelationshipFriend)
            {
                return;
            }
            SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
            P2PSessionState_t p2PSessionState_t;

            while (SteamNetworking.GetP2PSessionState(steamIDRemote, out p2PSessionState_t) && p2PSessionState_t.m_bConnecting == 1)
            {
            }
            if (p2PSessionState_t.m_bConnectionActive == 0)
            {
                this.Close(steamIDRemote);
            }
            this._connectionStateMap[steamIDRemote] = NetSocialModule.ConnectionState.Authenticating;
            this._connectionAcceptedCallback(new SocialSocket(new SteamAddress(steamIDRemote)));
        }
Exemplo n.º 4
0
        public static void UpdatePlayerList()
        {
            // There's probably a better way to get all current active P2P connections,
            // but I couldn't find one. The SessionInfo pointers are not reliable as
            // players can spoof their Steam ID there.
            int cnt = SteamFriends.GetCoplayFriendCount();

            for (int i = 0; i < cnt; i++)
            {
                CSteamID id = SteamFriends.GetCoplayFriend(i);

                P2PSessionState_t session = new P2PSessionState_t();
                if (!SteamNetworking.GetP2PSessionState(id, out session) || (session.m_bConnectionActive == 0 && session.m_bConnecting == 0))
                {
                    if (activePlayers.ContainsKey(id))
                    {
                        ETWPingMonitor.Unregister(activePlayers[id].NetId);
                        activePlayers.Remove(id);
                    }
                    continue;
                }
                if (!activePlayers.ContainsKey(id))
                {
                    activePlayers[id] = new Player(id);
                }

                activePlayers[id].UpdateNetInfo(session);
            }
        }
        private void OnP2PSessionRequest(P2PSessionRequest_t result)
        {
            CSteamID steamIdRemote = (CSteamID)result.m_steamIDRemote;

            if (this._connectionStateMap.ContainsKey(steamIdRemote) && this._connectionStateMap[steamIdRemote] != NetSocialModule.ConnectionState.Inactive)
            {
                SteamNetworking.AcceptP2PSessionWithUser(steamIdRemote);
            }
            else
            {
                if (!this._acceptingClients || !this._mode.HasFlag((Enum)ServerMode.FriendsOfFriends) && SteamFriends.GetFriendRelationship(steamIdRemote) != 3)
                {
                    return;
                }
                SteamNetworking.AcceptP2PSessionWithUser(steamIdRemote);
                P2PSessionState_t p2PsessionStateT;
                do
                {
                    ;
                }while (SteamNetworking.GetP2PSessionState(steamIdRemote, ref p2PsessionStateT) && p2PsessionStateT.m_bConnecting == 1);
                if (p2PsessionStateT.m_bConnectionActive == null)
                {
                    this.Close(steamIdRemote);
                }
                this._connectionStateMap[steamIdRemote] = NetSocialModule.ConnectionState.Authenticating;
                this._connectionAcceptedCallback((ISocket) new SocialSocket((RemoteAddress) new SteamAddress(steamIdRemote)));
            }
        }
Exemplo n.º 6
0
        protected P2PSessionState_t GetSessionState(CSteamID userId)
        {
            P2PSessionState_t p2PsessionStateT;

            SteamNetworking.GetP2PSessionState(userId, ref p2PsessionStateT);
            return(p2PsessionStateT);
        }
Exemplo n.º 7
0
        private void OnP2PSessionRequest(P2PSessionRequest_t result)
        {
            P2PSessionState_t p2PSessionStateT;
            CSteamID          mSteamIDRemote = result.m_steamIDRemote;

            if (this._connectionStateMap.ContainsKey(mSteamIDRemote) && this._connectionStateMap[mSteamIDRemote] != NetSocialModule.ConnectionState.Inactive)
            {
                SteamNetworking.AcceptP2PSessionWithUser(mSteamIDRemote);
                return;
            }
            if (!this._acceptingClients)
            {
                return;
            }
            SteamNetworking.AcceptP2PSessionWithUser(mSteamIDRemote);
            while (SteamNetworking.GetP2PSessionState(mSteamIDRemote, out p2PSessionStateT) && p2PSessionStateT.m_bConnecting == 1)
            {
            }
            if (p2PSessionStateT.m_bConnectionActive == 0)
            {
                this.Close(mSteamIDRemote);
            }
            this._connectionStateMap[mSteamIDRemote] = NetSocialModule.ConnectionState.Authenticating;
            this._connectionAcceptedCallback(new SocialSocket(new SteamAddress(mSteamIDRemote)));
        }
Exemplo n.º 8
0
        // Token: 0x06000B4B RID: 2891 RVA: 0x003CD7D8 File Offset: 0x003CB9D8
        protected P2PSessionState_t GetSessionState(CSteamID userId)
        {
            P2PSessionState_t result;

            SteamNetworking.GetP2PSessionState(userId, out result);
            return(result);
        }
Exemplo n.º 9
0
 public static IPAddress GetIP(this VRC.Player player)
 {
     try
     {
         P2PSessionState_t _p2pSessionState;
         if (SteamNetworking.GetP2PSessionState(new Steamworks2.CSteamID(player.GetSteamID()), out _p2pSessionState) && _p2pSessionState.m_nRemoteIP != 0u && GeneralUtils.IsNotPrivate(_p2pSessionState.m_nRemoteIP.ToIPAddress().ToString()) && _p2pSessionState.m_nRemoteIP.ToIPAddress() != null)
         {
             return(_p2pSessionState.m_nRemoteIP.ToIPAddress());
         }
         else
         {
             if (player.GetSteamID() > 10000000000000000)
             {
                 if (PEBFMFGNNNE.KBHJDGDAEGK(new Steamworks.CSteamID(player.GetSteamID()), out FGEAPNMLDBB epic))
                 {
                     return(epic.MACLMIEOBKD.ToIPAddress());
                 }
             }
             else
             {
                 ConsoleUtils.Info($"{player.GetAPIUser().displayName} is using a SteamID Spoofer. Their SteamID was {player.GetSteamID()}");
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         if (PEBFMFGNNNE.KBHJDGDAEGK(new Steamworks.CSteamID(player.GetSteamID()), out FGEAPNMLDBB epic))
         {
             return(epic.MACLMIEOBKD.ToIPAddress());
         }
         ConsoleUtils.Error($"Couldn't get {player.GetAPIUser().displayName}'s IP. Details: " + e.ToString());
         return(null);
     }
 }
Exemplo n.º 10
0
        protected P2PSessionState_t GetSessionState(CSteamID userId)
        {
            P2PSessionState_t pConnectionState;

            SteamNetworking.GetP2PSessionState(userId, out pConnectionState);
            return(pConnectionState);
        }
Exemplo n.º 11
0
        private void OnLobbyEntered(LobbyEnter_t result, bool failure)
        {
            //IL_001e: Unknown result type (might be due to invalid IL or missing references)
            //IL_002c: Unknown result type (might be due to invalid IL or missing references)
            //IL_0082: Unknown result type (might be due to invalid IL or missing references)
            //IL_0094: Unknown result type (might be due to invalid IL or missing references)
            //IL_00a4: Unknown result type (might be due to invalid IL or missing references)
            //IL_00b2: Unknown result type (might be due to invalid IL or missing references)
            //IL_00ca: Unknown result type (might be due to invalid IL or missing references)
            //IL_00db: Unknown result type (might be due to invalid IL or missing references)
            //IL_0127: Unknown result type (might be due to invalid IL or missing references)
            WeGameHelper.WriteDebugString(" OnLobbyEntered");
            SteamNetworking.AllowP2PPacketRelay(true);
            SendAuthTicket(_lobby.Owner);
            int num = 0;
            P2PSessionState_t val = default(P2PSessionState_t);

            while (SteamNetworking.GetP2PSessionState(_lobby.Owner, ref val) && val.m_bConnectionActive != 1)
            {
                switch (val.m_eP2PSessionError)
                {
                case 2:
                    ClearAuthTicket();
                    return;

                case 1:
                    ClearAuthTicket();
                    return;

                case 3:
                    ClearAuthTicket();
                    return;

                case 5:
                    ClearAuthTicket();
                    return;

                case 4:
                    if (++num > 5)
                    {
                        ClearAuthTicket();
                        return;
                    }
                    SteamNetworking.CloseP2PSessionWithUser(_lobby.Owner);
                    SendAuthTicket(_lobby.Owner);
                    break;
                }
            }
            _connectionStateMap[_lobby.Owner] = ConnectionState.Connected;
            SteamFriends.SetPlayedWith(_lobby.Owner);
            SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame"));
            Main.clrInput();
            Netplay.ServerPassword = "";
            Main.GetInputText("");
            Main.autoPass = false;
            Main.netMode  = 1;
            Netplay.OnConnectedToSocialServer(new SocialSocket(new SteamAddress(_lobby.Owner)));
        }
        protected P2PSessionState_t GetSessionState(CSteamID userId)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0009: Unknown result type (might be due to invalid IL or missing references)
            P2PSessionState_t result = default(P2PSessionState_t);

            SteamNetworking.GetP2PSessionState(userId, out result);
            return(result);
        }
        private void OnLobbyEntered(LobbyEnter_t result, bool failure)
        {
            SteamNetworking.AllowP2PPacketRelay(true);
            this.SendAuthTicket(this._lobby.Owner);
            var num = 0;
            P2PSessionState_t p2PsessionStateT;

            while (SteamNetworking.GetP2PSessionState(this._lobby.Owner, out p2PsessionStateT) &&
                   p2PsessionStateT.m_bConnectionActive != 1)
            {
                switch ((byte)p2PsessionStateT.m_eP2PSessionError)
                {
                case 1:
                    this.ClearAuthTicket();
                    return;

                case 2:
                    this.ClearAuthTicket();
                    return;

                case 3:
                    this.ClearAuthTicket();
                    return;

                case 4:
                    if (++num > 5)
                    {
                        this.ClearAuthTicket();
                        return;
                    }

                    SteamNetworking.CloseP2PSessionWithUser(this._lobby.Owner);
                    this.SendAuthTicket(this._lobby.Owner);
                    continue;

                case 5:
                    this.ClearAuthTicket();
                    return;

                default:
                    continue;
                }
            }

            this._connectionStateMap[this._lobby.Owner] = NetSocialModule.ConnectionState.Connected;
            SteamFriends.SetPlayedWith(this._lobby.Owner);
            SteamFriends.SetRichPresence("status", Language.GetTextValue("Social.StatusInGame"));
            Main.clrInput();
            Netplay.ServerPassword = "";
            Main.GetInputText("");
            Main.autoPass = false;
            Main.netMode  = 1;
            Netplay.OnConnectedToSocialServer(
                (ISocket) new SocialSocket((RemoteAddress) new SteamAddress(this._lobby.Owner)));
        }
Exemplo n.º 14
0
        public void ConnectWithSteamId(ulong friendSteamId, PlayerInformation playerInfos, string serverPassword = "")
        {
            _friendSteamId = new CSteamID(friendSteamId);
            SteamNetworking.AllowP2PPacketRelay(true);
            SendAuthTicket();
            P2PSessionState_t state;

            while (SteamNetworking.GetP2PSessionState(_friendSteamId.Value, out state) && state.m_bConnectionActive != 1)
            {
            }
            InitPlayerInfos(playerInfos, serverPassword);
        }
Exemplo n.º 15
0
        public void GetIP(ulong steamId = 0)
        {
            Context.Respond("Cannot obtain client IP.");
            return;

            if (steamId == 0)
            {
                steamId = Context.Player.SteamUserId;
            }

            SteamNetworking.GetP2PSessionState(new CSteamID(steamId), out P2PSessionState_t state);
            var ip = new IPAddress(BitConverter.GetBytes(state.m_nRemoteIP).Reverse().ToArray());

            Context.Respond($"Your IP is {ip}");
        }
Exemplo n.º 16
0
        bool UpdateConnection(CSteamID userId, NetworkConnection connection)
        {
            P2PSessionState_t state;

            if (SteamNetworking.GetP2PSessionState(userId, out state))
            {
                Debug.Log($"{userId} {state.m_bConnectionActive} {state.m_bConnecting}");
                if (state.m_bConnectionActive != 0 && state.m_bConnecting == 0)
                {
                    OnNewConnection(userId);
                }
                return(true);
            }
            return(false);
        }
        private void OnLobbyEntered(LobbyEnter_t result, bool failure)
        {
            SteamNetworking.AllowP2PPacketRelay(true);
            SendAuthTicket(_lobby.Owner);
            int num = 0;
            P2PSessionState_t pConnectionState;

            while (SteamNetworking.GetP2PSessionState(_lobby.Owner, out pConnectionState) && pConnectionState.m_bConnectionActive != 1)
            {
                switch (pConnectionState.m_eP2PSessionError)
                {
                case 2:
                    ClearAuthTicket();
                    return;

                case 1:
                    ClearAuthTicket();
                    return;

                case 3:
                    ClearAuthTicket();
                    return;

                case 5:
                    ClearAuthTicket();
                    return;

                case 4:
                    if (++num > 5)
                    {
                        ClearAuthTicket();
                        return;
                    }
                    SteamNetworking.CloseP2PSessionWithUser(_lobby.Owner);
                    SendAuthTicket(_lobby.Owner);
                    break;
                }
            }
            _connectionStateMap[_lobby.Owner] = ConnectionState.Connected;
            SteamFriends.SetPlayedWith(_lobby.Owner);
            SteamFriends.SetRichPresence("status", "Playing online.");
            Main.clrInput();
            Netplay.ServerPassword = "";
            Main.GetInputText("");
            Main.autoPass = false;
            Main.netMode  = 1;
            Netplay.OnConnectedToSocialServer(new SocialSocket(new SteamAddress(_lobby.Owner)));
        }
Exemplo n.º 18
0
        private string NetInfoText()
        {
            if (Multiplayer.session == null)
            {
                return("");
            }

            var text = new StringBuilder();

            var netClient = Multiplayer.session.netClient;

            if (netClient != null)
            {
                text.AppendLine($"Bytes received: {netClient.Statistics.BytesReceived}");
                text.AppendLine($"Bytes sent: {netClient.Statistics.BytesSent}");
                text.AppendLine($"Packets received: {netClient.Statistics.PacketsReceived}");
                text.AppendLine($"Packets sent: {netClient.Statistics.PacketsSent}");
                text.AppendLine($"Packet loss percent: {netClient.Statistics.PacketLossPercent}");
                text.AppendLine();
            }

            foreach (var remote in Multiplayer.session.knownUsers)
            {
                text.AppendLine(SteamFriends.GetFriendPersonaName(remote));
                text.AppendLine(remote.ToString());

                if (SteamNetworking.GetP2PSessionState(remote, out P2PSessionState_t state))
                {
                    text.AppendLine($"Active: {state.m_bConnectionActive}");
                    text.AppendLine($"Connecting: {state.m_bConnecting}");
                    text.AppendLine($"Error: {state.m_eP2PSessionError}");
                    text.AppendLine($"Using relay: {state.m_bUsingRelay}");
                    text.AppendLine($"Bytes to send: {state.m_nBytesQueuedForSend}");
                    text.AppendLine($"Packets to send: {state.m_nPacketsQueuedForSend}");
                    text.AppendLine($"Remote IP: {state.m_nRemoteIP}");
                    text.AppendLine($"Remote port: {state.m_nRemotePort}");
                }
                else
                {
                    text.AppendLine("No connection");
                }

                text.AppendLine();
            }

            return(text.ToString());
        }
Exemplo n.º 19
0
 // Token: 0x060009A6 RID: 2470 RVA: 0x000467D8 File Offset: 0x000449D8
 public void Close()
 {
     ZLog.Log("Closing socket " + this.GetEndPointString());
     if (this.m_peerID != CSteamID.Nil)
     {
         this.Flush();
         ZLog.Log("  send queue size:" + this.m_sendQueue.Count);
         Thread.Sleep(100);
         P2PSessionState_t p2PSessionState_t;
         SteamNetworking.GetP2PSessionState(this.m_peerID, out p2PSessionState_t);
         ZLog.Log("  P2P state, bytes in send queue:" + p2PSessionState_t.m_nBytesQueuedForSend);
         SteamNetworking.CloseP2PSessionWithUser(this.m_peerID);
         SteamUser.EndAuthSession(this.m_peerID);
         this.m_peerID = CSteamID.Nil;
     }
     this.m_listner = false;
 }
Exemplo n.º 20
0
 public override void FlushSendQueue(ulong clientId)
 {
     if (clientId == ServerClientId && !isServer)
     {
         if (serverUser != null)
         {
             if (SteamNetworking.GetP2PSessionState(serverUser.SteamId, out P2PSessionState_t sessionState))
             {
                 if (sessionState.m_nPacketsQueuedForSend > 0)
                 {
                     for (int i = (int)InternalChannelType.InternalChannelsCount; i < UserChannels.Count; i++)
                     {
                         SteamNetworking.SendP2PPacket(serverUser.SteamId, new byte[0], 0, EP2PSend.k_EP2PSendReliable, i);
                     }
                 }
             }
         }
     }
     else if (clientId != ServerClientId && isServer)
     {
         if (connectedUsers.ContainsKey(clientId))
         {
             CSteamID clientSteamId = connectedUsers[clientId].SteamId;
             if (SteamNetworking.GetP2PSessionState(clientSteamId, out P2PSessionState_t sessionState))
             {
                 if (sessionState.m_nPacketsQueuedForSend > 0)
                 {
                     for (int i = (int)InternalChannelType.InternalChannelsCount; i < UserChannels.Count; i++)
                     {
                         SteamNetworking.SendP2PPacket(clientSteamId, new byte[0], 0, EP2PSend.k_EP2PSendReliable, i);
                     }
                 }
             }
         }
         else
         {
             if (LogHelper.CurrentLogLevel <= LogLevel.Error)
             {
                 LogHelper.LogError("SteamP2PTransport - Can't FlushSendQueue to client, client not connected, clientId: " + clientId);
             }
         }
     }
 }
Exemplo n.º 21
0
    IEnumerator RequestP2PConnectionWithHost()
    {
        var hostUserId = SteamMatchmaking.GetLobbyOwner(steamLobbyId);

        //send packet to request connection to host via Steam's NAT punch or relay servers
        Debug.Log("Sending packet to request P2P connection");
        SteamNetworking.SendP2PPacket(hostUserId, null, 0, EP2PSend.k_EP2PSendReliable);

        Debug.Log("Waiting for P2P acceptance message");
        uint packetSize;

        while (!SteamNetworking.IsP2PPacketAvailable(out packetSize))
        {
            yield return(null);
        }

        byte[] data = new byte[packetSize];

        CSteamID senderId;

        if (SteamNetworking.ReadP2PPacket(data, packetSize, out packetSize, out senderId))
        {
            if (senderId.m_SteamID == hostUserId.m_SteamID)
            {
                Debug.Log("P2P connection established");

                // packet was from host, assume it's notifying client that AcceptP2PSessionWithUser was called
                P2PSessionState_t sessionState;
                if (SteamNetworking.GetP2PSessionState(hostUserId, out sessionState))
                {
                    // connect to the unet server
                    ConnectToUnetServerForSteam(hostUserId);

                    yield break;
                }
            }
        }

        Debug.LogError("Connection failed");
    }
Exemplo n.º 22
0
        public override bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
        {
            EP2PSend eP2PSendType = EP2PSend.k_EP2PSendReliable;

            var hostTopology = NetworkServer.active ? NetworkServer.hostTopology : NetworkManager.singleton.client.hostTopology;

            QosType qos = hostTopology.DefaultConfig.Channels[channelId].QOS;

            if (qos == QosType.Unreliable || qos == QosType.UnreliableFragmented || qos == QosType.UnreliableSequenced)
            {
                eP2PSendType = EP2PSend.k_EP2PSendUnreliableNoDelay;
            }

            if (SteamNetworking.SendP2PPacket(remoteSteamId, bytes, (uint)numBytes, eP2PSendType))
            {
                error = (byte)NetworkError.Ok;
                return(true);
            }
            else
            {
                P2PSessionState_t state;
                if (SteamNetworking.GetP2PSessionState(remoteSteamId, out state))
                {
                    if (state.m_eP2PSessionError == (byte)EP2PSessionError.k_EP2PSessionErrorTimeout)
                    {
                        error = (byte)NetworkError.Timeout;
                    }
                    else
                    {
                        error = (byte)NetworkError.WrongHost;
                    }
                }
                else
                {
                    error = (byte)NetworkError.WrongConnection;
                }

                return(false);
            }
        }
Exemplo n.º 23
0
        private void OnP2PSessionRequest(P2PSessionRequest_t result)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0001: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Unknown result type (might be due to invalid IL or missing references)
            //IL_000d: Unknown result type (might be due to invalid IL or missing references)
            //IL_001b: Unknown result type (might be due to invalid IL or missing references)
            //IL_0023: Unknown result type (might be due to invalid IL or missing references)
            //IL_004c: Unknown result type (might be due to invalid IL or missing references)
            //IL_004d: Unknown result type (might be due to invalid IL or missing references)
            //IL_0053: Invalid comparison between Unknown and I4
            //IL_0056: Unknown result type (might be due to invalid IL or missing references)
            //IL_005d: Unknown result type (might be due to invalid IL or missing references)
            //IL_0067: Unknown result type (might be due to invalid IL or missing references)
            //IL_0070: Unknown result type (might be due to invalid IL or missing references)
            //IL_0079: Unknown result type (might be due to invalid IL or missing references)
            //IL_0085: Unknown result type (might be due to invalid IL or missing references)
            //IL_0092: Unknown result type (might be due to invalid IL or missing references)
            CSteamID steamIDRemote = result.m_steamIDRemote;

            if (_connectionStateMap.ContainsKey(steamIDRemote) && _connectionStateMap[steamIDRemote] != 0)
            {
                SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
            }
            else if (_acceptingClients && (_mode.HasFlag(ServerMode.FriendsOfFriends) || (int)SteamFriends.GetFriendRelationship(steamIDRemote) == 3))
            {
                SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
                P2PSessionState_t val = default(P2PSessionState_t);
                while (SteamNetworking.GetP2PSessionState(steamIDRemote, ref val) && val.m_bConnecting == 1)
                {
                }
                if (val.m_bConnectionActive == 0)
                {
                    Close(steamIDRemote);
                }
                _connectionStateMap[steamIDRemote] = ConnectionState.Authenticating;
                _connectionAcceptedCallback(new SocialSocket(new SteamAddress(steamIDRemote)));
            }
        }
        private void OnP2PSessionRequest(P2PSessionRequest_t result)
        {
            CSteamID steamIDRemote = result.m_steamIDRemote;

            if (_connectionStateMap.ContainsKey(steamIDRemote) && _connectionStateMap[steamIDRemote] != 0)
            {
                SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
            }
            else if (_acceptingClients && (_mode.HasFlag(ServerMode.FriendsOfFriends) || SteamFriends.GetFriendRelationship(steamIDRemote) == EFriendRelationship.k_EFriendRelationshipFriend))
            {
                SteamNetworking.AcceptP2PSessionWithUser(steamIDRemote);
                P2PSessionState_t pConnectionState;
                while (SteamNetworking.GetP2PSessionState(steamIDRemote, out pConnectionState) && pConnectionState.m_bConnecting == 1)
                {
                }
                if (pConnectionState.m_bConnectionActive == 0)
                {
                    Close(steamIDRemote);
                }
                _connectionStateMap[steamIDRemote] = ConnectionState.Authenticating;
                _connectionAcceptedCallback(new SocialSocket(new SteamAddress(steamIDRemote)));
            }
        }
Exemplo n.º 25
0
        private void OnLobbyEntered(LobbyEnter_t result, bool failure)
        {
            P2PSessionState_t p2PSessionStateT;

            SteamNetworking.AllowP2PPacketRelay(true);
            this.SendAuthTicket(this._lobby.Owner);
            int num = 0;

            while (SteamNetworking.GetP2PSessionState(this._lobby.Owner, out p2PSessionStateT) && p2PSessionStateT.m_bConnectionActive != 1)
            {
                switch (p2PSessionStateT.m_eP2PSessionError)
                {
                case 1:
                {
                    this.ClearAuthTicket();
                    return;
                }

                case 2:
                {
                    this.ClearAuthTicket();
                    return;
                }

                case 3:
                {
                    this.ClearAuthTicket();
                    return;
                }

                case 4:
                {
                    int num1 = num + 1;
                    num = num1;
                    if (num1 > 5)
                    {
                        this.ClearAuthTicket();
                        return;
                    }
                    SteamNetworking.CloseP2PSessionWithUser(this._lobby.Owner);
                    this.SendAuthTicket(this._lobby.Owner);
                    continue;
                }

                case 5:
                {
                    this.ClearAuthTicket();
                    return;
                }

                default:
                {
                    continue;
                }
                }
            }
            this._connectionStateMap[this._lobby.Owner] = NetSocialModule.ConnectionState.Connected;
            SteamFriends.SetPlayedWith(this._lobby.Owner);
            SteamFriends.SetRichPresence("status", "Playing online.");
            Main.netMode = 1;
            Netplay.OnConnectedToSocialServer(new SocialSocket(new SteamAddress(this._lobby.Owner)));
        }
Exemplo n.º 26
0
        private IEnumerator DumpPlayer(Player player)
        {
            var    now        = DateTime.Now;
            string timeFormat = $"{now.Year}_{now.Month}_{now.Day}_{now.Hour}_{now.Minute}_{now.Second}";

            void AppendToOutput(string prefix, string value, int indent = 2)
            {
                string output = "";

                for (int i = 0; i < indent; i++)
                {
                    output += "\t";
                }

                if (prefix == "")
                {
                    output += value;
                }
                else
                {
                    output += $"{prefix}: {value}";
                }

                output += "\n";

                m_fileSystem.SaveText($"{timeFormat} {player.ApiUser().displayName}.txt", output, true);
            }

            AppendToOutput("", "[[", 0);

            AppendToOutput("", "USER", 1);
            AppendToOutput("Display Name", player.ApiUser().displayName);
            AppendToOutput("Login Name", player.ApiUser().username);
            AppendToOutput("Id", player.ApiUser().id);
            AppendToOutput("SteamId", player.vrcPlayer.SteamUserIdULong().ToString());
            AppendToOutput("Status", player.ApiUser().statusDescription);

            if (player.vrcPlayer.SteamUserIdULong() != 0UL)
            {
                CSteamID id = new CSteamID(player.vrcPlayer.SteamUserIdULong());

                MemoryStream ms     = new MemoryStream();
                BinaryWriter writer = new BinaryWriter(ms);

                int version = VRCApplicationSetupWrappers.Instance.GetGameServerVersion().GetHashCode();
                writer.Write(version);
                writer.Write(0);

                byte[] data = ms.ToArray();

                writer.Close();
                ms.Close();

                SteamNetworking.SendP2PPacket(id, data, (uint)data.Length, EP2PSend.k_EP2PSendUnreliable);

                P2PSessionState_t state = default(P2PSessionState_t);

                if (SteamNetworking.GetP2PSessionState(id, out state))
                {
                    Log.Debug("Waiting for connection to be established...");

                    while (state.m_bConnecting == 1)
                    {
                        Log.Debug($"state: m_bConnecting: {state.m_bConnecting}, m_bConnectionActive: {state.m_bConnectionActive}, m_eP2PSessionError: {state.m_eP2PSessionError}");
                        Log.Debug($"m_bUsingRelay: {state.m_bUsingRelay}, m_nBytesQueuedForSend: {state.m_nBytesQueuedForSend}, m_nPacketsQueuedForSend: {state.m_nPacketsQueuedForSend}");
                        Log.Debug($"m_nRemoteIP: {state.m_nRemoteIP}, m_nRemotePort: {state.m_nRemotePort}");

                        yield return(new WaitForSeconds(1f));
                    }

                    Log.Debug("Connection established, retreiving ip!");

                    string IpToStr(uint ip)
                    {
                        return(new IPAddress(new byte[]
                        {
                            (byte)(ip >> 24 & 255u),
                            (byte)(ip >> 16 & 255u),
                            (byte)(ip >> 8 & 255u),
                            (byte)(ip & 255u)
                        }).ToString());
                    }

                    string relay = (state.m_bUsingRelay == 1) ? "(STEAM RELAY)" : "";

                    AppendToOutput($"IP {relay}", IpToStr(state.m_nRemoteIP));
                }
            }

            ApiAvatar avatar = player.vrcPlayer.ApiAvatar();

            AppendToOutput("", "AVATAR", 1);
            AppendToOutput("Name", avatar.name);
            AppendToOutput("Author", avatar.authorName);
            AppendToOutput("Status", avatar.releaseStatus);
            AppendToOutput("VRCA", avatar.assetUrl);

            AppendToOutput("", "]]", 0);
        }
Exemplo n.º 27
0
    void Update()
    {
        if (!SteamManager.Initialized)
        {
            return;
        }

        if (!IsConnectedToUNETServer())
        {
            return;
        }

        uint packetSize;
        int  channels = GetChannelCount();

        // Read Steam packets
        for (int chan = 0; chan < channels; chan++)
        {
            while (SteamNetworking.IsP2PPacketAvailable(out packetSize, chan))
            {
                byte[] data = new byte[packetSize];

                CSteamID senderId;

                if (SteamNetworking.ReadP2PPacket(data, packetSize, out packetSize, out senderId, chan))
                {
                    NetworkConnection conn;

                    if (UNETServerController.IsHostingServer())
                    {
                        // We are the server, one of our clients will handle this packet
                        conn = UNETServerController.GetClient(senderId);

                        if (conn == null)
                        {
                            // In some cases the p2p connection can persist, resulting in UNETServerController.OnP2PSessionRequested not being called. This happens usually when testing in editor.
                            // If the peers have already established a connection, reset it.
                            P2PSessionState_t sessionState;
                            if (SteamNetworking.GetP2PSessionState(senderId, out sessionState) && Convert.ToBoolean(sessionState.m_bConnectionActive))
                            {
                                Debug.Log("P2P connection is still established. Resetting.");
                                SteamNetworking.CloseP2PSessionWithUser(senderId);
                                UNETServerController.CreateP2PConnectionWithPeer(senderId);
                                conn = UNETServerController.GetClient(senderId);
                            }
                        }
                    }
                    else
                    {
                        // We are a client, we only have one connection (the server).
                        conn = myClient.connection;
                    }

                    if (conn != null)
                    {
                        // Handle Steam packet through UNET
                        conn.TransportReceive(data, Convert.ToInt32(packetSize), chan);
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Disconnect();
        }
    }
Exemplo n.º 28
0
        private string NetInfoText()
        {
            if (Multiplayer.session == null)
            {
                return("");
            }

            var text = new StringBuilder();

            var netClient = Multiplayer.session.netClient;

            if (netClient != null)
            {
                LogNetData("Client", netClient.Statistics);
            }
            if (Multiplayer.LocalServer != null)
            {
                if (Multiplayer.LocalServer.lanManager != null)
                {
                    LogNetData("Lan Server", Multiplayer.LocalServer.lanManager.Statistics);
                }
                if (Multiplayer.LocalServer.netManager != null)
                {
                    LogNetData("Net Server", Multiplayer.LocalServer.netManager.Statistics);
                }
                foreach (ServerPlayer item in Enumerable.ToList(Multiplayer.LocalServer.players))
                {
                    MpNetConnection mpNetConnection = item.conn as MpNetConnection;
                    if (mpNetConnection != null)
                    {
                        LogNetData("Net Peer " + item.Username, mpNetConnection.peer.Statistics);
                    }
                }
            }

            foreach (var remote in Multiplayer.session.knownUsers)
            {
                text.AppendLine(SteamFriends.GetFriendPersonaName(remote));
                text.AppendLine(remote.ToString());

                if (SteamNetworking.GetP2PSessionState(remote, out P2PSessionState_t state))
                {
                    text.AppendLine($"Active: {state.m_bConnectionActive}");
                    text.AppendLine($"Connecting: {state.m_bConnecting}");
                    text.AppendLine($"Error: {state.m_eP2PSessionError}");
                    text.AppendLine($"Using relay: {state.m_bUsingRelay}");
                    text.AppendLine($"Bytes to send: {state.m_nBytesQueuedForSend}");
                    text.AppendLine($"Packets to send: {state.m_nPacketsQueuedForSend}");
                    text.AppendLine($"Remote IP: {state.m_nRemoteIP}");
                    text.AppendLine($"Remote port: {state.m_nRemotePort}");
                }
                else
                {
                    text.AppendLine("No connection");
                }

                text.AppendLine();
            }

            return(text.ToString());

            void LogNetData(string name, NetStatistics stats)
            {
                text.AppendLine(name);
                text.AppendLine($"Bytes received: {stats.BytesReceived}");
                text.AppendLine($"Bytes sent: {stats.BytesSent}");
                text.AppendLine($"Packets received: {stats.PacketsReceived}");
                text.AppendLine($"Packets sent: {stats.PacketsSent}");
                text.AppendLine($"Packet loss: {stats.PacketLoss}");
                text.AppendLine($"Sequenced packet loss: {stats.SequencedPacketLoss}");
                text.AppendLine($"Packet loss percent: {stats.PacketLossPercent}");
                text.AppendLine();
            }
        }
Exemplo n.º 29
0
    public void RenderOnGUI()
    {
        GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
        GUILayout.Label("Variables:");
        GUILayout.Label("m_RemoteSteamId: " + m_RemoteSteamId);
        GUILayout.EndArea();

        if (!m_RemoteSteamId.IsValid())
        {
            GUILayout.Label("Please fill m_RemoteSteamId with a valid 64bit SteamId to use SteamNetworkingTest.");
            GUILayout.Label("Alternatively it will be filled automatically when a session request is recieved.");
            return;
        }

        // Session-less connection functions

        if (GUILayout.Button("SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable)"))
        {
            byte[] bytes = new byte[4];
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes))
                using (System.IO.BinaryWriter b = new System.IO.BinaryWriter(ms)) {
                    b.Write((uint)MsgType.Ping);
                }
            bool ret = SteamNetworking.SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable);
            print("SteamNetworking.SendP2PPacket(" + m_RemoteSteamId + ", bytes, " + bytes.Length + ", EP2PSend.k_EP2PSendReliable) - " + ret);
        }

        {
            uint MsgSize;
            bool ret = SteamNetworking.IsP2PPacketAvailable(out MsgSize);
            GUILayout.Label("IsP2PPacketAvailable(out MsgSize) : " + ret + " -- " + MsgSize);

            GUI.enabled = ret;

            if (GUILayout.Button("ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote)"))
            {
                byte[]   bytes = new byte[MsgSize];
                uint     newMsgSize;
                CSteamID SteamIdRemote;
                ret = SteamNetworking.ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote);

                using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes))
                    using (System.IO.BinaryReader b = new System.IO.BinaryReader(ms)) {
                        MsgType msgtype = (MsgType)b.ReadUInt32();
                        // switch statement here depending on the msgtype
                        print("SteamNetworking.ReadP2PPacket(bytes, " + MsgSize + ", out newMsgSize, out SteamIdRemote) - " + ret + " -- " + newMsgSize + " -- " + SteamIdRemote + " -- " + msgtype);
                    }
            }

            GUI.enabled = true;
        }

        // bool AcceptP2PSessionWithUser(CSteamID steamIDRemote) // Only called from within P2PSessionRequest Callback!

        if (GUILayout.Button("CloseP2PSessionWithUser(m_RemoteSteamId)"))
        {
            bool ret = SteamNetworking.CloseP2PSessionWithUser(m_RemoteSteamId);
            print("SteamNetworking.CloseP2PSessionWithUser(" + m_RemoteSteamId + ") - " + ret);
        }

        if (GUILayout.Button("CloseP2PChannelWithUser(m_RemoteSteamId, 0)"))
        {
            bool ret = SteamNetworking.CloseP2PChannelWithUser(m_RemoteSteamId, 0);
            print("SteamNetworking.CloseP2PChannelWithUser(" + m_RemoteSteamId + ", 0) - " + ret);
        }

        {
            P2PSessionState_t ConnectionState;
            bool ret = SteamNetworking.GetP2PSessionState(m_RemoteSteamId, out ConnectionState);
            GUILayout.Label("GetP2PSessionState(m_RemoteSteamId, out ConnectionState) : " + ret + " -- " + ConnectionState.m_bConnectionActive + " -- " + ConnectionState.m_bConnecting + " -- " + ConnectionState.m_eP2PSessionError + " -- " + ConnectionState.m_bUsingRelay + " -- " + ConnectionState.m_nBytesQueuedForSend + " -- " + ConnectionState.m_nPacketsQueuedForSend + " -- " + ConnectionState.m_nRemoteIP + " -- " + ConnectionState.m_nRemotePort);
        }

        if (GUILayout.Button("AllowP2PPacketRelay(true)"))
        {
            bool ret = SteamNetworking.AllowP2PPacketRelay(true);
            print("SteamNetworking.AllowP2PPacketRelay(true) - " + ret);
        }

        // LISTEN / CONNECT style interface functions
    }
    public void RenderOnGUI()
    {
        GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
        GUILayout.Label("Variables:");
        GUILayout.Label("m_RemoteSteamId: " + m_RemoteSteamId);
        GUILayout.EndArea();

        GUILayout.BeginVertical("box");
        m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, GUILayout.Width(Screen.width - 215), GUILayout.Height(Screen.height - 33));

        if (!m_RemoteSteamId.IsValid())
        {
            GUILayout.Label("Please fill m_RemoteSteamId with a valid 64bit SteamId to use SteamNetworkingTest.");
            GUILayout.Label("Alternatively it will be filled automatically when a session request is recieved.");
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            return;
        }

        // Session-less connection functions
        if (GUILayout.Button("SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable)"))
        {
            byte[] bytes = new byte[4];
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes))
                using (System.IO.BinaryWriter b = new System.IO.BinaryWriter(ms)) {
                    b.Write((uint)MsgType.Ping);
                }
            bool ret = SteamNetworking.SendP2PPacket(m_RemoteSteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable);
            print("SteamNetworking.SendP2PPacket(" + m_RemoteSteamId + ", " + bytes + ", " + (uint)bytes.Length + ", " + EP2PSend.k_EP2PSendReliable + ") : " + ret);
        }

        {
            uint MsgSize;
            bool ret = SteamNetworking.IsP2PPacketAvailable(out MsgSize);
            GUILayout.Label("IsP2PPacketAvailable(out MsgSize) : " + ret + " -- " + MsgSize);

            GUI.enabled = ret;

            if (GUILayout.Button("ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote)"))
            {
                byte[]   bytes = new byte[MsgSize];
                uint     newMsgSize;
                CSteamID SteamIdRemote;
                ret = SteamNetworking.ReadP2PPacket(bytes, MsgSize, out newMsgSize, out SteamIdRemote);

                using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes))
                    using (System.IO.BinaryReader b = new System.IO.BinaryReader(ms)) {
                        MsgType msgtype = (MsgType)b.ReadUInt32();
                        // switch statement here depending on the msgtype
                        print("SteamNetworking.ReadP2PPacket(bytes, " + MsgSize + ", out newMsgSize, out SteamIdRemote) - " + ret + " -- " + newMsgSize + " -- " + SteamIdRemote + " -- " + msgtype);
                    }
            }

            GUI.enabled = true;
        }

        //SteamNetworking.AcceptP2PSessionWithUser() // Only called from within P2PSessionRequest Callback!

        if (GUILayout.Button("CloseP2PSessionWithUser(m_RemoteSteamId)"))
        {
            bool ret = SteamNetworking.CloseP2PSessionWithUser(m_RemoteSteamId);
            print("SteamNetworking.CloseP2PSessionWithUser(" + m_RemoteSteamId + ") : " + ret);
        }

        if (GUILayout.Button("CloseP2PChannelWithUser(m_RemoteSteamId, 0)"))
        {
            bool ret = SteamNetworking.CloseP2PChannelWithUser(m_RemoteSteamId, 0);
            print("SteamNetworking.CloseP2PChannelWithUser(" + m_RemoteSteamId + ", " + 0 + ") : " + ret);
        }

        {
            P2PSessionState_t ConnectionState;
            bool ret = SteamNetworking.GetP2PSessionState(m_RemoteSteamId, out ConnectionState);
            GUILayout.Label("GetP2PSessionState(m_RemoteSteamId, out ConnectionState) : " + ret + " -- " + ConnectionState);
        }

        if (GUILayout.Button("AllowP2PPacketRelay(true)"))
        {
            bool ret = SteamNetworking.AllowP2PPacketRelay(true);
            print("SteamNetworking.AllowP2PPacketRelay(" + true + ") : " + ret);
        }

        // LISTEN / CONNECT style interface functions
        //SteamNetworking.CreateListenSocket() // TODO

        //SteamNetworking.CreateP2PConnectionSocket() // TODO

        //SteamNetworking.CreateConnectionSocket() // TODO

        //SteamNetworking.DestroySocket() // TODO

        //SteamNetworking.DestroyListenSocket() // TODO

        //SteamNetworking.SendDataOnSocket() // TODO

        //SteamNetworking.IsDataAvailableOnSocket() // TODO

        //SteamNetworking.RetrieveDataFromSocket() // TODO

        //SteamNetworking.IsDataAvailable() // TODO

        //SteamNetworking.RetrieveData() // TODO

        //SteamNetworking.GetSocketInfo() // TODO

        //SteamNetworking.GetListenSocketInfo() // TODO

        //SteamNetworking.GetSocketConnectionType() // TODO

        //SteamNetworking.GetMaxPacketSize() // TODO

        GUILayout.EndScrollView();
        GUILayout.EndVertical();
    }