faluco@505: /**
faluco@505: * vim: set ts=4 :
ds@1330: * =============================================================================
ds@1947: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
ds@1330: *
ds@1330: * This file is part of the SourceMod/SourcePawn SDK.
faluco@505: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
ds@1330: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
ds@1330: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
ds@1330: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
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:
faluco@1040: /**
faluco@1040: * @section Message Flags.
faluco@1040: */
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 */
ds@1268: #define USERMSG_BLOCKHOOKS (1<<7) /**< Prevents the message from triggering SourceMod and Metamod hooks */
ds@1268:
faluco@505: /**
faluco@1040: * @endsection
faluco@1040: */
faluco@1040:
faluco@1040: /**
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.
ds@2112: * @error Invalid message name, unable to start a message, invalid client,
ds@2112: * or client not connected.
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.
ds@2112: * @error Invalid message name, unable to start a message, invalid client,
ds@2112: * or client not connected.
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@812: * 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@1394: * @return Ignored for normal hooks. For intercept hooks, Plugin_Handled
dvander@1394: * blocks the message from being sent, and Plugin_Continue
dvander@1394: * resumes normal functionality.
dvander@508: */
dvander@2317: functag public Action:MsgHook(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init);
faluco@552:
faluco@552: /**
dvander@2636: * Called when a message hook has completed.
faluco@552: *
faluco@552: * @param msg_id Message index.
dvander@2636: * @param sent True if message was sent, false if blocked.
faluco@552: */
dvander@2636: functag public MsgPostHook(UserMsg:msg_id, bool:sent);
dvander@508:
dvander@508: /**
dvander@812: * 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: */
dvander@2636: native HookUserMessage(UserMsg:msg_id, MsgHook:hook, bool:intercept=false, MsgPostHook:post=MsgPostHook:-1);
dvander@508:
dvander@508: /**
dvander@812: * 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 total = 0;
skamonkey@2920: new clients[MaxClients];
skamonkey@2920: 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: }