Skip to content

Commit

Permalink
Fixed false error logs when using a Client and a Server in the same a…
Browse files Browse the repository at this point in the history
…pplication
  • Loading branch information
tom-weiland committed Oct 20, 2021
1 parent dc12ef2 commit a0ad4e6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
Binary file not shown.
Binary file not shown.
26 changes: 13 additions & 13 deletions RiptideNetworking/RiptideNetworking/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,21 @@ protected override void CreateMessageHandlersDictionary(Assembly assembly, byte
if (attribute.GroupId != messageHandlerGroupId)
break;

ushort messageId = attribute.MessageId;
if (messageHandlers.ContainsKey(messageId))
RiptideLogger.Log("ERROR", $"Message handler method already exists for message ID {messageId}! Only one handler method is allowed per ID!");
else
Delegate clientMessageHandler = Delegate.CreateDelegate(typeof(MessageHandler), methods[i], false);
if (clientMessageHandler != null)
{
Delegate clientMessageHandler = Delegate.CreateDelegate(typeof(MessageHandler), methods[i], false);
if (clientMessageHandler != null)
messageHandlers.Add(messageId, (MessageHandler)clientMessageHandler);
// It's a message handler for Client instances
if (messageHandlers.ContainsKey(attribute.MessageId))
RiptideLogger.Log("ERROR", $"Message handler method already exists for message ID {attribute.MessageId}! Only one handler method is allowed per ID!");
else
{
// It's not a message handler for Client instances, but it might be one for Server instances
Delegate serverMessageHandler = Delegate.CreateDelegate(typeof(Server.MessageHandler), methods[i], false);
if (serverMessageHandler == null)
RiptideLogger.Log("ERROR", $"Method '{methods[i].Name}' didn't match a message handler signature!");
}
messageHandlers.Add(attribute.MessageId, (MessageHandler)clientMessageHandler);
}
else
{
// It's not a message handler for Client instances, but it might be one for Server instances
Delegate serverMessageHandler = Delegate.CreateDelegate(typeof(Server.MessageHandler), methods[i], false);
if (serverMessageHandler == null)
RiptideLogger.Log("ERROR", $"Method '{methods[i].Name}' didn't match a message handler signature!");
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions RiptideNetworking/RiptideNetworking/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ protected override void CreateMessageHandlersDictionary(Assembly assembly, byte
if (attribute.GroupId != messageHandlerGroupId)
break;

ushort messageId = attribute.MessageId;
if (messageHandlers.ContainsKey(messageId))
RiptideLogger.Log("ERROR", $"Message handler method already exists for message ID {messageId}! Only one handler method is allowed per ID!");
else
Delegate clientMessageHandler = Delegate.CreateDelegate(typeof(MessageHandler), methods[i], false);
if (clientMessageHandler != null)
{
Delegate clientMessageHandler = Delegate.CreateDelegate(typeof(MessageHandler), methods[i], false);
if (clientMessageHandler != null)
messageHandlers.Add(messageId, (MessageHandler)clientMessageHandler);
// It's a message handler for Server instances
if (messageHandlers.ContainsKey(attribute.MessageId))
RiptideLogger.Log("ERROR", $"Message handler method already exists for message ID {attribute.MessageId}! Only one handler method is allowed per ID!");
else
{
// It's not a message handler for Server instances, but it might be one for Client instances
Delegate serverMessageHandler = Delegate.CreateDelegate(typeof(Client.MessageHandler), methods[i], false);
if (serverMessageHandler == null)
RiptideLogger.Log("ERROR", $"Method '{methods[i].Name}' didn't match a message handler signature!");
}
messageHandlers.Add(attribute.MessageId, (MessageHandler)clientMessageHandler);
}
else
{
// It's not a message handler for Server instances, but it might be one for Client instances
Delegate serverMessageHandler = Delegate.CreateDelegate(typeof(Client.MessageHandler), methods[i], false);
if (serverMessageHandler == null)
RiptideLogger.Log("ERROR", $"Method '{methods[i].Name}' didn't match a message handler signature!");
}
}
}
Expand Down

0 comments on commit a0ad4e6

Please sign in to comment.