コード例 #1
0
        public override void InitializePlayer()
        {
            if (_hasJoined)
            {
                return;
            }

            try
            {
                if (CertificateData.ExtraData.Xuid == null)
                {
                    Disconnect("§cAn §2§lXBOX§r §caccount required to login to §dSkytonia §eNetwork");
                    return;
                }

                if (Whitelist.IsEnabled() && !Whitelist.OnWhitelist(Username))
                {
                    Disconnect(Whitelist.GetWhitelistMessage());
                    return;
                }

                StatisticsCore.AddPlayer(CertificateData.ExtraData.Xuid, Username);

                //Sync retrieve any active punishments
                PlayerPunishments playerPunishments = PunishCore.GetPunishmentsFor(CertificateData.ExtraData.Xuid);
                Punishment        activePunishment  = playerPunishments.GetActive(PunishmentType.Ban);
                if (activePunishment != null)
                {
                    Disconnect("§cYou are currently banned from the §dSkytonia §eNetwork\n" +
                               $"§c({PunishmentMessages.GetNeatExpiryForPunishment(activePunishment)})\n" +
                               $"§cReason: {activePunishment.PunishReason}");
                    return;
                }

                BarHandler = new BarHandler(this);

                SetPlayerGroup(PlayerGroup.Player);

                _hasJoined = true;

                RunnableTask.RunTask(() =>
                {
                    new DatabaseAction().Query(
                        "SELECT `group_name` FROM player_groups WHERE `player_xuid`=@id",
                        (command) =>
                    {
                        command.Parameters.AddWithValue("@id", CertificateData.ExtraData.Xuid);
                    },
                        (reader) =>
                    {
                        PlayerGroup.ValueOf(reader.GetString(0), out var playerGroup);

                        if (playerGroup == null)
                        {
                            //Simply set, then update perms in the post-delegate
                            playerGroup = PlayerGroup.Player;
                        }

                        PlayerGroup = playerGroup;
                    },
                        new Action(delegate
                    {
                        //Update permission levels
                        SetPlayerGroup(PlayerGroup);

                        _isRankLoaded = true;
                        //SkyUtil.log($"Initialized as {PlayerGroup.GroupName}({CommandPermission})");

                        SetGameMode(GameMode.Adventure);

                        if (SkyCoreApi.GameType.Equals("hub") && PlayerGroup.IsAtLeast(PlayerGroup.Mvp))
                        {
                            SetAllowFly(true);
                        }

                        foreach (Action action in _postLoginActions)
                        {
                            action.Invoke();
                        }
                        _postLoginActions.Clear();

                        if (Username.Equals("OhBlihv") || Username.Equals("Erazeo"))
                        {
                            if (PlayerGroup != PlayerGroup.Admin)
                            {
                                SetPlayerGroup(PlayerGroup.Admin);
                                //SkyUtil.log($"Overriding {Username}'s group to Admin");
                            }
                        }

                        RunnableTask.RunTaskLater(() =>
                        {
                            SendTitle("§f", TitleType.Clear);
                            SendTitle("§f", TitleType.AnimationTimes, 6, 6, 20 * 10);
                            SendTitle("§f", TitleType.ActionBar, 6, 6, 20 * 10);
                            SendTitle("§f", TitleType.Title, 6, 6, 20 * 10);
                            SendTitle("§f", TitleType.SubTitle, 6, 6, 20 * 10);
                        }, 500);

                        //Traditional Loading

                        IsSpawned = true;

                        //Should already be in a 'GameLevel'.
                        //Check and force-spawn them in if they're missing.
                        if (Level is GameLevel level && !level.PlayerTeamDict.ContainsKey(Username))
                        {
                            level.AddPlayer(this);
                        }

                        GameInfo targetedGame = ExternalGameHandler.GetGameForIncomingPlayer(Username);
                        if (targetedGame != null && (!(Level is GameLevel) || !((GameLevel)Level).GameId.Equals(targetedGame.GameId)))
                        {
                            SkyCoreApi.GameModes[SkyCoreApi.GameType].InstantQueuePlayer(this, targetedGame);
                        }

                        //Search this players pending groups
                        new DatabaseAction().Query(
                            "SELECT `group_name` FROM player_pending_groups WHERE `player_name`=@name",
                            (command) => { command.Parameters.AddWithValue("@name", Username); },
                            (reader) =>
                        {
                            PlayerGroup.ValueOf(reader.GetString(0), out var playerGroup);

                            if (playerGroup == null)
                            {
                                return;
                            }

                            SetPlayerGroup(playerGroup);

                            new DatabaseAction().Execute(
                                "DELETE FROM player_pending_groups WHERE `player_name`=@name",
                                (command) => { command.Parameters.AddWithValue("@name", Username); },
                                null);

                            new DatabaseAction().Execute(
                                "INSERT INTO `player_groups`\n" +
                                "  (`player_xuid`, `group_name`)\n" +
                                "VALUES\n" +
                                "  (@xuid, @group)\n" +
                                "ON DUPLICATE KEY UPDATE\n" +
                                "  `player_xuid`    = VALUES(`player_xuid`),\n" +
                                "  `group_name`     = VALUES(`group_name`);",
                                (command) =>
                            {
                                command.Parameters.AddWithValue("@xuid", CertificateData.ExtraData.Xuid);
                                command.Parameters.AddWithValue("@group", PlayerGroup.GroupName);
                            },
                                null
                                );
                        },
                            null);
                    })
                        );
                });

                //Initialize once we've loaded the group etc.
                base.InitializePlayer();
            }