// Remove player from the list, and notify remaining players public void UnregisterPlayer(Player player) { if (player == null) { log.Log("World.UnregisterPlayer: Trying to unregister a non-existent (null) player.", LogType.Debug); return; } lock ( playerListLock ) { if (players[player.id] == player) { log.Log("{0} left the server.", LogType.UserActivity, player.name); db.ProcessLogout(player); db.Save(); players[player.id] = null; playerCount--; SendToAll(PacketWriter.MakeRemoveEntity(player.id), null); SendToAll(PacketWriter.MakeMessage(Color.Sys + player.name + " left the server."), null); UpdatePlayerList(); } else { log.Log("World.UnregisterPlayer: Trying to unregister a non-existent (unknown id) player.", LogType.Warning); } } }
static void ImportRanks(Player player, CommandReader cmd) { string serverName = cmd.Next(); string fileName = cmd.Next(); string rankName = cmd.Next(); bool silent = (cmd.Next() != null); // Make sure all parameters are specified if (serverName == null || fileName == null || rankName == null) { CdImport.PrintUsage(player); return; } // Check if file exists if (!File.Exists(fileName)) { player.Message("File not found: {0}", fileName); return; } Rank targetRank = RankManager.FindRank(rankName); if (targetRank == null) { player.MessageNoRank(rankName); return; } string[] names; switch (serverName.ToLower()) { case "mcsharp": case "mczall": case "mclawl": try { names = File.ReadAllLines(fileName); } catch (Exception ex) { Logger.Log(LogType.Error, "Could not open \"{0}\" to import ranks: {1}", fileName, ex); return; } break; default: player.Message("fCraft does not support importing from {0}", serverName); return; } if (!cmd.IsConfirmed) { player.Confirm(cmd, "Import {0} player ranks from \"{1}\"?", names.Length, Path.GetFileName(fileName)); return; } string reason = "(Import from " + serverName + ")"; foreach (string name in names) { PlayerInfo info = PlayerDB.FindExact(name) ?? PlayerDB.AddUnrecognizedPlayer(name, RankChangeType.Promoted); try { info.ChangeRank(player, targetRank, reason, !silent, true, false); } catch (PlayerOpException ex) { player.Message(ex.MessageColored); } } PlayerDB.Save(); }
static void ImportBans(Player player, CommandReader cmd) { string serverName = cmd.Next(); string fileName = cmd.Next(); // Make sure all parameters are specified if (serverName == null || fileName == null) { CdImport.PrintUsage(player); return; } // Check if file exists if (!File.Exists(fileName)) { player.Message("File not found: {0}", fileName); return; } string[] names; switch (serverName.ToLower()) { case "mcsharp": case "mczall": case "mclawl": try { names = File.ReadAllLines(fileName); } catch (Exception ex) { Logger.Log(LogType.Error, "Could not open \"{0}\" to import bans: {1}", fileName, ex); return; } break; default: player.Message("fCraft does not support importing from {0}", serverName); return; } if (!cmd.IsConfirmed) { player.Confirm(cmd, "Import {0} bans from \"{1}\"?", names.Length, Path.GetFileName(fileName)); return; } string reason = "(import from " + serverName + ")"; foreach (string name in names) { if (Player.IsValidName(name)) { PlayerInfo info = PlayerDB.FindExact(name) ?? PlayerDB.AddUnrecognizedPlayer(name, RankChangeType.Default); info.Ban(player, reason, true, true); } else { IPAddress ip; if (IPAddressUtil.IsIP(name) && IPAddress.TryParse(name, out ip)) { ip.BanIP(player, reason, true, true); } else { player.Message("Could not parse \"{0}\" as either name or IP. Skipping.", name); } } } PlayerDB.Save(); IPBanList.Save(); }