public void CreateTeleporter(string name, Vector3S start, Vector3S end, Vector3S dest, byte destLook, byte destRot, HypercubeMap destMap) { var newtp = new Teleporter { Name = name, Start = start, End = end, Dest = dest, DestLook = destLook, DestRot = destRot, DestinationMap = destMap, }; var myTp = _teleporters.Find(o => o.Name == name); // -- Linq is so hacky.. damn. if (myTp != null) _teleporters.Remove(myTp); _teleporters.Add(newtp); // -- Save to file as well. _porterSettings.SelectGroup(name); _porterSettings.Write("StartX", start.X.ToString()); _porterSettings.Write("StartY", start.Y.ToString()); _porterSettings.Write("StartZ", start.Z.ToString()); _porterSettings.Write("EndX", end.X.ToString()); _porterSettings.Write("EndY", end.Y.ToString()); _porterSettings.Write("EndZ", end.Z.ToString()); _porterSettings.Write("DestX", dest.X.ToString()); _porterSettings.Write("DestY", dest.Y.ToString()); _porterSettings.Write("DestZ", dest.Z.ToString()); _porterSettings.Write("DestRot", destRot.ToString()); _porterSettings.Write("DestLook", destLook.ToString()); _porterSettings.Write("DestMap", destMap.CWMap.MapName); _porterSettings.SaveFile(); }
/// <summary> /// Creates a new MapHistory object. /// </summary> /// <param name="map">The map object to hold history for.</param> public MapHistory(HypercubeMap map) { _thisMap = map; _baseName = map.Path.Substring(0, map.Path.LastIndexOf('.')); if (!File.Exists(_baseName + ".hch")) { // -- Create a history file. using (var stream = new FileStream(_baseName + ".hch", FileMode.Create)) { var history = new byte[(_thisMap.CWMap.SizeX*_thisMap.CWMap.SizeY*_thisMap.CWMap.SizeZ)*4]; stream.Write(history, 0, history.Length); } if (map.Loaded == false && ServerCore.CompressHistory) GZip.CompressFile(_baseName + ".hch"); } if (map.Loaded && ServerCore.CompressHistory && FileCompressed()) GZip.DecompressFile(_baseName + ".hch"); else if (!ServerCore.CompressHistory) { // -- If the user recently disabled compression, we should decompress it first anyway. if (FileCompressed()) GZip.DecompressFile(_baseName + ".hch"); } Entries = new List<HistoryEntry>(); }
static void BoxHandler(NetworkClient client, HypercubeMap map, Vector3S location, byte mode, Block block) { if (mode != 1) return; switch (client.CS.MyEntity.BuildState) { case 0: client.CS.MyEntity.ClientState.SetCoord(location, 0); client.CS.MyEntity.BuildState = 1; break; case 1: var coord1 = client.CS.MyEntity.ClientState.GetCoord(0); var blocks = Math.Abs(location.X - coord1.X)*Math.Abs(location.Y - coord1.Y)* Math.Abs(location.Z - coord1.Z); var replaceBlock = client.CS.MyEntity.ClientState.GetString(0); if (blocks < 50000) { map.BuildBox(client, coord1.X, coord1.Y, coord1.Z, location.X, location.Y, location.Z, block, String.IsNullOrEmpty(replaceBlock) ? ServerCore.Blockholder.UnknownBlock : ServerCore.Blockholder.GetBlock(replaceBlock), false, 1, true, false); Chat.SendClientChat(client, "§SBox created."); } else Chat.SendClientChat(client, "§EBox too large."); client.CS.MyEntity.SetBuildmode(""); break; } }
static void WhiteHandler(HypercubeMap map, string[] args) { map.CWMap.BlockData = new byte[map.CWMap.BlockData.Length]; var airBlock = ServerCore.Blockholder.GetBlock(0); var whiteBlock = ServerCore.Blockholder.GetBlock(36); for (var ix = 0; ix < map.CWMap.SizeX; ix++) { for (var iy = 0; iy < map.CWMap.SizeY; iy++) map.BlockChange(-1, (short)ix, (short)iy, 0, whiteBlock, airBlock, false, false, false, 1); } for (var ix = 0; ix < map.CWMap.SizeX; ix++) { for (var iz = 0; iz < map.CWMap.SizeZ / 2; iz++) { map.BlockChange(-1, (short)ix, 0, (short)iz, whiteBlock, airBlock, false, false, false, 1); map.BlockChange(-1, (short)ix, (short)(map.CWMap.SizeY - 1), (short)iz, whiteBlock, airBlock, false, false, false, 1); } } for (var iy = 0; iy < map.CWMap.SizeY; iy++) { for (var iz = 0; iz < map.CWMap.SizeZ / 2; iz++) { map.BlockChange(-1, 0, (short)iy, (short)iz, whiteBlock, airBlock, false, false, false, 1); map.BlockChange(-1, (short)(map.CWMap.SizeX - 1), (short)iy, (short)iz, whiteBlock, airBlock, false, false, false, 1); } } Chat.SendMapChat(map, "&cMap done."); }
/// <summary> /// Changes the map the client is on. /// </summary> /// <param name="newMap">The map to send the client to.</param> public void ChangeMap(HypercubeMap newMap) { if (newMap.FreeIds.Count == 0) { // -- No more free entity ids (1-127) on the map. Chat.SendClientChat(this, "§EYou cannot join this map (It is full)."); return; } if (!HasAllPermissions(newMap.Joinperms.Values.ToList())) { // -- Check the users permissions if (!HasAllPermissions(newMap.Showperms.Values.ToList())) { // -- If they can't see the map, act like it doesn't exist. Chat.SendClientChat(this, "§EMap '" + newMap.CWMap.MapName + "' not found."); return; } Chat.SendClientChat(this, "§EYou do not have permission to join this map."); // -- If they can see it but they still dont have permission, tell them. return; } // -- Notify clients of the map change. Chat.SendMapChat(newMap, "§SPlayer " + CS.FormattedName + " §Schanged to map &f" + newMap.CWMap.MapName + ".", 0, true); Chat.SendMapChat(CS.CurrentMap, "§SPlayer " + CS.FormattedName + " §Schanged to map &f" + newMap.CWMap.MapName + "."); ServerCore.Luahandler.RunFunction("E_MapChange", this, CS.CurrentMap, newMap); lock (CS.CurrentMap.ClientLock) { // -- Update the map client list.. CS.CurrentMap.Clients.Remove(CS.Id); CS.CurrentMap.CreateClientList(); } CS.CurrentMap.DeleteEntity(ref CS.MyEntity); // -- Update the entity.. CS.CurrentMap = newMap; newMap.Send(this); // -- Send the map to the client lock (newMap.ClientLock) { // -- Add the client's entity to the new map newMap.Clients.Add(CS.Id, this); newMap.CreateClientList(); } CS.MyEntity.SetBlockPosition(CS.CurrentMap.GetSpawnVector()); // -- Spawn the entity at the spawn.. CS.MyEntity.Rot = newMap.CWMap.SpawnRotation; CS.MyEntity.Look = newMap.CWMap.SpawnLook; CS.MyEntity.Map = newMap; CS.MyEntity.ClientId = (byte)newMap.FreeIds.Pop(); ESpawn(CS.MyEntity.Name, CS.MyEntity.CreateStub()); lock (newMap.EntityLock) { newMap.Entities.Add(CS.MyEntity.Id, CS.MyEntity); newMap.CreateEntityList(); } CPE.UpdateExtPlayerList(this); // -- Update CPE listings as needed. }
public Entity(HypercubeMap map, string name, Vector3S location, byte rot, byte look) { Name = name; Location = location; Rot = rot; Look = look; Map = map; Model = "default"; Visible = true; Id = ServerCore.FreeEids.Pop(); BuildMaterial = ServerCore.Blockholder.GetBlock(""); Lastmaterial = ServerCore.Blockholder.GetBlock(1); ClientState = new BuildState(); BuildMode = new BmStruct {Name = ""}; ClientId = (byte)Map.FreeIds.Pop(); }
public void FillMap(HypercubeMap map, string fillname, params string[] args) { if (!Mapfills.ContainsKey(fillname)) return; if (Mapfills[fillname].Plugin == "") Mapfills[fillname].Run(map, args); else { map.CWMap.BlockData = new byte[map.CWMap.BlockData.Length]; ServerCore.Luahandler.RunFunction(Mapfills[fillname].Plugin, map, map.CWMap.SizeX, map.CWMap.SizeZ, map.CWMap.SizeY, args); } map.CWMap.GeneratorName = fillname; map.CWMap.GeneratingSoftware = "Hypercube"; map.Resend(); ServerCore.Luahandler.RunFunction("E_MapFilled", map, fillname); }
static void CreateTPHandler(NetworkClient client, HypercubeMap map, Vector3S location, byte mode, Block block) { if (mode != 1) return; var state = client.CS.MyEntity.BuildState; switch (state) { case 0: client.CS.MyEntity.ClientState.SetCoord(location.X, location.Y, location.Z, 1); client.CS.MyEntity.BuildState = 1; return; case 1: var destCoord = client.CS.MyEntity.ClientState.GetCoord(0); var destRot = client.CS.MyEntity.ClientState.GetInt(0); var destLook = client.CS.MyEntity.ClientState.GetInt(1); var startCoord = client.CS.MyEntity.ClientState.GetCoord(1); var endCoord = new Vector3S { X = location.X, Y = location.Y, Z = location.Z }; var teleName = client.CS.MyEntity.ClientState.GetString(0); var destMap = HypercubeMap.GetMap(client.CS.MyEntity.ClientState.GetString(1)); // -- Move things around so the smaller is the start, the larger being the end. if (startCoord.X > location.X) { endCoord.X = startCoord.X; startCoord.X = location.X; } if (startCoord.Y > location.Y) { endCoord.Y = startCoord.Y; startCoord.Y = location.Y; } if (startCoord.Z > location.Z) { endCoord.Z = startCoord.Z; startCoord.Z = location.Z; } client.CS.CurrentMap.Teleporters.CreateTeleporter(teleName, startCoord, endCoord, destCoord, (byte)destLook, (byte)destRot, destMap); Chat.SendClientChat(client, "§STeleporter created."); client.CS.MyEntity.SetBuildmode(""); break; } }
static void FlatgrassHandler(HypercubeMap map, string[] args) { var sw = new Stopwatch(); sw.Start(); map.CWMap.BlockData = new byte[map.CWMap.BlockData.Length]; var grassBlock = ServerCore.Blockholder.GetBlock(2); var dirtBlock = ServerCore.Blockholder.GetBlock(3); var airBlock = ServerCore.Blockholder.GetBlock(0); for (var x = 0; x < map.CWMap.SizeX; x++) { for (var y = 0; y < map.CWMap.SizeZ; y++) { for (var z = 0; z < (map.CWMap.SizeY / 2); z++) { map.BlockChange(-1, (short) x, (short) y, (short) z, z == (map.CWMap.SizeY/2) - 1 ? grassBlock : dirtBlock, airBlock, false, false, false, 1); } } } sw.Stop(); Chat.SendMapChat(map, "&cMap created in " + ((sw.ElapsedMilliseconds / 1000F)) + "s."); }
/// <summary> /// Sends a message to all clients on a certain map. /// </summary> public static void SendMapChat(HypercubeMap map, string message, sbyte messageType = 0, bool log = false) { var chat = new Message {PlayerId = messageType}; message = Text.CleanseString(message); if (log) ServerCore.Logger.Log(map.CWMap.MapName, message, LogType.Chat); message = EmoteReplace(message); if (message.Length > 0 && Text.StringMatches(message.Substring(message.Length - 1))) message += "."; var sending = SplitLines(message); foreach(var c in map.ClientsList) { foreach (var b in sending) { chat.Text = b; c.SendQueue.Enqueue(chat); } } }
static void WireworldHandler(HypercubeMap map, string[] args) { map.CWMap.BlockData = new byte[map.CWMap.BlockData.Length]; var airBlock = ServerCore.Blockholder.GetBlock(0); var blackBlock = ServerCore.Blockholder.GetBlock(34); for (var x = 0; x < map.CWMap.SizeX; x++) { for (var y = 0; y < map.CWMap.SizeY; y++) map.BlockChange(-1, (short)x, (short)y, 0, blackBlock, airBlock, false, false, false, 1); } Chat.SendMapChat(map, "&cMap done."); }
// -- These functions will provide Lua scripts an interface with the server // -- Allowing them to have a great deal on control over the server itself. public void Setblock(short clientId, HypercubeMap map, short x, short y, short z, byte type, bool undo, bool physics, bool send, short priority) { map.BlockChange(clientId, x, y, z, ServerCore.Blockholder.GetBlock(type), map.GetBlock(x, y, z), undo, physics, send, priority); }
/// <summary> /// Search the maps directory for maps and load them. /// </summary> public static void LoadMaps() { if (!Directory.Exists("Maps")) Directory.CreateDirectory("Maps"); var files = Directory.GetFiles("Maps", "*.cw*", SearchOption.AllDirectories); foreach (var file in files) { try { var newMap = new HypercubeMap(file); HypercubeMap m; ServerCore.Maps.TryGetValue(newMap.CWMap.MapName, out m); if (m != null) { ServerCore.Logger.Log("Maps", "Failed to load " + file + ". Map with duplicate name already loaded. (" + m.Path + ")", LogType.Error); continue; } ServerCore.Maps.Add(newMap.CWMap.MapName, newMap); ServerCore.Logger.Log("Maps", "Loaded map '" + file + "'. (X=" + newMap.CWMap.SizeX + " Y=" + newMap.CWMap.SizeZ + " Z=" + newMap.CWMap.SizeY + ")", LogType.Info); } catch (Exception e) { ServerCore.Logger.Log("Maps", "Failed to load map '" + file + "'.", LogType.Warning); ServerCore.Logger.Log("Maps", e.Message, LogType.Error); ServerCore.Logger.Log("Maps", e.StackTrace, LogType.Debug); GC.Collect(); } } }
public EntityStub(int id, byte clientId, bool visible, HypercubeMap cMap, Vector3S location, byte rot, byte look, string model) { Map = cMap; Id = id; ClientId = clientId; Visible = visible; Location = location; Rot = rot; Look = look; Looked = false; Changed = false; Spawned = false; Model = model; }
private static void HistoryHandler(NetworkClient client, HypercubeMap map, Vector3S location, byte mode, Block block) { Chat.SendClientChat(client, map.HCSettings.History ? map.History.LookupString(location.X, location.Z, location.Y) : "§EHistory is not enabled on this map."); client.CS.MyEntity.SetBuildmode(""); }
/// <summary> /// Loads server settings, loads the database, and prepares the system for use. /// </summary> public static void Setup() { Setting = new PbSettingsLoader(); TextFormats = new Text(); SysSettings = new Settings("System.txt", ReadSystemSettings); Setting.RegisterFile(SysSettings); SysSettings.LoadFile(); Rulesfile = new Settings("Rules.txt", ReadRules, "Settings/", false); Setting.RegisterFile(Rulesfile); Rulesfile.LoadFile(); if (RotateLogs) Logger.RotateLogs(); Permholder = new PermissionContainer(); Rankholder = new RankContainer(); Blockholder = new BlockContainer(); BmContainer = new BuildMode(); DefaultRank = Rankholder.GetRank(DefaultRank.Name); DB = new Database(); Logger.Log("Database", "Database loaded.", LogType.Info); Nh = new NetworkHandler(); Logger.Log("", "Core Initialized.", LogType.Info); Maps = new Dictionary<string, HypercubeMap>(StringComparer.InvariantCultureIgnoreCase); HypercubeMap.LoadMaps(); HypercubeMap m; Maps.TryGetValue(MapMain, out m); if (m == null) { var mainMap = new HypercubeMap("Maps/" + MapMain + ".cw", MapMain, 128, 128, 128); Maps.Add(MapMain, mainMap); Logger.Log("Core", "Main world not found, a new one has been created.", LogType.Warning); } Commandholder = new CommandHandler(); Fillholder = new FillContainer(); Luahandler = new HCLua(); Luahandler.RegisterFunctions(); Luahandler.LoadScripts(); Setting.SaveAll(); FillStacks(); ActionQueue = new ConcurrentQueue<MapAction>(); }
static void MapaddHandler(NetworkClient client, string[] args, string text1, string text2) { if (args.Length == 0) { Chat.SendClientChat(client, "§EThis command requires 1 argument. See /cmdhelp mapadd for usage."); return; } if (File.Exists("Maps/" + args[0] + ".cw") || File.Exists("Maps/" + args[0] + ".cwu")) { Chat.SendClientChat(client, "§EA file with the name " + args[0] + " already exists."); return; } var newMap = new HypercubeMap("Maps/" + args[0] + ".cw", args[0], 64, 64, 64); ServerCore.Maps.Add(args[0], newMap); newMap.BlockThread = new Thread(newMap.BlockQueueLoop); newMap.PhysicsThread = new Thread(newMap.PhysicsQueueLoop); newMap.BlockThread.Start(); newMap.PhysicsThread.Start(); TaskScheduler.CreateTask("Memory Conservation (" + newMap.CWMap.MapName + ")", new TimeSpan(0, 0, 30), newMap.MapMain); TaskScheduler.CreateTask("Autosave (" + newMap.CWMap.MapName + ")", new TimeSpan(0, newMap.HCSettings.SaveInterval, 0), newMap.MapSave); newMap.Teleporters = new TeleporterContainer(newMap.CWMap.MapName); Chat.SendClientChat(client, "§SMap added successfully."); }