diff options
| author | Salanto <62221668+Salanto@users.noreply.github.com> | 2022-06-06 10:14:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-06 19:14:44 +0200 |
| commit | f0a5e48f5ca6834c0f24b167c904a030894f706e (patch) | |
| tree | 0e7ae1497d0164e3a1a3c1d61a88e4f719beb5b5 /src/text_file_functions.cpp | |
| parent | c4f459b6cce6382cbd7c1960a6738a5a8a45ab8c (diff) | |
Dual-Stack AO2 Client to handle both TCP and Websocket connections seemlessly (#696)
* Replace TCP Serversocket with Websocket
* Have TCP sockets live harmoniously with WS
"like 5 lines" yeah probably lost a bet.
* Update .gitlab-ci.yml
* hack to fix favorites
* Add support for websockets in the favorites list (serverlist.txt)
Make "add_favorite_server" remember the socket type
* Preserve old serverlist style
This will keep new entries compatible with 2.9 and prior clients. Makes parsing the list easier too.
* Add lookup table and correct write code to use lowercase
* I have no idea what a lookup table is, but this looks close enough
* Fix lookup table
* Otherwise backend selection behaviour is inverted
* clang-tidy had one job
* Yet it did not do it.
Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
* const p_data
* Switch serverlist.txt to an ini format
* Fixes an Omni bug where : would split the servername
* Utilises internally QSettings properly for low parsing effort and clear structure
* Automatically migrates the legacy serverlist.txt to favorite_servers.ini
* Pleases my OCD
* Replace sample serverlist.
Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
Co-authored-by: stonedDiscord <Tukz@gmx.de>
Co-authored-by: Alex Noir <Varsash@gmail.com>
Diffstat (limited to 'src/text_file_functions.cpp')
| -rw-r--r-- | src/text_file_functions.cpp | 95 |
1 files changed, 55 insertions, 40 deletions
diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index b5bd6968..0dde68f6 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -236,52 +236,30 @@ bool AOApplication::append_to_file(QString p_text, QString p_file, return false; } -void AOApplication::write_to_serverlist_txt(QString p_line) -{ - QFile serverlist_txt; - QString serverlist_txt_path = get_base_path() + "serverlist.txt"; - - serverlist_txt.setFileName(serverlist_txt_path); - - if (!serverlist_txt.open(QIODevice::WriteOnly | QIODevice::Append)) { - return; - } - - QTextStream out(&serverlist_txt); - out.setCodec("UTF-8"); - out << "\r\n" << p_line; - - serverlist_txt.close(); -} - QVector<server_type> AOApplication::read_serverlist_txt() { QVector<server_type> f_server_list; - QFile serverlist_txt; - QString serverlist_txt_path = get_base_path() + "serverlist.txt"; - - serverlist_txt.setFileName(serverlist_txt_path); - - if (serverlist_txt.open(QIODevice::ReadOnly)) { - QTextStream in(&serverlist_txt); - in.setCodec("UTF-8"); + QFile serverlist_txt(get_base_path() + "serverlist.txt"); + QFile serverlist_ini(get_base_path() + "favorite_servers.ini"); - while (!in.atEnd()) { - QString line = in.readLine(); - server_type f_server; - QStringList line_contents = line.split(":"); - - if (line_contents.size() < 3) - continue; - - f_server.ip = line_contents.at(0); - f_server.port = line_contents.at(1).toInt(); - f_server.name = line_contents.at(2); - f_server.desc = ""; + if (serverlist_txt.exists() && !serverlist_ini.exists()) { + migrate_serverlist_txt(serverlist_txt); + } - f_server_list.append(f_server); - } + if (serverlist_ini.exists()) { + QSettings l_favorite_ini(get_base_path() + "favorite_servers.ini", QSettings::IniFormat); + l_favorite_ini.setIniCodec("UTF-8"); + for(QString &fav_index: l_favorite_ini.childGroups()) { + server_type f_server; + l_favorite_ini.beginGroup(fav_index); + f_server.ip = l_favorite_ini.value("address", "127.0.0.1").toString(); + f_server.port = l_favorite_ini.value("port", 27016).toInt(); + f_server.name = l_favorite_ini.value("name", "Missing Name").toString(); + f_server.socket_type = to_connection_type.value(l_favorite_ini.value("protocol", "tcp").toString()); + f_server_list.append(f_server); + l_favorite_ini.endGroup(); + } } server_type demo_server; @@ -294,6 +272,43 @@ QVector<server_type> AOApplication::read_serverlist_txt() return f_server_list; } +void AOApplication::migrate_serverlist_txt(QFile &p_serverlist_txt) +{ + // We migrate our legacy serverlist.txt to a QSettings object. + // Then we write it to disk. + QSettings l_settings(get_base_path() + "favorite_servers.ini", QSettings::IniFormat); + l_settings.setIniCodec("UTF-8"); + if (p_serverlist_txt.open(QIODevice::ReadOnly)) { + QTextStream l_favorite_textstream(&p_serverlist_txt); + l_favorite_textstream.setCodec("UTF-8"); + int l_entry_index = 0; + + while (!l_favorite_textstream.atEnd()) { + QString l_favorite_line = l_favorite_textstream.readLine(); + QStringList l_line_contents = l_favorite_line.split(":"); + + if (l_line_contents.size() >= 3) { + l_settings.beginGroup(QString::number(l_entry_index)); + l_settings.setValue("name", l_line_contents.at(2)); + l_settings.setValue("address", l_line_contents.at(0)); + l_settings.setValue("port", l_line_contents.at(1)); + + if (l_line_contents.size() >= 4) { + l_settings.setValue("protocol", l_line_contents.at(3)); + } + else { + l_settings.setValue("protocol","tcp"); + } + l_settings.endGroup(); + l_entry_index++; + } + } + l_settings.sync(); + } + p_serverlist_txt.close(); + p_serverlist_txt.rename(get_base_path() + "serverlist_depricated.txt"); +} + QString AOApplication::read_design_ini(QString p_identifier, VPath p_design_path) { |
