Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool setUserMode(const std::string& name, const std::string& chan, const std::string& mode, std::string output)
- {
- Database *db = Database::instance();
- if (!db->connect()) {
- output = "Unable to connect, please try again later.";
- return false;
- }
- Query q;
- Result r;
- std::string channels = "";
- std::string modes = "";
- q << "SELECT `modes`, `channels` FROM `channel_auths` WHERE `auth_name` = '" << name << "';";
- db->storeQuery(q, r);
- q.reset();
- if (r.numRows() != 0) {
- output = "r.numRows() > 0";
- for (int i = 0; i < r.numRows(); ++i) {
- if (r.getDataString("channels", i) != "") {
- output = "Found channels";
- channels += r.getDataString("channels", i) + " ";
- modes += r.getDataString("modes", i);
- if (channels.find(chan) != std::string::npos) {
- modes += mode;
- q << "UPDATE `channel_auths` SET `modes` = '" << modes << "' WHERE `channels` = '" << channels << "';";
- if (!db->executeQuery(q)) {
- output = "Unable to save auth. #1";
- return false;
- }
- }
- }
- }
- } else {
- q << "INSERT INTO `channel_auths` VALUES ('" << name << "', '" << chan << "', '" << mode << "');";
- if (!db->executeQuery(q)) {
- output = "Could not save auth. #2";
- return false;
- }
- }
- output = "Done. Flags for: " + name + " in " + chan + " are now " + modes + ".";
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement