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..69a8eb2 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,57 @@ int LuaChannel::sendToChannelRaw(lua_State* L) { return 0; } +/** + * Send a protocol message to all operators in this channel instance. + * @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; + string message = luaL_checkstring(L, 2); + + json_t* json = LuaChat::luaToJson(L); + const char* jsonstr = json_dumps(json, JSON_COMPACT); + + message += " "; + message += jsonstr; + + free((void*) jsonstr); + + json_decref(json); + + lua_pop(L, 3); + + MessagePtr outMessage(MessageBuffer::fromString(message)); + + conDesc = ServerState::getConnection(ownerName); + + 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 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);