public IResult Login(string id, string password)
 {
     lock (LOCK)
     {
         this.UserInfo = new User_Client(id);
         if (waitingRespond)
         {
             throw new Exception("产生过未上锁的异步请求");
         }
         this.waitingRespond = true;
         isSendSucceful      = true;
         clientSocket.Send(MessageTranslate.EncapsulationInfo(MessageContent.登录, MessageType.请求, id, password), ar => { if (ar == baseResult.Faild.ToString())
                                                                                                                        {
                                                                                                                            isSendSucceful = false;
                                                                                                                        }
                           });
         while (waitingRespond)
         {
             if (!isSendSucceful)
             {
                 waitingRespond = false; return(new Result(baseResult.Faild, "发送send失败"));
             }
         }
         //等待响应
         if (respondMessage["结果"] == baseResult.Successful.ToString())
         {
             this.UserInfo.UserState = UserState.已登录;
             UserInfo.IsPrerogative  = Boolean.Parse(respondMessage["权限"]);
             return(new Result(baseResult.Successful, respondMessage["权限"]));
         }
         return(new Result(baseResult.Faild, respondMessage["权限"]));
     }
 }
 public Client()
 {
     clientSocket              = new ClientSocket();
     clientSocket.OnException += e => { OnException?.Invoke(e); };
     UserInfo = new User_Client();
     LOCK     = new object();
 }
Ejemplo n.º 3
0
 public Client()
 {
     clientSocket = new ClientSocket();
     UserInfo     = new User_Client();
     LOCK         = new object();
 }