2019-03-30 13:48:46 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-03-30 13:48:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-10 23:21:40 +00:00
|
|
|
#include <functional>
|
2019-03-30 13:48:46 +00:00
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2019-08-04 16:32:29 +00:00
|
|
|
#include <string_view>
|
2019-03-30 13:48:46 +00:00
|
|
|
#include <thread>
|
2019-03-30 13:50:57 +00:00
|
|
|
#include <utility>
|
2019-03-30 13:48:46 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-04-06 12:09:20 +00:00
|
|
|
#include "Common/Event.h"
|
2019-03-30 13:48:46 +00:00
|
|
|
|
|
|
|
struct NetPlaySession
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::string region;
|
|
|
|
std::string method;
|
|
|
|
std::string server_id;
|
|
|
|
std::string game_id;
|
2019-04-07 21:53:13 +00:00
|
|
|
std::string version;
|
2019-03-30 13:48:46 +00:00
|
|
|
|
|
|
|
int player_count;
|
|
|
|
int port;
|
|
|
|
|
|
|
|
bool has_password;
|
|
|
|
bool in_game;
|
|
|
|
|
2019-08-04 16:32:29 +00:00
|
|
|
bool EncryptID(std::string_view password);
|
|
|
|
std::optional<std::string> DecryptID(std::string_view password) const;
|
2019-03-30 13:48:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NetPlayIndex
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit NetPlayIndex();
|
|
|
|
~NetPlayIndex();
|
|
|
|
|
|
|
|
std::optional<std::vector<NetPlaySession>>
|
|
|
|
List(const std::map<std::string, std::string>& filters = {});
|
|
|
|
|
2019-03-30 13:50:57 +00:00
|
|
|
static std::vector<std::pair<std::string, std::string>> GetRegions();
|
2019-03-30 13:48:46 +00:00
|
|
|
|
2019-08-04 16:29:15 +00:00
|
|
|
bool Add(const NetPlaySession& session);
|
2019-03-30 13:48:46 +00:00
|
|
|
void Remove();
|
|
|
|
|
2019-04-10 23:21:40 +00:00
|
|
|
bool HasActiveSession() const;
|
|
|
|
|
2019-03-30 13:48:46 +00:00
|
|
|
void SetPlayerCount(int player_count);
|
|
|
|
void SetInGame(bool in_game);
|
2019-03-30 13:50:57 +00:00
|
|
|
void SetGame(std::string game);
|
2019-03-30 13:48:46 +00:00
|
|
|
|
|
|
|
const std::string& GetLastError() const;
|
|
|
|
|
2019-04-10 23:21:40 +00:00
|
|
|
void SetErrorCallback(std::function<void()> callback);
|
|
|
|
|
2019-03-30 13:48:46 +00:00
|
|
|
private:
|
|
|
|
void NotificationLoop();
|
|
|
|
|
|
|
|
std::string m_secret;
|
|
|
|
std::string m_game;
|
|
|
|
int m_player_count = 0;
|
|
|
|
bool m_in_game = false;
|
|
|
|
|
|
|
|
std::string m_last_error;
|
|
|
|
std::thread m_session_thread;
|
2019-04-06 12:09:20 +00:00
|
|
|
|
|
|
|
Common::Event m_session_thread_exit_event;
|
2019-04-10 23:21:40 +00:00
|
|
|
|
|
|
|
std::function<void()> m_error_callback = nullptr;
|
2019-03-30 13:48:46 +00:00
|
|
|
};
|