Skip to content

Commit

Permalink
FIX: number of players online in chat window now correct (and also sh…
Browse files Browse the repository at this point in the history
…owing offline state)

git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11305 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Jun 22, 2024
1 parent 04af624 commit d261851
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions simutrans/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions src/base.tab
Original file line number Diff line number Diff line change
Expand Up @@ -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
--
Expand Down
14 changes: 5 additions & 9 deletions src/simutrans/gui/chat_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
28 changes: 28 additions & 0 deletions src/simutrans/simmesg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -352,6 +365,8 @@ void message_t::rdwr(loadsave_t* file)
}




chat_message_t::~chat_message_t()
{
clear();
Expand Down Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions src/simutrans/simmesg.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class message_t
class chat_message_t
{
public:

class chat_node {
public:
char msg[256];
Expand Down Expand Up @@ -128,6 +129,8 @@ class chat_message_t
chat_message_t() {};
~chat_message_t();

static uint8 get_online_players();

private:
slist_tpl<chat_node*> list;

Expand Down

0 comments on commit d261851

Please sign in to comment.