Skip to content

Commit

Permalink
Merge pull request #6 from JAJames/sarah
Browse files Browse the repository at this point in the history
Fixes compilation error & expands playerlist for RenX.ServerList
  • Loading branch information
JAJames committed Dec 19, 2018
2 parents d03d0c5 + e945134 commit 751b3e8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
6 changes: 4 additions & 2 deletions RenX.Commands/RenX_Commands.cpp
Expand Up @@ -1883,8 +1883,9 @@ void BanSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString
entry = entries.get(i);
if (isMatch(type))
{
time_t current_time = std::chrono::system_clock::to_time_t(entry->timestamp);
Jupiter::StringS &ip_str = Jupiter::Socket::ntop4(entry->ip);
strftime(timeStr, sizeof(timeStr), "%b %d %Y, %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(entry->timestamp))));
strftime(timeStr, sizeof(timeStr), "%b %d %Y, %H:%M:%S", localtime(&current_time));

if ((entry->flags & 0x7FFF) == 0)
types = " NULL;"_jrs;
Expand Down Expand Up @@ -2347,8 +2348,9 @@ void ExemptionSearchIRCCommand::trigger(IRC_Bot *source, const Jupiter::Readable
entry = entries.get(i);
if (isMatch(type))
{
time_t current_time = std::chrono::system_clock::to_time_t(entry->timestamp);
Jupiter::StringS &ip_str = Jupiter::Socket::ntop4(entry->ip);
strftime(timeStr, sizeof(timeStr), "%b %d %Y, %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(entry->timestamp))));
strftime(timeStr, sizeof(timeStr), "%b %d %Y, %H:%M:%S", localtime(&current_time));

if ((entry->flags & 0xFF) == 0)
types = " NULL;"_jrs;
Expand Down
18 changes: 12 additions & 6 deletions RenX.Core/RenX_Server.cpp
Expand Up @@ -559,7 +559,8 @@ void RenX::Server::banCheck(RenX::PlayerInfo &player)
char timeStr[256];
if (last_to_expire[0] != nullptr) // Game ban
{
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(last_to_expire[0]->timestamp + last_to_expire[0]->length))));
time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[0]->timestamp + last_to_expire[0]->length);
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(&current_time));
if (last_to_expire[0]->length == std::chrono::seconds::zero())
this->forceKickPlayer(player, Jupiter::StringS::Format("You were permanently banned from %.*s on %s for: %.*s", RenX::Server::ban_from_str.size(), RenX::Server::ban_from_str.ptr(), timeStr, last_to_expire[0]->reason.size(), last_to_expire[0]->reason.ptr()));
else
Expand All @@ -571,7 +572,8 @@ void RenX::Server::banCheck(RenX::PlayerInfo &player)
{
if (last_to_expire[1] != nullptr) // Chat ban
{
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(last_to_expire[1]->timestamp + last_to_expire[1]->length))));
time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[1]->timestamp + last_to_expire[1]->length);
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(&current_time));
this->mute(player);
if (last_to_expire[1]->length == std::chrono::seconds::zero())
this->sendMessage(player, Jupiter::StringS::Format("You were permanently muted on this server on %s for: %.*s", timeStr, last_to_expire[1]->reason.size(), last_to_expire[1]->reason.ptr()));
Expand All @@ -582,32 +584,36 @@ void RenX::Server::banCheck(RenX::PlayerInfo &player)
}
else if (last_to_expire[2] != nullptr) // Bot ban
{
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(last_to_expire[2]->timestamp + last_to_expire[2]->length))));
time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[2]->timestamp + last_to_expire[2]->length);
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(&current_time));
if (last_to_expire[2]->length == std::chrono::seconds::zero())
this->sendMessage(player, Jupiter::StringS::Format("You were permanently bot-muted on this server on %s for: %.*s", timeStr, last_to_expire[2]->reason.size(), last_to_expire[2]->reason.ptr()));
else
this->sendMessage(player, Jupiter::StringS::Format("You are bot-muted on this server until %s for: %.*s", timeStr, last_to_expire[2]->reason.size(), last_to_expire[2]->reason.ptr()));
}
if (last_to_expire[3] != nullptr) // Vote ban
{
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(last_to_expire[3]->timestamp + last_to_expire[3]->length))));
time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[3]->timestamp + last_to_expire[3]->length);
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(&current_time));
if (last_to_expire[3]->length == std::chrono::seconds::zero())
this->sendMessage(player, Jupiter::StringS::Format("You were permanently vote-muted on this server on %s for: %.*s", timeStr, last_to_expire[3]->reason.size(), last_to_expire[3]->reason.ptr()));
else
this->sendMessage(player, Jupiter::StringS::Format("You are vote-muted on this server until %s for: %.*s", timeStr, last_to_expire[3]->reason.size(), last_to_expire[3]->reason.ptr()));
}
if (last_to_expire[4] != nullptr) // Mine ban
{
time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[4]->timestamp + last_to_expire[4]->length);
this->mineBan(player);
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(last_to_expire[4]->timestamp + last_to_expire[4]->length))));
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(&current_time));
if (last_to_expire[4]->length == std::chrono::seconds::zero())
this->sendMessage(player, Jupiter::StringS::Format("You were permanently mine-banned on this server on %s for: %.*s", timeStr, last_to_expire[4]->reason.size(), last_to_expire[4]->reason.ptr()));
else
this->sendMessage(player, Jupiter::StringS::Format("You are mine-banned on this server until %s for: %.*s", timeStr, last_to_expire[4]->reason.size(), last_to_expire[4]->reason.ptr()));
}
if (last_to_expire[5] != nullptr) // Ladder ban
{
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(std::addressof<const time_t>(std::chrono::system_clock::to_time_t(last_to_expire[5]->timestamp + last_to_expire[5]->length))));
time_t current_time = std::chrono::system_clock::to_time_t(last_to_expire[5]->timestamp + last_to_expire[5]->length);
strftime(timeStr, sizeof(timeStr), "%b %d %Y at %H:%M:%S", localtime(&current_time));
if (last_to_expire[5]->length == std::chrono::seconds::zero())
this->sendMessage(player, Jupiter::StringS::Format("You were permanently ladder-banned on this server on %s for: %.*s", timeStr, last_to_expire[5]->reason.size(), last_to_expire[5]->reason.ptr()));
else
Expand Down
6 changes: 4 additions & 2 deletions RenX.ExtraLogging/RenX_ExtraLogging.cpp
Expand Up @@ -25,7 +25,8 @@ using namespace Jupiter::literals;

