示例#1
0
    public static void Ban(Steamworks.SteamId id)
    {
        ServerData.Config.AddId(id, ServerData.bansPath);
        Kick(id);

        Debug.Log("Kickbanning " + id);
    }
        /// <summary>
        ///
        /// Returns true if the steamid was found in  the players file
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool IdPresent(Steamworks.SteamId id)
        {
            StreamReader reader = new StreamReader(playersPath);

            if (reader.EndOfStream)
            {
                reader.Close();
                return(false);
            }


            string[] players = reader.ReadToEnd().Split('\n');

            reader.Close();


            for (int i = 0; i < players.Length; i++)
            {
                if (players[i] == id.ToString())
                {
                    return(true);
                }

                i++;
            }

            return(false);
        }
示例#3
0
    public void Kick(Steamworks.SteamId id)
    {
        AuthResponse msg = new AuthResponse
        {
            message  = "Kicked",
            accepted = false,
        };

        foreach (var connection in NetworkServer.connections)
        {
            if (((PlayerData)connection.Value.authenticationData).id == id)
            {
                Debug.Log("Kicking player with steamid " + id + "  name: " + ((PlayerData)connection.Value.authenticationData).steamName);


                // Dont kick us if we are the host
                if (NetworkClient.active && ((PlayerData)connection.Value.authenticationData).id == Steamworks.SteamClient.SteamId)
                {
                    Debug.Log("Someone tried to kick us, but we are the host.");
                    return;
                }

                connection.Value.Send(msg);

                NetworkServer.RemovePlayerForConnection(connection.Value, true);

                StartCoroutine(DelayedDisconnect(connection.Value, 2f));


                return;
            }
        }
    }
        /// <summary>
        /// Writes the steamid to the file specified
        /// </summary>
        /// <param name="id"></param>
        public static void AddId(Steamworks.SteamId id, string path)
        {
            RemoveId(id, path);

            StreamWriter writer = new StreamWriter(path, true);

            writer.Write(id + " ");

            writer.Close();
        }
