Ejemplo n.º 1
0
        void Login(ServerMessage request)
        {
            if (loggedIn != null)
            {
                SingleResponse.Send(clientStream, ServerMessageType.Fail,
                                    "You're already logged in");
                return;
            }
            var login = (LoginRequest)request;

            if (!s.Db.AuthenticateUser(login.Username, login.Password))
            {
                SingleResponse.Send(clientStream, ServerMessageType.AuthenticationError,
                                    "The username or password provided was incorrect");
                return;
            }
            loggedIn           = login.Username;
            currentPermissions = s.Db.GetPermissions(loggedIn);
            var maxIPcount = s.Permissions.MaxConcurrentIPs(currentPermissions);

            if (!s.IpManager.AddIP(loggedIn, ip, maxIPcount))
            {
                SingleResponse.Send(clientStream, ServerMessageType.NotPermitted,
                                    "You're logged into too many devices. The most your account level allows is "
                                    + maxIPcount);
                return;
            }
            sessionKey = s.HolePunchServer.Add(ip);
            LoginSuccess.Send(clientStream, sessionKey);
        }