Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NetLobby.h
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: NetLobby.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Base Class for Multiplayer Game Lobby classes
13 */
14 
15 #ifndef NetLobby_h
16 #define NetLobby_h
17 
18 #include "Types.h"
19 #include "NetLink.h"
20 #include "List.h"
21 
22 #define NET_CAMPAIGN_SHIFT 12
23 #define NET_MISSION_MASK 0xfff
24 #define NET_DISCONNECT_TIME 30
25 
26 // +-------------------------------------------------------------------+
27 
28 class Campaign;
29 class Mission;
30 class MissionElement;
31 class MissionInfo;
32 class NetCampaignInfo;
33 class NetChatEntry;
34 class NetUser;
35 class NetUnitEntry;
36 class NetLobbyParam;
37 class ModInfo;
38 
39 // +--------------------------------------------------------------------+
40 
41 class NetLobby
42 {
43 public:
44  static const char* TYPENAME() { return "NetLobby"; }
45 
46  NetLobby(bool temporary = false);
47  virtual ~NetLobby();
48 
49  virtual bool IsClient() const { return false; }
50  virtual bool IsServer() const { return false; }
51  virtual bool IsActive() const { return active; }
52 
53  virtual void ExecFrame();
54  virtual void Recv();
55  virtual void Send();
56  virtual int GetLastError() const { return 0; }
57 
58  virtual NetUser* FindUserByAddr(const NetAddr& addr);
59  virtual NetUser* FindUserByName(const char* name);
60  virtual NetUser* FindUserByNetID(DWORD id);
61 
62  virtual void BanUser(NetUser* user);
63  virtual void AddUser(NetUser* user);
64  virtual void DelUser(NetUser* user);
65  virtual bool SetUserHost(NetUser* user, bool host);
66  virtual int NumUsers();
67  virtual NetUser* GetHost();
68  virtual bool HasHost();
69  virtual bool IsHost() const { return false; }
70  virtual List<NetUser>& GetUsers();
71 
72  virtual List<ModInfo>& GetServerMods();
73 
74  virtual NetUser* GetLocalUser();
75  virtual void SetLocalUser(NetUser* user);
76 
77  virtual int GetStatus() const { return status; }
78  virtual void SetStatus(int s) { status = s; }
79 
80  virtual void AddChat(NetUser* user, const char* msg, bool route=true);
81  virtual List<NetChatEntry>&
82  GetChat();
83  virtual void ClearChat();
84  virtual void SaveChat() { }
85  virtual DWORD GetStartTime() const { return start_time; }
86 
87  virtual List<NetCampaignInfo>&
88  GetCampaigns();
89 
90  virtual void AddUnitMap(MissionElement* elem, int index=0);
91  virtual List<NetUnitEntry>&
92  GetUnitMap();
93  virtual void ClearUnitMap();
94  virtual void MapUnit(int n, const char* user, bool lock=false);
95  virtual void UnmapUnit(const char* user);
96  virtual bool IsMapped(const char* user);
97 
98  virtual Mission* GetSelectedMission() { return mission; }
99  virtual DWORD GetSelectedMissionID() const { return selected_mission; }
100  virtual void SelectMission(DWORD id);
101 
102  virtual const Text& GetMachineInfo() { return machine_info; }
103  virtual WORD GetGamePort() { return 0; }
104 
105  // actions:
106  virtual bool Ping();
107  virtual void GameStart() { }
108  virtual void GameStop() { }
109  virtual DWORD GetLag();
110 
111  // instance management:
112  static NetLobby* GetInstance();
113  static bool IsNetLobbyClient();
114  static bool IsNetLobbyServer();
115 
116 protected:
117  virtual void DoPing(NetPeer* peer, Text msg) { }
118  virtual void DoServerInfo(NetPeer* peer, Text msg) { }
119  virtual void DoServerMods(NetPeer* peer, Text msg) { }
120  virtual void DoLogin(NetPeer* peer, Text msg) { }
121  virtual void DoLogout(NetPeer* peer, Text msg) { }
122  virtual void DoAuthUser(NetPeer* peer, Text msg) { }
123  virtual void DoUserAuth(NetPeer* peer, Text msg) { }
124  virtual void DoChat(NetPeer* peer, Text msg) { }
125  virtual void DoUserList(NetPeer* peer, Text msg) { }
126  virtual void DoBanUser(NetPeer* peer, Text msg) { }
127  virtual void DoMissionList(NetPeer* peer, Text msg) { }
128  virtual void DoMissionSelect(NetPeer* peer, Text msg) { }
129  virtual void DoMissionData(NetPeer* peer, Text msg) { }
130  virtual void DoUnitList(NetPeer* peer, Text msg) { }
131  virtual void DoMapUnit(NetPeer* peer, Text msg) { }
132  virtual void DoGameStart(NetPeer* peer, Text msg) { }
133  virtual void DoGameStop(NetPeer* peer, Text msg) { }
134  virtual void DoExit(NetPeer* peer, Text msg) { }
135 
136  virtual void ParseMsg(Text msg, List<NetLobbyParam>& params);
137 
146 
147  bool active;
149  DWORD start_time;
152  int status;
153 };
154 
155 // +-------------------------------------------------------------------+
156 
158 {
159 public:
160  static const char* TYPENAME() { return "NetLobbyParam"; }
161 
162  NetLobbyParam(const char* n, const char* v) : name(n), value(v) { }
163 
164  int operator == (const NetLobbyParam& p) const { return name == p.name; }
165 
168 };
169 
170 // +-------------------------------------------------------------------+
171 
173 {
174 public:
175  static const char* TYPENAME() { return "NetUnitEntry"; }
176 
177  NetUnitEntry(MissionElement* elem, int index=0);
178  NetUnitEntry(const char* elem, const char* design, int iff, int index=0);
179  ~NetUnitEntry();
180 
181  int operator == (const NetUnitEntry& e) const { return (elem == e.elem) && (index == e.index); }
182 
183  Text GetDescription() const;
184  const Text& GetUserName() const { return user; }
185  const Text& GetElemName() const { return elem; }
186  const Text& GetDesign() const { return design; }
187  int GetIFF() const { return iff; }
188  int GetIndex() const { return index; }
189  int GetLives() const { return lives; }
190  int GetIntegrity() const { return hull; }
191  int GetMissionRole() const { return role; }
192  bool GetLocked() const { return lock; }
193 
194  void SetUserName(const char* u) { user = u; }
195  void SetElemName(const char* e) { elem = e; }
196  void SetDesign(const char* d) { design = d; }
197  void SetIFF(int i) { iff = i; }
198  void SetIndex(int i) { index = i; }
199  void SetLives(int i) { lives = i; }
200  void SetIntegrity(int i) { hull = i; }
201  void SetMissionRole(int i) { role = i; }
202  void SetLock(bool l) { lock = l; }
203 
204 private:
205  Text user;
206  Text elem;
207  Text design;
208  int iff;
209  int index;
210  int lives;
211  int hull;
212  int role;
213  bool lock;
214 };
215 
216 // +--------------------------------------------------------------------+
217 
219 {
220 public:
221  static const char* TYPENAME() { return "NetServerInfo"; }
222 
224 
225  NetServerInfo();
226 
232  WORD port;
233  WORD gameport;
234  bool save;
235 
238  int nplayers;
239  int hosted;
240  int status;
241 
242  DWORD ping_time;
243 };
244 
245 // +--------------------------------------------------------------------+
246 
248 {
249 public:
250  static const char* TYPENAME() { return "NetCampaignInfo"; }
251 
252  NetCampaignInfo() : id(0) { }
254 
255  int id;
257 
259 };
260 
261 // +--------------------------------------------------------------------+
262 
277 
280 
284 };
285 
286 // +--------------------------------------------------------------------+
287 
288 #endif NetLobby_h
289