· 10 years ago · Aug 30, 2016, 03:22 PM
1<?php
2
3Aseco::registerEvent('onStartup', 'event2_startup');
4Aseco::registerEvent('onPlayerFinish', 'event2_finish');
5Aseco::registerEvent('onPlayerConnect', 'event2_playerjoin');
6Aseco::registerEvent('onPlayerManialinkPageAnswer', 'clicboutonBern');
7Aseco::addChatCommand('Bern', 'ligne de commande chat');
8
9function clicboutonBern($aseco, $command) {
10
11 $playerid = $command[0];
12 $login = $command[1];
13 $action = $command[2].'';
14
15 if ($action == '1357924681'){
16 $chat = array();
17 $chat[0] = $playerid;
18 $chat[1] = $login;
19 $chat[2] = '/Bern league 1 1';
20 $chat[3] = true;
21 $aseco->playerChat($chat);
22 }
23 if ($action == '13579246821'){
24 $chat = array();
25 $chat[0] = $playerid;
26 $chat[1] = $login;
27 $chat[2] = '/Bern league 2 1';
28 $chat[3] = true;
29 $aseco->playerChat($chat);
30 }
31 if ($action == '1357924682'){
32 $chat = array();
33 $chat[0] = $playerid;
34 $chat[1] = $login;
35 $chat[2] = '/Bern league 2 1';
36 $chat[3] = true;
37 $aseco->playerChat($chat);
38 }
39 if ($action == '13579246822'){
40 $chat = array();
41 $chat[0] = $playerid;
42 $chat[1] = $login;
43 $chat[2] = '/Bern league 2 2';
44 $chat[3] = true;
45 $aseco->playerChat($chat);
46 }
47 if ($action == '13579246831'){
48 $chat = array();
49 $chat[0] = $playerid;
50 $chat[1] = $login;
51 $chat[2] = '/Bern league 3 1';
52 $chat[3] = true;
53 $aseco->playerChat($chat);
54 }
55
56 if ($action == '13579246841'){
57 $chat = array();
58 $chat[0] = $playerid;
59 $chat[1] = $login;
60 $chat[2] = '/Bern league 4 1';
61 $chat[3] = true;
62 $aseco->playerChat($chat);
63 }
64 if ($action == '13579246851'){
65 $chat = array();
66 $chat[0] = $playerid;
67 $chat[1] = $login;
68 $chat[2] = '/Bern league 5 1';
69 $chat[3] = true;
70 $aseco->playerChat($chat);
71 }
72if ($action == '13579246861'){
73 $chat = array();
74 $chat[0] = $playerid;
75 $chat[1] = $login;
76 $chat[2] = '/Bern league 6 1';
77 $chat[3] = true;
78 $aseco->playerChat($chat);
79 }
80if ($action == '13579246862'){
81 $chat = array();
82 $chat[0] = $playerid;
83 $chat[1] = $login;
84 $chat[2] = '/Bern league 6 2';
85 $chat[3] = true;
86 $aseco->playerChat($chat);
87 }
88if ($action == '13579246863'){
89 $chat = array();
90 $chat[0] = $playerid;
91 $chat[1] = $login;
92 $chat[2] = '/Bern league 6 3';
93 $chat[3] = true;
94 $aseco->playerChat($chat);
95 }
96if ($action == '13579246864'){
97 $chat = array();
98 $chat[0] = $playerid;
99 $chat[1] = $login;
100 $chat[2] = '/Bern league 6 4';
101 $chat[3] = true;
102 $aseco->playerChat($chat);
103 }
104if ($action == '13579246865'){
105 $chat = array();
106 $chat[0] = $playerid;
107 $chat[1] = $login;
108 $chat[2] = '/Bern league 6 5';
109 $chat[3] = true;
110 $aseco->playerChat($chat);
111 }
112if ($action == '13579246866'){
113 $chat = array();
114 $chat[0] = $playerid;
115 $chat[1] = $login;
116 $chat[2] = '/Bern league 6 6';
117 $chat[3] = true;
118 $aseco->playerChat($chat);
119 }
120if ($action == '13579246867'){
121 $chat = array();
122 $chat[0] = $playerid;
123 $chat[1] = $login;
124 $chat[2] = '/Bern league 6 7';
125 $chat[3] = true;
126 $aseco->playerChat($chat);
127 }
128if ($action == '13579246868'){
129 $chat = array();
130 $chat[0] = $playerid;
131 $chat[1] = $login;
132 $chat[2] = '/Bern league 6 8';
133 $chat[3] = true;
134 $aseco->playerChat($chat);
135 }
136if ($action == '13579246869'){
137 $chat = array();
138 $chat[0] = $playerid;
139 $chat[1] = $login;
140 $chat[2] = '/Bern league 6 9';
141 $chat[3] = true;
142 $aseco->playerChat($chat);
143 }
144 if ($action == '9897969594'){
145 $chat = array();
146 $chat[0] = $playerid;
147 $chat[1] = $login;
148 $chat[2] = '/Bern quit';
149 $chat[3] = true;
150 $aseco->playerChat($chat);
151 }
152
153
154}
155 function chat_Bern($aseco, $command) {
156 global $competitionBern;
157
158 // Modif Claude : seulement si admin ou superadmin
159 //$admin = $command['author'];
160 //$login = $admin->login;
161 //if (($aseco->isAdminL($login)) or ($aseco->isMasterAdminL($login)))
162 // Fin modif Claude
163 $competitionBern->chat_Bern($aseco, $command);
164 }
165function event2_playerjoin($aseco, $data) { global $competitionBern; $competitionBern->onPlayerjoin2($aseco, $data); }
166function event2_startup($aseco, $command)
167 {
168 global $aseco;
169 global $competitionBern;
170 $competitionBern= new competitionBern();
171 $competitionBern->aseco = $aseco;
172 $query = 'CREATE TABLE IF NOT EXISTS `total_records` (
173 `playerID` mediumint(9) NOT NULL default 0,
174 `login` varchar(100) NOT NULL default 0,
175 `nickname` varchar(100) NOT NULL default 0,
176 `temps` int(9) NOT NULL default 15000000,
177 `bouge` mediumint(9) NOT NULL default 0,
178 `league` mediumint(9) NOT NULL default 6,
179 UNIQUE KEY `playerID` (`playerID`)
180 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;';
181mysql_query($query);
182
183
184}
185
186class competitionBern
187 {
188 public $aseco;
189 var $mapid = array();
190 function chat_Bern($aseco, $command) {
191 global $competitionBern;
192 $admin = $command['author'];
193 $login = $admin->login;
194 $nick = $admin->nickname;
195
196 $cmd = explode(' ', $command['params']);
197
198 if($cmd[0] == 'league') {
199 $numleague=$cmd[1];
200 $numpage=$cmd[2];
201 $xml = '<?xml version="1.0" encoding="UTF-8"?>
202 <manialinks>
203 <manialink id="1213141516">
204 <frame posn="-10 40 0">
205 <quad posn="0 0 0.001" sizen="20 4.4" style="BgsButtons" substyle="BgButtonLarge" />
206 <quad posn="2 -5 0.001" sizen="18 66" style="Bgs1" substyle="BgGlow2" />
207
208 <quad posn="0 0 0.001" sizen="4 4" style="BgRaceScore2" substyle="LadderRank" />
209 <label posn="7 -1 0.001" text="league '.$numleague.'" ></label>
210 <quad posn="15.6 0 0.001" sizen="4.6 4.6" style="Icons64x64_1" substyle="QuitRace" action="9897969594"/>';
211
212
213 if ($numleague==6){
214 $xml.=' <quad posn="2 -71 0.001" sizen="18 4.4" style="BgsButtons" substyle="BgButtonLarge" />
215 <label posn="9.2 -72.2 0.001" text="$000'.$numpage.' / 20" ></label>';
216
217 if ($numpage>1){
218 $xml.='<quad posn="3.6 -70.8 0.001" sizen="4.6 4.6" style="Icons64x64_1" substyle="ArrowPrev" action="'.($numpage+13579246859).'"/>';
219 }
220 if ($numpage<20){
221 $xml.='<quad posn="14 -70.8 0.001" sizen="4.6 4.6" style="Icons64x64_1" substyle="ArrowNext" action="'.($numpage+13579246861).'"/>';
222 }
223
224 }
225
226
227 $hauteur=-8;
228 $querymap456 = 'SELECT nickname, bouge from total_records where league='.$numleague.' order by temps asc LIMIT 20 OFFSET '.(($numpage-1)*20).'';
229 $res456 = mysql_query($querymap456);
230 $place=1;
231 while ($row = mysql_fetch_object($res456))
232 {
233 $nickname = str_replace(chr(39), "", $row->nickname);
234 $nickname = str_replace(chr(34), "", $row->nickname);
235 $xml .='<label posn="4 '.$hauteur.' 0.001" sizen="12 4" text="'.$nickname.'"></label>';
236 if ($row->bouge==-1){
237 $xml .='<quad posn="0.6 '.$hauteur.' 0.001" sizen="3 3" style="Copilot" substyle="DownWrong" />';
238 }
239 elseif ($row->bouge==1){
240 $xml .='<quad posn="0.6 '.$hauteur.' 0.001" sizen="3 3" style="Copilot" substyle="UpGood" />';
241 }
242 else{
243 $xml .='<quad posn="0.6 '.$hauteur.' 0.001" sizen="3 3" style="Copilot" substyle="Right" />';
244 }
245 $place++;
246 $hauteur=$hauteur-3;
247 }
248 $xml .='</frame>
249 </manialink>
250 </manialinks>';
251 $aseco->client->addCall("SendDisplayManialinkPageToLogin", array($login,$xml, 0, false));
252 }
253
254 if($cmd[0] == 'quit') {
255 $xml = '<?xml version="1.0" encoding="UTF-8"?>
256 <manialinks>
257 <manialink id="1213141516">
258 </manialink>
259 </manialinks>';
260 $aseco->client->addCall("SendDisplayManialinkPageToLogin", array($login,$xml, 0, false));
261 }
262 if($cmd[0] == 'ChangeLeague') {
263 if ($cmd[1] == 'Yes'){
264
265 mysql_query('update total_records set league=2, bouge=0 where league=1 and bouge=-1');
266 mysql_query('update total_records set league=1, bouge=0 where league=2 and bouge=1');
267 mysql_query('update total_records set league=3, bouge=0 where league=2 and bouge=-1');
268 mysql_query('update total_records set league=2, bouge=0 where league=3 and bouge=1');
269 mysql_query('update total_records set league=4, bouge=0 where league=3 and bouge=-1');
270 mysql_query('update total_records set league=3, bouge=0 where league=4 and bouge=1');
271 mysql_query('update total_records set league=5, bouge=0 where league=4 and bouge=-1');
272 mysql_query('update total_records set league=4, bouge=0 where league=5 and bouge=1');
273 mysql_query('update total_records set league=6, bouge=0 where league=5 and bouge=-1');
274 mysql_query('update total_records set league=5, bouge=0 where league=6 and bouge=1');
275 }
276 }
277 if($cmd[0] == 'EraseAll') {
278 if ($cmd[1] == 'Yes'){
279
280 mysql_query('update total_records set league=6, bouge=0');
281
282 }
283 }
284 if($cmd[0] == 'StartBern') {
285
286 if($cmd[1] == 'Yes') {
287 $querymap45 = 'SELECT playerID from total_records order by temps asc';
288 $res45 = mysql_query($querymap45);
289 $place=1;
290 $league=1;
291 while ($row = mysql_fetch_object($res45))
292 {
293
294 mysql_query('update total_records set league='.$league.', bouge=0 where playerID='.$row->playerID.'');
295 $place++;
296
297 if ($place>=11){
298 $league=2;
299 }
300 if ($place>=21){
301 $league=3;
302 }
303 if ($place>=31){
304 $league=4;
305 }
306 if ($place>=41){
307 $league=5;
308 }
309 if ($place>=51){
310 $league=6;
311 }
312
313 }
314 }
315 }
316
317
318 }
319
320
321function onFinish2($aseco, $finish_item) {
322$this->calcul_total_temps($aseco, $finish_item);
323 }
324function calcul_total_temps($aseco, $temps) {
325$pid = $this->aseco->getPlayerId($temps->player->login);
326$nombremap=0;
327$mapid = array();
328$aseco->client->query('GetMapList', 5000, 0);
329 $mapinfos = $aseco->client->getResponse();
330 foreach ($mapinfos as &$tinfo) {
331 $querymap1 = 'SELECT Id FROM maps where UId="'.$tinfo['UId'].'"';
332
333 $res1112 = mysql_query($querymap1);
334
335 while ($row = mysql_fetch_object($res1112))
336 {
337 $mapid[] = $row->Id;
338 $nombremap++;
339 }
340
341 }
342
343$penalite=$nombremap;
344$ttemps=0;
345$querymap = 'SELECT MapId as idmap, Score as tempstt FROM records
346 WHERE playerID=' . $pid;
347 $res111 = mysql_query($querymap);
348
349 while ($rowmap = mysql_fetch_assoc($res111))
350 {
351 for ($i = 0; $i <$nombremap; $i++)
352 {
353 if ($mapid[$i]==$rowmap['idmap'])
354 {
355 $penalite=$penalite-1;
356 $ttemps=$ttemps+$rowmap['tempstt'];
357 }
358 }
359 }
360
361 $ttemps=$ttemps+150000*$penalite;
362
363 $query222 = 'UPDATE total_records SET temps='.$ttemps.' WHERE playerID='.$pid;
364 mysql_query($query222);
365
366 mysql_query('update total_records set bouge=0');
367
368 // requète 3 derniers league 1 et 3 premiers league 2
369 $querymap456 = 'SELECT playerID, temps from total_records where league=1 order by temps desc limit 3';
370 $res456 = mysql_query($querymap456);
371 $querymap4567 = 'SELECT playerID, temps from total_records where league=2 order by temps asc limit 3';
372 $res4567 = mysql_query($querymap4567);
373
374 while (($row = mysql_fetch_object($res456)) && ($row2 = mysql_fetch_object($res4567)))
375 {
376 mysql_query('update total_records set bouge=1 where playerID='.$row2->playerID.'');
377 mysql_query('update total_records set bouge=-1 where playerID='.$row->playerID.'');
378 }
379 // requète 3 derniers league 2 et 3 premiers league 3
380 $querymap456 = 'SELECT playerID, temps from total_records where league=2 order by temps desc limit 3';
381 $res456 = mysql_query($querymap456);
382 $querymap4567 = 'SELECT playerID, temps from total_records where league=3 order by temps asc limit 3';
383 $res4567 = mysql_query($querymap4567);
384
385 while (($row = mysql_fetch_object($res456)) && ($row2 = mysql_fetch_object($res4567)))
386 {
387 mysql_query('update total_records set bouge=1 where playerID='.$row2->playerID.'');
388 mysql_query('update total_records set bouge=-1 where playerID='.$row->playerID.'');
389 }
390
391 // requète 3 derniers league 3 et 3 premiers league 4
392 $querymap456 = 'SELECT playerID, temps from total_records where league=3 order by temps desc limit 3';
393 $res456 = mysql_query($querymap456);
394 $querymap4567 = 'SELECT playerID, temps from total_records where league=4 order by temps asc limit 3';
395 $res4567 = mysql_query($querymap4567);
396
397 while (($row = mysql_fetch_object($res456)) && ($row2 = mysql_fetch_object($res4567)))
398 {
399 mysql_query('update total_records set bouge=1 where playerID='.$row2->playerID.'');
400 mysql_query('update total_records set bouge=-1 where playerID='.$row->playerID.'');
401 }
402
403 // requète 3 derniers league 4 et 3 premiers league 5
404 $querymap456 = 'SELECT playerID, temps from total_records where league=4 order by temps desc limit 3';
405 $res456 = mysql_query($querymap456);
406 $querymap4567 = 'SELECT playerID, temps from total_records where league=5 order by temps asc limit 3';
407 $res4567 = mysql_query($querymap4567);
408
409 while (($row = mysql_fetch_object($res456)) && ($row2 = mysql_fetch_object($res4567)))
410 {
411 mysql_query('update total_records set bouge=1 where playerID='.$row2->playerID.'');
412 mysql_query('update total_records set bouge=-1 where playerID='.$row->playerID.'');
413 }
414
415// requète 3 derniers league 5 et 3 premiers league 6
416 $querymap456 = 'SELECT playerID, temps from total_records where league=5 order by temps desc limit 3';
417 $res456 = mysql_query($querymap456);
418 $querymap4567 = 'SELECT playerID, temps from total_records where league=6 order by temps asc limit 3';
419 $res4567 = mysql_query($querymap4567);
420
421 while (($row = mysql_fetch_object($res456)) && ($row2 = mysql_fetch_object($res4567)))
422 {
423 mysql_query('update total_records set bouge=1 where playerID='.$row2->playerID.'');
424 mysql_query('update total_records set bouge=-1 where playerID='.$row->playerID.'');
425 }
426
427}
428
429function onPlayerjoin2($aseco, $player)
430 {
431 $xml = '<?xml version="1.0" encoding="UTF-8"?>
432 <manialinks>
433 <manialink id="6168496818450606984">
434 <frame posn="-22.2 47 0">
435 <label sizen="10 5" posn="-28 0 0.001" style="CardButtonMedium" text="$fffleague 1" action="1357924681" />
436 <label sizen="10 5" posn="-12 0 0.001" style="CardButtonMedium" text="$fffleague 2" action="1357924682" />
437 <label sizen="10 5" posn="4 0 0.001" style="CardButtonMedium" text="$fffleague 3" action="13579246831" />
438 <label sizen="10 5" posn="20 0 0.001" style="CardButtonMedium" text="$fffleague 4" action="13579246841" />
439 <label sizen="10 5" posn="36 0 0.001" style="CardButtonMedium" text="$fffleague 5" action="13579246851" />
440 <label sizen="10 5" posn="52 0 0.001" style="CardButtonMedium" text="$fffleague 6" action="13579246861" />
441 </frame>
442 </manialink>
443 </manialinks>';
444 $this->aseco->client->addCall("SendDisplayManialinkPageToLogin", array($player->login,$xml, 0, false));
445$pid = $this->aseco->getPlayerId($player->login);
446$query4 = 'SELECT temps FROM total_records where playerID=' . $pid;
447$req=mysql_query($query4);
448$nbre_lignes=mysql_num_rows($req);
449if ($nbre_lignes==0) {
450$query3 = 'INSERT INTO total_records (playerID, temps, login, nickname, league)
451 VALUES (' . $pid . ', 150000000, "'.$player->login.'",'.quotedString($player->nickname).', 6)';
452 mysql_query($query3);
453}
454else
455{
456$query2222 = 'UPDATE total_records SET nickname='.quotedString($player->nickname).' WHERE playerID='.$pid;
457 mysql_query($query2222);
458}
459mysql_free_result($req);
460}
461
462}
463function event2_finish($aseco, $data) { global $competitionBern; $competitionBern->onFinish2($aseco, $data); }
464?>