示例#5
0
    public static void Kick(Steamworks.SteamId id)
    {
        if (ServerData.Players.IdPresent(id))
        {
            ((MyAuthenticator)Mirror.NetworkManager.singleton.authenticator).Kick(id);
        }


        Debug.Log("Kicking " + id);
    }
        /// <summary>
        /// Checks if the steamid is in the file specified
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool IdPresent(Steamworks.SteamId id, string path)
        {
            Debug.Log("Checking if ID is present in file.");

            Debug.Log("ID: " + id.ToString());
            Debug.Log("Path: " + path);

            Debug.Log("Creating stream reader");

            StreamReader reader = new StreamReader(path);

            Debug.Log("Stream reader created");

            bool present = false;



            if (!reader.EndOfStream)
            {
                string[] ids = reader.ReadLine().Split(' ');

                Debug.Log("Read ids");



                if (ids != null && ids.Length > 0)
                {
                    foreach (var idString in ids)
                    {
                        if (idString.Length > 1)
                        {
                            Debug.Log("Reading id: " + idString);

                            Debug.Log("Converting to ulong");

                            if (System.Convert.ToUInt64(idString) == id)
                            {
                                present = true;
                            }
                        }
                    }
                }
            }


            reader.Close();

            return(present);
        }
        /// <summary>
        ///
        /// Attempts to return the steamid associated with the given steam name in the players file
        ///
        /// Note that players can have duplicate steam names so it might return the wrong player
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Steamworks.SteamId GetId(string name)
        {
            Debug.Log("GetId() called on name: " + name);

            StreamReader reader = new StreamReader(playersPath);

            if (reader.EndOfStream)
            {
                reader.Close();
                return(0);
            }


            string[] players = reader.ReadToEnd().Split('\n');

            reader.Close();

            Steamworks.SteamId id = 0;

            Debug.Log("Finding ID associated with name.");
            Debug.Log("There are " + (players.Length / 2) + " players on record:");


            if (players != null && players.Length > 0)
            {
                for (int i = 0; i < players.Length; i++)
                {
                    if (players[i].Length >= 1)
                    {
                        if (players[i] == name)
                        {
                            id = System.Convert.ToUInt64(players[i - 1]);
                            break;
                        }
                    }
                }
            }


            if (id == 0)
            {
                Debug.Log("Couldn't find the id associated with the name " + name + ". " + playersPath + " may be corrupt.");
            }

            return(id);
        }
        /// <summary>
        /// Removes a player entry from the players file
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void RemovePlayer(Steamworks.SteamId id)
        {
            StreamReader reader = new StreamReader(playersPath);

            if (reader.EndOfStream)
            {
                reader.Close();
                return;
            }

            string[] players = reader.ReadToEnd().Split('\n');

            reader.Close();

            string updated = "";

            // Add all players to the updated string except for the player to remove
            if (players != null && players.Length > 0)
            {
                for (int i = 0; i < players.Length; i++)
                {
                    if (players[i].Length >= 1)
                    {
                        if (players[i] != id.ToString())
                        {
                            updated += players[i] + '\n' + players[i + 1] + '\n';
                        }


                        i++;
                    }
                }
            }
            else
            {
                Debug.Log("Players file was null or empty.");
            }


            StreamWriter writer = new StreamWriter(playersPath, false);

            writer.Write(updated);

            writer.Close();
        }
        /// <summary>
        /// Gets the name associated with the steamid found in the players file
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetName(Steamworks.SteamId id)
        {
            StreamReader reader = new StreamReader(playersPath);

            if (reader.EndOfStream)
            {
                reader.Close();
                return("");
            }

            string[] players = reader.ReadToEnd().Split('\n');

            string name = "";



            // Add all players to the updated string except for the player to remove
            if (players != null && players.Length > 0)
            {
                for (int i = 0; i < players.Length; i++)
                {
                    if (players[i].Length >= 1)
                    {
                        if (players[i] == id.ToString())
                        {
                            name = players[i + 1];
                            break;
                        }

                        i++;
                    }
                }
            }


            reader.Close();


            if (name == "")
            {
                Debug.Log("Couldn't find the name associated with the id " + id + ". " + playersPath + " may be corrupt.");
            }

            return(name);
        }
        /// <summary>
        /// Removes a steamid from the file specified
        /// </summary>
        /// <param name="id"></param>
        public static void RemoveId(Steamworks.SteamId id, string path)
        {
            // Get the current list

            StreamReader reader = new StreamReader(path);



            if (reader.EndOfStream)
            {
                reader.Close();
                return;
            }

            string[] ids = reader.ReadLine().Split(' ');

            reader.Close();



            // Make a new string to that will exclude this players id

            string updatedIds = "";

            if (ids != null && ids.Length > 0)
            {
                foreach (var idString in ids)
                {
                    if (idString.Length > 3 && System.Convert.ToUInt64(idString) != id)
                    {
                        updatedIds += idString + " ";
                    }
                }
            }



            // Write the updated id list

            StreamWriter writer = new StreamWriter(path, false);

            writer.Write(updatedIds);

            writer.Close();
        }
示例#11
0
 private void OnValidateAuthTicketResponse(Steamworks.SteamId SteamId, Steamworks.SteamId OwnerId, AuthResponse Status)
 {
     if (Auth_Steam.ValidateConnecting(SteamId, OwnerId, Status))
     {
         return;
     }
     Network.Connection str = Network.Net.sv.connections.FirstOrDefault <Network.Connection>((Network.Connection x) => x.userid == SteamId);
     if (str == null)
     {
         UnityEngine.Debug.LogWarning(string.Format("Steam gave us a {0} ticket response for unconnected id {1}", Status, SteamId));
         return;
     }
     if (Status == AuthResponse.OK)
     {
         UnityEngine.Debug.LogWarning(string.Format("Steam gave us a 'ok' ticket response for already connected id {0}", SteamId));
         return;
     }
     if (Status == AuthResponse.VACCheckTimedOut)
     {
         return;
     }
     str.authStatus = Status.ToString();
     Network.Net.sv.Kick(str, string.Concat("Steam: ", Status.ToString()));
 }
 private static extern Utf8StringPointer _GetFriendRichPresenceKeyByIndex(IntPtr self, SteamId steamIDFriend, int iKey);
        internal int GetFriendRichPresenceKeyCount(SteamId steamIDFriend)
        {
            var returnValue = _GetFriendRichPresenceKeyCount(Self, steamIDFriend);

            return(returnValue);
        }
 private static extern void _RequestFriendRichPresence(IntPtr self, SteamId steamIDFriend);
        internal string GetFriendRichPresenceKeyByIndex(SteamId steamIDFriend, int iKey)
        {
            var returnValue = _GetFriendRichPresenceKeyByIndex(Self, steamIDFriend, iKey);

            return(returnValue);
        }
        internal AppId GetFriendCoplayGame(SteamId steamIDFriend)
        {
            var returnValue = _GetFriendCoplayGame(Self, steamIDFriend);

            return(returnValue);
        }
 internal void RequestFriendRichPresence(SteamId steamIDFriend)
 {
     _RequestFriendRichPresence(Self, steamIDFriend);
 }
 private static extern int _GetFriendCoplayTime(IntPtr self, SteamId steamIDFriend);
