diff --git a/simutrans/history.txt b/simutrans/history.txt index bd5714e02b..49cd0c890c 100644 --- a/simutrans/history.txt +++ b/simutrans/history.txt @@ -6,6 +6,7 @@ CHG: Allow again building roads through other people halts but do not take road ownership afterwards FIX: Always have topped or new windows on the screen FIX: Saving discarded the newest messages + FIX: number of players online in chat window now correct (and also showing offline state) Release of 124.1 (r11272 on 3-June-2024): diff --git a/src/base.tab b/src/base.tab index 40e74400ee..2c5a88f614 100644 --- a/src/base.tab +++ b/src/base.tab @@ -4413,6 +4413,10 @@ obj=program_text name=Click to open the finance dialog. note=player ranking window -- +obj=program_text +name=Not online +note=message when offline in chat window +-- diff --git a/src/simutrans/gui/chat_frame.cc b/src/simutrans/gui/chat_frame.cc index 5d82f99e04..f4d39f5731 100644 --- a/src/simutrans/gui/chat_frame.cc +++ b/src/simutrans/gui/chat_frame.cc @@ -13,7 +13,6 @@ #include "../dataobj/translator.h" #include "../dataobj/environment.h" -#include "../dataobj/gameinfo.h" #include "../network/network_cmd_ingame.h" #include "../player/simplay.h" #include "../display/viewport.h" @@ -203,7 +202,6 @@ class gui_chat_balloon_t : scr_size get_min_size() const OVERRIDE { return scr_size(100 + lb_time_diff.get_size().w, message.get_min_size().h + 4 + D_V_SPACE + lb_time_diff.get_size().h); -// return scr_size(100 + lb_time_diff.get_size().w, size.h); } scr_size get_max_size() const OVERRIDE @@ -381,11 +379,6 @@ void chat_frame_t::fill_list() player_t* current_player = world()->get_active_player(); const scr_coord_val width = get_windowsize().w; - gameinfo_t gi(world()); - - lb_now_online.buf().printf(translator::translate("%u Client(s)\n"), (unsigned)gi.get_clients()); - lb_now_online.update(); - old_player_nr = current_player->get_player_nr(); cont_chat_log[chat_mode].clear_elements(); @@ -407,8 +400,8 @@ void chat_frame_t::fill_list() // no permission but visible messages you sent continue; } - break; + case CH_WHISPER: if (i->destination == NULL || i->sender == NULL) { continue; @@ -431,8 +424,8 @@ void chat_frame_t::fill_list() if (strcmp(env_t::nickname.c_str(), i->sender.c_str())) { chat_history.append_unique(i->sender); } - break; + default: case CH_PUBLIC: // system message and public chats @@ -560,6 +553,9 @@ bool chat_frame_t::action_triggered(gui_action_creator_t* comp, value_t) void chat_frame_t::draw(scr_coord pos, scr_size size) { + lb_now_online.buf().printf(translator::translate(env_t::networkmode ? "%u Client(s)\n" : "Not online"), chat_message_t::get_online_players()); + lb_now_online.update(); + if (welt->get_chat_message()->get_list().get_count() != last_count || old_player_nr != world()->get_active_player_nr()) { fill_list(); } diff --git a/src/simutrans/simmesg.cc b/src/simutrans/simmesg.cc index 342cbe8182..137b5cb3d9 100644 --- a/src/simutrans/simmesg.cc +++ b/src/simutrans/simmesg.cc @@ -13,8 +13,10 @@ #include "world/simworld.h" #include "dataobj/loadsave.h" +#include "dataobj/translator.h" #include "dataobj/environment.h" #include "dataobj/pakset_manager.h" +#include "network/network_socket_list.h" #include "player/simplay.h" #include "utils/simstring.h" #include "tpl/slist_tpl.h" @@ -28,6 +30,10 @@ static karte_ptr_t welt; +uint8 clients_active = 0; +const char *player_count; +size_t player_count_lenght; + uint32 message_node_t::get_type_shifted() const { return 1<<(type & message_t::MESSAGE_TYPE_MASK); @@ -127,6 +133,8 @@ void message_t::clear() delete list.remove_first(); } ticker::clear_messages(); + player_count = translator::translate("Now %u clients connected.", world()->get_settings().get_name_language_id()); + player_count_lenght = strchr(player_count, '%') - player_count; } @@ -162,6 +170,11 @@ void message_t::add_message(const char *text, koord3d pos, uint16 what_flags, FL { DBG_MESSAGE("message_t::add_msg()","%40s (at %i,%i,%i)", text, pos.x, pos.y, pos.z ); + // hacky, retrieve the number of clients for the last messages + if (strncmp(text, player_count, player_count_lenght) == 0) { + clients_active = atoi(text + player_count_lenght); + } + sint32 what_bit = 1<<(what_flags & MESSAGE_TYPE_MASK); if( what_bit&ignore_flags ) { // wants us to ignore this completely @@ -352,6 +365,8 @@ void message_t::rdwr(loadsave_t* file) } + + chat_message_t::~chat_message_t() { clear(); @@ -498,3 +513,16 @@ void chat_message_t::rdwr(loadsave_t* file) } } } + + +// return the number of connected clients +uint8 chat_message_t::get_online_players() +{ + if (env_t::server) { + return socket_list_t::get_playing_clients(); + } + else if (env_t::networkmode) { + return clients_active; + } + return 0; +} diff --git a/src/simutrans/simmesg.h b/src/simutrans/simmesg.h index 01f7f35b3a..ce0a646bde 100644 --- a/src/simutrans/simmesg.h +++ b/src/simutrans/simmesg.h @@ -101,6 +101,7 @@ class message_t class chat_message_t { public: + class chat_node { public: char msg[256]; @@ -128,6 +129,8 @@ class chat_message_t chat_message_t() {}; ~chat_message_t(); + static uint8 get_online_players(); + private: slist_tpl list;