summaryrefslogtreecommitdiff
path: root/serverbrowser/ServerBrowserDialog.h
blob: 2b2518679da434165b548973c7a66ef85dc817c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================

#ifndef SERVERBROWSERDIALOG_H
#define SERVERBROWSERDIALOG_H
#ifdef _WIN32
#pragma once
#endif

extern class IRunGameEngine *g_pRunGameEngine;

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CServerBrowserDialog : public vgui::Frame
{
	DECLARE_CLASS_SIMPLE( CServerBrowserDialog, vgui::Frame ); 

public:
	// Construction/destruction
	CServerBrowserDialog( vgui::Panel *parent );
	~CServerBrowserDialog( void );

	void		Initialize( void );

	// displays the dialog, moves it into focus, updates if it has to
	void		Open( void );

	// gets server info
	gameserveritem_t *GetServer(unsigned int serverID);
	// called every frame
	virtual void OnTick();

	// updates status text at bottom of window
	void UpdateStatusText(PRINTF_FORMAT_STRING const char *format, ...);
	
	// updates status text at bottom of window
	void UpdateStatusText(wchar_t *unicode);

	// context menu access
	CServerContextMenu *GetContextMenu(vgui::Panel *pParent);		

	// returns a pointer to a static instance of this dialog
	// valid for use only in sort functions
	static CServerBrowserDialog *GetInstance();

	// Adds a server to the list of favorites
	void AddServerToFavorites(gameserveritem_t &server);
	// Adds a server to our list of blacklisted servers
	void AddServerToBlacklist(gameserveritem_t &server);
	bool IsServerBlacklisted(gameserveritem_t &server); 

	// begins the process of joining a server from a game list
	// the game info dialog it opens will also update the game list
	CDialogGameInfo *JoinGame(IGameList *gameList, unsigned int serverIndex);

	// joins a game by a specified IP, not attached to any game list
	CDialogGameInfo *JoinGame(int serverIP, int serverPort, const char *pszConnectCode);

	// opens a game info dialog from a game list
	CDialogGameInfo *OpenGameInfoDialog(IGameList *gameList, unsigned int serverIndex);

	// opens a game info dialog by a specified IP, not attached to any game list
	CDialogGameInfo *OpenGameInfoDialog( int serverIP, uint16 connPort, uint16 queryPort, const char *pszConnectCode );

	// closes all the game info dialogs
	void CloseAllGameInfoDialogs();
	CDialogGameInfo *GetDialogGameInfoForFriend( uint64 ulSteamIDFriend );

	// accessor to the filter save data
	KeyValues *GetFilterSaveData(const char *filterSet);

	// gets the name of the mod directory we're restricted to accessing, NULL if none
	const char *GetActiveModName();
	CGameID &GetActiveAppID();
	const char *GetActiveGameName();

	// load/saves filter & favorites settings from disk
	void		LoadUserData();
	void		SaveUserData();

	// forces the currently active page to refresh
	void		RefreshCurrentPage();

	virtual gameserveritem_t *GetCurrentConnectedServer()
	{
		return &m_CurrentConnection;
	}

	void		BlacklistsChanged();
	CBlacklistedServers *GetBlacklistPage( void ) { return m_pBlacklist; }

private:

	// current game list change
	MESSAGE_FUNC( OnGameListChanged, "PageChanged" );
	void ReloadFilterSettings();

	// receives a specified game is active, so no other game types can be displayed in server list
	MESSAGE_FUNC_PARAMS( OnActiveGameName, "ActiveGameName", name );

	// notification that we connected / disconnected
	MESSAGE_FUNC_PARAMS( OnConnectToGame, "ConnectedToGame", kv );
	MESSAGE_FUNC( OnDisconnectFromGame, "DisconnectedFromGame" );
	MESSAGE_FUNC( OnLoadingStarted, "LoadingStarted" );

	virtual bool GetDefaultScreenPosition(int &x, int &y, int &wide, int &tall);
	virtual void ActivateBuildMode();

	void OnKeyCodePressed( vgui::KeyCode code );

private:
	// list of all open game info dialogs
	CUtlVector<vgui::DHANDLE<CDialogGameInfo> > m_GameInfoDialogs;

	// pointer to current game list
	IGameList *m_pGameList;

	// Status text
	vgui::Label	*m_pStatusLabel;

	// property sheet
	vgui::PropertySheet *m_pTabPanel;
	CFavoriteGames *m_pFavorites;
	CBlacklistedServers *m_pBlacklist;
	CHistoryGames *m_pHistory;
	CInternetGames *m_pInternetGames;
	CSpectateGames *m_pSpectateGames;
	CLanGames *m_pLanGames;
	CFriendsGames *m_pFriendsGames;

	KeyValues *m_pSavedData;
	KeyValues *m_pFilterData;

	// context menu
	CServerContextMenu *m_pContextMenu;

	// active game
	char m_szGameName[128];
	char m_szModDir[128];
	CGameID m_iLimitAppID;

	// currently connected game
	bool m_bCurrentlyConnected;
	gameserveritem_t m_CurrentConnection;
};

// singleton accessor
extern CServerBrowserDialog &ServerBrowserDialog();

// Used by the LAN tab and the add server dialog when trying to find servers without having
// been given any ports to look for servers on.
void GetMostCommonQueryPorts( CUtlVector<uint16> &ports );

#endif // SERVERBROWSERDIALOG_H