5 * Copyright (C) 2009 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.
29 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1|
32 - update the STAT file with differential
38 ini_set("max_execution_time", "240");
40 require_once("../Obj/brisk.phh");
41 require_once("../Obj/auth.phh");
42 require_once("Obj/briskin5.phh");
43 require_once("Obj/placing.phh");
47 GLOBAL $pazz, $G_alarm_passwd;
54 if ($pazz != $G_alarm_passwd)
57 if (($fp = @fopen(LEGAL_PATH."/points.log", 'r')) == FALSE) {
58 echo "Open data file error";
63 if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'r')) != FALSE) {
64 $skip = intval(fgets($fp_start));
66 fseek($fp, $skip, SEEK_SET);
70 $userdb = new LoginDB();
72 for ($i = 0 ; $i < $userdb->count() ; $i++) {
73 $login = $userdb->getlogin_byidx($i);
74 $tri[$i] = new Ptsgam($login);
75 $mon[$i] = new Ptsgam($login);
76 $wee[$i] = new Ptsgam($login);
79 // recalculate all the placings
81 // 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1|
84 $bf = fgets($fp, 4096);
85 $ar = csplitter($bf, '|');
86 // if not auth table, continue
91 if ($ar[7] >= TABLES_AUTH_N)
93 // echo $p++." ".$ar[5]."<br>";
94 // if not FINISH_GAME line, continue
95 if ($ar[5] != "STAT:BRISKIN5:FINISH_GAME")
98 // if to much old points, continue
99 if ($ar[0] < $curtime - TRI_LIMIT) {
100 if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'w')) != FALSE) {
101 $curpos = ftell($fp);
102 fwrite($fp_start, sprintf("%d\n", $curpos));
108 // echo $p++." ".BRISKIN5_PLAYERS_N."<br>";
112 for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) {
113 for ($e = $i + 1 ; $e < BRISKIN5_PLAYERS_N ; $e++) {
114 if ($ar[10+($i*2)] == $ar[10+($e*2)]) {
115 $mult = abs($ar[10+($i*2)]);
125 for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) {
126 // echo $p." i) ".$i."<br>";
127 $username = $ar[9+($i*2)];
128 if (($item = $userdb->getitem_bylogin($username, &$id)) == FALSE) {
129 echo "WARNING: the user [".$username."] NOT EXISTS!<br>";
133 // echo $item->login." id)".$id." ".$ar[10+($i*2)]." mult: ".$mult."<br>";
134 $tri[$id]->add($ar[10+($i*2)] / $mult);
135 if ($ar[0] >= $curtime - MON_LIMIT)
136 $mon[$id]->add($ar[10+($i*2)] / $mult);
137 if ($ar[0] >= $curtime - WEE_LIMIT)
138 $wee[$id]->add($ar[10+($i*2)] / $mult);
140 // $p++; echo $p++."<br>";
144 usort($tri, ptsgam_cmp);
145 usort($mon, ptsgam_cmp);
146 usort($wee, ptsgam_cmp);
148 echo "<br><br>TRI<br>\n";
150 if (($fplo = @fopen(LEGAL_PATH."/class_tri_lo.log", 'w')) == FALSE) {
151 echo "Open tri_lo failed<br>";
154 if (($fphi = @fopen(LEGAL_PATH."/class_tri_hi.log", 'w')) == FALSE) {
155 echo "Open tri_hi failed<br>";
159 for ($i = 0 ; $i < count($tri) ; $i++) {
160 if ($tri[$i]->gam == 0.0)
162 printf("%s: %s (%d) <br>\n", $tri[$i]->username, $tri[$i]->snormpts(), $tri[$i]->gam);
163 if ($tri[$i]->gam >= TRI_MAX_GAMES)
164 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam));
165 else if ($tri[$i]->gam > TRI_MIN_GAMES)
166 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam));
171 echo "<br><br>MON<br>\n";
173 if (($fplo = @fopen(LEGAL_PATH."/class_mon_lo.log", 'w')) == FALSE) {
174 echo "Open tri_lo failed<br>";
177 if (($fphi = @fopen(LEGAL_PATH."/class_mon_hi.log", 'w')) == FALSE) {
178 echo "Open tri_hi failed<br>";
182 for ($i = 0 ; $i < count($mon) ; $i++) {
183 if ($mon[$i]->gam == 0.0)
185 printf("%s: %s (%d) <br>\n", $mon[$i]->username, $mon[$i]->snormpts(), $mon[$i]->gam);
186 if ($mon[$i]->gam >= MON_MAX_GAMES)
187 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam));
188 else if ($mon[$i]->gam > MON_MIN_GAMES)
189 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam));
194 echo "<br><br>WEE<br>\n";
195 if (($fplo = @fopen(LEGAL_PATH."/class_wee_lo.log", 'w')) == FALSE) {
196 echo "Open wee_lo failed<br>";
199 if (($fphi = @fopen(LEGAL_PATH."/class_wee_hi.log", 'w')) == FALSE) {
200 echo "Open wee_hi failed<br>";
204 for ($i = 0 ; $i < count($wee) ; $i++) {
205 if ($wee[$i]->gam == 0.0)
207 printf("%s: %s (%d) <br>\n", $wee[$i]->username, $wee[$i]->snormpts(), $wee[$i]->gam);
208 if ($wee[$i]->gam >= WEE_MAX_GAMES)
209 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam));
210 else if ($wee[$i]->gam > WEE_MIN_GAMES)
211 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam));