mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 18:06:26 -07:00
[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:
parent
7c134efd29
commit
d36865518e
4 changed files with 69 additions and 12 deletions
23
cockatrice/src/interface/widgets/server/game_link.cpp
Normal file
23
cockatrice/src/interface/widgets/server/game_link.cpp
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue