Fixed multiple display name issues

This commit is contained in:
Yousef Khadadeh 2025-07-08 12:18:55 +03:00
parent a004ec40f9
commit 9aafb63dc0
6 changed files with 22 additions and 5 deletions

View file

@ -148,6 +148,13 @@ void MainProgram::update() {
return;
}
void MainProgram::update_display_names() {
for(auto& w : worlds) {
if(!w->network_being_used())
w->displayName = displayName;
}
}
void MainProgram::new_tab(const World::OpenWorldInfo& tabInfo, bool createSameThread) {
newTabToOpenInfo = tabInfo;
if(createSameThread)

View file

@ -100,6 +100,7 @@ class MainProgram {
void set_tab_to_close(size_t tabToClose);
bool network_being_used();
bool net_server_hosted();
void update_display_names();
void save_config();
void load_config();

View file

@ -81,6 +81,9 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
message(newClient.displayName, isDirectConnect);
ensure_display_name_unique(newClient.displayName);
if(isDirectConnect)
fileDisplayName = newClient.displayName;
newClient.id.first = Random::get().int_range<ServerPortionID>(1, std::numeric_limits<ServerPortionID>::max());
client.customID = newClient.id.first;
newClient.id.second = data.get_max_id(newClient.id.first);
@ -88,7 +91,7 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
if(isDirectConnect)
netServer->send_items_to_client(client, RELIABLE_COMMAND_CHANNEL, CLIENT_INITIAL_DATA, isDirectConnect, newClient.id.first, newClient.cursorColor);
else {
netServer->send_items_to_client(client, RELIABLE_COMMAND_CHANNEL, CLIENT_INITIAL_DATA, isDirectConnect, newClient.id.first, newClient.cursorColor, newClient.displayName, clients, data);
netServer->send_items_to_client(client, RELIABLE_COMMAND_CHANNEL, CLIENT_INITIAL_DATA, isDirectConnect, newClient.id.first, newClient.cursorColor, newClient.displayName, fileDisplayName, clients, data);
for(auto& [id, rData] : data.resources)
netServer->send_items_to_client(client, RESOURCE_COMMAND_CHANNEL, CLIENT_NEW_RESOURCE, id, rData);
}

View file

@ -16,5 +16,6 @@ class MainServer {
World& world;
void ensure_display_name_unique(std::string& displayName);
ServerData data;
std::string fileDisplayName;
std::chrono::steady_clock::time_point lastKeepAliveSent;
};

View file

@ -259,6 +259,8 @@ void Toolbar::set_config_json(const nlohmann::json& j) {
j.at("useNativeFilePicker").get_to(useNativeFilePicker);
j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded);
j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth);
main.update_display_names();
}
void Toolbar::update() {
@ -1121,7 +1123,8 @@ void Toolbar::options_menu() {
switch(generalSettingsOptions) {
case GSETTINGS_GENERAL: {
gui.input_text_field("display name input", "Display Name", &main.displayName);
gui.text_label("Note: Changes in display name dont affect canvas that is currently open");
main.update_display_names();
gui.text_label("Note: Changes in display name dont affect canvases that are connected online");
#ifndef __EMSCRIPTEN__
gui.checkbox_field("native file pick", "Use Native File Picker", &useNativeFilePicker);
#endif

View file

@ -69,7 +69,9 @@ void World::init_client_callbacks() {
bool isDirectConnect;
message(isDirectConnect, ownID, userColor);
if(!isDirectConnect) {
message(displayName, clients);
std::string fileDisplayName;
message(displayName, fileDisplayName, clients);
set_name(fileDisplayName);
drawProg.initialize_draw_data(message);
message(bMan);
}
@ -83,14 +85,14 @@ void World::init_client_callbacks() {
message(id, displayName, cursorColor);
clients[id].displayName = displayName;
clients[id].cursorColor = cursorColor;
add_chat_message(displayName + " joined", Toolbar::ChatMessage::COLOR_JOIN);
add_chat_message(clients[id].displayName + " joined", Toolbar::ChatMessage::COLOR_JOIN);
});
con.client_add_recv_callback(CLIENT_USER_DISCONNECT, [&](cereal::PortableBinaryInputArchive& message) {
ServerPortionID id;
message(id);
auto it = clients.find(id);
if(it != clients.end()) {
add_chat_message(displayName + " left", Toolbar::ChatMessage::COLOR_JOIN);
add_chat_message(clients[id].displayName + " left", Toolbar::ChatMessage::COLOR_JOIN);
clients.erase(id);
}
});