mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 18:06:26 -07:00
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>
23 lines
797 B
C++
23 lines
797 B
C++
#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);
|
|
}
|