mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 10:29:00 +00:00
This allows the same user to keep the buddy list across clients and config resets. At the same time this allows for per lobby buddy lists which is needed as the same nickname may refer to different people. Use lower case comparison for buddy names. This is in line with the idea of local part of jid should be seen as normalized nick and is used server-side to compare user names. The migration is kept simple. I.e. only attempted if the roster is empty and the config indicates no migration was done before. Fixes: #6824 Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
117 lines
3.9 KiB
C++
117 lines
3.9 KiB
C++
/* Copyright (C) 2026 Wildfire Games.
|
|
* This file is part of 0 A.D.
|
|
*
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef XMPPCLIENT_H
|
|
#define XMPPCLIENT_H
|
|
|
|
#include <js/Value.h>
|
|
#include <memory>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
namespace Script { class Interface; }
|
|
namespace Script { class Request; }
|
|
|
|
class XmppClient
|
|
{
|
|
public:
|
|
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);
|
|
~XmppClient();
|
|
|
|
void connect();
|
|
void disconnect();
|
|
bool isConnected();
|
|
void recv();
|
|
void SendIqGetBoardList();
|
|
void SendIqGetProfile(const std::string& player);
|
|
void SendIqGameReport(const Script::Request& rq, JS::HandleValue data);
|
|
void SendIqRegisterGame(const Script::Request& rq, JS::HandleValue data);
|
|
void SendIqGetConnectionData(const std::string& jid, const std::string& password,
|
|
const std::string& clientSalt, bool localIP);
|
|
void SendIqUnregisterGame();
|
|
void SendIqChangeStateGame(const std::string& nbp, const std::string& players);
|
|
void SendIqLobbyAuth(const std::string& to, const std::string& token);
|
|
void SetNick(const std::string& nick);
|
|
std::string GetNick() const;
|
|
std::string GetJID();
|
|
std::string GetUsername() const;
|
|
void ChangePassword(const std::string& newPassword);
|
|
void kick(const std::string& nick, const std::string& reason);
|
|
void ban(const std::string& nick, const std::string& reason);
|
|
void SetPresence(const std::string& presence);
|
|
const char* GetPresence(const std::string& nickname);
|
|
const char* GetRole(const std::string& nickname);
|
|
std::wstring GetRating(const std::string& nickname);
|
|
const std::wstring& GetSubject();
|
|
JS::Value GUIGetPlayerList(const Script::Request& rq);
|
|
JS::Value GUIGetGameList(const Script::Request& rq);
|
|
JS::Value GUIGetBoardList(const Script::Request& rq);
|
|
JS::Value GUIGetProfile(const Script::Request& rq);
|
|
|
|
JS::Value GuiPollNewMessages(const Script::Interface& guiInterface);
|
|
JS::Value GuiPollHistoricMessages(const Script::Interface& guiInterface);
|
|
bool GuiPollHasPlayerListUpdate();
|
|
|
|
void SendMUCMessage(const std::string& message);
|
|
void SendStunEndpointToHost(const std::string& ip, std::uint16_t port, const std::string& hostJID);
|
|
|
|
/* Roster */
|
|
|
|
/**
|
|
* Add the given nickname to the buddies of the current user.
|
|
*
|
|
* @param nick The nickname of a player in the lobby.
|
|
*/
|
|
void AddBuddy(const std::string& nick);
|
|
|
|
/**
|
|
* Remove the given nickname from the buddies of the current user.
|
|
*
|
|
* @param nick The nickname of a player in the lobby.
|
|
*/
|
|
void RemoveBuddy(const std::string& nick);
|
|
|
|
/**
|
|
* Whether the given nickname is a buddy of the current user.
|
|
*
|
|
* The buddies are stored in the XMPP roster of the connected lobby. Since
|
|
* a nickname only identifies a user within one lobby, this is meaningless
|
|
* without a connection and always returns false in that case.
|
|
*
|
|
* @param nick The nickname to look up, compared case-insensitively
|
|
*/
|
|
bool IsBuddy(const std::string& nick) const;
|
|
|
|
/**
|
|
* Get the nicknames of all buddies of the current user.
|
|
*
|
|
* @returns The (lowercase) nicknames of the buddies in the lobby's roster
|
|
*/
|
|
std::set<std::string> GetBuddies() const;
|
|
|
|
private:
|
|
class Impl;
|
|
const std::unique_ptr<Impl> m_Impl;
|
|
};
|
|
|
|
extern XmppClient *g_XmppClient;
|
|
extern bool g_rankedGame;
|
|
|
|
#endif // XMPPCLIENT_H
|