コード例 #1
0
        public override void Call(SignUpRequest packet, IUser sender, IServerManager manager)
        {
            var             profiles = manager.Data.Profiles;
            var             profile  = profiles.Where(x => x.Email.Equals(packet.Email)).FirstOrDefault();
            IPacketResponse p        = null;

            if (sender.IsLogIn)
            {
                p = new SignUpResponseFail
                {
                    Info = SignUpResponseFail.FailInfo.NotSpectator
                };
            }
            else if (profile != null)
            {
                p = new SignUpResponseFail
                {
                    Info = SignUpResponseFail.FailInfo.ExistsEmail
                };
            }
            else
            {
                p = new SignUpResponseLuck();
                int id         = profiles.Count() + 1;
                var newProfile = new Profile
                {
                    Id       = id,
                    Email    = packet.Email,
                    Password = packet.Password,
                    Name     = packet.Name
                };
                manager.Data.Profiles.Add(newProfile);
            }
            sender.Connector.Send(p);
        }
コード例 #2
0
        private void ReceivePacketHandler(object sender, EventArgs e)
        {
            IPacketResponse p = null;

            do
            {
                p = _connector?.Receive();
                p?.Handle(_manager);
            } while (p != null);
        }
コード例 #3
0
ファイル: LogInHandler.cs プロジェクト: popelenkow/SharpChat
        public override void Call(LogInRequest packet, IUser sender, IServerManager manager)
        {
            var             profile = manager.Data.Profiles.Where(x => x.Email.Equals(packet.Email)).FirstOrDefault();
            IPacketResponse p       = null;

            if (sender.IsLogIn)
            {
                p = new LogInResponseFail
                {
                    Info = LogInResponseFail.FailInfo.NotSpectator
                };
            }
            else if (profile == null)
            {
                p = new LogInResponseFail
                {
                    Info = LogInResponseFail.FailInfo.NotFoundEmail
                };
            }
            else if (manager.Users.Any(x => x.IsLogIn && x.Id == profile.Id))
            {
                p = new LogInResponseFail
                {
                    Info = LogInResponseFail.FailInfo.AlreadyOnline
                };
            }
            else if (!profile.Password.Equals(packet.Password))
            {
                p = new LogInResponseFail
                {
                    Info = LogInResponseFail.FailInfo.IncorrectPassword
                };
            }
            else
            {
                p = new LogInResponseLuck();
                sender.IsLogIn = true;
                sender.Id      = profile.Id;
            }
            sender.Connector.Send(p);
        }
コード例 #4
0
        public override void Call(MyProfileInfoRequest packet, IUser sender, IServerManager manager)
        {
            IPacketResponse p = null;

            if (sender.IsLogIn)
            {
                int[] idChats = manager.Data.Chats.Where(x => x.Profiles.Any(y => y.Id == sender.Id)).Select(x => x.Id).ToArray();
                p = new MyProfileInfoResponseLuck
                {
                    Id      = sender.Id,
                    IdChats = idChats
                };
            }
            else
            {
                p = new MyProfileInfoResponseFail
                {
                    Info = MyProfileInfoResponseFail.FailInfo.NotAuthorized
                };
            }
            sender.Connector.Send(p);
        }
コード例 #5
0
        private void ConnectionHandler(object sender, EventArgs e)
        {
            if (_isClosed)
            {
                return;
            }
            if (_connector == null || _connector?.IsClosed == true)
            {
                _connector  = NetworkConnector.GetClientConnector();
                IsConnected = false;
            }
            else if (_connectionInfo == null || !_connectionInfo.IsConnected)
            {
                IsConnected = false;

                IPacketResponse p = null;
                do
                {
                    p = _connector?.Receive();
                    p?.Handle(_manager);
                } while (p != null);

                _connector.Close();
                _connector = null;
            }
            else
            {
                IsConnected = true;
            }
            _connectionInfo = null;
            var request = new ConnectionRequest
            {
                IsConnect = true
            };

            _connector?.Send(request);
        }
コード例 #6
0
 public static void Handle(this IPacketResponse packet, IClientManager manager)
 {
     _dispatcher.GetMethod(packet)
     .Call(packet, manager);
 }