From 6f54bc95a483dfb7b6aaf0af02a1243d74e89f4c Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 18 May 2013 17:18:12 +0100 Subject: Use InspIRCd::Format instead of snprintf(). --- src/commands/cmd_commands.cpp | 9 +++------ src/commands/cmd_stats.cpp | 24 +++++++++++------------- 2 files changed, 14 insertions(+), 19 deletions(-) (limited to 'src/commands') diff --git a/src/commands/cmd_commands.cpp b/src/commands/cmd_commands.cpp index 36408b363..99acdfe96 100644 --- a/src/commands/cmd_commands.cpp +++ b/src/commands/cmd_commands.cpp @@ -53,12 +53,9 @@ CmdResult CommandCommands::Handle (const std::vector&, User *user) continue; Module* src = i->second->creator; - char buffer[MAXBUF]; - snprintf(buffer, MAXBUF, ":%s %03d %s :%s %s %d %d", - ServerInstance->Config->ServerName.c_str(), RPL_COMMANDS, user->nick.c_str(), - i->second->name.c_str(), src->ModuleSourceFile.c_str(), - i->second->min_params, i->second->Penalty); - list.push_back(buffer); + list.push_back(InspIRCd::Format(":%s %03d %s :%s %s %d %d", ServerInstance->Config->ServerName.c_str(), + RPL_COMMANDS, user->nick.c_str(), i->second->name.c_str(), src->ModuleSourceFile.c_str(), + i->second->min_params, i->second->Penalty)); } sort(list.begin(), list.end()); for(unsigned int i=0; i < list.size(); i++) diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp index 3145940be..9fef7bbd4 100644 --- a/src/commands/cmd_stats.cpp +++ b/src/commands/cmd_stats.cpp @@ -271,9 +271,9 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results) } FILETIME CreationTime; - FILETIME ExitTime; - FILETIME KernelTime; - FILETIME UserTime; + FILETIME ExitTime; + FILETIME KernelTime; + FILETIME UserTime; LARGE_INTEGER ThisSample; if(GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime) && QueryPerformanceCounter(&ThisSample)) @@ -301,15 +301,13 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results) case 'T': { - char buffer[MAXBUF]; results.push_back(sn+" 249 "+user->nick+" :accepts "+ConvToStr(ServerInstance->stats->statsAccept)+" refused "+ConvToStr(ServerInstance->stats->statsRefused)); results.push_back(sn+" 249 "+user->nick+" :unknown commands "+ConvToStr(ServerInstance->stats->statsUnknown)); results.push_back(sn+" 249 "+user->nick+" :nick collisions "+ConvToStr(ServerInstance->stats->statsCollisions)); results.push_back(sn+" 249 "+user->nick+" :dns requests "+ConvToStr(ServerInstance->stats->statsDnsGood+ServerInstance->stats->statsDnsBad)+" succeeded "+ConvToStr(ServerInstance->stats->statsDnsGood)+" failed "+ConvToStr(ServerInstance->stats->statsDnsBad)); results.push_back(sn+" 249 "+user->nick+" :connection count "+ConvToStr(ServerInstance->stats->statsConnects)); - snprintf(buffer,MAXBUF," 249 %s :bytes sent %5.2fK recv %5.2fK", - user->nick.c_str(),ServerInstance->stats->statsSent / 1024.0,ServerInstance->stats->statsRecv / 1024.0); - results.push_back(sn+buffer); + results.push_back(InspIRCd::Format("%s 249 %s :bytes sent %5.2fK recv %5.2fK", sn.c_str(), user->nick.c_str(), + ServerInstance->stats->statsSent / 1024.0, ServerInstance->stats->statsRecv / 1024.0)); } break; @@ -382,15 +380,15 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results) * Craig suggested this, and it seemed a good idea so in it went */ if (stime->tm_year > 70) { - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF," 242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d",user->nick.c_str(),(stime->tm_year-70),stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec); - results.push_back(sn+buffer); + results.push_back(InspIRCd::Format("%s 242 %s :Server up %d years, %d days, %.2d:%.2d:%.2d", + sn.c_str(), user->nick.c_str(), stime->tm_year - 70, stime->tm_yday, stime->tm_hour, + stime->tm_min, stime->tm_sec)); } else { - char buffer[MAXBUF]; - snprintf(buffer,MAXBUF," 242 %s :Server up %d days, %.2d:%.2d:%.2d",user->nick.c_str(),stime->tm_yday,stime->tm_hour,stime->tm_min,stime->tm_sec); - results.push_back(sn+buffer); + results.push_back(InspIRCd::Format("%s 242 %s :Server up %d days, %.2d:%.2d:%.2d", + sn.c_str(), user->nick.c_str(), stime->tm_yday, stime->tm_hour, stime->tm_min, + stime->tm_sec)); } } break; -- cgit v1.2.3 From ef3799a43a24f4b3da5e785765a6e4c01353845c Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 20 May 2013 19:25:46 +0100 Subject: Convert User::FormatNoticeMasks() to use std::string. --- include/users.h | 2 +- src/commands/cmd_whois.cpp | 2 +- src/mode.cpp | 2 +- src/users.cpp | 10 ++++------ 4 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/commands') diff --git a/include/users.h b/include/users.h index e27a764dc..9f732f134 100644 --- a/include/users.h +++ b/include/users.h @@ -403,7 +403,7 @@ class CoreExport User : public Extensible /** Create a displayable mode string for this users snomasks * @return The notice mask character sequence */ - const char* FormatNoticeMasks(); + std::string FormatNoticeMasks(); /** Process a snomask modifier string, e.g. +abc-de * @param sm A sequence of notice mask characters diff --git a/src/commands/cmd_whois.cpp b/src/commands/cmd_whois.cpp index fea14f375..de3d71152 100644 --- a/src/commands/cmd_whois.cpp +++ b/src/commands/cmd_whois.cpp @@ -152,7 +152,7 @@ void CommandWhois::DoWhois(User* user, User* dest, unsigned long signon, unsigne { if (dest->IsModeSet('s') != 0) { - ServerInstance->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes(), dest->FormatNoticeMasks()); + ServerInstance->SendWhoisLine(user, dest, 379, "%s %s :is using modes +%s +%s", user->nick.c_str(), dest->nick.c_str(), dest->FormatModes(), dest->FormatNoticeMasks().c_str()); } else { diff --git a/src/mode.cpp b/src/mode.cpp index 578fc2c27..ac0b111b1 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -190,7 +190,7 @@ void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targ /* Display user's current mode string */ user->WriteNumeric(RPL_UMODEIS, "%s :+%s",targetuser->nick.c_str(),targetuser->FormatModes()); if ((targetuser->IsOper())) - user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks()); + user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks().c_str()); return; } else diff --git a/src/users.cpp b/src/users.cpp index a8359692a..e0d420311 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -122,18 +122,16 @@ void User::SetNoticeMask(unsigned char sm, bool value) snomasks[sm-65] = value; } -const char* User::FormatNoticeMasks() +std::string User::FormatNoticeMasks() { - static char data[MAXBUF]; - int offset = 0; + std::string data; - for (int n = 0; n < 64; n++) + for (unsigned char n = 0; n < 64; n++) { if (snomasks[n]) - data[offset++] = n+65; + data.push_back(n + 65); } - data[offset] = 0; return data; } -- cgit v1.2.3