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