faluco@505: /** faluco@505: * vim: set ts=4 : faluco@505: * =============================================================== faluco@505: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. faluco@505: * =============================================================== faluco@505: * faluco@505: * This file is part of the SourceMod/SourcePawn SDK. This file may only be used faluco@505: * or modified under the Terms and Conditions of its License Agreement, which is found faluco@505: * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins faluco@505: * may change at any time. To view the latest information, see: faluco@505: * http://www.sourcemod.net/license.php faluco@505: * faluco@505: * Version: $Id$ faluco@505: */ faluco@505: faluco@505: #if defined _eventsmsgs_included faluco@505: #endinput faluco@505: #endif faluco@505: #define _eventsmsgs_included faluco@505: dvander@619: /** dvander@619: * UserMsg helper values. dvander@619: */ faluco@505: enum UserMsg faluco@505: { faluco@505: INVALID_MESSAGE_ID = -1, faluco@505: }; faluco@505: dvander@716: #define USERMSG_PASSTHRU (1<<0) /**< (DEPRECATED, NO EFFECT) */ dvander@716: #define USERMSG_PASSTHRU_ALL (1<<1) /**< (DEPRECATED, NO EFFECT) */ dvander@716: #define USERMSG_RELIABLE (1<<2) /**< Message will be set on the reliable stream */ faluco@505: #define USERMSG_INITMSG (1<<3) /**< Message will be considered to be an initmsg */ dvander@716: #define USERMSG_BLOCK_MM (1<<4) /**< Message will be blocked from going through MM:S hooks */ dvander@716: #define USERMSG_BLOCK_SM (1<<5) /**< Message will be blocked from going through SourceMod hooks */ dvander@716: #define USERMSG_BLOCK_ALL (1<<6) /**< Message will be blocked from going through any hooks */ faluco@505: faluco@505: /** faluco@505: * Returns the ID of a given message, or -1 on failure. faluco@505: * faluco@505: * @param msg String containing message name (case sensitive). faluco@505: * @return A message index, or INVALID_MESSAGE_ID on failure. faluco@505: */ faluco@505: native UserMsg:GetUserMessageId(const String:msg[]); faluco@505: faluco@505: /** ds@512: * Retrieves the name of a message by ID. ds@512: * ds@512: * @param msg_id Message index. ds@512: * @param msg Buffer to store the name of the message. ds@512: * @param maxlength Maximum length of string buffer. ds@512: * @return True if message index is valid, false otherwise. ds@512: */ ds@512: native bool:GetUserMessageName(UserMsg:msg_id, String:msg[], maxlength); ds@512: ds@512: /** faluco@505: * Starts a usermessage (network message). faluco@505: * @note Only one message can be active at a time. dvander@508: * @note It is illegal to send any message while a non-intercept hook is in progress. faluco@505: * faluco@505: * @param msgname Message name to start. faluco@505: * @param clients Array containing player indexes to broadcast to. faluco@505: * @param numClients Number of players in the array. ds@621: * @param flags Optional flags to set. faluco@505: * @return A handle to a bf_write bit packing structure, or faluco@505: * INVALID_HANDLE on failure. dvander@508: * @error Invalid message name or unable to start a message. faluco@505: */ ds@621: native Handle:StartMessage(String:msgname[], clients[], numClients, flags=0); faluco@505: faluco@505: /** faluco@505: * Starts a usermessage (network message). faluco@505: * @note Only one message can be active at a time. dvander@508: * @note It is illegal to send any message while a non-intercept hook is in progress. faluco@505: * faluco@505: * @param msg Message index to start. faluco@505: * @param clients Array containing player indexes to broadcast to. faluco@505: * @param numClients Number of players in the array. ds@621: * @param flags Optional flags to set. faluco@505: * @return A handle to a bf_write bit packing structure, or faluco@505: * INVALID_HANDLE on failure. dvander@508: * @error Invalid message name or unable to start a message. faluco@505: */ ds@621: native Handle:StartMessageEx(UserMsg:msg, clients[], numClients, flags=0); faluco@505: faluco@505: /** faluco@505: * Ends a previously started user message (network message). faluco@505: * faluco@505: * @noreturn faluco@505: */ faluco@505: native EndMessage(); faluco@505: faluco@505: /** dvander@508: * @brief Called when a message is hooked dvander@508: * dvander@508: * @param msg_id Message index. faluco@552: * @param bf Handle to the input bit buffer of the message. dvander@508: * @param players Array containing player indexes. dvander@508: * @param playersNum Number of players in the array. dvander@508: * @param reliable True if message is reliable, false otherwise. dvander@508: * @param init True if message is an initmsg, false otherwise. dvander@508: * @return Ignored for normal hooks. For intercept hooks, false blocks dvander@508: * the message from being sent, and true continues. dvander@508: */ faluco@552: functag MsgHook Action:public(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init); faluco@552: faluco@552: /** faluco@552: * @brief Called when a message is finished sending. faluco@552: * faluco@552: * @param msg_id Message index. faluco@552: */ faluco@552: functag MsgSentNotify public(UserMsg:msg_id); dvander@508: dvander@508: /** dvander@508: * @brief Hooks a user message. dvander@508: * dvander@508: * @param msg_id Message index. dvander@508: * @param hook Function to use as a hook. dvander@508: * @param intercept If intercept is true, message will be fully intercepted, dvander@508: * allowing the user to block the message. Otherwise, dvander@508: * the hook is normal and ignores the return value. faluco@552: * @param notify Notification function. dvander@508: * @noreturn dvander@508: * @error Invalid message index. dvander@508: */ faluco@552: native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgSentNotify:notify=MsgSentNotify:-1); dvander@508: dvander@508: /** dvander@508: * @brief Removes one usermessage hook. dvander@508: * dvander@508: * @param msg_id Message index. dvander@508: * @param hook Function used for the hook. dvander@508: * @param intercept Specifies whether the hook was an intercept hook or not. dvander@508: * @noreturn dvander@508: * @error Invalid message index. dvander@508: */ ds@626: native UnhookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false); dvander@508: dvander@508: /** faluco@505: * Starts a usermessage (network message) that broadcasts to all clients. dvander@508: * @note See StartMessage or StartMessageEx(). faluco@505: * faluco@505: * @param msgname Message name to start. faluco@505: * @param flags Optional flags to set. faluco@505: * @return A handle to a bf_write bit packing structure, or faluco@505: * INVALID_HANDLE on failure. faluco@505: */ faluco@505: stock Handle:StartMessageAll(String:msgname[], flags=0) faluco@505: { faluco@505: new maxClients = GetMaxClients(); faluco@505: new total = 0; faluco@505: new clients[maxClients]; faluco@505: for (new i=1; i<=maxClients; i++) faluco@505: { faluco@505: if (IsClientConnected(i)) faluco@505: { faluco@505: clients[total++] = i; faluco@505: } faluco@505: } faluco@505: return StartMessage(msgname, clients, total, flags); faluco@505: } faluco@505: faluco@505: /** faluco@505: * Starts a simpler usermessage (network message) for one client. dvander@508: * @note See StartMessage or StartMessageEx(). faluco@505: * faluco@505: * @param msgname Message name to start. faluco@505: * @param client Client to send to. faluco@505: * @param flags Optional flags to set. faluco@505: * @return A handle to a bf_write bit packing structure, or faluco@505: * INVALID_HANDLE on failure. faluco@505: */ faluco@505: stock Handle:StartMessageOne(String:msgname[], client, flags=0) faluco@505: { faluco@505: new players[1]; faluco@505: faluco@505: players[0] = client; faluco@505: faluco@505: return StartMessage(msgname, players, 1, flags); faluco@505: }