Beispiel #1
0
        public override void Execute(CommandQueue queue, CommandEntry entry)
        {
            if (entry.Arguments.Count < 1)
            {
                ShowUsage(queue, entry);
                return;
            }
            ListTag list    = ListTag.For(entry.GetArgument(queue, 0));
            string  message = "Kicked by the server.";

            if (entry.Arguments.Count >= 2)
            {
                message = "Kicked by the server: " + entry.GetArgument(queue, 1);
            }
            for (int i = 0; i < list.ListEntries.Count; i++)
            {
                PlayerEntity pl = TheServer.GetPlayerFor(list.ListEntries[i].ToString());
                if (pl == null)
                {
                    entry.Bad(queue, "Unknown player " + TagParser.Escape(list.ListEntries[i].ToString()));
                }
                else
                {
                    pl.Kick(message);
                }
            }
        }
Beispiel #2
0
 public string ToEscapedString()
 {
     return(TagParser.Escape(Name) + "[secondary=" + (SecondaryName == null ? "" : EscapeTagBase.Escape(SecondaryName)) + ";display=" + EscapeTagBase.Escape(DisplayName) + ";count=" + Count
            + ";weight=" + Weight + ";volume=" + Volume + ";temperature=" + Temperature + ";renderascomponent=" + (RenderAsComponent ? "true" : "false") + ";componentrenderoffset=" + ComponentRenderOffset.ToSimpleString()
            + ";description=" + EscapeTagBase.Escape(Description) + ";texture=" + EscapeTagBase.Escape(GetTextureName()) + ";model=" + EscapeTagBase.Escape(GetModelName()) + ";bound=" + (IsBound ? "true" : "false")
            + ";drawcolor=" + new ColorTag(DrawColor).ToString() + ";datum=" + Datum + ";shared=" + SharedStr() + ";local=" + EscapedLocalStr() + ";components=" + ComponentEscapedString() + "]");
 }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));

            if (player == null)
            {
                queue.HandleError(entry, "Invalid player!");
                return;
            }
            ItemAssetTag item = ItemAssetTag.For(entry.GetArgument(queue, 1));

            if (item == null)
            {
                queue.HandleError(entry, "Invalid item!");
                return;
            }
            byte amount = 1;

            if (entry.Arguments.Count > 2)
            {
                amount = (byte)Utilities.StringToUInt(entry.GetArgument(queue, 2));
            }
            if (ItemTool.tryForceGiveItem(player.Internal.player, item.Internal.id, amount))
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully gave a " + TagParser.Escape(item.Internal.name) + "!");
                }
            }
            else
            {
                queue.HandleError(entry, "Failed to give item (is the inventory full?)!");
            }
        }
Beispiel #4
0
        public string SharedStr()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            foreach (KeyValuePair <string, TemplateObject> val in SharedAttributes)
            {
                string type = "text";
                if (val.Value is IntegerTag)
                {
                    type = "inte";
                }
                else if (val.Value is NumberTag)
                {
                    type = "numb";
                }
                else if (val.Value is BooleanTag)
                {
                    type = "bool";
                }
                sb.Append(TagParser.Escape(val.Key) + "=" + type + "/" + TagParser.Escape(val.Value.ToString()) + ";");
            }
            sb.Append("}");
            return(sb.ToString());
        }
Beispiel #5
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            TemplateObject tcolor = entry.GetArgumentObject(queue, 0);
            ColorTag       color  = ColorTag.For(tcolor);

            if (color == null)
            {
                queue.HandleError(entry, "Invalid color: " + TagParser.Escape(tcolor.ToString()));
                return;
            }
            string    message  = entry.GetArgument(queue, 1);
            EChatMode chatMode = EChatMode.SAY;

            if (entry.Arguments.Count > 2)
            {
                string mode = entry.GetArgument(queue, 2);
                try
                {
                    chatMode = (EChatMode)Enum.Parse(typeof(EChatMode), mode.ToUpper());
                } catch (ArgumentException)
                {
                    queue.HandleError(entry, "Invalid chat mode: " + mode);
                    return;
                }
            }
            ChatManager.manager.channel.send("tellChat", ESteamCall.OTHERS, ESteamPacket.UPDATE_UNRELIABLE_BUFFER, new object[]
            {
                CSteamID.Nil,
                (byte)chatMode,
                color.Internal,
                message
            });
        }
Beispiel #6
0
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            Client TheClient = (entry.Command as BindCommand).TheClient;
            string key       = entry.GetArgument(queue, 0);
            Key    k         = KeyHandler.GetKeyForName(key);

            // TODO: Bad key error
            if (entry.Arguments.Count == 1)
            {
                CommandScript cs = KeyHandler.GetBind(k);
                if (cs == null)
                {
                    queue.HandleError(entry, "That key is not bound, or does not exist.");
                }
                else
                {
                    entry.Info(queue, TagParser.Escape(KeyHandler.keystonames[k] + ": {\n" + cs.FullString() + "}"));
                }
            }
            else if (entry.Arguments.Count >= 2)
            {
                KeyHandler.BindKey(k, entry.GetArgument(queue, 1));
                entry.Good(queue, "Keybind updated for " + KeyHandler.keystonames[k] + ".");
            }
        }
