Beispiel #1
0
        public override void RunImpl()
        {
            if ((_client.Login1 != _login1) && (_client.Login2 != _login2))
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                return;
            }

            L2Server server = ServerThreadPool.Instance.Get(_serverId);

            if (server == null)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                return;
            }

            if (server.Connected == 0)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonServerMaintenance));
            }
            else
            {
                _client.Send(PlayOk.ToPacket(_client));
            }
        }
Beispiel #2
0
        public override void RunImpl()
        {
            if (_client.State != LoginClientState.AuthedLogin)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            if (_client.Key.LoginOkId1 != _loginOkID1 && _client.Key.LoginOkId2 != _loginOkID2)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            L2Server server = ServerThreadPool.Instance.Get(_serverId);

            if (server == null)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            if (server.Connected == 0)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonServerMaintenance));
                _client.Close();
                return;
            }

            _client.Send(PlayOk.ToPacket(_client));
        }
Beispiel #3
0
        public override void RunImpl()
        {
            CipherParameters key = _client.RsaPair._privateKey;
            RSAEngine        rsa = new RSAEngine();

            rsa.init(false, key);

            byte[] decrypt = rsa.processBlock(Raw, 0, 128);

            if (decrypt.Length < 128)
            {
                byte[] temp = new byte[128];
                Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length);
                decrypt = temp;
            }

            string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty);
            string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty);

            AccountModel account = AccountService.GetAccountByLogin(username);

            if (account == null)
            {
                if (Config.Config.Instance.ServerConfig.AutoCreate)
                {
                    account = AccountService.CreateAccount(username, L2Security.HashPassword(password));
                }
                else
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }
            }
            else
            {
                if (!AccountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password)))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }

                if (ServerThreadPool.Instance.LoggedAlready(username.ToLower()))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse));
                    _client.Close();
                    return;
                }
            }

            Random rnd = new Random();

            _client.ActiveAccount = account;
            _client.SetLoginPair(rnd.Next(), rnd.Next());
            _client.SetPlayPair(rnd.Next(), rnd.Next());

            _client.Send(LoginOk.ToPacket(_client));
        }
Beispiel #4
0
        public override void RunImpl()
        {
            if ((_client.Login1 != _login1) && (_client.Login2 != _login2))
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                return;
            }

            _client.Send(ServerList.ToPacket(_client));
        }
Beispiel #5
0
        public override async Task RunImpl()
        {
            if (_client.State != LoginClientState.AuthedGG)
            {
                await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));

                _client.Close();
                return;
            }

            byte[] decrypt = DecryptPacket();

            string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty);
            string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty);

            AccountContract account = await _accountService.GetAccountByLogin(username);

            if (account == null)
            {
                if (_config.ServerConfig.AutoCreate)
                {
                    account = await _accountService.CreateAccount(username, password);
                }
                else
                {
                    await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));

                    _client.Close();
                    return;
                }
            }
            else
            {
                if (!await _accountService.CheckIfAccountIsCorrect(username, password))
                {
                    await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));

                    _client.Close();
                    return;
                }

                if (LoginServer.ServiceProvider.GetService <ServerThreadPool>().LoggedAlready(account.AccountId))
                {
                    await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse));

                    _client.Close();
                    return;
                }
            }

            _client.ActiveAccount = account;

            _client.State = LoginClientState.AuthedLogin;
            _client.SendAsync(LoginOk.ToPacket(_client));
        }
Beispiel #6
0
        public override void RunImpl()
        {
            if (_client.State != LoginClientState.AuthedLogin)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            if (!_client.Key.CheckLoginOKIdPair(_loginOkID1, _loginOkID2))
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            _client.Send(ServerList.ToPacket(_client));
        }
Beispiel #7
0
        public override void RunImpl()
        {
            if (_client.State != LoginClientState.AuthedLogin)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            if (_client.Key.LoginOkId1 != _loginOkID1 && _client.Key.LoginOkId2 != _loginOkID2)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            _client.Send(ServerList.ToPacket(_client));
        }
