Exemplo n.º 1
0
 public bool UserOnline(ServerUser user)
 {
     if(!userDictionary.ContainsKey(user.userName))
     {
         userDictionary.Add(user.userName, user);
         user.MoveToUserGroup(lobby);
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 2
0
 public void UserOffline(ServerUser user)
 {
     if (userDictionary.ContainsKey(user.userName))
     {
         userDictionary.Remove(user.userName);
         user.MoveToUserGroup(null);
     }
 }
 private void LoginTask(OperationRequest operationRequest)
 {
     if (operationRequest.Parameters.Count != 1)
     {
         OperationResponse response = new OperationResponse
             (
                 operationRequest.OperationCode,
                 (byte)ReturnCode.InvalidParameter,
                 "LoginTask Parameter Error",
                 new Dictionary<byte, object>()
             );
         server.logger.Info(string.Format("{0} LoginTask Parameter Error", guid));
         SendResponse(response);
     }
     else
     {
         string userName = (string)operationRequest.Parameters[(byte)LoginParameterItem.UserName];
         if(server.UserOnline(user = new ServerUser(userName, false, this)))
         {
             LobbyUpdateBroadcast(server.lobby);
             Dictionary<byte, object> parameter = new Dictionary<byte, object>
             {
                 { (byte)LoginResponseItem.UserName, user.userName }
             };
             OperationResponse response = new OperationResponse
             (
                 operationRequest.OperationCode,
                 (byte)ReturnCode.Correct,
                 "",
                 parameter
             );
             server.logger.Info(string.Format("{0} 登入成功", user.userName));
             SendResponse(response);
         }
         else
         {
             OperationResponse response = new OperationResponse
                 (
                     operationRequest.OperationCode,
                     (byte)ReturnCode.InvalidOperation,
                     "此帳號已經登入!",
                     new Dictionary<byte, object>()
                 );
             server.logger.Info(string.Format("{0} 此帳號已經登入", guid));
             SendResponse(response);
         }
     }
 }