5 * Copyright (C) 2009-2011 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
27 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1|
30 - update the STAT file with differential
36 ini_set("max_execution_time", "240");
38 require_once("../Obj/brisk.phh");
39 require_once("../Obj/auth.phh");
40 require_once("Obj/briskin5.phh");
41 require_once("Obj/placing.phh");
45 GLOBAL $pazz, $G_alarm_passwd;
52 if ($pazz != $G_alarm_passwd)
55 if (($fp = @fopen(LEGAL_PATH."/points.log", 'r')) == FALSE) {
56 echo "Open data file error";
61 if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'r')) != FALSE) {
62 $skip = intval(fgets($fp_start));
64 fseek($fp, $skip, SEEK_SET);
68 $userdb = new LoginDB();
70 for ($i = 0 ; $i < $userdb->count() ; $i++) {
71 $login = $userdb->getlogin_byidx($i);
72 $tri[$i] = new Ptsgam($login);
73 $mon[$i] = new Ptsgam($login);
74 $wee[$i] = new Ptsgam($login);
77 // recalculate all the placings
79 // 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1|
82 $bf = fgets($fp, 4096);
83 $ar = csplitter($bf, '|');
84 // if not auth table, continue
89 if ($ar[7] >= TABLES_AUTH_N)
91 // echo $p++." ".$ar[5]."<br>";
92 // if not FINISH_GAME line, continue
93 if ($ar[5] != "STAT:BRISKIN5:FINISH_GAME")
96 // if to much old points, continue
97 if ($ar[0] < $curtime - TRI_LIMIT) {
98 if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'w')) != FALSE) {
100 fwrite($fp_start, sprintf("%d\n", $curpos));
106 // echo $p++." ".BRISKIN5_PLAYERS_N."<br>";
110 for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) {
111 for ($e = $i + 1 ; $e < BRISKIN5_PLAYERS_N ; $e++) {
112 if ($ar[10+($i*2)] == $ar[10+($e*2)]) {
113 $mult = abs($ar[10+($i*2)]);
123 for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) {
124 // echo $p." i) ".$i."<br>";
125 $username = $ar[9+($i*2)];
126 if (($item = $userdb->getitem_bylogin($username, &$id)) == FALSE) {
127 echo "WARNING: the user [".$username."] NOT EXISTS!<br>";
131 // echo $item->login." id)".$id." ".$ar[10+($i*2)]." mult: ".$mult."<br>";
132 $tri[$id]->add($ar[10+($i*2)] / $mult);
133 if ($ar[0] >= $curtime - MON_LIMIT)
134 $mon[$id]->add($ar[10+($i*2)] / $mult);
135 if ($ar[0] >= $curtime - WEE_LIMIT)
136 $wee[$id]->add($ar[10+($i*2)] / $mult);
138 // $p++; echo $p++."<br>";
142 usort($tri, ptsgam_cmp);
143 usort($mon, ptsgam_cmp);
144 usort($wee, ptsgam_cmp);
146 echo "<br><br>TRI<br>\n";
148 if (($fplo = @fopen(LEGAL_PATH."/class_tri_lo.log", 'w')) == FALSE) {
149 echo "Open tri_lo failed<br>";
152 if (($fphi = @fopen(LEGAL_PATH."/class_tri_hi.log", 'w')) == FALSE) {
153 echo "Open tri_hi failed<br>";
157 for ($i = 0 ; $i < count($tri) ; $i++) {
158 if ($tri[$i]->gam == 0.0)
160 printf("%s: %s (%d) <br>\n", $tri[$i]->username, $tri[$i]->snormpts(), $tri[$i]->gam);
161 if ($tri[$i]->gam >= TRI_MAX_GAMES)
162 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam));
163 else if ($tri[$i]->gam > TRI_MIN_GAMES)
164 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam));
169 echo "<br><br>MON<br>\n";
171 if (($fplo = @fopen(LEGAL_PATH."/class_mon_lo.log", 'w')) == FALSE) {
172 echo "Open tri_lo failed<br>";
175 if (($fphi = @fopen(LEGAL_PATH."/class_mon_hi.log", 'w')) == FALSE) {
176 echo "Open tri_hi failed<br>";
180 for ($i = 0 ; $i < count($mon) ; $i++) {
181 if ($mon[$i]->gam == 0.0)
183 printf("%s: %s (%d) <br>\n", $mon[$i]->username, $mon[$i]->snormpts(), $mon[$i]->gam);
184 if ($mon[$i]->gam >= MON_MAX_GAMES)
185 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam));
186 else if ($mon[$i]->gam > MON_MIN_GAMES)
187 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam));
192 echo "<br><br>WEE<br>\n";
193 if (($fplo = @fopen(LEGAL_PATH."/class_wee_lo.log", 'w')) == FALSE) {
194 echo "Open wee_lo failed<br>";
197 if (($fphi = @fopen(LEGAL_PATH."/class_wee_hi.log", 'w')) == FALSE) {
198 echo "Open wee_hi failed<br>";
202 for ($i = 0 ; $i < count($wee) ; $i++) {
203 if ($wee[$i]->gam == 0.0)
205 printf("%s: %s (%d) <br>\n", $wee[$i]->username, $wee[$i]->snormpts(), $wee[$i]->gam);
206 if ($wee[$i]->gam >= WEE_MAX_GAMES)
207 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam));
208 else if ($wee[$i]->gam > WEE_MIN_GAMES)
209 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam));