From d586ff7891cb6549f64797b762bb4ec3c6221e9e Mon Sep 17 00:00:00 2001 From: Maw-Fox Date: Thu, 12 May 2016 20:00:19 -0600 Subject: [PATCH 1/7] Added channel helper function. --- script/main.lua | 2 +- src/lua_channel.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/script/main.lua b/script/main.lua index 0d734a7..3434271 100644 --- a/script/main.lua +++ b/script/main.lua @@ -737,7 +737,7 @@ function (con, args) end c.unban(chan, string.lower(args.character)) - u.send(con, "SYS", {channel=args.channel, message=args.character.." has been removed from the channel ban list."}) + c.sendToOps(chan, "SYS", {channel=args.channel, message=args.character.." has been removed from the channel ban list."}) return const.FERR_OK end diff --git a/src/lua_channel.cpp b/src/lua_channel.cpp index 2a9a084..d008539 100644 --- a/src/lua_channel.cpp +++ b/src/lua_channel.cpp @@ -58,6 +58,7 @@ static const luaL_Reg luachannel_funcs[] = { {"sendAllRaw", LuaChannel::sendToAllRaw}, {"sendChannel", LuaChannel::sendToChannel}, {"sendChannelRaw", LuaChannel::sendToChannelRaw}, + {"sendToOps", LuaChannel::sendToOps}, {"sendICH", LuaChannel::sendICH}, {"join", LuaChannel::joinChannel}, {"part", LuaChannel::partChannel}, @@ -444,6 +445,56 @@ int LuaChannel::sendToChannelRaw(lua_State* L) { return 0; } +/** + * Gets a the list of moderators in a channel. + * @param LUD channel + * @param string protocol + * @param table JSON + * @returns void + */ +int LuaChannel::sendToOps(lua_State* L) { + luaL_checkany(L, 3); + + LBase* base = 0; + GETLCHAN(base, L, 1, chan); + + const chmodmap_t mods = chan->getModRecords(); + string modName; + string ownerName = chan->getOwner().c_str(); + ConnectionPtr conDesc; + + json_t* json = LuaChat::luaToJson(L); + const char* jsonstr = json_dumps(json, JSON_COMPACT); + + string message = luaL_checkstring(L, 2); + message += " " + jsonstr; + + free((void*) jsonstr); + + json_decref(json); + + lua_pop(L, 3); + + conDesc = ServerState::getConnection(ownerName); + + MessageBuffer outMessage(MessageBuffer::fromString(message)); + + if (conDesc) { + conDesc->send(outMessage) + } + + for (chmodmap_t::const_iterator itr = mods.begin(); itr != mods.end(); ++itr) { + modName = itr->first.c_str(); + + conDesc = ServerState::getConnection(modName); + + if (conDesc) { + conDesc->send(outMessage); + } + } + return 0; +} + /** * Sends the ICH message for the selected channel to the selected connection. * @param LUD channel From 003eaebf2b6611c069cca5e9c570dc369b43e6d7 Mon Sep 17 00:00:00 2001 From: Maw-Fox Date: Thu, 12 May 2016 20:03:57 -0600 Subject: [PATCH 2/7] Added to compiled header file, because derp. --- src/lua_channel.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lua_channel.hpp b/src/lua_channel.hpp index 889b112..596593a 100644 --- a/src/lua_channel.hpp +++ b/src/lua_channel.hpp @@ -49,6 +49,7 @@ class LuaChannel { static int sendToAllRaw(lua_State* L); static int sendToChannel(lua_State* L); static int sendToChannelRaw(lua_State* L); + static int sendToOps(lua_State* L); static int sendICH(lua_State* L); From 3ac46ba1b464b1c76be8eb9e42285835c6c410b1 Mon Sep 17 00:00:00 2001 From: Maw-Fox Date: Thu, 12 May 2016 20:12:16 -0600 Subject: [PATCH 3/7] Fixes to use proper function. --- src/lua_channel.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lua_channel.cpp b/src/lua_channel.cpp index d008539..288397d 100644 --- a/src/lua_channel.cpp +++ b/src/lua_channel.cpp @@ -467,7 +467,8 @@ int LuaChannel::sendToOps(lua_State* L) { const char* jsonstr = json_dumps(json, JSON_COMPACT); string message = luaL_checkstring(L, 2); - message += " " + jsonstr; + message += " "; + message += jsonstr; free((void*) jsonstr); @@ -477,10 +478,8 @@ int LuaChannel::sendToOps(lua_State* L) { conDesc = ServerState::getConnection(ownerName); - MessageBuffer outMessage(MessageBuffer::fromString(message)); - if (conDesc) { - conDesc->send(outMessage) + conDesc->sendRaw(message); } for (chmodmap_t::const_iterator itr = mods.begin(); itr != mods.end(); ++itr) { @@ -489,7 +488,7 @@ int LuaChannel::sendToOps(lua_State* L) { conDesc = ServerState::getConnection(modName); if (conDesc) { - conDesc->send(outMessage); + conDesc->sendRaw(message); } } return 0; From 1aee4a1e43bb29717be9a609c179608f408d8462 Mon Sep 17 00:00:00 2001 From: Maw-Fox Date: Thu, 12 May 2016 20:18:48 -0600 Subject: [PATCH 4/7] Fixed function comment. --- src/lua_channel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_channel.cpp b/src/lua_channel.cpp index 288397d..5c0fc8c 100644 --- a/src/lua_channel.cpp +++ b/src/lua_channel.cpp @@ -446,7 +446,7 @@ int LuaChannel::sendToChannelRaw(lua_State* L) { } /** - * Gets a the list of moderators in a channel. + * Send a protocol message to all operators in this channel instance. * @param LUD channel * @param string protocol * @param table JSON From 6a4fd16d3e8966c34a23f4df89ac1b93e91c6b92 Mon Sep 17 00:00:00 2001 From: Maw-Fox Date: Thu, 12 May 2016 20:24:13 -0600 Subject: [PATCH 5/7] Fixed order for LUA argument reads. --- src/lua_channel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_channel.cpp b/src/lua_channel.cpp index 5c0fc8c..b27857a 100644 --- a/src/lua_channel.cpp +++ b/src/lua_channel.cpp @@ -462,11 +462,11 @@ int LuaChannel::sendToOps(lua_State* L) { string modName; string ownerName = chan->getOwner().c_str(); ConnectionPtr conDesc; - + string message = luaL_checkstring(L, 2); + json_t* json = LuaChat::luaToJson(L); const char* jsonstr = json_dumps(json, JSON_COMPACT); - string message = luaL_checkstring(L, 2); message += " "; message += jsonstr; From 231947de54e4017dd2f3f8e7f836e74dfb39b285 Mon Sep 17 00:00:00 2001 From: Maw-Fox Date: Fri, 13 May 2016 14:28:45 -0600 Subject: [PATCH 6/7] Use send and not sendRaw. Testing compile. --- src/lua_channel.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lua_channel.cpp b/src/lua_channel.cpp index b27857a..9c834e6 100644 --- a/src/lua_channel.cpp +++ b/src/lua_channel.cpp @@ -463,7 +463,7 @@ int LuaChannel::sendToOps(lua_State* L) { string ownerName = chan->getOwner().c_str(); ConnectionPtr conDesc; string message = luaL_checkstring(L, 2); - + json_t* json = LuaChat::luaToJson(L); const char* jsonstr = json_dumps(json, JSON_COMPACT); @@ -476,10 +476,12 @@ int LuaChannel::sendToOps(lua_State* L) { lua_pop(L, 3); + MessageBuffer outMessage(MessageBuffer::fromString(message)); + conDesc = ServerState::getConnection(ownerName); if (conDesc) { - conDesc->sendRaw(message); + conDesc->send(outMessage); } for (chmodmap_t::const_iterator itr = mods.begin(); itr != mods.end(); ++itr) { @@ -488,7 +490,7 @@ int LuaChannel::sendToOps(lua_State* L) { conDesc = ServerState::getConnection(modName); if (conDesc) { - conDesc->sendRaw(message); + conDesc->send(outMessage); } } return 0; From 07f32766f627947d45c03a02652b70bca77b6e2f Mon Sep 17 00:00:00 2001 From: Maw-Fox Date: Fri, 13 May 2016 14:38:39 -0600 Subject: [PATCH 7/7] Use send and not sendRaw (fixed). --- src/lua_channel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_channel.cpp b/src/lua_channel.cpp index 9c834e6..69a8eb2 100644 --- a/src/lua_channel.cpp +++ b/src/lua_channel.cpp @@ -476,7 +476,7 @@ int LuaChannel::sendToOps(lua_State* L) { lua_pop(L, 3); - MessageBuffer outMessage(MessageBuffer::fromString(message)); + MessagePtr outMessage(MessageBuffer::fromString(message)); conDesc = ServerState::getConnection(ownerName);