Пример #1
0
        /// <summary>
        /// Adds a virtualUser class together with the userID to the userManager. Login ticket will be nulled and previous logged in instances of this user will be dropped.
        /// </summary>
        /// <param name="userID">The ID of the user to add.</param>
        /// <param name="User">The virtualUser class of this user.</param>
        public static void addUser(int userID, virtualUser User)
        {
            if (_Users.ContainsKey(userID))
            {
                virtualUser oldUser = ((virtualUser)_Users[userID]);
                oldUser.Disconnect();
                if (_Users.ContainsKey(userID))
                {
                    _Users.Remove(userID);
                }
            }

            if (User.connectionRemoteIP == DB.runRead("SELECT ipaddress_last FROM users WHERE name = '" + User._Username + "'"))
            {
                _Users.Add(userID, User);
                DB.runQuery("UPDATE users SET ticket_sso = NULL WHERE id = '" + userID + "' LIMIT 1");
                Out.WriteLine("User " + userID + " logged in. [" + User._Username + "]", Out.logFlags.BelowStandardAction);
            }
            else
            {
                User.Disconnect(1000);
                User.sendData("BK" + "Invalid Session Ticket, please login again!");
            }

            if (_Users.Count > _peakUserCount)
            {
                _peakUserCount = _Users.Count;
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a virtualUser class together with the userID to the userManager. Login ticket will be nulled and previous logged in instances of this user will be dropped.
        /// </summary>
        /// <param name="userID">The ID of the user to add.</param>
        /// <param name="User">The virtualUser class of this user.</param>
        public static void addUser(int userID, virtualUser User)
        {
            if (_Users.ContainsKey(userID))
            {
                virtualUser oldUser = ((virtualUser)_Users[userID]);
                oldUser.Disconnect();
                if (_Users.ContainsKey(userID))
                {
                    _Users.Remove(userID);
                }
            }
            using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
            {
                dbClient.AddParamWithValue("name", User._Username);
                if (User.connectionRemoteIP == dbClient.getString("SELECT ipaddress_last FROM users WHERE name = @name LIMIT 1"))
                {
                    _Users.Add(userID, User);
                    dbClient.runQuery("UPDATE users SET ticket_sso = NULL WHERE id = '" + userID + "' LIMIT 1");
                    Out.WriteLine("User " + userID + " logged in. [" + User._Username + "]", Out.logFlags.BelowStandardAction);
                }

                else
                {
                    User.Disconnect(1000);
                    User.sendData("BK" + "Invalid Session Ticket, please login again!");
                }

                if (_Users.Count > dbClient.getInt("SELECT onlinecount_peak FROM system"))
                {
                    _peakUserCount = _Users.Count;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// (Re)bans a single user for a specified amount of hours and reason. If the user is online, then it receives the ban message and get's disconnected.
        /// </summary>
        /// <param name="userID">The database ID of the user to ban.</param>
        /// <param name="Hours">The amount of hours (starts now) till the ban is lifted.</param>
        /// <param name="Reason">The reason for the ban, that describes the user why it's account is blocked from the system.</param>
        public static void setBan(int userID, int Hours, string Reason)
        {
            string Expires = DateTime.Now.AddHours(Hours).ToString();

            DB.runQuery("DELETE FROM users_bans WHERE userid = '" + userID + "' LIMIT 1"); // Delete previous bans
            DB.runQuery("INSERT INTO users_bans (userid,date_expire,descr) VALUES ('" + userID + "','" + Expires + "','" + DB.Stripslash(Reason) + "')");

            if (_Users.ContainsKey(userID))
            {
                virtualUser User = ((virtualUser)_Users[userID]);
                User.sendData("@c" + Reason);
                User.Disconnect(1000);
            }
        }
Пример #4
0
        /// <summary>
        /// (Re)bans all the users on a certain IP address, making them unable to login, and making them unable to connect to the system. The ban is applied with a specified amount and reason. All affected users receive the ban message (which contains the reason) and they are disconnected.
        /// </summary>
        /// <param name="IP">The IP address to ban.</param>
        /// <param name="Hours">The amount of hours (starts now) till the ban is lifted.</param>
        /// <param name="Reason">The reason for the ban, that describes thes user why their IP address/accounts are blocked from the system.</param>
        public static void setBan(string IP, int Hours, string Reason)
        {
            string Expires = DateTime.Now.AddHours(Hours).ToString();

            DB.runQuery("DELETE FROM users_bans WHERE ipaddress = '" + IP + "'"); // Delete previous bans
            DB.runQuery("INSERT INTO users_bans (ipaddress,date_expire,descr) VALUES ('" + IP + "','" + Expires + "','" + DB.Stripslash(Reason) + "')");

            int[] userIDs = DB.runReadColumn("SELECT id FROM users WHERE ipaddress_last = '" + IP + "'", 0, null);
            for (int i = 0; i < userIDs.Length; i++)
            {
                if (_Users.ContainsKey(userIDs[i]))
                {
                    virtualUser User = ((virtualUser)_Users[userIDs[i]]);
                    User.sendData("@c" + Reason);
                    User.Disconnect(1000);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// (Re)bans a single user for a specified amount of hours and reason. If the user is online, then it receives the ban message and get's disconnected.
        /// </summary>
        /// <param name="userID">The database ID of the user to ban.</param>
        /// <param name="Hours">The amount of hours (starts now) till the ban is lifted.</param>
        /// <param name="Reason">The reason for the ban, that describes the user why it's account is blocked from the system.</param>
        public static void setBan(int userID, int Hours, string Reason)
        {
            string Expires = DateTime.Now.AddHours(Hours).ToString().Replace("/", "-").Replace(".", "-");

            using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
            {
                dbClient.AddParamWithValue("userid", userID);
                dbClient.AddParamWithValue("expires", Expires);
                dbClient.AddParamWithValue("reason", Reason);
                dbClient.runQuery("INSERT INTO users_bans (userid,date_expire,descr) VALUES (@userid,@expires,@reason)");
            }
            if (_Users.ContainsKey(userID))
            {
                virtualUser User = ((virtualUser)_Users[userID]);
                User.sendData("@c" + Reason);
                User.Disconnect(1000);
            }
        }
Пример #6
0
 /// <summary>
 /// Sends a single packet to the parent virtual user of this player. On error the action is skipped.
 /// </summary>
 /// <param name="Data">The packet to send.</param>
 internal void sendData(string Data)
 {
     try { User.sendData(Data); }
     catch { }
 }
Пример #7
0
            /// <summary>
            /// Called when a packet is received, the packet will be processed and the connection will be closed (after processing packet) in all cases. No errors will be thrown.
            /// </summary>
            /// <param name="iAr"></param>
            private void dataArrival(IAsyncResult iAr)
            {
                try
                {
                    int    bytesReceived = Connector.EndReceive(iAr);
                    string Data          = System.Text.Encoding.ASCII.GetString(dataBuffer, 0, bytesReceived);

                    string   musHeader = Data.Substring(0, 4);
                    string[] musData   = Data.Substring(4).Split(Convert.ToChar(2));
                    Out.WriteLine("DATA: " + Data);
                    #region MUS trigger commands
                    // Unsafe code, but on any error it jumps to the catch block & disconnects the socket
                    switch (musHeader)
                    {
                    case "HKTM":     // Housekeeping - textmessage [BK] :: "HKTM123This is a test message to user with ID 123"
                    {
                        int    userID  = int.Parse(musData[0]);
                        string Message = musData[1];
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).sendData("BK" + Message);
                        }
                        break;
                    }

                    case "HKMW":     // Housekeeping - alert user [mod warn] :: "HKMW123This is a test mod warn to user with ID 123"
                    {
                        int    userID  = int.Parse(musData[0]);
                        string Message = musData[1];
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).sendData("B!" + Message + Convert.ToChar(2));
                        }
                        break;
                    }

                    case "HKUK":     // Housekeeping - kick user from room [mod warn] :: "HKUK123This is a test kick from room + modwarn for user with ID 123"
                    {
                        int         userID  = int.Parse(musData[0]);
                        string      Message = musData[1];
                        virtualUser User    = userManager.getUser(userID);
                        if (User.Room != null)
                        {
                            User.Room.removeUser(User.roomUser.roomUID, true, Message);
                        }
                        break;
                    }

                    case "HKAR":     // Housekeeping - alert certain rank with BK message, contains flag to include users with higher rank :: "HKAR11This is a test message for all users with rank 1 and higher, so kindof a Hotel alert :D"
                    {
                        byte   Rank          = byte.Parse(musData[0]);
                        bool   includeHigher = (musData[1] == "1");
                        string Message       = musData[2];
                        userManager.sendToRank(Rank, includeHigher, "BK" + Message);
                        break;
                    }

                    case "HKSB":     // Housekeeping - ban user & kick from room :: "HKSB123This is a test ban for user with ID 123"
                    {
                        int         userID  = int.Parse(musData[0]);
                        string      Message = musData[1];
                        virtualUser User    = userManager.getUser(userID);
                        User.sendData("@c" + Message);
                        User.Disconnect(1000);
                        break;
                    }

                    case "HKRC":     // Housekeeping - rehash catalogue :: "HKRC"
                    {
                        catalogueManager.Init(false);
                        break;
                    }

                    case "UPRA":     // User profile - reload figure, sex and mission (poof!)
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).refreshAppearance(true, true, true);
                        }
                        break;
                    }

                    case "UPRC":         // User profile - reload credits
                    {
                        int userID = int.Parse(musData[0]);
                        userManager.getUser(userID).refreshValueables(true, false);
                        break;
                    }

                    case "UPRT":     // User profile - reload tickets
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).refreshValueables(false, true);
                        }
                        break;
                    }

                    case "UPRS":     // User profile - reload subscription (and badges)
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            virtualUser User = userManager.getUser(userID);
                            User.refreshClub();
                            User.refreshBadges();
                        }
                        break;
                    }

                    case "UPRH":    // User profile - reload hand
                    {
                        int userID = int.Parse(musData[0]);
                        if (userManager.containsUser(userID))
                        {
                            userManager.getUser(userID).refreshHand("new");
                        }
                        break;
                    }
                    }
                    #endregion
                }
                catch { }
                finally { killConnection(); }
            }