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
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);
73 for ($i = 0 ; $i < $bdb->count() ; $i++) {
74 $login = $bdb->getlogin_byidx($i);
75 $tri[$i] = new Ptsgam($login);
76 $mon[$i] = new Ptsgam($login);
77 $wee[$i] = new Ptsgam($login);
80 // recalculate all the placings
82 // 1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1|
85 $bf = fgets($fp, 4096);
86 $ar = csplitter($bf, '|');
87 // if not auth table, continue
92 if ($ar[7] >= TABLES_AUTH_N)
94 // echo $p++." ".$ar[5]."<br>";
95 // if not FINISH_GAME line, continue
96 if ($ar[5] != "STAT:BRISKIN5:FINISH_GAME")
99 // if to much old points, continue
100 if ($ar[0] < $curtime - TRI_LIMIT) {
101 if (($fp_start = @fopen(LEGAL_PATH."/points.start", 'w')) != FALSE) {
102 $curpos = ftell($fp);
103 fwrite($fp_start, sprintf("%d\n", $curpos));
109 // echo $p++." ".BRISKIN5_PLAYERS_N."<br>";
113 for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) {
114 for ($e = $i + 1 ; $e < BRISKIN5_PLAYERS_N ; $e++) {
115 if ($ar[10+($i*2)] == $ar[10+($e*2)]) {
116 $mult = abs($ar[10+($i*2)]);
126 for ($i = 0 ; $i < BRISKIN5_PLAYERS_N ; $i++) {
127 // echo $p." i) ".$i."<br>";
128 $username = $ar[9+($i*2)];
129 if (($item = $bdb->getitem_bylogin($username, &$id)) == FALSE) {
130 echo "WARNING: the user [".$username."] NOT EXISTS!<br>";
134 // echo $item->login." id)".$id." ".$ar[10+($i*2)]." mult: ".$mult."<br>";
135 $tri[$id]->add($ar[10+($i*2)] / $mult);
136 if ($ar[0] >= $curtime - MON_LIMIT)
137 $mon[$id]->add($ar[10+($i*2)] / $mult);
138 if ($ar[0] >= $curtime - WEE_LIMIT)
139 $wee[$id]->add($ar[10+($i*2)] / $mult);
141 // $p++; echo $p++."<br>";
145 usort($tri, ptsgam_cmp);
146 usort($mon, ptsgam_cmp);
147 usort($wee, ptsgam_cmp);
149 echo "<br><br>TRI<br>\n";
151 if (($fplo = @fopen(LEGAL_PATH."/class_tri_lo.log", 'w')) == FALSE) {
152 echo "Open tri_lo failed<br>";
155 if (($fphi = @fopen(LEGAL_PATH."/class_tri_hi.log", 'w')) == FALSE) {
156 echo "Open tri_hi failed<br>";
160 for ($i = 0 ; $i < count($tri) ; $i++) {
161 if ($tri[$i]->gam == 0.0)
163 printf("%s: %s (%d) <br>\n", $tri[$i]->username, $tri[$i]->snormpts(), $tri[$i]->gam);
164 if ($tri[$i]->gam >= TRI_MAX_GAMES)
165 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam));
166 else if ($tri[$i]->gam > TRI_MIN_GAMES)
167 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($tri[$i]->username), $tri[$i]->pts, $tri[$i]->gam));
172 echo "<br><br>MON<br>\n";
174 if (($fplo = @fopen(LEGAL_PATH."/class_mon_lo.log", 'w')) == FALSE) {
175 echo "Open tri_lo failed<br>";
178 if (($fphi = @fopen(LEGAL_PATH."/class_mon_hi.log", 'w')) == FALSE) {
179 echo "Open tri_hi failed<br>";
183 for ($i = 0 ; $i < count($mon) ; $i++) {
184 if ($mon[$i]->gam == 0.0)
186 printf("%s: %s (%d) <br>\n", $mon[$i]->username, $mon[$i]->snormpts(), $mon[$i]->gam);
187 if ($mon[$i]->gam >= MON_MAX_GAMES)
188 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam));
189 else if ($mon[$i]->gam > MON_MIN_GAMES)
190 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($mon[$i]->username), $mon[$i]->pts, $mon[$i]->gam));
195 echo "<br><br>WEE<br>\n";
196 if (($fplo = @fopen(LEGAL_PATH."/class_wee_lo.log", 'w')) == FALSE) {
197 echo "Open wee_lo failed<br>";
200 if (($fphi = @fopen(LEGAL_PATH."/class_wee_hi.log", 'w')) == FALSE) {
201 echo "Open wee_hi failed<br>";
205 for ($i = 0 ; $i < count($wee) ; $i++) {
206 if ($wee[$i]->gam == 0.0)
208 printf("%s: %s (%d) <br>\n", $wee[$i]->username, $wee[$i]->snormpts(), $wee[$i]->gam);
209 if ($wee[$i]->gam >= WEE_MAX_GAMES)
210 fwrite($fphi, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam));
211 else if ($wee[$i]->gam > WEE_MIN_GAMES)
212 fwrite($fplo, sprintf("%s|%d|%d|\n", xcapelt($wee[$i]->username), $wee[$i]->pts, $wee[$i]->gam));