Minor fixes to client mod

This commit is contained in:
Brant Martin
2018-07-18 19:25:08 -04:00
parent b8b0a0fcce
commit c889854818
2 changed files with 29 additions and 11 deletions

View File

@@ -148,6 +148,10 @@ namespace Torch.Mod
{ {
if (!MyAPIGateway.Multiplayer.IsServer) if (!MyAPIGateway.Multiplayer.IsServer)
throw new Exception("Only server can send targeted messages"); throw new Exception("Only server can send targeted messages");
if (_closing)
return;
message.Target = target; message.Target = target;
message.TargetType = MessageTarget.Single; message.TargetType = MessageTarget.Single;
MyLog.Default.WriteLineAndConsole($"Sending message of type {message.GetType().FullName}"); MyLog.Default.WriteLineAndConsole($"Sending message of type {message.GetType().FullName}");
@@ -159,6 +163,10 @@ namespace Torch.Mod
{ {
if (!MyAPIGateway.Multiplayer.IsServer) if (!MyAPIGateway.Multiplayer.IsServer)
throw new Exception("Only server can send targeted messages"); throw new Exception("Only server can send targeted messages");
if (_closing)
return;
message.TargetType = MessageTarget.AllClients; message.TargetType = MessageTarget.AllClients;
_outgoing.Enqueue(message); _outgoing.Enqueue(message);
ReleaseLock(); ReleaseLock();
@@ -166,8 +174,12 @@ namespace Torch.Mod
public static void SendMessageExcept(MessageBase message, params ulong[] ignoredUsers) public static void SendMessageExcept(MessageBase message, params ulong[] ignoredUsers)
{ {
if (MyAPIGateway.Multiplayer.IsServer) if (!MyAPIGateway.Multiplayer.IsServer)
throw new Exception("Only server can send targeted messages"); throw new Exception("Only server can send targeted messages");
if (_closing)
return;
message.TargetType = MessageTarget.AllExcept; message.TargetType = MessageTarget.AllExcept;
message.Ignore = ignoredUsers; message.Ignore = ignoredUsers;
_outgoing.Enqueue(message); _outgoing.Enqueue(message);
@@ -176,6 +188,9 @@ namespace Torch.Mod
public static void SendMessageToServer(MessageBase message) public static void SendMessageToServer(MessageBase message)
{ {
if (_closing)
return;
message.TargetType = MessageTarget.Server; message.TargetType = MessageTarget.Server;
_outgoing.Enqueue(message); _outgoing.Enqueue(message);
ReleaseLock(); ReleaseLock();
@@ -183,20 +198,16 @@ namespace Torch.Mod
private static void ReleaseLock() private static void ReleaseLock()
{ {
if(_lock==null) while(_lock?.TryAcquireExclusive() == false)
return; _lock?.ReleaseExclusive();
while(!_lock.TryAcquireExclusive()) _lock?.ReleaseExclusive();
_lock.ReleaseExclusive();
_lock.ReleaseExclusive();
} }
private static void AcquireLock() private static void AcquireLock()
{ {
if (_lock == null)
return;
ReleaseLock(); ReleaseLock();
_lock.AcquireExclusive(); _lock?.AcquireExclusive();
_lock.AcquireExclusive(); _lock?.AcquireExclusive();
} }
} }
} }

View File

@@ -23,8 +23,15 @@ namespace Torch.Mod
} }
protected override void UnloadData() protected override void UnloadData()
{
try
{ {
ModCommunication.Unregister(); ModCommunication.Unregister();
} }
catch
{
//session unloading, don't care
}
}
} }
} }