From 5b62f29942471f264aa55bee959c3d21394f210b Mon Sep 17 00:00:00 2001 From: Jari van der Kaap Date: Thu, 13 Apr 2023 22:13:05 +0200 Subject: [PATCH] changed favorites file to txt file --- src/client/component/server_list.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/client/component/server_list.cpp b/src/client/component/server_list.cpp index ebca233a..386ee761 100644 --- a/src/client/component/server_list.cpp +++ b/src/client/component/server_list.cpp @@ -93,7 +93,7 @@ namespace server_list std::string get_favorite_servers_file_path() { - return "players/user/favorite_servers.csv"; + return "players/user/favorite_servers.txt"; } void write_favorite_servers() @@ -101,12 +101,7 @@ namespace server_list std::string servers_buffer = ""; for (auto itr : favorite_servers) { - servers_buffer.append(utils::string::va("%u,%u\n", itr.addr, itr.port)); - } - - if (servers_buffer.empty()) - { - return; + servers_buffer.append(utils::string::va("%i.%i.%i.%i:%u\n", itr.ipv4.a, itr.ipv4.b, itr.ipv4.c, itr.ipv4.d, itr.port)); } utils::io::write_file(get_favorite_servers_file_path(), servers_buffer); @@ -126,12 +121,9 @@ namespace server_list if (utils::io::read_file(path, &filedata)) { auto servers = utils::string::split(filedata, '\n'); - for (auto server_data : servers) + for (auto server_address : servers) { - auto data = utils::string::split(server_data, ','); - auto addr = std::stoul(data[0].c_str()); - auto port = (uint16_t)atoi(data[1].c_str()); - auto server = network::address_from_ip(addr, port); + auto server = network::address_from_string(server_address); favorite_servers.push_back(server); } } @@ -229,7 +221,10 @@ namespace server_list lua_serverinfo_to_table_hook.create(0x141F1FD10_g, lua_serverinfo_to_table_stub); - read_favorite_servers(); + scheduler::loop([] + { + read_favorite_servers(); + }, scheduler::main); } void pre_destroy() override