Beispiel #7
0
        public override TemplateObject Handle(TagData data)
        {
            long   eid;
            string input = data.GetModifier(0).ToLowerFast();

            if (long.TryParse(input, out eid))
            {
                Entity e = TheServer.GetEntity(eid);
                if (e != null)
                {
                    return(new EntityTag(e).Handle(data.Shrink()));
                }
            }
            else
            {
                foreach (PlayerEntity p in TheServer.Players)
                {
                    if (p.Name.ToLowerFast() == input)
                    {
                        return(new EntityTag(p).Handle(data.Shrink()));
                    }
                }
            }
            data.Error("Invalid entity '" + TagParser.Escape(input) + "'!");
            return(new NullTag());
        }
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1));
         if (loc == null)
         {
             queue.HandleError(entry, "Invalid location!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         PlayerTag player;
         if (entity.TryGetPlayer(out player))
         {
             player.Internal.player.gameObject.AddComponent <LaunchComponent>().LaunchPlayer(loc.ToVector3());
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully launched player " + TagParser.Escape(player.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             zombie.Internal.gameObject.AddComponent <LaunchComponent>().Launch(loc.ToVector3());
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully launched zombie " + TagParser.Escape(zombie.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             animal.Internal.gameObject.AddComponent <LaunchComponent>().Launch(loc.ToVector3());
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully launched animal " + TagParser.Escape(animal.ToString()) + " to " + TagParser.Escape(loc.ToString()) + "!");
             }
             return;
         }
         ItemEntityTag item;
         if (entity.TryGetItem(out item))
         {
             // TODO: Find some way to teleport items, barricades, etc without voiding the InstanceID?
         }
         queue.HandleError(entry, "That entity can't be launched!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to launch entity: " + ex.ToString());
     }
 }
Beispiel #9
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));

            if (player == null)
            {
                queue.HandleError(entry, "Invalid player!");
                return;
            }
            ItemAssetTag item = ItemAssetTag.For(entry.GetArgument(queue, 1));

            if (item == null)
            {
                queue.HandleError(entry, "Invalid item!");
                return;
            }
            byte amount = 1;

            if (entry.Arguments.Count > 2)
            {
                amount = (byte)Utilities.StringToUInt(entry.GetArgument(queue, 2));
            }
            PlayerInventory inventory       = player.Internal.player.inventory;
            byte            remainingAmount = amount;
            InventorySearch search;

            while (remainingAmount > 0 && (search = inventory.has(item.Internal.id)) != null) // TODO: Less awkward code!?
            {
                if (search.jar.item.amount <= remainingAmount)
                {
                    inventory.removeItem(search.page, inventory.getIndex(search.page, search.jar.x, search.jar.y));
                    remainingAmount -= search.jar.item.amount;
                }
                else
                {
                    inventory.sendUpdateAmount(search.page, search.jar.x, search.jar.y, (byte)(search.jar.item.amount - remainingAmount));
                    remainingAmount = 0;
                }
            }
            if (remainingAmount == 0)
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully took " + amount + " " + TagParser.Escape(item.Internal.name) + "!");
                }
            }
            else if (remainingAmount < amount)
            {
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully took " + (amount - remainingAmount) + " " + TagParser.Escape(item.Internal.name) + "! (" + remainingAmount + " more not found!)");
                }
            }
            else
            {
                queue.HandleError(entry, "Failed to take item (does the inventory contain any?)!");
            }
        }
Beispiel #10
0
 public override void Execute(CommandQueue queue, CommandEntry entry)
 {
     if (entry.Arguments.Count < 1)
     {
         ShowUsage(queue, entry);
         return;
     }
     entry.Good(queue, "'<{color.emphasis}>" + TagParser.Escape(entry.GetArgument(queue, 0)) + "<{color.base}>' to you as well from " + ThePlugin.Name + "!");
 }
Beispiel #11
0
        public override TemplateObject Handle(TagData data)
        {
            TemplateObject rdata = data.GetModifierObject(0);
            RecipeTag      rtag  = RecipeTag.For(TheServer, data, rdata);

            if (rtag == null)
            {
                data.Error("Invalid recipe '" + TagParser.Escape(rdata.ToString()) + "'!");
                return(new NullTag());
            }
            return(rtag.Handle(data.Shrink()));
        }
