public JoinWorld ( [ newWorld, WorldChangeReason reason ) : void | ||
newWorld | [ | |
reason | WorldChangeReason | |
return | void |
public static void RevertGun() //Reverts names for online players. Offline players get reverted upon leaving the game { List <PlayerInfo> FFAPlayers = new List <PlayerInfo>(PlayerDB.PlayerInfoList.Where(r => (r.isPlayingFFA) && r.IsOnline).ToArray()); foreach (PlayerInfo pI in FFAPlayers) { Player p = pI.PlayerObject; p.JoinWorld(p.World, WorldChangeReason.Rejoin); //reset all special messages if (p.SupportsMessageTypes) { p.Send(PacketWriter.MakeSpecialMessage((byte)100, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)1, "&f")); p.Send(PacketWriter.MakeSpecialMessage((byte)2, "&f")); } pI.isPlayingFFA = false; if (pI != null) { //undo gunmode (taken from GunHandler.cs) p.GunMode = false; try { foreach (Vector3I block in p.GunCache.Values) { p.Send(PacketWriter.MakeSetBlock(block.X, block.Y, block.Z, p.WorldMap.GetBlock(block))); Vector3I removed; p.GunCache.TryRemove(block.ToString(), out removed); } if (p.bluePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.bluePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.blueOld[j])); j++; } } p.blueOld.Clear(); p.bluePortal.Clear(); } if (p.orangePortal.Count > 0) { int j = 0; foreach (Vector3I block in p.orangePortal) { if (p.WorldMap != null && p.World.IsLoaded) { p.WorldMap.QueueUpdate(new BlockUpdate(null, block, p.orangeOld[j])); j++; } } p.orangeOld.Clear(); p.orangePortal.Clear(); } } catch (Exception ex) { Logger.Log(LogType.SeriousError, "" + ex); } if (p.IsOnline) { p.Message("Your status has been reverted."); } } } }
static void TeleportHandler( Player player, CommandReader cmd ) { string name = cmd.Next(); if( name == null ) { CdTeleport.PrintUsage( player ); return; } if( cmd.Next() != null ) { cmd.Rewind(); int x, y, z; if( cmd.NextInt( out x ) && cmd.NextInt( out y ) && cmd.NextInt( out z ) ) { if( x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024 ) { player.Message( "Coordinates are outside the valid range!" ); } else { player.TeleportTo( new Position { X = (short)(x * 32 + 16), Y = (short)(y * 32 + 16), Z = (short)(z * 32 + 16), R = player.Position.R, L = player.Position.L } ); } } else { CdTeleport.PrintUsage( player ); } } else { if( name == "-" ) { if( player.LastUsedPlayerName != null ) { name = player.LastUsedPlayerName; } else { player.Message( "Cannot repeat player name: you haven't used any names yet." ); return; } } Player[] matches = Server.FindPlayers( player, name, false, true, true ); if( matches.Length == 1 ) { Player target = matches[0]; World targetWorld = target.World; if( targetWorld == null ) PlayerOpException.ThrowNoWorld( target ); if( targetWorld == player.World ) { player.TeleportTo( target.Position ); } else { switch( targetWorld.AccessSecurity.CheckDetailed( player.Info ) ) { case SecurityCheckResult.Allowed: case SecurityCheckResult.WhiteListed: if( targetWorld.IsFull ) { player.Message( "Cannot teleport to {0}&S because world {1}&S is full.", target.ClassyName, targetWorld.ClassyName ); return; } player.StopSpectating(); player.JoinWorld( targetWorld, WorldChangeReason.Tp, target.Position ); break; case SecurityCheckResult.BlackListed: player.Message( "Cannot teleport to {0}&S because you are blacklisted on world {1}", target.ClassyName, targetWorld.ClassyName ); break; case SecurityCheckResult.RankTooLow: player.Message( "Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName ); break; } } } else if( matches.Length > 1 ) { player.MessageManyMatches( "player", matches ); } else { player.MessageNoPlayer( name ); } } }
static void BackHandler(Player player, Command cmd) { if (player.previousLocation == null) { player.Message("&cYou haven't been teleported somewhere yet!"); return; } else { player.Message("&aTeleporting you back to your previous location..."); if (player.previousWorld == null) { player.TeleportTo(player.previousLocation); } else { player.JoinWorld(player.previousWorld, WorldChangeReason.ManualJoin); player.TeleportTo(player.previousLocation); } return; } }
static void RejoinHandler(Player player, Command cmd) { player.JoinWorld(player.World, WorldChangeReason.Rejoin); }
private static void BackHandler(Player player, CommandReader cmd) { if (player.LastPosition == null || player.LastWorld == null) { player.Message("Unknown last location!"); return; } if (player.LastWorld != player.World) { player.JoinWorld(player.LastWorld, WorldChangeReason.ManualJoin, player.LastPosition); } else { player.TeleportTo(player.LastPosition); player.Message("Teleported to last location!"); } }
static void SpectateHandler( Player player, Command cmd ) { string targetName = cmd.Next(); if( targetName == null ) { PlayerInfo lastSpec = player.LastSpectatedPlayer; if( lastSpec != null ) { Player spec = player.SpectatedPlayer; if( spec != null ) { if (spec.World.Name != player.World.Name) { player.JoinWorld(spec.World, WorldChangeReason.SpectateTargetJoined); player.Message("Joined " + spec.World.Name + " to continue spectating " + spec.ClassyName); } player.Message( "Now spectating {0}", spec.ClassyName ); } else { player.Message( "Last spectated {0}", lastSpec.ClassyName ); } } else { CdSpectate.PrintUsage( player ); } return; } Player target = Server.FindPlayerOrPrintMatches( player, targetName, false, true ); if( target == null ) return; if( target == player ) { player.Message( "You cannot spectate yourself." ); return; } if( !player.Can( Permission.Spectate, target.Info.Rank ) ) { player.Message( "You may only spectate players ranked {0}&S or lower.", player.Info.Rank.GetLimit( Permission.Spectate ).ClassyName ); player.Message( "{0}&S is ranked {1}", target.ClassyName, target.Info.Rank.ClassyName ); return; } if( !player.Spectate( target ) ) { player.Message( "Already spectating {0}", target.ClassyName ); } }
private static void TeleportHandler(Player player, CommandReader cmd) { string name = cmd.Next(); if (name == null) { CdTeleport.PrintUsage(player); return; } if (player.World.Name.ToLower() == "maze") { player.Message("Hey no cheating!"); return; } if (name == "zone") { string zoneName = cmd.Next(); if (zoneName == null) { player.Message("No zone name specified. See &H/Help tpzone"); return; } else { Zone zone = player.World.Map.Zones.Find(zoneName); if (zone == null) { player.MessageNoZone(zoneName); return; } int zoneX = (zone.Bounds.XMin + zone.Bounds.XMax)/2; int zoneY = (zone.Bounds.YMin + zone.Bounds.YMax)/2; int zoneZ = (zone.Bounds.ZMin + zone.Bounds.ZMax)/2; retry2: if (player.World.map.GetBlock(zoneX, zoneY, zoneZ - 1) == Block.Air) { zoneZ = zoneZ - 1; goto retry2; } retry: if (player.World.map.GetBlock(zoneX, zoneY, zoneZ) != Block.Air || player.World.map.GetBlock(zoneX, zoneY, zoneZ + 1) != Block.Air) { zoneZ = zoneZ + 1; goto retry; } Position zPos = new Position((zoneX) * 32 + 16, (zoneY) * 32 + 16, (zoneZ) * 32 + 64); if (player.World != null) { player.LastWorld = player.World; player.LastPosition = player.Position; } player.TeleportTo((zPos)); player.Message("&sTeleporting you to zone " + zone.ClassyName); return; } } if (name == "random" || name == "rand") { Random rand = new Random(); int x = rand.Next(0, player.WorldMap.Width); int y = rand.Next(0, player.WorldMap.Length); int z = player.Position.Z/32 + 1; retry2: if (player.World.map.GetBlock(x, y, z - 3) == Block.Air) { z = z - 1; goto retry2; } retry: if (player.World.map.GetBlock(x, y, z - 2) != Block.Air || player.World.map.GetBlock(x, y, z - 1) != Block.Air) { z = z + 1; goto retry; } if (player.World != null) { player.LastWorld = player.World; player.LastPosition = player.Position; } player.TeleportTo(new Position { X = (short) (x*32 + 16), Y = (short) (y*32 + 16), Z = (short) (z*32 + 16), R = player.Position.R, L = player.Position.L }); player.Message("Teleported to: ({0}, {1}, {2})", x, y, z); return; } if (cmd.Next() != null) { cmd.Rewind(); int x, y, z, rot, lot; rot = player.Position.R; lot = player.Position.L; if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) { if (cmd.HasNext) { if (cmd.HasNext) { if (cmd.NextInt(out rot) && cmd.NextInt(out lot)) { if (rot > 255 || rot < 0) { player.Message("R must be inbetween 0 and 255. Set to player R"); } if (lot > 255 || lot < 0) { player.Message("L must be inbetween 0 and 255. Set to player L"); } } } } if (x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024) { player.Message("Coordinates are outside the valid range!"); } else { if (player.World != null) { player.LastWorld = player.World; player.LastPosition = player.Position; } player.TeleportTo(new Position { X = (short) (x*32 + 16), Y = (short) (y*32 + 16), Z = (short) (z*32 + 48), R = (byte) rot, L = (byte) lot }); } } else { CdTeleport.PrintUsage(player); } } else { if (name == "-") { if (player.LastUsedPlayerName != null) { name = player.LastUsedPlayerName; } else { player.Message("Cannot repeat player name: you haven't used any names yet."); return; } } Player[] matches = Server.FindPlayers(player, name, SearchOptions.Default); if (matches.Length == 1) { Player target = matches[0]; World targetWorld = target.World; if (targetWorld == null) PlayerOpException.ThrowNoWorld(target); if (target.Info.TPDeny && target.Info.Rank >= player.Info.Rank) { player.Message("&CThis player does not want people teleporting to them"); player.Message("Cannot teleport to {0}&S.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); return; } if (targetWorld == player.World) { if (player.World != null) { player.LastWorld = player.World; player.LastPosition = player.Position; } player.TeleportTo(target.Position); } else { if (targetWorld.Name.StartsWith("PW_") && !targetWorld.AccessSecurity.ExceptionList.Included.Contains(player.Info)) { player.Message( "You cannot join due to that player being in a personal world that you cannot access."); return; } switch (targetWorld.AccessSecurity.CheckDetailed(player.Info)) { case SecurityCheckResult.Allowed: case SecurityCheckResult.WhiteListed: if (player.Info.Rank.Name == "Banned") { player.Message("&CYou can not change worlds while banned."); player.Message("Cannot teleport to {0}&S.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } if (targetWorld.IsFull) { player.Message("Cannot teleport to {0}&S because world {1}&S is full.", target.ClassyName, targetWorld.ClassyName); player.Message("Cannot teleport to {0}&S.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } player.StopSpectating(); player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position); break; case SecurityCheckResult.BlackListed: player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}", target.ClassyName, targetWorld.ClassyName); break; case SecurityCheckResult.RankTooLow: if (player.Info.Rank.Name == "Banned") { player.Message("&CYou can not change worlds while banned."); player.Message("Cannot teleport to {0}&S.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } if (targetWorld.IsFull) { if (targetWorld.IsFull) { player.Message("Cannot teleport to {0}&S because world {1}&S is full.", target.ClassyName, targetWorld.ClassyName); player.Message("Cannot teleport to {0}&S.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } player.StopSpectating(); player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position); break; } player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } } } else if (matches.Length > 1) { player.MessageManyMatches("player", matches); } } }
private static void MWHandler(Player player, CommandReader cmd) { switch (cmd.Next()) { #region Create case "create": case "c": string sizeStringc = cmd.Next(); int sizec; if (sizeStringc == null) { sizeStringc = "Normal"; } switch (sizeStringc.ToLower()) { case "64": case "tiny": sizec = 64; sizeStringc = "Tiny"; break; case "128": case "normal": sizec = 128; sizeStringc = "Normal"; break; case "256": case "large": sizec = 256; sizeStringc = "Large"; break; case "512": case "huge": sizec = 512; sizeStringc = "Huge"; break; default: sizec = 128; sizeStringc = "Normal"; break; } World[] totalc = WorldManager.FindWorlds(Player.Console, "PW_" + player.Name + "_"); if (totalc.Count() >= player.Info.Rank.MaxPersonalWorlds && player.Info.Rank != RankManager.HighestRank) { player.Message("You can only have a maximum of {0} personal worlds. Sorry!", player.Info.Rank.MaxPersonalWorlds); break; } string worldNamec = string.Format("PW_{0}_{1}", player.Name, (totalc.Any()) ? "" + (totalc.Count() + 1) : "1"); player.Message("Creating your {0}({1}) personal world: {2}", sizeStringc, sizec, worldNamec); Map map = MapGenerator.GenerateFlatgrass(sizec, sizec, sizec); Server.RequestGC(); if (map.Save("./Maps/" + worldNamec + ".fcm")) { player.Message("Done!. Saved to {0}.fcm", worldNamec); } else { player.Message("&WAn error occurred while saving generated map to {0}.fcm", worldNamec); } Rank buildRank = RankManager.HighestRank; Rank accessRank = RankManager.HighestRank; lock (WorldManager.SyncRoot) { World newWorld; try { newWorld = WorldManager.AddWorld(player, worldNamec, map, false); } catch (WorldOpException ex) { player.Message("WLoad: {0}", ex.Message); break; } player.LastUsedWorldName = worldNamec; newWorld.BuildSecurity.MinRank = buildRank; if (accessRank == null) { newWorld.AccessSecurity.ResetMinRank(); } else { newWorld.AccessSecurity.MinRank = accessRank; } newWorld.BlockDB.AutoToggleIfNeeded(); newWorld.LoadedBy = player.Name; newWorld.LoadedOn = DateTime.UtcNow; newWorld.IsHidden = true; Logger.Log(LogType.UserActivity, "{0} {1} &screated a new world named \"{2}\" (loaded from \"{3}\")", player.Info.Rank.Name, player.Name, worldNamec, worldNamec); newWorld.AccessSecurity.Include(player.Info); newWorld.BuildSecurity.Include(player.Info); newWorld.EdgeLevel = (short) (sizec/2); WorldManager.SaveWorldList(); } Server.RequestGC(); break; #endregion #region Reset case "reset": case "r": string wNumberStringr = cmd.Next(); int wNumberr; if (!int.TryParse(wNumberStringr, out wNumberr)) { wNumberr = 1; } string mapFiler = WorldManager.FindMapFile(Player.Console, "PW_" + player.Name + "_" + wNumberr); if (mapFiler == null) { player.Message("You have no personal worlds by that number: {0}", wNumberr); break; } if (!cmd.IsConfirmed) { player.Confirm(cmd, "This will reset your personal world: " + " PW_" + player.Name + "_" + wNumberr + "&n" + "&cThis cannot be undone!"); break; } World worldr = WorldManager.FindWorldExact("PW_" + player.Name + "_" + wNumberr); map = MapGenerator.GenerateFlatgrass(worldr.map.Width, worldr.map.Length, worldr.map.Height); worldr.MapChangedBy = player.Name; worldr.ChangeMap(map); player.Message("Your personal world({0}) has been reset to flatgrass!", wNumberr); Server.RequestGC(); break; #endregion #region Delete case "delete": case "d": case "remove": string wNumberStringd = cmd.Next(); int wNumberd; if (!int.TryParse(wNumberStringd, out wNumberd)) { wNumberd = 1; } string mapFiled = WorldManager.FindMapFile(Player.Console, "PW_" + player.Name + "_" + wNumberd); if (mapFiled == null) { player.Message("You have no personal worlds by that number: {0}", wNumberd); break; } if (!cmd.IsConfirmed) { player.Confirm(cmd, "This will delete your personal world: " + " PW_" + player.Name + "_" + wNumberd + "&n" + "&cThis cannot be undone!"); break; } World worldd = WorldManager.FindWorldExact("PW_" + player.Name + "_" + wNumberd); if (worldd != null) WorldManager.RemoveWorld(worldd); if (File.Exists("./maps/PW_" + player.Name + "_" + wNumberd + ".fcm")) { File.Delete("./maps/PW_" + player.Name + "_" + wNumberd + ".fcm"); } player.Message("Your personal world({0}) has been deleted!", wNumberd); Server.RequestGC(); break; #endregion #region Join case "j": case "join": string wNumberStringj = cmd.Next(); int wNumberj; if (!int.TryParse(wNumberStringj, out wNumberj)) { wNumberj = 1; } string playerStringj = cmd.Next(); PlayerInfo playerj = null; if (playerStringj != null) { playerj = PlayerDB.FindPlayerInfoOrPrintMatches(player, playerStringj, SearchOptions.Default); } string mapFilej = WorldManager.FindMapFile(Player.Console, "PW_" + ((playerj == null) ? player.Name : playerj.Name) + "_" + wNumberj); if (mapFilej == null) { player.Message("{0} no personal worlds by that number: {1}", (playerj == null) ? "You have" : "There are", wNumberj); break; } World worldj = WorldManager.FindWorldExact("PW_" + ((playerj == null) ? player.Name : playerj.Name) + "_" + wNumberj); if (worldj != null && player.CanJoin(worldj)) { player.JoinWorld(worldj, WorldChangeReason.ManualJoin); } else { player.Message("You cannot join that world!"); } break; #endregion #region BuildAccess case "buildaccess": case "ba": string wNumberStringba = cmd.Next(); string exceptionba = cmd.Next(); int wNumberba; bool changesWereMade = false; if (!int.TryParse(wNumberStringba, out wNumberba)) { wNumberba = 1; exceptionba = wNumberStringba; } string mapFileba = WorldManager.FindMapFile(Player.Console, "PW_" + player.Name + "_" + wNumberba); if (mapFileba == null) { player.Message("You have no personal worlds by that number: {0}", wNumberba); break; } World worldba = WorldManager.FindWorldExact("PW_" + player.Name + "_" + wNumberba); if (exceptionba == null) { CdMyWorld.PrintUsage(player); break; } if (exceptionba.Equals("-*")) { PlayerInfo[] oldWhitelistba = worldba.BuildSecurity.ExceptionList.Included.ToArray(); if (oldWhitelistba.Length > 0) { worldba.BuildSecurity.ResetIncludedList(); player.Message("Build whitelist of personal world {0}&S cleared: {1}", worldba.ClassyName, oldWhitelistba.JoinToClassyString()); Logger.Log(LogType.UserActivity, "{0} {1} &scleared build whitelist of personal world {2}: {3}", player.Info.Rank.Name, player.Name, worldba.Name, oldWhitelistba.JoinToString(pi => pi.Name)); worldba.BuildSecurity.Include(player.Info); } else { player.Message("Build whitelist of personal world {0}&S is empty.", worldba.ClassyName); } goto saveba; } // Clear blacklist if (exceptionba.Equals("+*")) { PlayerInfo[] oldBlacklist = worldba.BuildSecurity.ExceptionList.Excluded.ToArray(); if (oldBlacklist.Length > 0) { worldba.BuildSecurity.ResetExcludedList(); player.Message("Build blacklist of personal world {0}&S cleared: {1}", worldba.ClassyName, oldBlacklist.JoinToClassyString()); Logger.Log(LogType.UserActivity, "{0} {1} &scleared build blacklist of personal world {2}: {3}", player.Info.Rank.Name, player.Name, worldba.Name, oldBlacklist.JoinToString(pi => pi.Name)); } else { player.Message("Build blacklist of personal world {0}&S is empty.", worldba.ClassyName); } goto saveba; } // Whitelisting individuals if (exceptionba.StartsWith("+")) { PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, exceptionba.Substring(1), SearchOptions.Default); if (info == null) return; // prevent players from whitelisting themselves to bypass protection if (player.Info == info) { goto saveba; } if (worldba.BuildSecurity.Check(info)) { player.Message("{0}&S is already allowed to build in {1}", info.ClassyName, worldba.ClassyName); goto saveba; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (worldba.BuildSecurity.Include(info)) { case PermissionOverride.Deny: if (worldba.BuildSecurity.Check(info)) { player.Message("{0}&S is no longer barred from building in {1}", info.ClassyName, worldba.ClassyName); if (target != null) { target.Message( "You can now build in personal world {0}&S (removed from blacklist by {1}&S).", worldba.ClassyName, player.ClassyName); } } else { player.Message( "{0}&S was removed from the build blacklist of {1}&S. " + "Player is still NOT allowed to build.", info.ClassyName, worldba.ClassyName); if (target != null) { target.Message( "You were removed from the build blacklist of world {0}&S by {1}&S. " + "You are still NOT allowed to build.", worldba.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the build blacklist of {2}", player.Name, info.Name, worldba.Name); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now allowed to build in {1}", info.ClassyName, worldba.ClassyName); if (target != null) { target.Message("You can now build in world {0}&S (whitelisted by {1}&S).", worldba.ClassyName, player.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the build whitelist on personal world {2}", player.Name, info.Name, worldba.Name); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is already on the build whitelist of {1}", info.ClassyName, worldba.ClassyName); break; } // Blacklisting individuals } else if (exceptionba.StartsWith("-")) { PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, exceptionba.Substring(1), SearchOptions.Default); if (info == null) return; if (!worldba.BuildSecurity.Check(info)) { player.Message("{0}&S is already barred from building in {1}", info.ClassyName, worldba.ClassyName); goto saveba; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (worldba.BuildSecurity.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already on build blacklist of {1}", info.ClassyName, worldba.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now barred from building in {1}", info.ClassyName, worldba.ClassyName); if (target != null) { target.Message("&WYou were barred by {0}&W from building in personal world {1}", player.ClassyName, worldba.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the build blacklist on personal world {2}", player.Name, info.Name, worldba.Name); changesWereMade = true; break; case PermissionOverride.Allow: if (worldba.BuildSecurity.Check(info)) { player.Message( "{0}&S is no longer on the build whitelist of {1}&S. " + "Player is still allowed to build.", info.ClassyName, worldba.ClassyName); if (target != null) { target.Message( "You were removed from the build whitelist of personal world {0}&S by {1}&S. " + "You are still allowed to build.", worldba.ClassyName, player.ClassyName); } } else { player.Message("{0}&S is no longer allowed to build in {1}", info.ClassyName, worldba.ClassyName); if (target != null) { target.Message( "&WYou can no longer build in personal world {0}&W (removed from whitelist by {1}&W).", worldba.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the build whitelist on personal world {2}", player.Name, info.Name, worldba.Name); changesWereMade = true; break; } } saveba: if (changesWereMade) { WorldManager.SaveWorldList(); } break; #endregion #region JoinAccess case "ja": case "joinaccess": string wNumberStringja = cmd.Next(); string exceptionja = cmd.Next(); int wNumberja; bool changesWereMadeja = false; if (!int.TryParse(wNumberStringja, out wNumberja)) { wNumberja = 1; exceptionja = wNumberStringja; } string mapFileja = WorldManager.FindMapFile(Player.Console, "PW_" + player.Name + "_" + wNumberja); if (mapFileja == null) { player.Message("You have no personal worlds by that number: {0}", wNumberja); goto saveWorldja; } World worldja = WorldManager.FindWorldExact("PW_" + player.Name + "_" + wNumberja); if (exceptionja == null) { CdMyWorld.PrintUsage(player); break; } if (exceptionja.Equals("-*")) { PlayerInfo[] oldWhitelist = worldja.AccessSecurity.ExceptionList.Included.ToArray(); worldja.AccessSecurity.ResetIncludedList(); player.Message("Access whitelist of {0}&S cleared: {1}", worldja.ClassyName, oldWhitelist.JoinToClassyString()); Logger.Log(LogType.UserActivity, "{0} {1} &scleared access whitelist of personal world {2}: {3}", player.Info.Rank.Name, player.Name, worldja.Name, oldWhitelist.JoinToString(pi => pi.Name)); worldja.AccessSecurity.Include(player.Info); goto saveWorldja; } // Clear blacklist if (exceptionja.Equals("+*")) { PlayerInfo[] oldBlacklist = worldja.AccessSecurity.ExceptionList.Excluded.ToArray(); worldja.AccessSecurity.ResetExcludedList(); player.Message("Access blacklist of {0}&S cleared: {1}", worldja.ClassyName, oldBlacklist.JoinToClassyString()); Logger.Log(LogType.UserActivity, "{0} {1} &scleared access blacklist of personal world {2}: {3}", player.Info.Rank.Name, player.Name, worldja.Name, oldBlacklist.JoinToString(pi => pi.Name)); goto saveWorldja; } // Whitelisting individuals if (exceptionja.StartsWith("+")) { PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, exceptionja.Substring(1), SearchOptions.Default); if (info == null) goto saveWorldja; // prevent players from whitelisting themselves to bypass protection if (player.Info == info) { goto saveWorldja; } if (worldja.AccessSecurity.Check(info)) { player.Message("{0}&S is already allowed to access {1}", info.ClassyName, worldja.ClassyName); goto saveWorldja; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (worldja.AccessSecurity.Include(info)) { case PermissionOverride.Deny: if (worldja.AccessSecurity.Check(info)) { player.Message("{0}&S is no longer barred from accessing {1}", info.ClassyName, worldja.ClassyName); if (target != null) { target.Message( "You can now access personal world {0}&S (removed from blacklist by {1}&S).", worldja.ClassyName, player.ClassyName); } } else { player.Message( "{0}&S was removed from the access blacklist of {1}&S. " + "Player is still NOT allowed to join.", info.ClassyName, worldja.ClassyName); if (target != null) { target.Message( "You were removed from the access blacklist of world {0}&S by {1}&S. " + "You are still NOT allowed to join.", worldja.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the access blacklist of {2}", player.Name, info.Name, worldja.Name); changesWereMadeja = true; break; case PermissionOverride.None: player.Message("{0}&S is now allowed to access {1}", info.ClassyName, worldja.ClassyName); if (target != null) { target.Message("You can now access personal world {0}&S (whitelisted by {1}&S).", worldja.ClassyName, player.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the access whitelist on personal world {2}", player.Name, info.Name, worldja.Name); changesWereMadeja = true; break; case PermissionOverride.Allow: player.Message("{0}&S is already on the access whitelist of {1}", info.ClassyName, worldja.ClassyName); break; } // Blacklisting individuals } else if (exceptionja.StartsWith("-")) { PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, exceptionja.Substring(1), SearchOptions.Default); if (info == null) goto saveWorldja; if (!worldja.AccessSecurity.Check(info)) { player.Message("{0}&S is already barred from accessing {1}", info.ClassyName, worldja.ClassyName); goto saveWorldja; } Player target = info.PlayerObject; if (target == player) target = null; // to avoid duplicate messages switch (worldja.AccessSecurity.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already on access blacklist of {1}", info.ClassyName, worldja.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now barred from accessing {1}", info.ClassyName, worldja.ClassyName); if (target != null) { target.Message("&WYou were barred by {0}&W from accessing personal world {1}", player.ClassyName, worldja.ClassyName); } Logger.Log(LogType.UserActivity, "{0} added {1} to the access blacklist on personal world {2}", player.Name, info.Name, worldja.Name); changesWereMadeja = true; break; case PermissionOverride.Allow: if (worldja.AccessSecurity.Check(info)) { player.Message( "{0}&S is no longer on the access whitelist of {1}&S. " + "Player is still allowed to join.", info.ClassyName, worldja.ClassyName); if (target != null) { target.Message( "You were removed from the access whitelist of personal world {0}&S by {1}&S. " + "You are still allowed to join.", worldja.ClassyName, player.ClassyName); } } else { player.Message("{0}&S is no longer allowed to access {1}", info.ClassyName, worldja.ClassyName); if (target != null) { target.Message( "&WYou can no longer access personal world {0}&W (removed from whitelist by {1}&W).", worldja.ClassyName, player.ClassyName); } } Logger.Log(LogType.UserActivity, "{0} removed {1} from the access whitelist on personal world {2}", player.Name, info.Name, worldja.Name); changesWereMadeja = true; break; } } saveWorldja: if (changesWereMadeja) { worldja = WorldManager.FindWorldExact("PW_" + player.Name + "_" + wNumberja); var playersWhoCantStay = worldja.Players.Where(p => !p.CanJoin(worldja)); foreach (Player p in playersWhoCantStay) { p.Message("&WYou are no longer allowed to join world {0}", worldja.ClassyName); p.JoinWorld(WorldManager.FindMainWorld(p), WorldChangeReason.PermissionChanged); } WorldManager.SaveWorldList(); } break; #endregion #region List case "l": case "list": World[] worldsl = WorldManager.Worlds.Where(w => w.Name.StartsWith("PW_" + player.Name + "_")).ToArray(); World[] otherworldsl = WorldManager.Worlds.Where( w => w.Name.StartsWith("PW_") && w.AccessSecurity.ExceptionList.Included.Contains(player.Info) && !w.Name.StartsWith("PW_" + player.Name + "_")).ToArray(); if (worldsl.Any()) { player.Message("Your personal worlds: {0}", worldsl.JoinToClassyString()); } if (otherworldsl.Any()) { player.Message("Player personal worlds you have access to: {0}", otherworldsl.JoinToClassyString()); } if (!worldsl.Any() && !otherworldsl.Any()) { player.Message("You do not have access to any personal worlds."); } break; #endregion default: CdMyWorld.PrintUsage(player); break; } }
static void rejoinHandler(Player player, CommandReader cmd) { player.JoinWorld(player.World, WorldChangeReason.Rejoin, player.Position); }
private static void BotHandler(Player player, CommandReader cmd) { string option = cmd.Next(); if (string.IsNullOrEmpty(option)) { CdEntity.PrintUsage(player); return; } if (option.ToLower() == "list") { player.Message("_Entities on {0}_", ConfigKey.ServerName.GetString()); foreach (Bot botCheck in World.Bots) { player.Message(botCheck.Name + " on " + botCheck.World.Name); } return; } if (option.ToLower() == "removeall") { if (cmd.IsConfirmed) { foreach (Bot b in World.Bots) { b.World.Players.Send(Packet.MakeRemoveEntity(b.ID)); if (File.Exists("./Entities/" + b.Name.ToLower() + ".txt")) { File.Delete("./Entities/" + b.Name.ToLower() + ".txt"); } } World.Bots.Clear(); player.Message("All entities removed."); } else { player.Confirm(cmd, "This will remove all the entites everywhere, are you sure?"); } return; } //finally away from the special cases string botName = cmd.Next(); if (string.IsNullOrEmpty(botName)) { CdEntity.PrintUsage(player); return; } Bot bot = new Bot(); if (option != "create" && option != "add") { bot = World.FindBot(botName.ToLower()); if (bot == null) { player.Message( "Could not find {0}! Please make sure you spelled the entities name correctly. To view all the entities, type /ent list.", botName); return; } } Block blockmodel; switch (option.ToLower()) { case "create": case "add": string requestedModel = "humanoid"; if (cmd.HasNext) { requestedModel = cmd.Next().ToLower(); } if (!validEntities.Contains(requestedModel)) { if (Map.GetBlockByName(requestedModel, false, out blockmodel)) { requestedModel = blockmodel.GetHashCode().ToString(); } else { player.Message( "That wasn't a valid entity model! Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name."); return; } } //if a botname has already been chosen, ask player for a new name var matchingNames = from b in World.Bots where b.Name.ToLower() == botName.ToLower() select b; if (matchingNames.Count() > 0) { player.Message("An entity with that name already exists! To view all entities, type /ent list."); return; } string skinString1 = (cmd.Next() ?? botName); if (skinString1 != null) { if (skinString1.StartsWith("--")) { skinString1 = string.Format("http://minecraft.net/skin/{0}.png", skinString1.Replace("--", "")); } if (skinString1.StartsWith("-+")) { skinString1 = string.Format("http://skins.minecraft.net/MinecraftSkins/{0}.png", skinString1.Replace("-+", "")); } if (skinString1.StartsWith("++")) { skinString1 = string.Format("http://i.imgur.com/{0}.png", skinString1.Replace("++", "")); } } Bot botCreate = new Bot(); botCreate.setBot(botName, skinString1, requestedModel, player.World, player.Position, getNewID()); botCreate.createBot(); player.Message("Successfully created entity {0}&s with id:{1} and skin {2}.", botCreate.Name, botCreate.ID, skinString1 ?? bot.Name); break; case "remove": player.Message("{0} was removed from the server.", bot.Name); bot.removeBot(); break; case "model": if (cmd.HasNext) { string model = cmd.Next().ToLower(); string skinString2 = cmd.Next(); if (skinString2 != null) { if (skinString2.StartsWith("--")) { skinString2 = string.Format("http://minecraft.net/skin/{0}.png", skinString2.Replace("--", "")); } if (skinString2.StartsWith("-+")) { skinString2 = string.Format("http://skins.minecraft.net/MinecraftSkins/{0}.png", skinString2.Replace("-+", "")); } if (skinString2.StartsWith("++")) { skinString2 = string.Format("http://i.imgur.com/{0}.png", skinString2.Replace("++", "")); } } if (string.IsNullOrEmpty(model)) { player.Message( "Usage is /Ent model <bot> <model>. Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name."); break; } if (model == "human") { model = "humanoid"; } if (!validEntities.Contains(model)) { if (Map.GetBlockByName(model, false, out blockmodel)) { model = blockmodel.GetHashCode().ToString(); } else { player.Message( "That wasn't a valid entity model! Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name."); break; } } player.Message("Changed entity model to {0} with skin {1}.", model, skinString2 ?? bot.SkinName); bot.changeBotModel(model, skinString2 ?? bot.SkinName); } else player.Message( "Usage is /Ent model <bot> <model>. Valid models are chicken, creeper, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name."); break; case "bring": bot.teleportBot(player.Position); break; case "tp": case "teleport": World targetWorld = bot.World; Bot target = bot; if (targetWorld == player.World) { if (player.World != null) { player.LastWorld = player.World; player.LastPosition = player.Position; } player.TeleportTo(target.Position); } else { if (targetWorld.Name.StartsWith("PW_") && !targetWorld.AccessSecurity.ExceptionList.Included.Contains(player.Info)) { player.Message( "You cannot join due to that Bot being in a personal world that you cannot access."); break; } switch (targetWorld.AccessSecurity.CheckDetailed(player.Info)) { case SecurityCheckResult.Allowed: case SecurityCheckResult.WhiteListed: if (player.Info.Rank.Name == "Banned") { player.Message("&CYou can not change worlds while banned."); player.Message("Cannot teleport to {0}&S.", target.Name, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } if (targetWorld.IsFull) { player.Message("Cannot teleport to {0}&S because world {1}&S is full.", target.Name, targetWorld.ClassyName); player.Message("Cannot teleport to {0}&S.", target.Name, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } player.StopSpectating(); player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position); break; case SecurityCheckResult.BlackListed: player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}", target.Name, targetWorld.ClassyName); break; case SecurityCheckResult.RankTooLow: if (player.Info.Rank.Name == "Banned") { player.Message("&CYou can not change worlds while banned."); player.Message("Cannot teleport to {0}&S.", target.Name, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } if (targetWorld.IsFull) { if (targetWorld.IsFull) { player.Message("Cannot teleport to {0}&S because world {1}&S is full.", target.Name, targetWorld.ClassyName); player.Message("Cannot teleport to {0}&S.", target.Name, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } player.StopSpectating(); player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position); break; } player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.", target.Name, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; } } break; case "skin": string skinString3 = cmd.Next(); if (skinString3 != null) { if (skinString3.StartsWith("--")) { skinString3 = string.Format("http://minecraft.net/skin/{0}.png", skinString3.Replace("--", "")); } if (skinString3.StartsWith("-+")) { skinString3 = string.Format("http://skins.minecraft.net/MinecraftSkins/{0}.png", skinString3.Replace("-+", "")); } if (skinString3.StartsWith("++")) { skinString3 = string.Format("http://i.imgur.com/{0}.png", skinString3.Replace("++", "")); } } player.Message("Changed entity skin to {0}.", skinString3 ?? bot.Name); bot.changeBotSkin(skinString3); break; default: CdEntity.PrintUsage(player); break; } }
static void TPHandler2(Player player, Command cmd) { string name = cmd.Next(); if (name == null) { return; } if (cmd.Next() != null) { cmd.Rewind(); int x, y, z; if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) { if (x <= -1024 || x >= 1024 || y <= -1024 || y >= 1024 || z <= -1024 || z >= 1024) { player.Message("Coordinates are outside the valid range!"); } else { player.TeleportTo(new Position { X = (short)(x * 32 + 16), Y = (short)(y * 32 + 16), Z = (short)(z * 32 + 16), R = player.Position.R, L = player.Position.L }); } } else { return; } } else { Player[] matches = Server.FindPlayers(player, name, true); if (matches.Length == 1) { Player target = matches[0]; World targetWorld = target.World; if (targetWorld == null) PlayerOpException.ThrowNoWorld(target); if (targetWorld == player.World) { player.TeleportTo(target.Position); } else { switch (targetWorld.AccessSecurity.CheckDetailed(player.Info)) { case SecurityCheckResult.Allowed: case SecurityCheckResult.WhiteListed: if (targetWorld.IsFull) { player.Message("Cannot teleport to {0}&S because world {1}&S is full.", target.ClassyName, targetWorld.ClassyName); return; } player.StopSpectating(); player.JoinWorld(targetWorld, WorldChangeReason.Tp, target.Position); break; case SecurityCheckResult.BlackListed: player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}", target.ClassyName, targetWorld.ClassyName); break; case SecurityCheckResult.RankTooLow: player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.", target.ClassyName, targetWorld.ClassyName, targetWorld.AccessSecurity.MinRank.ClassyName); break; // TODO: case PermissionType.RankTooHigh: } } } else if (matches.Length > 1) { player.MessageManyMatches("player", matches); } else { // Try to guess if player typed "/TP" instead of "/Join" World[] worlds = WorldManager.FindWorlds(player, name); if (worlds.Length == 1) { player.LastUsedWorldName = worlds[0].Name; player.StopSpectating(); player.ParseMessage("/Join " + worlds[0].Name, false); } else { player.MessageNoPlayer(name); } } } }