예제 #1
0
 private ServerEvent NewEvent(Event_Type type, ClientArgs args)
 {
     return(new ServerEvent()
     {
         Type = type, RawContent = ClientArgs.ToBody(args), SendTime = DateTime.Now.ToString()
     });
 }
예제 #2
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());
            }
        }
예제 #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());
            }
        }