mirror of
https://github.com/anope/anope.git
synced 2026-07-05 22:13:13 +02:00
Use fstream for accessing files where possible.
This commit is contained in:
+9
-13
@@ -240,21 +240,17 @@ void MOTD::Run(MessageSource &source, const std::vector<Anope::string> ¶ms,
|
||||
if (s != Me)
|
||||
return;
|
||||
|
||||
FILE *f = fopen(Config->GetBlock("serverinfo")->Get<const Anope::string>("motd").c_str(), "r");
|
||||
if (f)
|
||||
std::ifstream stream(Config->GetBlock("serverinfo")->Get<const Anope::string>("motd").str());
|
||||
if (!stream.is_open())
|
||||
{
|
||||
IRCD->SendNumeric(375, source.GetSource(), "- " + s->GetName() + " Message of the Day");
|
||||
char buf[BUFSIZE];
|
||||
while (fgets(buf, sizeof(buf), f))
|
||||
{
|
||||
buf[strlen(buf) - 1] = 0;
|
||||
IRCD->SendNumeric(372, source.GetSource(), Anope::printf("- %s", buf));
|
||||
}
|
||||
fclose(f);
|
||||
IRCD->SendNumeric(376, source.GetSource(), "End of /MOTD command.");
|
||||
}
|
||||
else
|
||||
IRCD->SendNumeric(422, source.GetSource(), "- MOTD file not found! Please contact your IRC administrator.");
|
||||
return;
|
||||
}
|
||||
|
||||
IRCD->SendNumeric(375, source.GetSource(), "- " + s->GetName() + " Message of the Day");
|
||||
for (Anope::string line; std::getline(stream, line.str()); )
|
||||
IRCD->SendNumeric(372, source.GetSource(), Anope::printf("- %s", line.c_str()));
|
||||
IRCD->SendNumeric(376, source.GetSource(), "End of /MOTD command.");
|
||||
}
|
||||
|
||||
void Notice::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags)
|
||||
|
||||
Reference in New Issue
Block a user