Debian Codegraph @

src/bnetd/ladder.h

raw symbols SCIP
1 /*
2 * Copyright (C) 1999 Rob Crittenden ([email protected])
3 * Copyright (C) 1999,2000 Ross Combs ([email protected])
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #ifndef INCLUDED_LADDER_TYPES
20 #define INCLUDED_LADDER_TYPES
21
22 #include "account.h"
23 #include "common/tag.h"
24 #include <vector>
25 #include <list>
26 #include <map>
27 #include <string>
28 #include <utility>
29
30 #define W3_XPCALC_MAXLEVEL 65
31
32 namespace pvpgn
33 {
34
35 namespace bnetd
36 {
37
38
39 typedef enum
40 {
41 ladder_sort_highestrated,
42 ladder_sort_mostwins,
43 ladder_sort_mostgames,
44 ladder_sort_default
45 } t_ladder_sort;
46
47 extern const std::vector<std::string> bin_ladder_sort_str;
48
49 typedef enum
50 {
51 ladder_time_active,
52 ladder_time_current,
53 ladder_time_default
54 } t_ladder_time;
55
56 extern const std::vector<std::string> bin_ladder_time_str;
57
58 typedef enum
59 {
60 ladder_id_none = 0,
61 ladder_id_normal = 1,
62 ladder_id_ironman = 3,
63 ladder_id_solo = 5,
64 ladder_id_team = 6,
65 ladder_id_ffa = 7,
66 ladder_id_ateam = 8
67 } t_ladder_id;
68
69 const extern std::vector<std::string> ladder_id_str;
70 const extern std::vector<std::string> bin_ladder_id_str;
71
72 typedef enum
73 {
74 ladder_option_none = 0,
75 ladder_option_disconnectisloss = 1
76 } t_ladder_option;
77
78 typedef enum { referenceTypeAccount, referenceTypeTeam, referenceTypeClan } t_referenceType;
79
80 class LadderKey
81 {
82 public:
83 LadderKey(t_ladder_id ladderId_, t_clienttag clienttag_, t_ladder_sort ladderSort_, t_ladder_time ladderTime_);
84 ~LadderKey() throw ();
85 bool operator== (const LadderKey& right) const;
86 bool operator< (const LadderKey& right) const;
87 t_ladder_id getLadderId() const;
88 t_clienttag getClienttag() const;
89 t_ladder_sort getLadderSort() const;
90 t_ladder_time getLadderTime() const;
91 LadderKey getOpposingKey() const;
92 private:
93 t_ladder_id ladderId;
94 t_clienttag clienttag;
95 t_ladder_sort ladderSort;
96 t_ladder_time ladderTime;
97 };
98
99 class LadderReferencedObject
100 {
101 public:
102 explicit LadderReferencedObject(t_account *account_);
103 explicit LadderReferencedObject(t_team *team_);
104 ~LadderReferencedObject() throw ();
105 bool getData(const LadderKey& ladderKey_, unsigned int& uid, unsigned int& primary_, unsigned int& secondary_, unsigned int& tertiary_) const;
106 unsigned int getRank(const LadderKey& ladderKey_) const;
107 bool setRank(const LadderKey& ladderKey_, unsigned int rank_) const;
108 t_account* getAccount() const;
109 t_team* getTeam() const;
110 void activate(const LadderKey& ladderKey_) const;
111 const t_referenceType getReferenceType() const;
112 private:
113
114 t_referenceType referenceType;
115 t_account * account;
116 t_team * team;
117 };
118
119 class LadderEntry
120 {
121 public:
122 LadderEntry(unsigned int uid_, unsigned int primary_, unsigned int secondary_, unsigned int tertiary_, LadderReferencedObject referencedObject_);
123 ~LadderEntry() throw ();
124 unsigned int getUid() const;
125 unsigned int getPrimary() const;
126 unsigned int getSecondary() const;
127 unsigned int getTertiary() const;
128 unsigned int getRank() const;
129 const LadderReferencedObject& getReferencedObject() const;
130 bool setRank(unsigned int rank_, const LadderKey& ladderKey_);
131 void update(unsigned int primary_, unsigned int secondary_, unsigned int tertiary_);
132 std::string status() const;
133 bool operator== (const LadderEntry& right) const;
134 bool operator< (const LadderEntry& right) const;
135 private:
136 unsigned int uid;
137 unsigned int primary;
138 unsigned int secondary;
139 unsigned int tertiary;
140 unsigned int rank;
141 LadderReferencedObject referencedObject;
142 };
143
144 class LadderList
145 {
146 public:
147 explicit LadderList(LadderKey ladderkey_, t_referenceType referenceType_);
148 ~LadderList() throw ();
149 bool load();
150 bool save();
151 void addEntry(unsigned int uid_, unsigned int primary_, unsigned int secondary_, unsigned int tertiary_, const LadderReferencedObject& referencedObject_);
152 void updateEntry(unsigned int uid_, unsigned int primary_, unsigned int secondary_, unsigned int tertiary_, const LadderReferencedObject& referencedObject_);
153 bool delEntry(unsigned int uid_);
154 const LadderKey& getLadderKey() const;
155 const t_referenceType getReferenceType() const;
156 void sortAndUpdate();
157 const LadderReferencedObject* getReferencedObject(unsigned int rank) const;
158 unsigned int getRank(unsigned int uid_) const;
159 void activateFrom(const LadderList * currentLadder_);
160 void writeStatusfile() const;
161
162 private:
163 typedef std::vector<LadderEntry> LList;
164 LadderKey ladderKey;
165 LList ladder;
166 bool dirty;
167 bool saved;
168 std::string ladderFilename;
169 t_referenceType referenceType;
170 bool loadBinary();
171 bool saveBinary();
172 void readdata(std::ifstream &fp, unsigned int &data);
173 void readdata(std::ifstream &fp, unsigned int data[], unsigned int membercount);
174 void writedata(std::ofstream &fp, unsigned int &data);
175 void writedata(std::ofstream &fp, const unsigned int &data);
176 void writedata(std::ofstream &fp, unsigned int data[], unsigned int membercount);
177
178 };
179
180 class Ladders
181 {
182 public:
183 Ladders();
184 ~Ladders() throw ();
185 LadderList* getLadderList(const LadderKey& ladderKey_);
186 void load();
187 void update();
188 void activate();
189 void save();
190 void status() const;
191 private:
192 void rebuild(std::list<LadderList*>& laddersToRebuild);
193 typedef std::map<LadderKey, LadderList> KeyLadderMap;
194 KeyLadderMap ladderMap;
195 };
196
197
198 extern Ladders ladders;
199
200
201 #ifdef LADDER_INTERNAL_ACCESS
202
203 typedef struct
204 {
205 int startxp, neededxp, lossfactor, mingames;
206 } t_xplevel_entry;
207
208 typedef struct
209 {
210 int higher_winxp, higher_lossxp, lower_winxp, lower_lossxp;
211 } t_xpcalc_entry;
212 #endif
213
214
215 }
216
217 }
218
219 #endif
220
221 /*****/
222 #ifndef JUST_NEED_TYPES
223 #ifndef INCLUDED_LADDER_PROTOS
224 #define INCLUDED_LADDER_PROTOS
225
226 #define JUST_NEED_TYPES
227 #include "account.h"
228 #include "game.h"
229 #include "ladder_calc.h"
230 #include "common/tag.h"
231 #undef JUST_NEED_TYPES
232
233 namespace pvpgn
234 {
235
236 namespace bnetd
237 {
238
239 extern int ladder_update(t_clienttag clienttag, t_ladder_id id, unsigned int count, t_account * * players, t_game_result * results, t_ladder_info * info);
240 extern int ladder_update_wol(t_clienttag clienttag, t_ladder_id id, t_account * * players, t_game_result * results);
241
242 extern int ladder_init_account(t_account * account, t_clienttag clienttag, t_ladder_id id);
243 extern int ladder_init_account_wol(t_account * account, t_clienttag clienttag, t_ladder_id id);
244
245 extern int ladder_check_map(char const * mapname, t_game_maptype maptype, t_clienttag clienttag);
246
247
248 extern int ladder_createxptable(const char *xplevelfile, const char *xpcalcfile);
249 extern void ladder_destroyxptable(void);
250
251 extern int ladder_war3_xpdiff(unsigned int winnerlevel, unsigned int looserlevel, int *, int *);
252 extern int ladder_war3_updatelevel(unsigned int oldlevel, int xp);
253 extern int ladder_war3_get_min_xp(unsigned int level);
254 extern int war3_get_maxleveldiff(void);
255
256
257 extern void ladder_reload_conf(void);
258 /* reloads relevant parameters from bnetd.conf (xml/std mode for ladder) */
259 }
260
261 }
262
263 #endif
264 #endif