Beispiel #12
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1));

            if (loc == null)
            {
                queue.HandleError(entry, "Invalid location!");
                return;
            }
            EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));

            if (entity == null)
            {
                queue.HandleError(entry, "Invalid entity!");
                return;
            }
            ZombieTag zombie;

            if (entity.TryGetZombie(out zombie))
            {
                zombie.Internal.target.position  = loc.ToVector3();
                zombie.Internal.seeker.canMove   = true;
                zombie.Internal.seeker.canSearch = true;
                zombie.Internal.path             = EZombiePath.RUSH; // TODO: Option for this?
                if (!zombie.Internal.isTicking)
                {
                    zombie.Internal.isTicking = true;
                    ZombieManager.tickingZombies.Add(zombie.Internal);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully started a zombie walking to " + TagParser.Escape(loc.ToString()) + "!");
                }
                return;
            }
            AnimalTag animal;

            if (entity.TryGetAnimal(out animal))
            {
                animal.Internal.target = loc.ToVector3();
                if (!animal.Internal.isTicking)
                {
                    animal.Internal.isTicking = true;
                    AnimalManager.tickingAnimals.Add(animal.Internal);
                }
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully started an animal walking to " + TagParser.Escape(loc.ToString()) + "!");
                }
                return;
            }
            queue.HandleError(entry, "That entity can't be made to walk!");
        }
Beispiel #13
0
        public string ComponentString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            foreach (ItemStackBase itb in Components)
            {
                sb.Append(TagParser.Escape(itb.ToString()) + ";");
            }
            sb.Append("}");
            return(sb.ToString());
        }
Beispiel #14
0
        public override TemplateObject Handle(TagData data)
        {
            string      lname = data.GetModifier(0);
            LocationTag ltag  = LocationTag.For(TheServer, data, lname);

            if (ltag == null)
            {
                data.Error("Invalid location '" + TagParser.Escape(lname) + "'!");
                return(new NullTag());
            }
            return(ltag.Handle(data.Shrink()));
        }
Beispiel #15
0
        public override TemplateObject Handle(TagData data)
        {
            string rname = data.GetModifier(0);
            World  w     = TheServer.GetWorld(rname);

            if (w != null)
            {
                return(new WorldTag(w));
            }
            data.Error("Invalid world '" + TagParser.Escape(rname) + "'!");
            return(new NullTag());
        }
Beispiel #16
0
        public override TemplateObject Handle(TagData data)
        {
            TemplateObject pname = data.GetModifierObject(0);
            ItemTag        ptag  = ItemTag.For(TheServer, pname);

            if (ptag == null)
            {
                data.Error("Invalid player '" + TagParser.Escape(pname.ToString()) + "'!");
                return(new NullTag());
            }
            return(ptag.Handle(data.Shrink()));
        }
Beispiel #17
0
        public override TemplateObject Handle(TagData data)
        {
            string   cname = data.GetModifier(0);
            ColorTag ctag  = ColorTag.For(cname);

            if (ctag == null)
            {
                data.Error("Invalid color '" + TagParser.Escape(cname) + "'!");
                return(new NullTag());
            }
            return(ctag.Handle(data.Shrink()));
        }
Beispiel #18
0
        public override TemplateObject Handle(TagData data)
        {
            long   eid;
            string input = data.GetModifier(0).ToLowerFast();

            if (long.TryParse(input, out eid))
            {
                Entity e = TheServer.GetEntity(eid);
                if (e != null && e is ItemEntity)
                {
                    return(new ItemEntityTag((ItemEntity)e).Handle(data.Shrink()));
                }
            }
            data.Error("Invalid item entity '" + TagParser.Escape(input) + "'!");
            return(new NullTag());
        }
Beispiel #19
0
        public override TemplateObject Handle(TagData data)
        {
            string input = data.GetModifier(0).ToLowerFast();

            try
            {
                Material mat = MaterialHelpers.FromNameOrNumber(input);
                return(new MaterialTag(mat).Handle(data.Shrink()));
            }
            catch (Exception ex)
            {
                Utilities.CheckException(ex);
                data.Error("Invalid material '" + TagParser.Escape(input) + "'!");
                return(new NullTag());
            }
        }
