1 /*-------------------------------------------------------------------------------
2 
3 BARONY
4 File: lobbies.hpp
5 Desc: header for lobbies.cpp (matchmaking handlers)
6 
7 Copyright 2013-2020 (c) Turning Wheel LLC, all rights reserved.
8 See LICENSE for details.
9 
10 -------------------------------------------------------------------------------*/
11 
12 #pragma once
13 
14 class LobbyHandler_t
15 {
16 	const int kNumSearchResults = 200;
17 	bool filterShowInProgressLobbies = false;
18 public:
LobbyHandler_t()19 	LobbyHandler_t() :
20 		lobbyDisplayedSearchResults(kNumSearchResults, std::make_pair(-1, LOBBY_DISABLE))
21 	{
22 #if defined STEAMWORKS && !defined USE_EOS
23 		searchType = LOBBY_STEAM;
24 		joiningType = LOBBY_STEAM;
25 		hostingType = LOBBY_STEAM;
26 		P2PType = LOBBY_STEAM;
27 #elif !defined STEAMWORKS && defined USE_EOS
28 		searchType = LOBBY_CROSSPLAY;
29 		joiningType = LOBBY_CROSSPLAY;
30 		hostingType = LOBBY_CROSSPLAY;
31 		P2PType = LOBBY_CROSSPLAY;
32 #elif defined STEAMWORKS && defined USE_EOS
33 		searchType = LOBBY_COMBINED;
34 		joiningType = LOBBY_STEAM;
35 		hostingType = LOBBY_STEAM;
36 		P2PType = LOBBY_STEAM;
37 #endif
38 	};
39 
40 	enum LobbyServiceType : int
41 	{
42 		LOBBY_DISABLE,
43 		LOBBY_STEAM,
44 		LOBBY_CROSSPLAY,
45 		LOBBY_COMBINED
46 	};
47 	LobbyServiceType hostingType = LOBBY_DISABLE;
48 	LobbyServiceType joiningType = LOBBY_DISABLE;
49 	LobbyServiceType searchType = LOBBY_DISABLE;
50 	LobbyServiceType P2PType = LOBBY_DISABLE;
51 	void handleLobbyListRequests();
52 	void handleLobbyBrowser();
53 	void updateSearchResults();
54 	static void filterLobbyButton(button_t* my);
55 	static void searchLobbyWithFilter(button_t* my);
56 	void drawLobbyFilters();
57 	LobbyServiceType getDisplayedResultLobbyType(int selection);
58 	Sint32 getDisplayedResultLobbyIndex(int selection);
59 	std::vector<std::pair<Sint32, LobbyServiceType>> lobbyDisplayedSearchResults;
60 	Uint32 numLobbyDisplaySearchResults = 0;
61 	int selectedLobbyInList = 0;
62 	bool showLobbyFilters = false;
63 
64 	bool crossplayEnabled = false;
65 	bool settings_crossplayEnabled = false;
66 
getHostingType()67 	LobbyServiceType getHostingType()
68 	{
69 		return hostingType;
70 	}
getJoiningType()71 	LobbyServiceType getJoiningType()
72 	{
73 		return joiningType;
74 	}
getP2PType()75 	LobbyServiceType getP2PType()
76 	{
77 		return P2PType;
78 	}
setLobbyJoinTypeOfCurrentSelection()79 	LobbyServiceType setLobbyJoinTypeOfCurrentSelection()
80 	{
81 		if ( getDisplayedResultLobbyType(selectedLobbyInList) != LOBBY_DISABLE )
82 		{
83 			joiningType = getDisplayedResultLobbyType(selectedLobbyInList);
84 		}
85 		return joiningType;
86 	}
setP2PType(LobbyServiceType type)87 	void setP2PType(LobbyServiceType type)
88 	{
89 		P2PType = type;
90 	}
logError(const char * str,...)91 	static void logError(const char* str, ...)
92 	{
93 		char newstr[1024] = { 0 };
94 		va_list argptr;
95 
96 		// format the content
97 		va_start(argptr, str);
98 		vsnprintf(newstr, 1023, str, argptr);
99 		va_end(argptr);
100 		printlog("[Lobbies Error]: %s", newstr);
101 	}
102 	static std::string getLobbyJoinFailedConnectString(int result);
103 #ifdef STEAMWORKS
104 	CSteamID steamLobbyToValidate = {};
105 	void steamValidateAndJoinLobby(CSteamID& id);
106 	bool validateSteamLobbyDataOnJoin();
107 #endif
108 	enum EResult_LobbyFailures : int
109 	{
110 		LOBBY_USING_SAVEGAME = 50000,
111 		LOBBY_WRONG_SAVEGAME,
112 		LOBBY_NOT_USING_SAVEGAME,
113 		LOBBY_NO_OWNER,
114 		LOBBY_GAME_IN_PROGRESS,
115 		LOBBY_UNHANDLED_ERROR,
116 		LOBBY_JOIN_CANCELLED,
117 		LOBBY_JOIN_TIMEOUT,
118 		LOBBY_NOT_FOUND,
119 		LOBBY_TOO_MANY_PLAYERS
120 	};
121 };
122 extern LobbyHandler_t LobbyHandler;