core/smn_usermsgs.cpp
changeset 590 cb5add383a86
parent 553 a8efe0286237
child 592 c2a2c38f1331
     1.1 --- a/core/smn_usermsgs.cpp	Sat Mar 10 21:02:40 2007 +0000
     1.2 +++ b/core/smn_usermsgs.cpp	Sat Mar 10 21:12:40 2007 +0000
     1.3 @@ -15,7 +15,7 @@
     1.4  #include "HandleSys.h"
     1.5  #include "PluginSys.h"
     1.6  #include "CUserMessages.h"
     1.7 -#include "CMsgListenerWrapper.h"
     1.8 +#include "smn_usermsgs.h"
     1.9  
    1.10  HandleType_t g_WrBitBufType;
    1.11  Handle_t g_CurMsgHandle;
    1.12 @@ -149,11 +149,119 @@
    1.13  	return true;
    1.14  }
    1.15  
    1.16 -/**************************************
    1.17 -*                                     *
    1.18 -* USER MESSAGE NATIVE IMPLEMENTATIONS *
    1.19 -*                                     *
    1.20 -***************************************/
    1.21 +/***************************************
    1.22 + *                                     *
    1.23 + * USER MESSAGE WRAPPER IMPLEMENTATION *
    1.24 + *                                     *
    1.25 + ***************************************/
    1.26 +
    1.27 +size_t MsgListenerWrapper::PreparePlArray(int *pl_array, IRecipientFilter *pFilter)
    1.28 +{
    1.29 +	size_t size = static_cast<size_t>(pFilter->GetRecipientCount());
    1.30 +
    1.31 +	for (size_t i=0; i<size; i++)
    1.32 +	{
    1.33 +		pl_array[i] = pFilter->GetRecipientIndex(i);
    1.34 +	}
    1.35 +
    1.36 +	return size;
    1.37 +}
    1.38 +
    1.39 +bool MsgListenerWrapper::IsInterceptHook() const
    1.40 +{
    1.41 +	return m_IsInterceptHook;
    1.42 +}
    1.43 +
    1.44 +int MsgListenerWrapper::GetMessageId() const
    1.45 +{
    1.46 +	return m_MsgId;
    1.47 +}
    1.48 +
    1.49 +IPluginFunction *MsgListenerWrapper::GetHookedFunction() const
    1.50 +{
    1.51 +	if (m_Hook)
    1.52 +	{
    1.53 +		return m_Hook;
    1.54 +	} else {
    1.55 +		return m_Intercept;
    1.56 +	}
    1.57 +}
    1.58 +
    1.59 +IPluginFunction *MsgListenerWrapper::GetNotifyFunction() const
    1.60 +{
    1.61 +	return m_Notify;
    1.62 +}
    1.63 +
    1.64 +void MsgListenerWrapper::InitListener(int msgid, IPluginFunction *hook, IPluginFunction *notify, bool intercept)
    1.65 +{
    1.66 +	if (intercept)
    1.67 +	{
    1.68 +		m_Intercept = hook;
    1.69 +		m_Hook = NULL;
    1.70 +	} else {
    1.71 +		m_Hook = hook;
    1.72 +		m_Intercept = NULL;
    1.73 +	}
    1.74 +
    1.75 +	if (notify)
    1.76 +	{
    1.77 +		m_Notify = notify;
    1.78 +	} else {
    1.79 +		m_Notify = NULL;
    1.80 +	}
    1.81 +
    1.82 +	m_MsgId = msgid;
    1.83 +	m_IsInterceptHook = intercept;
    1.84 +}
    1.85 +
    1.86 +void MsgListenerWrapper::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
    1.87 +{
    1.88 +	cell_t res;
    1.89 +	size_t size = PreparePlArray(g_MsgPlayers, pFilter);
    1.90 +
    1.91 +	m_Hook->PushCell(msg_id);
    1.92 +	m_Hook->PushCell(0); //:TODO: push handle!
    1.93 +	m_Hook->PushArray(g_MsgPlayers, size);
    1.94 +	m_Hook->PushCell(size);
    1.95 +	m_Hook->PushCell(pFilter->IsReliable());
    1.96 +	m_Hook->PushCell(pFilter->IsInitMessage());
    1.97 +	m_Hook->Execute(&res);
    1.98 +}
    1.99 +
   1.100 +ResultType MsgListenerWrapper::InterceptUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
   1.101 +{
   1.102 +	cell_t res = static_cast<cell_t>(Pl_Continue);
   1.103 +	size_t size = PreparePlArray(g_MsgPlayers, pFilter);
   1.104 +
   1.105 +	m_Intercept->PushCell(msg_id);
   1.106 +	m_Intercept->PushCell(0); //:TODO: push handle!
   1.107 +	m_Intercept->PushArray(g_MsgPlayers, size);
   1.108 +	m_Intercept->PushCell(size);
   1.109 +	m_Intercept->PushCell(pFilter->IsReliable());
   1.110 +	m_Intercept->PushCell(pFilter->IsInitMessage());
   1.111 +	m_Intercept->Execute(&res);
   1.112 +
   1.113 +	return static_cast<ResultType>(res);
   1.114 +}
   1.115 +
   1.116 +void MsgListenerWrapper::OnUserMessageSent(int msg_id)
   1.117 +{
   1.118 +	cell_t res;
   1.119 +
   1.120 +	if (!m_Notify)
   1.121 +	{
   1.122 +		return;
   1.123 +	}
   1.124 +
   1.125 +	m_Notify->PushCell(msg_id);
   1.126 +	m_Notify->Execute(&res);
   1.127 +}
   1.128 +
   1.129 +/***************************************
   1.130 + *                                     *
   1.131 + * USER MESSAGE NATIVE IMPLEMENTATIONS *
   1.132 + *                                     *
   1.133 + ***************************************/
   1.134  
   1.135  static UsrMessageNatives s_UsrMessageNatives;
   1.136