Fix inconsistent code formatting
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Torch.Managers.NetworkManager;
|
||||
using VRage.Library.Collections;
|
||||
using VRage.Network;
|
||||
using VRage.Utils;
|
||||
@@ -14,39 +13,39 @@ namespace Torch.Managers
|
||||
{
|
||||
public ChatManager()
|
||||
{
|
||||
NetworkManager.NetworkManager.Instance.RegisterNetworkHandlers(new ChatIntercept());
|
||||
NetworkManager.Instance.RegisterNetworkHandlers(new ChatIntercept());
|
||||
}
|
||||
|
||||
private static ChatManager _instance;
|
||||
public static ChatManager Instance => _instance ?? (_instance = new ChatManager());
|
||||
|
||||
public delegate void MessageRecievedDel( ChatMsg msg, ref bool sendToOthers );
|
||||
public delegate void MessageRecievedDel(ChatMsg msg, ref bool sendToOthers);
|
||||
|
||||
public event MessageRecievedDel MessageRecieved;
|
||||
|
||||
internal void RaiseMessageRecieved( ChatMsg msg, ref bool sendToOthers ) =>
|
||||
internal void RaiseMessageRecieved(ChatMsg msg, ref bool sendToOthers) =>
|
||||
MessageRecieved?.Invoke(msg, ref sendToOthers);
|
||||
}
|
||||
|
||||
internal class ChatIntercept : NetworkHandlerBase
|
||||
{
|
||||
private bool? _unitTestResult;
|
||||
public override bool CanHandle( CallSite site )
|
||||
public override bool CanHandle(CallSite site)
|
||||
{
|
||||
if ( site.MethodInfo.Name != "OnChatMessageRecieved" )
|
||||
if (site.MethodInfo.Name != "OnChatMessageRecieved")
|
||||
return false;
|
||||
|
||||
if ( _unitTestResult.HasValue )
|
||||
if (_unitTestResult.HasValue)
|
||||
return _unitTestResult.Value;
|
||||
|
||||
var parameters = site.MethodInfo.GetParameters();
|
||||
if ( parameters.Length != 1 )
|
||||
if (parameters.Length != 1)
|
||||
{
|
||||
_unitTestResult = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( parameters[0].ParameterType != typeof(ChatMsg) )
|
||||
if (parameters[0].ParameterType != typeof(ChatMsg))
|
||||
_unitTestResult = false;
|
||||
|
||||
_unitTestResult = true;
|
||||
@@ -54,14 +53,14 @@ namespace Torch.Managers
|
||||
return _unitTestResult.Value;
|
||||
}
|
||||
|
||||
public override bool Handle( ulong remoteUserId, CallSite site, BitStream stream, object obj )
|
||||
public override bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj)
|
||||
{
|
||||
ChatMsg msg = new ChatMsg();
|
||||
var msg = new ChatMsg();
|
||||
|
||||
base.Serialize( site.MethodInfo, stream, ref msg );
|
||||
base.Serialize(site.MethodInfo, stream, ref msg);
|
||||
|
||||
bool sendToOthers = true;
|
||||
ChatManager.Instance.RaiseMessageRecieved( msg, ref sendToOthers );
|
||||
ChatManager.Instance.RaiseMessageRecieved(msg, ref sendToOthers);
|
||||
|
||||
return !sendToOthers;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ using VRage.Library.Collections;
|
||||
using VRage.Network;
|
||||
using VRage.Serialization;
|
||||
|
||||
namespace Torch.Managers.NetworkManager
|
||||
namespace Torch.Managers
|
||||
{
|
||||
public abstract class NetworkHandlerBase
|
||||
{
|
||||
@@ -17,7 +17,7 @@ namespace Torch.Managers.NetworkManager
|
||||
/// </summary>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public abstract bool CanHandle( CallSite site );
|
||||
public abstract bool CanHandle(CallSite site);
|
||||
|
||||
/// <summary>
|
||||
/// Performs action on network packet. Return value of true means the packet has been handled, and will not be passed on to the game server.
|
||||
@@ -27,7 +27,7 @@ namespace Torch.Managers.NetworkManager
|
||||
/// <param name="stream"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public abstract bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj );
|
||||
public abstract bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj);
|
||||
|
||||
/// <summary>
|
||||
/// Extracts method arguments from the bitstream or packs them back in, depending on stream read mode.
|
||||
@@ -220,22 +220,22 @@ namespace Torch.Managers.NetworkManager
|
||||
if ( stream.Reading )
|
||||
{
|
||||
MySerializationHelpers.CreateAndRead(stream, out arg1, s1, info1);
|
||||
MySerializationHelpers.CreateAndRead( stream, out arg2, s2, info2 );
|
||||
MySerializationHelpers.CreateAndRead( stream, out arg3, s3, info3 );
|
||||
MySerializationHelpers.CreateAndRead( stream, out arg4, s4, info4 );
|
||||
MySerializationHelpers.CreateAndRead( stream, out arg5, s5, info5 );
|
||||
MySerializationHelpers.CreateAndRead( stream, out arg6, s6, info6 );
|
||||
MySerializationHelpers.CreateAndRead( stream, out arg7, s7, info7 );
|
||||
MySerializationHelpers.CreateAndRead(stream, out arg2, s2, info2);
|
||||
MySerializationHelpers.CreateAndRead(stream, out arg3, s3, info3);
|
||||
MySerializationHelpers.CreateAndRead(stream, out arg4, s4, info4);
|
||||
MySerializationHelpers.CreateAndRead(stream, out arg5, s5, info5);
|
||||
MySerializationHelpers.CreateAndRead(stream, out arg6, s6, info6);
|
||||
MySerializationHelpers.CreateAndRead(stream, out arg7, s7, info7);
|
||||
}
|
||||
else
|
||||
{
|
||||
MySerializationHelpers.Write( stream, ref arg1, s1, info1 );
|
||||
MySerializationHelpers.Write( stream, ref arg2, s2, info2 );
|
||||
MySerializationHelpers.Write( stream, ref arg3, s3, info3 );
|
||||
MySerializationHelpers.Write( stream, ref arg4, s4, info4 );
|
||||
MySerializationHelpers.Write( stream, ref arg5, s5, info5 );
|
||||
MySerializationHelpers.Write( stream, ref arg6, s6, info6 );
|
||||
MySerializationHelpers.Write( stream, ref arg7, s7, info7 );
|
||||
MySerializationHelpers.Write(stream, ref arg1, s1, info1);
|
||||
MySerializationHelpers.Write(stream, ref arg2, s2, info2);
|
||||
MySerializationHelpers.Write(stream, ref arg3, s3, info3);
|
||||
MySerializationHelpers.Write(stream, ref arg4, s4, info4);
|
||||
MySerializationHelpers.Write(stream, ref arg5, s5, info5);
|
||||
MySerializationHelpers.Write(stream, ref arg6, s6, info6);
|
||||
MySerializationHelpers.Write(stream, ref arg7, s7, info7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ using VRage;
|
||||
using VRage.Library.Collections;
|
||||
using VRage.Network;
|
||||
|
||||
namespace Torch.Managers.NetworkManager
|
||||
namespace Torch.Managers
|
||||
{
|
||||
public class NetworkManager
|
||||
{
|
||||
@@ -33,26 +33,26 @@ namespace Torch.Managers.NetworkManager
|
||||
try
|
||||
{
|
||||
var syncLayerType = typeof(MySyncLayer);
|
||||
var transportLayerField = syncLayerType.GetField( MyTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
var transportLayerField = syncLayerType.GetField(MyTransportLayerField, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
if ( transportLayerField == null )
|
||||
throw new TypeLoadException( "Could not find internal type for TransportLayer" );
|
||||
if (transportLayerField == null)
|
||||
throw new TypeLoadException("Could not find internal type for TransportLayer");
|
||||
|
||||
Type transportLayerType = transportLayerField.FieldType;
|
||||
var transportLayerType = transportLayerField.FieldType;
|
||||
|
||||
Type replicationLayerType = typeof(MyReplicationLayerBase);
|
||||
if ( !Reflection.HasField( replicationLayerType, TypeTableField ) )
|
||||
throw new TypeLoadException( "Could not find TypeTable field" );
|
||||
var replicationLayerType = typeof(MyReplicationLayerBase);
|
||||
if (!Reflection.HasField(replicationLayerType, TypeTableField))
|
||||
throw new TypeLoadException("Could not find TypeTable field");
|
||||
|
||||
if ( !Reflection.HasField( transportLayerType, TransportHandlersField ) )
|
||||
throw new TypeLoadException( "Could not find Handlers field" );
|
||||
if (!Reflection.HasField(transportLayerType, TransportHandlersField))
|
||||
throw new TypeLoadException("Could not find Handlers field");
|
||||
|
||||
return true;
|
||||
}
|
||||
catch ( TypeLoadException ex )
|
||||
catch (TypeLoadException ex)
|
||||
{
|
||||
//ApplicationLog.BaseLog.Error(ex);
|
||||
TorchBase.Instance.Log.WriteException( ex );
|
||||
TorchBase.Instance.Log.WriteException(ex);
|
||||
if ( suppress )
|
||||
return false;
|
||||
throw;
|
||||
@@ -107,13 +107,13 @@ namespace Torch.Managers.NetworkManager
|
||||
return;
|
||||
}
|
||||
|
||||
BitStream stream = new BitStream();
|
||||
var stream = new BitStream();
|
||||
stream.ResetRead(packet);
|
||||
|
||||
NetworkId networkId = stream.ReadNetworkId();
|
||||
var networkId = stream.ReadNetworkId();
|
||||
//this value is unused, but removing this line corrupts the rest of the stream
|
||||
NetworkId blockedNetworkId = stream.ReadNetworkId();
|
||||
uint eventId = (uint)stream.ReadByte();
|
||||
var blockedNetworkId = stream.ReadNetworkId();
|
||||
var eventId = (uint)stream.ReadByte();
|
||||
|
||||
|
||||
CallSite site;
|
||||
@@ -133,7 +133,7 @@ namespace Torch.Managers.NetworkManager
|
||||
return;
|
||||
}
|
||||
var typeInfo = m_typeTable.Get(sendAs.GetType());
|
||||
int eventCount = typeInfo.EventTable.Count;
|
||||
var eventCount = typeInfo.EventTable.Count;
|
||||
if (eventId < eventCount) // Directly
|
||||
{
|
||||
obj = sendAs;
|
||||
@@ -148,23 +148,23 @@ namespace Torch.Managers.NetworkManager
|
||||
}
|
||||
|
||||
//we're handling the network live in the game thread, this needs to go as fast as possible
|
||||
bool handled = false;
|
||||
var discard = false;
|
||||
Parallel.ForEach(_networkHandlers, handler =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (handler.CanHandle(site))
|
||||
handled |= handler.Handle(packet.Sender.Value, site, stream, obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//ApplicationLog.Error(ex.ToString());
|
||||
TorchBase.Instance.Log.WriteException(ex);
|
||||
}
|
||||
});
|
||||
{
|
||||
try
|
||||
{
|
||||
if (handler.CanHandle(site))
|
||||
discard |= handler.Handle(packet.Sender.Value, site, stream, obj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//ApplicationLog.Error(ex.ToString());
|
||||
TorchBase.Instance.Log.WriteException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
//one of the handlers wants us to discard this packet
|
||||
if (handled)
|
||||
if (discard)
|
||||
return;
|
||||
|
||||
//pass the message back to the game server
|
||||
@@ -183,8 +183,8 @@ namespace Torch.Managers.NetworkManager
|
||||
|
||||
private void RegisterNetworkHandler(NetworkHandlerBase handler)
|
||||
{
|
||||
string handlerType = handler.GetType().FullName;
|
||||
List<NetworkHandlerBase> toRemove = new List<NetworkHandlerBase>();
|
||||
var handlerType = handler.GetType().FullName;
|
||||
var toRemove = new List<NetworkHandlerBase>();
|
||||
foreach (var item in _networkHandlers)
|
||||
{
|
||||
if (item.GetType().FullName == handlerType)
|
||||
@@ -253,7 +253,7 @@ namespace Torch.Managers.NetworkManager
|
||||
|
||||
var owner = obj as IMyEventOwner;
|
||||
if (obj != null && owner == null )
|
||||
throw new InvalidCastException( "Provided event target is not of type IMyEventOwner!" );
|
||||
throw new InvalidCastException("Provided event target is not of type IMyEventOwner!");
|
||||
|
||||
if(!method.HasAttribute<EventAttribute>())
|
||||
throw new CustomAttributeFormatException("Provided event target does not have the Event attribute! Replication will not succeed!");
|
||||
@@ -267,23 +267,23 @@ namespace Torch.Managers.NetworkManager
|
||||
arguments[3] = owner;
|
||||
|
||||
//copy supplied arguments into the reflection arguments
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
arguments[i + 4] = args[i];
|
||||
|
||||
//pad the array out with DBNull
|
||||
for (int j = args.Length + 4; j < 10; j++)
|
||||
for (var j = args.Length + 4; j < 10; j++)
|
||||
arguments[j] = e;
|
||||
|
||||
arguments[10] = (IMyEventOwner)null;
|
||||
|
||||
//create an array of Types so we can create a generic method
|
||||
Type[] argTypes = new Type[8];
|
||||
var argTypes = new Type[8];
|
||||
|
||||
for (int k = 3; k < 11; k++)
|
||||
for (var k = 3; k < 11; k++)
|
||||
argTypes[k - 3] = arguments[k]?.GetType() ?? typeof(IMyEventOwner);
|
||||
|
||||
var parameters = method.GetParameters();
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
for (var i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
if (argTypes[i] != parameters[i].ParameterType)
|
||||
throw new TypeLoadException($"Type mismatch on method parameters. Expected {string.Join(", ", parameters.Select(p => p.ParameterType.ToString()))} got {string.Join(", ", argTypes.Select(t => t.ToString()))}");
|
||||
|
@@ -10,27 +10,27 @@ namespace Torch
|
||||
public static class Reflection
|
||||
{
|
||||
//private static readonly Logger Log = LogManager.GetLogger( "BaseLog" );
|
||||
public static bool HasMethod( Type objectType, string methodName )
|
||||
public static bool HasMethod(Type objectType, string methodName)
|
||||
{
|
||||
return Reflection.HasMethod( objectType, methodName, null );
|
||||
return HasMethod(objectType, methodName, null);
|
||||
}
|
||||
|
||||
|
||||
public static bool HasMethod( Type objectType, string methodName, Type[ ] argTypes )
|
||||
public static bool HasMethod(Type objectType, string methodName, Type[] argTypes)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( String.IsNullOrEmpty( methodName ) )
|
||||
if (string.IsNullOrEmpty(methodName))
|
||||
return false;
|
||||
|
||||
if ( argTypes == null )
|
||||
if (argTypes == null)
|
||||
{
|
||||
MethodInfo method = objectType.GetMethod( methodName );
|
||||
if ( method == null )
|
||||
method = objectType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
||||
if ( method == null && objectType.BaseType != null )
|
||||
method = objectType.BaseType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
||||
if ( method == null )
|
||||
var methodInfo = objectType.GetMethod(methodName);
|
||||
if (methodInfo == null)
|
||||
methodInfo = objectType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
if (methodInfo == null && objectType.BaseType != null)
|
||||
methodInfo = objectType.BaseType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
if (methodInfo == null)
|
||||
{
|
||||
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "'" );
|
||||
return false;
|
||||
@@ -38,12 +38,12 @@ namespace Torch
|
||||
}
|
||||
else
|
||||
{
|
||||
MethodInfo method = objectType.GetMethod( methodName, argTypes );
|
||||
if ( method == null )
|
||||
method = objectType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null );
|
||||
if ( method == null && objectType.BaseType != null )
|
||||
method = objectType.BaseType.GetMethod( methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null );
|
||||
if ( method == null )
|
||||
MethodInfo method = objectType.GetMethod(methodName, argTypes);
|
||||
if (method == null)
|
||||
method = objectType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null);
|
||||
if (method == null && objectType.BaseType != null)
|
||||
method = objectType.BaseType.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, Type.DefaultBinder, argTypes, null);
|
||||
if (method == null)
|
||||
{
|
||||
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "'" );
|
||||
return false;
|
||||
@@ -52,11 +52,11 @@ namespace Torch
|
||||
|
||||
return true;
|
||||
}
|
||||
catch ( AmbiguousMatchException aex )
|
||||
catch (AmbiguousMatchException aex)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
catch ( Exception ex )
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log.Error( "Failed to find method '" + methodName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
||||
//Log.Error( ex );
|
||||
@@ -64,25 +64,25 @@ namespace Torch
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasField( Type objectType, string fieldName )
|
||||
public static bool HasField(Type objectType, string fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( String.IsNullOrEmpty( fieldName ) )
|
||||
if (string.IsNullOrEmpty(fieldName))
|
||||
return false;
|
||||
FieldInfo field = objectType.GetField( fieldName );
|
||||
if ( field == null )
|
||||
field = objectType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
||||
if ( field == null )
|
||||
field = objectType.BaseType.GetField( fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
||||
if ( field == null )
|
||||
var field = objectType.GetField(fieldName);
|
||||
if (field == null)
|
||||
field = objectType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
if (field == null)
|
||||
field = objectType.BaseType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
if (field == null)
|
||||
{
|
||||
//Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "'" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch ( Exception ex )
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log.Error( "Failed to find field '" + fieldName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
||||
//Log.Error( ex );
|
||||
@@ -90,25 +90,25 @@ namespace Torch
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasProperty( Type objectType, string propertyName )
|
||||
public static bool HasProperty(Type objectType, string propertyName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( String.IsNullOrEmpty( propertyName ) )
|
||||
if (string.IsNullOrEmpty(propertyName))
|
||||
return false;
|
||||
PropertyInfo prop = objectType.GetProperty( propertyName );
|
||||
if ( prop == null )
|
||||
prop = objectType.GetProperty( propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
||||
if ( prop == null )
|
||||
prop = objectType.BaseType.GetProperty( propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy );
|
||||
if ( prop == null )
|
||||
var prop = objectType.GetProperty(propertyName);
|
||||
if (prop == null)
|
||||
prop = objectType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
if (prop == null)
|
||||
prop = objectType.BaseType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
if (prop == null)
|
||||
{
|
||||
//Log.Error( "Failed to find property '" + propertyName + "' in type '" + objectType.FullName + "'" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch ( Exception ex )
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log.Error( "Failed to find property '" + propertyName + "' in type '" + objectType.FullName + "': " + ex.Message );
|
||||
//Log.Error( ex );
|
||||
|
@@ -18,6 +18,7 @@ namespace Torch
|
||||
/// Dirty hack because *keen*
|
||||
/// Use only if absolutely necessary.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public static ITorchBase Instance { get; private set; }
|
||||
public string[] RunArgs { get; set; }
|
||||
public IPluginManager Plugins { get; protected set; }
|
||||
|
Reference in New Issue
Block a user