summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2013-05-06 11:49:50 +0100
committerPeter Powell <petpow@saberuk.com>2013-05-15 03:32:56 +0100
commitaccccc212cd4f08a3c5532b1ae7a17e76bac8718 (patch)
tree18f4370778cc79d2f21a4308dafbb29a77cfa213 /src/commands
parent23e8bba13c55d33ce89d505780da36c9589e300a (diff)
Replace some C-isms with C++-isms.
* 'const char*' to 'const std::string&'. * snprintf to std::string concatenation. * Replace duplicated OneOfMatches with InspIRCd::MatchMask.
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/cmd_kick.cpp2
-rw-r--r--src/commands/cmd_oper.cpp24
-rw-r--r--src/commands/cmd_stats.cpp2
-rw-r--r--src/commands/cmd_time.cpp13
4 files changed, 10 insertions, 31 deletions
diff --git a/src/commands/cmd_kick.cpp b/src/commands/cmd_kick.cpp
index 3c5fb0052..87ee1da6d 100644
--- a/src/commands/cmd_kick.cpp
+++ b/src/commands/cmd_kick.cpp
@@ -77,7 +77,7 @@ CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User
reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
}
- c->KickUser(user, u, reason.c_str());
+ c->KickUser(user, u, reason);
return CMD_SUCCESS;
}
diff --git a/src/commands/cmd_oper.cpp b/src/commands/cmd_oper.cpp
index 117813719..15ee9c969 100644
--- a/src/commands/cmd_oper.cpp
+++ b/src/commands/cmd_oper.cpp
@@ -21,8 +21,6 @@
#include "inspircd.h"
-bool OneOfMatches(const char* host, const char* ip, const char* hostlist);
-
/** Handle /OPER. These command handlers can be reloaded by the core,
* and handle basic RFC1459 commands. Commands within modules work
* the same way, however, they can be fully unloaded, where these
@@ -43,30 +41,14 @@ class CommandOper : public SplitCommand
CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user);
};
-bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
-{
- std::stringstream hl(hostlist);
- std::string xhost;
- while (hl >> xhost)
- {
- if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
- {
- return true;
- }
- }
- return false;
-}
-
CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
{
- char TheHost[MAXBUF];
- char TheIP[MAXBUF];
bool match_login = false;
bool match_pass = false;
bool match_hosts = false;
- snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str());
- snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString().c_str());
+ const std::string userHost = user->ident + "@" + user->host;
+ const std::string userIP = user->ident + "@" + user->GetIPString();
OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
if (i != ServerInstance->Config->oper_blocks.end())
@@ -75,7 +57,7 @@ CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, L
ConfigTag* tag = ifo->oper_block;
match_login = true;
match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
- match_hosts = OneOfMatches(TheHost,TheIP,tag->getString("host"));
+ match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
if (match_pass && match_hosts)
{
diff --git a/src/commands/cmd_stats.cpp b/src/commands/cmd_stats.cpp
index ccf753956..d9f3c1496 100644
--- a/src/commands/cmd_stats.cpp
+++ b/src/commands/cmd_stats.cpp
@@ -283,7 +283,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results)
double n_eaten = (double)( ( (uint64_t)(KernelTime.dwHighDateTime - ServerInstance->stats->LastCPU.dwHighDateTime) << 32 ) + (uint64_t)(KernelTime.dwLowDateTime - ServerInstance->stats->LastCPU.dwLowDateTime) )/100000;
double n_elapsed = (double)(ThisSample.QuadPart - ServerInstance->stats->LastSampled.QuadPart) / ServerInstance->stats->QPFrequency.QuadPart;
double per = (n_eaten/n_elapsed);
-
+
char percent[30];
snprintf(percent, 30, "%03.5f%%", per);
diff --git a/src/commands/cmd_time.cpp b/src/commands/cmd_time.cpp
index db452d381..8c516ac42 100644
--- a/src/commands/cmd_time.cpp
+++ b/src/commands/cmd_time.cpp
@@ -50,16 +50,13 @@ CmdResult CommandTime::Handle (const std::vector<std::string>& parameters, User
{
if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
return CMD_SUCCESS;
- struct tm* timeinfo;
- time_t local = ServerInstance->Time();
-
- timeinfo = localtime(&local);
- char tms[26];
- snprintf(tms,26,"%s",asctime(timeinfo));
- tms[24] = 0;
+ time_t local = ServerInstance->Time();
+ struct tm* timeinfo = localtime(&local);
+ const std::string& humanTime = asctime(timeinfo);
- user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),ServerInstance->Config->ServerName.c_str(),tms);
+ user->SendText(":%s %03d %s %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_TIME, user->nick.c_str(),
+ ServerInstance->Config->ServerName.c_str(), humanTime.c_str());
return CMD_SUCCESS;
}