Esempio n. 1
0
/**
 * Sends the ICH message for the selected channel to the selected connection.
 * @param LUD channel
 * @param LUD connection
 * @returns Nothing.
 */
int LuaChannel::sendICH(lua_State* L) {
    luaL_checkany(L, 2);

    LBase* base = 0;
    GETLCHAN(base, L, 1, chan);
    GETLCON(base, L, 2, con);
    lua_pop(L, 2);

    json_t* root = json_object();
    json_object_set_new_nocheck(root, "channel",
            json_string_nocheck(chan->getName().c_str())
            );
    json_object_set_new_nocheck(root, "mode",
            json_string_nocheck(chan->getModeString().c_str())
            );
    json_t* array = json_array();
    const chconlist_t participants = chan->getParticipants();
    for (chconlist_t::const_iterator i = participants.begin(); i != participants.end(); ++i) {
        json_t* charnode = json_object();
        json_object_set_new_nocheck(charnode, "identity",
                json_string_nocheck((*i)->characterName.c_str())
                );
        json_array_append_new(array, charnode);
    }

    json_object_set_new_nocheck(root, "users", array);
    string msg = "ICH ";
    const char* ichstr = json_dumps(root, JSON_COMPACT);
    msg += ichstr;
    MessagePtr outMessage(MessageBuffer::fromString(msg));
    con->send(outMessage);
    free((void*) ichstr);
    json_decref(root);
    return 0;
}
Esempio n. 2
0
/**
 * Destroys a channel. This will send LCH messages to all channel participants if the channel exists.
 * @param string channel name
 * @returns Nothing.
 */
int LuaChannel::destroyChannel(lua_State* L) {
    luaL_checkany(L, 1);

    string name = luaL_checkstring(L, 1);
    lua_pop(L, 1);

    ChannelPtr chan = ServerState::getChannel(name);
    if (chan) {
        const ChannelType type = chan->getType();
        const char* channame = chan->getName().c_str();
        const chconlist_t particpants = chan->getParticipants();
        for (chconlist_t::const_iterator i = particpants.begin(); i != particpants.end(); ++i) {
            json_t* root = json_object();
            json_object_set_new_nocheck(root, "channel",
                    json_string_nocheck(channame)
                    );
            json_object_set_new_nocheck(root, "character",
                    json_string_nocheck((*i)->characterName.c_str())
                    );
            const char* leavestr = json_dumps(root, JSON_COMPACT);
            string msg = "LCH ";
            msg += leavestr;
            free((void*) leavestr);
            json_decref(root);
            MessagePtr outMessage(MessageBuffer::fromString(msg));
            (*i)->send(outMessage);
            chan->part((*i));
        }
        ServerState::removeChannel(name);
        if (type == CT_PUBLIC)
            ServerState::rebuildChannelOpList();
    }
    return 0;
}
Esempio n. 3
0
int LuaTesting::killChannel(lua_State* L) {
    luaL_checkany(L, 1);

    string chanName = luaL_checkstring(L, 1);
    lua_pop(L, 1);
    ChannelPtr chan = ServerState::getChannel(chanName);
    if (chan) {
        const chconlist_t particpants = chan->getParticipants();
        for (chconlist_t::const_iterator i = particpants.begin(); i != particpants.end(); ++i) {
            chan->part(*i);
        }
        ServerState::removeChannel(chanName);
    }

    return 0;
}
Esempio n. 4
0
/**
 * Pulls a list of users in a room that can have a bottle spin land on them.
 * @param LUD channel
 * @returns [table of strings] List of possible bottle users.
 */
int LuaChannel::getBottleList(lua_State* L) {
    luaL_checkany(L, 2);

    LBase* base = 0;
    GETLCHAN(base, L, 1, chan);
    GETLCON(base, L, 2, con);
    lua_pop(L, 1);

    const chconlist_t participants = chan->getParticipants();
    lua_newtable(L);
    int n = 1;
    for (chconlist_t::const_iterator i = participants.begin(); i != participants.end(); ++i) {
        if (((*i)->status == "online" || (*i)->status == "looking") && ((*i)->characterNameLower != con->characterNameLower)) {
            lua_pushstring(L, (*i)->characterName.c_str());
            lua_rawseti(L, -2, n++);
        }
    }

    return 1;
}