Beispiel #20
0
        public override void Execute(CommandQueue queue, CommandEntry entry)
        {
            if (entry.Arguments.Count < 2)
            {
                ShowUsage(queue, entry);
                return;
            }
            ListTag          players  = ListTag.For(entry.GetArgumentObject(queue, 0));
            ListTag          items    = ListTag.For(entry.GetArgumentObject(queue, 1));
            List <ItemStack> itemlist = new List <ItemStack>();

            for (int i = 0; i < items.ListEntries.Count; i++)
            {
                ItemTag item = ItemTag.For(TheServer, items.ListEntries[i]);
                if (item == null)
                {
                    queue.HandleError(entry, "Invalid item!");
                    return;
                }
                itemlist.Add(item.Internal);
            }
            List <PlayerEntity> playerlist = new List <PlayerEntity>();

            for (int i = 0; i < players.ListEntries.Count; i++)
            {
                PlayerTag player = PlayerTag.For(TheServer, players.ListEntries[i]);
                if (player == null)
                {
                    queue.HandleError(entry, "Invalid player: " + TagParser.Escape(items.ListEntries[i].ToString()));
                    return;
                }
                playerlist.Add(player.Internal);
            }
            foreach (PlayerEntity player in playerlist)
            {
                foreach (ItemStack item in itemlist)
                {
                    player.Items.GiveItem(item);
                }
            }
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, itemlist.Count + " item(s) given to " + playerlist.Count + " player(s)!");
            }
        }
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         BooleanTag boolean = BooleanTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (boolean == null)
         {
             queue.HandleError(entry, "Invalid boolean!");
             return;
         }
         PlayerTag player = PlayerTag.For(entry.GetArgument(queue, 0));
         if (player == null)
         {
             queue.HandleError(entry, "Invalid player!");
             return;
         }
         bool       value = boolean.Internal;
         PlayerLife life  = player.Internal.player.life;
         if (life.isBroken != value)
         {
             if (value)
             {
                 life.breakLegs();
             }
             else
             {
                 life._isBroken = false;
                 life.channel.send("tellBroken", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                 {
                     life._isBroken
                 });
             }
             entry.Good(queue, "Successfully adjusted the broken legs of player " + TagParser.Escape(player.ToString()) + " to " + TagParser.Escape(boolean.ToString()) + "!");
         }
         else
         {
             entry.Good(queue, "Player " + TagParser.Escape(player.ToString()) + " already has their broken legs set to " + TagParser.Escape(boolean.ToString()) + "!");
         }
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to adjust player's broken legs: " + ex.ToString());
     }
 }
