dolphin/Source/Core/UICommon/NetPlayIndex.h

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

76 lines
1.5 KiB
C
Raw Normal View History

2019-03-30 07:48:46 -06:00
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <functional>
2019-03-30 07:48:46 -06:00
#include <map>
#include <optional>
#include <string>
#include <string_view>
2019-03-30 07:48:46 -06:00
#include <thread>
2019-03-30 07:50:57 -06:00
#include <utility>
2019-03-30 07:48:46 -06:00
#include <vector>
#include "Common/Event.h"
2019-03-30 07:48:46 -06:00
struct NetPlaySession
{
std::string name;
std::string region;
std::string method;
std::string server_id;
std::string game_id;
2019-04-07 15:53:13 -06:00
std::string version;
2019-03-30 07:48:46 -06: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 07:48:46 -06:00
};
class NetPlayIndex
{
public:
explicit NetPlayIndex();
~NetPlayIndex();
std::optional<std::vector<NetPlaySession>>
List(const std::map<std::string, std::string>& filters = {});
2019-03-30 07:50:57 -06:00
static std::vector<std::pair<std::string, std::string>> GetRegions();
2019-03-30 07:48:46 -06:00
bool Add(const NetPlaySession& session);
2019-03-30 07:48:46 -06:00
void Remove();
bool HasActiveSession() const;
2019-03-30 07:48:46 -06:00
void SetPlayerCount(int player_count);
void SetInGame(bool in_game);
2019-03-30 07:50:57 -06:00
void SetGame(std::string game);
2019-03-30 07:48:46 -06:00
const std::string& GetLastError() const;
void SetErrorCallback(std::function<void()> callback);
2019-03-30 07:48:46 -06: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 07:48:46 -06:00
};