Modified timestamps

Modified the previous commit after discussing it with Soliton. We agreed
on sending timestamps to other players and using them [received timestamps]
in displaying time of chat messages, with fallback on using local time if
received message doesn't contain timestamp (old version of wesnoth).

This fixes several issues:
1) When viewing replays the time would be the one of the actual game
insted of the time of viewing the replay;
2) Previously, when opening some dialog while players send messages and
then closing it — chat messages would have timestamp of when the dialog
windows was closed, not the time when messages were sent.

This also introduces one new issue:
1) If player has time set up incorrectly, the timestamp that other players
will recieve will show incorrect time.
For example, when instead of setting to the right timezone player just
adjusted system time by adding or subtracting hours with incorrect
timezone selected.
This commit is contained in:
nurupo 2013-05-04 13:40:04 -04:00 committed by Maxim Biro
parent f79eae27e1
commit 7afab08eb7
2 changed files with 18 additions and 11 deletions

View file

@ -117,14 +117,6 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg
preferences::message_bell()); preferences::message_bell());
} }
if (cfg.has_child("turn") && cfg.child("turn").has_child("command") &&
cfg.child("turn").child("command").has_child("speak")) {
config& msg = const_cast<config&>(cfg).child("turn").child("command").child("speak");
const time_t time_ = time(NULL);
std::stringstream ss;
ss << time_;
msg["time"] = ss.str();
}
if (const config &msg = cfg.child("whisper") /*&& is_observer()*/) if (const config &msg = cfg.child("whisper") /*&& is_observer()*/)
{ {
resources::screen->add_chat_message(time(NULL), "whisper: " + msg["sender"].str(), 0, resources::screen->add_chat_message(time(NULL), "whisper: " + msg["sender"].str(), 0,

View file

@ -125,6 +125,22 @@ 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)
{
time_t time;
if (!speak["time"].empty())
{
std::stringstream ss(speak["time"].str());
ss >> time;
}
else
{
//fallback in case sender uses wesnoth that doesn't send timestamps
time = ::time(NULL);
}
return time;
}
// FIXME: this one now has to be assigned with set_random_generator // FIXME: this one now has to be assigned with set_random_generator
// from play_level or similar. We should surely hunt direct // from play_level or similar. We should surely hunt direct
// references to it from this very file and move it out of here. // references to it from this very file and move it out of here.
@ -149,8 +165,7 @@ chat_msg::chat_msg(const config &cfg)
} else { } else {
color_ = team::get_side_highlight_pango(side-1); color_ = team::get_side_highlight_pango(side-1);
} }
std::stringstream ss(cfg["time"].str()); time_ = get_time(cfg);
ss >> time_;
/* /*
} else if (side==1) { } else if (side==1) {
color_ = "red"; color_ = "red";
@ -939,7 +954,7 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
get_replay_source().add_chat_message_location(); get_replay_source().add_chat_message_location();
if (!get_replay_source().is_skipping() || is_whisper) { if (!get_replay_source().is_skipping() || is_whisper) {
int side = child["side"]; int side = child["side"];
resources::screen->add_chat_message(time(NULL), speaker_name, side, message, resources::screen->add_chat_message(get_time(child), speaker_name, side, message,
(team_name.empty() ? events::chat_handler::MESSAGE_PUBLIC (team_name.empty() ? events::chat_handler::MESSAGE_PUBLIC
: events::chat_handler::MESSAGE_PRIVATE), : events::chat_handler::MESSAGE_PRIVATE),
preferences::message_bell()); preferences::message_bell());