Beispiel #22
0
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            ListTag        players = ListTag.For(entry.GetArgument(queue, 0));
            TemplateObject tcolor  = entry.GetArgumentObject(queue, 1);
            ColorTag       color   = ColorTag.For(tcolor);

            if (color == null)
            {
                queue.HandleError(entry, "Invalid color: " + TagParser.Escape(tcolor.ToString()));
                return;
            }
            string    tchatter = entry.GetArgument(queue, 2);
            PlayerTag chatter  = PlayerTag.For(tchatter);

            if (chatter == null)
            {
                queue.HandleError(entry, "Invalid chatting player: " + TagParser.Escape(tchatter));
                return;
            }
            string message = entry.GetArgument(queue, 3);

            foreach (TemplateObject tplayer in players.ListEntries)
            {
                PlayerTag player = PlayerTag.For(tplayer.ToString());
                if (player == null)
                {
                    queue.HandleError(entry, "Invalid player: " + TagParser.Escape(tplayer.ToString()));
                    continue;
                }
                ChatManager.manager.channel.send("tellChat", player.Internal.playerID.steamID, ESteamPacket.UPDATE_UNRELIABLE_BUFFER,
                                                 chatter.Internal.playerID.steamID, (byte)0 /* TODO: Configurable mode? */, color.Internal, message);
                if (entry.ShouldShowGood(queue))
                {
                    entry.Good(queue, "Successfully sent a message.");
                }
            }
        }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            LocationTag loc = LocationTag.For(entry.GetArgument(queue, 1));

            if (loc == null)
            {
                queue.HandleError(entry, "Invalid location!");
                return;
            }
            string         targetAssetType = entry.GetArgument(queue, 0).ToLower();
            EffectAssetTag effectType      = EffectAssetTag.For(targetAssetType);

            if (effectType == null)
            {
                queue.HandleError(entry, "Invalid effect type!");
                return;
            }
            EffectManager.sendEffect(effectType.Internal.id, EffectManager.INSANE, loc.ToVector3());
            // TODO: radius option instead of always 512 units (INSANE)!
            if (entry.ShouldShowGood(queue))
            {
                entry.Good(queue, "Played effect " + TagParser.Escape(effectType.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
            }
        }
Beispiel #24
0
        public static void Execute(CommandQueue queue, CommandEntry entry)
        {
            // TODO: Update all the information here. The chunk usages in particular are entirely wrong due to RAM-management updates.
            Server       TheServer = (entry.Command as MeminfoCommand).TheServer;
            const string rn        = "   Region Name Here   ";
            const string cr        = "Chunk Exact RAM in MB";
            const string er        = "Entity Est. RAM in MB";

            entry.Info(queue, "[<{text_color.emphasis}>" + rn + "<{text_color.base}>] [<{text_color.emphasis}>" + cr + "<{text_color.base}>] [<{text_color.emphasis}>" + er + "<{text_color.base}>]");
            long cht  = 0;
            long entt = 0;
            int  n    = 0;

            foreach (World world in TheServer.LoadedWorlds)
            {
                n++;
                long chunk = Chunk.RAM_USAGE * world.MainRegion.ChunkCount();
                //string reg_cr = Utilities.Pad(Utilities.FormatNumber(chunk), ' ', cr.Length, false);
                long ent = 0;
                foreach (Entity e in world.MainRegion.Entities.Values)
                {
                    ent += e.GetRAMUsage();
                }
                string reg_er = Utilities.Pad(Utilities.FormatNumber(ent), ' ', er.Length, false);
                entry.Info(queue, "[<{text_color.emphasis}>" + n + "<{text_color.base}>] [<{text_color.emphasis}>" + TagParser.Escape(world.Name) + "<{text_color.base}>] [<{text_color.emphasis}>" + reg_er + "<{text_color.base}>]");
                cht  += chunk;
                entt += ent;
            }
            entry.Info(queue, "Totals -> Chunks (Semi-accurate): <{text_color.emphasis}>" + Utilities.FormatNumber(cht) + "<{text_color.base}>, Entities (Estimated): <{text_color.emphasis}>" + Utilities.FormatNumber(entt)
                       + "<{text_color.base}>, actual usage: <{text_color.emphasis}>" + Utilities.FormatNumber(GC.GetTotalMemory(false)) + "<{text_color.base}>.");
        }
        public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
        {
            try
            {
                TemplateObject spawned = null;
                LocationTag    loc     = LocationTag.For(entry.GetArgument(queue, 1));
                if (loc == null)
                {
                    queue.HandleError(entry, "Invalid location!");
                    return;
                }
                string     targetAssetType = entry.GetArgument(queue, 0).ToLowerFast();
                EntityType etype           = EntityType.ValueOf(targetAssetType);
                if (etype == null)
                {
                    queue.HandleError(entry, "Invalid entity type!");
                    return;
                }
                if (etype.Type == EntityAssetType.ZOMBIE)
                {
                    Vector3 vec3    = loc.ToVector3();
                    byte    reg     = 0; // TODO: Optionally specifiable
                    float   closest = float.MaxValue;
                    for (int r = 0; r < LevelZombies.zombies.Length; r++)
                    {
                        for (int i = 0; i < LevelZombies.zombies[r].Count; i++)
                        {
                            float dist = (LevelZombies.zombies[r][i].point - vec3).sqrMagnitude;
                            if (dist < closest)
                            {
                                closest = dist;
                                reg     = (byte)r;
                            }
                        }
                    }
                    ZombieManager.manager.addZombie(reg, 0, 0, 0, 0, 0, 0, 0, 0, vec3, 0, false);
                    Zombie zombie = ZombieManager.regions[reg].zombies[ZombieManager.regions[reg].zombies.Count - 1];
                    // TODO: Make this actually work! (See complaints file!)

                    /*
                     * foreach (SteamPlayer player in PlayerTool.getSteamPlayers())
                     * {
                     *  ZombieManager.manager.channel.openWrite();
                     *  ZombieManager.manager.channel.write(reg);
                     *  ZombieManager.manager.channel.write((ushort)1);
                     *  ZombieManager.manager.channel.write(new object[]
                     *      {
                     *          zombie.type,
                     *          (byte)zombie.speciality,
                     *          zombie.shirt,
                     *          zombie.pants,
                     *          zombie.hat,
                     *          zombie.gear,
                     *          zombie.move,
                     *          zombie.idle,
                     *          zombie.transform.position,
                     *          MeasurementTool.angleToByte(zombie.transform.rotation.eulerAngles.y),
                     *          zombie.isDead
                     *      });
                     *  ZombieManager.manager.channel.closeWrite("tellZombies", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER);
                     * }
                     */
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a zombie at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)");
                    }
                    spawned = new ZombieTag(zombie);
                }
                else if (etype.Type == EntityAssetType.ANIMAL)
                {
                    AnimalAssetTag asset = AnimalAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid animal type!");
                        return;
                    }
                    // TODO: Make this bit optional!
                    RaycastHit rch;
                    while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5))
                    {
                        loc.Y += 3;
                    }
                    // END TODO
                    AnimalManager.manager.addAnimal(asset.Internal.id, loc.ToVector3(), 0, false);
                    Animal animal = AnimalManager.animals[AnimalManager.animals.Count - 1];
                    foreach (SteamPlayer player in PlayerTool.getSteamPlayers())
                    {
                        AnimalManager.manager.channel.openWrite();
                        AnimalManager.manager.channel.write((ushort)1);
                        AnimalManager.manager.channel.write(new object[]
                        {
                            animal.id,
                            animal.transform.position,
                            MeasurementTool.angleToByte(animal.transform.rotation.eulerAngles.y),
                            animal.isDead
                        });
                        AnimalManager.manager.channel.closeWrite("tellAnimals", player.playerID.steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER);
                    }
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (" + animal.gameObject.GetInstanceID() + ")");
                    }
                    spawned = new AnimalTag(animal);
                }
                else if (etype.Type == EntityAssetType.VEHICLE)
                {
                    VehicleAssetTag asset = VehicleAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid vehicle type!");
                        return;
                    }
                    // TODO: Make this bit optional!
                    RaycastHit rch;
                    while (Physics.Raycast(loc.ToVector3(), new Vector3(0, 1, 0), out rch, 5))
                    {
                        loc.Y += 3;
                    }
                    // END TODO
                    VehicleManager.spawnVehicle(asset.Internal.id, loc.ToVector3(), Quaternion.identity);
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                    }
                    // TODO: Get the vehicle entity!
                }
                else if (etype.Type == EntityAssetType.WORLD_OBJECT)
                {
                    WorldObjectAssetTag asset = WorldObjectAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid world object type!");
                        return;
                    }
                    LevelObjects.addObject(loc.ToVector3(), Quaternion.identity, Vector3.one, asset.Internal.id, asset.Internal.name, asset.Internal.GUID, ELevelObjectPlacementOrigin.MANUAL);
                    // TODO: Network!
                    entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "! (WARNING: IT WILL BE INVISIBLE CURRENTLY - SEE THE COMPLAINTS FILE)");
                    // TODO: Get the world entity!
                }
                else if (etype.Type == EntityAssetType.ITEM)
                {
                    ItemAssetTag asset = ItemAssetTag.For(targetAssetType);
                    if (asset == null)
                    {
                        queue.HandleError(entry, "Invalid item type!");
                        return;
                    }
                    byte x;
                    byte y;
                    if (Regions.tryGetCoordinate(loc.ToVector3(), out x, out y))
                    {
                        Item     item = new Item(asset.Internal.id, 1, asset.Internal.quality);
                        ItemData data = new ItemData(item, ++ItemManager.instanceCount, loc.ToVector3(), Dedicator.isDedicated);
                        ItemManager.regions[x, y].items.Add(data);
                        ItemModelTracker.Track(data, loc.ToVector3());
                        ItemManager.manager.channel.send("tellItem", ESteamCall.CLIENTS, x, y, ItemManager.ITEM_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                        {
                            x,
                            y,
                            item.id,
                            item.amount,
                            item.quality,
                            item.state,
                            loc.ToVector3()
                        });
                        if (entry.ShouldShowGood(queue))
                        {
                            entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                        }
                        // TODO: Get the item entity!
                    }
                    else
                    {
                        queue.HandleError(entry, "Trying to spawn item outside any valid item regions!");
                    }
                }
                else if (etype.Type == EntityAssetType.BARRICADE)
                {
                    ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("barricade_".Length));
                    if (asset == null || !(asset.Internal is ItemBarricadeAsset))
                    {
                        queue.HandleError(entry, "Invalid item barricade type!");
                        return;
                    }
                    Barricade barric = new Barricade(asset.Internal.id);
                    BarricadeManager.dropBarricade(barric, null, loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID);
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                    }
                    // TODO: Get the game object!
                }
                else if (etype.Type == EntityAssetType.STRUCTURE)
                {
                    ItemAssetTag asset = ItemAssetTag.For(targetAssetType.Substring("structure_".Length));
                    if (asset == null || !(asset.Internal is ItemStructureAsset))
                    {
                        queue.HandleError(entry, "Invalid item structure type!");
                        return;
                    }
                    StructureManager.dropStructure(new Structure(asset.Internal.id), loc.ToVector3(), 0f, 0f, 0f, CSteamID.Nil.m_SteamID, CSteamID.Nil.m_SteamID);
                    if (entry.ShouldShowGood(queue))
                    {
                        entry.Good(queue, "Successfully spawned a " + TagParser.Escape(asset.ToString()) + " at " + TagParser.Escape(loc.ToString()) + "!");
                    }
                    // TODO: Get the game object!
                }
                else
                {
                    queue.HandleError(entry, "Invalid or unspawnable entity type!");
                    return;
                }
                if (spawned != null)
                {
                    queue.SetVariable("spawned", spawned);
                }
            }
            catch (Exception ex) // TODO: Necessity?
            {
                queue.HandleError(entry, "Failed to spawn entity: " + ex.ToString());
            }
        }
