
// Globals that we are going to use
local pairs 	= pairs
local unpack 	= unpack
local Msg 		= Msg
local umsg 		= umsg

/*---------------------------------------------------------
   Name: usermessage
   Desc: Enables the server to send the client messages 
		 (in a bandwidth friendly manner)
---------------------------------------------------------*/
module("usermessage")

local Hooks = {}

/*---------------------------------------------------------
   Name: Hook
   Desc: Adds a hook
---------------------------------------------------------*/
function Hook( messagename, func, ... )

	if ( SERVER ) then
		umsg.PoolString( messagename )
		return
	end

	Hooks[ messagename ] = Hooks[ messagename ] or {}

	Hooks[ messagename ].Function 	= func
	Hooks[ messagename ].PreArgs	= arg
	
end

/*---------------------------------------------------------
   Name: Call( name, args )
   Desc: Called by the engine to call a gamemode hook
---------------------------------------------------------*/
function IncomingMessage( MessageName, msg )

	if ( Hooks[ MessageName ] ) then
	
		Hooks[ MessageName ].Function( msg, unpack(Hooks[ MessageName ].PreArgs) )
		return
	
	end
	
	Msg("Warning: Unhandled usermessage '"..MessageName.."'\n")

end

