[Game] Extract makeGameJoinLink helper for cockatrice://joingame links (#7133)

The inline URL building in GameSelector's copy-link action moves into a
shared helper so every invite/copy site produces the same link format.
The helper embeds the game description as an extra "game" query item
(percent-encoded); links without it stay valid — the receiving parser
ignores unknown query items.

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-08-16 22:14:49 +02:00 committed by GitHub
parent 7c134efd29
commit d36865518e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 12 deletions

View file

@ -0,0 +1,23 @@
#include "game_link.h"
#include <QUrl>
#include <QUrlQuery>
QString makeGameJoinLink(const QString &hostname, int port, int roomId, int gameId, const QString &description)
{
QUrl url;
url.setScheme("cockatrice");
url.setHost("joingame");
QUrlQuery query;
query.addQueryItem("hostname", hostname);
query.addQueryItem("port", QString::number(port));
query.addQueryItem("roomid", QString::number(roomId));
query.addQueryItem("gameid", QString::number(gameId));
if (!description.isEmpty()) {
// addQueryItem percent-encodes, so arbitrary descriptions (quotes,
// ampersands, non-ASCII…) survive the trip through chat.
query.addQueryItem("game", description);
}
url.setQuery(query);
return url.toString(QUrl::FullyEncoded);
}