Skip to content

Commit

Permalink
Use std::time() instead of plain C time()
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed May 13, 2018
1 parent ccbb736 commit d268249
Show file tree
Hide file tree
Showing 33 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/ai/contexts.cpp
Expand Up @@ -442,7 +442,7 @@ void readonly_context_impl::log_message(const std::string& msg)
{
if(game_config::debug) {
game_display::get_singleton()->get_chat_manager().add_chat_message(
time(nullptr), "ai", get_side(), msg, events::chat_handler::MESSAGE_PUBLIC, false);
std::time(nullptr), "ai", get_side(), msg, events::chat_handler::MESSAGE_PUBLIC, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/formula/ai.cpp
Expand Up @@ -135,7 +135,7 @@ void formula_ai::handle_exception(const formula_error& e, const std::string& fai

void formula_ai::display_message(const std::string& msg) const
{
game_display::get_singleton()->get_chat_manager().add_chat_message(time(nullptr), "wfl", get_side(), msg,
game_display::get_singleton()->get_chat_manager().add_chat_message(std::time(nullptr), "wfl", get_side(), msg,
events::chat_handler::MESSAGE_PUBLIC, false);

}
Expand Down
6 changes: 3 additions & 3 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -77,7 +77,7 @@ bool authenticate(config& campaign, const config::attribute_value& passphrase)

std::string generate_salt(std::size_t len)
{
boost::mt19937 mt(time(0));
boost::mt19937 mt(std::time(0));
std::string salt = std::string(len, '0');
boost::uniform_int<> from_str(0, 63); // 64 possible values for base64
boost::variate_generator< boost::mt19937, boost::uniform_int<>> get_char(mt, from_str);
Expand Down Expand Up @@ -576,7 +576,7 @@ void server::handle_request_campaign_list(const server::request& req)
{
LOG_CS << "sending campaign list to " << req.addr << " using gzip\n";

std::time_t epoch = time(nullptr);
std::time_t epoch = std::time(nullptr);
config campaign_list;

campaign_list["timestamp"] = epoch;
Expand Down Expand Up @@ -825,7 +825,7 @@ void server::handle_upload(const server::request& req)
LOG_CS << "Upload denied - hidden add-on.\n";
send_error("Add-on upload denied. Please contact the server administration for assistance.", req.sock);
} else {
const std::time_t upload_ts = time(nullptr);
const std::time_t upload_ts = std::time(nullptr);

LOG_CS << "Upload is owner upload.\n";

Expand Down
2 changes: 1 addition & 1 deletion src/chat_command_handler.cpp
Expand Up @@ -28,7 +28,7 @@ bool chat_command_handler::is_enabled(const map_command_handler<chat_command_han

void chat_command_handler::print(const std::string& title, const std::string& message)
{
chat_handler_.add_chat_message(time(nullptr), title, 0, message);
chat_handler_.add_chat_message(std::time(nullptr), title, 0, message);
}


Expand Down
14 changes: 7 additions & 7 deletions src/chat_events.cpp
Expand Up @@ -60,7 +60,7 @@ void chat_handler::change_logging(const std::string& data) {
const std::string& msg =
VGETTEXT("Unknown debug level: '$level'.", symbols);
ERR_NG << msg << std::endl;
add_chat_message(time(nullptr), _("error"), 0, msg);
add_chat_message(std::time(nullptr), _("error"), 0, msg);
return;
}
if (!lg::set_log_domain_severity(domain, severity)) {
Expand All @@ -69,7 +69,7 @@ void chat_handler::change_logging(const std::string& data) {
const std::string& msg =
VGETTEXT("Unknown debug domain: '$domain'.", symbols);
ERR_NG << msg << std::endl;
add_chat_message(time(nullptr), _("error"), 0, msg);
add_chat_message(std::time(nullptr), _("error"), 0, msg);
return;
}
else {
Expand All @@ -79,7 +79,7 @@ void chat_handler::change_logging(const std::string& data) {
const std::string& msg =
VGETTEXT("Switched domain: '$domain' to level: '$level'.", symbols);
LOG_NG << msg << "\n";
add_chat_message(time(nullptr), "log", 0, msg);
add_chat_message(std::time(nullptr), "log", 0, msg);
}
}

Expand All @@ -96,7 +96,7 @@ void chat_handler::send_command(const std::string& cmd, const std::string& args
data.add_child(cmd)["username"] = args;
}
else if (cmd == "ping") {
data[cmd] = std::to_string(time(nullptr));
data[cmd] = std::to_string(std::time(nullptr));
}
else if (cmd == "report") {
data.add_child("query")["type"] = "report " + args;
Expand Down Expand Up @@ -149,14 +149,14 @@ void chat_handler::add_whisper_sent(const std::string& receiver, const std::stri
{
utils::string_map symbols;
symbols["receiver"] = receiver;
add_chat_message(time(nullptr), VGETTEXT("whisper to $receiver", symbols), 0, message);
add_chat_message(std::time(nullptr), VGETTEXT("whisper to $receiver", symbols), 0, message);
}

void chat_handler::add_whisper_received(const std::string& sender, const std::string& message)
{
utils::string_map symbols;
symbols["sender"] = sender;
add_chat_message(time(nullptr), VGETTEXT("whisper: $sender", symbols), 0, message);
add_chat_message(std::time(nullptr), VGETTEXT("whisper: $sender", symbols), 0, message);
}

void chat_handler::send_chat_room_message(const std::string& room,
Expand All @@ -178,7 +178,7 @@ void chat_handler::add_chat_room_message_sent(const std::string &room, const std
void chat_handler::add_chat_room_message_received(const std::string &room,
const std::string &speaker, const std::string &message)
{
add_chat_message(time(nullptr), room + ": " + speaker, 0, message, events::chat_handler::MESSAGE_PRIVATE);
add_chat_message(std::time(nullptr), room + ": " + speaker, 0, message, events::chat_handler::MESSAGE_PRIVATE);
}

}
2 changes: 1 addition & 1 deletion src/format_time_summary.cpp
Expand Up @@ -21,7 +21,7 @@
namespace utils {

std::string format_time_summary(std::time_t t) {
std::time_t curtime = time(nullptr);
std::time_t curtime = std::time(nullptr);
const struct tm* timeptr = localtime(&curtime);
if(timeptr == nullptr) {
return "";
Expand Down
6 changes: 3 additions & 3 deletions src/formula/function.cpp
Expand Up @@ -266,7 +266,7 @@ DEFINE_WFL_FUNCTION(debug_print, 1, 2)

if(game_config::debug) {
game_display::get_singleton()->get_chat_manager().add_chat_message(
time(nullptr), "WFL", 0, str1, events::chat_handler::MESSAGE_PUBLIC, false);
std::time(nullptr), "WFL", 0, str1, events::chat_handler::MESSAGE_PUBLIC, false);
}

return var1;
Expand All @@ -280,7 +280,7 @@ DEFINE_WFL_FUNCTION(debug_print, 1, 2)

if(game_config::debug && game_display::get_singleton()) {
game_display::get_singleton()->get_chat_manager().add_chat_message(
time(nullptr), str1, 0, str2, events::chat_handler::MESSAGE_PUBLIC, false);
std::time(nullptr), str1, 0, str2, events::chat_handler::MESSAGE_PUBLIC, false);
}

return var2;
Expand Down Expand Up @@ -313,7 +313,7 @@ DEFINE_WFL_FUNCTION(debug_profile, 1, 2)

if(game_config::debug && game_display::get_singleton()) {
game_display::get_singleton()->get_chat_manager().add_chat_message(
time(nullptr), speaker, 0, str.str(), events::chat_handler::MESSAGE_PUBLIC, false);
std::time(nullptr), speaker, 0, str.str(), events::chat_handler::MESSAGE_PUBLIC, false);
}

return value;
Expand Down
2 changes: 1 addition & 1 deletion src/game_events/pump.cpp
Expand Up @@ -366,7 +366,7 @@ void wml_event_pump::show_wml_messages(std::stringstream& source, const std::str
}

game_display::get_singleton()->get_chat_manager().add_chat_message(
time(nullptr), caption, 0, msg.str(), events::chat_handler::MESSAGE_PUBLIC, false);
std::time(nullptr), caption, 0, msg.str(), events::chat_handler::MESSAGE_PUBLIC, false);

if(to_cerr) {
std::cerr << caption << ": " << msg.str() << '\n';
Expand Down
2 changes: 1 addition & 1 deletion src/game_initialization/lobby_data.cpp
Expand Up @@ -67,7 +67,7 @@ void chat_session::add_message(const std::time_t& timestamp,

void chat_session::add_message(const std::string& user, const std::string& message)
{
add_message(time(nullptr), user, message);
add_message(std::time(nullptr), user, message);
}

void chat_session::clear()
Expand Down
2 changes: 1 addition & 1 deletion src/generators/map_generator.cpp
Expand Up @@ -85,7 +85,7 @@ int main(int argc, char** argv)
nplayers = std::stoi(argv[7]);
}

srand(time(nullptr));
srand(std::time(nullptr));
std::cout << generate_map(x,y,iterations,hill_size,lakes,nvillages,nplayers) << "\n";
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/debug_clock.cpp
Expand Up @@ -173,7 +173,7 @@ debug_clock::time::time() : hour(0), minute(0), second(0), millisecond(0)

void debug_clock::time::set_current_time()
{
std::time_t now = ::time(nullptr);
std::time_t now = ::std::time(nullptr);
tm* stamp = localtime(&now);

hour = stamp->tm_hour;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/widgets/chatbox.cpp
Expand Up @@ -219,7 +219,7 @@ void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const b
const bool chatbox_at_end = log.vertical_scrollbar_at_end();

const std::string new_text = formatter()
<< log.get_label() << "\n" << "<span color='#bcb088'>" << preferences::get_chat_timestamp(time(0)) << text << "</span>";
<< log.get_label() << "\n" << "<span color='#bcb088'>" << preferences::get_chat_timestamp(std::time(0)) << text << "</span>";

log.set_use_markup(true);
log.set_label(new_text);
Expand All @@ -243,7 +243,7 @@ void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const b

void chatbox::send_chat_message(const std::string& message, bool /*allies_only*/)
{
add_chat_message(time(nullptr), preferences::login(), 0, message);
add_chat_message(std::time(nullptr), preferences::login(), 0, message);

::config c {"message", ::config {"message", message, "sender", preferences::login()}};
send_to_server(c);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/debug.cpp
Expand Up @@ -84,7 +84,7 @@ std::string get_base_filename()
{
std::ostringstream ss;

std::time_t t = time(nullptr);
std::time_t t = std::time(nullptr);
ss << std::put_time(std::localtime(&t), "%Y%m%d_%H%M%S");

static unsigned counter = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/log.cpp
Expand Up @@ -227,7 +227,7 @@ std::ostream &logger::operator()(const log_domain& domain, bool show_names, bool
if(precise_timestamp) {
print_precise_timestamp(stream);
} else {
stream << get_timestamp(time(nullptr));
stream << get_timestamp(std::time(nullptr));
}
}
if (show_names) {
Expand Down Expand Up @@ -256,7 +256,7 @@ void scope_logger::do_log_exit() noexcept
} catch(...) {}
--indent;
do_indent();
if (timestamp) (*output_) << get_timestamp(time(nullptr));
if (timestamp) (*output_) << get_timestamp(std::time(nullptr));
(*output_) << "} END: " << str_ << " (took " << ticks << "ms)\n";
}

Expand Down
2 changes: 1 addition & 1 deletion src/log_windows.cpp
Expand Up @@ -109,7 +109,7 @@ std::string unique_log_filename()

o << log_file_prefix;

const std::time_t cur = time(nullptr);
const std::time_t cur = std::time(nullptr);
o << std::put_time(std::localtime(&cur), "%Y%m%d-%H%M%S-");

o << GetCurrentProcessId() << log_file_suffix;
Expand Down
8 changes: 4 additions & 4 deletions src/menu_events.cpp
Expand Up @@ -1159,7 +1159,7 @@ class console_handler : public map_command_handler<console_handler>, private cha

void print(const std::string& title, const std::string& message)
{
menu_handler_.add_chat_message(time(nullptr), title, 0, message);
menu_handler_.add_chat_message(std::time(nullptr), title, 0, message);
}

void init_map()
Expand Down Expand Up @@ -1273,7 +1273,7 @@ void menu_handler::send_chat_message(const std::string& message, bool allies_onl
config cfg;
cfg["id"] = preferences::login();
cfg["message"] = message;
const std::time_t time = ::time(nullptr);
const std::time_t time = ::std::time(nullptr);
std::stringstream ss;
ss << time;
cfg["time"] = ss.str();
Expand Down Expand Up @@ -1946,10 +1946,10 @@ void console_handler::do_whiteboard_options()
void menu_handler::do_ai_formula(const std::string& str, int side_num)
{
try {
add_chat_message(time(nullptr), "wfl", 0, ai::manager::get_singleton().evaluate_command(side_num, str));
add_chat_message(std::time(nullptr), "wfl", 0, ai::manager::get_singleton().evaluate_command(side_num, str));
} catch(const wfl::formula_error&) {
} catch(...) {
add_chat_message(time(nullptr), "wfl", 0, "UNKNOWN ERROR IN FORMULA");
add_chat_message(std::time(nullptr), "wfl", 0, "UNKNOWN ERROR IN FORMULA");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/playmp_controller.cpp
Expand Up @@ -393,7 +393,7 @@ bool playmp_controller::is_host() const

void playmp_controller::do_idle_notification()
{
gui_->get_chat_manager().add_chat_message(time(nullptr), "", 0,
gui_->get_chat_manager().add_chat_message(std::time(nullptr), "", 0,
_("This side is in an idle state. To proceed with the game, it must be assigned to another controller. You may use :droid, :control or :give_control for example."),
events::chat_handler::MESSAGE_PUBLIC, false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/playsingle_controller.cpp
Expand Up @@ -569,7 +569,7 @@ void playsingle_controller::play_ai_turn()
*/
void playsingle_controller::do_idle_notification()
{
gui_->get_chat_manager().add_chat_message(time(nullptr), "Wesnoth", 0,
gui_->get_chat_manager().add_chat_message(std::time(nullptr), "Wesnoth", 0,
"This side is in an idle state. To proceed with the game, the host must assign it to another controller.",
events::chat_handler::MESSAGE_PUBLIC, false);
}
Expand Down
4 changes: 2 additions & 2 deletions src/playturn.cpp
Expand Up @@ -135,13 +135,13 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg

if (const config &message = cfg.child("message"))
{
game_display::get_singleton()->get_chat_manager().add_chat_message(time(nullptr), message["sender"], message["side"],
game_display::get_singleton()->get_chat_manager().add_chat_message(std::time(nullptr), message["sender"], message["side"],
message["message"], events::chat_handler::MESSAGE_PUBLIC,
preferences::message_bell());
}
else if (const config &whisper = cfg.child("whisper") /*&& is_observer()*/)
{
game_display::get_singleton()->get_chat_manager().add_chat_message(time(nullptr), "whisper: " + whisper["sender"].str(), 0,
game_display::get_singleton()->get_chat_manager().add_chat_message(std::time(nullptr), "whisper: " + whisper["sender"].str(), 0,
whisper["message"], events::chat_handler::MESSAGE_PRIVATE,
preferences::message_bell());
}
Expand Down
2 changes: 1 addition & 1 deletion src/replay.cpp
Expand Up @@ -135,7 +135,7 @@ static std::time_t get_time(const config &speak)
else
{
//fallback in case sender uses wesnoth that doesn't send timestamps
time = ::time(nullptr);
time = std::time(nullptr);
}
return time;
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/game_lua_kernel.cpp
Expand Up @@ -188,7 +188,7 @@ void game_lua_kernel::log_error(char const * msg, char const * context)
void game_lua_kernel::lua_chat(const std::string& caption, const std::string& msg)
{
if (game_display_) {
game_display_->get_chat_manager().add_chat_message(time(nullptr), caption, 0, msg,
game_display_->get_chat_manager().add_chat_message(std::time(nullptr), caption, 0, msg,
events::chat_handler::MESSAGE_PUBLIC, false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/lua_common.cpp
Expand Up @@ -946,7 +946,7 @@ bool luaW_checkvariable(lua_State *L, variable_access_create& v, int n)
void chat_message(const std::string& caption, const std::string& msg)
{
if (!game_display::get_singleton()) return;
game_display::get_singleton()->get_chat_manager().add_chat_message(time(nullptr), caption, 0, msg,
game_display::get_singleton()->get_chat_manager().add_chat_message(std::time(nullptr), caption, 0, msg,
events::chat_handler::MESSAGE_PUBLIC, false);
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/ban.cpp
Expand Up @@ -94,7 +94,7 @@ static lg::log_domain log_server("server");
mask_(0),
ip_text_(ip),
end_time_(end_time),
start_time_(time(0)),
start_time_(std::time(0)),
reason_(reason),
who_banned_(who_banned),
group_(group),
Expand Down Expand Up @@ -236,7 +236,7 @@ static lg::log_domain log_server("server");
{
return "permanent";
}
return lg::get_timespan(end_time_ - time(nullptr));
return lg::get_timespan(end_time_ - std::time(nullptr));
}

bool banned::operator>(const banned& b) const
Expand Down
2 changes: 1 addition & 1 deletion src/server/ban.hpp
Expand Up @@ -137,7 +137,7 @@ namespace wesnothd {
void init_ban_help();
void check_ban_times(std::time_t time_now);
inline void expire_bans() {
check_ban_times(time(nullptr));
check_ban_times(std::time(nullptr));
}
public:
ban_manager();
Expand Down
2 changes: 1 addition & 1 deletion src/server/forum_user_handler.cpp
Expand Up @@ -123,7 +123,7 @@ std::string fuh::extract_salt(const std::string& name) {
}

void fuh::user_logged_in(const std::string& name) {
set_lastlogin(name, time(nullptr));
set_lastlogin(name, std::time(nullptr));
}

bool fuh::user_exists(const std::string& name) {
Expand Down
4 changes: 2 additions & 2 deletions src/server/metrics.cpp
Expand Up @@ -42,7 +42,7 @@ metrics::metrics() :
current_requests_(0),
nrequests_(0),
nrequests_waited_(0),
started_at_(time(nullptr)),
started_at_(std::time(nullptr)),
terminations_()
{}

Expand Down Expand Up @@ -150,7 +150,7 @@ std::ostream& metrics::requests(std::ostream& out) const

std::ostream& operator<<(std::ostream& out, metrics& met)
{
const std::time_t time_up = time(nullptr) - met.started_at_;
const std::time_t time_up = std::time(nullptr) - met.started_at_;
const int seconds = time_up%60;
const int minutes = (time_up/60)%60;
const int hours = (time_up/(60*60))%24;
Expand Down
2 changes: 1 addition & 1 deletion src/server/player.cpp
Expand Up @@ -76,7 +76,7 @@ void wesnothd::player::mark_registered(bool registered)

bool wesnothd::player::is_message_flooding()
{
const std::time_t now = time(nullptr);
const std::time_t now = std::time(nullptr);
if (flood_start_ == 0) {
flood_start_ = now;
return false;
Expand Down

0 comments on commit d268249

Please sign in to comment.