- changed TextMsg to return a bool

- fixed a bug where you couldn't send messages from post hooks
- added protection in functions which expect StartMessage to succeed

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401138
This commit is contained in:
David Anderson 2007-07-19 00:34:44 +00:00
parent 0069612c95
commit 3fdc205544
5 changed files with 21 additions and 8 deletions

View File

@ -244,13 +244,19 @@ void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
} }
} }
void CHalfLife2::TextMsg(int client, int dest, const char *msg) bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
{ {
bf_write *pBitBuf = NULL; bf_write *pBitBuf = NULL;
cell_t players[] = {client}; cell_t players[] = {client};
pBitBuf = g_UserMsgs.StartMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE); if ((pBitBuf = g_UserMsgs.StartMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
{
return false;
}
pBitBuf->WriteByte(dest); pBitBuf->WriteByte(dest);
pBitBuf->WriteString(msg); pBitBuf->WriteString(msg);
g_UserMsgs.EndMessage(); g_UserMsgs.EndMessage();
return true;
} }

View File

@ -56,7 +56,7 @@ public: //IGameHelpers
ServerClass *FindServerClass(const char *classname); ServerClass *FindServerClass(const char *classname);
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset); typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
void SetEdictStateChanged(edict_t *pEdict, unsigned short offset); void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
void TextMsg(int client, int dest, const char *msg); bool TextMsg(int client, int dest, const char *msg);
private: private:
DataTableInfo *_FindServerClass(const char *classname); DataTableInfo *_FindServerClass(const char *classname);
private: private:

View File

@ -330,6 +330,8 @@ void UserMessages::OnMessageEnd_Post()
iter++; iter++;
} }
m_InHook = false;
pList = &m_msgHooks[m_CurId]; pList = &m_msgHooks[m_CurId];
for (iter=pList->begin(); iter!=pList->end(); ) for (iter=pList->begin(); iter!=pList->end(); )
{ {
@ -348,8 +350,6 @@ void UserMessages::OnMessageEnd_Post()
pInfo->IsHooked = false; pInfo->IsHooked = false;
iter++; iter++;
} }
m_InHook = false;
} }
void UserMessages::OnMessageEnd_Pre() void UserMessages::OnMessageEnd_Pre()

View File

@ -284,7 +284,10 @@ static cell_t PrintToChat(IPluginContext *pContext, const cell_t *params)
return 0; return 0;
} }
g_HL2.TextMsg(client, HUD_PRINTTALK, buffer); if (!g_HL2.TextMsg(client, HUD_PRINTTALK, buffer))
{
return pContext->ThrowNativeError("Could not send a usermessage");
}
return 1; return 1;
} }
@ -315,7 +318,10 @@ static cell_t PrintCenterText(IPluginContext *pContext, const cell_t *params)
return 0; return 0;
} }
g_HL2.TextMsg(client, HUD_PRINTCENTER, buffer); if (!g_HL2.TextMsg(client, HUD_PRINTCENTER, buffer))
{
return pContext->ThrowNativeError("Could not send a usermessage");
}
return 1; return 1;
} }

View File

@ -95,8 +95,9 @@ namespace SourceMod
* @param client Client index. * @param client Client index.
* @param dest Destination on the HUD. * @param dest Destination on the HUD.
* @param msg Message to send. * @param msg Message to send.
* @return True on success, false on failure.
*/ */
virtual void TextMsg(int client, int dest, const char *msg) =0; virtual bool TextMsg(int client, int dest, const char *msg) =0;
}; };
} }