Example #1
0
        internal void GetContacts(MessageToServer receivedMessage, Socket handler)
        {
            MessageFromServer message = new MessageFromServer
            {
                Users = _database.SelectContacts(receivedMessage.Id)
            };

            handler.Send(message.EncodeMessage());
        }
Example #2
0
        internal void LoadMessages(MessageToServer receivedMessage, Socket handler)
        {
            MessageFromServer message = new MessageFromServer
            {
                Messages = _database.SelectMessages(receivedMessage.Id, receivedMessage.TargetId)
            };

            handler.Send(message.EncodeMessage());
        }
Example #3
0
        internal void Reject(Socket handler)
        {
            MessageFromServer message = new MessageFromServer()
            {
                Command = CommandFromServer.REJECTED
            };

            handler.Send(message.EncodeMessage());
        }
Example #4
0
        internal void Accept(Socket handler)
        {
            MessageFromServer message = new MessageFromServer()
            {
                Command = CommandFromServer.ACCEPTED
            };

            handler.Send(message.EncodeMessage());
        }
Example #5
0
        internal void SearchContacts(MessageToServer receivedMessage, Socket handler)
        {
            MessageFromServer message = new MessageFromServer
            {
                Users = _database.SearchUsers(receivedMessage.Name)
            };

            handler.Send(message.EncodeMessage());
        }
Example #6
0
        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);
        }
Example #7
0
        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());
            }
        }