From ae38212c1ce829c783edf971081c90137abb49a0 Mon Sep 17 00:00:00 2001 From: Naram Qashat Date: Sun, 25 Jul 2010 21:58:20 -0400 Subject: Epic commit to replace most of the strings in Anope with a single Anope::string class, plus some other little fixes here and there. If you follow 1.9.x development and are testing things, THIS is one of those things that NEEDS testing. --- modules/core/bs_act.cpp | 17 +- modules/core/bs_assign.cpp | 19 +- modules/core/bs_badwords.cpp | 69 ++-- modules/core/bs_bot.cpp | 142 ++++--- modules/core/bs_botlist.cpp | 11 +- modules/core/bs_help.cpp | 9 +- modules/core/bs_info.cpp | 38 +- modules/core/bs_kick.cpp | 195 ++++----- modules/core/bs_say.cpp | 19 +- modules/core/bs_set.cpp | 77 ++-- modules/core/bs_unassign.cpp | 13 +- modules/core/cs_access.cpp | 189 +++++---- modules/core/cs_akick.cpp | 202 +++++----- modules/core/cs_ban.cpp | 37 +- modules/core/cs_clear.cpp | 69 ++-- modules/core/cs_drop.cpp | 23 +- modules/core/cs_forbid.cpp | 28 +- modules/core/cs_getkey.cpp | 17 +- modules/core/cs_help.cpp | 17 +- modules/core/cs_info.cpp | 69 ++-- modules/core/cs_invite.cpp | 14 +- modules/core/cs_kick.cpp | 33 +- modules/core/cs_list.cpp | 83 ++-- modules/core/cs_modes.cpp | 99 ++--- modules/core/cs_register.cpp | 33 +- modules/core/cs_saset.cpp | 29 +- modules/core/cs_saset_noexpire.cpp | 14 +- modules/core/cs_set.cpp | 29 +- modules/core/cs_set_bantype.cpp | 22 +- modules/core/cs_set_description.cpp | 24 +- modules/core/cs_set_entrymsg.cpp | 24 +- modules/core/cs_set_founder.cpp | 23 +- modules/core/cs_set_keeptopic.cpp | 20 +- modules/core/cs_set_mlock.cpp | 37 +- modules/core/cs_set_opnotice.cpp | 20 +- modules/core/cs_set_peace.cpp | 20 +- modules/core/cs_set_persist.cpp | 24 +- modules/core/cs_set_private.cpp | 20 +- modules/core/cs_set_restricted.cpp | 20 +- modules/core/cs_set_secure.cpp | 20 +- modules/core/cs_set_securefounder.cpp | 20 +- modules/core/cs_set_secureops.cpp | 20 +- modules/core/cs_set_signkick.cpp | 30 +- modules/core/cs_set_successor.cpp | 25 +- modules/core/cs_set_topiclock.cpp | 20 +- modules/core/cs_set_xop.cpp | 28 +- modules/core/cs_status.cpp | 22 +- modules/core/cs_suspend.cpp | 56 ++- modules/core/cs_topic.cpp | 26 +- modules/core/cs_unban.cpp | 12 +- modules/core/cs_xop.cpp | 106 ++--- modules/core/db_plain.cpp | 431 ++++++++++---------- modules/core/enc_md5.cpp | 26 +- modules/core/enc_none.cpp | 32 +- modules/core/enc_old.cpp | 27 +- modules/core/enc_sha1.cpp | 26 +- modules/core/enc_sha256.cpp | 48 +-- modules/core/hs_del.cpp | 18 +- modules/core/hs_delall.cpp | 18 +- modules/core/hs_group.cpp | 12 +- modules/core/hs_help.cpp | 10 +- modules/core/hs_list.cpp | 26 +- modules/core/hs_off.cpp | 6 +- modules/core/hs_on.cpp | 14 +- modules/core/hs_set.cpp | 82 +--- modules/core/hs_setall.cpp | 78 +--- modules/core/ms_cancel.cpp | 21 +- modules/core/ms_check.cpp | 24 +- modules/core/ms_del.cpp | 21 +- modules/core/ms_help.cpp | 10 +- modules/core/ms_info.cpp | 56 +-- modules/core/ms_list.cpp | 32 +- modules/core/ms_read.cpp | 30 +- modules/core/ms_rsend.cpp | 17 +- modules/core/ms_send.cpp | 15 +- modules/core/ms_sendall.cpp | 15 +- modules/core/ms_set.cpp | 73 ++-- modules/core/ms_staff.cpp | 13 +- modules/core/ns_access.cpp | 61 ++- modules/core/ns_alist.cpp | 43 +- modules/core/ns_drop.cpp | 41 +- modules/core/ns_forbid.cpp | 31 +- modules/core/ns_getemail.cpp | 14 +- modules/core/ns_getpass.cpp | 26 +- modules/core/ns_ghost.cpp | 36 +- modules/core/ns_group.cpp | 158 ++++---- modules/core/ns_help.cpp | 12 +- modules/core/ns_identify.cpp | 86 ++-- modules/core/ns_info.cpp | 58 +-- modules/core/ns_list.cpp | 97 ++--- modules/core/ns_logout.cpp | 31 +- modules/core/ns_recover.cpp | 40 +- modules/core/ns_register.cpp | 98 +++-- modules/core/ns_release.cpp | 30 +- modules/core/ns_resetpass.cpp | 40 +- modules/core/ns_saset.cpp | 79 ++-- modules/core/ns_saset_noexpire.cpp | 20 +- modules/core/ns_sendpass.cpp | 30 +- modules/core/ns_set.cpp | 63 +-- modules/core/ns_set_autoop.cpp | 50 ++- modules/core/ns_set_email.cpp | 48 +-- modules/core/ns_set_greet.cpp | 39 +- modules/core/ns_set_hide.cpp | 70 ++-- modules/core/ns_set_kill.cpp | 44 +- modules/core/ns_set_language.cpp | 34 +- modules/core/ns_set_message.cpp | 32 +- modules/core/ns_set_private.cpp | 32 +- modules/core/ns_set_secure.cpp | 32 +- modules/core/ns_status.cpp | 20 +- modules/core/ns_suspend.cpp | 98 ++--- modules/core/ns_update.cpp | 12 +- modules/core/os_akill.cpp | 98 ++--- modules/core/os_chankill.cpp | 43 +- modules/core/os_chanlist.cpp | 20 +- modules/core/os_clearmodes.cpp | 40 +- modules/core/os_defcon.cpp | 149 ++++--- modules/core/os_global.cpp | 14 +- modules/core/os_help.cpp | 8 +- modules/core/os_ignore.cpp | 59 ++- modules/core/os_jupe.cpp | 17 +- modules/core/os_kick.cpp | 18 +- modules/core/os_mode.cpp | 16 +- modules/core/os_modinfo.cpp | 32 +- modules/core/os_modlist.cpp | 22 +- modules/core/os_modload.cpp | 10 +- modules/core/os_modunload.cpp | 10 +- modules/core/os_news.cpp | 89 ++--- modules/core/os_noop.cpp | 26 +- modules/core/os_oline.cpp | 22 +- modules/core/os_quit.cpp | 14 +- modules/core/os_reload.cpp | 12 +- modules/core/os_restart.cpp | 14 +- modules/core/os_session.cpp | 215 +++++----- modules/core/os_set.cpp | 92 ++--- modules/core/os_shutdown.cpp | 14 +- modules/core/os_snline.cpp | 104 ++--- modules/core/os_sqline.cpp | 99 +++-- modules/core/os_staff.cpp | 16 +- modules/core/os_stats.cpp | 28 +- modules/core/os_svsnick.cpp | 24 +- modules/core/os_szline.cpp | 100 ++--- modules/core/os_umode.cpp | 20 +- modules/core/os_update.cpp | 6 +- modules/core/os_userlist.cpp | 23 +- modules/core/ss_main.cpp | 8 +- modules/extra/cs_appendtopic.cpp | 48 ++- modules/extra/cs_enforce.cpp | 49 ++- modules/extra/cs_set_misc.cpp | 74 ++-- modules/extra/cs_tban.cpp | 68 ++-- modules/extra/hs_request.cpp | 204 ++++------ modules/extra/m_helpchan.cpp | 10 +- modules/extra/m_ssl.cpp | 16 +- modules/extra/mysql/db_mysql.h | 6 +- modules/extra/mysql/db_mysql_execute.cpp | 2 +- modules/extra/mysql/db_mysql_read.cpp | 20 +- modules/extra/mysql/db_mysql_write.cpp | 18 +- modules/extra/ns_maxemail.cpp | 32 +- modules/extra/ns_set_misc.cpp | 83 ++-- modules/protocol/bahamut.cpp | 202 +++++----- modules/protocol/inspircd11.cpp | 297 ++++++-------- modules/protocol/inspircd12.cpp | 349 +++++++--------- modules/protocol/inspircd20.cpp | 509 +++++++++++------------- modules/protocol/ratbox.cpp | 300 ++++++-------- modules/protocol/unreal32.cpp | 372 ++++++++--------- modules/socketengines/m_socketengine_epoll.cpp | 34 +- modules/socketengines/m_socketengine_select.cpp | 26 +- 166 files changed, 4330 insertions(+), 4890 deletions(-) (limited to 'modules') diff --git a/modules/core/bs_act.cpp b/modules/core/bs_act.cpp index aa054d11b..ecfe76e94 100644 --- a/modules/core/bs_act.cpp +++ b/modules/core/bs_act.cpp @@ -20,10 +20,10 @@ class CommandBSAct : public Command { } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { ChannelInfo *ci = cs_findchan(params[0]); - ci::string message = params[1]; + Anope::string message = params[1]; if (!check_access(u, ci, CA_SAY)) { @@ -44,22 +44,22 @@ class CommandBSAct : public Command } size_t i = 0; - while ((i = message.find_first_of("\001"), i) && i != std::string::npos) + while ((i = message.find(1)) && i != Anope::string::npos) message.erase(i, 1); - ircdproto->SendAction(ci->bi, ci->name.c_str(), "%s", message.c_str()); + ircdproto->SendAction(ci->bi, ci->name, "%s", message.c_str()); ci->bi->lastmsg = time(NULL); - if (Config.LogBot && Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) + if (Config.LogBot && !Config.LogChannel.empty() && LogChan && !debug && findchan(Config.LogChannel)) ircdproto->SendPrivmsg(ci->bi, Config.LogChannel, "ACT %s %s %s", u->nick.c_str(), ci->name.c_str(), message.c_str()); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "ACT", BOT_ACT_SYNTAX); } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_ACT); return true; @@ -74,10 +74,11 @@ class CommandBSAct : public Command class BSAct : public Module { public: - BSAct(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSAct(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSAct()); } }; diff --git a/modules/core/bs_assign.cpp b/modules/core/bs_assign.cpp index 0695a7e6d..22f5f4487 100644 --- a/modules/core/bs_assign.cpp +++ b/modules/core/bs_assign.cpp @@ -20,10 +20,10 @@ class CommandBSAssign : public Command { } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { - const char *chan = params[0].c_str(); - const char *nick = params[1].c_str(); + Anope::string chan = params[0]; + Anope::string nick = params[1]; BotInfo *bi; ChannelInfo *ci; @@ -35,7 +35,7 @@ class CommandBSAssign : public Command if (!(bi = findbot(nick))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } @@ -53,9 +53,9 @@ class CommandBSAssign : public Command return MOD_CONT; } - if (ci->bi && ci::string(ci->bi->nick.c_str()) == nick) + if (ci->bi && nick.equals_ci(ci->bi->nick)) { - notice_lang(Config.s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick.c_str(), chan); + notice_lang(Config.s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick.c_str(), chan.c_str()); return MOD_CONT; } @@ -64,13 +64,13 @@ class CommandBSAssign : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_ASSIGN); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "ASSIGN", BOT_ASSIGN_SYNTAX); } @@ -84,10 +84,11 @@ class CommandBSAssign : public Command class BSAssign : public Module { public: - BSAssign(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSAssign); } }; diff --git a/modules/core/bs_badwords.cpp b/modules/core/bs_badwords.cpp index 822847a6a..e7dacb42b 100644 --- a/modules/core/bs_badwords.cpp +++ b/modules/core/bs_badwords.cpp @@ -19,7 +19,7 @@ class BadwordsListCallback : public NumberList ChannelInfo *ci; bool SentHeader; public: - BadwordsListCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, false), u(_u), ci(_ci), SentHeader(false) + BadwordsListCallback(User *_u, ChannelInfo *_ci, const Anope::string &list) : NumberList(list, false), u(_u), ci(_ci), SentHeader(false) { } @@ -45,7 +45,7 @@ class BadwordsListCallback : public NumberList static void DoList(User *u, ChannelInfo *ci, unsigned Number, BadWord *bw) { - notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), ((bw->type == BW_SINGLE) ? "(SINGLE)" : ((bw->type == BW_START) ? "(START)" : ((bw->type == BW_END) ? "(END)" : "")))); + notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), bw->type == BW_SINGLE ? "(SINGLE)" : (bw->type == BW_START ? "(START)" : (bw->type == BW_END ? "(END)" : ""))); } }; @@ -55,7 +55,7 @@ class BadwordsDelCallback : public NumberList ChannelInfo *ci; unsigned Deleted; public: - BadwordsDelCallback(User *_u, ChannelInfo *_ci, const std::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0) + BadwordsDelCallback(User *_u, ChannelInfo *_ci, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), Deleted(0) { } @@ -82,13 +82,13 @@ class BadwordsDelCallback : public NumberList class CommandBSBadwords : public Command { private: - CommandReturn DoList(User *u, ChannelInfo *ci, const ci::string &word) + CommandReturn DoList(User *u, ChannelInfo *ci, const Anope::string &word) { if (!ci->GetBadWordCount()) notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_EMPTY, ci->name.c_str()); - else if (!word.empty() && strspn(word.c_str(), "1234567890,-") == word.length()) + else if (!word.empty() && word.find_first_not_of("1234567890,-") == Anope::string::npos) { - BadwordsListCallback list(u, ci, word.c_str()); + BadwordsListCallback list(u, ci, word); list.Process(); } else @@ -99,7 +99,7 @@ class CommandBSBadwords : public Command { BadWord *bw = ci->GetBadWord(i); - if (!word.empty() && !Anope::Match(bw->word, word.c_str(), false)) + if (!word.empty() && !Anope::Match(bw->word, word)) continue; if (!SentHeader) @@ -118,25 +118,25 @@ class CommandBSBadwords : public Command return MOD_CONT; } - CommandReturn DoAdd(User *u, ChannelInfo *ci, const ci::string &word) + CommandReturn DoAdd(User *u, ChannelInfo *ci, const Anope::string &word) { - size_t pos = word.find_last_of(" "); + size_t pos = word.rfind(' '); BadWordType type = BW_ANY; - ci::string realword = word; + Anope::string realword = word; - if (pos != ci::string::npos) + if (pos != Anope::string::npos) { - ci::string opt = ci::string(word, pos + 1); + Anope::string opt = word.substr(pos + 1); if (!opt.empty()) { - if (opt == "SINGLE") + if (opt.equals_ci("SINGLE")) type = BW_SINGLE; - else if (opt == "START") + else if (opt.equals_ci("START")) type = BW_START; - else if (opt == "END") + else if (opt.equals_ci("END")) type = BW_END; } - realword = ci::string(word, 0, pos); + realword = word.substr(0, pos); } if (ci->GetBadWordCount() >= Config.BSBadWordsMax) @@ -149,26 +149,26 @@ class CommandBSBadwords : public Command { BadWord *bw = ci->GetBadWord(i); - if (!bw->word.empty() && ((Config.BSCaseSensitive && !stricmp(bw->word.c_str(), realword.c_str())) || (!Config.BSCaseSensitive && bw->word == realword.c_str()))) + if (!bw->word.empty() && ((Config.BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config.BSCaseSensitive && realword.equals_ci(bw->word)))) { notice_lang(Config.s_BotServ, u, BOT_BADWORDS_ALREADY_EXISTS, bw->word.c_str(), ci->name.c_str()); return MOD_CONT; } } - ci->AddBadWord(realword.c_str(), type); + ci->AddBadWord(realword, type); notice_lang(Config.s_BotServ, u, BOT_BADWORDS_ADDED, realword.c_str(), ci->name.c_str()); return MOD_CONT; } - CommandReturn DoDelete(User *u, ChannelInfo *ci, const ci::string &word) + CommandReturn DoDelete(User *u, ChannelInfo *ci, const Anope::string &word) { /* Special case: is it a number/list? Only do search if it isn't. */ - if (!word.empty() && isdigit(word[0]) && strspn(word.c_str(), "1234567890,-") == word.length()) + if (!word.empty() && isdigit(word[0]) && word.find_first_not_of("1234567890,-") == Anope::string::npos) { - BadwordsDelCallback list(u, ci, word.c_str()); + BadwordsDelCallback list(u, ci, word); list.Process(); } else @@ -180,7 +180,7 @@ class CommandBSBadwords : public Command { badword = ci->GetBadWord(i); - if (badword->word == word) + if (word.equals_ci(badword->word)) break; } @@ -209,13 +209,13 @@ class CommandBSBadwords : public Command { } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { - const char *chan = params[0].c_str(); - ci::string cmd = params[1]; - ci::string word = params.size() > 2 ? params[2].c_str() : ""; + Anope::string chan = params[0]; + Anope::string cmd = params[1]; + Anope::string word = params.size() > 2 ? params[2] : ""; ChannelInfo *ci; - bool need_args = cmd == "LIST" || cmd == "CLEAR"; + bool need_args = cmd.equals_ci("LIST") || cmd.equals_ci("CLEAR"); if (!need_args && word.empty()) { @@ -237,13 +237,13 @@ class CommandBSBadwords : public Command return MOD_CONT; } - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) return this->DoAdd(u, ci, word); - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) return this->DoDelete(u, ci, word); - else if (cmd == "LIST") + else if (cmd.equals_ci("LIST")) return this->DoList(u, ci, word); - else if (cmd == "CLEAR") + else if (cmd.equals_ci("CLEAR")) return this->DoClear(u, ci); else this->OnSyntaxError(u, ""); @@ -251,13 +251,13 @@ class CommandBSBadwords : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_BADWORDS); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "BADWORDS", BOT_BADWORDS_SYNTAX); } @@ -271,10 +271,11 @@ class CommandBSBadwords : public Command class BSBadwords : public Module { public: - BSBadwords(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSBadwords); } }; diff --git a/modules/core/bs_bot.cpp b/modules/core/bs_bot.cpp index 3af9fa685..3c5136bd5 100644 --- a/modules/core/bs_bot.cpp +++ b/modules/core/bs_bot.cpp @@ -16,34 +16,33 @@ class CommandBSBot : public Command { private: - CommandReturn DoAdd(User *u, const std::vector ¶ms) + CommandReturn DoAdd(User *u, const std::vector ¶ms) { - const char *nick = params[1].c_str(); - const char *user = params[2].c_str(); - const char *host = params[3].c_str(); - const char *real = params[4].c_str(); - const char *ch = NULL; + Anope::string nick = params[1]; + Anope::string user = params[2]; + Anope::string host = params[3]; + Anope::string real = params[4]; BotInfo *bi; if (findbot(nick)) { - notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick); + notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } - if (strlen(nick) > Config.NickLen) + if (nick.length() > Config.NickLen) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; } - if (strlen(user) > Config.UserLen) + if (user.length() > Config.UserLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_IDENT, Config.UserLen); return MOD_CONT; } - if (strlen(user) > Config.HostLen) + if (host.length() > Config.HostLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_HOST, Config.HostLen); return MOD_CONT; @@ -56,8 +55,8 @@ class CommandBSBot : public Command return MOD_CONT; } - for (ch = nick; *ch && ch - nick < Config.NickLen; ++ch) - if (!isvalidnick(*ch)) + for (unsigned i = 0, end = nick.length(); i < end && i < Config.NickLen; ++i) + if (!isvalidnick(nick[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; @@ -77,8 +76,8 @@ class CommandBSBot : public Command return MOD_CONT; } - for (ch = user; *ch && ch - user < Config.UserLen; ++ch) - if (!isalnum(*ch)) + for (unsigned i = 0, end = user.length(); i < end && i < Config.UserLen; ++i) + if (!isalnum(user[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_IDENT, Config.UserLen); return MOD_CONT; @@ -90,7 +89,7 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick); + notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } @@ -100,23 +99,22 @@ class CommandBSBot : public Command return MOD_CONT; } - notice_lang(Config.s_BotServ, u, BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, bi->realname); + notice_lang(Config.s_BotServ, u, BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); FOREACH_MOD(I_OnBotCreate, OnBotCreate(bi)); return MOD_CONT; } - CommandReturn DoChange(User *u, const std::vector ¶ms) + CommandReturn DoChange(User *u, const std::vector ¶ms) { - const char *oldnick = params[1].c_str(); - const char *nick = params.size() > 2 ? params[2].c_str() : NULL; - const char *user = params.size() > 3 ? params[3].c_str() : NULL; - const char *host = params.size() > 4 ? params[4].c_str() : NULL; - const char *real = params.size() > 5 ? params[5].c_str() : NULL; - const char *ch = NULL; + Anope::string oldnick = params[1]; + Anope::string nick = params.size() > 2 ? params[2] : ""; + Anope::string user = params.size() > 3 ? params[3] : ""; + Anope::string host = params.size() > 4 ? params[4] : ""; + Anope::string real = params.size() > 5 ? params[5] : ""; BotInfo *bi; - if (!oldnick || !nick) + if (oldnick.empty() || nick.empty()) { this->OnSyntaxError(u, "CHANGE"); return MOD_CONT; @@ -124,37 +122,37 @@ class CommandBSBot : public Command if (!(bi = findbot(oldnick))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } - if (stricmp(oldnick, nick) && nickIsServices(oldnick, 0)) + if (!oldnick.equals_ci(nick) && nickIsServices(oldnick, 0)) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } - if (strlen(nick) > Config.NickLen) + if (nick.length() > Config.NickLen) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; } - if (user && strlen(user) > Config.UserLen) + if (!user.empty() && user.length() > Config.UserLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_IDENT, Config.UserLen); return MOD_CONT; } - if (host && strlen(host) > Config.HostLen) + if (!host.empty() && host.length() > Config.HostLen) { notice_lang(Config.s_BotServ, u, BOT_LONG_HOST, Config.HostLen); return MOD_CONT; } - if (stricmp(oldnick, nick) && nickIsServices(nick, 0)) + if (!oldnick.equals_ci(nick) && nickIsServices(nick, 0)) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } @@ -163,7 +161,7 @@ class CommandBSBot : public Command * And we must finally check that the nick is not already * taken by another bot. */ - if (bi->nick == nick && (user ? bi->GetIdent() == user : 1) && (host ? !strcmp(bi->host, host) : 1) && (real ? !strcmp(bi->realname, real) : 1)) + if (nick.equals_cs(bi->nick) && (!user.empty() ? user.equals_cs(bi->GetIdent()) : 1) && (!host.empty() ? host.equals_cs(bi->host) : 1) && (!real.empty() ? real.equals_cs(bi->realname) : 1)) { notice_lang(Config.s_BotServ, u, BOT_BOT_ANY_CHANGES); return MOD_CONT; @@ -176,8 +174,8 @@ class CommandBSBot : public Command return MOD_CONT; } - for (ch = nick; *ch && ch - nick < Config.NickLen; ++ch) - if (!isvalidnick(*ch)) + for (unsigned i = 0, end = nick.length(); i < end && i < Config.NickLen; ++i) + if (!isvalidnick(nick[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_NICK); return MOD_CONT; @@ -190,28 +188,27 @@ class CommandBSBot : public Command return MOD_CONT; } - if (host && !isValidHost(host, 3)) + if (!host.empty() && !isValidHost(host, 3)) { notice_lang(Config.s_BotServ, u, BOT_BAD_HOST); return MOD_CONT; } - if (user) - for (ch = user; *ch && ch - user < Config.UserLen; ++ch) - if (!isalnum(*ch)) + if (!user.empty()) + for (unsigned i = 0, end = user.length(); i < end && i < Config.UserLen; ++i) + if (!isalnum(user[i])) { notice_lang(Config.s_BotServ, u, BOT_BAD_IDENT, Config.UserLen); return MOD_CONT; } - ci::string ci_bi_nick(bi->nick.c_str()); - if (ci_bi_nick != nick && findbot(nick)) + if (!nick.equals_ci(bi->nick) && findbot(nick)) { - notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick); + notice_lang(Config.s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } - if (ci_bi_nick != nick) + if (!nick.equals_ci(bi->nick)) { /* We check whether the nick is registered, and inform the user * if so. You need to drop the nick manually before you can use @@ -219,7 +216,7 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick); + notice_lang(Config.s_BotServ, u, NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } @@ -227,7 +224,7 @@ class CommandBSBot : public Command the old nick. */ if (ircd->sqline) { - XLine x(bi->nick.c_str()); + XLine x(bi->nick); ircdproto->SendSQLineDel(&x); } @@ -235,45 +232,45 @@ class CommandBSBot : public Command EnforceQlinedNick(nick, Config.s_BotServ); } - if (user) + if (!user.empty()) ircdproto->SendQuit(bi, "Quit: Be right back"); else { ircdproto->SendChangeBotNick(bi, nick); - XLine x(bi->nick.c_str(), "Reserved for services"); + XLine x(bi->nick, "Reserved for services"); ircdproto->SendSQLine(&x); } - if (bi->nick != nick) + if (!nick.equals_cs(bi->nick)) bi->SetNewNick(nick); - if (user && bi->GetIdent() != user) + if (!user.empty() && !user.equals_cs(bi->GetIdent())) bi->SetIdent(user); - if (host && strcmp(bi->host, host)) - bi->host = sstrdup(host); - if (real && strcmp(bi->realname, real)) - bi->realname = sstrdup(real); + if (!host.empty() && !host.equals_cs(bi->host)) + bi->host = host; + if (!real.empty() && !real.equals_cs(bi->realname)) + bi->realname = real; - if (user) + if (!user.empty()) { ircdproto->SendClientIntroduction(bi->nick, bi->GetIdent(), bi->host, bi->realname, ircd->pseudoclient_mode, bi->GetUID()); - XLine x(bi->nick.c_str(), "Reserved for services"); + XLine x(bi->nick, "Reserved for services"); ircdproto->SendSQLine(&x); bi->RejoinAll(); } - notice_lang(Config.s_BotServ, u, BOT_BOT_CHANGED, oldnick, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host, bi->realname); + notice_lang(Config.s_BotServ, u, BOT_BOT_CHANGED, oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); FOREACH_MOD(I_OnBotChange, OnBotChange(bi)); return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector ¶ms) + CommandReturn DoDel(User *u, const std::vector ¶ms) { - const char *nick = params[1].c_str(); + Anope::string nick = params[1]; BotInfo *bi; - if (!nick) + if (nick.empty()) { this->OnSyntaxError(u, "DEL"); return MOD_CONT; @@ -281,24 +278,24 @@ class CommandBSBot : public Command if (!(bi = findbot(nick))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } if (nickIsServices(nick, 0)) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", u->nick.c_str()); - XLine x(bi->nick.c_str()); + XLine x(bi->nick); ircdproto->SendSQLineDel(&x); delete bi; - notice_lang(Config.s_BotServ, u, BOT_BOT_DELETED, nick); + notice_lang(Config.s_BotServ, u, BOT_BOT_DELETED, nick.c_str()); return MOD_CONT; } public: @@ -307,9 +304,9 @@ class CommandBSBot : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { - ci::string cmd = params[0]; + Anope::string cmd = params[0]; if (readonly) { @@ -317,7 +314,7 @@ class CommandBSBot : public Command return MOD_CONT; } - if (cmd == "ADD") + if (cmd.equals_ci("ADD")) { // ADD nick user host real - 5 if (!u->Account()->HasCommand("botserv/bot/add")) @@ -332,14 +329,14 @@ class CommandBSBot : public Command return MOD_CONT; } - std::vector tempparams = params; + std::vector tempparams = params; // ADD takes less params than CHANGE, so we need to take 6 if given and append it with a space to 5. if (tempparams.size() >= 6) tempparams[4] = tempparams[4] + " " + tempparams[5]; return this->DoAdd(u, tempparams); } - else if (cmd == "CHANGE") + else if (cmd.equals_ci("CHANGE")) { // CHANGE oldn newn user host real - 6 // but only oldn and newn are required @@ -357,7 +354,7 @@ class CommandBSBot : public Command return this->DoChange(u, params); } - else if (cmd == "DEL") + else if (cmd.equals_ci("DEL")) { // DEL nick if (!u->Account()->HasCommand("botserv/bot/del")) @@ -380,13 +377,13 @@ class CommandBSBot : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_lang(Config.s_BotServ, u, BOT_SERVADMIN_HELP_BOT); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "BOT", BOT_BOT_SYNTAX); } @@ -400,10 +397,11 @@ class CommandBSBot : public Command class BSBot : public Module { public: - BSBot(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSBot()); } }; diff --git a/modules/core/bs_botlist.cpp b/modules/core/bs_botlist.cpp index 44848b5cb..a54b50154 100644 --- a/modules/core/bs_botlist.cpp +++ b/modules/core/bs_botlist.cpp @@ -20,7 +20,7 @@ class CommandBSBotList : public Command { } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { unsigned count = 0; @@ -39,7 +39,7 @@ class CommandBSBotList : public Command if (!count) notice_lang(Config.s_BotServ, u, BOT_BOTLIST_HEADER); ++count; - u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host); + u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); } } @@ -53,7 +53,7 @@ class CommandBSBotList : public Command if (bi->HasFlag(BI_PRIVATE)) { - u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host); + u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); ++count; } } @@ -67,7 +67,7 @@ class CommandBSBotList : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_BOTLIST); return true; @@ -82,10 +82,11 @@ class CommandBSBotList : public Command class BSBotList : public Module { public: - BSBotList(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSBotList()); } }; diff --git a/modules/core/bs_help.cpp b/modules/core/bs_help.cpp index 7183c6fe9..08146f827 100644 --- a/modules/core/bs_help.cpp +++ b/modules/core/bs_help.cpp @@ -22,13 +22,13 @@ class CommandBSHelp : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { - mod_help_cmd(findbot(Config.s_BotServ), u, params[0].c_str()); + mod_help_cmd(findbot(Config.s_BotServ), u, params[0]); return MOD_CONT; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { // Abuse syntax error to display general list help. notice_help(Config.s_BotServ, u, BOT_HELP); @@ -42,10 +42,11 @@ class CommandBSHelp : public Command class BSHelp : public Module { public: - BSHelp(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSHelp(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSHelp()); } }; diff --git a/modules/core/bs_info.cpp b/modules/core/bs_info.cpp index 7d8e6aea7..65147d859 100644 --- a/modules/core/bs_info.cpp +++ b/modules/core/bs_info.cpp @@ -17,31 +17,26 @@ class CommandBSInfo : public Command { private: - void send_bot_channels(User * u, BotInfo * bi) + void send_bot_channels(User *u, BotInfo *bi) { - char buf[307], *end; - - *buf = 0; - end = buf; - + Anope::string buf; for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { ChannelInfo *ci = it->second; if (ci->bi == bi) { - if (strlen(buf) + strlen(ci->name.c_str()) > 300) + if (buf.length() + ci->name.length() > 300) { - u->SendMessage(Config.s_BotServ, "%s", buf); - *buf = 0; - end = buf; + u->SendMessage(Config.s_BotServ, "%s", buf.c_str()); + buf.clear(); } - end += snprintf(end, sizeof(buf) - (end - buf), " %s ", ci->name.c_str()); + buf += " " + ci->name + " "; } } - if (*buf) - u->SendMessage(Config.s_BotServ, "%s", buf); + if (!buf.empty()) + u->SendMessage(Config.s_BotServ, "%s", buf.c_str()); return; } public: @@ -50,11 +45,11 @@ class CommandBSInfo : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { BotInfo *bi; ChannelInfo *ci; - const char *query = params[0].c_str(); + Anope::string query = params[0]; int need_comma = 0; char buf[BUFSIZE], *end; @@ -65,8 +60,8 @@ class CommandBSInfo : public Command struct tm *tm; notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_HEADER, bi->nick.c_str()); - notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_MASK, bi->GetIdent().c_str(), bi->host); - notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_REALNAME, bi->realname); + notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_MASK, bi->GetIdent().c_str(), bi->host.c_str()); + notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_REALNAME, bi->realname.c_str()); tm = localtime(&bi->created); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); notice_lang(Config.s_BotServ, u, BOT_INFO_BOT_CREATED, buf); @@ -198,17 +193,17 @@ class CommandBSInfo : public Command notice_lang(Config.s_BotServ, u, BOT_INFO_CHAN_OPTIONS, *buf ? buf : getstring(u, BOT_INFO_OPT_NONE)); } else - notice_lang(Config.s_BotServ, u, BOT_INFO_NOT_FOUND, query); + notice_lang(Config.s_BotServ, u, BOT_INFO_NOT_FOUND, query.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_INFO); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "INFO", BOT_INFO_SYNTAX); } @@ -222,10 +217,11 @@ class CommandBSInfo : public Command class BSInfo : public Module { public: - BSInfo(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSInfo()); } }; diff --git a/modules/core/bs_kick.cpp b/modules/core/bs_kick.cpp index 2f2784d93..4936f0112 100644 --- a/modules/core/bs_kick.cpp +++ b/modules/core/bs_kick.cpp @@ -21,20 +21,20 @@ class CommandBSKick : public Command { } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { - const char *chan = params[0].c_str(); - ci::string option = params[1]; - ci::string value = params[2]; - const char *ttb = params.size() > 3 ? params[3].c_str() : NULL; + Anope::string chan = params[0]; + Anope::string option = params[1]; + Anope::string value = params[2]; + Anope::string ttb = params.size() > 3 ? params[3] : ""; ChannelInfo *ci = cs_findchan(chan); if (readonly) notice_lang(Config.s_BotServ, u, BOT_KICK_DISABLED); - else if (!chan || option.empty() || value.empty()) + else if (chan.empty() || option.empty() || value.empty()) syntax_error(Config.s_BotServ, u, "KICK", BOT_KICK_SYNTAX); - else if (value != "ON" && value != "OFF") + else if (!value.equals_ci("ON") && !value.equals_ci("OFF")) syntax_error(Config.s_BotServ, u, "KICK", BOT_KICK_SYNTAX); else if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) notice_lang(Config.s_BotServ, u, ACCESS_DENIED); @@ -42,22 +42,22 @@ class CommandBSKick : public Command notice_help(Config.s_BotServ, u, BOT_NOT_ASSIGNED); else { - if (option == "BADWORDS") + if (option.equals_ci("BADWORDS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_BADWORDS] = strtol(ttb, NULL, 10); + Anope::string error; + ci->ttb[TTB_BADWORDS] = convertTo(ttb, error, false); /* Only error if errno returns ERANGE or EINVAL or we are less then 0 - TSL */ - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_BADWORDS] < 0) + if (!error.empty() || ci->ttb[TTB_BADWORDS] < 0) { /* leaving the debug behind since we might want to know what these are */ - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_BADWORDS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BADWORDS]; /* reset the value back to 0 - TSL */ ci->ttb[TTB_BADWORDS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -75,19 +75,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_BADWORDS_OFF); } } - else if (option == "BOLDS") + else if (option.equals_ci("BOLDS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_BOLDS] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_BOLDS] < 0) + Anope::string error; + ci->ttb[TTB_BOLDS] = convertTo(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_BOLDS] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_BOLDS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BOLDS]; ci->ttb[TTB_BOLDS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -105,39 +105,39 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_BOLDS_OFF); } } - else if (option == "CAPS") + else if (option.equals_ci("CAPS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - const char *min = params.size() > 4 ? params[4].c_str() : NULL; - const char *percent = params.size() > 5 ? params[5].c_str() : NULL; + Anope::string min = params.size() > 4 ? params[4] : ""; + Anope::string percent = params.size() > 5 ? params[5] : ""; - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_CAPS] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_CAPS] < 0) + Anope::string error; + ci->ttb[TTB_CAPS] = convertTo(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_CAPS] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_CAPS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_CAPS]; ci->ttb[TTB_CAPS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } else ci->ttb[TTB_CAPS] = 0; - if (!min) + if (min.empty()) ci->capsmin = 10; else - ci->capsmin = atol(min); + ci->capsmin = min.is_number_only() ? convertTo(min) : 10; if (ci->capsmin < 1) ci->capsmin = 10; - if (!percent) + if (percent.empty()) ci->capspercent = 25; else - ci->capspercent = atol(percent); + ci->capspercent = percent.is_number_only() ? convertTo(percent) : 25; if (ci->capspercent < 1 || ci->capspercent > 100) ci->capspercent = 25; @@ -153,19 +153,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_CAPS_OFF); } } - else if (option == "COLORS") + else if (option.equals_ci("COLORS")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_COLORS] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_COLORS] < 0) + Anope::string error; + ci->ttb[TTB_COLORS] = convertTo(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_COLORS] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_COLORS]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_COLORS]; ci->ttb[TTB_COLORS] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -183,39 +183,39 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_COLORS_OFF); } } - else if (option == "FLOOD") + else if (option.equals_ci("FLOOD")) { - if (value == "ON") + if (value.equals_ci("ON")) { - const char *lines = params.size() > 4 ? params[4].c_str() : NULL; - const char *secs = params.size() > 5 ? params[5].c_str() : NULL; + Anope::string lines = params.size() > 4 ? params[4] : ""; + Anope::string secs = params.size() > 5 ? params[5] : ""; - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_FLOOD] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_FLOOD] < 0) + Anope::string error; + ci->ttb[TTB_FLOOD] = convertTo(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_FLOOD] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_FLOOD]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_FLOOD]; ci->ttb[TTB_FLOOD] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } else ci->ttb[TTB_FLOOD] = 0; - if (!lines) + if (lines.empty()) ci->floodlines = 6; else - ci->floodlines = atol(lines); + ci->floodlines = lines.is_number_only() ? convertTo(lines) : 6; if (ci->floodlines < 2) ci->floodlines = 6; - if (!secs) + if (secs.empty()) ci->floodsecs = 10; else - ci->floodsecs = atol(secs); + ci->floodsecs = secs.is_number_only() ? convertTo(secs) : 10; if (ci->floodsecs < 1 || ci->floodsecs > Config.BSKeepData) ci->floodsecs = 10; @@ -231,31 +231,31 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_FLOOD_OFF); } } - else if (option == "REPEAT") + else if (option.equals_ci("REPEAT")) { - if (value == "ON") + if (value.equals_ci("ON")) { - const char *times = params.size() > 4 ? params[4].c_str() : NULL; + Anope::string times = params.size() > 4 ? params[4] : ""; - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_REPEAT] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_REPEAT] < 0) + Anope::string error; + ci->ttb[TTB_REPEAT] = convertTo(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_REPEAT] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_REPEAT]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REPEAT]; ci->ttb[TTB_REPEAT] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } else ci->ttb[TTB_REPEAT] = 0; - if (!times) + if (times.empty()) ci->repeattimes = 3; else - ci->repeattimes = atol(times); + ci->repeattimes = times.is_number_only() ? convertTo(times) : 3; if (ci->repeattimes < 2) ci->repeattimes = 3; @@ -271,19 +271,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_REPEAT_OFF); } } - else if (option == "REVERSES") + else if (option.equals_ci("REVERSES")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_REVERSES] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_REVERSES] < 0) + Anope::string error; + ci->ttb[TTB_REVERSES] = convertTo(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_REVERSES] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_REVERSES]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REVERSES]; ci->ttb[TTB_REVERSES] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -301,19 +301,19 @@ class CommandBSKick : public Command notice_lang(Config.s_BotServ, u, BOT_KICK_REVERSES_OFF); } } - else if (option == "UNDERLINES") + else if (option.equals_ci("UNDERLINES")) { - if (value == "ON") + if (value.equals_ci("ON")) { - if (ttb) + if (!ttb.empty()) { - errno = 0; - ci->ttb[TTB_UNDERLINES] = strtol(ttb, NULL, 10); - if (errno == ERANGE || errno == EINVAL || ci->ttb[TTB_UNDERLINES] < 0) + Anope::string error; + ci->ttb[TTB_UNDERLINES] = convertTo(ttb, error, false); + if (!error.empty() || ci->ttb[TTB_UNDERLINES] < 0) { - Alog(LOG_DEBUG) << "errno is " << errno << " ERANGE " << ERANGE << " EINVAL " << EINVAL << " ttb " << ci->ttb[TTB_UNDERLINES]; + Alog(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_UNDERLINES]; ci->ttb[TTB_UNDERLINES] = 0; - notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb); + notice_lang(Config.s_BotServ, u, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -337,25 +337,25 @@ class CommandBSKick : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) notice_help(Config.s_BotServ, u, BOT_HELP_KICK); - else if (subcommand == "BADWORDS") + else if (subcommand.equals_ci("BADWORDS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_BADWORDS); - else if (subcommand == "BOLDS") + else if (subcommand.equals_ci("BOLDS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_BOLDS); - else if (subcommand == "CAPS") + else if (subcommand.equals_ci("CAPS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_CAPS); - else if (subcommand == "COLORS") + else if (subcommand.equals_ci("COLORS")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_COLORS); - else if (subcommand == "FLOOD") + else if (subcommand.equals_ci("FLOOD")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_FLOOD); - else if (subcommand == "REPEAT") + else if (subcommand.equals_ci("REPEAT")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_REPEAT); - else if (subcommand == "REVERSES") + else if (subcommand.equals_ci("REVERSES")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_REVERSES); - else if (subcommand == "UNDERLINES") + else if (subcommand.equals_ci("UNDERLINES")) notice_help(Config.s_BotServ, u, BOT_HELP_KICK_UNDERLINES); else return false; @@ -363,7 +363,7 @@ class CommandBSKick : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "KICK", BOT_KICK_SYNTAX); } @@ -377,10 +377,11 @@ class CommandBSKick : public Command class BSKick : public Module { public: - BSKick(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSKick()); } }; diff --git a/modules/core/bs_say.cpp b/modules/core/bs_say.cpp index 88b298544..81616cf32 100644 --- a/modules/core/bs_say.cpp +++ b/modules/core/bs_say.cpp @@ -20,12 +20,12 @@ class CommandBSSay : public Command { } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { ChannelInfo *ci; - const char *chan = params[0].c_str(); - const char *text = params[1].c_str(); + Anope::string chan = params[0]; + Anope::string text = params[1]; ci = cs_findchan(chan); @@ -53,20 +53,20 @@ class CommandBSSay : public Command return MOD_CONT; } - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", text); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", text.c_str()); ci->bi->lastmsg = time(NULL); - if (Config.LogBot && Config.LogChannel && LogChan && !debug && findchan(Config.LogChannel)) - ircdproto->SendPrivmsg(ci->bi, Config.LogChannel, "SAY %s %s %s", u->nick.c_str(), ci->name.c_str(), text); + if (Config.LogBot && !Config.LogChannel.empty() && LogChan && !debug && findchan(Config.LogChannel)) + ircdproto->SendPrivmsg(ci->bi, Config.LogChannel, "SAY %s %s %s", u->nick.c_str(), ci->name.c_str(), text.c_str()); return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { notice_help(Config.s_BotServ, u, BOT_HELP_SAY); return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "SAY", BOT_SAY_SYNTAX); } @@ -80,10 +80,11 @@ class CommandBSSay : public Command class BSSay : public Module { public: - BSSay(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSSay(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCommand(BotServ, new CommandBSSay()); } }; diff --git a/modules/core/bs_set.cpp b/modules/core/bs_set.cpp index d6f70352a..9788c278c 100644 --- a/modules/core/bs_set.cpp +++ b/modules/core/bs_set.cpp @@ -21,11 +21,11 @@ class CommandBSSet : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector ¶ms) + CommandReturn Execute(User *u, const std::vector ¶ms) { - const char *chan = params[0].c_str(); - ci::string option = params[1]; - ci::string value = params[2]; + Anope::string chan = params[0]; + Anope::string option = params[1]; + Anope::string value = params[2]; ChannelInfo *ci; if (readonly) @@ -34,22 +34,22 @@ class CommandBSSet : public Command return MOD_CONT; } - if (u->Account()->HasCommand("botserv/set/private") && option == "PRIVATE") + if (u->Account()->HasCommand("botserv/set/private") && option.equals_ci("PRIVATE")) { BotInfo *bi; if (!(bi = findbot(chan))) { - notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, chan); + notice_lang(Config.s_BotServ, u, BOT_DOES_NOT_EXIST, chan.c_str()); return MOD_CONT; } - if (value == "ON") + if (value.equals_ci("ON")) { bi->SetFlag(BI_PRIVATE); notice_lang(Config.s_BotServ, u, BOT_SET_PRIVATE_ON, bi->nick.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { bi->UnsetFlag(BI_PRIVATE); notice_lang(Config.s_BotServ, u, BOT_SET_PRIVATE_OFF, bi->nick.c_str()); @@ -59,19 +59,19 @@ class CommandBSSet : public Command return MOD_CONT; } else if (!(ci = cs_findchan(chan))) - notice_lang(Config.s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); + notice_lang(Config.s_BotServ, u, CHAN_X_NOT_REGISTERED, chan.c_str()); else if (!u->Account()->HasPriv("botserv/administration") && !check_access(u, ci, CA_SET)) notice_lang(Config.s_BotServ, u, ACCESS_DENIED); else { - if (option == "DONTKICKOPS") + if (option.equals_ci("DONTKICKOPS")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_DONTKICKOPS); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKOPS_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_DONTKICKOPS); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKOPS_OFF, ci->name.c_str()); @@ -79,14 +79,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET DONTKICKOPS", BOT_SET_DONTKICKOPS_SYNTAX); } - else if (option == "DONTKICKVOICES") + else if (option.equals_ci("DONTKICKVOICES")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_DONTKICKVOICES); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKVOICES_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_DONTKICKVOICES); notice_lang(Config.s_BotServ, u, BOT_SET_DONTKICKVOICES_OFF, ci->name.c_str()); @@ -94,14 +94,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET DONTKICKVOICES", BOT_SET_DONTKICKVOICES_SYNTAX); } - else if (option == "FANTASY") + else if (option.equals_ci("FANTASY")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_FANTASY); notice_lang(Config.s_BotServ, u, BOT_SET_FANTASY_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_FANTASY); notice_lang(Config.s_BotServ, u, BOT_SET_FANTASY_OFF, ci->name.c_str()); @@ -109,14 +109,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET FANTASY", BOT_SET_FANTASY_SYNTAX); } - else if (option == "GREET") + else if (option.equals_ci("GREET")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_GREET); notice_lang(Config.s_BotServ, u, BOT_SET_GREET_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_GREET); notice_lang(Config.s_BotServ, u, BOT_SET_GREET_OFF, ci->name.c_str()); @@ -124,16 +124,16 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET GREET", BOT_SET_GREET_SYNTAX); } - else if (u->Account()->HasCommand("botserv/set/nobot") && option == "NOBOT") + else if (u->Account()->HasCommand("botserv/set/nobot") && option.equals_ci("NOBOT")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_NOBOT); if (ci->bi) ci->bi->UnAssign(u, ci); notice_lang(Config.s_BotServ, u, BOT_SET_NOBOT_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_NOBOT); notice_lang(Config.s_BotServ, u, BOT_SET_NOBOT_OFF, ci->name.c_str()); @@ -141,14 +141,14 @@ class CommandBSSet : public Command else syntax_error(Config.s_BotServ, u, "SET NOBOT", BOT_SET_NOBOT_SYNTAX); } - else if (option == "SYMBIOSIS") + else if (option.equals_ci("SYMBIOSIS")) { - if (value == "ON") + if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_SYMBIOSIS); notice_lang(Config.s_BotServ, u, BOT_SET_SYMBIOSIS_ON, ci->name.c_str()); } - else if (value == "OFF") + else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_SYMBIOSIS); notice_lang(Config.s_BotServ, u, BOT_SET_SYMBIOSIS_OFF, ci->name.c_str()); @@ -162,7 +162,7 @@ class CommandBSSet : public Command return MOD_CONT; } - bool OnHelp(User *u, const ci::string &subcommand) + bool OnHelp(User *u, const Anope::string &subcommand) { if (subcommand.empty()) { @@ -170,19 +170,19 @@ class CommandBSSet : public Command if (u->Account() && u->Account()->IsServicesOper()) notice_help(Config.s_BotServ, u, BOT_SERVADMIN_HELP_SET); } - else if (subcommand == "DONTKICKOPS") + else if (subcommand.equals_ci("DONTKICKOPS")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_DONTKICKOPS); - else if (subcommand == "DONTKICKVOICES") + else if (subcommand.equals_ci("DONTKICKVOICES")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_DONTKICKVOICES); - else if (subcommand == "FANTASY") + else if (subcommand.equals_ci("FANTASY")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_FANTASY); - else if (subcommand == "GREET") + else if (subcommand.equals_ci("GREET")) notice_help(Config.s_BotServ, u, BOT_HELP_SET_GREET); - else if (subcommand == "SYMBIOSIS") - notice_lang(Config.s_BotServ, u, BOT_HELP_SET_SYMBIOSIS, Config.s_ChanServ); - else if (subcommand == "NOBOT") + else if (subcommand.equals_ci("SYMBIOSIS")) + notice_lang(Config.s_BotServ, u, BOT_HELP_SET_SYMBIOSIS, Config.s_ChanServ.c_str()); + else if (subcommand.equals_ci("NOBOT")) notice_lang(Config.s_BotServ, u, BOT_SERVADMIN_HELP_SET_NOBOT); - else if (subcommand == "PRIVATE") + else if (subcommand.equals_ci("PRIVATE")) notice_lang(Config.s_BotServ, u, BOT_SERVADMIN_HELP_SET_PRIVATE); else return false; @@ -190,7 +190,7 @@ class CommandBSSet : public Command return true; } - void OnSyntaxError(User *u, const ci::string &subcommand) + void OnSyntaxError(User *u, const Anope::string &subcommand) { syntax_error(Config.s_BotServ, u, "SET", BOT_SET_SYNTAX); } @@ -204,10 +204,11 @@ class CommandBSSet : public Command class BSSet : public Module { public: - BSSet(const std::string &modname, const std::string &creator) : Module(modname, creator) + BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) { this->SetAuthor("Anope"); this->SetType(CORE); + this->AddCo