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; 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) { void MainProgram::new_tab(const World::OpenWorldInfo& tabInfo, bool createSameThread) {
newTabToOpenInfo = tabInfo; newTabToOpenInfo = tabInfo;
if(createSameThread) if(createSameThread)

View file

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

View file

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

View file

@ -16,5 +16,6 @@ class MainServer {
World& world; World& world;
void ensure_display_name_unique(std::string& displayName); void ensure_display_name_unique(std::string& displayName);
ServerData data; ServerData data;
std::string fileDisplayName;
std::chrono::steady_clock::time_point lastKeepAliveSent; 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("useNativeFilePicker").get_to(useNativeFilePicker);
j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded); j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded);
j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth); j.at("velocityAffectsBrushWidth").get_to(velocityAffectsBrushWidth);
main.update_display_names();
} }
void Toolbar::update() { void Toolbar::update() {
@ -1121,7 +1123,8 @@ void Toolbar::options_menu() {
switch(generalSettingsOptions) { switch(generalSettingsOptions) {
case GSETTINGS_GENERAL: { case GSETTINGS_GENERAL: {
gui.input_text_field("display name input", "Display Name", &main.displayName); 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__ #ifndef __EMSCRIPTEN__
gui.checkbox_field("native file pick", "Use Native File Picker", &useNativeFilePicker); gui.checkbox_field("native file pick", "Use Native File Picker", &useNativeFilePicker);
#endif #endif

View file

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