private void Run(IConsoleShell shell, IPlayerSession?player, string eventName)
        {
            var stationSystem = EntitySystem.Get <StationEventSystem>();

            var resultText = eventName == "random"
                ? stationSystem.RunRandomEvent()
                : stationSystem.RunEvent(eventName);

            shell.WriteLine(resultText);
        }
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "You need to be a player to use this command.");
                return;
            }

            EntitySystem.Get <VerbSystem>().AddContainerVisibility(player);
        }
Exemplo n.º 3
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player == null)
            {
                return;
            }
            var attachedEntity = player.AttachedEntity;

            if (args.Length > 2)
            {
                var target = args[2];
                if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity))
                {
                    return;
                }
            }

            if (attachedEntity == null)
            {
                return;
            }
            if (!attachedEntity.TryGetComponent(out ServerActionsComponent? actionsComponent))
            {
                shell.SendText(player, "user has no actions component");
                return;
            }

            var actionTypeRaw = args[0];

            if (!Enum.TryParse <ActionType>(actionTypeRaw, out var actionType))
            {
                shell.SendText(player, "unrecognized ActionType enum value, please" +
                               " ensure you used correct casing: " + actionTypeRaw);
                return;
            }
            var actionMgr = IoCManager.Resolve <ActionManager>();

            if (!actionMgr.TryGet(actionType, out var action))
            {
                shell.SendText(player, "unrecognized actionType " + actionType);
                return;
            }

            var cooldownStart = IoCManager.Resolve <IGameTiming>().CurTime;

            if (!uint.TryParse(args[1], out var seconds))
            {
                shell.SendText(player, "cannot parse seconds: " + args[1]);
                return;
            }

            var cooldownEnd = cooldownStart.Add(TimeSpan.FromSeconds(seconds));

            actionsComponent.Cooldown(action.ActionType, (cooldownStart, cooldownEnd));
        }
Exemplo n.º 4
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            var gasId = -1;
            var gas   = (Gas)(-1);

            if (args.Length < 3)
            {
                return;
            }
            if (!int.TryParse(args[0], out var id) ||
                !(int.TryParse(args[1], out gasId) || Enum.TryParse(args[1], out gas)) ||
                !float.TryParse(args[2], out var moles))
            {
                return;
            }

            var gridId = new GridId(id);

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

            if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp))
            {
                shell.SendText(player, "Invalid grid ID.");
                return;
            }

            var entMan = IoCManager.Resolve <IEntityManager>();

            if (!entMan.TryGetEntity(gridComp.GridEntityId, out var grid))
            {
                shell.SendText(player, "Failed to get grid entity.");
                return;
            }

            if (!grid.HasComponent <GridAtmosphereComponent>())
            {
                shell.SendText(player, "Grid doesn't have an atmosphere.");
                return;
            }

            var gam = grid.GetComponent <GridAtmosphereComponent>();

            foreach (var tile in gam)
            {
                if (gasId != -1)
                {
                    tile.Air?.AdjustMoles(gasId, moles);
                    gam.Invalidate(tile.GridIndices);
                    continue;
                }

                tile.Air?.AdjustMoles(gas, moles);
                gam.Invalidate(tile.GridIndices);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Play an audio file at a static position.
 /// </summary>
 /// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
 /// <param name="coordinates">The coordinates at which to play the audio.</param>
 /// <param name="audioParams"></param>
 /// <param name="range">The max range at which the audio will be heard. Less than or equal to 0 to send to every player.</param>
 /// <param name="excludedSession">Session that won't receive the audio message.</param>
 /// <param name="audioSystem">A pre-fetched instance of <see cref="AudioSystem"/> to use, can be null.</param>
 public static void PlaySoundFrom(
     this EntityCoordinates coordinates,
     string filename,
     AudioParams?audioParams = null,
     int range = AudioDistanceRange,
     IPlayerSession?excludedSession = null,
     AudioSystem?audioSystem        = null)
 {
     audioSystem ??= EntitySystem.Get <AudioSystem>();
     audioSystem.PlayAtCoords(filename, coordinates, audioParams, range, excludedSession);
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Play an audio file following an entity.
 /// </summary>
 /// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
 /// <param name="entity">The entity "emitting" the audio.</param>
 /// <param name="audioParams"></param>
 /// <param name="range">The max range at which the audio will be heard. Less than or equal to 0 to send to every player.</param>
 /// <param name="excludedSession">Sessions that won't receive the audio message.</param>
 /// <param name="audioSystem">A pre-fetched instance of <see cref="AudioSystem"/> to use, can be null.</param>
 public static void PlaySoundFrom(
     this IEntity entity,
     string filename,
     AudioParams?audioParams = null,
     int range = AudioDistanceRange,
     IPlayerSession?excludedSession = null,
     AudioSystem?audioSystem        = null)
 {
     audioSystem ??= EntitySystem.Get <AudioSystem>();
     audioSystem.PlayFromEntity(filename, entity, audioParams, range, excludedSession);
 }
Exemplo n.º 7
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player?.AttachedEntity == null)
            {
                return;
            }

            var pos = player.AttachedEntity.Transform.GridPosition;

            shell.SendText(player, $"MapID:{IoCManager.Resolve<IMapManager>().GetGrid(pos.GridID).ParentMapId} GridID:{pos.GridID} X:{pos.X:N2} Y:{pos.Y:N2}");
        }
