public void Undo(long since, Level l) {
     ExtraData<Tuple<short, short, short>, Tuple<long, byte>> toChange = GetOriginalBlocks(since, l);
     List<long> asked = new List<long>();
     foreach (Player p in l.Players) {
         if (p != player)
             toChange = p.history.redoRecentOthersUndo(toChange, since, l);
     }
     toChange = redoArchiveOthersUndoForAllPlayers(toChange, since, l);
     string path = GetFullPath(l);
     if (!Directory.Exists(path)) Directory.CreateDirectory(path);
     string tmppath = GetFullPath(l) + DateTime.Now.Ticks + futureEnding;
     FileStream fs = new FileStream(tmppath, FileMode.Create, FileAccess.Write);
     GZipStream gz = new GZipStream(fs, CompressionMode.Compress);
     BinaryWriter bw = new BinaryWriter(gz);
     foreach (Tuple<short, short, short> v in toChange.Keys) {
         //all changes are associated to the time in the filename
         byte tmp = l.GetBlock(v.Item1, v.Item2, v.Item3);
         if (tmp != toChange[v].Item2) {
             bw.Write(v.Item1);//coords
             bw.Write(v.Item2);
             bw.Write(v.Item3);
             bw.Write(toChange[v].Item2);//after undo
             l.BlockChange(new Vector3S(v.Item1, v.Item2, v.Item3), toChange[v].Item2);
         }
     }
     bw.Close();
     gz.Close();
     fs.Close();
 }
 public string[] GetOverview(Level l)
 {
     List<string> ret = new List<string>();
     foreach (string v in store[l.Name].ToArray()) {
         ret.Add(v + ": " + l.ExtraData["MessageBlock" + v]);
     }
     return ret.ToArray();
 }
 void OnLevelLoad(Level l, LevelLoadEventArgs args)
 {
     //The level loaded does not have a texture file, create it. TODO: Test
     if (CFGDict.GetIfExist<Level, CFGSettings>(l) == null)
     {
         CFGSettings s = new CFGSettings(l);
         CFGDict.CreateIfNotExist<Level, CFGSettings>(l, s);
     }
 }
        void OnAllLevelsUnload_Normal(Level sender, API.Events.LevelLoadEventArgs args) {
            if ( !lstUnloaded.Items.Contains(sender.Name) )
                lstUnloaded.Items.Add(sender.Name);

            int index = GetRowIndexFromLevel(sender);
            if ( index != -1 ) {
                dtaLoaded.Rows.RemoveAt(index);
            } 
        }
 /// <summary>
 /// Returns false if the message was only updated
 /// </summary>
 /// <param name="l"></param>
 /// <param name="v"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public bool Add(Level l, Vector3S v, string message)
 {
     bool ret = false;
     if (!store[l.Name].Contains(v)) {
         store[l.Name].Add(v);
         ret = true;
     }
     l.ExtraData["MessageBlock" + v] = message;
     return ret;
 }
Esempio n. 6
0
 /// <summary>
 /// Sends the specified detail to all players in the specified level.
 /// </summary>
 /// <param name="l">Level to send to.</param>
 /// <param name="message">Message to send.</param>
 public static void LevelSendDetail(Level l, string message)
 {
     Server.ForeachPlayer(p =>
     {
         if (l == p.Level)
         {
             message = PluginWoMTextures.ConvertVars(p, message);
             if ((bool)(p.ExtraData.GetIfExist<object, object>("UsingWoM") ?? false))
             {
                 p.SendMessage("^detail.user=%e" + message);
             }
         }
     });
 }
