Use std::time_t instead of plain C time_t
This commit is contained in:
parent
e16373bada
commit
ccbb736a18
44 changed files with 123 additions and 121 deletions
|
@ -54,8 +54,8 @@ struct addon_info
|
||||||
|
|
||||||
std::string feedback_url;
|
std::string feedback_url;
|
||||||
|
|
||||||
time_t updated;
|
std::time_t updated;
|
||||||
time_t created;
|
std::time_t created;
|
||||||
|
|
||||||
// Artificial upload order index used to preserve add-ons upload order
|
// Artificial upload order index used to preserve add-ons upload order
|
||||||
// until we have actual first-upload timestamps implemented. This index
|
// until we have actual first-upload timestamps implemented. This index
|
||||||
|
|
|
@ -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";
|
LOG_CS << "sending campaign list to " << req.addr << " using gzip\n";
|
||||||
|
|
||||||
time_t epoch = time(nullptr);
|
std::time_t epoch = time(nullptr);
|
||||||
config campaign_list;
|
config campaign_list;
|
||||||
|
|
||||||
campaign_list["timestamp"] = epoch;
|
campaign_list["timestamp"] = epoch;
|
||||||
|
@ -585,14 +585,14 @@ void server::handle_request_campaign_list(const server::request& req)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool before_flag = false;
|
bool before_flag = false;
|
||||||
time_t before = epoch;
|
std::time_t before = epoch;
|
||||||
try {
|
try {
|
||||||
before += req.cfg["before"].to_time_t();
|
before += req.cfg["before"].to_time_t();
|
||||||
before_flag = true;
|
before_flag = true;
|
||||||
} catch(const bad_lexical_cast&) {}
|
} catch(const bad_lexical_cast&) {}
|
||||||
|
|
||||||
bool after_flag = false;
|
bool after_flag = false;
|
||||||
time_t after = epoch;
|
std::time_t after = epoch;
|
||||||
try {
|
try {
|
||||||
after += req.cfg["after"].to_time_t();
|
after += req.cfg["after"].to_time_t();
|
||||||
after_flag = true;
|
after_flag = true;
|
||||||
|
@ -825,7 +825,7 @@ void server::handle_upload(const server::request& req)
|
||||||
LOG_CS << "Upload denied - hidden add-on.\n";
|
LOG_CS << "Upload denied - hidden add-on.\n";
|
||||||
send_error("Add-on upload denied. Please contact the server administration for assistance.", req.sock);
|
send_error("Add-on upload denied. Please contact the server administration for assistance.", req.sock);
|
||||||
} else {
|
} else {
|
||||||
const time_t upload_ts = time(nullptr);
|
const std::time_t upload_ts = time(nullptr);
|
||||||
|
|
||||||
LOG_CS << "Upload is owner upload.\n";
|
LOG_CS << "Upload is owner upload.\n";
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ protected:
|
||||||
void do_speak(const std::string& message, bool allies_only=false);
|
void do_speak(const std::string& message, bool allies_only=false);
|
||||||
|
|
||||||
//called from do_speak
|
//called from do_speak
|
||||||
virtual void add_chat_message(const time_t& time,
|
virtual void add_chat_message(const std::time_t& time,
|
||||||
const std::string& speaker, int side, const std::string& message,
|
const std::string& speaker, int side, const std::string& message,
|
||||||
MESSAGE_TYPE type=MESSAGE_PRIVATE) = 0;
|
MESSAGE_TYPE type=MESSAGE_PRIVATE) = 0;
|
||||||
virtual void send_chat_message(const std::string& message, bool allies_only=false) = 0;
|
virtual void send_chat_message(const std::string& message, bool allies_only=false) = 0;
|
||||||
|
|
|
@ -296,9 +296,9 @@ std::size_t config_attribute_value::to_size_t(std::size_t def) const
|
||||||
return apply_visitor(attribute_numeric_visitor<std::size_t>(def));
|
return apply_visitor(attribute_numeric_visitor<std::size_t>(def));
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t config_attribute_value::to_time_t(time_t def) const
|
std::time_t config_attribute_value::to_time_t(std::time_t def) const
|
||||||
{
|
{
|
||||||
return apply_visitor(attribute_numeric_visitor<time_t>(def));
|
return apply_visitor(attribute_numeric_visitor<std::time_t>(def));
|
||||||
}
|
}
|
||||||
|
|
||||||
double config_attribute_value::to_double(double def) const
|
double config_attribute_value::to_double(double def) const
|
||||||
|
|
|
@ -153,7 +153,7 @@ public:
|
||||||
long long to_long_long(long long def = 0) const;
|
long long to_long_long(long long def = 0) const;
|
||||||
unsigned to_unsigned(unsigned def = 0) const;
|
unsigned to_unsigned(unsigned def = 0) const;
|
||||||
std::size_t to_size_t(std::size_t def = 0) const;
|
std::size_t to_size_t(std::size_t def = 0) const;
|
||||||
time_t to_time_t(time_t def = 0) const;
|
std::time_t to_time_t(std::time_t def = 0) const;
|
||||||
double to_double(double def = 0.) const;
|
double to_double(double def = 0.) const;
|
||||||
std::string str(const std::string& fallback = "") const;
|
std::string str(const std::string& fallback = "") const;
|
||||||
t_string t_str() const;
|
t_string t_str() const;
|
||||||
|
|
|
@ -43,7 +43,7 @@ display_chat_manager::chat_message::chat_message(int speaker, int h)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
void display_chat_manager::add_chat_message(const time_t& time, const std::string& speaker,
|
void display_chat_manager::add_chat_message(const std::time_t& time, const std::string& speaker,
|
||||||
int side, const std::string& message, events::chat_handler::MESSAGE_TYPE type,
|
int side, const std::string& message, events::chat_handler::MESSAGE_TYPE type,
|
||||||
bool bell)
|
bool bell)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
void remove_whisperer(const std::string& nick) { whisperers_.erase(nick); }
|
void remove_whisperer(const std::string& nick) { whisperers_.erase(nick); }
|
||||||
const std::set<std::string>& whisperers() const { return whisperers_; }
|
const std::set<std::string>& whisperers() const { return whisperers_; }
|
||||||
|
|
||||||
void add_chat_message(const time_t& time, const std::string& speaker,
|
void add_chat_message(const std::time_t& time, const std::string& speaker,
|
||||||
int side, const std::string& msg, events::chat_handler::MESSAGE_TYPE type, bool bell);
|
int side, const std::string& msg, events::chat_handler::MESSAGE_TYPE type, bool bell);
|
||||||
void clear_chat_messages() { prune_chat_messages(true); }
|
void clear_chat_messages() { prune_chat_messages(true); }
|
||||||
|
|
||||||
|
|
|
@ -991,7 +991,7 @@ bool file_exists(const std::string& name)
|
||||||
return file_exists(fs::path(name));
|
return file_exists(fs::path(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t file_modified_time(const std::string& fname)
|
std::time_t file_modified_time(const std::string& fname)
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
auto mtime = fs::last_write_time(fs::path(fname), ec);
|
auto mtime = fs::last_write_time(fs::path(fname), ec);
|
||||||
|
|
|
@ -219,7 +219,7 @@ bool is_directory(const std::string& fname);
|
||||||
bool file_exists(const std::string& name);
|
bool file_exists(const std::string& name);
|
||||||
|
|
||||||
/** Get the modification time of a file. */
|
/** Get the modification time of a file. */
|
||||||
time_t file_modified_time(const std::string& fname);
|
std::time_t file_modified_time(const std::string& fname);
|
||||||
|
|
||||||
/** Returns true if the file ends with '.gz'. */
|
/** Returns true if the file ends with '.gz'. */
|
||||||
bool is_gzip_file(const std::string& filename);
|
bool is_gzip_file(const std::string& filename);
|
||||||
|
@ -239,7 +239,7 @@ struct file_tree_checksum
|
||||||
void reset() {nfiles = 0;modified = 0;sum_size=0;}
|
void reset() {nfiles = 0;modified = 0;sum_size=0;}
|
||||||
// @todo make variables private!
|
// @todo make variables private!
|
||||||
std::size_t nfiles, sum_size;
|
std::size_t nfiles, sum_size;
|
||||||
time_t modified;
|
std::time_t modified;
|
||||||
bool operator==(const file_tree_checksum &rhs) const;
|
bool operator==(const file_tree_checksum &rhs) const;
|
||||||
bool operator!=(const file_tree_checksum &rhs) const
|
bool operator!=(const file_tree_checksum &rhs) const
|
||||||
{ return !operator==(rhs); }
|
{ return !operator==(rhs); }
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
std::string format_time_summary(time_t t) {
|
std::string format_time_summary(std::time_t t) {
|
||||||
time_t curtime = time(nullptr);
|
std::time_t curtime = time(nullptr);
|
||||||
const struct tm* timeptr = localtime(&curtime);
|
const struct tm* timeptr = localtime(&curtime);
|
||||||
if(timeptr == nullptr) {
|
if(timeptr == nullptr) {
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -18,5 +18,5 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
std::string format_time_summary(time_t t);
|
std::string format_time_summary(std::time_t t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ static lg::log_domain log_lobby("lobby");
|
||||||
|
|
||||||
namespace mp {
|
namespace mp {
|
||||||
|
|
||||||
chat_message::chat_message(const time_t& timestamp,
|
chat_message::chat_message(const std::time_t& timestamp,
|
||||||
const std::string& user,
|
const std::string& user,
|
||||||
const std::string& message)
|
const std::string& message)
|
||||||
: timestamp(timestamp), user(user), message(message)
|
: timestamp(timestamp), user(user), message(message)
|
||||||
|
@ -57,7 +57,7 @@ chat_session::chat_session() : history_()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void chat_session::add_message(const time_t& timestamp,
|
void chat_session::add_message(const std::time_t& timestamp,
|
||||||
const std::string& user,
|
const std::string& user,
|
||||||
const std::string& message)
|
const std::string& message)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -28,11 +29,11 @@ namespace mp {
|
||||||
struct chat_message
|
struct chat_message
|
||||||
{
|
{
|
||||||
/** Create a chat message */
|
/** Create a chat message */
|
||||||
chat_message(const time_t& timestamp,
|
chat_message(const std::time_t& timestamp,
|
||||||
const std::string& user,
|
const std::string& user,
|
||||||
const std::string& message);
|
const std::string& message);
|
||||||
|
|
||||||
time_t timestamp;
|
std::time_t timestamp;
|
||||||
std::string user;
|
std::string user;
|
||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
@ -43,7 +44,7 @@ class chat_session
|
||||||
public:
|
public:
|
||||||
chat_session();
|
chat_session();
|
||||||
|
|
||||||
void add_message(const time_t& timestamp,
|
void add_message(const std::time_t& timestamp,
|
||||||
const std::string& user,
|
const std::string& user,
|
||||||
const std::string& message);
|
const std::string& message);
|
||||||
|
|
||||||
|
|
|
@ -831,7 +831,7 @@ void addon_manager::copy_url_callback(text_box& url_box)
|
||||||
desktop::clipboard::copy_to_clipboard(url_box.get_value(), false);
|
desktop::clipboard::copy_to_clipboard(url_box.get_value(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string format_addon_time(time_t time)
|
static std::string format_addon_time(std::time_t time)
|
||||||
{
|
{
|
||||||
if(time) {
|
if(time) {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
|
@ -173,7 +173,7 @@ debug_clock::time::time() : hour(0), minute(0), second(0), millisecond(0)
|
||||||
|
|
||||||
void debug_clock::time::set_current_time()
|
void debug_clock::time::set_current_time()
|
||||||
{
|
{
|
||||||
time_t now = ::time(nullptr);
|
std::time_t now = ::time(nullptr);
|
||||||
tm* stamp = localtime(&now);
|
tm* stamp = localtime(&now);
|
||||||
|
|
||||||
hour = stamp->tm_hour;
|
hour = stamp->tm_hour;
|
||||||
|
|
|
@ -256,7 +256,7 @@ void chatbox::user_relation_changed(const std::string& /*name*/)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void chatbox::add_chat_message(const time_t& /*time*/,
|
void chatbox::add_chat_message(const std::time_t& /*time*/,
|
||||||
const std::string& speaker,
|
const std::string& speaker,
|
||||||
int /*side*/,
|
int /*side*/,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
|
|
@ -107,7 +107,7 @@ protected:
|
||||||
virtual void user_relation_changed(const std::string& name) override;
|
virtual void user_relation_changed(const std::string& name) override;
|
||||||
|
|
||||||
/** Inherited form @ref chat_handler */
|
/** Inherited form @ref chat_handler */
|
||||||
virtual void add_chat_message(const time_t& time,
|
virtual void add_chat_message(const std::time_t& time,
|
||||||
const std::string& speaker,
|
const std::string& speaker,
|
||||||
int side,
|
int side,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
|
|
@ -84,7 +84,7 @@ std::string get_base_filename()
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
||||||
time_t t = time(nullptr);
|
std::time_t t = time(nullptr);
|
||||||
ss << std::put_time(std::localtime(&t), "%Y%m%d_%H%M%S");
|
ss << std::put_time(std::localtime(&t), "%Y%m%d_%H%M%S");
|
||||||
|
|
||||||
static unsigned counter = 0;
|
static unsigned counter = 0;
|
||||||
|
|
|
@ -172,18 +172,18 @@ bool broke_strict() {
|
||||||
return strict_threw_;
|
return strict_threw_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_timestamp(const time_t& t, const std::string& format) {
|
std::string get_timestamp(const std::time_t& t, const std::string& format) {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
|
|
||||||
ss << std::put_time(std::localtime(&t), format.c_str());
|
ss << std::put_time(std::localtime(&t), format.c_str());
|
||||||
|
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
std::string get_timespan(const time_t& t) {
|
std::string get_timespan(const std::time_t& t) {
|
||||||
std::ostringstream sout;
|
std::ostringstream sout;
|
||||||
// There doesn't seem to be any library function for this
|
// There doesn't seem to be any library function for this
|
||||||
const time_t minutes = t / 60;
|
const std::time_t minutes = t / 60;
|
||||||
const time_t days = minutes / 60 / 24;
|
const std::time_t days = minutes / 60 / 24;
|
||||||
if(t <= 0) {
|
if(t <= 0) {
|
||||||
sout << "expired";
|
sout << "expired";
|
||||||
} else if(minutes == 0) {
|
} else if(minutes == 0) {
|
||||||
|
|
|
@ -138,8 +138,8 @@ public:
|
||||||
|
|
||||||
void timestamps(bool);
|
void timestamps(bool);
|
||||||
void precise_timestamps(bool);
|
void precise_timestamps(bool);
|
||||||
std::string get_timestamp(const time_t& t, const std::string& format="%Y%m%d %H:%M:%S ");
|
std::string get_timestamp(const std::time_t& t, const std::string& format="%Y%m%d %H:%M:%S ");
|
||||||
std::string get_timespan(const time_t& t);
|
std::string get_timespan(const std::time_t& t);
|
||||||
|
|
||||||
logger &err(), &warn(), &info(), &debug();
|
logger &err(), &warn(), &info(), &debug();
|
||||||
log_domain& general();
|
log_domain& general();
|
||||||
|
|
|
@ -109,7 +109,7 @@ std::string unique_log_filename()
|
||||||
|
|
||||||
o << log_file_prefix;
|
o << log_file_prefix;
|
||||||
|
|
||||||
const time_t cur = time(nullptr);
|
const std::time_t cur = time(nullptr);
|
||||||
o << std::put_time(std::localtime(&cur), "%Y%m%d-%H%M%S-");
|
o << std::put_time(std::localtime(&cur), "%Y%m%d-%H%M%S-");
|
||||||
|
|
||||||
o << GetCurrentProcessId() << log_file_suffix;
|
o << GetCurrentProcessId() << log_file_suffix;
|
||||||
|
|
|
@ -1012,7 +1012,7 @@ void menu_handler::do_speak(const std::string& message)
|
||||||
chat_handler::do_speak(message, false);
|
chat_handler::do_speak(message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void menu_handler::add_chat_message(const time_t& time,
|
void menu_handler::add_chat_message(const std::time_t& time,
|
||||||
const std::string& speaker,
|
const std::string& speaker,
|
||||||
int side,
|
int side,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
@ -1273,7 +1273,7 @@ void menu_handler::send_chat_message(const std::string& message, bool allies_onl
|
||||||
config cfg;
|
config cfg;
|
||||||
cfg["id"] = preferences::login();
|
cfg["id"] = preferences::login();
|
||||||
cfg["message"] = message;
|
cfg["message"] = message;
|
||||||
const time_t time = ::time(nullptr);
|
const std::time_t time = ::time(nullptr);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << time;
|
ss << time;
|
||||||
cfg["time"] = ss.str();
|
cfg["time"] = ss.str();
|
||||||
|
|
|
@ -123,7 +123,7 @@ public:
|
||||||
const gamemap& map() const;
|
const gamemap& map() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void add_chat_message(const time_t& time,
|
void add_chat_message(const std::time_t& time,
|
||||||
const std::string& speaker,
|
const std::string& speaker,
|
||||||
int side,
|
int side,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
|
|
|
@ -890,7 +890,7 @@ compression::format save_compression_format()
|
||||||
return compression::GZIP;
|
return compression::GZIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_chat_timestamp(const time_t& t) {
|
std::string get_chat_timestamp(const std::time_t& t) {
|
||||||
if (chat_timestamping()) {
|
if (chat_timestamping()) {
|
||||||
if(preferences::use_twelve_hour_clock_format() == false) {
|
if(preferences::use_twelve_hour_clock_format() == false) {
|
||||||
return lg::get_timestamp(t, _("[%H:%M]")) + " ";
|
return lg::get_timestamp(t, _("[%H:%M]")) + " ";
|
||||||
|
|
|
@ -199,7 +199,7 @@ class acquaintance;
|
||||||
|
|
||||||
|
|
||||||
// Multiplayer functions
|
// Multiplayer functions
|
||||||
std::string get_chat_timestamp(const time_t& t);
|
std::string get_chat_timestamp(const std::time_t& t);
|
||||||
bool chat_timestamping();
|
bool chat_timestamping();
|
||||||
void set_chat_timestamping(bool value);
|
void set_chat_timestamping(bool value);
|
||||||
|
|
||||||
|
|
|
@ -124,9 +124,9 @@ static void verify(const unit_map& units, const config& cfg) {
|
||||||
LOG_REPLAY << "verification passed\n";
|
LOG_REPLAY << "verification passed\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static time_t get_time(const config &speak)
|
static std::time_t get_time(const config &speak)
|
||||||
{
|
{
|
||||||
time_t time;
|
std::time_t time;
|
||||||
if (!speak["time"].empty())
|
if (!speak["time"].empty())
|
||||||
{
|
{
|
||||||
std::stringstream ss(speak["time"].str());
|
std::stringstream ss(speak["time"].str());
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "map/location.hpp"
|
#include "map/location.hpp"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -35,14 +36,14 @@ public:
|
||||||
const std::string &text() const { return text_; }
|
const std::string &text() const { return text_; }
|
||||||
const std::string &nick() const { return nick_; }
|
const std::string &nick() const { return nick_; }
|
||||||
const std::string &color() const { return color_; }
|
const std::string &color() const { return color_; }
|
||||||
const time_t &time() const { return time_; }
|
const std::time_t &time() const { return time_; }
|
||||||
chat_msg(const config &cfg);
|
chat_msg(const config &cfg);
|
||||||
virtual ~chat_msg();
|
virtual ~chat_msg();
|
||||||
private:
|
private:
|
||||||
std::string color_;
|
std::string color_;
|
||||||
std::string nick_;
|
std::string nick_;
|
||||||
std::string text_;
|
std::string text_;
|
||||||
time_t time_;
|
std::time_t time_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class replay
|
class replay
|
||||||
|
|
|
@ -1534,7 +1534,7 @@ REPORT_GENERATOR(report_clock, /*rc*/)
|
||||||
? "%I:%M %p"
|
? "%I:%M %p"
|
||||||
: "%H:%M";
|
: "%H:%M";
|
||||||
|
|
||||||
time_t t = std::time(nullptr);
|
std::time_t t = std::time(nullptr);
|
||||||
ss << std::put_time(std::localtime(&t), format);
|
ss << std::put_time(std::localtime(&t), format);
|
||||||
|
|
||||||
return text_report(ss.str(), _("Clock"));
|
return text_report(ss.str(), _("Clock"));
|
||||||
|
|
|
@ -43,11 +43,11 @@ void extract_summary_from_config(config&, config&);
|
||||||
|
|
||||||
void save_index_class::rebuild(const std::string& name)
|
void save_index_class::rebuild(const std::string& name)
|
||||||
{
|
{
|
||||||
time_t modified = filesystem::file_modified_time(filesystem::get_saves_dir() + "/" + name);
|
std::time_t modified = filesystem::file_modified_time(filesystem::get_saves_dir() + "/" + name);
|
||||||
rebuild(name, modified);
|
rebuild(name, modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_index_class::rebuild(const std::string& name, const time_t& modified)
|
void save_index_class::rebuild(const std::string& name, const std::time_t& modified)
|
||||||
{
|
{
|
||||||
log_scope("load_summary_from_file");
|
log_scope("load_summary_from_file");
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ void save_index_class::remove(const std::string& name)
|
||||||
write_save_index();
|
write_save_index();
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_index_class::set_modified(const std::string& name, const time_t& modified)
|
void save_index_class::set_modified(const std::string& name, const std::time_t& modified)
|
||||||
{
|
{
|
||||||
modified_[name] = modified;
|
modified_[name] = modified;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ void save_index_class::set_modified(const std::string& name, const time_t& modif
|
||||||
config& save_index_class::get(const std::string& name)
|
config& save_index_class::get(const std::string& name)
|
||||||
{
|
{
|
||||||
config& result = data(name);
|
config& result = data(name);
|
||||||
time_t m = modified_[name];
|
std::time_t m = modified_[name];
|
||||||
|
|
||||||
config::attribute_value& mod_time = result["mod_time"];
|
config::attribute_value& mod_time = result["mod_time"];
|
||||||
if(mod_time.empty() || mod_time.to_time_t() != m) {
|
if(mod_time.empty() || mod_time.to_time_t() != m) {
|
||||||
|
@ -227,7 +227,7 @@ std::string save_info::format_time_local() const
|
||||||
|
|
||||||
std::string save_info::format_time_summary() const
|
std::string save_info::format_time_summary() const
|
||||||
{
|
{
|
||||||
time_t t = modified();
|
std::time_t t = modified();
|
||||||
return utils::format_time_summary(t);
|
return utils::format_time_summary(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ create_save_info::create_save_info(const std::string* d)
|
||||||
|
|
||||||
save_info create_save_info::operator()(const std::string& filename) const
|
save_info create_save_info::operator()(const std::string& filename) const
|
||||||
{
|
{
|
||||||
time_t modified = filesystem::file_modified_time(dir + "/" + filename);
|
std::time_t modified = filesystem::file_modified_time(dir + "/" + filename);
|
||||||
save_index_manager.set_modified(filename, modified);
|
save_index_manager.set_modified(filename, modified);
|
||||||
return save_info(filename, modified);
|
return save_info(filename, modified);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ class save_info
|
||||||
private:
|
private:
|
||||||
friend class create_save_info;
|
friend class create_save_info;
|
||||||
|
|
||||||
save_info(const std::string& name, const time_t& modified)
|
save_info(const std::string& name, const std::time_t& modified)
|
||||||
: name_(name)
|
: name_(name)
|
||||||
, modified_(modified)
|
, modified_(modified)
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const time_t& modified() const
|
const std::time_t& modified() const
|
||||||
{
|
{
|
||||||
return modified_;
|
return modified_;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
time_t modified_;
|
std::time_t modified_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,10 +86,10 @@ public:
|
||||||
save_index_class();
|
save_index_class();
|
||||||
|
|
||||||
void rebuild(const std::string& name);
|
void rebuild(const std::string& name);
|
||||||
void rebuild(const std::string& name, const time_t& modified);
|
void rebuild(const std::string& name, const std::time_t& modified);
|
||||||
|
|
||||||
void remove(const std::string& name);
|
void remove(const std::string& name);
|
||||||
void set_modified(const std::string& name, const time_t& modified);
|
void set_modified(const std::string& name, const std::time_t& modified);
|
||||||
|
|
||||||
config& get(const std::string& name);
|
config& get(const std::string& name);
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ private:
|
||||||
|
|
||||||
bool loaded_;
|
bool loaded_;
|
||||||
config data_;
|
config data_;
|
||||||
std::map<std::string, time_t> modified_;
|
std::map<std::string, std::time_t> modified_;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern save_index_class save_index_manager;
|
extern save_index_class save_index_manager;
|
||||||
|
|
|
@ -85,7 +85,7 @@ static lg::log_domain log_server("server");
|
||||||
}
|
}
|
||||||
|
|
||||||
banned::banned(const std::string& ip,
|
banned::banned(const std::string& ip,
|
||||||
const time_t end_time,
|
const std::time_t end_time,
|
||||||
const std::string& reason,
|
const std::string& reason,
|
||||||
const std::string& who_banned,
|
const std::string& who_banned,
|
||||||
const std::string& group,
|
const std::string& group,
|
||||||
|
@ -324,7 +324,7 @@ static lg::log_domain log_server("server");
|
||||||
writer.write(cfg);
|
writer.write(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ban_manager::parse_time(const std::string& duration, time_t* time) const
|
bool ban_manager::parse_time(const std::string& duration, std::time_t* time) const
|
||||||
{
|
{
|
||||||
if (!time) return false;
|
if (!time) return false;
|
||||||
|
|
||||||
|
@ -489,7 +489,7 @@ static lg::log_domain log_server("server");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ban_manager::ban(const std::string& ip,
|
std::string ban_manager::ban(const std::string& ip,
|
||||||
const time_t& end_time,
|
const std::time_t& end_time,
|
||||||
const std::string& reason,
|
const std::string& reason,
|
||||||
const std::string& who_banned,
|
const std::string& who_banned,
|
||||||
const std::string& group,
|
const std::string& group,
|
||||||
|
@ -562,7 +562,7 @@ static lg::log_domain log_server("server");
|
||||||
write();
|
write();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ban_manager::check_ban_times(time_t time_now)
|
void ban_manager::check_ban_times(std::time_t time_now)
|
||||||
{
|
{
|
||||||
while (!time_queue_.empty())
|
while (!time_queue_.empty())
|
||||||
{
|
{
|
||||||
|
@ -704,7 +704,7 @@ static lg::log_domain log_server("server");
|
||||||
{
|
{
|
||||||
ban_times_.clear();
|
ban_times_.clear();
|
||||||
for (const config &bt : cfg.child_range("ban_time")) {
|
for (const config &bt : cfg.child_range("ban_time")) {
|
||||||
time_t duration = 0;
|
std::time_t duration = 0;
|
||||||
if (parse_time(bt["time"], &duration)) {
|
if (parse_time(bt["time"], &duration)) {
|
||||||
ban_times_.emplace(bt["name"], duration);
|
ban_times_.emplace(bt["name"], duration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,8 @@ namespace wesnothd {
|
||||||
unsigned int ip_;
|
unsigned int ip_;
|
||||||
unsigned int mask_;
|
unsigned int mask_;
|
||||||
std::string ip_text_;
|
std::string ip_text_;
|
||||||
time_t end_time_;
|
std::time_t end_time_;
|
||||||
time_t start_time_;
|
std::time_t start_time_;
|
||||||
std::string reason_;
|
std::string reason_;
|
||||||
std::string who_banned_;
|
std::string who_banned_;
|
||||||
std::string group_;
|
std::string group_;
|
||||||
|
@ -68,19 +68,19 @@ namespace wesnothd {
|
||||||
banned(const std::string& ip);
|
banned(const std::string& ip);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
banned(const std::string& ip, const time_t end_time, const std::string& reason, const std::string& who_banned=who_banned_default_, const std::string& group="", const std::string& nick="");
|
banned(const std::string& ip, const std::time_t end_time, const std::string& reason, const std::string& who_banned=who_banned_default_, const std::string& group="", const std::string& nick="");
|
||||||
banned(const config&);
|
banned(const config&);
|
||||||
|
|
||||||
void read(const config&);
|
void read(const config&);
|
||||||
void write(config&) const;
|
void write(config&) const;
|
||||||
|
|
||||||
time_t get_end_time() const
|
std::time_t get_end_time() const
|
||||||
{ return end_time_; }
|
{ return end_time_; }
|
||||||
|
|
||||||
std::string get_human_end_time() const;
|
std::string get_human_end_time() const;
|
||||||
std::string get_human_start_time() const;
|
std::string get_human_start_time() const;
|
||||||
std::string get_human_time_span() const;
|
std::string get_human_time_span() const;
|
||||||
static std::string get_human_time(const time_t&);
|
static std::string get_human_time(const std::time_t&);
|
||||||
|
|
||||||
std::string get_reason() const
|
std::string get_reason() const
|
||||||
{ return reason_; }
|
{ return reason_; }
|
||||||
|
@ -135,7 +135,7 @@ namespace wesnothd {
|
||||||
{ return c - '0'; }
|
{ return c - '0'; }
|
||||||
|
|
||||||
void init_ban_help();
|
void init_ban_help();
|
||||||
void check_ban_times(time_t time_now);
|
void check_ban_times(std::time_t time_now);
|
||||||
inline void expire_bans() {
|
inline void expire_bans() {
|
||||||
check_ban_times(time(nullptr));
|
check_ban_times(time(nullptr));
|
||||||
}
|
}
|
||||||
|
@ -152,9 +152,9 @@ namespace wesnothd {
|
||||||
* @returns false if an invalid time modifier is encountered.
|
* @returns false if an invalid time modifier is encountered.
|
||||||
* *time is undefined in that case.
|
* *time is undefined in that case.
|
||||||
*/
|
*/
|
||||||
bool parse_time(const std::string& duration, time_t* time) const;
|
bool parse_time(const std::string& duration, std::time_t* time) const;
|
||||||
|
|
||||||
std::string ban(const std::string&, const time_t&, const std::string&, const std::string&, const std::string&, const std::string& = "");
|
std::string ban(const std::string&, const std::time_t&, const std::string&, const std::string&, const std::string&, const std::string& = "");
|
||||||
void unban(std::ostringstream& os, const std::string& ip, bool immediate_write=true);
|
void unban(std::ostringstream& os, const std::string& ip, bool immediate_write=true);
|
||||||
void unban_group(std::ostringstream& os, const std::string& group);
|
void unban_group(std::ostringstream& os, const std::string& group);
|
||||||
|
|
||||||
|
|
|
@ -220,8 +220,8 @@ std::string fuh::user_info(const std::string& name) {
|
||||||
throw error("No user with the name '" + name + "' exists.");
|
throw error("No user with the name '" + name + "' exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t reg_date = get_registrationdate(name);
|
std::time_t reg_date = get_registrationdate(name);
|
||||||
time_t ll_date = get_lastlogin(name);
|
std::time_t ll_date = get_lastlogin(name);
|
||||||
|
|
||||||
std::string reg_string = ctime(®_date);
|
std::string reg_string = ctime(®_date);
|
||||||
std::string ll_string;
|
std::string ll_string;
|
||||||
|
@ -269,27 +269,27 @@ std::string fuh::get_mail(const std::string& user) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t fuh::get_lastlogin(const std::string& user) {
|
std::time_t fuh::get_lastlogin(const std::string& user) {
|
||||||
try {
|
try {
|
||||||
int time_int = get_writable_detail_for_user<int>(user, "user_lastvisit");
|
int time_int = get_writable_detail_for_user<int>(user, "user_lastvisit");
|
||||||
return time_t(time_int);
|
return std::time_t(time_int);
|
||||||
} catch (const sql_error& e) {
|
} catch (const sql_error& e) {
|
||||||
ERR_UH << "Could not retrieve last visit for user '" << user << "' :" << e.message << std::endl;
|
ERR_UH << "Could not retrieve last visit for user '" << user << "' :" << e.message << std::endl;
|
||||||
return time_t(0);
|
return std::time_t(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t fuh::get_registrationdate(const std::string& user) {
|
std::time_t fuh::get_registrationdate(const std::string& user) {
|
||||||
try {
|
try {
|
||||||
int time_int = get_detail_for_user<int>(user, "user_regdate");
|
int time_int = get_detail_for_user<int>(user, "user_regdate");
|
||||||
return time_t(time_int);
|
return std::time_t(time_int);
|
||||||
} catch (const sql_error& e) {
|
} catch (const sql_error& e) {
|
||||||
ERR_UH << "Could not retrieve registration date for user '" << user << "' :" << e.message << std::endl;
|
ERR_UH << "Could not retrieve registration date for user '" << user << "' :" << e.message << std::endl;
|
||||||
return time_t(0);
|
return std::time_t(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fuh::set_lastlogin(const std::string& user, const time_t& lastlogin) {
|
void fuh::set_lastlogin(const std::string& user, const std::time_t& lastlogin) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
write_detail(user, "user_lastvisit", int(lastlogin));
|
write_detail(user, "user_lastvisit", int(lastlogin));
|
||||||
|
|
|
@ -85,11 +85,11 @@ class fuh : public user_handler {
|
||||||
std::string get_mail(const std::string& user);
|
std::string get_mail(const std::string& user);
|
||||||
/*std::vector<std::string> get_friends(const std::string& user);
|
/*std::vector<std::string> get_friends(const std::string& user);
|
||||||
std::vector<std::string> get_ignores(const std::string& user);*/
|
std::vector<std::string> get_ignores(const std::string& user);*/
|
||||||
time_t get_lastlogin(const std::string& user);
|
std::time_t get_lastlogin(const std::string& user);
|
||||||
time_t get_registrationdate(const std::string& user);
|
std::time_t get_registrationdate(const std::string& user);
|
||||||
bool is_inactive(const std::string& user);
|
bool is_inactive(const std::string& user);
|
||||||
|
|
||||||
void set_lastlogin(const std::string& user, const time_t& lastlogin);
|
void set_lastlogin(const std::string& user, const std::time_t& lastlogin);
|
||||||
|
|
||||||
std::string db_name_, db_host_, db_user_, db_password_, db_users_table_, db_banlist_table_, db_extra_table_;
|
std::string db_name_, db_host_, db_user_, db_password_, db_users_table_, db_banlist_table_, db_extra_table_;
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ std::ostream& metrics::requests(std::ostream& out) const
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, metrics& met)
|
std::ostream& operator<<(std::ostream& out, metrics& met)
|
||||||
{
|
{
|
||||||
const time_t time_up = time(nullptr) - met.started_at_;
|
const std::time_t time_up = time(nullptr) - met.started_at_;
|
||||||
const int seconds = time_up%60;
|
const int seconds = time_up%60;
|
||||||
const int minutes = (time_up/60)%60;
|
const int minutes = (time_up/60)%60;
|
||||||
const int hours = (time_up/(60*60))%24;
|
const int hours = (time_up/(60*60))%24;
|
||||||
|
|
|
@ -72,7 +72,7 @@ private:
|
||||||
int current_requests_;
|
int current_requests_;
|
||||||
int nrequests_;
|
int nrequests_;
|
||||||
int nrequests_waited_;
|
int nrequests_waited_;
|
||||||
const time_t started_at_;
|
const std::time_t started_at_;
|
||||||
std::map<std::string,int> terminations_;
|
std::map<std::string,int> terminations_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ void wesnothd::player::mark_registered(bool registered)
|
||||||
|
|
||||||
bool wesnothd::player::is_message_flooding()
|
bool wesnothd::player::is_message_flooding()
|
||||||
{
|
{
|
||||||
const time_t now = time(nullptr);
|
const std::time_t now = time(nullptr);
|
||||||
if (flood_start_ == 0) {
|
if (flood_start_ == 0) {
|
||||||
flood_start_ = now;
|
flood_start_ = now;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -73,10 +73,10 @@ private:
|
||||||
|
|
||||||
bool registered_;
|
bool registered_;
|
||||||
|
|
||||||
time_t flood_start_;
|
std::time_t flood_start_;
|
||||||
unsigned int messages_since_flood_start_;
|
unsigned int messages_since_flood_start_;
|
||||||
const std::size_t MaxMessages;
|
const std::size_t MaxMessages;
|
||||||
const time_t TimePeriod;
|
const std::time_t TimePeriod;
|
||||||
STATUS status_;
|
STATUS status_;
|
||||||
bool moderator_;
|
bool moderator_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -119,7 +119,7 @@ void suh::set_realname(const std::string& user, const std::string& realname) {
|
||||||
// set_lastlogin() is not called by the server via set_user_detail()
|
// set_lastlogin() is not called by the server via set_user_detail()
|
||||||
// and thus must not throw user_handler::error
|
// and thus must not throw user_handler::error
|
||||||
|
|
||||||
void suh::set_lastlogin(const std::string& user, const time_t& lastlogin) {
|
void suh::set_lastlogin(const std::string& user, const std::time_t& lastlogin) {
|
||||||
users_[user].lastlogin = lastlogin;
|
users_[user].lastlogin = lastlogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,11 +137,11 @@ std::string suh::get_realname(const std::string& user) {
|
||||||
return users_[user].realname;
|
return users_[user].realname;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t suh::get_lastlogin(const std::string& user) {
|
std::time_t suh::get_lastlogin(const std::string& user) {
|
||||||
return users_[user].lastlogin;
|
return users_[user].lastlogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t suh::get_registrationdate(const std::string& user) {
|
std::time_t suh::get_registrationdate(const std::string& user) {
|
||||||
return users_[user].registrationdate;
|
return users_[user].registrationdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,11 +185,11 @@ void suh::clean_up() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t now = time(nullptr);
|
std::time_t now = time(nullptr);
|
||||||
|
|
||||||
//A minute has 60 seconds, an hour 60 minutes and
|
//A minute has 60 seconds, an hour 60 minutes and
|
||||||
//a day 24 hours.
|
//a day 24 hours.
|
||||||
time_t limit = user_expiration_ * 60 * 60 * 24;
|
std::time_t limit = user_expiration_ * 60 * 60 * 24;
|
||||||
|
|
||||||
std::vector<std::string> us = users();
|
std::vector<std::string> us = users();
|
||||||
for(std::vector<std::string>::const_iterator u = us.begin(); u != us.end(); ++u) {
|
for(std::vector<std::string>::const_iterator u = us.begin(); u != us.end(); ++u) {
|
||||||
|
@ -211,8 +211,8 @@ void suh::user_logged_in(const std::string& name) {
|
||||||
std::string suh::user_info(const std::string& name) {
|
std::string suh::user_info(const std::string& name) {
|
||||||
if(!user_exists(name)) throw error("No user with the name '" + name + "' exists.");
|
if(!user_exists(name)) throw error("No user with the name '" + name + "' exists.");
|
||||||
|
|
||||||
time_t reg_date = get_registrationdate(name);
|
std::time_t reg_date = get_registrationdate(name);
|
||||||
time_t ll_date = get_lastlogin(name);
|
std::time_t ll_date = get_lastlogin(name);
|
||||||
|
|
||||||
std::string reg_string = ctime(®_date);
|
std::string reg_string = ctime(®_date);
|
||||||
std::string ll_string;
|
std::string ll_string;
|
||||||
|
|
|
@ -58,8 +58,8 @@ class suh : public user_handler {
|
||||||
std::string password;
|
std::string password;
|
||||||
std::string realname;
|
std::string realname;
|
||||||
std::string mail;
|
std::string mail;
|
||||||
time_t lastlogin;
|
std::time_t lastlogin;
|
||||||
time_t registrationdate;
|
std::time_t registrationdate;
|
||||||
bool is_moderator;
|
bool is_moderator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ class suh : public user_handler {
|
||||||
std::string get_mail(const std::string& user);
|
std::string get_mail(const std::string& user);
|
||||||
std::string get_password(const std::string& user);
|
std::string get_password(const std::string& user);
|
||||||
std::string get_realname(const std::string& user) ;
|
std::string get_realname(const std::string& user) ;
|
||||||
time_t get_lastlogin(const std::string& user);
|
std::time_t get_lastlogin(const std::string& user);
|
||||||
time_t get_registrationdate(const std::string& user);
|
std::time_t get_registrationdate(const std::string& user);
|
||||||
|
|
||||||
void check_name(const std::string& name);
|
void check_name(const std::string& name);
|
||||||
void check_mail(const std::string& mail);
|
void check_mail(const std::string& mail);
|
||||||
|
@ -85,7 +85,7 @@ class suh : public user_handler {
|
||||||
void set_password(const std::string& user, const std::string& password);
|
void set_password(const std::string& user, const std::string& password);
|
||||||
void set_realname(const std::string& user, const std::string& realname);
|
void set_realname(const std::string& user, const std::string& realname);
|
||||||
|
|
||||||
void set_lastlogin(const std::string& user, const time_t& lastlogin);
|
void set_lastlogin(const std::string& user, const std::time_t& lastlogin);
|
||||||
|
|
||||||
int user_expiration_;
|
int user_expiration_;
|
||||||
|
|
||||||
|
|
|
@ -504,14 +504,14 @@ std::string server::is_ip_banned(const std::string& ip) {
|
||||||
return ban_manager_.is_ip_banned(ip);
|
return ban_manager_.is_ip_banned(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
void server::dump_stats(const time_t& now) {
|
void server::dump_stats(const std::time_t& now) {
|
||||||
last_stats_ = now;
|
last_stats_ = now;
|
||||||
LOG_SERVER << "Statistics:"
|
LOG_SERVER << "Statistics:"
|
||||||
<< "\tnumber_of_games = " << games().size()
|
<< "\tnumber_of_games = " << games().size()
|
||||||
<< "\tnumber_of_users = " << player_connections_.size() << "\n";
|
<< "\tnumber_of_users = " << player_connections_.size() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void server::clean_user_handler(const time_t& now) {
|
void server::clean_user_handler(const std::time_t& now) {
|
||||||
if(!user_handler_) {
|
if(!user_handler_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -782,7 +782,7 @@ bool server::authenticate(socket_ptr socket, const std::string& username, const
|
||||||
}
|
}
|
||||||
// This name is registered and an incorrect password provided
|
// This name is registered and an incorrect password provided
|
||||||
else if(!(user_handler_->login(username, password, seeds_[reinterpret_cast<unsigned long>(socket.get())]))) {
|
else if(!(user_handler_->login(username, password, seeds_[reinterpret_cast<unsigned long>(socket.get())]))) {
|
||||||
const time_t now = time(nullptr);
|
const std::time_t now = time(nullptr);
|
||||||
|
|
||||||
// Reset the random seed
|
// Reset the random seed
|
||||||
seeds_.erase(reinterpret_cast<unsigned long>(socket.get()));
|
seeds_.erase(reinterpret_cast<unsigned long>(socket.get()));
|
||||||
|
@ -1812,7 +1812,7 @@ void server::send_server_message_to_all(const std::string& message, socket_ptr e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t now = time(nullptr);
|
std::time_t now = time(nullptr);
|
||||||
if (last_ping_ + network::ping_interval <= now) {
|
if (last_ping_ + network::ping_interval <= now) {
|
||||||
if (lan_server_ && players_.empty() && last_user_seen_time_ + lan_server_ < now)
|
if (lan_server_ && players_.empty() && last_user_seen_time_ + lan_server_ < now)
|
||||||
{
|
{
|
||||||
|
@ -2432,7 +2432,7 @@ void server::ban_handler(const std::string& issuer_name, const std::string& /*qu
|
||||||
const std::string target(parameters.begin(), first_space);
|
const std::string target(parameters.begin(), first_space);
|
||||||
|
|
||||||
const std::string duration(first_space + 1, second_space);
|
const std::string duration(first_space + 1, second_space);
|
||||||
time_t parsed_time = time(nullptr);
|
std::time_t parsed_time = time(nullptr);
|
||||||
if (ban_manager_.parse_time(duration, &parsed_time) == false) {
|
if (ban_manager_.parse_time(duration, &parsed_time) == false) {
|
||||||
*out << "Failed to parse the ban duration: '" << duration << "'\n"
|
*out << "Failed to parse the ban duration: '" << duration << "'\n"
|
||||||
<< ban_manager_.get_ban_help();
|
<< ban_manager_.get_ban_help();
|
||||||
|
@ -2500,7 +2500,7 @@ void server::kickban_handler(const std::string& issuer_name, const std::string&
|
||||||
std::string::iterator second_space = std::find(first_space + 1, parameters.end(), ' ');
|
std::string::iterator second_space = std::find(first_space + 1, parameters.end(), ' ');
|
||||||
const std::string target(parameters.begin(), first_space);
|
const std::string target(parameters.begin(), first_space);
|
||||||
const std::string duration(first_space + 1, second_space);
|
const std::string duration(first_space + 1, second_space);
|
||||||
time_t parsed_time = time(nullptr);
|
std::time_t parsed_time = time(nullptr);
|
||||||
if (ban_manager_.parse_time(duration, &parsed_time) == false) {
|
if (ban_manager_.parse_time(duration, &parsed_time) == false) {
|
||||||
*out << "Failed to parse the ban duration: '" << duration << "'\n"
|
*out << "Failed to parse the ban duration: '" << duration << "'\n"
|
||||||
<< ban_manager_.get_ban_help();
|
<< ban_manager_.get_ban_help();
|
||||||
|
@ -2589,7 +2589,7 @@ void server::gban_handler(const std::string& issuer_name, const std::string& /*q
|
||||||
second_space = std::find(first_space + 1, parameters.end(), ' ');
|
second_space = std::find(first_space + 1, parameters.end(), ' ');
|
||||||
|
|
||||||
const std::string duration(first_space + 1, second_space);
|
const std::string duration(first_space + 1, second_space);
|
||||||
time_t parsed_time = time(nullptr);
|
std::time_t parsed_time = time(nullptr);
|
||||||
if (ban_manager_.parse_time(duration, &parsed_time) == false) {
|
if (ban_manager_.parse_time(duration, &parsed_time) == false) {
|
||||||
*out << "Failed to parse the ban duration: '" << duration << "'\n"
|
*out << "Failed to parse the ban duration: '" << duration << "'\n"
|
||||||
<< ban_manager_.get_ban_help();
|
<< ban_manager_.get_ban_help();
|
||||||
|
|
|
@ -74,10 +74,10 @@ private:
|
||||||
wesnothd::ban_manager ban_manager_;
|
wesnothd::ban_manager ban_manager_;
|
||||||
|
|
||||||
struct connection_log {
|
struct connection_log {
|
||||||
connection_log(std::string _nick, std::string _ip, time_t _log_off) :
|
connection_log(std::string _nick, std::string _ip, std::time_t _log_off) :
|
||||||
nick(_nick), ip(_ip), log_off(_log_off) {}
|
nick(_nick), ip(_ip), log_off(_log_off) {}
|
||||||
std::string nick, ip;
|
std::string nick, ip;
|
||||||
time_t log_off;
|
std::time_t log_off;
|
||||||
|
|
||||||
bool operator==(const connection_log& c) const
|
bool operator==(const connection_log& c) const
|
||||||
{
|
{
|
||||||
|
@ -89,11 +89,11 @@ private:
|
||||||
std::deque<connection_log> ip_log_;
|
std::deque<connection_log> ip_log_;
|
||||||
|
|
||||||
struct login_log {
|
struct login_log {
|
||||||
login_log(std::string _ip, int _attempts, time_t _first_attempt) :
|
login_log(std::string _ip, int _attempts, std::time_t _first_attempt) :
|
||||||
ip(_ip), attempts(_attempts), first_attempt(_first_attempt) {}
|
ip(_ip), attempts(_attempts), first_attempt(_first_attempt) {}
|
||||||
std::string ip;
|
std::string ip;
|
||||||
int attempts;
|
int attempts;
|
||||||
time_t first_attempt;
|
std::time_t first_attempt;
|
||||||
|
|
||||||
bool operator==(const login_log& l) const
|
bool operator==(const login_log& l) const
|
||||||
{
|
{
|
||||||
|
@ -140,8 +140,8 @@ private:
|
||||||
std::size_t default_time_period_;
|
std::size_t default_time_period_;
|
||||||
std::size_t concurrent_connections_;
|
std::size_t concurrent_connections_;
|
||||||
bool graceful_restart;
|
bool graceful_restart;
|
||||||
time_t lan_server_;
|
std::time_t lan_server_;
|
||||||
time_t last_user_seen_time_;
|
std::time_t last_user_seen_time_;
|
||||||
std::string restart_command;
|
std::string restart_command;
|
||||||
std::size_t max_ip_log_size_;
|
std::size_t max_ip_log_size_;
|
||||||
std::string uh_name_;
|
std::string uh_name_;
|
||||||
|
@ -151,7 +151,7 @@ private:
|
||||||
bool allow_remote_shutdown_;
|
bool allow_remote_shutdown_;
|
||||||
std::vector<std::string> tor_ip_list_;
|
std::vector<std::string> tor_ip_list_;
|
||||||
int failed_login_limit_;
|
int failed_login_limit_;
|
||||||
time_t failed_login_ban_;
|
std::time_t failed_login_ban_;
|
||||||
std::deque<login_log>::size_type failed_login_buffer_size_;
|
std::deque<login_log>::size_type failed_login_buffer_size_;
|
||||||
|
|
||||||
/** Parse the server config into local variables. */
|
/** Parse the server config into local variables. */
|
||||||
|
@ -167,12 +167,12 @@ private:
|
||||||
|
|
||||||
metrics metrics_;
|
metrics metrics_;
|
||||||
|
|
||||||
time_t last_ping_;
|
std::time_t last_ping_;
|
||||||
time_t last_stats_;
|
std::time_t last_stats_;
|
||||||
void dump_stats(const time_t& now);
|
void dump_stats(const std::time_t& now);
|
||||||
|
|
||||||
time_t last_uh_clean_;
|
std::time_t last_uh_clean_;
|
||||||
void clean_user_handler(const time_t& now);
|
void clean_user_handler(const std::time_t& now);
|
||||||
|
|
||||||
/** Process commands from admins and users. */
|
/** Process commands from admins and users. */
|
||||||
std::string process_command(std::string cmd, std::string issuer_name);
|
std::string process_command(std::string cmd, std::string issuer_name);
|
||||||
|
|
|
@ -868,7 +868,7 @@ struct dialog_tester<mp_lobby>
|
||||||
};
|
};
|
||||||
|
|
||||||
class fake_chat_handler : public events::chat_handler {
|
class fake_chat_handler : public events::chat_handler {
|
||||||
void add_chat_message(const time_t&,
|
void add_chat_message(const std::time_t&,
|
||||||
const std::string&, int, const std::string&,
|
const std::string&, int, const std::string&,
|
||||||
MESSAGE_TYPE) {}
|
MESSAGE_TYPE) {}
|
||||||
void send_chat_message(const std::string&, bool) {}
|
void send_chat_message(const std::string&, bool) {}
|
||||||
|
|
|
@ -91,7 +91,7 @@
|
||||||
#include <clocale> // for setlocale, LC_ALL, etc
|
#include <clocale> // for setlocale, LC_ALL, etc
|
||||||
#include <cstdio> // for remove, fprintf, stderr
|
#include <cstdio> // for remove, fprintf, stderr
|
||||||
#include <cstdlib> // for srand, exit
|
#include <cstdlib> // for srand, exit
|
||||||
#include <ctime> // for time, ctime, time_t
|
#include <ctime> // for time, ctime, std::time_t
|
||||||
#include <exception> // for exception
|
#include <exception> // for exception
|
||||||
#include <fstream> // for operator<<, basic_ostream, etc
|
#include <fstream> // for operator<<, basic_ostream, etc
|
||||||
#include <iostream> // for cerr, cout
|
#include <iostream> // for cerr, cout
|
||||||
|
@ -1033,7 +1033,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::cerr << "Battle for Wesnoth v" << game_config::revision << '\n';
|
std::cerr << "Battle for Wesnoth v" << game_config::revision << '\n';
|
||||||
const time_t t = time(nullptr);
|
const std::time_t t = time(nullptr);
|
||||||
std::cerr << "Started on " << ctime(&t) << "\n";
|
std::cerr << "Started on " << ctime(&t) << "\n";
|
||||||
|
|
||||||
const std::string& exe_dir = filesystem::get_exe_dir();
|
const std::string& exe_dir = filesystem::get_exe_dir();
|
||||||
|
|
Loading…
Add table
Reference in a new issue