Esempio n. 1
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "history")
            {
                return(false);
            }
            object[] args = JsonConvert.DeserializeObject <object[]>(request.Args.ToString());
            DateTime last;

            switch (request.Cmd)
            {
            case "room":
                string rstr = args[0] as string;
                string time = args[1].ToString();
                last = DateTime.Parse(time).ToUniversalTime();
                ChatMessage[] h = Manager.FindRoom(rstr)?.GetMessageHistoryTo(last);
                client.SendMessage(ResponseConstructor.GetRoomHistoryResponse(rstr, h));
                break;

            case "private":
                string user1 = (string)args[0];
                string user2 = (string)args[1];
                time = args[2].ToString();
                last = DateTime.Parse(time).ToUniversalTime();
                h    = HistoryDataprovider.GetPrivateHistory(user1, user2, last);
                client.SendMessage(ResponseConstructor.GetPrivateHistoryResponse(user2, h));
                break;

            default: break;
            }

            return(true);
        }
Esempio n. 2
0
        //protected RoomObject Active;


        public virtual void On_MessageReceived(string room, ChatMessage msg)
        {
            if (msg.Sender == client.Username)
            {
                return;
            }

            //if(Active.Name == room)
            //{
            client.SendMessage(JsonConvert.SerializeObject(new RequestObject("msg", "msg", new object[] { room, msg })));
            //}
            //else
            //{
            //     client.SendMessage(JsonConvert.SerializeObject(new RequestObject("msg", "notify", room)));
            //}
        }
Esempio n. 3
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "auth")
            {
                return(false);
            }

            string key = request.Args.ToString();

            AuthPool.PoolObject obj = AuthPool.GetRecordByKey(key);

            if (obj == null)
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("authorization failed", "login"));
                return(true);
            }
            if (Manager.FindClient(obj.Username) != null)
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("You have already logged in", "login"));
                client.Close();
                return(true);
            }
            client.Username = obj.Username;
            switch (obj.status)
            {
            case AuthStatus.User:
                client.Role = new User(client);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("user", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as user", client.Username));
                break;

            case AuthStatus.Banned:
                client.Role = new BannedUser(client, obj.banTill);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("banned", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as banned user", client.Username));
                break;

            case AuthStatus.Admin:
                client.Role = new Admin(client);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("admin", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as admin", client.Username));
                break;
            }
            Manager.AddClient(client);
            return(true);
        }
Esempio n. 4
0
        public void TrackBlackList(string username)
        {
            IClientObject user = Manager.FindClient(username);

            string tmp = ResponseConstructor.GetUnBannedNotification(username);

            user.SendMessage(tmp);
            user.Role = new User(user);
        }
Esempio n. 5
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "Forgot")
            {
                return(false);
            }
            bool flag = false;//new ApiAuth().api.ForgotPassword(request.Args.ToString());

            if (flag == true)
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("Success", "login"));
            }
            else
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("Error", "login"));
            }
            return(true);
        }
Esempio n. 6
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "room")
            {
                return(false);
            }
            string roomName = (string)request.Args;
            var    room     = Manager.FindRoom(roomName);

            if (request.Cmd == "create")
            {
                if (room != null)
                {
                    client.SendMessage(ResponseConstructor.GetErrorNotification("This room already exists", "room"));
                    LogProvider.AppendRecord(string.Format("[{0}]: tried to create existing room {1}", client.Username, roomName));
                }
                else
                {
                    Manager.CreateRoom(roomName, client.Username);
                    LogProvider.AppendRecord(string.Format("[{0}]: created new room {1}", client.Username, roomName));
                }
            }
            else if (request.Cmd == "close")
            {
                if (room == null)
                {
                    client.SendMessage(ResponseConstructor.GetErrorNotification("Can't delete this room as it doesn't exist", "room"));
                    LogProvider.AppendRecord(string.Format("[{0}]: tried to close unexisting room {1}", client.Username, roomName));
                }
                else if (room.Creator != client.Username && client.Role.GetType() != typeof(Admin))
                {
                    client.SendMessage(ResponseConstructor.GetErrorNotification("Can't delete room " + roomName + " . No permission.", "room"));
                    LogProvider.AppendRecord(string.Format("[{0}]: tried to close room {1} but had no permission", client.Username, roomName));
                }
                else
                {
                    Manager.CloseRoom((string)request.Args);
                    LogProvider.AppendRecord(string.Format("[{0}]: closed room {1}", client.Username, roomName));
                }
            }
            return(true);
        }
