Beispiel #1
0
        /// <summary>
        /// Initializes a new connection instance, greets the client and starts listening for data.
        /// </summary>
        /// <param name="connectionID">The ID of this connection.</param>
        /// <param name="Socket">The socket object of this connection.</param>
        public userManager(int connectionID, Socket Socket)
        {
            this.connectionID = connectionID;
            this.Socket = Socket;
            this.dataBuffer = new byte[1024];
            this.packetHandler = new Packets(this);

            this.Socket.BeginReceive(this.dataBuffer, 0, this.dataBuffer.Length, SocketFlags.None, new AsyncCallback(this.dataArrival), null);
        }
Beispiel #2
0
        public static void attemptLogin(string Username, string Password, Packets pH)
        {
            string[] Data = Database.runReadRowStrings("SELECT id,name,access,level,hair_id,password,salt FROM users WHERE name = '" + Username + "'");
            if (Data.Length > 0)
            {
                try
                {
                    User userInfo = new User();
                    userInfo.userID = int.Parse(Data[0]);
                    userInfo.Username = Data[1];
                    userInfo.Access = int.Parse(Data[2]);
                    userInfo.Level = int.Parse(Data[3]);
                    userInfo.HairID = int.Parse(Data[4]);
                    userInfo.connectionID = pH.Connection.connectionID;

                    userSession Session = new userSession(pH.Connection, userInfo);
                    pH.Connection.Session = Session;

                    try { _Sessions.Add(userInfo.userID, Session); }
                    catch
                    {
                        _Sessions.Remove(userInfo.userID);
                        _Sessions.Add(userInfo.userID, Session);
                    }

                    pH.Connection.sendMessage("%xt%loginResponse%-1%true%" + userInfo.userID + "%" + userInfo.Username + "%" + Settings.server_motd + "%1262809466137%sNews=" + Settings.client_news + ",sMap=" + Settings.client_map + ",sBook=" + Settings.client_book + "%");
                }
                catch
                {
                    Logging.logWarning("Disconnected user because another user with same id is already logged in.");
                    Sockets.endConnection(pH.Connection, pH.Connection.Session.userInfo.roomID);
                }
            }
            else
            {
                Logging.logWarning("Disconnected user because of no data.");
                Sockets.endConnection(pH.Connection, pH.Connection.Session.userInfo.roomID);
            }
        }