Ejemplo n.º 1
0
        private void OnClAuthRespond(ClAuthRespond msg, ClientId id)
        {
            var cl          = clients[id];
            var accessFlags = UserAccess.Default;
            var result      = AuthenticateClient(msg.Login, msg.Password, ref accessFlags);
            var respond     = new SvAuthResult {
                Result = result
            };

            if (result == AuthResult.Accepted)
            {
                cl.Login         = msg.Login;
                cl.Password      = msg.Password;
                cl.AccessFlags   = accessFlags;
                cl.Authenticated = true;
                nameToClient.Add(cl.Login, cl);
                Root.Log(LogLevel.Info, "Client #{0} ({1}) : authentication succeeded", cl.Id, cl.Login);
                respond.Message = "All ok";
                if (SendTo(id, respond))
                {
                    OnClientAuthSuccess(id);
                }
            }
            else
            {
                Root.Log(LogLevel.Info, "Client #{0} ({1}) : authentication failed <{2}>",
                         cl.Id, msg.Login, result);
                // XXX: add extra details here
                respond.Message = "";
                if (SendTo(id, respond))
                {
                    DisconnectClient(cl);
                }
            }
        }
Ejemplo n.º 2
0
        public void SaveLoadSvAuthResult()
        {
            // arrange
            const string     refMessage = "You have been banned by serveradmin";
            const AuthResult refResult  = AuthResult.Banned;
            var msg = new SvAuthResult
            {
                Message = refMessage,
                Result  = refResult,
            };

            // act
            MultiprotocolSaveLoad(msg, () =>
            {
                // assert
                Assert.AreEqual(msg.Message, refMessage);
                Assert.AreEqual(msg.Result, refResult);
            });
        }
Ejemplo n.º 3
0
 private void OnAuthResult(SvAuthResult msg)
 {
     if (msg.Result == Core.AuthResult.Accepted)
     {
         authenticated = true;
         var statusMsg = msg.Message;
         if (statusMsg == "")
         {
             statusMsg = "All ok";
         }
         Root.Log(LogLevel.Info, "Server: authentication succeeded <{0}>", statusMsg);
     }
     else
     {
         var statusMsg = msg.Result.ToString();
         if (msg.Message != "")
         {
             statusMsg = String.Format("{0}: {1}", statusMsg, msg.Message);
         }
         Root.Log(LogLevel.Error, "Server: authentication failed <{0}>", statusMsg);
         Reset(); // server closes connection after rejection
     }
     OnAuthResult(msg.Result, msg.Message);
 }