1
0
Fork 0
mirror of https://github.com/besterprotocol/besterd synced 2023-12-13 21:00:32 +01:00

Added findHandler() function in server

This commit is contained in:
Tristan B. Kildaire 2020-04-19 14:45:53 +02:00
parent 985be7c95f
commit d18cf4ae4f

View file

@ -90,6 +90,23 @@ public class BesterServer
return true;
}
/* Returns the MessageHandler object of the requested type */
public MessageHandler findHandler(string payloadType)
{
/* The found MessageHandler */
MessageHandler foundHandler;
for(uint i = 0; i < handlers.length; i++)
{
if(cmp(handlers[i].getPluginName(), payloadType) == 0)
{
foundHandler = handlers[i];
break;
}
}
return foundHandler;
}
public static bool isBuiltInCommand(string command)
{
/* Whether or not `payloadType` is a built-in command */
@ -593,16 +610,7 @@ private class BesterConnection : Thread
JSONValue payloadData = payloadBlock["data"];
/* Lookup the payloadType handler */
MessageHandler chosenHandler;
for(uint i = 0; i < server.handlers.length; i++)
{
if(cmp(server.handlers[i].getPluginName(), payloadType) == 0)
{
chosenHandler = server.handlers[i];
break;
}
}
MessageHandler chosenHandler = server.findHandler(payloadType);
/* Check if the payload is a built-in command */
if(cmp(payloadType, "builtin") == 0)