+ bool ReadDatabase()
+ {
+ // If the xline database doesn't exist then we don't need to load it.
+ if (!FileSystem::FileExists(xlinedbpath))
+ return true;
+
+ std::ifstream stream(xlinedbpath.c_str());
+ if (!stream.is_open())
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Cannot read database \"%s\"! %s (%d)", xlinedbpath.c_str(), strerror(errno), errno);
+ ServerInstance->SNO->WriteToSnoMask('a', "database: cannot read xline db \"%s\": %s (%d)", xlinedbpath.c_str(), strerror(errno), errno);
+ return false;
+ }
+
+ std::string line;
+ while (std::getline(stream, line))
+ {
+ // Inspired by the command parser. :)
+ irc::tokenstream tokens(line);
+ int items = 0;
+ std::string command_p[7];
+ std::string tmp;
+
+ while (tokens.GetToken(tmp) && (items < 7))
+ {
+ command_p[items] = tmp;
+ items++;
+ }
+
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Processing %s", line.c_str());
+
+ if (command_p[0] == "VERSION")
+ {
+ if (command_p[1] != "1")
+ {
+ stream.close();
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "I got database version %s - I don't understand it", command_p[1].c_str());
+ ServerInstance->SNO->WriteToSnoMask('a', "database: I got a database version (%s) I don't understand", command_p[1].c_str());
+ return false;
+ }
+ }
+ else if (command_p[0] == "LINE")
+ {
+ // Mercilessly stolen from spanningtree
+ XLineFactory* xlf = ServerInstance->XLines->GetFactory(command_p[1]);
+
+ if (!xlf)
+ {
+ ServerInstance->SNO->WriteToSnoMask('a', "database: Unknown line type (%s).", command_p[1].c_str());
+ continue;
+ }
+
+ XLine* xl = xlf->Generate(ServerInstance->Time(), atoi(command_p[5].c_str()), command_p[3], command_p[6], command_p[2]);
+ xl->SetCreateTime(atoi(command_p[4].c_str()));
+
+ if (ServerInstance->XLines->AddLine(xl, NULL))
+ {
+ ServerInstance->SNO->WriteToSnoMask('x', "database: Added a line of type %s", command_p[1].c_str());
+ }
+ else
+ delete xl;
+ }
+ }
+ stream.close();
+ return true;
+ }
+
+ Version GetVersion() CXX11_OVERRIDE