Beispiel #8
0
        public override void RunImpl()
        {
            if (_client.State != LoginClientState.Connected)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            if (_sessionId == _client.SessionId)
            {
                _client.State = LoginClientState.AuthedGG;
                _client.Send(GGAuth.ToPacket(_client));
            }
            else
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
            }
        }
Beispiel #9
0
        public override async Task RunImpl()
        {
            if (_client.State != LoginClientState.AuthedLogin)
            {
                await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));

                _client.Close();
                return;
            }

            if (_client.Key.LoginOkId1 != _loginOkID1 || _client.Key.LoginOkId2 != _loginOkID2)
            {
                await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));

                _client.Close();
                return;
            }

            _client.SendAsync(ServerList.ToPacket(_client));
        }
Beispiel #10
0
        public UserSession Login(string userName, string password, string browserName, string ipAddress)
        {
            var result = new UserSession();

            try
            {
                var user = baseDbContext.Users.FirstOrDefault(x => x.UserName == userName && x.Password == password);
                if (user != null)
                {
                    result.UserId   = user.Id;
                    result.UserName = user.UserName;
                    if (user.UserType.Name.ToLower() == UserTypeNameConst.Admin.ToLower())
                    {
                        result.LstPermission = baseDbContext.Permissions.Select(x => x.Name).ToList();
                    }
                    else
                    {
                        //Lấy theo vai trò + loại người dùng
                        result.LstPermission = new List <string>();
                    }
                }
                else
                {
                    var loginFail = new LoginFail
                    {
                        Id        = Guid.NewGuid().ToString(),
                        IpAddress = ipAddress,
                        Browser   = browserName,
                        UserName  = userName
                    };
                    baseDbContext.LoginFails.Add(loginFail);
                    baseDbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                result = new UserSession();
            }
            return(result);
        }
Beispiel #11
0
        public override async Task RunImpl()
        {
            if (_client.State != LoginClientState.AuthedLogin)
            {
                await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));

                _client.Close();
                return;
            }

            if (_client.Key.LoginOkId1 != _loginOkID1 || _client.Key.LoginOkId2 != _loginOkID2)
            {
                await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));

                _client.Close();
                return;
            }

            L2Server server = LoginServer.ServiceProvider.GetService <ServerThreadPool>().Get(_serverId);

            if (server == null)
            {
                await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));

                _client.Close();
                return;
            }

            if (!server.Connected)
            {
                await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonServerMaintenance));

                _client.Close();
                return;
            }

            await server.Thread.SendPlayer(_client);

            _client.SendAsync(PlayOk.ToPacket(_client));
        }
Beispiel #12
0
        public override async Task RunImpl()
        {
            await Task.Run(() =>
            {
                if (_client.State != LoginClientState.Connected)
                {
                    _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                    _client.Close();
                    return;
                }

                if (_sessionId == _client.SessionId)
                {
                    _client.State = LoginClientState.AuthedGG;
                    _client.SendAsync(GGAuth.ToPacket(_client));
                }
                else
                {
                    _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                    _client.Close();
                }
            });
        }
Beispiel #13
0
        public override void RunImpl()
        {
            if (_client.State != LoginClientState.AuthedGG)
            {
                _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed));
                _client.Close();
                return;
            }

            var       key = _client.RsaPair._privateKey;
            RSAEngine rsa = new RSAEngine();

            rsa.init(false, key);

            byte[] decrypt = rsa.processBlock(Raw, 0, 128);

            if (decrypt.Length < 128)
            {
                byte[] temp = new byte[128];
                Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length);
                decrypt = temp;
            }

            string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty);
            string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty);

            AccountContract account = _accountService.GetAccountByLogin(username);

            if (account == null)
            {
                if (_config.ServerConfig.AutoCreate)
                {
                    account = _accountService.CreateAccount(username, L2Security.HashPassword(password));
                }
                else
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }
            }
            else
            {
                if (!_accountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password)))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong));
                    _client.Close();
                    return;
                }

                if (LoginServer.ServiceProvider.GetService <ServerThreadPool>().LoggedAlready(username.ToLower()))
                {
                    _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse));
                    _client.Close();
                    return;
                }
            }

            _client.ActiveAccount = account;

            _client.State = LoginClientState.AuthedLogin;
            _client.Send(LoginOk.ToPacket(_client));
        }
