public void OnDisable() { IsDisabled = true; if (!GameType.Equals("hub")) { foreach (Level level in Server.LevelManager.Levels) { foreach (MiNET.Player player in level.Players.Values) { ExternalGameHandler.AddPlayer(player as SkyPlayer, "hub"); } } Thread.Sleep(1000); } foreach (Level level in Server.LevelManager.Levels) { foreach (MiNET.Player player in level.Players.Values) { player.Disconnect(" §d§lSkytonia §f§lNetwork§r\n" + "§7Skytonia is currently rebooting, try joining again soon!"); } } RunnableTask.CancelAllTasks(); PunishCore.Close(); StatisticsCore.Close(); }
public void CommandKick(MiNET.Player player, string playerName, string[] reason) { if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Helper)) { player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); return; } RunnableTask.RunTask(() => { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } string punishReason = GetReasonFromArgs(reason); PunishCore.AddKick(targetXuid, punishReason, player.CertificateData.ExtraData.Xuid); SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); target?.Disconnect($"§cYou have been kicked from the server.\n" + $"§6Reason: {punishReason}"); player.SendMessage($"§f[PUNISH] §7{playerName} §chas been kicked for: §f\"{punishReason}\""); }); }
public void CommandUnban(MiNET.Player player, string playerName) { if (!(player is SkyPlayer skyPlayer) || !skyPlayer.PlayerGroup.IsAtLeast(PlayerGroup.Mod)) { player.SendMessage("§c§l(!)§r §cYou do not have permission for this command."); return; } RunnableTask.RunTask(() => { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } if (PunishCore.GetPunishmentsFor(targetXuid).RemoveActive(PunishmentType.Ban)) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been unbanned."); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not currently banned."); } }); }
private static void RunPunishmentCommand(MiNET.Player player, PunishmentType punishmentType, String playerName, string[] args) { string targetXuid = StatisticsCore.GetXuidForPlayername(playerName); if (targetXuid == null) { player.SendMessage($"§f[PUNISH] §7{playerName} §cis not a Skytonia user."); return; } args = ParseExpiryTime(player, args, out DurationUnit durationUnit, out int durationAmount); if (args == null) { return; //Message printed to player } string punishReason = GetReasonFromArgs(args); DateTime expiry = UpdateExpiryTime(durationUnit, durationAmount); Punishment punishment = new Punishment(punishReason, player.CertificateData.ExtraData.Xuid, true, durationAmount, durationUnit, expiry); PunishCore.AddPunishment(targetXuid, punishmentType, punishment); if (punishmentType == PunishmentType.Ban) { SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); if (durationUnit == DurationUnit.Permanent) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been banned permanently for: \"{punishReason}\""); target?.Disconnect(PunishmentMessages.GetPunishmentMessage(target, punishmentType, punishment)); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been banned for: §f{GetNeatDuration(durationAmount, durationUnit)} \"{punishReason}\""); target?.Disconnect(PunishmentMessages.GetPunishmentMessage(target, punishmentType, punishment)); } } else if (punishmentType == PunishmentType.Mute) { SkyPlayer target = SkyCoreAPI.Instance.GetPlayer(playerName); if (durationUnit == DurationUnit.Permanent) { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been muted permanently for: \"{punishReason}\""); target?.SendMessage(PunishmentMessages.GetPunishmentMessage(target, PunishmentType.Mute, punishment)); } else { player.SendMessage($"§f[PUNISH] §7{playerName} §chas been muted for: §f{GetNeatDuration(durationAmount, durationUnit)} \"{punishReason}\""); target?.SendMessage(PunishmentMessages.GetPunishmentMessage(target, PunishmentType.Mute, punishment)); } } }
private static void RunUpdateTask() { List <PendingUpdatePunishment> pendingUpdates = new List <PendingUpdatePunishment>(); DateTime currentTime = DateTime.Now; foreach (string playerXuid in PlayerPunishmentCache.Keys) { PlayerPunishments punishments = PlayerPunishmentCache[playerXuid]; foreach (PunishmentType punishmentType in punishments.Punishments.Keys) { foreach (Punishment punishment in punishments.Punishments[punishmentType]) { if (punishment.Dirty) { punishment.Dirty = false; pendingUpdates.Add(new PendingUpdatePunishment(playerXuid, punishmentType, punishment)); SkyUtil.log($"Marking {StatisticsCore.GetPlayerNameFromXuid(playerXuid)}'s {punishmentType} as non-dirty (saved)"); continue; } if (!punishment.IsActive()) { continue; } //Ensure this punishment is still active if (punishment.DurationUnit != DurationUnit.Permanent && currentTime.CompareTo(punishment.Expiry) >= 0) //TODO: Check if this is correct { SkyUtil.log($"Marking {StatisticsCore.GetPlayerNameFromXuid(playerXuid)}'s active {punishmentType} as inactive (expired)"); punishment.Active = false; pendingUpdates.Add(new PendingUpdatePunishment(playerXuid, punishmentType, punishment)); } else { if (punishment.DurationUnit == DurationUnit.Permanent) { SkyUtil.log($"{StatisticsCore.GetPlayerNameFromXuid(playerXuid)}'s active {punishmentType} is still active (PERMANENT)"); } else { SkyUtil.log($"{StatisticsCore.GetPlayerNameFromXuid(playerXuid)}'s active {punishmentType} is still active ({punishment.Expiry.Subtract(currentTime).ToString()} Remaining)"); } } } } } if (pendingUpdates.Count > 0) { new DatabaseBatch <PendingUpdatePunishment>( "INSERT INTO `punishments`\n" + " (`player_xuid`, `punish_type`, `issuer`, `reason`, `active`, `duration_amount`, `duration_unit`, `issue_time`)\n" + "VALUES\n" + " (@player_xuid, @punish_type, @issuer, @reason, @active, @duration_amount, @duration_unit, @issue_time)\n" + "ON DUPLICATE KEY UPDATE\n" + " `player_xuid` = VALUES(`player_xuid`),\n"+ " `punish_type` = VALUES(`punish_type`),\n"+ " `issuer` = VALUES(`issuer`),\n"+ " `reason` = VALUES(`reason`),\n"+ " `active` = VALUES(`active`),\n"+ " `duration_amount` = VALUES(`duration_amount`),\n" + " `duration_unit` = VALUES(`duration_unit`),\n" + " `issue_time` = VALUES(`issue_time`);", "punishments", (parameters) => { parameters.Add("@player_xuid", MySqlDbType.VarChar, 50, "player_xuid"); parameters.Add("@punish_type", MySqlDbType.VarChar, 4, "punish_type"); parameters.Add("@issuer", MySqlDbType.VarChar, 50, "issuer"); parameters.Add("@reason", MySqlDbType.VarChar, 128, "reason"); parameters.Add("@active", MySqlDbType.Int16, 1, "active"); parameters.Add("@duration_amount", MySqlDbType.Int16, 2, "duration_amount"); parameters.Add("@duration_unit", MySqlDbType.VarChar, 10, "duration_unit"); parameters.Add("@issue_time", MySqlDbType.DateTime, 10, "issue_time"); }, (dataRow, batchItem) => { dataRow["player_xuid"] = batchItem.PlayerXuid; dataRow["punish_type"] = batchItem.PunishmentType.ToString(); dataRow["issuer"] = batchItem.Punishment.Issuer; dataRow["reason"] = batchItem.Punishment.PunishReason; dataRow["active"] = batchItem.Punishment.Active; dataRow["duration_amount"] = batchItem.Punishment.DurationAmount; dataRow["duration_unit"] = batchItem.Punishment.DurationUnit; dataRow["issue_time"] = batchItem.Punishment.GetIssueDate(); return(true); }, null, pendingUpdates ).ExecuteBatch(); } }
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(); }