internal void GetContacts(MessageToServer receivedMessage, Socket handler) { MessageFromServer message = new MessageFromServer { Users = _database.SelectContacts(receivedMessage.Id) }; handler.Send(message.EncodeMessage()); }
internal void LoadMessages(MessageToServer receivedMessage, Socket handler) { MessageFromServer message = new MessageFromServer { Messages = _database.SelectMessages(receivedMessage.Id, receivedMessage.TargetId) }; handler.Send(message.EncodeMessage()); }
internal void Reject(Socket handler) { MessageFromServer message = new MessageFromServer() { Command = CommandFromServer.REJECTED }; handler.Send(message.EncodeMessage()); }
internal void Accept(Socket handler) { MessageFromServer message = new MessageFromServer() { Command = CommandFromServer.ACCEPTED }; handler.Send(message.EncodeMessage()); }
internal void SearchContacts(MessageToServer receivedMessage, Socket handler) { MessageFromServer message = new MessageFromServer { Users = _database.SearchUsers(receivedMessage.Name) }; handler.Send(message.EncodeMessage()); }
internal void Authorize(MessageToServer receivedMessage, Socket handler) { User user = _database.SelectOneUser(receivedMessage.Username); if (user != null) { if (user.Password == receivedMessage.Password) { _connectedUsers.Add(receivedMessage.Username, handler); MessageFromServer message = new MessageFromServer() { Command = CommandFromServer.ACCEPTED, Id = user.Id, Name = user.Name }; handler.Send(message.EncodeMessage()); return; } } Reject(handler); }
internal void Register(MessageToServer receivedMessage, Socket handler) { User user = _database.SelectOneUser(receivedMessage.Username); if (user != null) { Reject(handler); } else { _connectedUsers.Add(receivedMessage.Username, handler); user = new User(receivedMessage.Username, receivedMessage.Password, receivedMessage.Username); _database.Insert(user); user = _database.SelectOneUser(user.Username); MessageFromServer message = new MessageFromServer() { Command = CommandFromServer.ACCEPTED, Id = user.Id, Name = user.Name }; handler.Send(message.EncodeMessage()); } }