Beispiel #26
0
        public override void Execute(CommandQueue queue, CommandEntry entry)
        {
            const string rn = "   Region Name Here   ";
            const string cr = "Chunk Exact RAM in MB";
            const string er = "Entity Est. RAM in MB";

            entry.Info(queue, "[<{text_color.emphasis}>" + rn + "<{text_color.base}>] [<{text_color.emphasis}>" + cr + "<{text_color.base}>] [<{text_color.emphasis}>" + er + "<{text_color.base}>]");
            long cht  = 0;
            long entt = 0;
            int  n    = 0;

            foreach (World world in TheServer.LoadedWorlds)
            {
                n++;
                long chunk = Chunk.RAM_USAGE * world.MainRegion.LoadedChunks.Count;
                //string reg_cr = Utilities.Pad(Utilities.FormatNumber(chunk), ' ', cr.Length, false);
                long ent = 0;
                foreach (Entity e in world.MainRegion.Entities.Values)
                {
                    ent += e.GetRAMUsage();
                }
                string reg_er = Utilities.Pad(Utilities.FormatNumber(ent), ' ', er.Length, false);
                entry.Info(queue, "[<{text_color.emphasis}>" + n + "<{text_color.base}>] [<{text_color.emphasis}>" + TagParser.Escape(world.Name) + "<{text_color.base}>] [<{text_color.emphasis}>" + reg_er + "<{text_color.base}>]");
                cht  += chunk;
                entt += ent;
            }
            entry.Info(queue, "Totals -> Chunks (Semi-accurate): <{text_color.emphasis}>" + Utilities.FormatNumber(cht) + "<{text_color.base}>, Entities (Estimated): <{text_color.emphasis}>" + Utilities.FormatNumber(entt)
                       + "<{text_color.base}>, actual usage: <{text_color.emphasis}>" + Utilities.FormatNumber(GC.GetTotalMemory(false)) + "<{text_color.base}>.");
        }
