Esempio n. 1
0
        private void ExeRegister(ClientEvent eEvent)
        {
            //Log
            Log.Info("thread" + Thread.CurrentThread.ManagedThreadId + " exe reigister event", eEvent.Client.LogSource);

            //OP
            RegisterArgs      args   = ClientArgs.AnalysisBody <RegisterArgs>(eEvent.Body);
            DbResult <string> result = DbUserAction.Register(args.Name, args.Password, args.Sex, args.City, args.UserType);

            if (result.Status == DbEnum.Success)
            {
                eEvent.Client.Send(new ServerEvent()
                {
                    Type = Event_Type.Register, RawContent = ClientArgs.ToBody(new RegisterArgs()
                    {
                        User_ID = result.Data, ErrorCode = ClientArgs.ArgSuccess
                    }), SendTime = DateTime.Now.ToString()
                }.ToString());
            }
            else
            {
                eEvent.Client.Send(new ServerEvent()
                {
                    Type = Event_Type.Register, RawContent = ClientArgs.ToBody(new BadRequestArgs()
                    {
                        Code = result.ErrorCode, Message = result.Error
                    }), SendTime = DateTime.Now.ToString()
                }.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 退出登录状态,但是不断开socket连接,如果需要断开连接,客户端发送'exit<EOF>'即可
        /// </summary>
        /// <param name="eEvent"></param>
        private void ExeLogoutEvent(ClientEvent eEvent)
        {
            //Log
            Log.Info("thread" + Thread.CurrentThread.ManagedThreadId + " exe logout event", eEvent.Client.LogSource);

            //OP
            C_User cUser = ClientArgs.AnalysisBody <C_User>(eEvent.Body);

            //DB OP
            var result = DbUserAction.Logout(cUser.User_ID, eEvent.Client.Address.ToString(), eEvent.Client.Port);

            if (result.Status == DbEnum.Success)
            {
                //Log
                Log.Warn("update as Offline", eEvent.Client.LogSource);

                //status
                lock (eEvent.Client)
                {
                    eEvent.Client.Login = false;
                }

                //Send Back
                if (eEvent.Client.Socket.Connected)
                {
                    eEvent.Client.Send(NewEvent(Event_Type.Logout, result.Data).ToString());
                }
            }
            else
            {
                //Log
                Log.Warn(result.Error, eEvent.Client.LogSource);

                //Send Error Back
                eEvent.Client.Send(NewEvent(Event_Type.Logout, new BadRequestArgs()
                {
                    Code = result.ErrorCode, Message = result.Error
                }).ToString());
            }
        }
Esempio n. 3
0
        private void ExeLoginEvent(ClientEvent eEvent)
        {
            //Log
            Log.Info("thread" + Thread.CurrentThread.ManagedThreadId + " exe login event", eEvent.Client.LogSource);

            //OP
            LoginArgs loginArgs = ClientArgs.AnalysisBody <LoginArgs>(eEvent.Body);

            //DB OP
            var result = DbUserAction.Login(loginArgs.Name, loginArgs.Password, eEvent.Client.Address.ToString(), eEvent.Client.Port);

            if (result.Data.Success)
            {
                lock (eEvent.Client)
                {
                    eEvent.Client.Login = true;
                }

                eEvent.Client.Send(new ServerEvent()
                {
                    Type = Event_Type.Login, RawContent = ClientArgs.ToBody(result.Data), SendTime = DateTime.Now.ToString()
                }.ToString());
            }
            else
            {
                lock (eEvent.Client)
                {
                    eEvent.Client.Login = false;
                }
                eEvent.Client.Send(new ServerEvent()
                {
                    Type = Event_Type.Login, RawContent = ClientArgs.ToBody(new BadRequestArgs()
                    {
                        Code = result.ErrorCode, Message = result.Error
                    }), SendTime = DateTime.Now.ToString()
                }.ToString());
            }
        }