diff --git a/src/MainProgram.cpp b/src/MainProgram.cpp index cfab56a..5282138 100755 --- a/src/MainProgram.cpp +++ b/src/MainProgram.cpp @@ -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) diff --git a/src/MainProgram.hpp b/src/MainProgram.hpp index 353bec0..292472f 100644 --- a/src/MainProgram.hpp +++ b/src/MainProgram.hpp @@ -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(); diff --git a/src/Server/MainServer.cpp b/src/Server/MainServer.cpp index 3b9dd4f..30f6909 100644 --- a/src/Server/MainServer.cpp +++ b/src/Server/MainServer.cpp @@ -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(1, std::numeric_limits::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); } diff --git a/src/Server/MainServer.hpp b/src/Server/MainServer.hpp index 6ec482f..fc9a80e 100644 --- a/src/Server/MainServer.hpp +++ b/src/Server/MainServer.hpp @@ -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; }; diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index d139c3e..f1acd14 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -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 diff --git a/src/World.cpp b/src/World.cpp index 019f3f7..9b772e8 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -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); } });