summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/MirLua/src/m_protocols.cpp119
-rw-r--r--plugins/MirLua/src/m_protocols.h10
-rw-r--r--plugins/MirLua/src/main.cpp21
-rw-r--r--plugins/MirLua/src/mlua.h2
-rw-r--r--plugins/MirLua/src/stdafx.h3
-rw-r--r--plugins/MirLua/src/version.h2
6 files changed, 150 insertions, 7 deletions
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp
index c095f44470..5f82e69da2 100644
--- a/plugins/MirLua/src/m_protocols.cpp
+++ b/plugins/MirLua/src/m_protocols.cpp
@@ -1,5 +1,7 @@
#include "stdafx.h"
+HANDLE hRecvMessage = NULL;
+
static void MapToTable(lua_State *L, const PROTOCOLDESCRIPTOR* pd)
{
lua_newtable(L);
@@ -187,6 +189,120 @@ static int lua_EnumAccounts(lua_State *L)
return 1;
}
+int ProtoAckHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
+{
+ lua_State *L = (lua_State*)obj;
+
+ int ref = param;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+
+ lua_pushnumber(L, wParam);
+
+ ACKDATA *ack = (ACKDATA*)lParam;
+
+ lua_newtable(L);
+ lua_pushliteral(L, "Module");
+ lua_pushstring(L, ptrA(mir_utf8encode(ack->szModule)));
+ lua_settable(L, -3);
+ lua_pushliteral(L, "hContact");
+ lua_pushinteger(L, ack->hContact);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "Type");
+ lua_pushinteger(L, ack->type);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "Result");
+ lua_pushinteger(L, ack->result);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "hProcess");
+ lua_pushlightuserdata(L, ack->hProcess);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "lParam");
+ lua_pushnumber(L, ack->lParam);
+ lua_settable(L, -3);
+
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+
+ int res = (int)lua_tointeger(L, 1);
+
+ return res;
+}
+
+static int lua_OnProtoAck(lua_State *L)
+{
+ if (!lua_isfunction(L, 1))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
+ lua_pushvalue(L, 1);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ HANDLE res = ::HookEventObjParam(ME_PROTO_ACK, ProtoAckHookEventObjParam, L, ref);
+ lua_pushlightuserdata(L, res);
+
+ CMLua::Hooks.insert(res);
+ CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
+
+ return 1;
+}
+
+int RecvMessageHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
+{
+ lua_State *L = (lua_State*)obj;
+
+ int ref = param;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+
+ lua_pushnumber(L, wParam);
+
+ CCSDATA *ccs = (CCSDATA*)lParam;
+ PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam;
+
+ lua_newtable(L);
+ lua_pushliteral(L, "hContact");
+ lua_pushinteger(L, ccs->hContact);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "Message");
+ lua_pushstring(L, pre->szMessage);
+ lua_settable(L, -3);
+
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+
+ int res = (int)lua_tointeger(L, 1);
+
+ return res;
+}
+
+static int lua_OnReceiveMessage(lua_State *L)
+{
+ if (!lua_isfunction(L, 1))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
+ lua_pushvalue(L, 1);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ HANDLE res = ::HookEventObjParam(MODULE PSR_MESSAGE, RecvMessageHookEventObjParam, L, ref);
+ lua_pushlightuserdata(L, res);
+
+ CMLua::Hooks.insert(res);
+ CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
+
+ return 1;
+}
+
+INT_PTR FilterRecvMessage(WPARAM wParam, LPARAM lParam)
+{
+ NotifyEventHooks(hRecvMessage, wParam, lParam);
+
+ return Proto_ChainRecv(wParam, (CCSDATA*)lParam);
+}
+
static luaL_Reg protocolsApi[] =
{
{ "GetProto", lua_GetProto },
@@ -197,6 +313,9 @@ static luaL_Reg protocolsApi[] =
{ "AllAccounts", lua_AllAccounts },
{ "EnumAccounts", lua_EnumAccounts },
+ { "OnProtoAck", lua_OnProtoAck },
+ { "OnReceiveMessage", lua_OnReceiveMessage },
+
{ NULL, NULL }
};
diff --git a/plugins/MirLua/src/m_protocols.h b/plugins/MirLua/src/m_protocols.h
new file mode 100644
index 0000000000..1b8ef74d43
--- /dev/null
+++ b/plugins/MirLua/src/m_protocols.h
@@ -0,0 +1,10 @@
+#ifndef _LUA_M_PROTOCOLS_H_
+#define _LUA_M_PROTOCOLS_H_
+
+#define MLUA_PROTOCOLS "m_protocols"
+LUAMOD_API int (luaopen_m_protocols)(lua_State *L);
+
+extern HANDLE hRecvMessage;
+INT_PTR FilterRecvMessage(WPARAM wParam, LPARAM lParam);
+
+#endif //_LUA_M_PROTOCOLS_H_ \ No newline at end of file
diff --git a/plugins/MirLua/src/main.cpp b/plugins/MirLua/src/main.cpp
index 2ec8920988..5381b34c19 100644
--- a/plugins/MirLua/src/main.cpp
+++ b/plugins/MirLua/src/main.cpp
@@ -43,11 +43,14 @@ int OnModulesLoaded(WPARAM, LPARAM)
{
g_hCommonScriptFolder = FoldersRegisterCustomPathT(MODULE, Translate("Common scripts folder"), COMMON_SCRIPTS_PATHT);
+ HookEvent(ME_OPT_INITIALISE, CLuaOptions::OnOptionsInit);
+
+ hRecvMessage = CreateHookableEvent(MODULE PSR_MESSAGE);
+ CreateProtoServiceFunction(MODULE, PSR_MESSAGE, FilterRecvMessage);
+
g_mLua = new CMLua();
g_mLua->Load();
- HookEvent(ME_OPT_INITIALISE, CLuaOptions::OnOptionsInit);
-
return 0;
}
@@ -64,6 +67,20 @@ extern "C" int __declspec(dllexport) Load(void)
nlu.szSettingsModule = MODULE;
hNetlib = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ PROTOCOLDESCRIPTOR pd = { 0 };
+ pd.cbSize = sizeof(pd);
+ pd.szName = MODULE;
+ pd.type = PROTOTYPE_FILTER;
+ Proto_RegisterModule(&pd);
+
+ CreateProtoServiceFunction(MODULE, PSR_MESSAGE, FilterRecvMessage);
+ /*CreateProtoServiceFunction(MODULE, PSR_AUTH, FilterRecvAuth);
+ CreateProtoServiceFunction(MODULE, PSR_FILE, FilterRecvFile);
+ CreateProtoServiceFunction(MODULE, PSR_URL, FilterRecvUrl);
+ CreateProtoServiceFunction(MODULE, PSR_CONTACTS, FilterRecvUrl);
+ CreateProtoServiceFunction(MODULE, PSR_AWAYMSG, FilterRecvUrl);*/
+
+
return 0;
}
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h
index d73d88f7e0..6c8796b4ff 100644
--- a/plugins/MirLua/src/mlua.h
+++ b/plugins/MirLua/src/mlua.h
@@ -17,8 +17,6 @@ private:
static void KillModuleEventHooks();
static void KillModuleServices();
-
-
public:
static LIST<void> Hooks;
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h
index 4e3f764cb9..ab257b27eb 100644
--- a/plugins/MirLua/src/stdafx.h
+++ b/plugins/MirLua/src/stdafx.h
@@ -88,8 +88,7 @@ LUAMOD_API int (luaopen_m_message)(lua_State *L);
#define MLUA_POPUP "m_popup"
LUAMOD_API int (luaopen_m_popup)(lua_State *L);
-#define MLUA_PROTOCOLS "m_protocols"
-LUAMOD_API int (luaopen_m_protocols)(lua_State *L);
+#include "m_protocols.h"
#include "m_toptoolbar.h"
diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h
index 5e29a1a083..1d725ca11a 100644
--- a/plugins/MirLua/src/version.h
+++ b/plugins/MirLua/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 4
-#define __BUILD_NUM 5
+#define __BUILD_NUM 6
#include <stdver.h>