Beispiel #14
0
        public void Response(Proto.Packet packet)
        {
            IUpperReceivedCmd cmd = null;

            switch (packet.Type) //Packet→Cmd
            {
            case 0:
                cmd = new HBReq();
                break;

            case 1:
                //客户端主动发心跳的回复,不需操作
                break;

            case 111:
                cmd = new News();
                break;

            case 112:
                cmd = new StopNews();
                break;

            case 121:
                cmd = new Poster();
                break;

            case 1002:
                cmd = new LoginOk();
                break;

            case 1003:
                cmd = new LoginFail();
                break;

            case 1102:
                cmd = new Config();
                break;

                #region 2000+
            case 2002:
                cmd = new EditUserInfoResult();
                break;

            case 2004:
                cmd = new NicknameProvided();
                break;

            case 2012:
                cmd = new UserHeartInfo();
                break;

            case 2022:
                cmd = new UpgradeSkillOk();
                break;

            case 2023:
                cmd = new UpgradeSkillFail();
                break;

            case 2025:
                cmd = new UpgradeVegetableOk();
                break;

            case 2026:
                cmd = new UpgradeVegetableFail();
                break;

            case 2032:
                cmd = new BuyCharacterOk();
                break;

            case 2033:
                cmd = new BuyCharacterFail();
                break;

            case 2042:
                cmd = new SpeedUpVegetableUpgradeOk();
                break;

            case 2043:
                cmd = new SpeedUpVegetableUpgradeFail();
                break;

            case 2102:
                cmd = new ExchangeOk();
                break;

            case 2103:
                cmd = new ExchangeFail();
                break;

            case 2202:
                cmd = new UseEquipOk();
                break;

            case 2203:
                cmd = new UseEquipFail();
                break;

            case 2212:
                cmd = new ChangeCharacterOk();
                break;

            case 2213:
                cmd = new ChangeCharacterFail();
                break;

            case 2222:
                cmd = new UserVegetable();
                break;

            case 2223:
                cmd = new RequestUserVegetableFail();
                break;

            case 2232:
                cmd = new UserMailList();
                break;

            case 2242:
                cmd = new RequestMailGiftOK();
                break;

            case 2243:
                cmd = new RequestMailGiftFail();
                break;

            case 2301:
                cmd = new NeedOAuthInfo();
                break;

            case 2303:
                cmd = new BindOAuthInfoOk();
                break;

            case 2304:
                cmd = new BindOAuthInfoFail();
                break;

            case 2312:
                cmd = new SNSFriendInfoList();
                break;

            case 2322:
                cmd = new RandomTeamMemberList();
                break;

                #endregion
            case 10003:
                cmd = new MatchOk();
                break;

            case 10004:
                cmd = new MatchFail();
                break;

            case 10021:
                cmd = new StartRound();
                break;

            case 10022:
                cmd = new EndRound();
                break;

            case 10023:
                cmd = new SyncData();
                break;

            case 10032:
                cmd = new UseSkillOk();
                break;

            case 10033:
                cmd = new UseSkillFail();
                break;

            case 10034:
                cmd = new RivalUseSkill();
                break;

                #region 挑战
            case 10102:
                cmd = new RequestChallengeOk();
                break;

            case 10103:
                cmd = new RequestChallengeFail();
                break;

            case 10105:
                cmd = new StartChallenge();
                break;

            case 10106:
                cmd = new RequestStartChallengeFail();
                break;

            case 10108:
                cmd = new UploadChallengeOk();
                break;

            case 10109:
                cmd = new UploadChallengeFail();
                break;

                #endregion
                #region 排行榜
            case 10202:
                cmd = new Leaderboard();
                break;

                #endregion
            default:
                Debug.LogError("未处理的Cmd:" + packet.Type);
                break;
            }
            if (cmd != null)
            {
                try
                {
                    if (packet.Content != null)
                    {
                        cmd.ParseFrom(packet.Content);
                    }
                    Debug.Log(string.Format("{0}:{1}", cmd.GetType().Name, cmd));
                    Execute(cmd);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }
        }