Permalink
Browse files

Fix prints for the new commands

  • Loading branch information...
mbasaglia committed Feb 21, 2016
1 parent 8264884 commit dbc642aed121e30f4eed75bf2c2641445424c675
Showing with 54 additions and 47 deletions.
  1. +43 −42 daemon/src/engine/server/sv_ccmds.cpp
  2. +11 −5 daemon/src/engine/server/sv_main.cpp
@@ -249,7 +249,44 @@ class StatusCmd: public Cmd::StaticCmd
cpu = 100 * svs.stats.latched_active / cpu;
}
std::vector<std::string> players;
auto players = std::count_if(
svs.clients,
svs.clients+sv_maxclients->integer,
[](const client_t& cl) {
return cl.state != clientState_t::CS_FREE;
}
);
std::string time_string;
auto seconds = svs.time / 1000 % 60;
auto minutes = svs.time / 1000 / 60 % 60;
if ( auto hours = svs.time / 1000 / 60 / 60 / 60 )
{
time_string = Str::Format("%02d:", hours);
}
time_string += Str::Format("%02d:%02d", minutes, seconds);
Print(
"(begin server status)\n"
"hostname: %s\n"
"version: %s\n"
"protocol: %d\n"
"cpu: %.0f%%\n"
"time: %s\n"
"map: %s\n"
"players: %d / %d\n"
"num score connection address port name\n"
"--- ----- ---------- ---------------------- ------ ----",
sv_hostname->string,
Q3_VERSION " on " Q3_ENGINE,
PROTOCOL_VERSION,
cpu,
time_string,
sv_mapname->string,
players,
sv_maxclients->integer
);
for ( int i = 0; i < sv_maxclients->integer; i++ )
{
const client_t& cl = svs.clients[i];
@@ -280,54 +317,18 @@ class StatusCmd: public Cmd::StaticCmd
const char *address = NET_AdrToString( cl.netchan.remoteAddress );
players.push_back(Str::Format(
Print(
"%3i %5i %10s %-22s %-6i %s",
i,
ps->persistant[ PERS_SCORE ],
connection,
address,
cl.netchan.qport,
cl.name
));
);
}
std::string time_string;
auto seconds = svs.time / 1000 % 60;
auto minutes = svs.time / 1000 / 60 % 60;
if ( auto hours = svs.time / 1000 / 60 / 60 / 60 )
{
time_string = Str::Format("%02d:", hours);
}
time_string += Str::Format("%02d:%02d", minutes, seconds);
Log::Notice(
"(begin server status)\n"
"hostname: %s\n"
"version: %s\n"
"protocol: %d\n"
"cpu: %.0f%%\n"
"time: %s\n"
"map: %s\n"
"players: %d / %d\n"
"num score connection address port name\n"
"--- ----- ---------- ---------------------- ------ ----\n",
sv_hostname->string,
Q3_VERSION " on " Q3_ENGINE,
PROTOCOL_VERSION,
cpu,
time_string,
sv_mapname->string,
players.size(),
sv_maxclients->integer
);
for ( const auto& player : players )
{
Log::Notice( "%s", player.c_str() );
}
Log::Notice( "(end server status)" );
Print( "(end server status)" );
}
};
static StatusCmd StatusCmdRegistration;
@@ -414,11 +415,11 @@ class ListMapsCmd: public Cmd::StaticCmd
std::sort( maps.begin(), maps.end() );
maps.erase( std::unique( maps.begin(), maps.end() ), maps.end() );
Log::Notice("Listing %d maps:", maps.size());
Print("Listing %d maps:", maps.size());
for ( const auto& map: maps )
{
Log::Notice("%s", map.c_str());
Print("%s", map.c_str());
}
}
};
@@ -787,18 +787,24 @@ class RconEnvironment: public Cmd::DefaultEnvironment {
: from(from), bufferSize(MAX_MSGLEN - prefix.size() - 1)
{}
virtual void Print(Str::StringRef text) OVERRIDE {
if (text.size() + buffer.size() > bufferSize - 1) {
virtual void Print(Str::StringRef text) OVERRIDE
{
if (text.size() + buffer.size() > bufferSize - 1)
{
Flush();
}
buffer += text;
buffer += '\n';
}
void Flush() {
Net::OutOfBandPrint(netsrc_t::NS_SERVER, from, "%s\n%s", prefix, buffer);
buffer.clear();
void Flush()
{
if ( !buffer.empty() )
{
Net::OutOfBandPrint(netsrc_t::NS_SERVER, from, "%s\n%s", prefix, buffer);
buffer.clear();
}
}
static void PrintError(netadr_t to, const std::string& message)

0 comments on commit dbc642a

Please sign in to comment.