Ejemplo n.º 1
0
            private string TargetModelName(Player p, CommandData data, string arg, bool checkPerms = true)
            {
                string playerNameWithPlus = GetNameWithPlus(p.name);

                if (arg.CaselessEq("-own"))
                {
                    arg = playerNameWithPlus;
                }

                if (!ValidModelName(p, arg))
                {
                    return(null);
                }

                if (checkPerms)
                {
                    string maybePlayerName = StoredCustomModel.GetPlayerName(arg);
                    bool   targettingSelf  = maybePlayerName != null && maybePlayerName.CaselessEq(playerNameWithPlus);

                    // if you aren't targetting your own models,
                    // and you aren't admin, denied
                    if (!targettingSelf && !CheckExtraPerm(p, data, 1))
                    {
                        return(null);
                    }
                }

                return(Path.GetFileName(arg));
            }
Ejemplo n.º 2
0
            void Goto(Player p, string playerName = null, ushort page = 0)
            {
                bool all = false;

                if (playerName != null)
                {
                    playerName = playerName.ToLower();
                    if (playerName == "all")
                    {
                        all = true;
                    }
                    else if (playerName == "public")
                    {
                        playerName = null;
                    }
                    else
                    {
                        playerName = StoredCustomModel.GetPlayerName(playerName) ?? StoredCustomModel.GetPlayerName(playerName + "+");
                    }
                }

                List <string> modelNames;

                if (all)
                {
                    var dict = GetAllModels(p);
                    modelNames = dict
                                 // public ones first
                                 .OrderByDescending(pair => pair.Key == "Public")
                                 // then by player name A-Z
                                 .ThenBy(pair => pair.Key)
                                 .Select(pair => pair.Value)
                                 .SelectMany(x => x)
                                 .ToList();
                }
                else
                {
                    modelNames = GetModels(playerName, p);
                }
                if (modelNames == null)
                {
                    return;
                }

                // - 1 for our self player
                var partitionSize = Packet.MaxCustomModels - 1;
                var partitions    = modelNames.Partition(partitionSize).ToList();

                if (page >= partitions.Count)
                {
                    p.Message(
                        "%WPage doesn't exist"
                        );
                    return;
                }
                var total = modelNames.Count;

                modelNames = partitions[page];
                p.Message(
                    "%HViewing %T{0} %Hmodels{1}",
                    total,
                    partitions.Count > 1
                        ? string.Format(
                        " %S(page %T{0}%S/%T{1}%S)",
                        page + 1,
                        partitions.Count
                        )
                        : ""
                    );
                if (partitions.Count > 1 && page < (partitions.Count - 1))
                {
                    p.Message(
                        "%SUse \"%H/cm goto {0} {1}%S\" to go to the next page",
                        playerName,
                        page + 2
                        );
                }

                var mapName = string.Format(
                    "&f{0} Custom Models{1}",
                    all ? "All" : (
                        playerName == null
                            ? "Public"
                            : GetNameWithoutPlus(playerName) + "'s"
                        ),
                    page != 0 ? string.Format(" ({0})", page + 1) : ""
                    );

                ushort spacing = 4;
                ushort width   = (ushort)(
                    // edges
                    (spacing * 2) +
                    // grass blocks
                    modelNames.Count +
                    // inbetween blocks
                    ((modelNames.Count - 1) * (spacing - 1))
                    );
                ushort height = 1;
                ushort length = 16;

                byte[] blocks = new byte[width * height * length];

                Level lvl = new Level(mapName, width, height, length, blocks);

                for (int i = 0; i < blocks.Length; i++)
                {
                    blocks[i] = 1;
                }

                lvl.SaveChanges        = false;
                lvl.ChangedSinceBackup = false;

                lvl.IsMuseum        = true;
                lvl.BuildAccess.Min = LevelPermission.Nobody;
                lvl.Config.Physics  = 0;

                lvl.spawnx = spacing;
                lvl.spawny = 2;
                lvl.Config.HorizonBlock = 1;
                lvl.Config.EdgeLevel    = 1;
                lvl.Config.CloudsHeight = -0xFFFFFF;
                lvl.Config.SidesOffset  = 0;
                lvl.Config.Buildable    = false;
                lvl.Config.Deletable    = false;

                for (ushort i = 0; i < modelNames.Count; i++)
                {
                    ushort x = (ushort)(spacing + (i * spacing));
                    ushort y = 0;
                    ushort z = spacing;

                    blocks[lvl.PosToInt(x, y, z)] = 2;

                    var modelName = modelNames[i];

                    var storedModel = new StoredCustomModel(modelName);
                    if (storedModel.Exists())
                    {
                        storedModel.LoadFromFile();
                    }

                    var skinName = p.SkinName;
                    if (
                        !storedModel.usesHumanSkin &&
                        storedModel.defaultSkin != null
                        )
                    {
                        skinName = storedModel.defaultSkin;
                    }

                    // hack because clients strip + at the end
                    var botName = "&f" + (modelName.EndsWith("+") ? modelName + "&0+" : modelName);
                    var bot     = new PlayerBot(botName, lvl)
                    {
                        id       = (byte)i,
                        Model    = modelName,
                        SkinName = skinName,
                    };
                    bot.SetInitialPos(Position.FromFeetBlockCoords(x, y + 1, z));
                    bot.SetYawPitch(Orientation.DegreesToPacked(180), Orientation.DegreesToPacked(0));
                    bot.ClickedOnText = "/CustomModel wear " + modelName;

                    _ = lvl.Bots.Add(bot);
                }

                if (!PlayerActions.ChangeMap(p, lvl))
                {
                    return;
                }
            }
