From 1409016cbda0c65e36a2a2ef56afd0f15a2c0e88 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 2 Nov 2010 13:30:49 +1300 Subject: [PATCH] (gecko) Allow mods to override order validation --- OpenRA.Game/Network/Connection.cs | 4 ++-- OpenRA.Game/Network/OrderManager.cs | 2 +- OpenRA.Game/Network/UnitOrders.cs | 12 +++++----- OpenRA.Game/OpenRA.Game.csproj | 3 ++- OpenRA.Game/Traits/TraitsInterfaces.cs | 7 ++++-- OpenRA.Game/Traits/ValidateOrder.cs | 31 ++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 OpenRA.Game/Traits/ValidateOrder.cs diff --git a/OpenRA.Game/Network/Connection.cs b/OpenRA.Game/Network/Connection.cs index e2bdfb75ff..97fb39e0de 100755 --- a/OpenRA.Game/Network/Connection.cs +++ b/OpenRA.Game/Network/Connection.cs @@ -18,7 +18,7 @@ using OpenRA.Support; namespace OpenRA.Network { - enum ConnectionState + public enum ConnectionState { PreConnecting, NotConnected, @@ -26,7 +26,7 @@ namespace OpenRA.Network Connected, } - interface IConnection : IDisposable + public interface IConnection : IDisposable { int LocalClientId { get; } ConnectionState ConnectionState { get; } diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs index 4a1df96808..3c8e09756f 100755 --- a/OpenRA.Game/Network/OrderManager.cs +++ b/OpenRA.Game/Network/OrderManager.cs @@ -16,7 +16,7 @@ using OpenRA.FileFormats; namespace OpenRA.Network { - class OrderManager : IDisposable + public class OrderManager : IDisposable { readonly SyncReport syncReport; readonly FrameData frameData = new FrameData(); diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index b62cfac2ad..ae2733cd2b 100755 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -27,14 +27,14 @@ namespace OpenRA.Network public static void ProcessOrder( OrderManager orderManager, World world, int clientId, Order order ) { - // Drop exploiting orders - if (order.Subject != null && order.Subject.Owner.ClientIndex != clientId) + if (world != null) { - Game.Debug("Detected exploit order from {0}: {1}".F(clientId, order.OrderString)); - return; + if (!world.WorldActor.TraitsImplementing().All(vo => + vo.OrderValidation(orderManager, world, clientId, order))) + return; } - - switch( order.OrderString ) + + switch( order.OrderString ) { case "Chat": { diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index c5f37e8455..503d4c103f 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -221,6 +221,7 @@ + @@ -257,4 +258,4 @@ --> - \ No newline at end of file + diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index d4403603e3..930c4bdfe9 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -13,6 +13,7 @@ using System.Drawing; using OpenRA.FileFormats; using OpenRA.GameRules; using OpenRA.Graphics; +using OpenRA.Network; namespace OpenRA.Traits { @@ -44,8 +45,10 @@ namespace OpenRA.Traits int OrderPriority { get; } bool CanTargetUnit( Actor self, Actor target, bool forceAttack, bool forceMove, ref string cursor ); bool CanTargetLocation( Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceMove, ref string cursor ); - } - public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } + } + public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } + public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); + } public interface IOrderCursor { string CursorForOrder(Actor self, Order order); } public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); } diff --git a/OpenRA.Game/Traits/ValidateOrder.cs b/OpenRA.Game/Traits/ValidateOrder.cs new file mode 100644 index 0000000000..f2af3c179f --- /dev/null +++ b/OpenRA.Game/Traits/ValidateOrder.cs @@ -0,0 +1,31 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using OpenRA.Network; + +namespace OpenRA.Traits +{ + public class ValidateOrderInfo : TraitInfo { } + + public class ValidateOrder : IValidateOrder + { + public bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order) + { + // Drop exploiting orders + if (order.Subject != null && order.Subject.Owner.ClientIndex != clientId) + { + Game.Debug("Detected exploit order from {0}: {1}".F(clientId, order.OrderString)); + return false; + } + + return true; + } + } +}