Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dual-Stack AO2 Client to handle both TCP and Websocket connections seemlessly #696

Merged
merged 15 commits into from
Jun 6, 2022

Conversation

Salanto
Copy link
Contributor

@Salanto Salanto commented Mar 23, 2022

Is this a breaking change? Depends on how you view it.

If you intentionally sabotaged WebAO usage on your server by either limiting what Clients can join trough the websocket or just disabled them, this PR would break any connectivity we would have to that server till they either update or reenable websockets.

The replacement is a nice-to-have, as it finally removes the need for two ports and different connection medias between the regular AO2-Client and WebAO, giving new servers less of a headache implementing both and allowing already existing servers to streamline their connection code.

Closes #739

@stonedDiscord
Copy link
Member

you can still sabotage webAO by using the version check packet

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -27,10 +27,10 @@ class NetworkManager : public QObject {

AOApplication *ao_app;
QNetworkAccessManager *http;
QTcpSocket *server_socket;
QWebSocket *server_socket;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'server_socket' has public visibility [misc-non-private-member-variables-in-classes]

  QWebSocket *server_socket;
              ^

QTimer *heartbeat_timer;

const QString DEFAULT_MS_BASEURL = "https://servers.aceattorneyonline.com";
const QString DEFAULT_MS_BASEURL = "http://servers.aceattorneyonline.com";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable 'DEFAULT_MS_BASEURL' has public visibility [misc-non-private-member-variables-in-classes]

  const QString DEFAULT_MS_BASEURL = "http://servers.aceattorneyonline.com";
                ^

}

void NetworkManager::handle_server_packet()
void NetworkManager::handle_server_packet(QString p_data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: the parameter 'p_data' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
void NetworkManager::handle_server_packet(QString p_data)
void NetworkManager::handle_server_packet(const QString& p_data)

include/networkmanager.h:47:

-   void handle_server_packet(QString p_data);
+   void handle_server_packet(const QString& p_data);

@Salanto
Copy link
Contributor Author

Salanto commented Mar 23, 2022

Yeah, but at that point is it even worth it anymore? Just allow WebAO, its not harmful.

@Crystalwarrior
Copy link
Contributor

Do not remove tcp support or no one will update because their favorite server breaks or they can't play with friends who are not technically inclined.

Instead make it connect by websockets first, and if it fails fall back to tcp. Add settings that allow you to disable tcp entirely, and make it off by default.

@Salanto
Copy link
Contributor Author

Salanto commented Mar 23, 2022

Do not remove TCP support or no one will update because their favourite server breaks or they can't play with friends who are not technically inclined.

Instead make it connect by WebSockets first, and if it fails fall back to TCP. Add settings that allow you to disable TCP entirely, and make it off by default.

Literally what? Name me one of the popular servers that is not CaseCafe or DRO, which has no Websocket support in general and their mostly unique client, that don't have websocket support. This is no harder to set up on the server owner as all major derivatives and servers have WebSocket support which is turned on with a single config change.

Adding Websockets as an addition to TCP only adds more clutter to the AOClient with no tangible benefit besides "we backwards compatible because reasons."

It already filters for websocket enabled servers so there is no "oh no, can't connect to this server on master" moment.

Copy link
Member

@oldmud0 oldmud0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

staying compatible with legacy tcp is like 5 lines. i will prove it to you

there are a number of servers that don't have ws forwarded properly or don't want to allow webao for whatever reason. They would not be prepared for this otherwise major change

@Salanto
Copy link
Contributor Author

Salanto commented Mar 23, 2022

In the end I can't stop you from doing so, but the endless nemesis of legacy support will eventually make this project less maintainable than it already is, but a long term goal should be to prefer Websocket over TCP and phase the later out.

@Crystalwarrior Crystalwarrior added this to the 2.10 milestone Mar 24, 2022
@oldmud0
Copy link
Member

oldmud0 commented Mar 24, 2022

yeah i know, having legacy things around is the rather unfortunate consequence of a game with such a long history

"like 5 lines" yeah probably lost a bet.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

void connect_to_server(server_type p_server);
void disconnect_from_server();

public slots:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]

Suggested change
public slots:

include/networkmanager.h:46: previously declared here

public:
^