Esempio n. 7
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "info")
            {
                return(false);
            }
            var           arg  = Manager.GetAllInfo();
            RequestObject robj = new RequestObject("info", "all", arg);

            client.SendMessage(JsonConvert.SerializeObject(robj));
            LogProvider.AppendRecord(string.Format("[{0}]: requested info", client.Username));
            return(true);
        }
Esempio n. 8
0
 protected void ResolveStatus(IClientObject client)
 {
     if (IsAdmin(client.Username))
     {
         client.Role = new Admin(client);
         client.SendMessage(ResponseConstructor.GetLoginResultNotification("admin", client.Username));
         LogProvider.AppendRecord(string.Format("[{0}]: Logged in as admin", client.Username));
     }
     else if (BlackListProvider.RecordExists(client.Username))
     {
         client.Role = new BannedUser(client);
         client.SendMessage(ResponseConstructor.GetLoginResultNotification("banned", client.Username));
         LogProvider.AppendRecord(string.Format("[{0}]: logged as banned user", client.Username));
     }
     else
     {
         client.Role = new User(client);
         client.SendMessage(ResponseConstructor.GetLoginResultNotification("ok", client.Username));
         LogProvider.AppendRecord(string.Format("[{0}]: logged in", client.Username));
     }
     Manager.AddClient(client);
 }
Esempio n. 9
0
        private void BanUser(string username, DateTime?duration)
        {
            AuthServerAdminClient.Ban(username, duration);

            IClientObject user = Manager.FindClient(username);

            if (user == null || user.ToString() == "")  //user not found
            {
                return;
            }
            LogProvider.AppendRecord(string.Format("[{0}]: banned user {1}", user.Username, username));
            user.SendMessage(ResponseConstructor.GetBannedNotification(duration));
            user.Role = new BannedUser(user, duration);
        }
Esempio n. 10
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "Registration")
            {
                return(false);
            }

            object[] arg  = JsonConvert.DeserializeObject <object[]>(request.Args.ToString());
            Person   user = new Person(arg[0].ToString(), arg[1].ToString(), arg[2].ToString());
            string   info = "hooy";// new ApiAuth().api.Reg(user);

            client.SendMessage(ResponseConstructor.GetErrorNotification(info, "login"));

            return(true);
        }
Esempio n. 11
0
        private void UnBanUser(string username)
        {
            AuthServerAdminClient.UnBan(username);

            IClientObject user = Manager.FindClient(username);

            if (user == null || user.ToString() == "")
            {
                return;
            }

            user.SendMessage(ResponseConstructor.GetUnBannedNotification(username));
            LogProvider.AppendRecord(string.Format("[{0}]: unbanned user {1}", user.Username, username));

            user.Role = new User(user);
        }
Esempio n. 12
0
        protected virtual void HandleActive(IClientObject client, RequestObject request)
        {
            RoomObject room = null;

            room = Manager.FindRoom(request.Args.ToString());

            if (room != null)
            {
                room.AddListener(this);

                LogProvider.AppendRecord(string.Format("[{0}]: entered room {1}", client.Username, room.Name));
                ChatMessage[] msgs = room.GetMessageHistoryTo(DateTime.Now);
                if (msgs.Length > 0)
                {
                    client.SendMessage(ResponseConstructor.GetRoomHistoryResponse(room.Name, msgs));
                }
            }
        }
Esempio n. 13
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "private")
            {
                return(false);
            }

            IClientObject recipient = Manager.FindClient(request.Cmd);

            if (recipient != null)
            {
                recipient.SendMessage(JsonConvert.SerializeObject(new RequestObject("private", null, request.Args)));
                ChatMessage msg = JsonConvert.DeserializeObject <ChatMessage>(request.Args.ToString());
                msg.TimeStamp = msg.TimeStamp.ToUniversalTime();
                HistoryDataprovider.AppendPrivateMessage(client.Username, recipient.Username, msg);
            }
            return(true);
        }