RenX_ExtraLoggingPlugin::RenX_ExtraLoggingPlugin()
{
RenX_ExtraLoggingPlugin::day = localtime(std::addressof<const time_t>(time(nullptr)))->tm_yday;
time_t current_time = time(nullptr);
RenX_ExtraLoggingPlugin::day = localtime(&current_time)->tm_yday;
}

RenX_ExtraLoggingPlugin::~RenX_ExtraLoggingPlugin()
Expand Down Expand Up @@ -76,7 +77,8 @@ int RenX_ExtraLoggingPlugin::think()
{
if (RenX_ExtraLoggingPlugin::file != nullptr && RenX_ExtraLoggingPlugin::newDayFmt.isNotEmpty())
{
int currentDay = localtime(std::addressof<const time_t>(time(nullptr)))->tm_yday;
time_t current_time = time(nullptr);
int currentDay = localtime(&current_time)->tm_yday;
if (currentDay != RenX_ExtraLoggingPlugin::day)
{
RenX_ExtraLoggingPlugin::day = currentDay;
Expand Down
6 changes: 4 additions & 2 deletions RenX.Ladder.Daily/RenX_Ladder_Daily.cpp
Expand Up @@ -24,12 +24,13 @@ using namespace Jupiter::literals;

bool RenX_Ladder_Daily_TimePlugin::initialize()
{
time_t current_time = time(0);
// Load database
this->database.process_file(this->config.get("LadderDatabase"_jrs, "Ladder.Daily.db"_jrs));
this->database.setName(this->config.get("DatabaseName"_jrs, "Daily"_jrs));
this->database.setOutputTimes(this->config.get<bool>("OutputTimes"_jrs, false));

this->last_sorted_day = gmtime(std::addressof<const time_t>(time(0)))->tm_wday;
this->last_sorted_day = gmtime(&current_time)->tm_wday;
this->database.OnPreUpdateLadder = OnPreUpdateLadder;

// Force database to default, if desired
Expand All @@ -44,7 +45,8 @@ RenX_Ladder_Daily_TimePlugin pluginInstance;

void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server &, const RenX::TeamType &)
{
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
time_t current_time = time(0);
tm *tm_ptr = gmtime(&current_time);
if (pluginInstance.last_sorted_day != tm_ptr->tm_wday)
database.erase();
pluginInstance.last_sorted_day = tm_ptr->tm_wday;
Expand Down
6 changes: 4 additions & 2 deletions RenX.Ladder.Monthly/RenX_Ladder_Monthly.cpp
Expand Up @@ -24,12 +24,13 @@ using namespace Jupiter::literals;

bool RenX_Ladder_Monthly_TimePlugin::initialize()
{
time_t current_time = time(0);
// Load database
this->database.process_file(this->config.get("LadderDatabase"_jrs, "Ladder.Monthly.db"_jrs));
this->database.setName(this->config.get("DatabaseName"_jrs, "Monthly"_jrs));
this->database.setOutputTimes(this->config.get<bool>("OutputTimes"_jrs, false));

this->last_sorted_month = gmtime(std::addressof<const time_t>(time(0)))->tm_mon;
this->last_sorted_month = gmtime(&current_time)->tm_mon;
this->database.OnPreUpdateLadder = OnPreUpdateLadder;

// Force database to default, if desired
Expand All @@ -44,7 +45,8 @@ RenX_Ladder_Monthly_TimePlugin pluginInstance;

void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server &, const RenX::TeamType &)
{
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
time_t current_time = time(0);
tm *tm_ptr = gmtime(&current_time);
if (pluginInstance.last_sorted_month != tm_ptr->tm_mon)
database.erase();
pluginInstance.last_sorted_month = tm_ptr->tm_mon;
Expand Down
6 changes: 4 additions & 2 deletions RenX.Ladder.Weekly/RenX_Ladder_Weekly.cpp
Expand Up @@ -24,12 +24,13 @@ using namespace Jupiter::literals;

bool RenX_Ladder_Weekly_TimePlugin::initialize()
{
time_t current_time = time(0);
// Load database
this->database.process_file(this->config.get("LadderDatabase"_jrs, "Ladder.Weekly.db"_jrs));
this->database.setName(this->config.get("DatabaseName"_jrs, "Weekly"_jrs));
this->database.setOutputTimes(this->config.get<bool>("OutputTimes"_jrs, false));

this->last_sorted_day = gmtime(std::addressof<const time_t>(time(0)))->tm_wday;
this->last_sorted_day = gmtime(&current_time)->tm_wday;
this->reset_day = this->config.get<int>("ResetDay"_jrs);
this->database.OnPreUpdateLadder = OnPreUpdateLadder;

Expand All @@ -45,7 +46,8 @@ RenX_Ladder_Weekly_TimePlugin pluginInstance;

void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server &, const RenX::TeamType &)
{
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
time_t current_time = time(0);
tm *tm_ptr = gmtime(&current_time);
if (pluginInstance.last_sorted_day != tm_ptr->tm_wday && tm_ptr->tm_wday == pluginInstance.reset_day)
database.erase();
pluginInstance.last_sorted_day = tm_ptr->tm_wday;
Expand Down
6 changes: 4 additions & 2 deletions RenX.Ladder.Yearly/RenX_Ladder_Yearly.cpp
Expand Up @@ -24,12 +24,13 @@ using namespace Jupiter::literals;

bool RenX_Ladder_Yearly_TimePlugin::initialize()
{
time_t current_time = time(0);
// Load database
this->database.process_file(this->config.get("LadderDatabase"_jrs, "Ladder.Yearly.db"_jrs));
this->database.setName(this->config.get("DatabaseName"_jrs, "Yearly"_jrs));
this->database.setOutputTimes(this->config.get<bool>("OutputTimes"_jrs, false));

this->last_sorted_year = gmtime(std::addressof<const time_t>(time(0)))->tm_year;
this->last_sorted_year = gmtime(&current_time)->tm_year;
this->database.OnPreUpdateLadder = OnPreUpdateLadder;

// Force database to default, if desired
Expand All @@ -44,7 +45,8 @@ RenX_Ladder_Yearly_TimePlugin pluginInstance;

void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server &, const RenX::TeamType &)
{
tm *tm_ptr = gmtime(std::addressof<const time_t>(time(0)));
time_t current_time = time(0);
tm *tm_ptr = gmtime(&current_time);
if (pluginInstance.last_sorted_year != tm_ptr->tm_year)
database.erase();
pluginInstance.last_sorted_year = tm_ptr->tm_year;
Expand Down
28 changes: 15 additions & 13 deletions RenX.ServerList/RenX_ServerList.cpp
Expand Up @@ -450,7 +450,7 @@ void RenX_ServerListPlugin::addServerToServerList(RenX::Server &server)

// append to server_list_json

if (RenX_ServerListPlugin::server_list_json.isEmpty())
if (RenX_ServerListPlugin::server_list_json.size() <= 2)
{
RenX_ServerListPlugin::server_list_json = '[';
RenX_ServerListPlugin::server_list_json += server_as_json(server);
Expand Down Expand Up @@ -533,17 +533,15 @@ void RenX_ServerListPlugin::addServerToServerList(RenX::Server &server)

auto node = server.players.begin();

while (node != server.players.end())
if (node != server.players.end())
{
if (node->isBot == false)
{
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(node->name);
server_json_block += "\"}"_jrs;

++node;
break;
}
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(node->name);
server_json_block += "\", \"isBot\":"_jrs;
server_json_block += json_bool_as_cstring(node->isBot);
server_json_block += ", \"Team\":"_jrs;
server_json_block.aformat("%d", static_cast<int>(node->team));
server_json_block += "}"_jrs;

++node;
}
Expand All @@ -552,7 +550,11 @@ void RenX_ServerListPlugin::addServerToServerList(RenX::Server &server)
{
server_json_block += ",{\"Name\":\""_jrs;
server_json_block += jsonify(node->name);
server_json_block += "\"}"_jrs;
server_json_block += "\", \"isBot\":"_jrs;
server_json_block += json_bool_as_cstring(node->isBot);
server_json_block += ", \"Team\":"_jrs;
server_json_block.aformat("%d", static_cast<int>(node->team));
server_json_block += "}"_jrs;

++node;
}
Expand All @@ -571,7 +573,7 @@ void RenX_ServerListPlugin::updateServerList()
size_t index = 0;
RenX::Server *server;

// regenerate server_list_json and server_list_Game
// regenerate server_list_json and server_list_Game

RenX_ServerListPlugin::server_list_json = '[';
RenX_ServerListPlugin::server_list_game = server_list_game_header;
Expand Down

0 comments on commit 751b3e8

Please sign in to comment.