2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * FICS-Extensions used at GICS chess.unix-ag.uni-kl.de 5000
19 * (c) 1995/1996 by Ulrich Schlechte <Ulrich.Schlechte@ipp.tu-clausthal.de>
20 * Klaus Knopper <Knopper@unix-ag.uni-kl.de>
28 void init_userstat(void)
33 if ((fp = fopen_s(STATS_DIR "/user.stats", "r")) == NULL) {
34 bzero((char *) &gics_globals.userstat, sizeof(gics_globals.userstat));
38 for (i = 0; i < 48; i++) {
39 fscanf(fp, "%d\n", &gics_globals.userstat.users[i]);
41 fscanf(fp, "%d\n", &gics_globals.userstat.usermax);
42 fscanf(fp, "%d\n", (int *) &gics_globals.userstat.usermaxtime);
43 fscanf(fp, "%d\n", &gics_globals.userstat.logins);
44 fscanf(fp, "%d\n", &gics_globals.userstat.games);
45 fscanf(fp, "%d\n", &gics_globals.userstat.gamemax);
46 fscanf(fp, "%d\n", (int *) &gics_globals.userstat.gamemaxtime);
50 void save_userstat(void)
55 if ((fp = fopen_s(STATS_DIR "/user.stats", "w")) == NULL)
57 for (i = 0; i < 48; i++)
58 fprintf(fp, "%d\n", gics_globals.userstat.users[i]);
59 fprintf(fp, "%d\n%d\n%d\n",
60 gics_globals.userstat.usermax, gics_globals.userstat.usermaxtime, gics_globals.userstat.logins);
61 fprintf(fp, "%d\n%d\n%d\n",
62 gics_globals.userstat.games, gics_globals.userstat.gamemax, gics_globals.userstat.gamemaxtime);
67 int com_ping(int p, param_list param)
70 struct timeval timeState;
73 if ((p1 = player_find_bylogin(param[0].val.word)) < 0) {
74 pprintf(p, "Player \"%s\" not logged on!\n", param[0].val.word);
77 if ((!con[player_globals.parray[p1].socket].timeseal) || (con[player_globals.parray[p1].socket].method)) {
78 pprintf(p, "%s is not using timeseal or uses an old client.\n", player_globals.parray[p1].name);
81 pprintf(p1, "\n[P]\n");
82 gettimeofday(&timeState, &tz);
83 con[player_globals.parray[p1].socket].pingtime = (((int) timeState.tv_sec % 10000) * 1000) + ((int) timeState.tv_usec / 1000);
84 con[player_globals.parray[p1].socket].pingplayer = p;
89 void game_save_playerratio(char *file, char *Opponent, int Result, int rated)
92 char Name[32], file1[256];
93 int win, loss, draw, flag = 0, inc = 1;
98 sprintf(file1, "%s.new", file);
99 if ((fp = fopen_s(file, "r")) != NULL) {
100 fp1 = fopen_s(file1, "w");
102 if (fscanf(fp, "%s %d %d %d\n", Name, &win, &draw, &loss) != 4) {
105 if (strcasecmp(Name, Opponent) == 0) {
114 fprintf(fp1, "%s %d %d %d\n", Name, win, draw, loss);
118 win = loss = draw = 0;
125 fprintf(fp1, "%s %d %d %d\n", Opponent, win, draw, loss);
129 if (rename(file1, file) != 0) {
130 d_printf("CHESSD: Problems rename %s to %s : %d\n", file1, file, errno);
135 fp = fopen_s(file, "w");
138 d_printf("Unable to open %s - very bad, info not saved\n",file);
141 win = loss = draw = 0;
148 fprintf(fp, "%s %d %d %d\n", Opponent, win, draw, loss);
153 int com_pstat(int p, param_list param)
155 struct player *pp = &player_globals.parray[p];
156 int p1 = p, p2, ptemp, pflag=0;
157 int p1_connected = 1, p2_connected = 1;
158 int win = 0, draw = 0, loss = 0, flag = 0;
160 char Name[32], fname[256];
162 if (param[0].type == TYPE_NULL) {
164 pprintf(p, "You are not playing a game.\n");
167 if (game_globals.garray[pp->game].status == GAME_EXAMINE) {
168 pprintf(p, "You are examining a game please specify variables.\n");
173 if (!FindPlayer(p, param[0].val.word, &p2, &p2_connected)) {
174 pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
177 if (param[1].type != TYPE_NULL) {
178 if (!FindPlayer(p, param[1].val.word, &p1, &p1_connected)) {
179 pprintf(p, "No user named \"%s\" is logged in.\n", param[1].val.word);
191 pprintf(p, "You have not played against yourself ;-)\n");
198 sprintf(fname, "%s/player_data/%c/%s.gstats", STATS_DIR, player_globals.parray[p1].login[0], player_globals.parray[p1].login);
199 if ((fp = fopen_s(fname, "r")) != NULL) {
201 if (fscanf(fp, "%s %d %d %d\n", Name, &win, &draw, &loss) != 4) {
202 win = loss = draw = 0;
205 if (strcasecmp(Name, player_globals.parray[p2].name) == 0) {
213 win = loss = draw = 0;
214 pprintf(p, "Record for %s vs. %s:\n", player_globals.parray[p1].name, player_globals.parray[p2].name);
215 pprintf(p, " wins losses draws\n");
216 pprintf(p, " rated %4d %4d %4d\n", win % 100000, loss % 100000, draw % 100000);
217 pprintf(p, " unrated %4d %4d %4d\n", win / 100000, loss / 100000, draw / 100000);
218 /* pprintf(p, "Ratio of %s vs. %s (r/u): %d/%d wins %d/%d draws %d/%d losses\n", player_globals.parray[p1].name, player_globals.parray[p2].name,
219 * win % 100000, win / 100000, draw % 100000, draw / 100000, loss % 100000, loss / 100000);