NetPlayIndex.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <functional>
  5. #include <map>
  6. #include <optional>
  7. #include <string>
  8. #include <string_view>
  9. #include <thread>
  10. #include <utility>
  11. #include <vector>
  12. #include "Common/Event.h"
  13. struct NetPlaySession
  14. {
  15. std::string name;
  16. std::string region;
  17. std::string method;
  18. std::string server_id;
  19. std::string game_id;
  20. std::string version;
  21. int player_count = 0;
  22. int port = 0;
  23. bool has_password = false;
  24. bool in_game = false;
  25. bool EncryptID(std::string_view password);
  26. std::optional<std::string> DecryptID(std::string_view password) const;
  27. };
  28. class NetPlayIndex
  29. {
  30. public:
  31. explicit NetPlayIndex();
  32. ~NetPlayIndex();
  33. std::optional<std::vector<NetPlaySession>>
  34. List(const std::map<std::string, std::string>& filters = {});
  35. static std::vector<std::pair<std::string, std::string>> GetRegions();
  36. bool Add(const NetPlaySession& session);
  37. void Remove();
  38. bool HasActiveSession() const;
  39. void SetPlayerCount(int player_count);
  40. void SetInGame(bool in_game);
  41. void SetGame(std::string game);
  42. const std::string& GetLastError() const;
  43. void SetErrorCallback(std::function<void()> callback);
  44. private:
  45. void NotificationLoop();
  46. std::string m_secret;
  47. std::string m_game;
  48. int m_player_count = 0;
  49. bool m_in_game = false;
  50. std::string m_last_error;
  51. std::thread m_session_thread;
  52. Common::Event m_session_thread_exit_event;
  53. std::function<void()> m_error_callback = nullptr;
  54. };