dolphin/Source/Core/UICommon/NetPlayIndex.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.5 KiB
C
Raw Normal View History

2019-03-30 13:48:46 +00:00
// Copyright 2019 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2019-03-30 13:48:46 +00:00
#pragma once
#include <functional>
2019-03-30 13:48:46 +00:00
#include <map>
#include <optional>
#include <string>
#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>
#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;
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
bool Add(const NetPlaySession& session);
2019-03-30 13:48:46 +00:00
void Remove();
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;
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;
Common::Event m_session_thread_exit_event;
std::function<void()> m_error_callback = nullptr;
2019-03-30 13:48:46 +00:00
};