public override bool CanHandle( CallSite site ) { if ( site.MethodInfo.Name == "SetCustomNameEvent" ) { if ( _unitTestResult == null ) { ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 1 ) { _unitTestResult = false; Essentials.Log.Error( "Unit test 1" ); return false; } if ( parameters[0].ParameterType != typeof(string) ) { _unitTestResult = false; Essentials.Log.Error("Unit test 2"); return false; } _unitTestResult = true; } return _unitTestResult.Value; } return false; }
public override bool CanHandle( CallSite site ) { if ( site.MethodInfo.Name != "OnEntityClosedRequest" ) return false; if ( _unitTestResult == null ) { //static void OnEntityClosedRequest(long entityId) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 1 ) { _unitTestResult = false; return false; } if ( parameters[0].ParameterType != typeof(long) ) { _unitTestResult = false; return false; } _unitTestResult = true; } return _unitTestResult.Value; }
public override bool CanHandle( CallSite site ) { if ( site.MethodInfo.Name != "OnChangeDisplayNameRequest" ) return false; if ( _unitTestResult == null ) { //void OnChangeDisplayNameRequest(String displayName) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 1 ) { _unitTestResult = false; return false; } if ( parameters[0].ParameterType != typeof(string) ) { _unitTestResult = false; return false; } _unitTestResult = true; } return _unitTestResult.Value; }
static void Prefix(object __instance, MyPacketDataBitStreamBase data, CallSite site, object obj, IMyNetObject sendAs, Vector3D?position, EndpointId source, ref ProfilerToken?__localProfilerHandle) { if (!MethodIndices.TryGetValue(site.Id, out var methodIndex)) { var methodName = $"{Type.FullName}#OnEvent_{site.MethodInfo.Name}"; methodIndex = StringIndexer.Instance.IndexOf(methodName); MethodIndices.Add(site.Id, methodIndex); } __localProfilerHandle = ProfilerPatch.StartToken(__instance, methodIndex, Category); }
public override bool CanHandle( CallSite site ) { if ( site.MethodInfo.Name == ChangeOwnerName ) { if ( !_unitTestResults.ContainsKey( ChangeOwnerName ) ) { //void OnChangeOwnerRequest(long blockId, long owner, MyOwnershipShareModeEnum shareMode) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 3 ) { _unitTestResults[ChangeOwnerName] = false; return false; } if ( parameters[0].ParameterType != typeof(long) || parameters[1].ParameterType != typeof(long) || parameters[2].ParameterType != typeof(MyOwnershipShareModeEnum) ) { _unitTestResults[ChangeOwnerName] = false; return false; } _unitTestResults[ChangeOwnerName] = true; } return _unitTestResults[ChangeOwnerName]; } if ( site.MethodInfo.Name == ChangeOwnersName ) { if ( !_unitTestResults.ContainsKey( ChangeOwnersName ) ) { //private static void OnChangeOwnersRequest(MyOwnershipShareModeEnum shareMode, List<MySingleOwnershipRequest> requests, long requestingPlayer) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 3 ) { _unitTestResults[ChangeOwnersName] = false; return false; } if ( parameters[0].ParameterType != typeof(MyOwnershipShareModeEnum) || parameters[1].ParameterType != typeof(List<MyCubeGrid.MySingleOwnershipRequest>) || parameters[2].ParameterType != typeof(long) ) { _unitTestResults[ChangeOwnersName] = false; return false; } _unitTestResults[ChangeOwnersName] = true; } return _unitTestResults[ChangeOwnersName]; } return false; }
public override bool CanHandle( CallSite site ) { if ( site.MethodInfo.Name == RazeBlocksName ) { if ( !_unitTestResults.ContainsKey( RazeBlocksName ) ) { //public void RazeBlocks(List<Vector3I> locations) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 1 ) { _unitTestResults[RazeBlocksName] = false; return false; } if ( parameters[0].ParameterType != typeof(List<Vector3I>) ) { _unitTestResults[RazeBlocksName] = false; return false; } _unitTestResults[RazeBlocksName] = true; } return _unitTestResults[RazeBlocksName]; } if ( site.MethodInfo.Name == RazeAreaName ) { if ( !_unitTestResults.ContainsKey( RazeAreaName ) ) { //void RazeBlocksAreaRequest(Vector3I pos, Vector3UByte size) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 2 ) { _unitTestResults[RazeAreaName] = false; return false; } if ( parameters[0].ParameterType != typeof(Vector3I) || parameters[1].ParameterType != typeof(Vector3UByte) ) { _unitTestResults[RazeAreaName] = false; return false; } _unitTestResults[RazeAreaName] = true; } return _unitTestResults[RazeAreaName]; } return false; }
internal override void ProcessEvent(BitStream stream, CallSite site, object obj, IMyNetObject sendAs, EndpointId source) { LastMessageFromServer = DateTime.UtcNow; // Client blindly invokes everything received from server (without validation) Invoke(site, stream, obj, source, null, false); }
internal override bool DispatchBlockingEvent(BitStream stream, CallSite site, EndpointId recipient, IMyNetObject eventInstance, IMyNetObject blockedNetObj, float unreliablePriority) { Debug.Fail("Client should not call blocking events"); // For client this code is old. Only server can dispatch blocking events. return DispatchEvent(stream, site, recipient, eventInstance, unreliablePriority); }
internal override void ProcessEvent(BitStream stream, CallSite site, object obj, IMyNetObject sendAs, EndpointId source) { // Return when validation fails if (!Invoke(site, stream, obj, source, GetClientData(source), true)) return; // Send event in case it has [Broadcast], [BroadcastExcept] or [Client] attribute if (site.HasClientFlag || site.HasBroadcastFlag || site.HasBroadcastExceptFlag) { DispatchEvent(stream, site, source, sendAs, 1.0f); } }
internal override bool DispatchEvent(BitStream stream, CallSite site, EndpointId target, IMyNetObject eventInstance, float unreliablePriority) { Debug.Assert(site.HasClientFlag || site.HasBroadcastFlag || site.HasBroadcastExceptFlag, String.Format("Event '{0}' does not have Client, Broadcast or BroadcastExcept flag, it can't be invoked on client!", site)); var replicable = eventInstance as IMyReplicable; if (site.HasRefreshReplicableFlag && replicable != null) { RefreshReplicable(replicable); } if (site.HasBroadcastFlag || site.HasBroadcastExceptFlag) { foreach (var client in m_clientStates) { if (site.HasBroadcastExceptFlag && client.Key == target) continue; // Send it also to client who invoked this method on server float priority; if (ShouldSendEvent(eventInstance, site.IsReliable, client.Value, out priority)) { DispatchEvent(client.Value, priority * unreliablePriority, client.Key, stream, site.IsReliable); } } } else if (site.HasClientFlag) { Debug.Assert(target.IsValid, "Target cannot be null when invoking Client event"); Debug.Assert(m_clientStates.ContainsKey(target), "Target client not found"); ClientData clientData; float priority; if (m_clientStates.TryGetValue(target, out clientData) && ShouldSendEvent(eventInstance, site.IsReliable, clientData, out priority)) { DispatchEvent(clientData, priority, target, stream, site.IsReliable); } } return site.HasServerFlag; // Invoke locally when Local flag is set }
internal override bool DispatchBlockingEvent(BitStream stream, CallSite site, EndpointId target, IMyNetObject targetReplicable, IMyNetObject blockingReplicable, float unreliablePriority) { var blockedRepl = blockingReplicable as IMyReplicable; var replicable = targetReplicable as IMyReplicable; if (site.HasBroadcastFlag || site.HasBroadcastExceptFlag) { foreach (var client in m_clientStates) { if (site.HasBroadcastExceptFlag && client.Key == target) continue; float priority; if (ShouldSendEvent(targetReplicable, site.IsReliable, client.Value, out priority)) { // Register networkId as blocked and streaming has to finish for it. this.TryAddBlockerForClient(client.Value, replicable, blockedRepl); } } } else if (site.HasClientFlag && m_localClientEndpoint != target) { ClientData clientData; // Register networkId as blocked and streaming has to finish for it. if (m_clientStates.TryGetValue(target, out clientData)) { this.TryAddBlockerForClient(clientData, replicable, blockedRepl); } } return DispatchEvent(stream, site, target, targetReplicable, unreliablePriority); }
private bool TryGetStaticCallSite <T>(Func <T, Delegate> callSiteGetter, out CallSite site) { return(m_typeTable.StaticEventTable.TryGet(callSiteGetter, callSiteGetter, default(T), out site)); }
internal override bool DispatchEvent(BitStream stream, CallSite site, EndpointId target, IMyNetObject instance, float unreliablePriority) { Debug.Assert(site.HasServerFlag, String.Format("Event '{0}' does not have server flag, it can't be invoked on server!", site)); if (site.HasServerFlag) { m_callback.SendEvent(stream, site.IsReliable); //Client.SendMessageToServer(stream, site.Reliability, PacketPriorityEnum.LOW_PRIORITY, MyChannelEnum.Replication); } else if (site.HasClientFlag) { // Invoke locally only when it has ClientFlag and no ServerFlag return true; } return false; }
internal override bool DispatchBlockingEvent(BitStream stream, CallSite site, EndpointId recipient, IMyNetObject eventInstance, IMyNetObject blockedNetObj, float unreliablePriority) { Debug.Fail("Client should not call blocking events"); // For client this code is old. Only server can dispatch blocking events. return(DispatchEvent(stream, site, recipient, eventInstance, unreliablePriority)); }
public override bool CanHandle(CallSite site) { if (site.MethodInfo.Name == ColorBlocks) { bool result; if (!_unitTestResults.TryGetValue(ColorBlocks, out result)) { //make sure Keen hasn't changed the method somehow //private void ColorBlockRequest(Vector3I min, Vector3I max, Vector3 newHSV, bool playSound) var parameters = site.MethodInfo.GetParameters(); if (parameters.Length != 4) { _unitTestResults[ColorBlocks] = false; return false; } if (parameters[0].ParameterType != typeof(Vector3I) || parameters[1].ParameterType != typeof(Vector3I) || parameters[2].ParameterType != typeof(Vector3) || parameters[3].ParameterType != typeof(bool)) { _unitTestResults[ColorBlocks] = false; return false; } _unitTestResults[ColorBlocks] = true; result = true; } return result; } else if (site.MethodInfo.Name == ColorGrid) { bool result; if (!_unitTestResults.TryGetValue(ColorGrid, out result)) { var parameters = site.MethodInfo.GetParameters(); if (parameters.Length != 2) { _unitTestResults[ColorGrid] = false; return false; } if (parameters[0].ParameterType != typeof(Vector3) || parameters[1].ParameterType != typeof(bool)) { _unitTestResults[ColorGrid] = false; return false; } _unitTestResults[ColorGrid] = true; result = true; } return result; } else { return false; } }
internal abstract bool DispatchBlockingEvent(BitStream stream, CallSite site, EndpointId recipient, IMyNetObject eventInstance, IMyNetObject blockedNetObject, float unreliablePriority);
/// <summary> /// Called when event is received over network. /// Event can be validated, invoked and/or transferred to other peers. /// </summary> internal abstract void ProcessEvent(BitStream stream, CallSite site, object obj, IMyNetObject sendAs, EndpointId source);
public override bool CanHandle( CallSite site ) { //okay, there's three distinct methods that build blocks, we need to handle all of them if ( site.MethodInfo.Name == BuildBlockName ) { if ( !_unitTestResults.ContainsKey( BuildBlockName ) ) { //public void BuildBlockRequest(uint colorMaskHsv, MyBlockLocation location, [DynamicObjectBuilder] MyObjectBuilder_CubeBlock blockObjectBuilder, long builderEntityId, bool instantBuild, long ownerId) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 6 ) { _unitTestResults[BuildBlockName] = false; Essentials.Log.Error( "BuildBlockHandler failed unit test 1!" ); return false; } if ( parameters[0].ParameterType != typeof(uint) || parameters[1].ParameterType != typeof(MyCubeGrid.MyBlockLocation) || parameters[2].ParameterType != typeof(MyObjectBuilder_CubeBlock) || parameters[3].ParameterType != typeof(long) || parameters[4].ParameterType != typeof(bool) || parameters[5].ParameterType != typeof(long) ) { _unitTestResults[BuildBlockName] = false; Essentials.Log.Error( "BuildBlockHandler failed unit test 2!" ); return false; } _unitTestResults[BuildBlockName] = true; } return _unitTestResults[BuildBlockName]; } if ( site.MethodInfo.Name == BuildBlocksName ) { if ( !_unitTestResults.ContainsKey( BuildBlocksName ) ) { //void BuildBlocksRequest(uint colorMaskHsv, HashSet<MyBlockLocation> locations, long builderEntityId, bool instantBuild, long ownerId) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 5 ) { _unitTestResults[BuildBlocksName] = false; Essentials.Log.Error( "BuildBlockHandler failed unit test 3!" ); return false; } if ( parameters[0].ParameterType != typeof(uint) || parameters[1].ParameterType != typeof(HashSet<MyCubeGrid.MyBlockLocation>) || parameters[2].ParameterType != typeof(long) || parameters[3].ParameterType != typeof(bool) || parameters[4].ParameterType != typeof(long) ) { _unitTestResults[BuildBlocksName] = false; Essentials.Log.Error( "BuildBlockHandler failed unit test 4!" ); return false; } _unitTestResults[BuildBlocksName] = true; } return _unitTestResults[BuildBlocksName]; } if ( site.MethodInfo.Name == BuildAreaName ) { if ( !_unitTestResults.ContainsKey( BuildAreaName ) ) { //private void BuildBlocksAreaRequest(MyCubeGrid.MyBlockBuildArea area, long builderEntityId, bool instantBuild, long ownerId) ParameterInfo[] parameters = site.MethodInfo.GetParameters( ); if ( parameters.Length != 4 ) { _unitTestResults[BuildAreaName] = false; Essentials.Log.Error( "BuildBlockHandler failed unit test 5!" ); return false; } if ( parameters[0].ParameterType != typeof(MyCubeGrid.MyBlockBuildArea) || parameters[1].ParameterType != typeof(long) || parameters[2].ParameterType != typeof(bool) || parameters[3].ParameterType != typeof(long) ) { _unitTestResults[BuildAreaName] = false; Essentials.Log.Error( "BuildBlockHandler failed unit test 6!" ); return false; } _unitTestResults[BuildAreaName] = true; } return _unitTestResults[BuildAreaName]; } return false; }
public bool TryGet <T>(object associatedObject, Func <T, Delegate> getter, T arg, out CallSite site) { if (!m_associateObjectLookup.TryGetValue(associatedObject, out site)) { var method = getter(arg).Method; if (m_methodInfoLookup.TryGetValue(method, out site)) { m_associateObjectLookup[associatedObject] = site; return(true); } return(false); } return(true); }
public override bool Handle( ulong remoteUserId, CallSite site, BitStream stream, object obj ) { if ( !PluginSettings.Instance.ProtectedEnabled ) return false; long entityId = 0; Serialize( site.MethodInfo, stream, ref entityId ); if ( entityId == 0 ) { Essentials.Log.Debug( "Error deserializing argument in GridDeleteHandler" ); return false; } MyCubeGrid grid; if ( !MyEntities.TryGetEntityById( entityId, out grid ) ) { //Essentials.Log.Debug( "Couldn't find grid in GridDeleteHandler." ); return false; } foreach ( ProtectedItem item in PluginSettings.Instance.ProtectedItems ) { if ( !item.Enabled ) continue; if (item.EntityId != grid.EntityId && item.EntityId != -1) continue; if ( !item.ProtectionSettingsDict.Dictionary.ContainsKey( ProtectedItem.ProtectionModeEnum.GridDelete ) ) continue; ProtectedItem.ProtectionSettings settings = item.ProtectionSettingsDict[ProtectedItem.ProtectionModeEnum.GridDelete]; if ( Protection.Instance.CheckPlayerExempt( settings, grid, remoteUserId ) ) continue; if ( item.LogOnly ) { Essentials.Log.Info( $"Recieved grid delete request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); continue; } if ( !string.IsNullOrEmpty( settings.PrivateWarningMessage ) ) Communication.Notification( remoteUserId, MyFontEnum.Red, 5000, settings.PrivateWarningMessage ); if ( !string.IsNullOrEmpty( settings.PublicWarningMessage ) ) Communication.SendPublicInformation( settings.PublicWarningMessage.Replace( "%player%", PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId ) ) ); if ( settings.BroadcastGPS ) { MyPlayer player = MySession.Static.Players.GetPlayerById( new MyPlayer.PlayerId( remoteUserId, 0 ) ); Vector3D pos = player.GetPosition( ); MyAPIGateway.Utilities.SendMessage( $"GPS:{player.DisplayName}:{pos.X}:{pos.Y}:{pos.Z}:" ); } Essentials.Log.Info( $"Intercepted grid delete request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); switch ( settings.PunishmentType ) { case ProtectedItem.PunishmentEnum.Kick: _kickTimer.Elapsed += ( sender, e ) => { Essentials.Log.Info( $"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for deleting protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); MyMultiplayer.Static.KickClient( remoteUserId ); }; _kickTimer.AutoReset = false; _kickTimer.Start( ); break; case ProtectedItem.PunishmentEnum.Ban: _kickTimer.Elapsed += ( sender, e ) => { Essentials.Log.Info( $"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for deleting protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); MyMultiplayer.Static.BanClient( remoteUserId, true ); }; _kickTimer.AutoReset = false; _kickTimer.Start( ); break; case ProtectedItem.PunishmentEnum.Speed: Task.Run( ( ) => { lock ( ProcessSpeed.SpeedPlayers ) { long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( remoteUserId ); ProcessSpeed.SpeedPlayers[playerId] = new Tuple<float, DateTime>( (float)settings.SpeedLimit, DateTime.Now + TimeSpan.FromMinutes( settings.SpeedTime ) ); } } ); Essentials.Log.Info( $"Limited user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )} to {settings.SpeedLimit}m/s for {settings.SpeedTime} minutes" ); break; } //send the fail message to make the client play the paste fail sound //just because we can var inf = typeof(MyCubeBuilder).GetMethod("SpawnGridReply", BindingFlags.NonPublic | BindingFlags.Static); ServerNetworkManager.Instance.RaiseStaticEvent(inf, remoteUserId, false); return true; } return false; }
private bool TryGetInstanceCallSite <T>(Func <T, Delegate> callSiteGetter, T arg, out CallSite site) { var typeInfo = m_typeTable.Get(arg.GetType()); return(typeInfo.EventTable.TryGet(callSiteGetter, callSiteGetter, arg, out site)); }
public override bool Handle( ulong remoteUserId, CallSite site, BitStream stream, object obj ) { if ( !PluginSettings.Instance.ProtectedEnabled ) return false; HashSet<MyCubeGrid> processGrids = new HashSet<MyCubeGrid>( ); if ( site.MethodInfo.Name == ChangeOwnerName ) { MyCubeGrid grid = obj as MyCubeGrid; if ( grid == null ) { Essentials.Log.Debug( "Null grid in BlockOwnHandler" ); return false; } processGrids.Add( grid ); } else if ( site.MethodInfo.Name == ChangeOwnersName ) { MyOwnershipShareModeEnum shareMode = MyOwnershipShareModeEnum.None; List<MyCubeGrid.MySingleOwnershipRequest> requests = new List<MyCubeGrid.MySingleOwnershipRequest>( ); long requestingPlayer = 0; Serialize( site.MethodInfo, stream, ref shareMode, ref requests, ref requestingPlayer ); foreach ( MyCubeGrid.MySingleOwnershipRequest request in requests ) { MyEntity entity; MyEntities.TryGetEntityById( request.BlockId, out entity ); MyCubeBlock block = entity as MyCubeBlock; if ( block?.CubeGrid == null ) continue; processGrids.Add( block.CubeGrid ); } } //Parallel.ForEach( processGrids, grid => foreach (var grid in processGrids) { foreach (ProtectedItem item in PluginSettings.Instance.ProtectedItems) { if (!item.Enabled) continue; if (item.EntityId != grid.EntityId && item.EntityId != -1) continue; if (!item.ProtectionSettingsDict.Dictionary.ContainsKey( ProtectedItem.ProtectionModeEnum.BlockOwn )) continue; ProtectedItem.ProtectionSettings settings = item.ProtectionSettingsDict[ProtectedItem.ProtectionModeEnum.BlockOwn]; if (Protection.Instance.CheckPlayerExempt( settings, grid, remoteUserId )) continue; if (item.LogOnly) { Essentials.Log.Info( $"Recieved block ownership change request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); continue; } if (!string.IsNullOrEmpty( settings.PrivateWarningMessage )) Communication.Notification( remoteUserId, MyFontEnum.Red, 5000, settings.PrivateWarningMessage ); if (!string.IsNullOrEmpty( settings.PublicWarningMessage )) Communication.SendPublicInformation( settings.PublicWarningMessage.Replace( "%player%", PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId ) ) ); if (settings.BroadcastGPS) { MyPlayer player = MySession.Static.Players.GetPlayerById( new MyPlayer.PlayerId( remoteUserId, 0 ) ); Vector3D pos = player.GetPosition( ); MyAPIGateway.Utilities.SendMessage( $"GPS:{player.DisplayName}:{pos.X}:{pos.Y}:{pos.Z}:" ); } Essentials.Log.Info( $"Intercepted block ownership change request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); switch (settings.PunishmentType) { case ProtectedItem.PunishmentEnum.Kick: _kickTimer.Elapsed += ( sender, e ) => { Essentials.Log.Info( $"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for changing block ownership on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); MyMultiplayer.Static.KickClient( remoteUserId ); }; _kickTimer.AutoReset = false; _kickTimer.Start( ); break; case ProtectedItem.PunishmentEnum.Ban: _kickTimer.Elapsed += ( sender, e ) => { Essentials.Log.Info( $"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for changing block ownership on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); MyMultiplayer.Static.BanClient( remoteUserId, true ); }; _kickTimer.AutoReset = false; _kickTimer.Start( ); break; case ProtectedItem.PunishmentEnum.Speed: Task.Run( ( ) => { lock (ProcessSpeed.SpeedPlayers) { long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( remoteUserId ); ProcessSpeed.SpeedPlayers[playerId] = new Tuple<float, DateTime>( (float)settings.SpeedLimit, DateTime.Now + TimeSpan.FromMinutes( settings.SpeedTime ) ); } } ); Essentials.Log.Info( $"Limited user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )} to {settings.SpeedLimit}m/s for {settings.SpeedTime} minutes" ); break; } return true; } } return false; }
protected sealed override void DispatchEvent <T1, T2, T3, T4, T5, T6, T7, T8>(CallSite callSite, EndpointId recipient, float unreliablePriority, ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5, ref T6 arg6, ref T7 arg7, ref T8 arg8) { IMyNetObject sendAs; NetworkId networkId; uint sendId = callSite.Id; if (callSite.MethodInfo.IsStatic) { Debug.Assert(arg1 == null, "First argument (the instance on which is event invoked) should be null for static events"); sendAs = null; networkId = NetworkId.Invalid; } else if (arg1 == null) { throw new InvalidOperationException("First argument (the instance on which is event invoked) cannot be null for non-static events"); } else if (arg1 is IMyEventProxy) { sendAs = GetProxyTarget((IMyEventProxy)arg1); if (sendAs == null) { string msg = "Raising event on object which is not recognized by replication: " + arg1; Debug.Fail(msg); MyLog.Default.WriteLine(msg); return; } sendId += (uint)m_typeTable.Get(sendAs.GetType()).EventTable.Count; // Add max id of Proxy networkId = GetNetworkIdByObject(sendAs); Debug.Assert(object.ReferenceEquals(GetProxyTarget(((IMyProxyTarget)sendAs).Target), sendAs), "There must be one-to-one relationship between IMyEventProxy and IMyEventTarget. Proxy.EventTarget.Target == Proxy"); } else if (arg1 is IMyNetObject) { sendAs = (IMyNetObject)arg1; networkId = GetNetworkIdByObject(sendAs); } else { throw new InvalidOperationException("Instance events may be called only on IMyNetObject or IMyEventProxy"); } NetworkId blockingNetworkId = NetworkId.Invalid; IMyNetObject blockedNetObj = null; if (arg8 is IMyEventProxy && callSite.IsBlocking) { blockedNetObj = GetProxyTarget((IMyEventProxy)arg8); blockingNetworkId = GetNetworkIdByObject(blockedNetObj); } else if (arg8 is IMyEventProxy && !callSite.IsBlocking) { throw new InvalidOperationException("Rising blocking event but event itself does not have Blocking attribute"); } else if (!(arg8 is IMyEventProxy) && callSite.IsBlocking) { throw new InvalidOperationException("Event contain Blocking attribute but blocked event proxy is not set or raised event is not blocking one"); } Debug.Assert(sendId <= 255, "Max 256 events are supported per hierarchy"); m_sendStreamEvent.ResetWrite(); m_sendStreamEvent.WriteNetworkId(networkId); m_sendStreamEvent.WriteNetworkId(blockingNetworkId); m_sendStreamEvent.WriteByte((byte)sendId); // TODO: Compress eventId to necessary number of bits var site = (CallSite <T1, T2, T3, T4, T5, T6, T7>)callSite; using (MySerializerNetObject.Using(this)) { site.Serializer(arg1, m_sendStreamEvent, ref arg2, ref arg3, ref arg4, ref arg5, ref arg6, ref arg7); } bool dispatchRes = false; // If blocking event, than process a little differently. (Internally it will call DispatchEvent anyway) if (!blockingNetworkId.IsInvalid) { dispatchRes = DispatchBlockingEvent(m_sendStreamEvent, callSite, recipient, sendAs, blockedNetObj, unreliablePriority); } else { dispatchRes = DispatchEvent(m_sendStreamEvent, callSite, recipient, sendAs, unreliablePriority); } if (dispatchRes) { InvokeLocally(site, arg1, arg2, arg3, arg4, arg5, arg6, arg7); } }
public override bool Handle( ulong remoteUserId, CallSite site, BitStream stream, object obj ) { if ( !PluginSettings.Instance.ProtectedEnabled ) return false; MyCubeGrid grid = (obj as MyTerminalBlock)?.CubeGrid; if ( grid == null ) { Essentials.Log.Debug( "Null grid in BlockNameHandler" ); return false; } foreach ( ProtectedItem item in PluginSettings.Instance.ProtectedItems ) { if ( !item.Enabled ) continue; if (item.EntityId != grid.EntityId && item.EntityId != -1) continue; if ( !item.ProtectionSettingsDict.Dictionary.ContainsKey( ProtectedItem.ProtectionModeEnum.BlockRename ) ) continue; ProtectedItem.ProtectionSettings settings = item.ProtectionSettingsDict[ProtectedItem.ProtectionModeEnum.BlockRename]; if ( Protection.Instance.CheckPlayerExempt( settings, grid, remoteUserId ) ) continue; if ( item.LogOnly ) { Essentials.Log.Info( $"Recieved block rename request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); continue; } if ( !string.IsNullOrEmpty( settings.PrivateWarningMessage ) ) Communication.Notification( remoteUserId, MyFontEnum.Red, 5000, settings.PrivateWarningMessage ); if ( !string.IsNullOrEmpty( settings.PublicWarningMessage ) ) Communication.SendPublicInformation( settings.PublicWarningMessage.Replace( "%player%", PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId ) ) ); if ( settings.BroadcastGPS ) { MyPlayer player = MySession.Static.Players.GetPlayerById( new MyPlayer.PlayerId( remoteUserId, 0 ) ); Vector3D pos = player.GetPosition( ); MyAPIGateway.Utilities.SendMessage( $"GPS:{player.DisplayName}:{pos.X}:{pos.Y}:{pos.Z}:" ); } Essentials.Log.Info( $"Intercepted block rename request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); switch ( settings.PunishmentType ) { case ProtectedItem.PunishmentEnum.Kick: _kickTimer.Elapsed += ( sender, e ) => { Essentials.Log.Info( $"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); MyMultiplayer.Static.KickClient( remoteUserId ); }; _kickTimer.AutoReset = false; _kickTimer.Start( ); break; case ProtectedItem.PunishmentEnum.Ban: _kickTimer.Elapsed += ( sender, e ) => { Essentials.Log.Info( $"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}" ); MyMultiplayer.Static.BanClient( remoteUserId, true ); }; _kickTimer.AutoReset = false; _kickTimer.Start( ); break; case ProtectedItem.PunishmentEnum.Speed: Task.Run( ( ) => { lock ( ProcessSpeed.SpeedPlayers ) { long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( remoteUserId ); ProcessSpeed.SpeedPlayers[playerId] = new Tuple<float, DateTime>( (float)settings.SpeedLimit, DateTime.Now + TimeSpan.FromMinutes( settings.SpeedTime ) ); } } ); Essentials.Log.Info( $"Limited user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )} to {settings.SpeedLimit}m/s for {settings.SpeedTime} minutes" ); break; } var block = (MyTerminalBlock)obj; block.SetCustomName( block.CustomName ); return true; } return false; }
protected abstract void DispatchEvent <T1, T2, T3, T4, T5, T6, T7>(CallSite callSite, EndpointId recipient, float unreliablePriority, ref T1 arg1, ref T2 arg2, ref T3 arg3, ref T4 arg4, ref T5 arg5, ref T6 arg6, ref T7 arg7) where T1 : IMyEventOwner;
internal override void ProcessEvent(BitStream stream, CallSite site, object obj, IMyNetObject sendAs, EndpointId source) { // Client blindly invokes everything received from server (without validation) Invoke(site, stream, obj, source, null, false); }
public override bool CanHandle( CallSite site ) { return site.MethodInfo.Name == ConvertShipName || site.MethodInfo.Name == ConvertStationName; }