Ejemplo n.º 3
0
            void List(Player p, string playerName = null, string query = null)
            {
                bool all = false;

                if (playerName != null)
                {
                    playerName = playerName.ToLower();
                    if (playerName == "all" || playerName == "count")
                    {
                        all = true;
                    }
                    else if (playerName == "public")
                    {
                        playerName = null;
                    }
                    else
                    {
                        playerName = StoredCustomModel.GetPlayerName(playerName) ?? StoredCustomModel.GetPlayerName(playerName + "+");
                    }
                }

                if (query != null)
                {
                    query = query.ToLower();
                }

                if (all)
                {
                    var dict = GetAllModels(p);
                    if (dict == null)
                    {
                        return;
                    }

                    if (query == null)
                    {
                        p.Message("%TAll %SCustom Models");
                        foreach (var pair in dict.OrderByDescending(pair => pair.Value.Count))
                        {
                            p.Message("  %T{0,3}%S: %T{1}", pair.Value.Count, pair.Key);
                        }
                    }
                    else
                    {
                        var modelNames = new List <string>();
                        foreach (var pair in dict)
                        {
                            modelNames.AddRange(
                                pair.Value.Where(
                                    (name) => name.Contains(query)
                                    )
                                );
                        }

                        p.Message(
                            "%SSearching %TAll %SCustom Models: %T{0}",
                            modelNames.Join("%S, %T")
                            );
                    }
                }
                else
                {
                    var modelNames = GetModels(playerName, p);
                    if (modelNames == null)
                    {
                        return;
                    }

                    if (query == null)
                    {
                        p.Message(
                            "%T{0} %SCustom Models: %T{1}",
                            playerName == null ?
                            "Public" :
                            GetNameWithoutPlus(playerName) + "%S's",
                            modelNames.Join("%S, %T")
                            );
                    }
                    else
                    {
                        p.Message(
                            "%SSearching %T{0} %SCustom Models: %T{1}",
                            playerName == null ?
                            "Public" :
                            GetNameWithoutPlus(playerName) + "%S's",
                            modelNames.Where(
                                (name) => name.Contains(query)
                                ).Join("%S, %T")
                            );
                    }
                }
            }