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