Beispiel #27
0
        public override TemplateObject Handle(TagData data)
        {
            data.Shrink();
            if (data.Remaining == 0)
            {
                return(new TextTag(ToString()));
            }
            switch (data[0])
            {
            // <--[tagbase]
            // @Name ServerTag.online_players
            // @Group Entities
            // @ReturnType ListTag
            // @Returns a list of all online players.
            // @Example .online_players could return "Fortifier|mcmonkey".
            // -->
            case "online_players":
            {
                ListTag players = new ListTag();
                foreach (PlayerEntity p in TheServer.Players)
                {
                    players.ListEntries.Add(new PlayerTag(p));
                }
                return(players.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.loaded_worlds
            // @Group World
            // @ReturnType ListTag
            // @Returns a list of all loaded worlds.
            // @Example .loaded_worlds could return "default|bob".
            // -->
            case "loaded_worlds":
            {
                ListTag worlds = new ListTag();
                foreach (World w in TheServer.LoadedWorlds)
                {
                    worlds.ListEntries.Add(new WorldTag(w));
                }
                return(worlds.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.loaded_recipes
            // @Group Items
            // @ReturnType ListTag
            // @Returns a list of all loaded recipes.
            // -->
            case "loaded_recipes":
            {
                ListTag recipes = new ListTag();
                foreach (ItemRecipe r in TheServer.Recipes.Recipes)
                {
                    recipes.ListEntries.Add(new RecipeTag(r));
                }
                return(recipes.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.can_craft_from[<ListTag>]
            // @Group Items
            // @ReturnType ListTag
            // @Returns a list of all loaded recipes that can be crafted from the given input.
            // @Example .can_craft_from[blocks/grass_forest] could return "1&pipeblocks/grass_forest|".
            // -->
            case "can_craft_from":
            {
                // TODO: Handle errors neatly!
                List <ItemStack> items = new List <ItemStack>();
                ListTag          list  = ListTag.For(data.GetModifierObject(0));
                foreach (TemplateObject obj in list.ListEntries)
                {
                    items.Add(ItemTag.For(TheServer, obj).Internal);
                }
                ListTag recipes = new ListTag();
                foreach (RecipeResult r in TheServer.Recipes.CanCraftFrom(items.ToArray()))
                {
                    recipes.ListEntries.Add(new RecipeResultTag(r));
                }
                return(recipes.Handle(data.Shrink()));
            }

            // <--[tagbase]
            // @Name ServerTag.match_player[<TextTag>]
            // @Group Entities
            // @ReturnType PlayerTag
            // @Returns the player whose name best matches the input.
            // @Example .match_player[Fort] out of a group of "Fortifier", "Fort", and "Forty" would return "Fort".
            // @Example .match_player[monk] out of a group of "mcmonkey", "morph", and "Fort" would return "mcmonkey".
            // -->
            case "match_player":
            {
                string       pname  = data.GetModifier(0);
                PlayerEntity player = TheServer.GetPlayerFor(pname);
                if (player == null)
                {
                    data.Error("Invalid player '" + TagParser.Escape(pname) + "'!");
                    return(new NullTag());
                }
                return(new PlayerTag(player).Handle(data.Shrink()));
            }

            default:
                return(new TextTag(ToString()).Handle(data));
            }
        }
 public override void UnknownCommand(FreneticScript.CommandSystem.CommandQueue queue, string basecommand, string[] arguments)
 {
     Bad("Invalid command: " + TagParser.Escape(basecommand) + "!", queue.CommandStack.Count > 0 ? queue.CommandStack.Peek().Debug : DebugMode.FULL);
 }
Beispiel #29
0
        public override TemplateObject Handle(TagData data)
        {
            if (data.Remaining == 0)
            {
                return(this);
            }
            switch (data[0])
            {
            // <--[tag]
            // @Name ColorTag.red
            // @Group General Information
            // @ReturnType NumberTag
            // @Returns the red value of this color.
            // @Example "0.1,0.2,0.3,1" .red returns "0.1".
            // -->
            case "red":
                return(new NumberTag(Internal.r).Handle(data.Shrink()));

            // <--[tag]
            // @Name ColorTag.green
            // @Group General Information
            // @ReturnType NumberTag
            // @Returns the green value of this color.
            // @Example "0.1,0.2,0.3,1" .green returns "0.2".
            // -->
            case "green":
                return(new NumberTag(Internal.g).Handle(data.Shrink()));

            // <--[tag]
            // @Name ColorTag.blue
            // @Group General Information
            // @ReturnType NumberTag
            // @Returns the blue value of this color.
            // @Example "0.1,0.2,0.3,1" .red returns "0.3".
            // -->
            case "blue":
                return(new NumberTag(Internal.b).Handle(data.Shrink()));

            // <--[tag]
            // @Name ColorTag.alpha
            // @Group General Information
            // @ReturnType NumberTag
            // @Returns the alpha value of this color.
            // @Example "0.1,0.2,0.3,1" .red returns "1".
            // -->
            case "alpha":
                return(new NumberTag(Internal.a).Handle(data.Shrink()));

            // <--[tag]
            // @Name ColorTag.mix[<ColorTag>|...]
            // @Group Mathematics
            // @ReturnType ColorTag
            // @Returns the result of mixing the specified color(s) with this one.
            // @Example "blue" .mix[red] returns "0.5,0,0.5,1"
            // -->
            case "mix":
            {
                ListTag list       = ListTag.For(data.GetModifierObject(0));
                Color   mixedColor = Internal;
                foreach (TemplateObject tcolor in list.ListEntries)
                {
                    ColorTag color = ColorTag.For(tcolor);
                    if (color == null)
                    {
                        SysConsole.Output(OutputType.ERROR, "Invalid color: " + TagParser.Escape(tcolor.ToString()));
                        continue;
                    }
                    mixedColor += color.Internal;
                }
                return(new ColorTag(mixedColor / list.ListEntries.Count).Handle(data.Shrink()));
            }

            default:
                return(new TextTag(ToString()).Handle(data));
            }
        }
 public override void Execute(FreneticScript.CommandSystem.CommandQueue queue, CommandEntry entry)
 {
     try
     {
         IntegerTag num = IntegerTag.TryFor(entry.GetArgumentObject(queue, 1));
         if (num.Internal < 0)
         {
             queue.HandleError(entry, "Must provide a non-negative number!");
             return;
         }
         EntityTag entity = EntityTag.For(entry.GetArgumentObject(queue, 0));
         if (entity == null)
         {
             queue.HandleError(entry, "Invalid entity!");
             return;
         }
         EPlayerKill kill; // for use with "out EPlayerKill" parameters
         PlayerTag   player;
         if (entity.TryGetPlayer(out player))
         {
             PlayerLife          life             = player.Internal.player.life;
             UFMHealthController healthController = player.Internal.player.GetComponent <UFMHealthController>();
             uint health = healthController != null ? healthController.health : life.health;
             if (num.Internal >= health)
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.health = 0;
                 }
                 if (amount >= byte.MaxValue) // TODO: better handling
                 {
                     life._health = 0;
                     amount       = 1;
                 }
                 life.askDamage((byte)amount, Vector3.zero, EDeathCause.KILL, ELimb.SPINE, CSteamID.Nil, out kill, null);
             }
             else
             {
                 uint amount = (uint)num.Internal;
                 if (healthController != null)
                 {
                     healthController.Damage((uint)num.Internal);
                 }
                 life._health = healthController.Translate();
                 life.channel.send("tellHealth", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                 {
                     life.health
                 });
             }
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a player by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ZombieTag zombie;
         if (entity.TryGetZombie(out zombie))
         {
             uint xp;
             zombie.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a zombie by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         AnimalTag animal;
         if (entity.TryGetAnimal(out animal))
         {
             uint xp;
             animal.Internal.askDamage((byte)num.Internal, Vector3.zero, out kill, out xp);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged an animal by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         BarricadeTag barricade;
         if (entity.TryGetBarricade(out barricade))
         {
             // TODO: Use BarricadeManager?
             barricade.InternalData.barricade.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a barricade by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         ResourceTag resource;
         if (entity.TryGetResource(out resource))
         {
             // TODO: Use ResourceManager?
             resource.Internal.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a resource by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         StructureTag structure;
         if (entity.TryGetStructure(out structure))
         {
             // TODO: Use StructureManager?
             structure.InternalData.structure.askDamage((ushort)num.Internal);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a structure by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         VehicleTag vehicle;
         if (entity.TryGetVehicle(out vehicle))
         {
             vehicle.Internal.askDamage((ushort)num.Internal, false);
             if (entry.ShouldShowGood(queue))
             {
                 entry.Good(queue, "Successfully damaged a vehicle by " + TagParser.Escape(num.ToString()) + "!");
             }
             return;
         }
         queue.HandleError(entry, "That entity can't be damaged!");
     }
     catch (Exception ex) // TODO: Necessity?
     {
         queue.HandleError(entry, "Failed to damage entity: " + ex.ToString());
     }
 }