OpenClonk
C4Network2Reference.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 #ifndef C4NETWORK2REFERENCE_H
17 #define C4NETWORK2REFERENCE_H
18 
19 #include "C4Version.h"
21 #include "game/C4GameVersion.h"
22 #include "lib/C4InputValidation.h"
23 #include "network/C4Network2.h"
25 #include "network/C4HTTP.h"
26 
27 // Session data
29 {
30 public:
33 
34  // Game parameters
36 
37 private:
38  // General information
39  int32_t Icon{0};
41  StdCopyStrBuf GameMode; // Game mode (e.g. "Melee") to decide the correct league for evaluation
42  C4Network2Status GameStatus;
43  int32_t Time{0};
44  int32_t Frame{0};
45  int32_t StartTime{0};
46  int32_t LeaguePerformance{0}; // custom settlement league performance if scenario doesn't use elapsed frames
48  bool JoinAllowed{true};
49  bool ObservingAllowed{true};
50  bool PasswordNeeded{false};
51  bool OfficialServer{false};
52  bool IsEditor{false};
53  C4NetpuncherID NetpuncherGameID;
54  StdCopyStrBuf NetpuncherAddr;
55  StdCopyStrBuf Statistics;
56 
57  // Engine information
58  C4GameVersion Game;
59 
60  // Network addresses
61  uint8_t iAddrCnt{0};
64 
65 public:
66  const C4Network2Address &getAddr(int i) const { return Addrs[i]; }
67  C4Network2Address &getAddr(int i) { return Addrs[i]; }
68  int getAddrCnt() const { return iAddrCnt; }
69  const char *getTitle() const { return Title.getData(); }
70  int32_t getIcon() const { return Icon; }
71  C4Network2Status getGameStatus() const { return GameStatus; }
72  const char *getComment() const { return Comment.getData(); }
73  const C4GameVersion &getGameVersion() const { return Game; }
74  bool isPasswordNeeded() const { return PasswordNeeded; }
75  bool isJoinAllowed() const { return JoinAllowed; }
76  bool isOfficialServer() const { return OfficialServer; }
77  int32_t getSortOrder() const;
78  int32_t getTime() const { return Time; }
79  int32_t getStartTime() const { return StartTime; }
81  bool isEditor() const { return IsEditor; }
82  C4NetpuncherID getNetpuncherGameID() const { return NetpuncherGameID; }
83  StdStrBuf getNetpuncherAddr() const { return NetpuncherAddr; }
84 
86  const C4NetIO::EndpointAddress &GetSourceAddress() const { return source; }
87 
88  void InitLocal();
89 
90  void SortNullIPsBack();
91 
92  void CompileFunc(StdCompiler *pComp);
93 };
94 
95 // Serves references (mini-HTTP-server)
97 {
98 public:
100  ~C4Network2RefServer() override;
101 
102 private:
103  CStdCSec RefCSec;
104  C4Network2Reference *pReference{nullptr};
105 
106 public:
107  void Clear();
108  void SetReference(C4Network2Reference *pReference);
109 
110 protected:
111  // Overridden
112  void PackPacket(const C4NetIOPacket &rPacket, StdBuf &rOutBuf) override;
113  size_t UnpackPacket(const StdBuf &rInBuf, const C4NetIO::addr_t &addr) override;
114 
115 private:
116  // Responses
117  void RespondNotImplemented(const C4NetIO::addr_t &addr, const char *szMessage);
118  void RespondReference(const C4NetIO::addr_t &addr);
119 
120 };
121 
122 
123 // Loads current update url string (mini-HTTP-client)
125 {
126 public:
128 
129  bool QueryUpdateURL();
130  bool GetUpdateURL(StdStrBuf *pUpdateURL);
131  bool GetVersion(StdStrBuf *pVersion);
132 };
133 
134 // Loads references (mini-HTTP-client)
136 {
137 public:
139 
140  bool QueryReferences();
141  bool GetReferences(C4Network2Reference **&rpReferences, int32_t &rRefCount);
142 };
143 
144 #endif // C4NETWORK2REFERENCE_H
C4Game Game
Definition: C4Globals.cpp:52
const int32_t C4ClientMaxAddr
bool GetReferences(C4Network2Reference **&rpReferences, int32_t &rRefCount)
size_t UnpackPacket(const StdBuf &rInBuf, const C4NetIO::addr_t &addr) override
void SetReference(C4Network2Reference *pReference)
void PackPacket(const C4NetIOPacket &rPacket, StdBuf &rOutBuf) override
int32_t getTime() const
C4GameParameters Parameters
bool isPasswordNeeded() const
int32_t getSortOrder() const
void CompileFunc(StdCompiler *pComp)
const C4GameVersion & getGameVersion() const
const C4Network2Address & getAddr(int i) const
bool isOfficialServer() const
void SetSourceAddress(const C4NetIO::EndpointAddress &ip)
StdStrBuf getNetpuncherAddr() const
int32_t getStartTime() const
const char * getComment() const
StdStrBuf getGameGoalString() const
const char * getTitle() const
C4Network2Address & getAddr(int i)
const C4NetIO::EndpointAddress & GetSourceAddress() const
C4Network2Status getGameStatus() const
int32_t getIcon() const
C4NetpuncherID getNetpuncherGameID() const
bool GetVersion(StdStrBuf *pVersion)
bool GetUpdateURL(StdStrBuf *pUpdateURL)
Definition: StdBuf.h:30
const char * getData() const
Definition: StdBuf.h:442