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