Exemplo n.º 1
0
        public override void OnOperateRequest(byte[] bytes, ClientPeer peer, SendParameters sendParameters)
        {
            Operation.UserInfo userInfo = PackageHelper.Desirialize <Operation.UserInfo>(bytes);
            Model.UserInfo     dbUser   = UserManager.GetByUserName(userInfo.username);

            if (dbUser == null)
            {
                return;
            }

            OperationResponse response = new OperationResponse((byte)OperationCode.Login);

            if (dbUser.Password == userInfo.password)
            {
                response.ReturnCode = (short)ReturnCode.Success;
            }
            else
            {
                response.ReturnCode = (short)ReturnCode.Failed;
            }
            LoginSuccessResponse obj = new LoginSuccessResponse();

            obj.userName = userInfo.username;
            PackageHelper.SetData(response, PackageHelper.Serialize <LoginSuccessResponse>(obj));
            peer.SendOperationResponse(response, sendParameters);

            GameApplication application = GameApplication.Instance as GameApplication;

            if (application != null)
            {
                application.AddClientInfo(peer as GameClientPeer, userInfo.username);
            }
        }
Exemplo n.º 2
0
 public static Model.UserInfo GetByUserName(string userName)
 {
     Model.UserInfo userInfo = null;
     using (ISession session = NHibernateHelper.OpenSession())
     {
         ICriteria criteria = session.CreateCriteria(typeof(Model.UserInfo));
         criteria.Add(Restrictions.Eq("UserName", userName));
         userInfo = criteria.UniqueResult <Model.UserInfo>();
     }
     return(userInfo);
 }
Exemplo n.º 3
0
 public static void Remove(Model.UserInfo user)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Delete(user);
             transaction.Commit();
         }
     }
 }
Exemplo n.º 4
0
 public static Model.UserInfo GetByID(int id)
 {
     Model.UserInfo userInfo = null;
     using (ISession session = NHibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             userInfo = session.Get <Model.UserInfo>(id);
             transaction.Commit();
         }
     }
     return(userInfo);
 }
Exemplo n.º 5
0
        public override void OnOperateRequest(byte[] bytes, ClientPeer peer, SendParameters sendParameters)
        {
            Operation.UserInfo userInfo = PackageHelper.Desirialize <Operation.UserInfo>(bytes);
            Model.UserInfo     dbUser   = UserManager.GetByUserName(userInfo.username);

            OperationResponse response = new OperationResponse((byte)OperationCode.Regist);

            if (dbUser != null)
            {
                response.ReturnCode = (short)ReturnCode.Failed;
            }
            else
            {
                dbUser = new Model.UserInfo()
                {
                    UserName = userInfo.username, Password = userInfo.password, RegisterDate = System.DateTime.Now
                };
                UserManager.Add(dbUser);
                response.ReturnCode = (short)ReturnCode.Success;
            }
            peer.SendOperationResponse(response, sendParameters);
        }