Example #1
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);
            }
        }
Example #2
0
        private void UpdateNetInfo(P2PSessionState_t session)
        {
            bool endpointChanged = sessionState.m_nRemoteIP != session.m_nRemoteIP || sessionState.m_nRemotePort != session.m_nRemotePort;

            sessionState = session;

            if (endpointChanged)
            {
                // If IP/port changed for whatever reason
                ETWPingMonitor.Unregister(NetId);

                Region = "...";

                byte[] ipBytes = BitConverter.GetBytes(sessionState.m_nRemoteIP).Reverse().ToArray();
                NetId = (ulong)sessionState.m_nRemotePort << 32 | BitConverter.ToUInt32(ipBytes, 0);
                ETWPingMonitor.Register(NetId);

                if (session.m_bUsingRelay == 0)
                {
                    IpLocationAPI.GetLocationAsync(new IPAddress(ipBytes).ToString(), r => Region = r);
                }
                else
                {
                    Region = "[STEAM RELAY]";
                }
            }
        }
        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 = SteamApi.SteamFriends.GetCoplayFriendCount();

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

                P2PSessionState_t session = new P2PSessionState_t();
                if (!SteamApi.SteamNetworking.GetP2PSessionState(id, ref session) || session.m_bConnectionActive == 0)
                {
                    activePlayers.Remove(id);
                }

                else if (!activePlayers.ContainsKey(id))
                {
                    activePlayers[id] = new Player(id, session);
                }

                else
                {
                    activePlayers[id].UpdateNetInfo(session);
                }
            }
        }
Example #4
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);
        }
Example #6
0
        public static void PostFixObj(CSteamID steamIDRemote, ref P2PSessionState_t pConnectionState)
        {
            SteamPlayer pl = PlayerTool.getSteamPlayer(steamIDRemote);

            if (pl.transportConnection.TryGetIPv4Address(out uint IP))
            {
                pConnectionState.m_nRemoteIP = IP;
            }
        }
        private Player(ulong steamID, P2PSessionState_t session)
        {
            SteamID   = steamID;
            SteamName = FixedPersonaName(steamID);

            CharSlot = "";
            TeamId   = -1;
            CharName = "";

            UpdateNetInfo(session);
        }
Example #8
0
        private Player(CSteamID steamID)
        {
            SteamID   = steamID;
            SteamName = SteamFriends.GetFriendPersonaName(steamID);

            NetId        = 0;
            sessionState = new P2PSessionState_t();

            CharSlot = "";
            TeamId   = -1;
            CharName = "";
        }
Example #9
0
 public static void Dump(string tag, P2PSessionState_t s)
 {
     Debug.Log("##### " + tag + " #####");
     Debug.Log("m_bConnecting: " + s.m_bConnecting);
     Debug.Log("m_bConnectionActive: " + s.m_bConnectionActive);
     Debug.Log("m_bUsingRelay: " + s.m_bUsingRelay);
     Debug.Log("m_eP2PSessionError: " + s.m_eP2PSessionError);
     Debug.Log("m_nBytesQueuedForSend: " + s.m_nBytesQueuedForSend);
     Debug.Log("m_nPacketsQueuedForSend: " + s.m_nPacketsQueuedForSend);
     Debug.Log("m_nRemoteIP: " + s.m_nRemoteIP);
     Debug.Log("m_nRemotePort: " + s.m_nRemotePort);
 }
        private void UpdateNetInfo(P2PSessionState_t session)
        {
            if (sessionState.m_nRemoteIP == session.m_nRemoteIP)
            {
                return;
            }

            sessionState = session;
            Ip           = null;
            Region       = "...";

            if (session.m_bUsingRelay == 0)
            {
                byte[] ipBytes = BitConverter.GetBytes(sessionState.m_nRemoteIP).Reverse().ToArray();
                Ip = new IPAddress(ipBytes);
                IpLocationAPI.GetLocationAsync(Ip.ToString(), r => Region = r);
            }
        }
Example #11
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)));
            }
        }
 public static bool GetP2PSessionState(CSteamID steamIDRemote, out P2PSessionState_t pConnectionState)
 {
     InteropHelp.TestIfAvailableGameServer();
     return(NativeMethods.ISteamGameServerNetworking_GetP2PSessionState(steamIDRemote, out pConnectionState));
 }
 // bool
 public bool GetP2PSessionState(CSteamID steamIDRemote /*class CSteamID*/, ref P2PSessionState_t pConnectionState /*struct P2PSessionState_t **/)
 {
     return(platform.ISteamNetworking_GetP2PSessionState(steamIDRemote.Value, ref pConnectionState));
 }
Example #14
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);
        }
Example #15
0
 /// <summary>
 /// <para> fills out P2PSessionState_t structure with details about the underlying connection to the user</para>
 /// <para> should only needed for debugging purposes</para>
 /// <para> returns false if no connection exists to the specified user</para>
 /// </summary>
 public static bool GetP2PSessionState(CSteamID steamIDRemote, out P2PSessionState_t pConnectionState)
 {
     InteropHelp.TestIfAvailableClient();
     return(NativeMethods.ISteamNetworking_GetP2PSessionState(CSteamAPIContext.GetSteamNetworking(), steamIDRemote, out pConnectionState));
 }
Example #16
0
 private static void P2PSessionState(P2PSessionState_t param)
 {
     Debug.Log("param.m_bConnectionActive: " + param.m_bConnectionActive);
 }
Example #17
0
        internal bool GetP2PSessionState(SteamId steamIDRemote, ref P2PSessionState_t pConnectionState)
        {
            var returnValue = _GetP2PSessionState(Self, steamIDRemote, ref pConnectionState);

            return(returnValue);
        }
Example #18
0
 public abstract bool GetP2PSessionState(ulong steamIDRemote,ref P2PSessionState_t pConnectionState);
Example #19
0
 public override bool GetP2PSessionState(ulong steamIDRemote,ref P2PSessionState_t pConnectionState)
 {
     CheckIfUsable();
     bool result = NativeEntrypoints.SteamAPI_ISteamNetworking_GetP2PSessionState(m_pSteamNetworking,steamIDRemote,ref pConnectionState);
     return result;
 }
Example #20
0
 public static IPAddress GetRemoteIP(this P2PSessionState_t state)
 {
     // What is endianness anyway?
     return(new IPAddress(BitConverter.GetBytes(state.m_nRemoteIP).Reverse().ToArray()));
 }
Example #21
0
 private static extern bool _GetP2PSessionState(IntPtr self, SteamId steamIDRemote, ref P2PSessionState_t pConnectionState);