OpenClonk
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 
22 #include "lib/SHA1.h"
23 #include "gui/C4Gui.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:
105  C4LeagueResponseHead() = default;
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{nullptr};
194 
195 public:
196  C4LeagueFBIDList() = default;
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{C4LA_None};
211  C4LeagueFBIDList FBIDList;
212 
213 public:
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 public:
254  C4LeagueSignupDialog(const char *szPlayerName, const char *szLeagueName, const char *szLeagueServerName, const char *szAccountPref, const char *szPassPref, bool fWarnThirdParty, bool fRegister, bool fRememberLogin);
255  ~C4LeagueSignupDialog() override = default;
256 
257  const char *GetAccount() { return pEdtAccount->GetText(); }
258  bool HasPass() { return !pChkPassword || pChkPassword->GetChecked(); }
259  const char *GetPass() { return pEdtPass->GetText(); }
260  bool GetRememberLogin() { return pChkRememberLogin && pChkRememberLogin->GetChecked(); }
261 
262  // check for errors (overridden)
263  void UserClose(bool fOK) override;
264 
265  // show modal league dialog to query password for player; return
266  static bool ShowModal(const char *szPlayerName, const char *szLeagueName, const char *szLeagueServerName, StdStrBuf *psAccount, StdStrBuf *psPass, bool fWarnThirdParty, bool fRegister, bool *pfRememberLogin);
267 
268 private:
269  void OnChkPassword();
270 };
271 
272 
273 #endif // C4LEAGUE_H_INCLUDED
C4LeagueDisconnectReason
Definition: C4Constants.h:143
C4LeagueAction
Definition: C4League.h:32
@ C4LA_None
Definition: C4League.h:33
@ C4LA_RefQuery
Definition: C4League.h:40
@ C4LA_PlrAuthCheck
Definition: C4League.h:38
@ C4LA_ReportDisconnect
Definition: C4League.h:43
@ C4LA_Update
Definition: C4League.h:36
@ C4LA_PlrAuth
Definition: C4League.h:41
@ C4LA_End
Definition: C4League.h:37
@ C4LA_Start
Definition: C4League.h:35
const int32_t C4NetMaxLeagues
Definition: C4League.h:29
uint8_t BYTE
#define SHA_DIGEST_LENGTH
Definition: SHA1.h:42
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
bool GetChecked() const
Definition: C4Gui.h:1478
bool fOK
Definition: C4Gui.h:2083
const char * GetText() const
Definition: C4Gui.h:1436
C4LeagueAction getCurrentAction() const
Definition: C4League.h:216
bool Start(const C4Network2Reference &Ref)
Definition: C4League.cpp:298
bool GetAuthReply(StdStrBuf *pMessage, StdStrBuf *pAUID, StdStrBuf *pAccount, bool *pRegister, StdStrBuf *pLoginToken)
Definition: C4League.cpp:425
bool GetStartReply(StdStrBuf *pMessage, StdStrBuf *pLeague, StdStrBuf *pStreamingAddr, int32_t *pSeed, int32_t *pMaxPlayers)
Definition: C4League.cpp:312
bool GetReportDisconnectReply(StdStrBuf *pMessage)
Definition: C4League.cpp:500
bool GetAuthCheckReply(StdStrBuf *pMessage, const char *szLeague, class C4PlayerInfo *pPlrInfo)
Definition: C4League.cpp:471
const char * getCSID() const
Definition: C4League.h:215
void ResetCurrentAction()
Definition: C4League.h:217
bool ReportDisconnect(const C4ClientPlayerInfos &rSendPlayerFBIDs, C4LeagueDisconnectReason eReason)
Definition: C4League.cpp:485
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:405
bool GetEndReply(StdStrBuf *pMessage, class C4RoundResultsPlayers *pRoundResults)
Definition: C4League.cpp:390
bool Update(const C4Network2Reference &Ref)
Definition: C4League.cpp:345
bool GetUpdateReply(StdStrBuf *pMessage, C4ClientPlayerInfos *pPlayerLeagueInfos)
Definition: C4League.cpp:360
bool AuthCheck(const C4PlayerInfo &PlrInfo)
Definition: C4League.cpp:455
bool End(const C4Network2Reference &Ref, const char *szRecordName, const BYTE *pRecordSHA)
Definition: C4League.cpp:375
void RemoveFBIDByAccount(const char *szAccount)
Definition: C4League.cpp:220
bool FindFBIDByAccount(const char *szAccount, StdStrBuf *pFBIDOut)
Definition: C4League.cpp:207
void AddFBID(const char *szFBID, const char *szAccount)
Definition: C4League.cpp:237
C4LeagueFBIDList()=default
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:75
C4LeagueReportDisconnectHead(const char *szCSID, C4LeagueDisconnectReason eReason)
Definition: C4League.h:78
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:91
C4LeagueRequestHeadEnd(C4LeagueAction eAction, const char *szCSID, const char *szRecordName=nullptr, const BYTE *pRecordSHA=nullptr)
Definition: C4League.h:87
C4LeagueRequestHead(C4LeagueAction eAction, const char *szCSID="", const char *szAUID="")
Definition: C4League.h:49
void SetNewPassword(const char *szNewPassword)
Definition: C4League.cpp:68
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:27
void SetAuth(const char *szAccount, const char *szPassword, bool fRememberLogin)
Definition: C4League.cpp:56
void SetNewAccount(const char *szNewAccount)
Definition: C4League.cpp:63
int32_t getRank(const char *szLeague) const
Definition: C4League.cpp:154
int32_t getRankSymbol(const char *szLeague) const
Definition: C4League.cpp:162
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:176
const char * getClanTag() const
Definition: C4League.h:178
int32_t getScore(const char *szLeague) const
Definition: C4League.cpp:146
const char * getProgressData(const char *szLeague) const
Definition: C4League.cpp:170
bool isSuccess() const
Definition: C4League.h:121
bool isStatusRegister() const
Definition: C4League.h:122
const char * getAUID() const
Definition: C4League.h:124
C4LeagueResponseHead()=default
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:101
const char * getFBID() const
Definition: C4League.h:125
const char * getAccount() const
Definition: C4League.h:123
const char * getLoginToken() const
Definition: C4League.h:126
const char * getCSID() const
Definition: C4League.h:119
const char * getMessage() const
Definition: C4League.h:120
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:116
const char * getStreamingAddr() const
Definition: C4League.h:142
const char * getLeague() const
Definition: C4League.h:141
bool haveSeed() const
Definition: C4League.h:143
int32_t getSeed() const
Definition: C4League.h:144
int32_t getMaxPlayers() const
Definition: C4League.h:145
const C4ClientPlayerInfos & GetPlrInfos() const
Definition: C4League.h:158
const char * getLeague() const
Definition: C4League.h:157
void CompileFunc(StdCompiler *pComp)
Definition: C4League.cpp:132
void UserClose(bool fOK) override
Definition: C4League.cpp:602
~C4LeagueSignupDialog() override=default
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:661
const char * GetPass()
Definition: C4League.h:259
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:515
const char * GetAccount()
Definition: C4League.h:257
bool GetRememberLogin()
Definition: C4League.h:260
const char * getData() const
Definition: StdBuf.h:442