/** * 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; }
void ServerState::saveChannels() { DLOG(INFO) << "Saving channels."; json_t* root = json_object(); json_t* publicarray = json_array(); json_t* privatearray = json_array(); for (chanptrmap_t::const_iterator i = channelMap.begin(); i != channelMap.end(); ++i) { ChannelPtr chan = i->second; if (chan->getType() == CT_PUBLIC) { json_array_append_new(publicarray, chan->saveChannel()); } else if (chan->getType() == CT_PUBPRIVATE) { json_array_append_new(privatearray, chan->saveChannel()); } } json_object_set_new_nocheck(root, "public", publicarray); json_object_set_new_nocheck(root, "private", privatearray); const char* chanstr = json_dumps(root, JSON_INDENT(4)); string contents = chanstr; free((void*) chanstr); json_decref(root); fsaveFile("./channels.json", contents); }