| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <functional> |
| 7 |
#include <map> |
| 8 |
#include <optional> |
| 9 |
#include <string> |
| 10 |
#include <string_view> |
| 11 |
#include <thread> |
| 12 |
#include <utility> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#include "Common/Event.h" |
| 16 |
|
| 17 |
struct NetPlaySession |
| 18 |
{ |
| 19 |
std::string name; |
| 20 |
std::string region; |
| 21 |
std::string method; |
| 22 |
std::string server_id; |
| 23 |
std::string game_id; |
| 24 |
std::string version; |
| 25 |
|
| 26 |
int player_count = 0; |
| 27 |
int port = 0; |
| 28 |
|
| 29 |
bool has_password = false; |
| 30 |
bool in_game = false; |
| 31 |
|
| 32 |
bool EncryptID(std::string_view password); |
| 33 |
std::optional<std::string> DecryptID(std::string_view password) const; |
| 34 |
}; |
| 35 |
|
| 36 |
class NetPlayIndex |
| 37 |
{ |
| 38 |
public: |
| 39 |
explicit NetPlayIndex(); |
| 40 |
~NetPlayIndex(); |
| 41 |
|
| 42 |
std::optional<std::vector<NetPlaySession>> |
| 43 |
List(const std::map<std::string, std::string>& filters = {}); |
| 44 |
|
| 45 |
static std::vector<std::pair<std::string, std::string>> GetRegions(); |
| 46 |
|
| 47 |
bool Add(const NetPlaySession& session); |
| 48 |
void Remove(); |
| 49 |
|
| 50 |
bool HasActiveSession() const; |
| 51 |
|
| 52 |
void SetPlayerCount(int player_count); |
| 53 |
void SetInGame(bool in_game); |
| 54 |
void SetGame(std::string game); |
| 55 |
|
| 56 |
const std::string& GetLastError() const; |
| 57 |
|
| 58 |
void SetErrorCallback(std::function<void()> callback); |
| 59 |
|
| 60 |
private: |
| 61 |
void NotificationLoop(); |
| 62 |
|
| 63 |
std::string m_secret; |
| 64 |
std::string m_game; |
| 65 |
int m_player_count = 0; |
| 66 |
bool m_in_game = false; |
| 67 |
|
| 68 |
std::string m_last_error; |
| 69 |
std::thread m_session_thread; |
| 70 |
|
| 71 |
Common::Event m_session_thread_exit_event; |
| 72 |
|
| 73 |
std::function<void()> m_error_callback = nullptr; |
| 74 |
}; |