示例#19
0
    public static void Unmod(Steamworks.SteamId id)
    {
        ServerData.Config.RemoveId(id, ServerData.modsPath);

        Debug.Log("Unmodding " + id);
    }
示例#20
0
    // This gets called on server once steam has checked the auth ticket
    private void OnValidateAuthTicketResponse(Steamworks.SteamId userId, Steamworks.SteamId ownerId, Steamworks.AuthResponse response)
    {
        string message  = "";
        bool   accepted = false;

        Debug.Log("[Server/Host] Validation response recieved: ");

        switch (response)
        {
        case Steamworks.AuthResponse.OK:
            message  = "Accepted!";
            accepted = true;
            break;

        case Steamworks.AuthResponse.UserNotConnectedToSteam:
            message  = "Not connected to Steam!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.NoLicenseOrExpired:
            message  = "No liscense or expired!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.VACBanned:
            message  = "VAC banned!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.LoggedInElseWhere:
            message  = "Logged in elsewhere!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.VACCheckTimedOut:
            message  = "VAC check timed out!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.AuthTicketCanceled:
            message  = "Auth ticket canceled!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.AuthTicketInvalidAlreadyUsed:
            message  = "Auth tiekcet invalid or already used!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.AuthTicketInvalid:
            message  = "Invalid auth ticket!";
            accepted = false;
            break;

        case Steamworks.AuthResponse.PublisherIssuedBan:
            message  = "Game ban!";
            accepted = false;
            break;

        default:
            break;
        }

        if (NetworkServer.active && !accepted)
        {
            return;
        }

        Debug.Log("[Server] Accepted: " + accepted + ", Message: " + message);


        AuthResponse msg = new AuthResponse
        {
            message  = message,
            accepted = accepted
        };


        // Now we need to find the connection associated with the steamid we need to respond to, and send the reponse

        foreach (var authUnit in currentAuthUnits)
        {
            if (userId == authUnit.playerData.id)
            {
                if (accepted)
                {
                    StartCoroutine(DelayAuthenticationApproval(.5f, authUnit, msg));
                }
                else
                {
                    FailAuthentication(authUnit.connection, msg);
                }


                // Remove auth unit from temporary list
                currentAuthUnits.Remove(authUnit);
                break;
            }
        }
    }
        internal int GetFriendCoplayTime(SteamId steamIDFriend)
        {
            var returnValue = _GetFriendCoplayTime(Self, steamIDFriend);

            return(returnValue);
        }
 private static extern int _GetFriendRichPresenceKeyCount(IntPtr self, SteamId steamIDFriend);
        internal CallResult <JoinClanChatRoomCompletionResult_t> JoinClanChatRoom(SteamId steamIDClan)
        {
            var returnValue = _JoinClanChatRoom(Self, steamIDClan);

            return(new CallResult <JoinClanChatRoomCompletionResult_t>(returnValue, IsServer));
        }
 private static extern SteamAPICall_t _JoinClanChatRoom(IntPtr self, SteamId steamIDClan);
示例#25
0
    public static void UnBan(Steamworks.SteamId id)
    {
        ServerData.Config.RemoveId(id, ServerData.bansPath);

        Debug.Log("Unbanning " + id);
    }
        internal bool InviteUserToGame(SteamId steamIDFriend, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8StringToNative))] string pchConnectString)
        {
            var returnValue = _InviteUserToGame(Self, steamIDFriend, pchConnectString);

            return(returnValue);
        }
示例#27
0
    public static void Mod(Steamworks.SteamId id)
    {
        ServerData.Config.AddId(id, ServerData.modsPath);

        Debug.Log("Modding " + id);
    }
 private static extern bool _InviteUserToGame(IntPtr self, SteamId steamIDFriend, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8StringToNative))] string pchConnectString);
 private static extern bool _LeaveClanChatRoom(IntPtr self, SteamId steamIDClan);
 private static extern AppId _GetFriendCoplayGame(IntPtr self, SteamId steamIDFriend);