Exemplo n.º 8
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }
            if (!int.TryParse(args[0], out var id))
            {
                shell.SendText(player, "Not enough arguments!");
            }

            var gridId = new GridId(id);

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

            if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp))
            {
                shell.SendText(player, "Invalid grid ID.");
                return;
            }

            var entMan = IoCManager.Resolve <IEntityManager>();

            if (!entMan.TryGetEntity(gridComp.GridEntityId, out var grid))
            {
                shell.SendText(player, "Failed to get grid entity.");
                return;
            }

            if (!grid.HasComponent <GridAtmosphereComponent>())
            {
                shell.SendText(player, "Grid doesn't have an atmosphere.");
                return;
            }

            var gam = grid.GetComponent <GridAtmosphereComponent>();

            var tiles = 0;
            var moles = 0f;

            foreach (var tile in gam)
            {
                if (tile.Air == null || tile.Air.Immutable)
                {
                    continue;
                }
                tiles++;
                moles += tile.Air.TotalMoles;
                tile.Air.RemoveRatio(1f);
                gam.Invalidate(tile.GridIndices);
            }

            shell.SendText(player, $"Removed {moles} moles from {tiles} tiles.");
        }
Exemplo n.º 9
0
 public void CreateRestartVote(IPlayerSession?initiator)
 {
     var alone   = _playerManager.PlayerCount == 1 && initiator != null;
     var options = new VoteOptions
     {
         Title   = Loc.GetString("ui-vote-restart-title"),
         Options =
         {
             (Loc.GetString("ui-vote-restart-yes"), true),
             (Loc.GetString("ui-vote-restart-no"),  false)
         },
Exemplo n.º 10
0
 /// <inheritdoc />
 public void SendText(IPlayerSession?session, string?text)
 {
     if (session != null)
     {
         SendText(session.ConnectedClient, text);
     }
     else
     {
         _systemConsole.Print(text + "\n");
     }
 }
Exemplo n.º 11
0
        private void OnPowerStateChanged(object?sender, PowerStateEventArgs e)
        {
            if (e.Powered)
            {
                return;
            }

            UserInterface?.CloseAll();
            _player = null;
            _spectators.Clear();
        }
Exemplo n.º 12
0
    // ReSharper disable once InconsistentNaming
    public void TrySendInGameICMessage(EntityUid source, string message, InGameICChatType desiredType, bool hideChat,
                                       IConsoleShell?shell = null, IPlayerSession?player = null)
    {
        if (HasComp <GhostComponent>(source))
        {
            // Ghosts can only send dead chat messages, so we'll forward it to InGame OOC.
            TrySendInGameOOCMessage(source, message, InGameOOCChatType.Dead, hideChat, shell, player);
            return;
        }

        // Sus
        if (player?.AttachedEntity is { Valid : true } entity&& source != entity)
        {
            return;
        }

        if (!CanSendInGame(message, shell, player))
        {
            return;
        }

        bool shouldCapitalize = (desiredType != InGameICChatType.Emote);

        message = SanitizeInGameICMessage(source, message, out var emoteStr, shouldCapitalize);

        // Was there an emote in the message? If so, send it.
        if (player != null && emoteStr != message && emoteStr != null)
        {
            SendEntityEmote(source, emoteStr, hideChat);
        }

        // This can happen if the entire string is sanitized out.
        if (string.IsNullOrEmpty(message))
        {
            return;
        }

        // Otherwise, send whatever type.
        switch (desiredType)
        {
        case InGameICChatType.Speak:
            SendEntitySpeak(source, message, hideChat);
            break;

        case InGameICChatType.Whisper:
            SendEntityWhisper(source, message, hideChat);
            break;

        case InGameICChatType.Emote:
            SendEntityEmote(source, message, hideChat);
            break;
        }
    }
Exemplo n.º 13
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "You cannot use this command from the server console.");
                return;
            }

            var mgr = IoCManager.Resolve <IAdminManager>();

            mgr.DeAdmin(player);
        }
