Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions src/lua_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lua_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down