Files
RobustToolbox/Robust.Server/GameObjects/EntitySystems/InputSystem.cs
T
SilverandGitHub 25926a17b7 Renames SS14.* to Robust.* (#793)
RobustToolbox projects should be named Robust.* 

This PR changes the RobustToolbox projects from SS14.* to Robust.*

Updates SS14.* prefixes/namespaces to Robust.*
Updates SpaceStation14.sln to RobustToolbox.sln
Updates MSBUILD/SS14.* to MSBUILD/Robust.*
Updates CSProject and MSBuild references for the above
Updates git_helper.py
Removes Runserver and Runclient as they are unusable
2019-04-15 20:24:59 -06:00

95 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Input;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
namespace Robust.Server.GameObjects.EntitySystems
{
/// <summary>
/// Server side processing of incoming user commands.
/// </summary>
public class InputSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _playerManager;
private readonly Dictionary<IPlayerSession, IPlayerCommandStates> _playerInputs = new Dictionary<IPlayerSession, IPlayerCommandStates>();
private readonly CommandBindMapping _bindMap = new CommandBindMapping();
/// <summary>
/// Server side input command binds.
/// </summary>
public ICommandBindMapping BindMap => _bindMap;
/// <inheritdoc />
public override void RegisterMessageTypes()
{
RegisterMessageType<FullInputCmdMessage>();
}
/// <inheritdoc />
public override void Initialize()
{
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
}
/// <inheritdoc />
public override void Shutdown()
{
_playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
}
/// <inheritdoc />
public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message)
{
if (!(message is FullInputCmdMessage msg))
return;
//Client Sanitization: out of bounds functionID
if (!_playerManager.KeyMap.TryGetKeyFunction(msg.InputFunctionId, out var function))
return;
var session = _playerManager.GetSessionByChannel(channel);
//Client Sanitization: bad enum key state value
if (!Enum.IsDefined(typeof(BoundKeyState), msg.State))
return;
// route the cmdMessage to the proper bind
//Client Sanitization: unbound command, just ignore
if (_bindMap.TryGetHandler(function, out var command))
{
// set state, only bound key functions get state changes
var states = GetInputStates(session);
states.SetState(function, msg.State);
command.HandleCmdMessage(session, msg);
}
}
public IPlayerCommandStates GetInputStates(IPlayerSession session)
{
return _playerInputs[session];
}
private void OnPlayerStatusChanged(object sender, SessionStatusEventArgs args)
{
switch (args.NewStatus)
{
case SessionStatus.Connected:
_playerInputs.Add(args.Session, new PlayerCommandStates());
break;
case SessionStatus.Disconnected:
_playerInputs.Remove(args.Session);
break;
}
}
}
}