public BannedUser(IClientObject client, DateTime?banTill) : base(client) { MessageReadonly ro = new MessageReadonly(); ro.client = this.client; Handlers = new IHandlerModule[] { new Logout(), new Info(), ro, new Private() }; this.client = client; if (banTill != null || banTill != DateTime.MaxValue) { Task.Factory.StartNew(async() => { TimeSpan taskRunTime = banTill.Value.Subtract(DateTime.Now); if (taskRunTime.TotalMilliseconds > 0) { await Task.Delay(taskRunTime); } TrackBlackList(client.Username); }); } }
public Boolean Logon(ClientInfo clientData) { try { String sUrl = String.Format(@"tcp://{0}:{1}/ClientObject.soap", clientData.ipAddress.ToString(), clientData.portN.ToString()); IClientObject ClientObj = (IClientObject)Activator.GetObject(typeof(IClientObject), sUrl); clientData.ClientObj = ClientObj; clientData.DateTimeLogin = DateTime.Now; if (ClientList.ContainsKey(clientData.name)) { Logoff(clientData.name, "has duplicate key in ClientList"); } lock (this) { ClientList.Add(clientData.name, clientData); } WriteBuffer("Logon: " + clientData.name + ", IP address: " + clientData.ipAddress.ToString() + ", Port: " + clientData.portN.ToString()); return(true); } catch (Exception ex) { WriteBuffer("Error source: Logon() " + clientData.name + ", IP address: " + clientData.ipAddress.ToString() + ", Port: " + clientData.portN.ToString() + " " + ex.Message + " " + ex.StackTrace); return(false); } }
public virtual bool Handle(IClientObject client, RequestObject request) { if (request.Module != "msg") { return(false); } switch (request.Cmd) { case "msg": HandleMessage(client, request); break; case "active": HandleActive(client, request); break; case "leave": HandleLeave(client, request); break; default: break; } return(true); }
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); }
public bool Handle(IClientObject client, RequestObject request) { if (request.Module != "admin") { return(false); } switch (request.Cmd) { case "ban": object[] args = JsonConvert.DeserializeObject <object[]>(request.Args.ToString()); BanUser((string)args[0], (DateTime)args[1]); //[0] -username break; case "unban": UnBanUser(request.Args.ToString()); break; case "close_room": Manager.CloseRoom(request.Args.ToString()); break; default: break; } return(true); }
public void TrackBlackList(string username) { IClientObject user = Manager.FindClient(username); string tmp = ResponseConstructor.GetUnBannedNotification(username); user.SendMessage(tmp); user.Role = new User(user); }
public void Broadcast(IClientObject excl, ChatMessage msg) { Messages.AddLast(msg); foreach (RoomObserverBase observer in Clients) { if (observer.client != excl) { observer.On_MessageReceived(Name, msg); } NewMessage?.Invoke(Name, msg); } }
protected virtual void HandleMessage(IClientObject client, RequestObject request) { object[] args = JsonConvert.DeserializeObject <object[]>(request.Args.ToString()); string rstr = args[0] as string; ChatMessage msg = JsonConvert.DeserializeObject <ChatMessage>(args[1].ToString()); msg.TimeStamp = msg.TimeStamp.ToUniversalTime(); RoomObject r = Manager.FindRoom(rstr); r?.Broadcast(client, msg); LogProvider.AppendRecord(string.Format("[{0}]: Sent a message {1}", client.Username, msg.ToString())); }
public bool Handle(IClientObject client, RequestObject request) { if (request.Module != "logout") { return(false); } client.Close(); LogProvider.AppendRecord(string.Format("[{0}]: left chat", client.Username)); return(true); }
public override bool Handle(IClientObject client, RequestObject request) { if (request.Module != "Gmail") { return(false); } string name = request.Args.ToString(); LogProvider.AppendRecord(string.Format("{0} loggin gmail user [{1}]", DateTime.Now.ToString(), name)); client.Username = name; ResolveStatus(client); return(true); }
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); }
protected virtual void HandleLeave(IClientObject client, RequestObject request) { RoomObject room = Manager.FindRoom((string)request.Args); //if (room != null) //{ room.RemoveListener(this); LogProvider.AppendRecord(string.Format("[{0}]: left room {1}", client.Username, room.Name)); // if (Active == room) //{ // Active = Manager.Host; //} //} }
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); }
public User(IClientObject clnt) : base(clnt) { RoomObserver messageModule = new RoomObserver(); messageModule.client = clnt; Handlers = new IHandlerModule[] { new HistoryModule(), messageModule, new Logout(), new Info(), new Private(), new Room() }; }
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); }
public Admin(IClientObject clnt) : base(clnt) { RoomObserver ro = new RoomObserver(); ro.client = clnt; Handlers = new IHandlerModule[] { new Logout(), new Info(), new HistoryModule(), ro, new Private(), new Room(), new AdminModule() }; }
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); }
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); }
public static DefaultClientObject CreateNewLead(IClientObject source) { if (source == null) { return(null); } var destination = new DefaultClientObject(); foreach (var valuePair in source.ClientObject) { destination.ClientObject.Add(new KeyValuePair <string, object>(valuePair.Key, valuePair.Value)); } return(destination); }
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)); } } }
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); }
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); }
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); }
public override bool Handle(IClientObject client, RequestObject request) { if (request.Module != "login") { return(false); } object[] arg = JsonConvert.DeserializeObject <object[]>(request.Args.ToString()); Person user = new Person(arg[0].ToString(), arg[1].ToString(), null); /*string flag = "hooy";// new ApiAuth().api.LogIn(user); * if (flag == "false") * { * client.SendMessage(ResponseConstructor.GetErrorNotification("Please check that you have entered your login and password correctly", "login")); * return true; * }*/ client.Username = user.name; ResolveStatus(client); return(true); }
public void ReceiveCallback(IAsyncResult result) { IClientObject client = null; try { client = (IClientObject)result.AsyncState; var receive = client.Listener.EndReceive(result); var ipandport = client.Listener.RemoteEndPoint; if (receive > 0) { IEnumerable <byte> bytes = client.Buffer.Take(receive); byte[] message = bytes.ToArray(); string data = Encoding.ASCII.GetString(message); } } catch (Exception ex) { } }
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); }
public virtual void Handle(IClientObject client, string request) { RequestObject req = null; try { req = JsonConvert.DeserializeObject <RequestObject>(request); } catch (Exception e) { LogProvider.AppendRecord(string.Format("user {0} sent bad request {1}", client.Username, request)); return; } foreach (IHandlerModule module in client.Role.Handlers) { if (module.Handle(client, req)) { break; } } }
public static void AddClient(IClientObject client) { Clients.AddLast(client); }
public RoleBase(IClientObject clnt) { this.client = clnt; }
protected override void HandleMessage(IClientObject client, RequestObject request) { }