Esempio n. 7
0
        public BotMap(Level l)
        {
            AirMap = new bool[l.Size.x, l.Size.z, l.Size.y];//return x + z * Size.x + y * Size.x * Size.z;
            for (int i = 0; i < l.Data.Length; i++) {
                Vector3S pos = l.IntToPos(i);
                AirMap[pos.x, pos.z, pos.y] = isAir(l.GetBlock(i));
            }
            for (int x = 0; x < AirMap.GetLength(0); x++) {
                for (int z = 0; z < AirMap.GetLength(1); z++) {
                    for (int y = 0; y < AirMap.GetLength(2); y++) {

                    }
                }
            }
        }
 /// <summary>
 /// Used to register a method to be executed when the event is fired.
 /// </summary>
 /// <param name="callback">The method to call</param>
 /// <param name="target">The level to watch for. (null for any level)</param>
 /// <returns>A reference to the event</returns>
 public static OnLevelSave Register(OnCall callback, Level target)
 {
     Logger.Log("OnLevelSave registered to the method " + callback.Method.Name, LogType.Debug);
     //We add it to the list here
     OnLevelSave pe = _eventQueue.Find(match => match.level == null);
     if (pe != null)
         //It already exists, so we just add it to the queue.
         pe._queue += callback;
     else {
         //Doesn't exist yet.  Make a new one.
         pe = new OnLevelSave(callback, target);
         _eventQueue.Add(pe);
     }
     return pe;
 }
 /// <summary>
 /// Draws the on level.
 /// </summary>
 /// <param name="mLevel">The level to draw on.</param>
 /// <param name="startPos">The start pos.</param>
 /// <param name="blockOverlay">A block to set the component as. If it is not already set</param>
 /// <remarks>if the block in the component is set to 255 a block overlay will be used automaticly, no block change will occur if the block is at 254</remarks>
 public void DrawOnLevel(Level mLevel, Vector3S startPos, Direction dir, byte blockOverlay = 1) {
     for (int i = 0; i < components.Length; i++) {
         var comp = components[i];
         if (comp.Block == 254)
             continue;
         switch (dir) {
             case Direction.East:
                 mLevel.SetBlock(comp.Pos + startPos, comp.Block == 255 ? blockOverlay : comp.Block);
                 break;
             case Direction.West:
                 mLevel.SetBlock(comp.Pos - startPos, comp.Block == 255 ? blockOverlay : comp.Block);
                 break;
         }
     }
 }
Esempio n. 10
0
 public CFGSettings(Level l)
     : base("CFGSettings_"+l.Name, new SettingNode[]{
     new SettingNode("server.name", ServerSettings.GetSetting("ServerName"), "The name of your server. (Top right line)"),
     new SettingNode("server.detail", ServerSettings.GetSetting("MOTD"), "The MOTD of the server. (Second line)"),
     new SettingNode("detail.user", "Welcome to my server! $name", "The User Detail Line text. (Third line)"),
     new SettingNode("server.sendwomid","true", "Causes the client to send the server a /womid (VERSION) message upon load."),
     new SettingNode("environment.fog", "1377559", "The RGB value (Decimal, not Hex) of the colour to use for the fog."),
     new SettingNode("environment.sky", "1377559", "The RGB value (Decimal, not Hex) of the colour to use for the sky."),
     new SettingNode("environment.cloud", "1377559", "The RGB value (Decimal, not Hex) of the colour to use for the clouds."),
     new SettingNode("environment.level", "0", "The elevation of \"ground level\" to use for this map. (Affects where the \"sea\" is on the map."),
     new SettingNode("environment.edge", "685cfceb13ccee86d3b93f163f4ac6e4a28347bf", null),
     new SettingNode("environment.terrain", "f3dac271d7bce9954baad46e183a6a910a30d13b", null),
     new SettingNode("environment.side", "7c0fdebeb6637929b9b3170680fa7a79b656c3f7", null)}, false)
 {
     this.l = l;
 }
Esempio n. 11
0
 /// <summary>
 /// A robot (entity) that appears in the world.
 /// </summary>
 public Bot(string Username, Vector3S Position, byte[] Rotation, Level level, bool FollowPlayers, bool BreakBlocks, bool Jumping)
 {
     Player = new Player();
     Player.IsBot = true;
     Player.Username = Username;
     Player.Pos = Position;
     Player.oldPos = new Vector3S(Position.x, Position.z, Position.y);
     Player.Rot = Rotation;
     Player.Level = level;
     Player.id = FreeId();
     Server.Bots.Add(this);
     SpawnThisBotToOtherPlayers(this);
     this.FollowPlayers = FollowPlayers;
     this.BreakBlocks = BreakBlocks;
     this.Jumping = Jumping;
 }
Esempio n. 12
0
        public BotMap(Level l)
        {
            AirMap = new TriBool[l.CWMap.Size.x, l.CWMap.Size.z, l.CWMap.Size.y];//return x + z * Size.x + y * Size.x * Size.z;
            Size = l.CWMap.Size;
            for (int i = 0; i < l.CWMap.BlockData.Length; i++)
            {
                Vector3S pos = l.IntToPos(i);
                if (isAir(l.GetBlock(i)))
                    AirMap[pos.x, pos.z, pos.y] = true;
                else if (Block.IsOPBlock(l.GetBlock(i)))
                    AirMap[pos.x, pos.z, pos.y] = TriBool.Unknown;
                else
                    AirMap[pos.x, pos.z, pos.y] = false;
            }
            /*for (int x = 0; x < AirMap.GetLength(0); x++) {
                for (int z = 0; z < AirMap.GetLength(1); z++) {
                    for (int y = 0; y < AirMap.GetLength(2); y++) {

                    }
                }
            }*/
        }
