Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
XmppClient.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef XMPPCLIENT_H
19#define XMPPCLIENT_H
20
21#include <js/Value.h>
22#include <memory>
23#include <set>
24#include <string>
25
26namespace Script { class Interface; }
27namespace Script { class Request; }
28
30{
31public:
32 XmppClient(const Script::Interface* scriptInterface, const std::string& username,
33 const std::string& password, const std::string& room, const std::string& nick,
34 const int historyRequestSize = 0, bool regOpt = false);
36
37 void connect();
38 void disconnect();
39 bool isConnected();
40 void recv();
41 void SendIqGetBoardList();
42 void SendIqGetProfile(const std::string& player);
43 void SendIqGameReport(const Script::Request& rq, JS::HandleValue data);
44 void SendIqRegisterGame(const Script::Request& rq, JS::HandleValue data);
45 void SendIqGetConnectionData(const std::string& jid, const std::string& password,
46 const std::string& clientSalt, bool localIP);
48 void SendIqChangeStateGame(const std::string& nbp, const std::string& players);
49 void SendIqLobbyAuth(const std::string& to, const std::string& token);
50 void SetNick(const std::string& nick);
51 std::string GetNick() const;
52 std::string GetJID();
53 std::string GetUsername() const;
54 void ChangePassword(const std::string& newPassword);
55 void kick(const std::string& nick, const std::string& reason);
56 void ban(const std::string& nick, const std::string& reason);
57 void SetPresence(const std::string& presence);
58 const char* GetPresence(const std::string& nickname);
59 const char* GetRole(const std::string& nickname);
60 std::wstring GetRating(const std::string& nickname);
61 const std::wstring& GetSubject();
62 JS::Value GUIGetPlayerList(const Script::Request& rq);
63 JS::Value GUIGetGameList(const Script::Request& rq);
64 JS::Value GUIGetBoardList(const Script::Request& rq);
65 JS::Value GUIGetProfile(const Script::Request& rq);
66
67 JS::Value GuiPollNewMessages(const Script::Interface& guiInterface);
68 JS::Value GuiPollHistoricMessages(const Script::Interface& guiInterface);
70
71 void SendMUCMessage(const std::string& message);
72 void SendStunEndpointToHost(const std::string& ip, std::uint16_t port, const std::string& hostJID);
73
74 /* Roster */
75
76 /**
77 * Add the given nickname to the buddies of the current user.
78 *
79 * @param nick The nickname of a player in the lobby.
80 */
81 void AddBuddy(const std::string& nick);
82
83 /**
84 * Remove the given nickname from the buddies of the current user.
85 *
86 * @param nick The nickname of a player in the lobby.
87 */
88 void RemoveBuddy(const std::string& nick);
89
90 /**
91 * Whether the given nickname is a buddy of the current user.
92 *
93 * The buddies are stored in the XMPP roster of the connected lobby. Since
94 * a nickname only identifies a user within one lobby, this is meaningless
95 * without a connection and always returns false in that case.
96 *
97 * @param nick The nickname to look up, compared case-insensitively
98 */
99 bool IsBuddy(const std::string& nick) const;
100
101 /**
102 * Get the nicknames of all buddies of the current user.
103 *
104 * @returns The (lowercase) nicknames of the buddies in the lobby's roster
105 */
106 std::set<std::string> GetBuddies() const;
107
108private:
109 class Impl;
110 const std::unique_ptr<Impl> m_Impl;
111};
112
114extern bool g_rankedGame;
115
116#endif // XMPPCLIENT_H
XmppClient * g_XmppClient
Definition: Globals.cpp:22
bool g_rankedGame
Definition: Globals.cpp:23
Definition: Interface.h:93
Definition: Request.h:51
Definition: XmppClient.cpp:137
Definition: XmppClient.h:30
std::wstring GetRating(const std::string &nickname)
Get the most recent received rating of the given nick.
Definition: XmppClient.cpp:1479
void RemoveBuddy(const std::string &nick)
Remove the given nickname from the buddies of the current user.
Definition: XmppClient.cpp:1606
bool isConnected()
Definition: XmppClient.cpp:416
bool IsBuddy(const std::string &nick) const
Whether the given nickname is a buddy of the current user.
Definition: XmppClient.cpp:1619
JS::Value GuiPollHistoricMessages(const Script::Interface &guiInterface)
Definition: XmppClient.cpp:958
void recv()
Definition: XmppClient.cpp:421
void ban(const std::string &nick, const std::string &reason)
Ban a player from the current room.
Definition: XmppClient.cpp:1426
void SendIqGetBoardList()
Request the leaderboard data from the server.
Definition: XmppClient.cpp:518
void SendIqChangeStateGame(const std::string &nbp, const std::string &players)
Send a request to change the state of a registered game on the server.
Definition: XmppClient.cpp:678
const char * GetRole(const std::string &nickname)
Get the current xmpp role of the given nick.
Definition: XmppClient.cpp:1465
const std::unique_ptr< Impl > m_Impl
Definition: XmppClient.h:110
std::string GetNick() const
Get current MUC nickname.
Definition: XmppClient.cpp:1378
void SendIqLobbyAuth(const std::string &to, const std::string &token)
Send lobby authentication token.
Definition: XmppClient.cpp:703
JS::Value GUIGetProfile(const Script::Request &rq)
Handle requests from the GUI for profile data.
Definition: XmppClient.cpp:843
void SendMUCMessage(const std::string &message)
Send a standard MUC textual message.
Definition: XmppClient.cpp:981
void kick(const std::string &nick, const std::string &reason)
Kick a player from the current room.
Definition: XmppClient.cpp:1415
std::set< std::string > GetBuddies() const
Get the nicknames of all buddies of the current user.
Definition: XmppClient.cpp:1624
JS::Value GUIGetPlayerList(const Script::Request &rq)
Handle requests from the GUI for the list of players.
Definition: XmppClient.cpp:764
void SetPresence(const std::string &presence)
Change the xmpp presence of the client.
Definition: XmppClient.cpp:1436
const char * GetPresence(const std::string &nickname)
Get the current xmpp presence of the given nick.
Definition: XmppClient.cpp:1452
XmppClient(const Script::Interface *scriptInterface, const std::string &username, const std::string &password, const std::string &room, const std::string &nick, const int historyRequestSize=0, bool regOpt=false)
Construct the XMPP client.
Definition: XmppClient.cpp:310
void SendIqGameReport(const Script::Request &rq, JS::HandleValue data)
Send game report containing numerous game properties to the server.
Definition: XmppClient.cpp:571
void SendIqUnregisterGame()
Send a request to unregister a game to the server.
Definition: XmppClient.cpp:656
void SendIqGetConnectionData(const std::string &jid, const std::string &password, const std::string &clientSalt, bool localIP)
Request the Connection data (ip, port...) from the server.
Definition: XmppClient.cpp:550
void AddBuddy(const std::string &nick)
Add the given nickname to the buddies of the current user.
Definition: XmppClient.cpp:1593
const std::wstring & GetSubject()
Get current subject.
Definition: XmppClient.cpp:1360
std::string GetJID()
Definition: XmppClient.cpp:1383
void SetNick(const std::string &nick)
Request MUC nick change, real change via mucRoomHandler.
Definition: XmppClient.cpp:1370
void SendStunEndpointToHost(const std::string &ip, std::uint16_t port, const std::string &hostJID)
Definition: XmppClient.cpp:1493
~XmppClient()
Destroy the xmpp client.
Definition: XmppClient.cpp:394
std::string GetUsername() const
Get the XMPP username.
Definition: XmppClient.cpp:1394
JS::Value GUIGetGameList(const Script::Request &rq)
Handle requests from the GUI for the list of all active games.
Definition: XmppClient.cpp:791
JS::Value GUIGetBoardList(const Script::Request &rq)
Handle requests from the GUI for leaderboard data.
Definition: XmppClient.cpp:818
void disconnect()
Definition: XmppClient.cpp:411
JS::Value GuiPollNewMessages(const Script::Interface &guiInterface)
Definition: XmppClient.cpp:916
void ChangePassword(const std::string &newPassword)
Change password for authenticated user.
Definition: XmppClient.cpp:1404
void connect()
Network.
Definition: XmppClient.cpp:405
void SendIqRegisterGame(const Script::Request &rq, JS::HandleValue data)
Send a request to register a game to the server.
Definition: XmppClient.cpp:614
void SendIqGetProfile(const std::string &player)
Request the profile data from the server.
Definition: XmppClient.cpp:534
bool GuiPollHasPlayerListUpdate()
Definition: XmppClient.cpp:906
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32