Esempio n. 1
0
        private void ProcessEmote(string text, string name, ChatChannel channel, int?entityId, NetConnection client)
        {
            if (entityId == null)
            {
                return; //No emotes from non-entities!
            }
            var args = new List <string>();

            CommandParsing.ParseArguments(text, args);
            if (_emotes.ContainsKey(args[0]))
            {
                var userText  = String.Format(_emotes[args[0]].SelfText, name);         //todo user-only channel
                var otherText = String.Format(_emotes[args[0]].OtherText, name, "his"); //todo pronouns, gender
                SendChatMessage(ChatChannel.Emote, otherText, name, entityId);
            }
            else
            {
                //todo Bitch at the user
            }
        }
Esempio n. 2
0
        private void ProcessEmote(string text, string name, ChatChannel channel, int?entityId, INetChannel client)
        {
            if (entityId == null)
            {
                return; //No emotes from non-entities!
            }
            var args = new List <string>();

            CommandParsing.ParseArguments(text, args);
            if (_emotes.ContainsKey(args[0]))
            {
                // todo make a user-only channel that only the sender can see i.e. for emotes and game feedback ('you put the coins in the jar' or whatever)
                var otherText = String.Format(_emotes[args[0]].OtherText, name, "his"); //todo pronouns, gender
                SendChatMessage(ChatChannel.Emote, otherText, name, entityId);
            }
            else
            {
                //todo Bitch at the user
            }
        }
        public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "Only players can use this command");
                return;
            }

            if (args.Length != 2)
            {
                shell.SendText(player, Help);
                return;
            }

            shell.ExecuteCommand(player, $"addmap {args[0]} false");
            shell.ExecuteCommand(player, $"loadbp {args[0]} \"{CommandParsing.Escape(args[1])}\"");
            shell.ExecuteCommand(player, $"aghost");
            shell.ExecuteCommand(player, $"tp 0 0 {args[0]}");

            shell.SendText(player, $"Created unloaded map from file {args[1]} with id {args[0]}. Use \"savebp 4 foo.yml\" to save it.");
        }
Esempio n. 4
0
        /// <inheritdoc />
        public override void ExecuteCommand(ICommonSession?session, string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                return;
            }

            // echo the command locally
            WriteLine(null, "> " + command);

            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List <string>();

            CommandParsing.ParseArguments(command, args);

            var commandName = args[0];

            if (AvailableCommands.ContainsKey(commandName))
            {
                var playerManager = IoCManager.Resolve <IPlayerManager>();
#if !DEBUG
                if (!_conGroup.CanCommand(commandName) && playerManager.LocalPlayer?.Session.Status > SessionStatus.Connecting)
                {
                    WriteError(null, $"Insufficient perms for command: {commandName}");
                    return;
                }
#endif
                var command1 = AvailableCommands[commandName];
                args.RemoveAt(0);
                var shell   = new ConsoleShell(this, null);
                var cmdArgs = args.ToArray();

                AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
                command1.Execute(shell, command, cmdArgs);
            }
            else
            {
                WriteError(null, "Unknown command: " + commandName);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Processes commands (chat messages starting with /)
        /// </summary>
        /// <param name="text">Text content.</param>
        /// <param name="name">Player name that sent the chat text.</param>
        /// <param name="channel">Channel message was received on.</param>
        /// <param name="client">Client that sent the command.</param>
        private void ProcessCommand(string text, string name, ChatChannel channel, int?entityId, INetChannel client)
        {
            List <string> args = new List <string>();

            CommandParsing.ParseArguments(text.Substring(1), args); // Parse, but cut out the first character (/).

            if (args.Count <= 0)
            {
                return;
            }

            string command = args[0];

            if (!_commands.ContainsKey(command))
            {
                string message = string.Format("Command '{0}' not found.", command);
                SendPrivateMessage(client, ChatChannel.Default, message, "Server", null);
                return;
            }

            _commands[command].Execute(this, client, args.ToArray());
        }
Esempio n. 6
0
        /// <summary>
        ///     Processes commands (chat messages starting with /)
        /// </summary>
        /// <param name="text">input text</param>
        public void ProcessCommand(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // echo the command locally
            AddLine("> " + text, Color.Lime);

            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List <string>();

            CommandParsing.ParseArguments(text, args);

            var commandname = args[0];

            var forward = true;

            if (_commands.ContainsKey(commandname))
            {
                var command = _commands[commandname];
                args.RemoveAt(0);
                forward = command.Execute(this, args.ToArray());
            }
            else if (!_network.IsConnected)
            {
                AddLine("Unknown command: " + commandname, Color.Red);
                return;
            }

            if (forward)
            {
                SendServerConsoleCommand(text);
            }
        }
Esempio n. 7
0
 private void SubmitButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
 {
     // Small verification if Player Name exists
     IoCManager.Resolve <IClientConsoleHost>().ExecuteCommand(
         $"ban \"{PlayerNameLine.Text}\" \"{CommandParsing.Escape(ReasonLine.Text)}\" {MinutesLine.Text}");
 }
Esempio n. 8
0
        /// <summary>
        /// Processes commands (chat messages starting with /)
        /// </summary>
        /// <param name="text">input text</param>
        private void ProcessCommand(string text)
        {   
            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List<string>();

            CommandParsing.ParseArguments(text, args);

            string command = args[0];

            //Entity player;
            //var entMgr = IoCManager.Resolve<IEntityManager>();
            //var plrMgr = IoCManager.Resolve<IPlayerManager>();
            //player = plrMgr.ControlledEntity;
            //IoCManager.Resolve<INetworkManager>().

            switch (command)
            {
                case "cls":
                    lines.Clear();
                    components.Clear();
                    last_y = 0;
                    //this.scrollbarH.Value = 0;
                    this.scrollbarV.Value = 0;
                    break;
                case "quit":
                    Environment.Exit(0);
                    break;
                case "addparticles": //This is only clientside.
                    if (args.Count >= 3)
                    {
                        Entity target = null;
                        if (args[1].ToLowerInvariant() == "player")
                        {
                            var plrMgr = IoCManager.Resolve<IPlayerManager>();
                            if (plrMgr != null)
                                if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity;
                        }
                        else
                        {
                            var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
                            if (entMgr != null)
                            {
                                int entUid = int.Parse(args[1]);
                                target = entMgr.EntityManager.GetEntity(entUid);
                            }
                        }

                        if (target != null)
                        {
                            if (!target.HasComponent(ComponentFamily.Particles))
                            {
                                var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
                                var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
                                target.AddComponent(ComponentFamily.Particles, compo);
                            }
                            else
                            {
                                var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
                                var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
                                target.AddComponent(ComponentFamily.Particles, compo);                                
                            }
                        }
                    }
                    SendServerConsoleCommand(text); //Forward to server.
                    break;
                case "removeparticles":
                    if (args.Count >= 3)
                    {
                        Entity target = null;
                        if (args[1].ToLowerInvariant() == "player")
                        {
                            var plrMgr = IoCManager.Resolve<IPlayerManager>();
                            if (plrMgr != null)
                                if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity;
                        }
                        else
                        {
                            var entMgr = IoCManager.Resolve<IEntityManagerContainer>();
                            if (entMgr != null)
                            {
                                int entUid = int.Parse(args[1]);
                                target = entMgr.EntityManager.GetEntity(entUid);
                            }
                        }

                        if (target != null)
                        {
                            if (target.HasComponent(ComponentFamily.Particles))
                            {
                                IParticleSystemComponent compo = (IParticleSystemComponent)target.GetComponent(ComponentFamily.Particles);
                                compo.RemoveParticleSystem(args[2]);
                            }
                        }
                    }
                    SendServerConsoleCommand(text); //Forward to server.
                    break;
                default:
                    SendServerConsoleCommand(text); //Forward to server.
                    break;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Processes commands (chat messages starting with /)
        /// </summary>
        /// <param name="text">input text</param>
        private void ProcessCommand(string text)
        {
            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List <string>();

            CommandParsing.ParseArguments(text, args);

            string command = args[0];

            //Entity player;
            //var entMgr = IoCManager.Resolve<IEntityManager>();
            //var plrMgr = IoCManager.Resolve<IPlayerManager>();
            //player = plrMgr.ControlledEntity;
            //IoCManager.Resolve<INetworkManager>().

            switch (command)
            {
            case "cls":
                components.Clear();
                last_y = 0;
                //this.scrollbarH.Value = 0;
                this.scrollbarV.Value = 0;
                break;

            case "quit":
                Environment.Exit(0);
                break;

            case "addparticles":     //This is only clientside.
                if (args.Count >= 3)
                {
                    Entity target = null;
                    if (args[1].ToLowerInvariant() == "player")
                    {
                        var plrMgr = IoCManager.Resolve <IPlayerManager>();
                        if (plrMgr != null)
                        {
                            if (plrMgr.ControlledEntity != null)
                            {
                                target = plrMgr.ControlledEntity;
                            }
                        }
                    }
                    else
                    {
                        var entMgr = IoCManager.Resolve <IEntityManagerContainer>();
                        if (entMgr != null)
                        {
                            int entUid = int.Parse(args[1]);
                            target = entMgr.EntityManager.GetEntity(entUid);
                        }
                    }

                    if (target != null)
                    {
                        if (!target.HasComponent(ComponentFamily.Particles))
                        {
                            var entMgr = IoCManager.Resolve <IEntityManagerContainer>();
                            var compo  = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
                            target.AddComponent(ComponentFamily.Particles, compo);
                        }
                        else
                        {
                            var entMgr = IoCManager.Resolve <IEntityManagerContainer>();
                            var compo  = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
                            target.AddComponent(ComponentFamily.Particles, compo);
                        }
                    }
                }
                SendServerConsoleCommand(text);     //Forward to server.
                break;

            case "removeparticles":
                if (args.Count >= 3)
                {
                    Entity target = null;
                    if (args[1].ToLowerInvariant() == "player")
                    {
                        var plrMgr = IoCManager.Resolve <IPlayerManager>();
                        if (plrMgr != null)
                        {
                            if (plrMgr.ControlledEntity != null)
                            {
                                target = plrMgr.ControlledEntity;
                            }
                        }
                    }
                    else
                    {
                        var entMgr = IoCManager.Resolve <IEntityManagerContainer>();
                        if (entMgr != null)
                        {
                            int entUid = int.Parse(args[1]);
                            target = entMgr.EntityManager.GetEntity(entUid);
                        }
                    }

                    if (target != null)
                    {
                        if (target.HasComponent(ComponentFamily.Particles))
                        {
                            IParticleSystemComponent compo = (IParticleSystemComponent)target.GetComponent(ComponentFamily.Particles);
                            compo.RemoveParticleSystem(args[2]);
                        }
                    }
                }
                SendServerConsoleCommand(text);     //Forward to server.
                break;

            case "sendchat":
                if (args.Count < 2)
                {
                    return;
                }

                INetworkManager    NetworkManager = IoCManager.Resolve <INetworkManager>();
                NetOutgoingMessage message        = NetworkManager.CreateMessage();
                message.Write((byte)NetMessage.ChatMessage);
                message.Write((byte)ChatChannel.Player);
                message.Write(args[1]);
                NetworkManager.SendMessage(message, NetDeliveryMethod.ReliableUnordered);

                break;

            // To debug console scrolling and stuff.
            case "fill":
                SFML.Graphics.Color[] colors = { SFML.Graphics.Color.Green, SFML.Graphics.Color.Blue, SFML.Graphics.Color.Red };
                Random random = new Random();
                for (int x = 0; x < 50; x++)
                {
                    AddLine("filling...", colors[random.Next(0, colors.Length)]);
                }
                break;

            default:
                SendServerConsoleCommand(text);     //Forward to server.
                break;
            }
        }
Esempio n. 10
0
        private void _onChatBoxTextSubmitted(ChatBox chatBox, string text)
        {
            DebugTools.Assert(chatBox == _currentChatBox);

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            // Check if message is longer than the character limit
            if (text.Length > _maxMessageLength)
            {
                string locWarning = Loc.GetString("Your message exceeds {0} character limit", _maxMessageLength);
                _currentChatBox?.AddLine(locWarning, ChatChannel.Server, Color.Orange);
                _currentChatBox.ClearOnEnter = false;   // The text shouldn't be cleared if it hasn't been sent
                return;
            }

            switch (text[0])
            {
            case ConCmdSlash:
            {
                // run locally
                var conInput = text.Substring(1);
                _console.ProcessCommand(conInput);
                break;
            }

            case OOCAlias:
            {
                var conInput = text.Substring(1);
                if (string.IsNullOrWhiteSpace(conInput))
                {
                    return;
                }
                _console.ProcessCommand($"ooc \"{CommandParsing.Escape(conInput)}\"");
                break;
            }

            case AdminChatAlias:
            {
                var conInput = text.Substring(1);
                if (string.IsNullOrWhiteSpace(conInput))
                {
                    return;
                }
                if (_groupController.CanCommand("asay"))
                {
                    _console.ProcessCommand($"asay \"{CommandParsing.Escape(conInput)}\"");
                }
                else
                {
                    _console.ProcessCommand($"ooc \"{CommandParsing.Escape(conInput)}\"");
                }
                break;
            }

            case MeAlias:
            {
                var conInput = text.Substring(1);
                if (string.IsNullOrWhiteSpace(conInput))
                {
                    return;
                }
                _console.ProcessCommand($"me \"{CommandParsing.Escape(conInput)}\"");
                break;
            }

            default:
            {
                var conInput = _currentChatBox.DefaultChatFormat != null
                        ? string.Format(_currentChatBox.DefaultChatFormat, CommandParsing.Escape(text))
                        : text;

                _console.ProcessCommand(conInput);
                break;
            }
            }
        }
        public void ProcessCommand(string text, NetConnection sender)
        {
            var args = new List <string>();

            CommandParsing.ParseArguments(text, args);

            string command = args[0];

            Vector2 position;
            Entity  player;

            var playerMgr = IoCManager.Resolve <IPlayerManager>();

            player = playerMgr.GetSessionByConnection(sender).attachedEntity;

            var map = IoCManager.Resolve <IMapManager>();

            switch (command)
            {
            case "addparticles":
                if (args.Count >= 3)
                {
                    var    _serverMain = IoCManager.Resolve <ISS14Server>();
                    Entity target      = null;
                    if (args[1].ToLowerInvariant() == "player")
                    {
                        target = player;
                    }
                    else
                    {
                        int entUid = int.Parse(args[1]);
                        target = _serverMain.EntityManager.GetEntity(entUid);
                    }

                    if (target != null)
                    {
                        if (target.HasComponent(ComponentFamily.Particles))
                        {
                            IParticleSystemComponent compo = (IParticleSystemComponent)target.GetComponent(ComponentFamily.Particles);
                            compo.AddParticleSystem(args[2], true);
                        }
                        else
                        {
                            var compo = (IParticleSystemComponent)_serverMain.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent");
                            target.AddComponent(ComponentFamily.Particles, compo);
                            compo.AddParticleSystem(args[2], true);
                            //Can't find a way to add clientside compo from here.
                        }
                    }
                }
                break;

            case "removeparticles":
                if (args.Count >= 3)
                {
                    var    _serverMain = IoCManager.Resolve <ISS14Server>();
                    Entity target      = null;
                    if (args[1].ToLowerInvariant() == "player")
                    {
                        target = player;
                    }
                    else
                    {
                        int entUid = int.Parse(args[1]);
                        target = _serverMain.EntityManager.GetEntity(entUid);
                    }

                    if (target != null)
                    {
                        if (target.HasComponent(ComponentFamily.Particles))
                        {
                            IParticleSystemComponent compo = (IParticleSystemComponent)target.GetComponent(ComponentFamily.Particles);
                            compo.RemoveParticleSystem(args[2]);
                        }
                    }
                }
                break;

            //case "addgas":
            //    if (args.Count > 1 && Convert.ToDouble(args[1]) > 0)
            //    {
            //        if (player != null)
            //        {
            //            double amount = Convert.ToDouble(args[1]);
            //            var t =
            //                map.GetFloorAt(
            //                    player.GetComponent<ITransformComponent>(ComponentFamily.Transform).Position) as
            //                Tile;
            //            if (t != null)
            //                t.GasCell.AddGas((float) amount, GasType.Toxin);
            //            SendConsoleReply(amount.ToString() + " Gas added.", sender);
            //        }
            //    }
            //    break;
            //case "heatgas":
            //    if (args.Count > 1 && Convert.ToDouble(args[1]) > 0)
            //    {
            //        if (player != null)
            //        {
            //            double amount = Convert.ToDouble(args[1]);
            //            var t =
            //                map.GetFloorAt(
            //                    player.GetComponent<ITransformComponent>(ComponentFamily.Transform).Position) as
            //                Tile;
            //            if (t != null)
            //                t.GasCell.AddGas((float) amount, GasType.Toxin);
            //            SendConsoleReply(amount.ToString() + " Gas added.", sender);
            //        }
            //    }
            //    break;
            //case "atmosreport":
            //    IoCManager.Resolve<IAtmosManager>().TotalAtmosReport();
            //    break;
            //case "tpvreport": // Reports on temp / pressure
            //    if (player != null)
            //    {
            //        var ti =
            //            (Tile)
            //            map.GetFloorAt(player.GetComponent<ITransformComponent>(ComponentFamily.Transform).Position);
            //        if (ti == null)
            //            break;
            //        GasCell ce = ti.gasCell;
            //        SendConsoleReply("T/P/V: " + ce.GasMixture.Temperature.ToString() + " / " + ce.GasMixture.Pressure.ToString() + " / " + ce.GasVelocity.ToString(), sender);
            //        //var chatMgr = IoCManager.Resolve<IChatManager>();
            //        //chatMgr.SendChatMessage(ChatChannel.Default,
            //        //                        "T/P/V: " + ce.GasMixture.Temperature.ToString() + " / " +
            //        //                        ce.GasMixture.Pressure.ToString() + " / " + ce.GasVelocity.ToString(),
            //        //                        "TempCheck",
            //        //                        0);
            //    }
            //    break;
            //case "gasreport":
            //    if (player != null)
            //    {
            //        var tile = map.GetFloorAt(player.GetComponent<ITransformComponent>(ComponentFamily.Transform).Position) as Tile;
            //        if (tile == null)
            //            break;
            //        GasCell c = tile.gasCell;
            //        for (int i = 0; i < c.GasMixture.gasses.Length; i++)
            //        {
            //            SendConsoleReply(((GasType) i).ToString() + ": " +c.GasMixture.gasses[i].ToString(CultureInfo.InvariantCulture) + " m", sender);
            //            //var chatMgr = IoCManager.Resolve<IChatManager>();
            //            //chatMgr.SendChatMessage(ChatChannel.Default,
            //            //                        ((GasType) i).ToString() + ": " +
            //            //                        c.GasMixture.gasses[i].ToString(CultureInfo.InvariantCulture) + " m",
            //            //                        "GasReport", 0);
            //        }
            //    }
            //    break;
            case "everyonesondrugs":
                foreach (IPlayerSession playerfordrugs in IoCManager.Resolve <IPlayerManager>().GetAllPlayers())
                {
                    playerfordrugs.AddPostProcessingEffect(PostProcessingEffectType.Acid, 60);
                    SendConsoleReply("Okay then.", sender);
                }
                break;

            default:
                string message = "Command '" + command + "' not recognized.";
                SendConsoleReply(message, sender);
                break;
            }
        }
        public LateJoinGui()
        {
            IoCManager.InjectDependencies(this);

            Title = Loc.GetString("Late Join");

            var jobList = new VBoxContainer();
            var vBox    = new VBoxContainer
            {
                Children =
                {
                    new ScrollContainer
                    {
                        SizeFlagsVertical = SizeFlags.FillExpand,
                        Children          =
                        {
                            jobList
                        }
                    }
                }
            };

            Contents.AddChild(vBox);

            foreach (var job in _prototypeManager.EnumeratePrototypes <JobPrototype>().OrderBy(j => j.Name))
            {
                var jobButton = new JobButton
                {
                    JobId = job.ID
                };

                var jobSelector = new HBoxContainer
                {
                    SizeFlagsHorizontal = SizeFlags.FillExpand
                };

                var icon = new TextureRect
                {
                    TextureScale = (2, 2),
                    Stretch      = TextureRect.StretchMode.KeepCentered
                };

                if (job.Icon != null)
                {
                    var specifier = new SpriteSpecifier.Rsi(new ResourcePath("/Textures/Interface/Misc/job_icons.rsi"), job.Icon);
                    icon.Texture = specifier.Frame0();
                }
                jobSelector.AddChild(icon);

                var jobLabel = new Label
                {
                    Text = job.Name
                };

                jobSelector.AddChild(jobLabel);

                jobButton.AddChild(jobSelector);
                jobList.AddChild(jobButton);
                jobButton.OnPressed += args =>
                {
                    SelectedId?.Invoke(jobButton.JobId);
                };
            }

            SelectedId += jobId =>
            {
                Logger.InfoS("latejoin", $"Late joining as ID: {jobId}");
                _console.ProcessCommand($"joingame {CommandParsing.Escape(jobId)}");
                Close();
            };
        }
Esempio n. 13
0
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            var player = shell.Player as IPlayerSession;

            if (player == null)
            {
                shell.WriteLine("Only players can use this command");
                return;
            }

#if DEBUG
            shell.WriteError("WARNING: The server is using a debug build. You are risking losing your changes.");
#endif

            var    mapManager = IoCManager.Resolve <IMapManager>();
            int    mapId;
            string mapName;

            switch (args.Length)
            {
            case 1:
                if (player.AttachedEntity == null)
                {
                    shell.WriteError("The map name argument cannot be omitted if you have no entity.");
                    return;
                }

                mapId   = (int)mapManager.NextMapId();
                mapName = args[0];
                break;

            case 2:
                if (!int.TryParse(args[0], out var id))
                {
                    shell.WriteError($"{args[0]} is not a valid integer.");
                    return;
                }

                mapId   = id;
                mapName = args[1];
                break;

            default:
                shell.WriteLine(Help);
                return;
            }

            if (mapManager.MapExists(new MapId(mapId)))
            {
                shell.WriteLine($"Map {mapId} already exists");
                return;
            }

            shell.ExecuteCommand("sudo cvar events.enabled false");
            shell.ExecuteCommand($"addmap {mapId} false");
            shell.ExecuteCommand($"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true");

            if (player.AttachedEntity is { Valid : true } playerEntity&&
                _entities.GetComponent <MetaDataComponent>(playerEntity).EntityPrototype?.ID != "AdminObserver")
            {
                shell.ExecuteCommand("aghost");
            }

            shell.ExecuteCommand($"tp 0 0 {mapId}");
            shell.RemoteExecuteCommand("showmarkers");

            var newGrid      = mapManager.GetAllGrids().OrderByDescending(g => (int)g.Index).First();
            var pauseManager = IoCManager.Resolve <IPauseManager>();

            pauseManager.SetMapPaused(newGrid.ParentMapId, true);

            shell.WriteLine($"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGrid.Index} foo.yml\" to save the new grid as a map.");
        }
        public void TestEscape(string source, string expected)
        {
            var escaped = CommandParsing.Escape(source);

            Assert.That(escaped, Is.EqualTo(expected));
        }
Esempio n. 15
0
 public Side(CommandParsing type, DataHandler dh)
 {
 }
Esempio n. 16
0
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            var player = shell.Player as IPlayerSession;

            if (player == null)
            {
                shell.WriteLine("Only players can use this command");
                return;
            }

            if (args.Length > 2)
            {
                shell.WriteLine(Help);
                return;
            }

#if DEBUG
            shell.WriteError("WARNING: The server is using a debug build. You are risking losing your changes.");
#endif

            var   mapManager = IoCManager.Resolve <IMapManager>();
            MapId mapId;

            // Get the map ID to use
            if (args.Length == 2)
            {
                if (!int.TryParse(args[1], out var id))
                {
                    shell.WriteError($"{args[1]} is not a valid integer.");
                    return;
                }

                mapId = new MapId(id);
                if (mapManager.MapExists(mapId))
                {
                    shell.WriteError($"Map {mapId} already exists");
                    return;
                }
            }
            else
            {
                mapId = mapManager.NextMapId();
            }

            // either load a map or create a new one.
            if (args.Length == 0)
            {
                shell.ExecuteCommand($"addmap {mapId} false");
            }
            else
            {
                shell.ExecuteCommand($"loadmap {mapId} \"{CommandParsing.Escape(args[0])}\"");
            }

            // was the map actually created?
            if (!mapManager.MapExists(mapId))
            {
                shell.WriteError($"An error occurred when creating the new map.");
                return;
            }

            // map successfully created. run misc helpful mapping commands
            if (player.AttachedEntity is { Valid : true } playerEntity&&
                _entities.GetComponent <MetaDataComponent>(playerEntity).EntityPrototype?.ID != "AdminObserver")
            {
                shell.ExecuteCommand("aghost");
            }

            shell.ExecuteCommand("sudo cvar events.enabled false");
            shell.ExecuteCommand($"tp 0 0 {mapId}");
            shell.RemoteExecuteCommand("showmarkers");
            shell.RemoteExecuteCommand("togglelight");
            shell.RemoteExecuteCommand("showsubfloorforever");
            mapManager.SetMapPaused(mapId, true);

            if (args.Length != 0)
            {
                shell.WriteLine($"Created uninitialized map from file {args[0]} with id {mapId}.");
            }
            else
            {
                shell.WriteLine($"Created a new uninitialized map with id {mapId}.");
            }
        }