public static bool GetPosSizeXyz(BCMCmdArea command) { if (!int.TryParse(command.Pars[1], out var x) || !int.TryParse(command.Pars[2], out var y) || !int.TryParse(command.Pars[3], out var z)) { BCCommandAbstract.SendOutput("Unable to parse x,y,z into ints"); return(false); } if (!int.TryParse(command.Pars[4], out var x2) || !int.TryParse(command.Pars[5], out var y2) || !int.TryParse(command.Pars[6], out var z2)) { BCCommandAbstract.SendOutput("Unable to parse x2,y2,z2 into ints"); return(false); } command.Position = new BCMVector3(Math.Min(x, x2), Math.Min(y, y2), Math.Min(z, z2)); command.HasPos = true; command.Size = new BCMVector3(Math.Abs(x - x2) + 1, Math.Abs(y - y2) + 1, Math.Abs(z - z2) + 1); command.HasSize = true; command.ChunkBounds = new BCMVector4( World.toChunkXZ(Math.Min(x, x2)), World.toChunkXZ(Math.Min(z, z2)), World.toChunkXZ(Math.Max(x, x2)), World.toChunkXZ(Math.Max(z, z2)) ); command.HasChunkPos = true; return(true); }
public static void DoProcess(World world, BCMCmdArea command, BCCommandAbstract cmdRef) { if (command.Opts.ContainsKey("forcesync")) { BCCommandAbstract.SendOutput("Processing Command synchronously..."); ProcessCommand(world, command, cmdRef); return; } if (BCCommandAbstract.SenderInfo.NetworkConnection != null && !(BCCommandAbstract.SenderInfo.NetworkConnection is TelnetConnection)) { BCCommandAbstract.SendOutput("Processing Async Command... Sending output to log"); } else { BCCommandAbstract.SendOutput("Processing Async Command..."); } BCTask.AddTask( command.CmdType, ThreadManager.AddSingleTask( info => ProcessCommand(world, command, cmdRef), null, (info, e) => BCTask.DelTask(command.CmdType, info.GetHashCode())) .GetHashCode(), command); }
public static bool CheckWorld() { if (GameManager.Instance.World != null) { return(true); } BCCommandAbstract.SendOutput("World not loaded"); return(false); }
public static bool GetChunkPosXz(BCMCmdArea command) { if (!int.TryParse(command.Pars[1], out var x) || !int.TryParse(command.Pars[2], out var z)) { BCCommandAbstract.SendOutput("Unable to parse x,z into ints"); return(false); } command.ChunkBounds = new BCMVector4(x - command.Radius, z - command.Radius, x + command.Radius, z + command.Radius); command.HasChunkPos = true; return(true); }
public static bool GetChunkSizeXyzw(BCMCmdArea command) { if (!int.TryParse(command.Pars[1], out var x) || !int.TryParse(command.Pars[2], out var y) || !int.TryParse(command.Pars[3], out var z) || !int.TryParse(command.Pars[4], out var w)) { BCCommandAbstract.SendOutput("Unable to parse x,z x2,z2 into ints"); return(false); } command.ChunkBounds = new BCMVector4(Math.Min(x, z), Math.Min(y, w), Math.Max(x, z), Math.Max(y, w)); command.HasChunkPos = true; return(true); }
public static bool GetEntPos(BCMCmdArea command, EntityPlayer entity) { //todo: if /h=#,# then set y to pos + [0], y2 to pos + [1], if only 1 number then y=pos y2=pos+# if (entity != null) { var loc = new Vector3i(int.MinValue, 0, int.MinValue); var hasLoc = false; if (command.Opts.ContainsKey("loc")) { loc = BCLocation.GetPos(BCCommandAbstract.SenderInfo.RemoteClientInfo?.playerId); if (loc.x == int.MinValue) { BCCommandAbstract.SendOutput("No location stored or player not found. Use bc-loc to store a location."); return(false); } hasLoc = true; command.Position = new BCMVector3((int)entity.position.x, (int)entity.position.y, (int)entity.position.z); command.HasPos = true; command.Position = new BCMVector3(Math.Min(loc.x, (int)entity.position.x), Math.Min(loc.y, (int)entity.position.y), Math.Min(loc.z, (int)entity.position.z)); command.HasPos = true; command.Size = new BCMVector3( Math.Min(Math.Abs(loc.x - (int)entity.position.x), 1), Math.Min(Math.Abs(loc.y - (int)entity.position.y), 1), Math.Min(Math.Abs(loc.z - (int)entity.position.z), 1) ); command.HasSize = true; } command.ChunkBounds = new BCMVector4 { x = World.toChunkXZ(hasLoc ? Math.Min(loc.x, (int)entity.position.x) : (int)entity.position.x - command.Radius), y = World.toChunkXZ(hasLoc ? Math.Min(loc.z, (int)entity.position.z) : (int)entity.position.z - command.Radius), z = World.toChunkXZ(hasLoc ? Math.Max(loc.x, (int)entity.position.x) : (int)entity.position.x + command.Radius), w = World.toChunkXZ(hasLoc ? Math.Max(loc.z, (int)entity.position.z) : (int)entity.position.z + command.Radius) }; command.HasChunkPos = true; } else { BCCommandAbstract.SendOutput("Unable to get a position"); return(false); } return(true); }
public static void GetRadius(BCMCmdArea command, ushort max) { if (command.Opts.ContainsKey("r")) { ushort.TryParse(command.Opts["r"], out command.Radius); if (command.Radius > max) { command.Radius = max; } BCCommandAbstract.SendOutput($"Setting radius to +{command.Radius}"); } else { BCCommandAbstract.SendOutput("Setting radius to default of +0"); } }
public static bool GetPositionXyz(BCMCmdArea command) { if (!int.TryParse(command.Pars[1], out var x) || !int.TryParse(command.Pars[2], out var y) || !int.TryParse(command.Pars[3], out var z)) { BCCommandAbstract.SendOutput("Unable to parse x,y,z into ints"); return(false); } command.Position = new BCMVector3(x, y, z); command.HasPos = true; command.ChunkBounds = new BCMVector4(World.toChunkXZ(x), World.toChunkXZ(z), World.toChunkXZ(x), World.toChunkXZ(z)); command.HasChunkPos = true; return(!command.Opts.ContainsKey("item") || command.Command != "additem" || GetItemStack(command)); }
public static bool GetItemStack(BCMCmdArea command) { var quality = -1; var count = 1; if (command.Opts.ContainsKey("q")) { if (!int.TryParse(command.Opts["q"], out quality)) { BCCommandAbstract.SendOutput("Unable to parse quality, using random value"); } } if (command.Opts.ContainsKey("c")) { if (!int.TryParse(command.Opts["c"], out count)) { BCCommandAbstract.SendOutput($"Unable to parse count, using default value of {count}"); } } var ic = int.TryParse(command.Opts["item"], out var id) ? ItemClass.GetForId(id) : ItemData.GetForName(command.Opts["item"]); if (ic == null) { BCCommandAbstract.SendOutput($"Unable to get item or block from given value '{command.Opts["item"]}'"); return(false); } command.ItemStack = new ItemStack { itemValue = new ItemValue(ic.Id, true), count = count <= ic.Stacknumber.Value ? count : ic.Stacknumber.Value }; if (command.ItemStack.count < count) { BCCommandAbstract.SendOutput("Using max stack size for " + ic.Name + " of " + command.ItemStack.count); } if (command.ItemStack.itemValue.HasQuality && quality > 0) { command.ItemStack.itemValue.Quality = quality; } return(true); }
public static void ProcessCommand(World world, BCMCmdArea command, BCCommandAbstract cmdRef) { var affectedChunks = GetAffectedChunks(command, world); if (affectedChunks == null) { BCCommandAbstract.SendOutput("Aborting, unable to load all chunks in area before timeout."); BCCommandAbstract.SendOutput("Use /timeout=#### to override the default 2000 millisecond limit, or wait for the requested chunks to finish loading and try again."); return; } var location = ""; if (command.HasPos) { location += $"Pos {command.Position.x} {command.Position.y} {command.Position.z} "; if (command.HasSize) { var maxPos = command.MaxPos; location += $"to {maxPos.x} {maxPos.y} {maxPos.z} "; } } if (command.HasChunkPos) { location += $"Chunks {command.ChunkBounds.x} {command.ChunkBounds.y} to {command.ChunkBounds.z} {command.ChunkBounds.w}"; } if (!string.IsNullOrEmpty(location)) { BCCommandAbstract.SendOutput(location); } cmdRef.ProcessSwitch(world, command, out var reload); //RELOAD CHUNKS FOR PLAYER(S) - If steamId is empty then all players in area will get reload if (reload != ReloadMode.None && !(command.Opts.ContainsKey("noreload") || command.Opts.ContainsKey("nr"))) { BCChunks.ReloadForClients(affectedChunks, reload == ReloadMode.Target ? command.SteamId : string.Empty); } }
public static Dictionary <long, Chunk> GetAffectedChunks(BCMCmdArea command, World world) { var modifiedChunks = new Dictionary <long, Chunk>(); var timeout = 2000; if (command.Opts.ContainsKey("timeout")) { if (command.Opts["timeout"] != null) { int.TryParse(command.Opts["timeout"], out timeout); } } ChunkObserver(command, world, timeout / 2000); //request any unloaded chunks in area for (var x = command.ChunkBounds.x; x <= command.ChunkBounds.z; x++) { for (var z = command.ChunkBounds.y; z <= command.ChunkBounds.w; z++) { var chunkKey = WorldChunkCache.MakeChunkKey(x, z); modifiedChunks.Add(chunkKey, null); } } var chunkCount = (command.ChunkBounds.z - command.ChunkBounds.x + 1) * (command.ChunkBounds.w - command.ChunkBounds.y + 1); var count = 0; var sw = Stopwatch.StartNew(); while (count < chunkCount && sw.ElapsedMilliseconds < timeout) { for (var x = command.ChunkBounds.x; x <= command.ChunkBounds.z; x++) { for (var z = command.ChunkBounds.y; z <= command.ChunkBounds.w; z++) { //check if already in list var chunkKey = WorldChunkCache.MakeChunkKey(x, z); if (modifiedChunks.ContainsKey(chunkKey) && modifiedChunks[chunkKey] != null) { continue; } //check if chunk has loaded if (!world.ChunkCache.ContainsChunkSync(chunkKey)) { continue; } modifiedChunks[chunkKey] = world.GetChunkSync(chunkKey) as Chunk; if (modifiedChunks[chunkKey] != null) { count++; } } } } sw.Stop(); if (count < chunkCount) { BCCommandAbstract.SendOutput($"Unable to load {chunkCount - count}/{chunkCount} chunks"); return(null); } BCCommandAbstract.SendOutput($"Loading {chunkCount} chunks took {Math.Round(sw.ElapsedMilliseconds / 1000f, 2)} seconds"); return(modifiedChunks); }