Exemplo n.º 14
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            var id               = args.Length == 0 ? null : string.Join(" ", args);
            var entityManager    = IoCManager.Resolve <IEntityManager>();
            var prototypeManager = IoCManager.Resolve <IPrototypeManager>();

            IEntityQuery query;

            if (id == null)
            {
                query = new AllEntityQuery();
            }
            else
            {
                if (!prototypeManager.TryIndex(id, out EntityPrototype prototype))
                {
                    shell.SendText(player, $"No entity prototype found with id {id}.");
                    return;
                }

                query = new PredicateEntityQuery(e => e.Prototype == prototype);
            }

            var entities   = 0;
            var components = 0;

            foreach (var entity in entityManager.GetEntities(query))
            {
                if (entity.Prototype == null)
                {
                    continue;
                }

                var modified = false;

                foreach (var component in entity.GetAllComponents())
                {
                    if (!entity.Prototype.Components.ContainsKey(component.Name))
                    {
                        entityManager.ComponentManager.RemoveComponent(entity.Uid, component);
                        components++;

                        modified = true;
                    }
                }

                if (modified)
                {
                    entities++;
                }
            }

            shell.SendText(player, $"Removed {components} components from {entities} entities{(id == null ? "." : $" with id {id}")}");
Exemplo n.º 15
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "You cannot run this command from the server.");
                return;
            }

            var attachedEntity = player.AttachedEntity;

            if (attachedEntity == null)
            {
                shell.SendText(player, "You don't have an entity.");
                return;
            }

            if (args.Length > 2)
            {
                var target = args[2];
                if (!CommandUtils.TryGetAttachedEntityByUsernameOrId(shell, target, player, out attachedEntity))
                {
                    return;
                }
            }

            if (!CommandUtils.ValidateAttachedEntity(shell, player, attachedEntity))
            {
                return;
            }

            if (!attachedEntity.TryGetComponent(out ServerAlertsComponent? alertsComponent))
            {
                shell.SendText(player, "user has no alerts component");
                return;
            }

            var alertType = args[0];
            var severity  = args[1];
            var alertMgr  = IoCManager.Resolve <AlertManager>();

            if (!alertMgr.TryGet(Enum.Parse <AlertType>(alertType), out var alert))
            {
                shell.SendText(player, "unrecognized alertType " + alertType);
                return;
            }
            if (!short.TryParse(severity, out var sevint))
            {
                shell.SendText(player, "invalid severity " + sevint);
                return;
            }
            alertsComponent.ShowAlert(alert.AlertType, sevint == -1 ? (short?)null : sevint);
        }
        public void EquippedHand(EquippedHandEventArgs eventArgs)
        {
            if (!eventArgs.User.TryGetComponent(out IActorComponent? actor) || actor.playerSession == _lastUser)
            {
                return;
            }

            _lastUser = actor.playerSession;

            Owner.PopupMessage(eventArgs.User, Loc.GetString("Play Needles Piano Now"));
            EntitySystem.Get <AudioSystem>().PlayGlobal("/Audio/Misc/needles_piano_pickup.ogg", null,
                                                        session => session == _lastUser);
        }
Exemplo n.º 17
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player?.AttachedEntity == null)
            {
                return;
            }

            var pos           = player.AttachedEntity.Transform.Coordinates;
            var entityManager = IoCManager.Resolve <IEntityManager>();
            var gridId        = pos.GetGridId(entityManager);

            shell.SendText(player, $"MapID:{IoCManager.Resolve<IMapManager>().GetGrid(gridId).ParentMapId} GridID:{gridId} X:{pos.X:N2} Y:{pos.Y:N2}");
        }
Exemplo n.º 18
0
        private void Running(IConsoleShell shell, IPlayerSession?player)
        {
            var eventName = EntitySystem.Get <StationEventSystem>().CurrentEvent?.Name;

            if (!string.IsNullOrEmpty(eventName))
            {
                shell.WriteLine(eventName);
            }
            else
            {
                shell.WriteLine(Loc.GetString("No station event running"));
            }
        }
Exemplo n.º 19
0
        private void SetupPlayer(MapId mapId, IConsoleShell shell, IPlayerSession?player, IMapManager mapManager)
        {
            if (mapId == MapId.Nullspace)
            {
                return;
            }
            var pauseManager = IoCManager.Resolve <IPauseManager>();

            pauseManager.SetMapPaused(mapId, false);
            IoCManager.Resolve <IMapManager>().GetMapEntity(mapId).GetComponent <SharedPhysicsMapComponent>().Gravity = new Vector2(0, -4.9f);

            return;
        }
Exemplo n.º 20
0
        private void SetupPlayer(MapId mapId, IConsoleShell shell, IPlayerSession?player, IMapManager mapManager)
        {
            if (mapId == MapId.Nullspace)
            {
                return;
            }
            mapManager.SetMapPaused(mapId, false);
            var mapUid = mapManager.GetMapEntityIdOrThrow(mapId);

            IoCManager.Resolve <IEntityManager>().GetComponent <SharedPhysicsMapComponent>(mapUid).Gravity = new Vector2(0, -9.8f);

            return;
        }
 /// <summary>
 ///     Sets a state. This can be used for stateful UI updating, which can be easier to implement,
 ///     but is more costly on bandwidth.
 ///     This state is sent to all clients, and automatically sent to all new clients when they open the UI.
 ///     Pretty much how NanoUI did it back in ye olde BYOND.
 /// </summary>
 /// <param name="state">
 ///     The state object that will be sent to all current and future client.
 ///     This can be null.
 /// </param>
 /// <param name="session">
 ///     The player session to send this new state to.
 ///     Set to null for sending it to every subscribed player session.
 /// </param>
 public void SetState(BoundUserInterfaceState state, IPlayerSession?session = null)
 {
     if (session == null)
     {
         _lastState = state;
         _playerStateOverrides.Clear();
     }
     else
     {
         _playerStateOverrides[session] = state;
     }
     _stateDirty = true;
 }
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "This does not work from the server console.");
                return;
            }

            var eui = IoCManager.Resolve <EuiManager>();
            var ui  = new PermissionsEui();

            eui.OpenEui(ui, player);
        }
Exemplo n.º 23
0
            public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
            {
                // system console can't log in to itself, and is pointless anyways
                if (player == null)
                {
                    return;
                }

                var groupController = IoCManager.Resolve <IConGroupController>();

                groupController.SetGroup(player, new ConGroupIndex(1));
                shell.SendText(player, "Logged out.");
            }
Exemplo n.º 24
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player == null)
            {
                shell.SendText(player, "This command cannot be run from the server.");
                return;
            }

            if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue)
            {
                return;
            }

            if (args.Length < 1)
            {
                return;
            }

            var message = string.Join(" ", args).Trim();

            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            var chat         = IoCManager.Resolve <IChatManager>();
            var playerEntity = player.AttachedEntity;

            if (playerEntity == null)
            {
                shell.SendText(player, "You don't have an entity!");
                return;
            }

            if (playerEntity.HasComponent <GhostComponent>())
            {
                chat.SendDeadChat(player, message);
            }
            else
            {
                var mindComponent = player.ContentData()?.Mind;

                if (mindComponent == null)
                {
                    shell.SendText(player, "You don't have a mind!");
                    return;
                }

                chat.EntitySay(mindComponent.OwnedEntity, message);
            }
        }
Exemplo n.º 25
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (player?.Status != SessionStatus.InGame || player.AttachedEntity == null)
            {
                return;
            }

            if (args.Length < 2 || !float.TryParse(args[0], out var posX) || !float.TryParse(args[1], out var posY))
            {
                return;
            }

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

            var position  = new Vector2(posX, posY);
            var transform = player.AttachedEntity?.Transform;

            if (transform == null)
            {
                return;
            }

            transform.AttachToGridOrMap();

            MapId mapId;

            if (args.Length == 3 && int.TryParse(args[2], out var intMapId))
            {
                mapId = new MapId(intMapId);
            }
            else
            {
                mapId = transform.MapID;
            }

            if (mapMgr.TryFindGridAt(mapId, position, out var grid))
            {
                var gridPos = grid.WorldToLocal(position);

                transform.Coordinates = new EntityCoordinates(grid.GridEntityId, gridPos);
            }
            else
            {
                var mapEnt = mapMgr.GetMapEntity(mapId);

                transform.AttachParent(mapEnt);
                transform.WorldPosition = position;
            }

            shell.SendText(player, $"Teleported {player} to {mapId}:{posX},{posY}.");
        }