switch (p_server.socket_type) {
case TCP:
qInfo() << "using TCP backend";
server_socket.tcp = new QTcpSocket(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

    server_socket.tcp = new QTcpSocket(this);
                  ^

qInfo() << "using TCP backend";
server_socket.tcp = new QTcpSocket(this);

connect(server_socket.tcp, &QAbstractSocket::connected, this, [] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

    connect(server_socket.tcp, &QAbstractSocket::connected, this, [] {
                          ^

connect(server_socket.tcp, &QAbstractSocket::connected, this, [] {
qDebug() << "established connection to server";
});
connect(server_socket.tcp, &QIODevice::readyRead, this, [this] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

    connect(server_socket.tcp, &QIODevice::readyRead, this, [this] {
                          ^

qDebug() << "established connection to server";
});
connect(server_socket.tcp, &QIODevice::readyRead, this, [this] {
handle_server_packet(QString::fromUtf8(server_socket.tcp->readAll()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

      handle_server_packet(QString::fromUtf8(server_socket.tcp->readAll()));
                                                           ^

server_socket.tcp->deleteLater();
break;
case WEBSOCKETS:
server_socket.ws->close(QWebSocketProtocol::CloseCodeGoingAway);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

    server_socket.ws->close(QWebSocketProtocol::CloseCodeGoingAway);
                  ^

break;
case WEBSOCKETS:
server_socket.ws->close(QWebSocketProtocol::CloseCodeGoingAway);
server_socket.ws->deleteLater();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

    server_socket.ws->deleteLater();
                  ^

server_socket->write(p_packet.toUtf8());
switch (active_connection_type) {
case TCP:
server_socket.tcp->write(p_packet.toUtf8());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

    server_socket.tcp->write(p_packet.toUtf8());
                  ^

server_socket.tcp->write(p_packet.toUtf8());
break;
case WEBSOCKETS:
server_socket.ws->sendTextMessage(p_packet);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

    server_socket.ws->sendTextMessage(p_packet);
                  ^

src/networkmanager.cpp Outdated Show resolved Hide resolved
@oldmud0
Copy link
Member

oldmud0 commented Mar 24, 2022

oh crap, houston we got a big big problem. need to rebuild the windows qt5 builder so that it includes the websockets module. alternatively remove the gitlab CI for windows altogether

@Salanto
Copy link
Contributor Author

Salanto commented Mar 24, 2022

Given that Github Actions produce usable clients, we don't need to run the same CI twice, do we? Though I am sure to be corrected because some people still use 32-bit operating systems in 2022, though.

@AwesomeAim
Copy link

This completely breaks favourites. Also, I can apparently double click on a favourite entry and it stores my double click and then the next time I click on a server that replies it immediately joins it.

include/networkmanager.h Show resolved Hide resolved
@Crystalwarrior
Copy link
Contributor

Crystalwarrior commented Apr 4, 2022

This completely breaks favourites. Also, I can apparently double click on a favourite entry and it stores my double click and then the next time I click on a server that replies it immediately joins it.

Just launched it, favorites seem to work? Wait the favorites tab is not functional on Github Actions but it is functional from qt creator, what the hell?

EDIT: Turns out I've been compiling with minGW while github actions uses VS. stonedDiscord is gonna debug it

@Crystalwarrior
Copy link
Contributor

Crystalwarrior commented Apr 4, 2022

It only uses TCP backend when connecting to Favorites servers when built via minGW

src/networkmanager.cpp Outdated Show resolved Hide resolved
Crystalwarrior and others added 2 commits April 6, 2022 14:40
Make "add_favorite_server" remember the socket type
This will keep new entries compatible with 2.9 and prior clients. Makes parsing the list easier too.
src/text_file_functions.cpp Outdated Show resolved Hide resolved
src/aoapplication.cpp Outdated Show resolved Hide resolved
Salanto and others added 4 commits May 23, 2022 21:30
* I have no idea what a lookup table is, but this looks close enough
* Otherwise backend selection behaviour is inverted
* Yet it did not do it.

Co-authored-by: oldmud0 <[email protected]>
@Salanto
Copy link
Contributor Author

Salanto commented May 23, 2022

Should be good to go now. Tested on MingW 32-bit and the CI action.

oldmud0
oldmud0 previously approved these changes May 27, 2022
Copy link
Member

@oldmud0 oldmud0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has waited far too long

@Salanto Salanto changed the title Replace TCP Serversocket with Websocket Dual-Stack AO2 Client to handle both TCP and Websocket connections seemlessly May 27, 2022
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

include/datatypes.h Show resolved Hide resolved
Copy link
Member

@oldmud0 oldmud0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a major feature for 2.10, so let's get this merged

@oldmud0 oldmud0 dismissed stonedDiscord’s stale review June 4, 2022 03:32

your review sucks jk

oldmud0
oldmud0 previously requested changes Jun 4, 2022
src/text_file_functions.cpp Outdated Show resolved Hide resolved
* 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
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 27016 is a magic number; consider replacing it with a named constant [readability-magic-numbers]

      f_server.port = l_favorite_ini.value("port", 27016).toInt();
                                                   ^

@stonedDiscord stonedDiscord merged commit f0a5e48 into master Jun 6, 2022
@oldmud0
Copy link
Member

oldmud0 commented Jun 6, 2022

Cool. Very cool

@stonedDiscord stonedDiscord deleted the remove-tcp-add-websocket branch June 7, 2022 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Favorites Tab not equipped to add websocket servers
5 participants