-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlobby.hpp
More file actions
executable file
·111 lines (83 loc) · 2.21 KB
/
lobby.hpp
File metadata and controls
executable file
·111 lines (83 loc) · 2.21 KB
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
#ifndef LOBBY_HPP
#define LOBBY_HPP
#include <map>
#include <string>
#include "screenview.hpp"
#include "main.hpp"
#include "frame.hpp"
#include "tracker.hpp"
// Keeps track of all of the players in the chat lobby before a game.
class Lobby:public Frame
{
public:
Lobby();
virtual ~Lobby();
virtual bool isFull() const = 0;
virtual void addPlayer(const std::string &name) = 0;
virtual void removePlayer(const std::string &name);
virtual void timepass();
const char *getMapName();
void setupWidgets(bool echoChat);
protected:
std::string modifiedPlayerName(const std::string &name);
void processChat();
virtual void processPackets() = 0;
// If a player joins and someone else already has his name,
// then the new player gets an number appended to his name.
typedef std::map<std::string, int> PlayerPool;
PlayerPool players;
unsigned maxPlayers;
std::string mapName;
TextDisplay messages;
};
class HostLobby:public Lobby
{
public:
HostLobby(const std::string &map, unsigned maxNumPlayers);
~HostLobby();
void onEnable();
void onDisable();
void set(const std::string &map, unsigned maxNumPlayers, std::string name);
bool isFull() const;
void addPlayer(const std::string &name);
void removePlayer(const std::string &name);
void disconnected(NetworkNode *node);
void setupWidgets();
private:
void processPackets();
void sendMessage(std::string message);
void tellOthersAboutNewPlayer(
const std::string &nameToAdd,
int newestPlayerNode);
void tellNewPlayerAboutOthers(int newestPlayerNode);
std::string gameName;
int numPlayers;
};
class ClientLobby:public Lobby
{
public:
ClientLobby();
~ClientLobby();
bool isFull() const;
void addPlayer(const std::string &name);
void disconnected(NetworkNode *node);
void setupWidgets();
private:
void processPackets();
};
template<class T> class ScrollPane;
class JoinFrame:public Frame
{
public:
JoinFrame();
~JoinFrame();
void onEnable();
void setupWidgets();
void timepass();
private:
ScrollPane<ServerDesc> *serverview;
};
extern HostLobby *hostLobby;
extern ClientLobby *clientLobby;
extern JoinFrame *joinFrame;
#endif