Admins can get a list of the StationEvents (#1670)
* -GetStationEventsMsg -Fixed random in events help * Don't send on connect * Delete StationEvents on disconnect * Resolve IClientNetManager when needed * :smilethink: * Remove setter * Removed unused imports * Don't resolve twice * Add Event
This commit is contained in:
@@ -1,23 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Content.Server.StationEvents;
|
||||
using Content.Server.StationEvents;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
using Robust.Shared.Interfaces.Reflection;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using static Content.Shared.StationEvents.SharedStationEvent;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems.StationEvents
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class StationEventSystem : EntitySystem
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IServerNetManager _netManager;
|
||||
[Dependency] private readonly IPlayerManager _playerManager;
|
||||
#pragma warning restore 649
|
||||
// Somewhat based off of TG's implementation of events
|
||||
|
||||
|
||||
public StationEvent CurrentEvent { get; private set; }
|
||||
|
||||
public IReadOnlyCollection<StationEvent> StationEvents => _stationEvents;
|
||||
@@ -154,8 +161,31 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
|
||||
var stationEvent = (StationEvent) typeFactory.CreateInstance(type);
|
||||
_stationEvents.Add(stationEvent);
|
||||
}
|
||||
|
||||
_netManager.RegisterNetMessage<MsgGetStationEvents>(nameof(MsgGetStationEvents), GetEventReceived);
|
||||
}
|
||||
|
||||
private void GetEventReceived(MsgGetStationEvents msg)
|
||||
{
|
||||
var player = _playerManager.GetSessionByChannel(msg.MsgChannel);
|
||||
SendEvents(player);
|
||||
}
|
||||
|
||||
private void SendEvents(IPlayerSession player)
|
||||
{
|
||||
if (!IoCManager.Resolve<IConGroupController>().CanCommand(player, "events"))
|
||||
return;
|
||||
|
||||
var newMsg = _netManager.CreateNetMessage<MsgGetStationEvents>();
|
||||
newMsg.Events = new List<string>();
|
||||
foreach (var e in StationEvents)
|
||||
{
|
||||
newMsg.Events.Add(e.Name);
|
||||
}
|
||||
_netManager.ServerSendMessage(newMsg, player.ConnectedClient);
|
||||
}
|
||||
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -318,4 +348,4 @@ namespace Content.Server.GameObjects.EntitySystems.StationEvents
|
||||
CurrentEvent?.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.GameObjects.EntitySystems.StationEvents;
|
||||
using JetBrains.Annotations;
|
||||
@@ -14,11 +14,10 @@ namespace Content.Client.Commands
|
||||
{
|
||||
public string Command => "events";
|
||||
public string Description => "Provides admin control to station events";
|
||||
public string Help => "events <list/pause/resume/random/stop/run <eventname>>\n" +
|
||||
public string Help => "events <list/pause/resume/stop/run <eventname/random>>\n" +
|
||||
"list: return all event names that can be run\n " +
|
||||
"pause: stop all random events from running\n" +
|
||||
"resume: allow random events to run again\n" +
|
||||
"random: choose a random event that is valid and run it\n" +
|
||||
"run: start a particular event now; <eventname> is case-insensitive and not localized";
|
||||
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||
{
|
||||
@@ -99,4 +98,4 @@ namespace Content.Client.Commands
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user