Esempio n. 13
0
 /// <summary>
 /// A robot (entity) that appears in the world.
 /// </summary>
 public Bot(string Username, Vector3S Position, byte[] Rotation, Level level, bool FollowPlayers, bool BreakBlocks, bool Jumping)
 {
     Player = new Player();
     Player.IsLoggedIn = false;
     Player.DisplayName = Username;
     Player.IsBot = true;
     Player.Username = Username;
     Player.Pos = Position;
     Player.oldPos = new Vector3S(Position.x, Position.z, Position.y);
     Player.Rot = new Vector2S(Rotation[0], Rotation[1]);
     Player.Level = level;
     Player.ID = FreeId();
     Server.Bots.Add(this);
     SpawnThisBotToOtherPlayers(this);
     Player.IsLoggedIn = true;
     this.FollowPlayers = FollowPlayers;
     this.BreakBlocks = BreakBlocks;
     this.Jumping = Jumping;
     this.LevelMap = new BotMap(level);
     this.BlackListPlayers = new Dictionary<string, int>();
     Player.OnAllPlayersBlockChange.Important += OnBlockChange;
 }
Esempio n. 14
0
        public Zone(Vector3D point1, Vector3D point2, string owner, string name, byte minimumGroup, Level level, bool skipChecks = false)
        {
            ProtectedZone = new Cuboid(point1, point2);
            Owner = owner;
            Permission = minimumGroup;
            Zones.Add(this);
            Level = level;
            Name = name;

            if (skipChecks)
                return;
            ZoneList zones;
            if (Level.ExtraData.ContainsKey("zones"))
            {
                zones = ZoneList.FromString((string)Level.ExtraData.GetIfExist("zones"), Level);
                zones.Add(this);
            }
            else
            {
                zones = GetAllZonesForLevel(Level);
            }
            Level.ExtraData["zones"] = zones;
        }
Esempio n. 15
0
        public static ZoneList GetAllZonesForLevel(Level level)
        {
            ZoneList zonelist = null;
            if (level.ExtraData.ContainsKey("zones"))
            {
                zonelist = ZoneList.FromString((string)level.ExtraData.GetIfExist("zones"), level);
            }


            if (zonelist != null)
                foreach (var zone in zonelist.ToArray())
                {
                    if (!Zones.Contains(zone))
                        Zones.Add(zone);
                }

            var zones = new ZoneList();
            foreach (var zone in Zones)
            {
                if (zone.Level == level)
                    zones.Add(zone);
            }
            return zones;
        }
Esempio n. 16
0
        /// <summary>
        /// Adds the level to the level list.
        /// </summary>
        /// <param name="level">Name of the level.</param>
        public static void AddLevel(Level level) {
            if (Levels.Contains(level))
                return;

            Levels.Add(level);
        }
Esempio n. 17
0
        /// <summary>
        /// Load a level.
        /// </summary>
        /// <returns>The loaded level</returns>
        //TODO: Load all the types of levels (old mcforge, new mcforge, fcraft, minecpp, etc...)
        public static Level LoadLevel(string levelName) {
            //if (FindLevel(levelName) != null)
            //    return null;
            string name = levelName.Split('\\')[1].Split('.')[0];
            Console.WriteLine("Converting " + name);
            //string Name = "levels\\" + levelName + ".lvl";
            Level finalLevel = new Level(new Vector3S(32, 32, 32));
            finalLevel.Name = levelName;
            try {
                BinaryReader Binary = null;
                try {
                    Binary = new BinaryReader(File.Open(levelName, FileMode.Open));
                }
                catch (Exception e) { 
                	Console.WriteLine(e.ToString());
                	return null;
                }

                using (Binary) {
                    long v = Binary.ReadInt64();
                    if (v != MAGIC_NUMBER) //The magic number
                    {
                        //Binary.Dispose();
                        Binary.Close();
                        return new MCForgeOldMap().Load(name, levelName);
                    }
                    else //Is a new MCForge level!
                    {
                    	return null;
                    }
                }
                Binary.Close();
                //Binary.Dispose();
                //finalLevel.HandleMetaData();
                //Logger.Log("[Level] " + levelName + " was loaded");
                return finalLevel;
            }
            catch (Exception e) { 
                //Logger.Log(e.Message); Logger.Log(e.StackTrace); } 
                return null;
            }
        }
