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