Added guards around NetHandlers functions

This commit is contained in:
Jordan Cristiano 2015-06-18 20:09:06 -04:00
parent c6fb1e6ff2
commit 0d7c67aef8
1 changed files with 20 additions and 5 deletions

View File

@ -48,34 +48,49 @@ typedef void (*NetMsgToStringFn)(std::ostringstream& out, void* data);
bool NetHandlers::NetMsg_BitRead(uint32_t type, bf_read& bitbuf, SourceGameContext& context, void* data)
{
static const NetMsgBitReadFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(BitRead);
assert(type < (sizeof(netHandlers) / sizeof(NetMsgBitReadFn)));
if (type >= (sizeof(netHandlers) / sizeof(NetMsgBitReadFn)))
{
return false;
}
return netHandlers[type](bitbuf, context, data);
}
bool NetHandlers::NetMsg_BitWrite(uint32_t type, bf_write& bitbuf, const SourceGameContext& context, void* data)
{
static const NetMsgBitWriteFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(BitWrite);
assert(type < (sizeof(netHandlers) / sizeof(NetMsgBitWriteFn)));
if (type >= (sizeof(netHandlers) / sizeof(NetMsgBitWriteFn)))
{
return false;
}
return netHandlers[type](bitbuf, context, data);
}
bool NetHandlers::NetMsg_JsonRead(uint32_t type, JsonRead& jsonbuf, SourceGameContext& context, void* data)
{
static const NetMsgJsonReadFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(JsonRead);
assert(type < (sizeof(netHandlers) / sizeof(NetMsgJsonReadFn)));
if (type >= (sizeof(netHandlers) / sizeof(NetMsgJsonReadFn)))
{
return false;
}
return netHandlers[type](jsonbuf, context, data);
}
bool NetHandlers::NetMsg_JsonWrite(uint32_t type, JsonWrite& jsonbuf, const SourceGameContext& context, void* data)
{
static const NetMsgJsonWriteFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(JsonWrite);
assert(type < (sizeof(netHandlers) / sizeof(NetMsgJsonWriteFn)));
if (type >= (sizeof(netHandlers) / sizeof(NetMsgJsonWriteFn)))
{
return false;
}
return netHandlers[type](jsonbuf, context, data);
}
void NetHandlers::NetMsg_ToString(uint32_t type, std::ostringstream& out, void* data)
{
static const NetMsgToStringFn netHandlers[] = DECLARE_NET_HANDLER_ARRAY(ToString);
assert(type < (sizeof(netHandlers) / sizeof(NetMsgToStringFn)));
if (type >= (sizeof(netHandlers) / sizeof(NetMsgToStringFn)))
{
return;
}
netHandlers[type](out, data);
}