Esempio n. 18
0
 int GetRowIndexFromLevel(Level level) {
     return GetRowIndexFromLevelName(level.Name);
 }
Esempio n. 19
0
 string[] GetRowDataFromLevel(Level level) {
     return new[] {level.Name, string.Format("{0} x {1} x  {2}", level.Size.x, level.Size.y, level.Size.z), "True", level.Players.Count.ToString() };
 }
 public static void GlobalBlockchange(Level l, ushort x, ushort z, ushort y, byte block)
 {
     Server.ForeachPlayer(delegate(Player p)
     {
         if (p.Level == l)
             p.SendBlockChange(x, z, y, block);
     });
 }
 void add(Level l, ushort x, ushort z, ushort y, string message, Player sender) {
     PluginMessageBlock pmb = (PluginMessageBlock)Plugin.getByType(typeof(PluginMessageBlock).Name);
     if (pmb == null) {
         Logger.Log(typeof(PluginMessageBlock).Name + " is currently not loaded");
         sender.SendMessage(typeof(PluginMessageBlock).Name + " is currently not loaded");
         return;
     }
     if (message.StartsWith("/") && sender.Group.Permission >= commandBlockPermission) {
         message = "c:" + sender.Group.Permission + ":" + message.ToHexString();
     }
     else {
         message = "m" + message;
     }
     if (pmb.Add(l, new Vector3S(x, z, y), message)) {
         sender.SendMessage("Message block added");
     }
     else {
         sender.SendMessage("Message block updated");
     }
 }
Esempio n. 22
0
 public virtual void SetBlock(ushort x, ushort z, ushort y, Level l)
 {
     l.SetBlock(x, z, y, VisibleBlock);
 }
Esempio n. 23
0
 public virtual void SetBlock(Vector3 pos, Level l)
 {
     l.SetBlock(pos.x, pos.z, pos.y, VisibleBlock);
 }
Esempio n. 24
0
 void Undo(long UID, int time, Level l, Player online) {
     long since=DateTime.Now.AddSeconds(-time).Ticks;
     int count = 0;
     foreach (var ch in BlockChangeHistory.GetCurrentIfUID(l.Name, (uint)UID, since)) {
         RedoHistory.Add((uint)UID, l.Name, ch.Item1, ch.Item2, ch.Item3, ch.Item4);
         count++;
     }
     foreach (var ch in BlockChangeHistory.Undo(l.Name, (uint)UID, since)) {
         l.BlockChange(ch.Item1, ch.Item2, ch.Item3, ch.Item4);
     }
     online.SendMessage("&e" + count + Server.DefaultColor + " Blocks changed");
     return;
 }
Esempio n. 25
0
 void OnAllLevelsLoadUnload_Normal(Level sender, API.Events.LevelLoadEventArgs args) {
     if (args.Loaded) {
         if (!BlockChangeHistory.Load(sender.Name)) {
             BlockChangeHistory.SetLevel(sender.Name, (ushort)sender.Size.x, (ushort)sender.Size.z, (ushort)sender.Size.y, sender.Data);
         }
     }
     else
         BlockChangeHistory.WriteOut(sender.Name, true);
 }
 internal void SendBlockchangeToOthers(Level l, ushort x, ushort z, ushort y, byte block)
 {
     Server.ForeachPlayer(delegate(Player p)
     {
         if (p == this) return;
         if (p.Level == l)
             p.SendBlockChange(x, z, y, block);
     });
 }
Esempio n. 27
0
 public virtual void SetBlock(int x, int z, int y, Level l)
 {
     l.SetBlock((ushort)x, (ushort)z, (ushort)y, VisibleBlock);
 }
 public int RemoveAll(Level l) {
     int count = 0;
     foreach (string v in store[l.Name].ToArray()) {
         l.ExtraData["MessageBlock" + v] = null;
         store[l.Name].Remove(v);
         count++;
     }
     return count;
 }
Esempio n. 29
0
 public virtual void SetBlock(int pos, Level l)
 {
     l.SetBlock(pos, VisibleBlock);
 }
 public bool Remove(Level l, Vector3S v) {
     if (store[l.Name].Contains(v)) {
         store[l.Name].Remove(v);
         l.ExtraData["MessageBlock" + v] = null;
         return true;
     }
     return false;
 }