]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/getreplies.qc
Some more defs.qh cleanup, update gameplay hash
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / getreplies.qc
1 #include "getreplies.qh"
2
3 #include <server/defs.qh>
4 #include <server/g_world.qh>
5 #include <server/miscfunctions.qh>
6
7 #include <common/command/_mod.qh>
8 #include "getreplies.qh"
9
10 #include "../race.qh"
11
12 #include <common/constants.qh>
13 #include <common/gamemodes/_mod.qh>
14 #include <common/net_linked.qh>
15 #include <common/util.qh>
16
17 #include <common/monsters/_mod.qh>
18
19 // =========================================================
20 //  Reply messages for common commands, re-worked by Samual
21 //  Last updated: December 30th, 2011
22 // =========================================================
23
24 // These strings are set usually during init in g_world.qc,
25 // or also by some game modes or other functions manually,
26 // and their purpose is to output information to clients
27 // without using any extra processing time.
28
29 // See common.qc for their proper commands
30
31 string getrecords(int page)  // 50 records per page
32 {
33         string s = "";
34
35         MUTATOR_CALLHOOK(GetRecords, page, s);
36         s = M_ARGV(1, string);
37
38         MapInfo_ClearTemps();
39
40         if (s == "" && page == 0)
41                 return "No records are available on this server for the current game mode.\n";
42         return s;
43 }
44
45 string getrankings()
46 {
47         float t, i;
48         string n, s, p, map;
49
50         map = GetMapname();
51
52         s = "";
53         for (i = 1; i <= RANKINGS_CNT; ++i)
54         {
55                 t = race_readTime(map, i);
56
57                 if (t == 0) continue;
58
59                 n = race_readName(map, i);
60                 p = count_ordinal(i);
61                 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
62         }
63
64         MapInfo_ClearTemps();
65
66         if (s == "") return strcat("No records are available for the map: ", map, "\n");
67         else return strcat("Records for ", map, ":\n", s);
68 }
69
70 string getladder()
71 {
72         int i, j, k, uidcnt = 0, thiscnt;
73         string s, temp_s, rr, myuid, thisuid;
74
75         rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
76
77         for (k = 0; k < MapInfo_count; ++k)
78         {
79                 if (MapInfo_Get_ByID(k))
80                 {
81                         for (i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award
82                         {
83                                 if (i == 0)                   // speed award
84                                 {
85                                         if (stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) continue;
86
87                                         myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp"));
88                                 }
89                                 else  // normal record, if it exists (else break)
90                                 {
91                                         if (race_readTime(MapInfo_Map_bspname, i) == 0) continue;
92
93                                         myuid = race_readUID(MapInfo_Map_bspname, i);
94                                 }
95
96                                 // string s contains:
97                                 // arg 0 = # of speed recs
98                                 // arg 1 = # of 1st place recs
99                                 // arg 2 = # of 2nd place recs
100                                 // ... etc
101                                 // LADDER_CNT+1 = total points
102
103                                 temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
104
105                                 if (temp_s == "")
106                                 {
107                                         db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
108                                         ++uidcnt;
109
110                                         for (j = 0; j <= LADDER_CNT + 1; ++j)
111                                         {
112                                                 if (j != LADDER_CNT + 1) temp_s = strcat(temp_s, "0 ");
113                                                 else temp_s = strcat(temp_s, "0");
114                                         }
115                                 }
116
117                                 tokenize_console(temp_s);
118                                 s = "";
119
120                                 if (i == 0)                                         // speed award
121                                 {
122                                         for (j = 0; j <= LADDER_CNT; ++j)               // loop over each arg in the string
123                                         {
124                                                 if (j == 0)                                 // speed award
125                                                         s = strcat(s, ftos(stof(argv(j)) + 1)); // add 1 to speed rec count and write
126                                                 else s = strcat(s, " ", argv(j));           // just copy over everything else
127                                         }
128                                 }
129                                 else  // record
130                                 {
131                                         for (j = 0; j <= LADDER_CNT; ++j)                    // loop over each arg in the string
132                                         {
133                                                 if (j == 0) s = strcat(s, argv(j));              // speed award, dont prefix with " "
134                                                 else if (j == i)                                 // wanted rec!
135                                                         s = strcat(s, " ", ftos(stof(argv(j)) + 1)); // update argv(j)
136                                                 else s = strcat(s, " ", argv(j));                // just copy over everything else
137                                         }
138                                 }
139
140                                 // total points are (by default) calculated like this:
141                                 // speedrec = floor(100 / 10) = 10 points
142                                 // 1st place = floor(100 / 1) = 100 points
143                                 // 2nd place = floor(100 / 2) = 50 points
144                                 // 3rd place = floor(100 / 3) = 33 points
145                                 // 4th place = floor(100 / 4) = 25 points
146                                 // 5th place = floor(100 / 5) = 20 points
147                                 // ... etc
148
149                                 if (i == 0) s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
150                                 else s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + floor(LADDER_FIRSTPOINT / i)));  // record, add LADDER_FIRSTPOINT / i points
151
152                                 db_put(TemporaryDB, strcat("ladder", myuid), s);
153                         }
154                 }
155         }
156
157         for (i = 0; i <= uidcnt; ++i)  // for each known uid
158         {
159                 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
160                 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
161                 tokenize_console(temp_s);
162                 thiscnt = stof(argv(LADDER_CNT + 1));
163
164                 if (thiscnt > top_scores[LADDER_SIZE - 1])
165                 {
166                         for (j = 0; j < LADDER_SIZE; ++j)  // for each place in ladder
167                         {
168                                 if (thiscnt > top_scores[j])
169                                 {
170                                         for (k = LADDER_SIZE - 1; k >= j; --k)
171                                         {
172                                                 top_uids[k] = top_uids[k - 1];
173                                                 top_scores[k] = top_scores[k - 1];
174                                         }
175
176                                         top_uids[j] = thisuid;
177                                         top_scores[j] = thiscnt;
178                                         break;
179                                 }
180                         }
181                 }
182         }
183
184         s = "^3-----------------------\n\n";
185
186         s = strcat(s, "Pos ^3|");
187         s = strcat(s, " ^7Total  ^3|");
188
189         for (i = 1; i <= LADDER_CNT; ++i)
190                 s = strcat(s, " ^7", count_ordinal(i), " ^3|");
191         s = strcat(s, " ^7Speed awards ^3| ^7Name");
192         s = strcat(s, "\n^3----+--------");
193
194         for (i = 1; i <= min(9, LADDER_CNT); ++i)
195                 s = strcat(s, "+-----");
196 #if LADDER_CNT > 9
197                 for (i = 1; i <= LADDER_CNT - 9; ++i)
198                         s = strcat(s, "+------");
199 #endif
200
201         s = strcat(s, "+--------------+--------------------\n");
202
203         for (i = 0; i < LADDER_SIZE; ++i)
204         {
205                 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
206                 tokenize_console(temp_s);
207
208                 if (argv(LADDER_CNT + 1) == "")                           // total is 0, skip
209                         continue;
210
211                 s = strcat(s, strpad(4, count_ordinal(i + 1)), "^3| ^7"); // pos
212                 s = strcat(s, strpad(7, argv(LADDER_CNT + 1)), "^3| ^7"); // total
213
214                 for (j = 1; j <= min(9, LADDER_CNT); ++j)
215                         s = strcat(s, strpad(4, argv(j)), "^3| ^7");          // 1st, 2nd, 3rd etc cnt
216
217 #if LADDER_CNT > 9
218                         for (j = 10; j <= LADDER_CNT; ++j)
219                                 s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt
220 #endif
221
222                 s = strcat(s, strpad(13, argv(0)), "^3| ^7");         // speed award cnt
223                 s = strcat(s, uid2name(top_uids[i]), "\n");           // name
224         }
225
226         MapInfo_ClearTemps();
227
228         if (s == "") return "No ladder on this server!\n";
229         else return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
230 }
231
232 string getmaplist()
233 {
234         string maplist = "", col;
235         int i, argc;
236
237         argc = tokenize_console(autocvar_g_maplist);
238         for (i = 0; i < argc; ++i)
239         {
240                 if (MapInfo_CheckMap(argv(i)))
241                 {
242                         if (i % 2) col = "^2"; else col = "^3";
243                         maplist = sprintf("%s%s%s ", maplist, col, argv(i));
244                 }
245         }
246
247         MapInfo_ClearTemps();
248         return sprintf("^7Maps in list: %s\n", maplist);
249 }
250
251 const int LSMAPS_MAX = 250;
252 string getlsmaps()
253 {
254         string lsmaps = "", col;
255         bool newmaps = false;
256         int added = 0;
257
258         for (int i = 0; i < MapInfo_count; ++i)
259         {
260                 if ((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags()))
261                 {
262                         ++added;
263
264                         if(added > LSMAPS_MAX)
265                                 continue; // we still get the added count, but skip the actual processing
266
267                         // todo: Check by play count of maps for other game types?
268                         if((g_race || g_cts) && !race_readTime(MapInfo_Map_bspname, 1))
269                         {
270                                 newmaps = true;
271                                 if (i % 2) col = "^4*"; else col = "^5*";
272                         }
273                         else
274                         {
275                                 if (i % 2) col = "^2"; else col = "^3";
276                         }
277
278                         lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname);
279                 }
280         }
281
282         if(added > LSMAPS_MAX)
283                 lsmaps = sprintf("%s^7(%d not listed)", lsmaps, added - LSMAPS_MAX);
284
285         MapInfo_ClearTemps();
286         return sprintf("^7Maps available (%d)%s: %s\n", added, (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps);
287 }
288
289 string getmonsterlist()
290 {
291         string monsterlist = "";
292
293         FOREACH(Monsters, it != MON_Null && !(it.spawnflags & MON_FLAG_HIDDEN),
294         {
295                 string col = ((i % 2) ? "^2" : "^3");
296                 monsterlist = sprintf("%s%s%s ", monsterlist, col, it.netname);
297         });
298
299         return sprintf("^7Monsters available: %s\n", monsterlist);
300 }