OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4League.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 /* engine handler of league system */
18 
19 #ifndef C4LEAGUE_H_INCLUDED
20 #define C4LEAGUE_H_INCLUDED
21 
23 #include "gui/C4Gui.h"
24 #include "lib/SHA1.h"
25 
26 #define C4League_Name_Valid_Characters "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD9\xDA\xDB\xDC\xDD\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF\x20\x2E\x2D\x5F"
27 
28 // maximum league count a game can run in
29 const int32_t C4NetMaxLeagues = 10;
30 
32 {
33  C4LA_None, // no action
34 
35  C4LA_Start, // [host] Game registration
36  C4LA_Update, // [host] Game status update (heartbeat)
37  C4LA_End, // [host] Final game status
38  C4LA_PlrAuthCheck,// [host] Player authentication check
39 
40  C4LA_RefQuery, // [client] Query reference list
41  C4LA_PlrAuth, // [client] Player authentication request
42 
43  C4LA_ReportDisconnect // [both] Sent by host and client when a client is disconnected irregularly
44 };
45 
47 {
48 public:
49  C4LeagueRequestHead(C4LeagueAction eAction, const char *szCSID = "", const char *szAUID = "")
50  : eAction(eAction), CSID(szCSID), AUID(szAUID), fRememberLogin(false)
51  { }
52 
53 private:
54  C4LeagueAction eAction;
55  StdCopyStrBuf CSID;
56  StdCopyStrBuf AUID;
57 
58  // Auth
59  StdCopyStrBuf Account;
60  StdCopyStrBuf Password;
61  StdCopyStrBuf NewAccount;
62  StdCopyStrBuf NewPassword;
63  bool fRememberLogin;
64 
65 public:
66  void SetAuth(const char *szAccount, const char *szPassword, bool fRememberLogin);
67  void SetNewAccount(const char *szNewAccount);
68  void SetNewPassword(const char *szNewPassword);
69 
70  void CompileFunc(StdCompiler *pComp);
71 };
72 
74 {
75 private:
77 public:
78  C4LeagueReportDisconnectHead(const char *szCSID, C4LeagueDisconnectReason eReason) : C4LeagueRequestHead(C4LA_ReportDisconnect, szCSID, nullptr), eReason(eReason) {}
79 
80 public:
81  void CompileFunc(StdCompiler *pComp);
82 };
83 
85 {
86 public:
87  C4LeagueRequestHeadEnd(C4LeagueAction eAction, const char *szCSID, const char *szRecordName = nullptr, const BYTE *pRecordSHA = nullptr)
88  : C4LeagueRequestHead(eAction, szCSID), RecordName(szRecordName)
89  {
90  if (pRecordSHA)
91  memcpy(RecordSHA, pRecordSHA, SHA_DIGEST_LENGTH);
92  }
93 
94 private:
95  StdCopyStrBuf RecordName;
96  uint8_t RecordSHA[SHA_DIGEST_LENGTH];
97 
98 public:
99  void CompileFunc(StdCompiler *pComp);
100 };
101 
103 {
104 public:
106 
107 private:
108  StdCopyStrBuf Status;
109  StdCopyStrBuf CSID;
110  StdCopyStrBuf Message;
111 
112  // Auth
113  StdCopyStrBuf Account;
114  StdCopyStrBuf AUID;
115  StdCopyStrBuf FBID;
116  StdCopyStrBuf LoginToken;
117 
118 public:
119  const char *getCSID() const { return CSID.getData(); }
120  const char *getMessage() const { return Message.getData(); }
121  bool isSuccess() const { return SEqualNoCase(Status.getData(), "Success"); }
122  bool isStatusRegister() const { return SEqualNoCase(Status.getData(), "Register"); }
123  const char *getAccount() const { return Account.getData(); }
124  const char *getAUID() const { return AUID.getData(); }
125  const char *getFBID() const { return FBID.getData(); }
126  const char *getLoginToken() const { return LoginToken.getData(); }
127 
128  void CompileFunc(StdCompiler *pComp);
129 };
130 
132 {
133 private:
134  StdCopyStrBuf League;
135  StdCopyStrBuf StreamingAddr;
136  int32_t fHaveSeed;
137  int32_t iSeed;
138  int32_t iMaxPlayers;
139 
140 public:
141  const char *getLeague() const { return League.getData(); }
142  const char *getStreamingAddr() const { return StreamingAddr.getData(); }
143  bool haveSeed() const { return !!fHaveSeed; }
144  int32_t getSeed() const { return iSeed; }
145  int32_t getMaxPlayers() const { return iMaxPlayers; }
146 
147  void CompileFunc(StdCompiler *pComp);
148 };
149 
151 {
152 private:
153  StdCopyStrBuf League;
154  C4ClientPlayerInfos PlrInfos;
155 
156 public:
157  const char *getLeague() const { return League.getData(); }
158  const C4ClientPlayerInfos &GetPlrInfos() const { return PlrInfos; }
159 
160  void CompileFunc(StdCompiler *pComp);
161 };
162 
164 {
165 
166 private:
168  int32_t Scores[C4NetMaxLeagues];
169  int32_t Ranks[C4NetMaxLeagues];
170  int32_t RankSymbols[C4NetMaxLeagues];
171  StdCopyStrBuf ClanTag;
172  StdCopyStrBuf ProgressData;
173 
174 public:
175  int32_t getScore(const char *szLeague) const;
176  int32_t getRank(const char *szLeague) const;
177  int32_t getRankSymbol(const char *szLeague) const;
178  const char *getClanTag() const { return ClanTag.getData(); }
179  const char *getProgressData(const char *szLeague) const;
180 
181  void CompileFunc(StdCompiler *pComp);
182 };
183 
184 // a linked list of all known feedback IDs, associated to player IDs
186 {
187 private:
188  struct FBIDItem
189  {
190  StdCopyStrBuf Account;
191  StdCopyStrBuf FBID;
192  FBIDItem *pNext;
193  } *pFirst;
194 
195 public:
196  C4LeagueFBIDList() : pFirst(nullptr) {}
198  void Clear();
199  void RemoveFBIDByAccount(const char *szAccount);
200  bool FindFBIDByAccount(const char *szAccount, StdStrBuf *pFBIDOut);
201 
202  void AddFBID(const char *szFBID, const char *szAccount);
203 };
204 
206 {
207 
208 private:
209  StdCopyStrBuf CSID;
210  C4LeagueAction eCurrAction;
211  C4LeagueFBIDList FBIDList;
212 
213 public:
214  C4LeagueClient() : C4Network2RefClient(), CSID(), eCurrAction(C4LA_None) { }
215  const char *getCSID() const { return CSID.getData(); }
216  C4LeagueAction getCurrentAction() const { return eCurrAction; }
217  void ResetCurrentAction() { eCurrAction = C4LA_None; }
218 
219  // Action "Start"
220  bool Start(const C4Network2Reference &Ref);
221  bool GetStartReply(StdStrBuf *pMessage, StdStrBuf *pLeague, StdStrBuf *pStreamingAddr, int32_t *pSeed, int32_t *pMaxPlayers);
222 
223  // Action "Update"
224  bool Update(const C4Network2Reference &Ref);
225  bool GetUpdateReply(StdStrBuf *pMessage, C4ClientPlayerInfos *pPlayerLeagueInfos);
226 
227  // Action "End"
228  bool End(const C4Network2Reference &Ref, const char *szRecordName, const BYTE *pRecordSHA);
229  bool GetEndReply(StdStrBuf *pMessage, class C4RoundResultsPlayers *pRoundResults);
230 
231  // Action "Auth"
232  bool Auth(const C4PlayerInfo &PlrInfo, const char *szAccount, const char *szPassword, const char *szNewAccount = nullptr, const char *szNewPassword = nullptr, bool fRememberLogin = false);
233  bool GetAuthReply(StdStrBuf *pMessage, StdStrBuf *pAUID, StdStrBuf *pAccount, bool *pRegister, StdStrBuf *pLoginToken);
234 
235  // Action "Join"
236  bool AuthCheck(const C4PlayerInfo &PlrInfo);
237  bool GetAuthCheckReply(StdStrBuf *pMessage, const char *szLeague, class C4PlayerInfo *pPlrInfo);
238 
239  // Action "Disconnect" - sent by host and client when one or more clients are disconnected irregularly
240  bool ReportDisconnect(const C4ClientPlayerInfos &rSendPlayerFBIDs, C4LeagueDisconnectReason eReason);
241  bool GetReportDisconnectReply(StdStrBuf *pMessage);
242 };
243 
244 // dialog shown for each participating player to enter league authentication data
246 {
247 private:
248  C4GUI::CheckBox *pChkPassword, *pChkRememberLogin;
249  C4GUI::LabeledEdit *pEdtAccount, *pEdtPass, *pEdtPass2;
250  C4GUI::Button *pBtnOK, *pBtnAbort;
251  int32_t iEdtPassSpace;
252  StdStrBuf strPlayerName;
253  bool fRememberLogin;
254 public:
255  C4LeagueSignupDialog(const char *szPlayerName, const char *szLeagueName, const char *szLeagueServerName, const char *szAccountPref, const char *szPassPref, bool fWarnThirdParty, bool fRegister, bool fRememberLogin);
257 
258  const char *GetAccount() { return pEdtAccount->GetText(); }
259  bool HasPass() { return !pChkPassword || pChkPassword->GetChecked(); }
260  const char *GetPass() { return pEdtPass->GetText(); }
261  bool GetRememberLogin() { return pChkRememberLogin && pChkRememberLogin->GetChecked(); }
262 
263  // check for errors (overridden)
264  virtual void UserClose(bool fOK);
265 
266  // show modal league dialog to query password for player; return
267  static bool ShowModal(const char *szPlayerName, const char *szLeagueName, const char *szLeagueServerName, StdStrBuf *psAccount, StdStrBuf *psPass, bool fWarnThirdParty, bool fRegister, bool *pfRememberLogin);
268 
269 private:
270  void OnChkPassword();
271 };
272 
273 
274 #endif // C4LEAGUE_H_INCLUDED
const char * getClanTag() const
Definition: C4League.h:178
const char * getMessage() const
Definition: C4League.h:120
const char * getData() const
Definition: StdBuf.h:450
const char * GetText() const
Definition: C4Gui.h:1435
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:133
#define SHA_DIGEST_LENGTH
bool Auth(const C4PlayerInfo &PlrInfo, const char *szAccount, const char *szPassword, const char *szNewAccount=nullptr, const char *szNewPassword=nullptr, bool fRememberLogin=false)
Definition: C4League.cpp:406
virtual void UserClose(bool fOK)
Definition: C4League.cpp:603
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:76
bool GetUpdateReply(StdStrBuf *pMessage, C4ClientPlayerInfos *pPlayerLeagueInfos)
Definition: C4League.cpp:361
bool isSuccess() const
Definition: C4League.h:121
const char * GetPass()
Definition: C4League.h:260
const char * getStreamingAddr() const
Definition: C4League.h:142
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:92
void ResetCurrentAction()
Definition: C4League.h:217
C4LeagueAction
Definition: C4League.h:31
void RemoveFBIDByAccount(const char *szAccount)
Definition: C4League.cpp:221
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
const char * getLoginToken() const
Definition: C4League.h:126
const C4ClientPlayerInfos & GetPlrInfos() const
Definition: C4League.h:158
const char * getAUID() const
Definition: C4League.h:124
bool End(const C4Network2Reference &Ref, const char *szRecordName, const BYTE *pRecordSHA)
Definition: C4League.cpp:376
uint8_t BYTE
const char * getAccount() const
Definition: C4League.h:123
int32_t getRank(const char *szLeague) const
Definition: C4League.cpp:155
const char * getLeague() const
Definition: C4League.h:141
int32_t getMaxPlayers() const
Definition: C4League.h:145
bool GetAuthReply(StdStrBuf *pMessage, StdStrBuf *pAUID, StdStrBuf *pAccount, bool *pRegister, StdStrBuf *pLoginToken)
Definition: C4League.cpp:426
bool fOK
Definition: C4Gui.h:2082
C4LeagueDisconnectReason
Definition: C4Constants.h:143
const char * getCSID() const
Definition: C4League.h:215
int32_t getScore(const char *szLeague) const
Definition: C4League.cpp:147
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:28
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:177
bool GetRememberLogin()
Definition: C4League.h:261
bool isStatusRegister() const
Definition: C4League.h:122
const char * getFBID() const
Definition: C4League.h:125
bool AuthCheck(const C4PlayerInfo &PlrInfo)
Definition: C4League.cpp:456
void SetAuth(const char *szAccount, const char *szPassword, bool fRememberLogin)
Definition: C4League.cpp:57
bool GetAuthCheckReply(StdStrBuf *pMessage, const char *szLeague, class C4PlayerInfo *pPlrInfo)
Definition: C4League.cpp:472
void AddFBID(const char *szFBID, const char *szAccount)
Definition: C4League.cpp:238
const int32_t C4NetMaxLeagues
Definition: C4League.h:29
bool FindFBIDByAccount(const char *szAccount, StdStrBuf *pFBIDOut)
Definition: C4League.cpp:208
int32_t getSeed() const
Definition: C4League.h:144
bool GetEndReply(StdStrBuf *pMessage, class C4RoundResultsPlayers *pRoundResults)
Definition: C4League.cpp:391
bool Update(const C4Network2Reference &Ref)
Definition: C4League.cpp:346
bool haveSeed() const
Definition: C4League.h:143
void SetNewAccount(const char *szNewAccount)
Definition: C4League.cpp:64
void SetNewPassword(const char *szNewPassword)
Definition: C4League.cpp:69
bool GetChecked() const
Definition: C4Gui.h:1477
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:117
C4LeagueSignupDialog(const char *szPlayerName, const char *szLeagueName, const char *szLeagueServerName, const char *szAccountPref, const char *szPassPref, bool fWarnThirdParty, bool fRegister, bool fRememberLogin)
Definition: C4League.cpp:516
C4LeagueRequestHeadEnd(C4LeagueAction eAction, const char *szCSID, const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
Definition: C4League.h:87
bool Start(const C4Network2Reference &Ref)
Definition: C4League.cpp:299
bool ReportDisconnect(const C4ClientPlayerInfos &rSendPlayerFBIDs, C4LeagueDisconnectReason eReason)
Definition: C4League.cpp:486
bool GetStartReply(StdStrBuf *pMessage, StdStrBuf *pLeague, StdStrBuf *pStreamingAddr, int32_t *pSeed, int32_t *pMaxPlayers)
Definition: C4League.cpp:313
const char * getProgressData(const char *szLeague) const
Definition: C4League.cpp:171
const char * getLeague() const
Definition: C4League.h:157
bool GetReportDisconnectReply(StdStrBuf *pMessage)
Definition: C4League.cpp:501
static bool ShowModal(const char *szPlayerName, const char *szLeagueName, const char *szLeagueServerName, StdStrBuf *psAccount, StdStrBuf *psPass, bool fWarnThirdParty, bool fRegister, bool *pfRememberLogin)
Definition: C4League.cpp:662
C4LeagueAction getCurrentAction() const
Definition: C4League.h:216
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:102
int32_t getRankSymbol(const char *szLeague) const
Definition: C4League.cpp:163
C4LeagueRequestHead(C4LeagueAction eAction, const char *szCSID="", const char *szAUID="")
Definition: C4League.h:49
C4LeagueReportDisconnectHead(const char *szCSID, C4LeagueDisconnectReason eReason)
Definition: C4League.h:78
const char * getCSID() const
Definition: C4League.h:119
const char * GetAccount()
Definition: C4League.h:258