diff options
author | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-07-25 21:58:20 -0400 |
---|---|---|
committer | Naram Qashat <cyberbotx@cyberbotx.com> | 2010-07-25 21:58:20 -0400 |
commit | ae38212c1ce829c783edf971081c90137abb49a0 (patch) | |
tree | 5c652d9cdc38103dec6fa112d57fca882b4e3e44 /src/protocol.cpp | |
parent | 15d7f0f6fe8bb903275f603f734c13f65f3aa906 (diff) |
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.
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r-- | src/protocol.cpp | 111 |
1 files changed, 56 insertions, 55 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp index 13ff84a24..7bb21407b 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -1,6 +1,6 @@ #include "services.h" -void IRCDProto::SendMessageInternal(BotInfo *bi, const char *dest, const char *buf) +void IRCDProto::SendMessageInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { if (Config.NSDefFlags.HasFlag(NI_MSG)) SendPrivmsgInternal(bi, dest, buf); @@ -8,50 +8,49 @@ void IRCDProto::SendMessageInternal(BotInfo *bi, const char *dest, const char *b SendNoticeInternal(bi, dest, buf); } -void IRCDProto::SendNoticeInternal(BotInfo *bi, const char *dest, const char *msg) +void IRCDProto::SendNoticeInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :%s", dest, msg); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :%s", dest.c_str(), msg.c_str()); } -void IRCDProto::SendPrivmsgInternal(BotInfo *bi, const char *dest, const char *buf) +void IRCDProto::SendPrivmsgInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s :%s", dest, buf); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s :%s", dest.c_str(), buf.c_str()); } -void IRCDProto::SendQuitInternal(BotInfo *bi, const char *buf) +void IRCDProto::SendQuitInternal(BotInfo *bi, const Anope::string &buf) { - if (buf) - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT :%s", buf); + if (!buf.empty()) + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT :%s", buf.c_str()); else send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "QUIT"); } -void IRCDProto::SendPartInternal(BotInfo *bi, Channel *chan, const char *buf) +void IRCDProto::SendPartInternal(BotInfo *bi, Channel *chan, const Anope::string &buf) { - if (buf) - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s :%s", chan->name.c_str(), buf); + if (!buf.empty()) + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s :%s", chan->name.c_str(), buf.c_str()); else send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s", chan->name.c_str()); } -void IRCDProto::SendGlobopsInternal(BotInfo *source, const char *buf) +void IRCDProto::SendGlobopsInternal(BotInfo *source, const Anope::string &buf) { if (source) - send_cmd(ircd->ts6 ? source->GetUID() : source->nick, "GLOBOPS :%s", buf); + send_cmd(ircd->ts6 ? source->GetUID() : source->nick, "GLOBOPS :%s", buf.c_str()); else - send_cmd(Config.ServerName, "GLOBOPS :%s", buf); + send_cmd(Config.ServerName, "GLOBOPS :%s", buf.c_str()); } -void IRCDProto::SendCTCPInternal(BotInfo *bi, const char *dest, const char *buf) +void IRCDProto::SendCTCPInternal(BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { - char *s = normalizeBuffer(buf); - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :\1%s\1", dest, s); - delete [] s; + Anope::string s = normalizeBuffer(buf); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :\1%s\1", dest.c_str(), s.c_str()); } -void IRCDProto::SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf) +void IRCDProto::SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) { - send_cmd(source, "%03d %s %s", numeric, dest, buf); + send_cmd(source, "%03d %s %s", numeric, dest.c_str(), buf.c_str()); } void IRCDProto::SendSVSKill(BotInfo *source, User *user, const char *fmt, ...) @@ -110,7 +109,7 @@ void IRCDProto::SendNoticeChanops(BotInfo *bi, Channel *dest, const char *fmt, . SendNoticeChanopsInternal(bi, dest, buf); } -void IRCDProto::SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendMessage(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -120,7 +119,7 @@ void IRCDProto::SendMessage(BotInfo *bi, const char *dest, const char *fmt, ...) SendMessageInternal(bi, dest, buf); } -void IRCDProto::SendNotice(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendNotice(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -130,18 +129,18 @@ void IRCDProto::SendNotice(BotInfo *bi, const char *dest, const char *fmt, ...) SendNoticeInternal(bi, dest, buf); } -void IRCDProto::SendAction(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendAction(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; - char buf[BUFSIZE] = "", actionbuf[BUFSIZE] = ""; + char buf[BUFSIZE] = ""; va_start(args, fmt); vsnprintf(buf, BUFSIZE - 1, fmt, args); va_end(args); - snprintf(actionbuf, BUFSIZE - 1, "%cACTION %s%c", 1, buf, 1); + Anope::string actionbuf = Anope::string("\1ACTION ") + buf + '\1'; SendPrivmsgInternal(bi, dest, actionbuf); } -void IRCDProto::SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendPrivmsg(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -151,17 +150,17 @@ void IRCDProto::SendPrivmsg(BotInfo *bi, const char *dest, const char *fmt, ...) SendPrivmsgInternal(bi, dest, buf); } -void IRCDProto::SendGlobalNotice(BotInfo *bi, Server *dest, const char *msg) +void IRCDProto::SendGlobalNotice(BotInfo *bi, Server *dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str()); } -void IRCDProto::SendGlobalPrivmsg(BotInfo *bi, Server *dest, const char *msg) +void IRCDProto::SendGlobalPrivmsg(BotInfo *bi, Server *dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str()); } -void IRCDProto::SendQuit(const char *nick, const char *) +void IRCDProto::SendQuit(const Anope::string &nick, const Anope::string &) { send_cmd(nick, "QUIT"); } @@ -176,12 +175,12 @@ void IRCDProto::SendQuit(BotInfo *bi, const char *fmt, ...) SendQuitInternal(bi, buf); } -void IRCDProto::SendPing(const char *servname, const char *who) +void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who) { - if (!servname) - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s", who); + if (servname.empty()) + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s", who.c_str()); else - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s %s", servname, who); + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PING %s %s", servname.c_str(), who.c_str()); } /** @@ -190,17 +189,17 @@ void IRCDProto::SendPing(const char *servname, const char *who) * @param servname Daemon or client that is responding to the PING. * @param who Origin of the PING and destination of the PONG message. **/ -void IRCDProto::SendPong(const char *servname, const char *who) +void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who) { - if (!servname) - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s", who); - else - send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s %s", servname, who); + if (servname.empty()) + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s", who.c_str()); + else + send_cmd(ircd->ts6 ? TS6SID : Config.ServerName, "PONG %s %s", servname.c_str(), who.c_str()); } -void IRCDProto::SendInvite(BotInfo *bi, const char *chan, const char *nick) +void IRCDProto::SendInvite(BotInfo *bi, const Anope::string &chan, const Anope::string &nick) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "INVITE %s %s", nick, chan); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "INVITE %s %s", nick.c_str(), chan.c_str()); } void IRCDProto::SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...) @@ -214,7 +213,8 @@ void IRCDProto::SendPart(BotInfo *bi, Channel *chan, const char *fmt, ...) va_end(args); SendPartInternal(bi, chan, buf); } - else SendPartInternal(bi, chan, NULL); + else + SendPartInternal(bi, chan, ""); } void IRCDProto::SendGlobops(BotInfo *source, const char *fmt, ...) @@ -227,21 +227,22 @@ void IRCDProto::SendGlobops(BotInfo *source, const char *fmt, ...) SendGlobopsInternal(source, buf); } -void IRCDProto::SendSquit(const char *servname, const char *message) +void IRCDProto::SendSquit(const Anope::string &servname, const Anope::string &message) { - send_cmd(NULL, "SQUIT %s :%s", servname, message); + send_cmd("", "SQUIT %s :%s", servname.c_str(), message.c_str()); } -void IRCDProto::SendChangeBotNick(BotInfo *bi, const char *newnick) +void IRCDProto::SendChangeBotNick(BotInfo *bi, const Anope::string &newnick) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick, static_cast<long>(time(NULL))); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick.c_str(), static_cast<long>(time(NULL))); } -void IRCDProto::SendForceNickChange(User *u, const char *newnick, time_t when) + +void IRCDProto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when) { - send_cmd(NULL, "SVSNICK %s %s :%ld", u->nick.c_str(), newnick, static_cast<long>(when)); + send_cmd("", "SVSNICK %s %s :%ld", u->nick.c_str(), newnick.c_str(), static_cast<long>(when)); } -void IRCDProto::SendCTCP(BotInfo *bi, const char *dest, const char *fmt, ...) +void IRCDProto::SendCTCP(BotInfo *bi, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -251,7 +252,7 @@ void IRCDProto::SendCTCP(BotInfo *bi, const char *dest, const char *fmt, ...) SendCTCPInternal(bi, dest, buf); } -void IRCDProto::SendNumeric(const char *source, int numeric, const char *dest, const char *fmt, ...) +void IRCDProto::SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -261,10 +262,10 @@ void IRCDProto::SendNumeric(const char *source, int numeric, const char *dest, c SendNumericInternal(source, numeric, dest, buf); } -int IRCDProto::IsChannelValid(const char *chan) +bool IRCDProto::IsChannelValid(const Anope::string &chan) { - if (*chan != '#') - return 0; + if (chan[0] != '#') + return false; - return 1; + return true; } |