Skip to content

Commit

Permalink
Fix stuck repeating commands (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored Sep 25, 2023
1 parent 90fce27 commit a14ee4a
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions OpenDreamRuntime/Input/DreamCommandSystem.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
using OpenDreamShared.Input;
using Robust.Server.Player;

namespace OpenDreamRuntime.Input {
sealed class DreamCommandSystem : SharedDreamCommandSystem {
[Dependency] private readonly DreamManager _dreamManager = default!;
namespace OpenDreamRuntime.Input;

private readonly List<(string Command, IPlayerSession session)> _repeatingCommands = new();
internal sealed class DreamCommandSystem : SharedDreamCommandSystem {
[Dependency] private readonly DreamManager _dreamManager = default!;

public override void Initialize() {
SubscribeNetworkEvent<CommandEvent>(OnCommandEvent);
SubscribeNetworkEvent<RepeatCommandEvent>(OnRepeatCommandEvent);
SubscribeNetworkEvent<StopRepeatCommandEvent>(OnStopRepeatCommandEvent);
}
private readonly HashSet<(string Command, IPlayerSession session)> _repeatingCommands = new();

public void RunRepeatingCommands() {
foreach (var (command, session) in _repeatingCommands) {
RunCommand(command, session);
}
}
public override void Initialize() {
SubscribeNetworkEvent<CommandEvent>(OnCommandEvent);
SubscribeNetworkEvent<RepeatCommandEvent>(OnRepeatCommandEvent);
SubscribeNetworkEvent<StopRepeatCommandEvent>(OnStopRepeatCommandEvent);
}

private void OnCommandEvent(CommandEvent e, EntitySessionEventArgs sessionEvent) {
RunCommand(e.Command, (IPlayerSession)sessionEvent.SenderSession);
public void RunRepeatingCommands() {
foreach (var (command, session) in _repeatingCommands) {
RunCommand(command, session);
}
}

private void OnRepeatCommandEvent(RepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);
private void OnCommandEvent(CommandEvent e, EntitySessionEventArgs sessionEvent) {
RunCommand(e.Command, (IPlayerSession)sessionEvent.SenderSession);
}

_repeatingCommands.Add(tuple);
}
private void OnRepeatCommandEvent(RepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);

private void OnStopRepeatCommandEvent(StopRepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);
_repeatingCommands.Add(tuple);
}

_repeatingCommands.Remove(tuple);
}
private void OnStopRepeatCommandEvent(StopRepeatCommandEvent e, EntitySessionEventArgs sessionEvent) {
var tuple = (e.Command, (IPlayerSession)sessionEvent.SenderSession);

private void RunCommand(string command, IPlayerSession session) {
var connection = _dreamManager.GetConnectionBySession(session);
connection.HandleCommand(command);
}
_repeatingCommands.Remove(tuple);
}

private void RunCommand(string command, IPlayerSession session) {
var connection = _dreamManager.GetConnectionBySession(session);
connection.HandleCommand(command);
}
}

0 comments on commit a14ee4a

Please sign in to comment.