Exemplo n.º 26
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            IEntity entity;

            switch (args.Length)
            {
            case 0:
                if (player == null)
                {
                    shell.SendText(player, "An entity needs to be specified when the command isn't used by a player.");
                    return;
                }

                if (player.AttachedEntity == null)
                {
                    shell.SendText(player, "An entity needs to be specified when you aren't attached to an entity.");
                    return;
                }

                entity = player.AttachedEntity;
                break;

            case 1:
                if (!EntityUid.TryParse(args[0], out var id))
                {
                    shell.SendText(player, $"{args[0]} isn't a valid entity id.");
                    return;
                }

                var entityManager = IoCManager.Resolve <IEntityManager>();
                if (!entityManager.TryGetEntity(id, out var parsedEntity))
                {
                    shell.SendText(player, $"No entity found with id {id}.");
                    return;
                }

                entity = parsedEntity;
                break;

            default:
                shell.SendText(player, Help);
                return;
            }

            var godmodeSystem = EntitySystem.Get <GodmodeSystem>();
            var enabled       = godmodeSystem.ToggleGodmode(entity);

            shell.SendText(player, enabled
                ? $"Enabled godmode for entity {entity.Name} with id {entity.Uid}"
                : $"Disabled godmode for entity {entity.Name} with id {entity.Uid}");
        }
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            if (args.Length == 0)
            {
                shell.SendText(player, $"Invalid amount of arguments: {args.Length}.\n{Help}");
                return;
            }

            var components       = new List <Type>();
            var componentFactory = IoCManager.Resolve <IComponentFactory>();
            var invalidArgs      = new List <string>();

            foreach (var arg in args)
            {
                if (!componentFactory.TryGetRegistration(arg, out var registration))
                {
                    invalidArgs.Add(arg);
                    continue;
                }

                components.Add(registration.Type);
            }

            if (invalidArgs.Count > 0)
            {
                shell.SendText(player, $"No component found for component names: {string.Join(", ", invalidArgs)}");
                return;
            }

            var entityManager = IoCManager.Resolve <IEntityManager>();
            var query         = new MultipleTypeEntityQuery(components);
            var entityIds     = new HashSet <string>();

            foreach (var entity in entityManager.GetEntities(query))
            {
                if (entity.Prototype == null)
                {
                    continue;
                }

                entityIds.Add(entity.Prototype.ID);
            }

            if (entityIds.Count == 0)
            {
                shell.SendText(player, $"No entities found with components {string.Join(", ", args)}.");
                return;
            }

            shell.SendText(player, $"{entityIds.Count} entities found:\n{string.Join("\n", entityIds)}");
        }
Exemplo n.º 28
0
        public void Execute(IConsoleShell shell, IPlayerSession?player, string[] args)
        {
            var mapManager = IoCManager.Resolve <IMapManager>();

            var msg = new StringBuilder();

            foreach (var grid in mapManager.GetAllGrids().OrderBy(grid => grid.Index.Value))
            {
                msg.AppendFormat("{0}: map: {1}, ent: {4}, default: {2}, pos: {3} \n",
                                 grid.Index, grid.ParentMapId, grid.IsDefaultGrid, grid.WorldPosition, grid.GridEntityId);
            }

            shell.SendText(player, msg.ToString());
        }
Exemplo n.º 29
0
        private void RegisterPlayerSession(IPlayerSession session)
        {
            if (_player == null)
            {
                _player = session;
            }
            else
            {
                _spectators.Add(session);
            }

            UpdatePlayerStatus(session);
            _game?.UpdateNewPlayerUI(session);
        }
Exemplo n.º 30
0
 private void OutputText(IPlayerSession?session, string text, bool error)
 {
     if (session != null)
     {
         var replyMsg = NetManager.CreateNetMessage <MsgConCmdAck>();
         replyMsg.Error = error;
         replyMsg.Text  = text;
         NetManager.ServerSendMessage(replyMsg, session.ConnectedClient);
     }
     else
     {
         _systemConsole.Print(text + "\n");
     }
 }