// Not in a class due to circular dependancy hell.
static std::string permchannelsconf;
-static bool WriteDatabase(InspIRCd *ServerInstance)
+static bool WriteDatabase()
{
FILE *f;
}
// Now, let's write.
- Channel *c = NULL;
-
for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
{
- c = i->second;
+ Channel* chan = i->second;
+ if (!chan->IsModeSet('P'))
+ continue;
- if (c->IsModeSet('P'))
+ char line[1024];
+ const char* items[] =
{
- fprintf(f, "<permchannels channel=\"%s\" topic=\"%s\" modes=\"%s\">\n", c->name.c_str(), c->topic.c_str(), c->ChanModes(true));
+ "<permchannels channel=",
+ chan->name.c_str(),
+ " topic=",
+ chan->topic.c_str(),
+ " modes=",
+ chan->ChanModes(true),
+ ">\n"
+ };
+
+ int lpos = 0, item = 0, ipos = 0;
+ while (lpos < 1022 && item < 7)
+ {
+ char c = items[item][ipos++];
+ if (c == 0)
+ {
+ // end of this string; hop to next string, insert a quote
+ item++;
+ ipos = 0;
+ c = '"';
+ }
+ else if (c == '\\' || c == '"')
+ {
+ line[lpos++] = '\\';
+ }
+ line[lpos++] = c;
}
+ line[--lpos] = 0;
+ fputs(line, f);
}
int write_error = 0;
if (write_error)
{
ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot write to new database! %s (%d)", strerror(errno), errno);
- ServerInstance->SNO->WriteToSnoMask('x', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
+ ServerInstance->SNO->WriteToSnoMask('a', "database: cannot write to new db: %s (%d)", strerror(errno), errno);
return false;
}
if (rename(tempname.c_str(), permchannelsconf.c_str()) < 0)
{
ServerInstance->Logs->Log("m_permchannels",DEFAULT, "permchannels: Cannot move new to old database! %s (%d)", strerror(errno), errno);
- ServerInstance->SNO->WriteToSnoMask('x', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
+ ServerInstance->SNO->WriteToSnoMask('a', "database: cannot replace old with new db: %s (%d)", strerror(errno), errno);
return false;
}
class PermChannel : public ModeHandler
{
public:
- PermChannel(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'P', 0, 0, false, MODETYPE_CHANNEL, false) { }
+ PermChannel(InspIRCd* Instance, Module* Creator) : ModeHandler(Creator, 'P', PARAM_NONE, MODETYPE_CHANNEL) { }
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
{
channel->SetMode('P',true);
// Save permchannels db if needed.
- WriteDatabase(ServerInstance);
+ WriteDatabase();
return MODEACTION_ALLOW;
}
}
channel->SetMode('P',false);
// Save permchannels db if needed.
- WriteDatabase(ServerInstance);
+ WriteDatabase();
return MODEACTION_ALLOW;
}
}
virtual ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string ¶m, bool adding, int pcnt)
{
if (chan && chan->IsModeSet('P'))
- WriteDatabase(ServerInstance);
+ WriteDatabase();
return MOD_RES_PASSTHRU;
}
virtual void OnPostTopicChange(User*, Channel *c, const std::string&)
{
if (c->IsModeSet('P'))
- WriteDatabase(ServerInstance);
+ WriteDatabase();
}
virtual Version GetVersion()