aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
Diffstat (limited to 'FICS')
-rw-r--r--FICS/Makefile.in.orig110
-rw-r--r--FICS/acconfig.h.orig49
-rw-r--r--FICS/command.h.orig135
-rw-r--r--FICS/comproc.c.orig1625
-rw-r--r--FICS/ficsmain.c.orig171
-rw-r--r--FICS/gameproc.c.orig2826
-rw-r--r--FICS/multicol.c.orig153
-rw-r--r--FICS/network.c.orig657
-rw-r--r--FICS/ratings.c.orig1432
-rw-r--r--FICS/stdinclude.h.orig164
-rw-r--r--FICS/utils.c.orig991
-rw-r--r--FICS/utils.h.orig115
-rw-r--r--FICS/vers.h.orig31
13 files changed, 0 insertions, 8459 deletions
diff --git a/FICS/Makefile.in.orig b/FICS/Makefile.in.orig
deleted file mode 100644
index 7b3bff1..0000000
--- a/FICS/Makefile.in.orig
+++ /dev/null
@@ -1,110 +0,0 @@
-##
-## fics - An internet chess server.
-## Copyright (C) 1993 Richard V. Nash
-##
-## This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-##
-## This is the Makefile template; see machine dependant config.h for
-## more configuration options.
-
-
-SHELL = /bin/sh
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-
-##
-## Where to install FICS
-##
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-bindir = ${exec_prefix}/bin
-
-
-##
-## Binaries and Options to use
-##
-CC = @CC@
-CFLAGS = @CFLAGS@ -DTIMESEAL -I${srcdir}
-INSTALL = @INSTALL@
-INSTALL_DATA = @INSTALL_DATA@
-LIBS = @LIBS@
-LNFLAGS = @LDFLAGS@ ${LIBS}
-
-
-##
-## Version information
-##
-VERSION=echo 'char SGS_VERS[]=""; char VERS_NUM[]="1.2.3";'
-
-
-SRCS=adminproc.c algcheck.c board.c channel.c command.c talkproc.c comproc.c \
- fics_addplayer.c ficsmain.c formula.c gamedb.c gameproc.c \
- get_tcp_conn.c legal.c lists.c makerank.c \
- movecheck.c multicol.c network.c playerdb.c ratings.c \
- rmalloc.c utils.c variable.c vers.c eco.c matchproc.c \
- timeseal.c ${MORESRCS}
-
-OBJS=network.o lists.o formula.o playerdb.o command.o talkproc.o comproc.o movecheck.o \
- ratings.o gamedb.o channel.o utils.o rmalloc.o legal.o vers.o variable.o \
- board.o gameproc.o algcheck.o adminproc.o \
- get_tcp_conn.o multicol.o eco.o matchproc.o timeseal.o ${MOREOBJS}
-
-VERSION=echo 'char SGS_VERS[]=""; char VERS_NUM[]="1.2.18"; char COMP_DATE[]="'`date`'";'
-
-PROGRAM=fics
-ADDPLAYER=fics_addplayer
-#DELPLAYER=fics_delplayer
-#MAILSERVER=fics_mailproc
-#MAILPROC=mailproc
-MAKERANK=makerank
-
-ALL= ${PROGRAM} ${ADDPLAYER} ${MAKERANK}
-
-#all: ${PROGRAM} ${MAILSERVER} ${ADDPLAYER} ${DELPLAYER} ${MAILPROC}
-all: ${ALL}
-
-${PROGRAM}: ficsmain.o $(OBJS)
- $(CC) ficsmain.o $(CFLAGS) $(OBJS) $(LNFLAGS) -o ${PROGRAM}
-
-#${MAILSERVER}: fics_mailproc.o $(OBJS)
-# $(CC) fics_mailproc.o $(CFLAGS) $(OBJS) $(LNFLAGS) -o ${MAILSERVER}
-
-${ADDPLAYER}: fics_addplayer.o $(OBJS)
- $(CC) fics_addplayer.o $(CFLAGS) $(OBJS) $(LNFLAGS) -o ${ADDPLAYER}
-
-#${DELPLAYER}: fics_delplayer.o $(OBJS)
-# $(CC) fics_delplayer.o $(CFLAGS) $(OBJS) $(LNFLAGS) -o ${DELPLAYER}
-
-#${MAILPROC}: mailproc.o lock.o network.o rmalloc.o
-# $(CC) mailproc.o lock.o network.o rmalloc.o $(CFLAGS) -o ${MAILPROC}
-# $(CC) mailproc.o lock.o network.o rmalloc.o memmove.o $(CFLAGS) -o ${MAILPROC}
-
-${MAKERANK}: makerank.o
- $(CC) makerank.o $(CFLAGS) $(LNFLAGS) -o ${MAKERANK}
-
-vers.c:
- ${VERSION} >vers.c
-
-depend:
- makedepend -- ${CFLAGS} ${MAKEDEPMORECFLAGS} -- ${SRCS}
-
-clean:
- rm -f *.o ${ALL} *~ vers.c
- @ echo "Project cleaned."
-
-distclean: clean
- rm -rf Makefile autoconfig.h config.h config.status config.cache \
- config.log
-
-install:
- for f in ${ALL}; do ${INSTALL} $$f ${bindir}; done
diff --git a/FICS/acconfig.h.orig b/FICS/acconfig.h.orig
deleted file mode 100644
index a7f3dd8..0000000
--- a/FICS/acconfig.h.orig
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
-
- This file contains descriptive text for the C preprocessor macros
- that are missing in the original acconfig.h of the autoconf
- distribution, but used in the configure.in of the FICS distribution.
-
- It is used *only* by the autoheader program contained in the
- autoconf distribution.
-
-
- Leave the following blank line there!! Autoheader needs it. */
-
-
-/* Define this to be the return value of the time() function. */
-#undef time_t
-
-/* Undefine, if your compiler doesn't support prototypes */
-#undef HAVE_PROTOTYPES
-
-/* Define, if you have a statfs() function which fills a struct
- statfs, declared in sys/vfs.h. (NeXTStep) */
-#undef HAVE_STATFS_FILLING_STRUCT_STATFS
-
-/* Define, if you have a statfs() function which fills a struct
- fs_data, declared in sys/mount.h. (Ultrix) */
-#undef HAVE_STATFS_FILLING_STRUCT_FS_DATA
-
-/* Define, if you have crypt() and it is declared in either
- crypt.h or unistd.h. */
-#undef HAVE_CRYPT_DECLARED
-
-/* Define this to be tv_usec, if your struct rusage has
- a member ru_utime.tv_usec.
- Define this to be tv_nsec, if your struct rusage has
- a member ru_utime.tv_nsec. */
-#undef TV_USEC
diff --git a/FICS/command.h.orig b/FICS/command.h.orig
deleted file mode 100644
index 1d5d47f..0000000
--- a/FICS/command.h.orig
+++ /dev/null
@@ -1,135 +0,0 @@
-/* command.h
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-
-#include "variable.h"
-#ifndef _COMMAND_H
-#define _COMMAND_H
-
-extern char *mess_dir;
-extern char *index_dir;
-extern char *help_dir[NUM_LANGS];
-extern char *comhelp_dir;
-extern char *info_dir;
-extern char *adhelp_dir;
-extern char *stats_dir;
-extern char *config_dir;
-extern char *player_dir;
-extern char *adj_dir;
-extern char *hist_dir;
-extern char *board_dir;
-extern char *def_prompt;
-extern char *source_dir;
-extern char *lists_dir;
-extern char *news_dir;
-
-extern char *hadmin_handle;
-
-extern int startuptime;
-extern char fics_hostname[81];
-extern int player_high;
-extern int game_high;
-extern int MailGameResult;
-
-/* Maximum length of a login name */
-#define MAX_LOGIN_NAME 20
-
-/* Maximum number of parameters per command */
-#define MAXNUMPARAMS 10
-
-/* Maximum string length of a single command word */
-#define MAX_COM_LENGTH 50
-
-/* Maximum string length of the whole command line */
-#define MAX_STRING_LENGTH 1024
-
-#define COM_OK 0
-#define COM_FAILED 1
-#define COM_ISMOVE 2
-#define COM_AMBIGUOUS 3
-#define COM_BADPARAMETERS 4
-#define COM_BADCOMMAND 5
-#define COM_LOGOUT 6
-#define COM_FLUSHINPUT 7
-#define COM_RIGHTS 8
-#define COM_OK_NOPROMPT 9
-
-#define ADMIN_USER 0
-#define ADMIN_ADMIN 10
-#define ADMIN_MASTER 20
-#define ADMIN_DEMIGOD 60
-#define ADMIN_GOD 100
-
-#define TYPE_NULL 0
-/*#define TYPE_NULL NULL <-- this is WRONG WRONG WRONG! --mann 5/10/95 */
-#define TYPE_WORD 1
-#define TYPE_STRING 2
-#define TYPE_INT 3
-typedef struct u_parameter {
- int type;
- union {
- char *word;
- char *string;
- int integer;
- } val;
-} parameter;
-
-typedef parameter param_list[MAXNUMPARAMS];
-
-typedef struct s_command_type {
- char *comm_name;
- char *param_string;
- int (*comm_func)();
- int adminLevel;
-} command_type;
-
-typedef struct s_alias_type {
- char *comm_name;
- char *alias;
-} alias_type;
-
-extern int commanding_player; /* The player whose command you're in */
-
-extern int process_input(int, char *);
-extern int process_new_connection(int, unsigned int);
-extern int process_disconnection(int);
-/* extern int process_incomplete(int, char *); */
-extern int process_heartbeat(int *);
-
-extern void commands_init(void);
-
-extern void TerminateCleanup(void);
-extern int process_command(int, char *, char **);
-
-
-extern int alias_lookup();
-extern int gethostname();
-
-#if defined(SGI)
-#else
-extern int wait3();
-/* extern char tolower(); */
-/* extern int sscanf(); */
-#endif
-
-#endif /* _COMMAND_H */
diff --git a/FICS/comproc.c.orig b/FICS/comproc.c.orig
deleted file mode 100644
index 2ec74e3..0000000
--- a/FICS/comproc.c.orig
+++ /dev/null
@@ -1,1625 +0,0 @@
-/* comproc.c
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
- foxbat 95/03/11 added filters in cmatch.
-*/
-
-#include "stdinclude.h"
-
-#include "common.h"
-#include "talkproc.h"
-#include "comproc.h"
-#include "command.h"
-#include "utils.h"
-#include "ficsmain.h"
-#include "config.h"
-#include "playerdb.h"
-#include "network.h"
-#include "rmalloc.h"
-#include "channel.h"
-#include "variable.h"
-#include "gamedb.h"
-#include "gameproc.h"
-#include "board.h"
-/* #include "hostinfo.h" */
-#include "multicol.h"
-#include "ratings.h"
-#include "formula.h"
-#include "lists.h"
-#include "eco.h"
-#include "network.h"
-#include <string.h>
-
-#include <sys/resource.h>
-
-/* grimm */
-#if defined(SGI)
-#else
-/* int system(char *arg); */
-#endif
-
-const none = 0;
-const blitz_rat = 1;
-const std_rat = 2;
-const wild_rat = 3;
-
-
-PUBLIC int com_rating_recalc(int p, param_list param)
-{
- ASSERT(parray[p].adminLevel >= ADMIN_ADMIN);
- rating_recalc();
- return COM_OK;
-}
-
-PUBLIC int com_more(int p, param_list param)
-{
-/* in_push(IN_HELP); */
- pmore_file(p);
- return COM_OK;
-}
-
-PUBLIC int num_news = -1;
-
-PUBLIC int com_news(int p, param_list param)
-{
- FILE *fp;
- char filename[MAX_FILENAME_SIZE];
- char junk[MAX_LINE_SIZE];
- char *junkp;
- int crtime, found = 0;
- char count[10];
-
- if (num_news == -1) {
- sprintf(filename, "%s/news.index", news_dir);
- fp = fopen(filename, "r");
- if (!fp) {
- fprintf(stderr, "Cant find news index.\n");
- return COM_OK;
- }
- num_news = count_lines(fp);
- fclose(fp); /* It's customary to close files after use! */
- }
-
- if (param[0].type == 0) {
- /* no params - then just display index over news */
- sprintf(filename, "%s/news.index", news_dir);
- fp = fopen(filename, "r");
- if (!fp) {
- fprintf(stderr, "Can't find news index.\n");
- return COM_OK;
- }
- pprintf(p,"Index of recent news items:\n");
- while (!feof(fp)) {
- junkp = junk;
- fgets(junk, MAX_LINE_SIZE, fp);
- if (feof(fp))
- break;
- if (strlen(junk) > 1) {
- sscanf(junkp, "%d %s", &crtime, count);
- if (atoi(count) > num_news - 10) {
- junkp = nextword(junkp);
- junkp = nextword(junkp);
- pprintf(p, "%3s (%s) %s", count, strltime(&crtime), junkp);
- }
- }
- }
- fclose(fp);
- } else if ((param[0].type == TYPE_WORD) && !strcmp(param[0].val.word, "all")) {
- /* param all - displays all news items */
- sprintf(filename, "%s/news.index", news_dir);
- fp = fopen(filename, "r");
- if (!fp) {
- fprintf(stderr, "Can't find news index.\n");
- return COM_OK;
- }
- pprintf(p, "Index of all news items:\n");
- while (!feof(fp)) {
- junkp = junk;
- fgets(junk, MAX_LINE_SIZE, fp);
- if (feof(fp))
- break;
- if (strlen(junk) > 1) {
- sscanf(junkp, "%d %s", &crtime, count);
- junkp = nextword(junkp);
- junkp = nextword(junkp);
- pprintf(p, "%3s (%s) %s", count, strltime(&crtime), junkp);
- }
- }
- fclose(fp); /* It's customary to close files after use! */
- } else { /* check if the specific news file exist in index */
- sprintf(filename, "%s/news.index", news_dir);
- fp = fopen(filename, "r");
- if (!fp) {
- fprintf(stderr, "Can't find news index.\n");
- return COM_OK;
- }
- while (!feof(fp) && !found) {
- junkp = junk;
- fgets(junk, MAX_LINE_SIZE, fp);
- if (feof(fp))
- break;
- if (strlen(junk) > 1) {
- sscanf(junkp, "%d %s", &crtime, count);
- if (!strcmp(count, param[0].val.word)) {
- found = 1;
- junkp = nextword(junkp);
- junkp = nextword(junkp);
- pprintf(p, "NEWS %3s (%s) %s\n", count, strltime(&crtime), junkp);
- }
- }
- }
- fclose(fp);
- if (!found) {
- pprintf(p, "Bad index number!\n");
- return COM_OK;
- }
- /* file exists - show it */
- sprintf(filename, "%s/news.%s", news_dir, param[0].val.word);
- fp = fopen(filename, "r");
- if (!fp) {
- pprintf(p, "No more info.\n");
- return COM_OK;
- }
- fclose(fp);
- sprintf(filename, "news.%s", param[0].val.word);
- if (psend_file(p, news_dir, filename) < 0) {
- pprintf(p, "Internal error - couldn't send news file!\n");
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_quit(int p, param_list param)
-{
- if ((parray[p].game >= 0) && (garray[parray[p].game].status == GAME_EXAMINE)) {
- pcommand(p, "unexamine");
- }
-
- if (parray[p].game >= 0) {
- pprintf(p, "You can't quit while you are playing a game.\nType 'resign' to resign the game, or you can request an abort with 'abort'.\n");
- return COM_OK;
- }
- psend_logoutfile(p, mess_dir, MESS_LOGOUT);
- return COM_LOGOUT;
-}
-
-PUBLIC int com_set(int p, param_list param)
-{
- int result;
- int which;
- char *val;
-
- if (param[1].type == TYPE_NULL)
- val = NULL;
- else
- val = param[1].val.string;
- result = var_set(p, param[0].val.word, val, &which);
- switch (result) {
- case VAR_OK:
- break;
- case VAR_BADVAL:
- pprintf(p, "Bad value given for variable %s.\n", param[0].val.word);
- break;
- case VAR_NOSUCH:
- pprintf(p, "No such variable name %s.\n", param[0].val.word);
- break;
- case VAR_AMBIGUOUS:
- pprintf(p, "Ambiguous variable name %s.\n", param[0].val.word);
- break;
- }
- player_save(p);
- return COM_OK;
-}
-
-PUBLIC int FindPlayer(int p, parameter * param, int *p1, int *connected)
-{
- if (param->type == TYPE_WORD) {
- *p1 = player_search(p, param->val.word);
- if (*p1 == 0)
- return 0;
- if (*p1 < 0) { /* player had to be connected and will be
- removed later */
- *connected = 0;
- *p1 = (-*p1) - 1;
- } else {
- *connected = 1;
- *p1 = *p1 - 1;
- }
- } else {
- *p1 = p;
- *connected = 1;
- }
- return 1;
-}
-
-PRIVATE void com_stats_andify(int *numbers, int howmany, char *dest)
-{
- char tmp[10];
-
- *dest = '\0';
- while (howmany--) {
- sprintf(tmp, "%d", numbers[howmany]);
- strcat(dest, tmp);
- if (howmany > 1)
- sprintf(tmp, ", ");
- else if (howmany == 1)
- sprintf(tmp, " and ");
- else
- sprintf(tmp, ".\n");
- strcat(dest, tmp);
- }
- return;
-}
-
-PRIVATE void com_stats_rating(char *hdr, statistics * stats, char *dest)
-{
- char tmp[100];
-
- sprintf(dest, "%-10s%4s %5.1f %4d %4d %4d %4d",
- hdr, ratstr(stats->rating), stats->sterr, stats->win, stats->los, stats->dra, stats->num);
- if (stats->whenbest) {
- sprintf(tmp, " %d", stats->best);
- strcat(dest, tmp);
- strftime(tmp, sizeof(tmp), " (%d-%b-%y)", localtime((time_t *) & stats->whenbest));
- strcat(dest, tmp);
- }
- strcat(dest, "\n");
- return;
-}
-
-PUBLIC int com_stats(int p, param_list param)
-{
- int g, i, t;
- int p1, connected;
- char line[255], tmp[255];
- int numbers[MAX_OBSERVE > MAX_SIMUL ? MAX_OBSERVE : MAX_SIMUL];
- int days, hours, mins, secs, onTime;
-
- if (!FindPlayer(p, &param[0], &p1, &connected))
- return COM_OK;
-
- sprintf(line, "\nStatistics for %-11s ", parray[p1].name);
- if ((connected) && (parray[p1].status == PLAYER_PROMPT)) {
- sprintf(tmp, "On for: %s", hms(player_ontime(p1), 0, 0, 0));
- strcat(line, tmp);
- sprintf(tmp, " Idle: %s\n", hms(player_idle(p1), 0, 0, 0));
- } else {
- if ((t = player_lastdisconnect(p1)))
- sprintf(tmp, "(Last disconnected %s):\n", strltime(&t));
- else
- sprintf(tmp, "(Never connected.)\n");
- }
- strcat(line, tmp);
- pprintf(p, "%s", line);
- if (parray[p1].simul_info.numBoards) {
- for (i = 0, t = 0; i < parray[p1].simul_info.numBoards; i++) {
- if ((numbers[t] = parray[p1].simul_info.boards[i] + 1) != 0)
- t++;
- }
- pprintf(p, "%s is giving a simul: game%s ", parray[p1].name, ((t > 1) ? "s" : ""));
- com_stats_andify(numbers, t, tmp);
- pprintf(p, tmp);
- } else if (parray[p1].game >= 0) {
- g = parray[p1].game;
- if (garray[g].status == GAME_EXAMINE) {
- pprintf(p, "(Examining game %d: %s vs. %s)\n", g + 1,
- garray[g].white_name, garray[g].black_name);
- } else {
- pprintf(p, "(playing game %d: %s vs. %s)\n", g + 1,
- parray[garray[g].white].name, parray[garray[g].black].name);
- }
- }
- if (parray[p1].num_observe) {
- for (i = 0, t = 0; i < parray[p1].num_observe; i++) {
- g = parray[p1].observe_list[i];
- if ((g != -1) && ((parray[p].adminLevel >= ADMIN_ADMIN) || (garray[g].private == 0)))
- numbers[t++] = g + 1;
- }
- if (t) {
- pprintf(p, "%s is observing game%s ", parray[p1].name, ((t > 1) ? "s" : ""));
- com_stats_andify(numbers, t, tmp);
- pprintf(p, tmp);
- }
- }
- if (parray[p1].busy[0]) {
- pprintf(p, "(%s %s)\n", parray[p1].name, parray[p1].busy);
- }
- if (!parray[p1].registered) {
- pprintf(p, "%s is NOT a registered player.\n\n", parray[p1].name);
- } else {
- pprintf(p, "\n rating RD win loss draw total best\n");
- com_stats_rating("Blitz", &parray[p1].b_stats, tmp);
- pprintf(p, tmp);
- com_stats_rating("Standard", &parray[p1].s_stats, tmp);
- pprintf(p, tmp);
- com_stats_rating("Wild", &parray[p1].w_stats, tmp);
- pprintf(p, tmp);
- }
- pprintf(p, "\n");
- if (parray[p1].adminLevel > 0) {
- pprintf(p, "Admin Level: ");
- switch (parray[p1].adminLevel) {
-/*
- case 0:
- pprintf(p, "Normal User\n");
- break;
- case 5:
- pprintf(p, "Extra Cool User\n"); vek wants to be 5
- break;
-
- Forget it - you can do some admin stuff if your level is > than 0 - DAV
-
-*/
- case 5:
- pprintf(p, "Authorized Helper Person\n");
- break;
- case 10:
- pprintf(p, "Administrator\n");
- break;
- case 15:
- pprintf(p, "Help File Librarian/Administrator\n");
- break;
- case 20:
- pprintf(p, "Master Administrator\n");
- break;
- case 50:
- pprintf(p, "Master Help File Librarian/Administrator\n");
- break;
- case 60:
- pprintf(p, "Assistant Super User\n");
- break;
- case 100:
- pprintf(p, "Super User\n");
- break;
- default:
- pprintf(p, "%d\n", parray[p1].adminLevel);
- break;
- }
- }
- if (parray[p].adminLevel > 0)
- pprintf(p, "Full Name : %s\n", (parray[p1].fullName ? parray[p1].fullName : "(none)"));
- if (((p1 == p) && (parray[p1].registered)) || (parray[p].adminLevel > 0))
- pprintf(p, "Address : %s\n", (parray[p1].emailAddress ? parray[p1].emailAddress : "(none)"));
- if (parray[p].adminLevel > 0) {
- pprintf(p, "Host : %s\n",
-/*
- ((hp = gethostbyaddr((const char*) (connected ? &parray[p1].thisHost : &parray[p1].lastHost), sizeof(parray[p1].thisHost), AF_INET)) == 0) ? "" : hp->h_name,
-*/
- dotQuad(connected ? parray[p1].thisHost : parray[p1].lastHost));
- }
- if ((parray[p].adminLevel > 0) && (parray[p1].registered))
- if (parray[p1].num_comments)
- pprintf(p, "Comments : %d\n", parray[p1].num_comments);
-
- if (connected && parray[p1].registered && (p==p1 ||
- (parray[p].adminLevel > 0))) {
- char *timeToStr = ctime((time_t *) &parray[p1].timeOfReg);
-
- timeToStr[strlen(timeToStr)-1]='\0';
- pprintf(p, "\n");
- onTime = (time(0) - parray[p1].logon_time) + parray[p1].totalTime;
- days = (onTime / (60*60*24));
- hours = ((onTime % (60*60*24)) / (60*60));
- mins = (((onTime % (60*60*24)) % (60*60)) / 60);
- secs = (((onTime % (60*60*24)) % (60*60)) % 60);
- if ((days==0) && (hours==0) && (mins==0)) {
- pprintf(p, "Total time on-line: %d second%s\n",
- secs, (secs==1) ? "" : "s");
- } else if ((days==0) && (hours==0)) {
- pprintf(p, "Total time on-line: %d minute%s and %d second%s\n",
- mins, (mins==1) ? "" : "s",
- secs, (secs==1) ? "" : "s");
- } else if (days==0) {
- pprintf(p, "Total time on-line: %d hour%s, %d minute%s and %d "
- "second%s\n",
- hours, (hours==1) ? "" : "s",
- mins, (mins==1) ? "" : "s",
- secs, (secs==1) ? "" : "s");
- } else {
- pprintf(p, "Total time on-line: %d day%s, %d hour%s, %d minute%s "
- "and %d second%s\n",
- days, (days==1) ? "" : "s",
- hours, (hours==1) ? "" : "s",
- mins, (mins==1) ? "" : "s",
- secs, (secs==1) ? "" : "s");
- }
- pprintf(p, "%% of life on-line: %3.1f (since %s)\n",
- (double)((onTime*100)/(double)(time(0)-parray[p1].timeOfReg)),
- timeToStr);
- }
-
-#ifdef TIMESEAL
-
- if (connected)
- pprintf(p, "\nTimeseal : %s\n", (con[parray[p1].socket].timeseal)
-? "On" : "Off");
- if ((parray[p].adminLevel > 0) && (connected)) {
- if (findConnection(parray[p1].socket)) {
- pprintf(p, "Unix acc : %s\nSystem/OS : %s\n",
- con[parray[p1].socket].user,
- con[parray[p1].socket].sys);
- }
- }
-
-#endif
-
- if (parray[p1].num_plan) {
- pprintf(p, "\n");
- for (i = 0; i < parray[p1].num_plan; i++)
- pprintf(p, "%2d: %s\n", i + 1, (parray[p1].planLines[i] != NULL) ? parray[p1].planLines[i] : "");
- }
- if (!connected)
- player_remove(p1);
- return COM_OK;
-}
-
-PUBLIC int com_variables(int p, param_list param)
-{
- int p1, connected;
- int i;
-
- if (!FindPlayer(p, &param[0], &p1, &connected))
- return COM_OK;
-
- pprintf(p, "Variable settings of %s:\n", parray[p1].name);
-/* if (parray[p1].fullName)
- pprintf(p, " Realname: %s\n", parray[p1].fullName);
-*/
- if (parray[p1].uscfRating)
- pprintf(p, " USCF: %d\n", parray[p1].uscfRating);
- pprintf(p, " time=%-3d inc=%-3d private=%d Lang=%s\n",
- parray[p1].d_time, parray[p1].d_inc, parray[p1].private,
- Language(parray[p1].language));
- pprintf(p, " rated=%d ropen=%d open=%d simopen=%d\n",
- parray[p1].rated, parray[p1].ropen, parray[p1].open, parray[p1].sopen);
- pprintf(p, " shout=%d cshout=%d kib=%d tell=%d notifiedby=%d\n",
- parray[p1].i_shout, parray[p1].i_cshout, parray[p1].i_kibitz, parray[p1].i_tell, parray[p1].notifiedby);
- pprintf(p, " pin=%d gin=%d style=%-3d flip=%d\n",
- parray[p1].i_login, parray[p1].i_game, parray[p1].style + 1, parray[p1].flip);
- pprintf(p, " highlight=%d bell=%d auto=%d mailmess=%d pgn=%d\n",
- parray[p1].highlight, parray[p1].bell, parray[p1].automail, parray[p1].i_mailmess, parray[p1].pgn);
- pprintf(p, " width=%-3d height=%-3d\n",
- parray[p1].d_width, parray[p1].d_height);
- if (parray[p1].prompt && parray[p1].prompt != def_prompt)
- pprintf(p, " Prompt: %s\n", parray[p1].prompt);
-
- { /* added code to print channels */
- int count = 0;
- for (i = 0; i < MAX_CHANNELS; i++) {
- if (on_channel(i, p1)) {
- if (!count)
- pprintf(p, "\n Channels:");
- pprintf(p, " %d", i);
- count++;
- }
- }
- if (count)
- pprintf(p, "\n");
- }
-/* if (parray[p1].numAlias && (p == p1)) {
- pprintf(p, "\n Aliases:\n");
- for (i = 0; i < parray[p1].numAlias; i++) {
- pprintf(p, " %s %s\n", parray[p1].alias_list[i].comm_name,
- parray[p1].alias_list[i].alias);
- }
- }
-*/
- if (parray[p1].num_formula) {
- pprintf(p, "\n");
- for (i = 0; i < parray[p1].num_formula; i++) {
- if (parray[p1].formulaLines[i] != NULL)
- pprintf(p, " f%d: %s\n", i + 1, parray[p1].formulaLines[i]);
- else
- pprintf(p, " f%d:\n", i + 1);
- }
- }
- if (parray[p1].formula != NULL)
- pprintf(p, "\nFormula: %s\n", parray[p1].formula);
-
- if (!connected)
- player_remove(p1);
- return COM_OK;
-}
-
-PUBLIC int com_password(int p, param_list param)
-{
- char *oldpassword = param[0].val.word;
- char *newpassword = param[1].val.word;
- char salt[3];
-
- if (!parray[p].registered) {
- pprintf(p, "Setting a password is only for registered players.\n");
- return COM_OK;
- }
- if (parray[p].passwd) {
- salt[0] = parray[p].passwd[0];
- salt[1] = parray[p].passwd[1];
- salt[2] = '\0';
- if (strcmp(crypt(oldpassword, salt), parray[p].passwd)) {
- pprintf(p, "Incorrect password, password not changed!\n");
- return COM_OK;
- }
- rfree(parray[p].passwd);
- parray[p].passwd = NULL;
- }
- salt[0] = 'a' + rand() % 26;
- salt[1] = 'a' + rand() % 26;
- salt[2] = '\0';
- parray[p].passwd = strdup(crypt(newpassword, salt));
- pprintf(p, "Password changed to \"%s\".\n", newpassword);
- return COM_OK;
-}
-
-PUBLIC int com_uptime(int p, param_list param)
-{
- unsigned long uptime = time(0) - startuptime;
- struct rusage ru;
- int days = (uptime / (60*60*24));
- int hours = ((uptime % (60*60*24)) / (60*60));
- int mins = (((uptime % (60*60*24)) % (60*60)) / 60);
- int secs = (((uptime % (60*60*24)) % (60*60)) % 60);
-
- pprintf(p, "Server location: %s Server version : %s\n", fics_hostname,VERS_NUM);
- pprintf(p, "The server has been up since %s.\n", strltime(&startuptime));
- if ((days==0) && (hours==0) && (mins==0)) {
- pprintf(p, "(Up for %d second%s)\n",
- secs, (secs==1) ? "" : "s");
- } else if ((days==0) && (hours==0)) {
- pprintf(p, "(Up for %d minute%s and %d second%s)\n",
- mins, (mins==1) ? "" : "s",
- secs, (secs==1) ? "" : "s");
- } else if (days==0) {
- pprintf(p, "(Up for %d hour%s, %d minute%s and %d second%s)\n",
- hours, (hours==1) ? "" : "s",
- mins, (mins==1) ? "" : "s",
- secs, (secs==1) ? "" : "s");
- } else {
- pprintf(p, "(Up for %d day%s, %d hour%s, %d minute%s and %d second%s)\n",
- days, (days==1) ? "" : "s",
- hours, (hours==1) ? "" : "s",
- mins, (mins==1) ? "" : "s",
- secs, (secs==1) ? "" : "s");
- }
- pprintf(p, "\nAllocs: %u Frees: %u Allocs In Use: %u\n",
- malloc_count, free_count, malloc_count - free_count);
- if (parray[p].adminLevel >= ADMIN_ADMIN) {
- pprintf(p, "\nplayer size:%d, game size:%d, con size:%d, g_num:%d\n",
- sizeof(player), sizeof(game), net_consize(), g_num);
- getrusage(RUSAGE_SELF, &ru);
- pprintf(p, "pagesize = %d, maxrss = %d, total = %d\n", getpagesize(), ru.ru_maxrss, getpagesize() * ru.ru_maxrss);
- }
- pprintf(p, "\nPlayer limit: %d\n", max_connections);
- pprintf(p, "\nThere are currently %d players, with a high of %d since last restart.\n", player_count(), player_high);
- pprintf(p, "There are currently %d games, with a high of %d since last restart.\n", game_count(), game_high);
- pprintf(p, "\nCompiled on %s\n", COMP_DATE);
- return COM_OK;
-}
-
-PUBLIC int com_date(int p, param_list param)
-{
- int t = time(0);
- pprintf(p, "Local time - %s\n", strltime(&t));
- pprintf(p, "Greenwich time - %s\n", strgtime(&t));
- return COM_OK;
-}
-
-char *inout_string[] = {
- "login", "logout"
-};
-
-PRIVATE int plogins(p, fname)
-int p;
-char *fname;
-{
- FILE *fp;
- int inout, thetime, registered;
- char loginName[MAX_LOGIN_NAME + 1];
- char ipstr[20];
-
- fp = fopen(fname, "r");
- if (!fp) {
- pprintf(p, "Sorry, no login information available.\n");
- return COM_OK;
- }
- while (!feof(fp)) {
- if (fscanf(fp, "%d %s %d %d %s\n", &inout, loginName, &thetime,
- &registered, ipstr) != 5) {
- fprintf(stderr, "FICS: Error in login info format. %s\n", fname);
- fclose(fp);
- return COM_OK;
- }
- pprintf(p, "%s: %-17s %-6s", strltime(&thetime), loginName,
- inout_string[inout]);
- if (parray[p].adminLevel > 0) {
- pprintf(p, " from %s\n", ipstr);
- } else
- pprintf(p, "\n");
- }
- fclose(fp);
- return COM_OK;
-}
-
-PUBLIC int com_llogons(int p, param_list param)
-{
- char fname[MAX_FILENAME_SIZE];
-
- sprintf(fname, "%s/%s", stats_dir, STATS_LOGONS);
- return plogins(p, fname);
-}
-
-PUBLIC int com_logons(int p, param_list param)
-{
- char fname[MAX_FILENAME_SIZE];
-
- if (param[0].type == TYPE_WORD) {
- sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, param[0].val.word[0], param[0].val.word, STATS_LOGONS);
- } else {
- sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, parray[p].login[0], parray[p].login, STATS_LOGONS);
- }
- return plogins(p, fname);
-}
-
-#define WHO_OPEN 0x01
-#define WHO_CLOSED 0x02
-#define WHO_RATED 0x04
-#define WHO_UNRATED 0x08
-#define WHO_FREE 0x10
-#define WHO_PLAYING 0x20
-#define WHO_REGISTERED 0x40
-#define WHO_UNREGISTERED 0x80
-
-PRIVATE void who_terse(int p, int num, int *plist, int type)
-{
- char ptmp[80 + 20]; /* for highlight */
- multicol *m = multicol_start(PARRAY_SIZE);
- int i;
- int p1;
- int rat;
-
- /* altered DAV 3/15/95 */
-
- for (i = 0; i < num; i++) {
- p1 = plist[i];
- if (type == blitz_rat)
- rat = parray[p1].b_stats.rating;
- if (type == wild_rat)
- rat = parray[p1].w_stats.rating;
- if (type == std_rat)
- rat = parray[p1].s_stats.rating;
-
- if (type == none) {
- sprintf(ptmp, " ");
- } else {
- sprintf(ptmp, "%-4s", ratstrii(rat, parray[p1].registered));
- if (parray[p1].simul_info.numBoards) {
- strcat(ptmp, "~");
- } else if ((parray[p1].game >= 0) && (garray[parray[p1].game].status == GAME_EXAMINE)) {
- strcat(ptmp, "#");
- } else if (parray[p1].game >= 0) {
- strcat(ptmp, "^");
- } else if (!parray[p1].open) {
- strcat(ptmp, ":");
- } else if (player_idle(p1) > 300) {
- strcat(ptmp, ".");
- } else {
- strcat(ptmp, " ");
- }
- }
- if (p == p1) {
- psprintf_highlight(p, ptmp + strlen(ptmp), "%s", parray[p1].name);
- } else {
- strcat(ptmp, parray[p1].name);
- }
- if ((parray[p1].adminLevel >= 10) && (parray[p1].i_admin))
- strcat(ptmp, "(*)");
- if (in_list("computer", parray[p1].name))
- strcat(ptmp, "(C)");
-/* grimm's fishlist
- if (in_list("fish", parray[p1].name)) strcat(ptmp, "(Fish)");
-*/
- if (in_list("fm", parray[p1].name))
- strcat(ptmp, "(FM)");
- if (in_list("im", parray[p1].name))
- strcat(ptmp, "(IM)");
- if (in_list("gm", parray[p1].name))
- strcat(ptmp, "(GM)");
- if (in_list("td", parray[p1].name))
- strcat(ptmp, "(TD)");
- multicol_store(m, ptmp);
- }
- multicol_pprint(m, p, 80, 2);
- multicol_end(m);
- pprintf(p, "\n %d Players displayed (of %d). (*) indicates system administrator.\n", num, player_count());
-}
-
-PRIVATE void who_verbose(p, num, plist)
-int p;
-int num;
-int plist[];
-{
- int i, p1;
- char playerLine[255], tmp[255]; /* +8 for highlight */
-
- pprintf(p,
- " +---------------------------------------------------------------+\n"
- );
- pprintf(p,
- " | User Standard Blitz On for Idle |\n"
- );
- pprintf(p,
- " +---------------------------------------------------------------+\n"
- );
-
- for (i = 0; i < num; i++) {
- p1 = plist[i];
-
- strcpy(playerLine, " |");
-
- if (parray[p1].game >= 0)
- sprintf(tmp, "%3d", parray[p1].game + 1);
- else
- sprintf(tmp, " ");
- strcat(playerLine, tmp);
-
- if (!parray[p1].open)
- sprintf(tmp, "X");
- else
- sprintf(tmp, " ");
- strcat(playerLine, tmp);
-
- if (parray[p1].registered)
- if (parray[p1].rated) {
- sprintf(tmp, " ");
- } else {
- sprintf(tmp, "u");
- }
- else
- sprintf(tmp, "U");
- strcat(playerLine, tmp);
-
- /* Modified by DAV 3/15/95 */
- if (p == p1) {
- strcpy(tmp, " ");
- psprintf_highlight(p, tmp + strlen(tmp), "%-17s", parray[p1].name);
- } else {
- sprintf(tmp, " %-17s", parray[p1].name);
- }
- strcat(playerLine, tmp);
-
- sprintf(tmp, " %4s %-4s %5s ",
- ratstrii(parray[p1].s_stats.rating, parray[p1].registered),
- ratstrii(parray[p1].b_stats.rating, parray[p1].registered),
- hms(player_ontime(p1), 0, 0, 0));
- strcat(playerLine, tmp);
-
- if (player_idle(p1) >= 60) {
- sprintf(tmp, "%5s |\n", hms(player_idle(p1), 0, 0, 0));
- } else {
- sprintf(tmp, " |\n");
- }
- strcat(playerLine, tmp);
- pprintf(p, "%s", playerLine);
- }
-
- pprintf(p,
- " | |\n"
- );
- pprintf(p,
- " | %3d Players Displayed |\n",
- num
- );
- pprintf(p,
- " +---------------------------------------------------------------+\n"
- );
-}
-
-PRIVATE void who_winloss(p, num, plist)
-int p;
-int num;
-int plist[];
-{
- int i, p1;
- char playerLine[255], tmp[255]; /* for highlight */
-
- pprintf(p,
- "Name Stand win loss draw Blitz win loss draw idle\n"
- );
- pprintf(p,
- "---------------- ----- ------------- ----- ------------- ----\n"
- );
-
- for (i = 0; i < num; i++) {
- p1 = plist[i];
- if (p1 == p) {
- psprintf_highlight(p, playerLine, "%-17s", parray[p1].name);
- } else {
- sprintf(playerLine, "%-17s", parray[p1].name);
- }
- sprintf(tmp, " %4s %4d %4d %4d ",
- ratstrii(parray[p1].s_stats.rating, parray[p1].registered),
- (int) parray[p1].s_stats.win,
- (int) parray[p1].s_stats.los,
- (int) parray[p1].s_stats.dra);
- strcat(playerLine, tmp);
-
- sprintf(tmp, "%4s %4d %4d %4d ",
- ratstrii(parray[p1].b_stats.rating, parray[p1].registered),
- (int) parray[p1].b_stats.win,
- (int) parray[p1].b_stats.los,
- (int) parray[p1].b_stats.dra);
- strcat(playerLine, tmp);
-
- if (player_idle(p1) >= 60) {
- sprintf(tmp, "%5s\n", hms(player_idle(p1), 0, 0, 0));
- } else {
- sprintf(tmp, " \n");
- }
- strcat(playerLine, tmp);
-
- pprintf(p, "%s", playerLine);
- }
- pprintf(p, " %3d Players Displayed.\n", num);
-}
-
-PRIVATE int who_ok(p, sel_bits)
-int p;
-unsigned int sel_bits;
-{
- if (parray[p].status != PLAYER_PROMPT)
- return 0;
- if (sel_bits == 0xff)
- return 1;
- if (sel_bits & WHO_OPEN)
- if (!parray[p].open)
- return 0;
- if (sel_bits & WHO_CLOSED)
- if (parray[p].open)
- return 0;
- if (sel_bits & WHO_RATED)
- if (!parray[p].rated)
- return 0;
- if (sel_bits & WHO_UNRATED)
- if (parray[p].rated)
- return 0;
- if (sel_bits & WHO_FREE)
- if (parray[p].game >= 0)
- return 0;
- if (sel_bits & WHO_PLAYING)
- if (parray[p].game < 0)
- return 0;
- if (sel_bits & WHO_REGISTERED)
- if (!parray[p].registered)
- return 0;
- if (sel_bits & WHO_UNREGISTERED)
- if (parray[p].registered)
- return 0;
- return 1;
-}
-
-
-PRIVATE int blitz_cmp(const void *pp1, const void *pp2)
-{
- register int p1 = *(int *) pp1;
- register int p2 = *(int *) pp2;
- if (parray[p1].status != PLAYER_PROMPT) {
- if (parray[p2].status != PLAYER_PROMPT)
- return 0;
- else
- return -1;
- }
- if (parray[p2].status != PLAYER_PROMPT)
- return 1;
- if (parray[p1].b_stats.rating > parray[p2].b_stats.rating)
- return -1;
- if (parray[p1].b_stats.rating < parray[p2].b_stats.rating)
- return 1;
- if (parray[p1].registered > parray[p2].registered)
- return -1;
- if (parray[p1].registered < parray[p2].registered)
- return 1;
- return strcmp(parray[p1].login, parray[p2].login);
-}
-
-PRIVATE int stand_cmp(const void *pp1, const void *pp2)
-{
- register int p1 = *(int *) pp1;
- register int p2 = *(int *) pp2;
- if (parray[p1].status != PLAYER_PROMPT) {
- if (parray[p2].status != PLAYER_PROMPT)
- return 0;
- else
- return -1;
- }
- if (parray[p2].status != PLAYER_PROMPT)
- return 1;
- if (parray[p1].s_stats.rating > parray[p2].s_stats.rating)
- return -1;
- if (parray[p1].s_stats.rating < parray[p2].s_stats.rating)
- return 1;
- if (parray[p1].registered > parray[p2].registered)
- return -1;
- if (parray[p1].registered < parray[p2].registered)
- return 1;
- return strcmp(parray[p1].login, parray[p2].login);
-}
-
-PRIVATE int wild_cmp(const void *pp1, const void *pp2)
-{
- register int p1 = *(int *) pp1;
- register int p2 = *(int *) pp2;
- if (parray[p1].status != PLAYER_PROMPT) {
- if (parray[p2].status != PLAYER_PROMPT)
- return 0;
- else
- return -1;
- }
- if (parray[p2].status != PLAYER_PROMPT)
- return 1;
- if (parray[p1].w_stats.rating > parray[p2].w_stats.rating)
- return -1;
- if (parray[p1].w_stats.rating < parray[p2].w_stats.rating)
- return 1;
- if (parray[p1].registered > parray[p2].registered)
- return -1;
- if (parray[p1].registered < parray[p2].registered)
- return 1;
- return strcmp(parray[p1].login, parray[p2].login);
-}
-
-PRIVATE int alpha_cmp(const void *pp1, const void *pp2)
-{
- register int p1 = *(int *) pp1;
- register int p2 = *(int *) pp2;
- if (parray[p1].status != PLAYER_PROMPT) {
- if (parray[p2].status != PLAYER_PROMPT)
- return 0;
- else
- return -1;
- }
- if (parray[p2].status != PLAYER_PROMPT)
- return 1;
- return strcmp(parray[p1].login, parray[p2].login);
-}
-
-PUBLIC void sort_players(int players[PARRAY_SIZE],
- int ((*cmp_func) (const void *, const void *)))
-{
- int i;
-
- for (i = 0; i < p_num; i++) {
- players[i] = i;
- }
- qsort(players, p_num, sizeof(int), cmp_func);
-}
-
-/* This is the of the most compliclicated commands in terms of parameters */
-PUBLIC int com_who(int p, param_list param)
-{
- int style = 0;
- float stop_perc = 1.0;
- float start_perc = 0;
- unsigned int sel_bits = 0xff;
- int sortlist[PARRAY_SIZE], plist[PARRAY_SIZE];
- int ((*cmp_func) (const void *, const void *)) = blitz_cmp;
- int startpoint;
- int stoppoint;
- int i, len;
- int tmpI, tmpJ;
- char c;
- int p1, count, num_who;
- int sort_type = blitz_rat;
-
- if (param[0].type == TYPE_WORD) {
- len = strlen(param[0].val.word);
- for (i = 0; i < len; i++) {
- c = param[0].val.word[i];
- if (isdigit(c)) {
- if (i == 0 || !isdigit(param[0].val.word[i - 1])) {
- tmpI = c - '0';
- if (tmpI == 1) {
- start_perc = 0.0;
- stop_perc = 0.333333;
- } else if (tmpI == 2) {
- start_perc = 0.333333;
- stop_perc = 0.6666667;
- } else if (tmpI == 3) {
- start_perc = 0.6666667;
- stop_perc = 1.0;
- } else if ((i == len - 1) || (!isdigit(param[0].val.word[i + 1])))
- return COM_BADPARAMETERS;
- } else {
- tmpI = c - '0';
- tmpJ = param[0].val.word[i - 1] - '0';
- if (tmpI == 0)
- return COM_BADPARAMETERS;
- if (tmpJ > tmpI)
- return COM_BADPARAMETERS;
- start_perc = ((float) tmpJ - 1.0) / (float) tmpI;
- stop_perc = ((float) tmpJ) / (float) tmpI;
- }
- } else {
- switch (c) {
- case 'o':
- if (sel_bits == 0xff)
- sel_bits = WHO_OPEN;
- else
- sel_bits |= WHO_OPEN;
- break;
- case 'r':
- if (sel_bits == 0xff)
- sel_bits = WHO_RATED;
- else
- sel_bits |= WHO_RATED;
- break;
- case 'f':
- if (sel_bits == 0xff)
- sel_bits = WHO_FREE;
- else
- sel_bits |= WHO_FREE;
- break;
- case 'a':
- if (sel_bits == 0xff)
- sel_bits = WHO_FREE | WHO_OPEN;
- else
- sel_bits |= (WHO_FREE | WHO_OPEN);
- break;
- case 'R':
- if (sel_bits == 0xff)
- sel_bits = WHO_REGISTERED;
- else
- sel_bits |= WHO_REGISTERED;
- break;
- case 'l': /* Sort order */
- cmp_func = alpha_cmp;
- sort_type = none;
- break;
- case 'A': /* Sort order */
- cmp_func = alpha_cmp;
- break;
- case 'w': /* Sort order */
- cmp_func = wild_cmp;
- sort_type = wild_rat;
- break;
- case 's': /* Sort order */
- cmp_func = stand_cmp;
- sort_type = std_rat;
- break;
- case 'b': /* Sort order */
- cmp_func = blitz_cmp;
- sort_type = blitz_rat;
- break;
- case 't': /* format */
- style = 0;
- break;
- case 'v': /* format */
- style = 1;
- break;
- case 'n': /* format */
- style = 2;
- break;
- case 'U':
- if (sel_bits == 0xff)
- sel_bits = WHO_UNREGISTERED;
- else
- sel_bits |= WHO_UNREGISTERED;
- break;
- default:
- return COM_BADPARAMETERS;
- break;
- }
- }
- }
- }
- sort_players(sortlist, cmp_func);
- count = 0;
- for (p1 = 0; p1 < p_num; p1++) {
- if (!who_ok(sortlist[p1], sel_bits))
- continue;
- count++;
- }
- startpoint = floor((float) count * start_perc);
- stoppoint = ceil((float) count * stop_perc) - 1;
- num_who = 0;
- count = 0;
- for (p1 = 0; p1 < p_num; p1++) {
- if (!who_ok(sortlist[p1], sel_bits))
- continue;
- if ((count >= startpoint) && (count <= stoppoint)) {
- plist[num_who++] = sortlist[p1];
- }
- count++;
- }
- if (num_who == 0) {
- pprintf(p, "No logged in players match the flags in your who request.\n");
- return COM_OK;
- }
- switch (style) {
- case 0: /* terse */
- who_terse(p, num_who, plist, sort_type);
- break;
- case 1: /* verbose */
- who_verbose(p, num_who, plist);
- break;
- case 2: /* win-loss */
- who_winloss(p, num_who, plist);
- break;
- default:
- return COM_BADPARAMETERS;
- break;
- }
- return COM_OK;
-}
-
-PUBLIC int com_refresh(int p, param_list param)
-{
- int g, p1;
-
- if (param[0].type == TYPE_NULL) {
- if (parray[p].game >= 0) {
- send_board_to(parray[p].game, p);
- } else { /* Do observing in here */
- if (parray[p].num_observe) {
- for (g = 0; g < parray[p].num_observe; g++) {
- send_board_to(parray[p].observe_list[g], p);
- }
- } else {
- pprintf(p, "You are neither playing, observing nor examining a game.\n");
- return COM_OK;
- }
- }
- } else {
- g = GameNumFromParam (p, &p1, &param[0]);
- if (g < 0)
- return COM_OK;
- if ((g >= g_num) || ((garray[g].status != GAME_ACTIVE)
- && (garray[g].status != GAME_EXAMINE))) {
- pprintf(p, "No such game.\n");
- } else if (garray[g].private && parray[p].adminLevel==ADMIN_USER) {
- pprintf (p, "Sorry, game %d is a private game.\n", g+1);
- } else {
- if (garray[g].private)
- pprintf(p, "Refreshing PRIVATE game %d\n", g+1);
- send_board_to(g, p);
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_open(int p, param_list param)
-{
- int retval;
- ASSERT(param[0].type == TYPE_NULL);
- if ((retval = pcommand(p, "set open")) != COM_OK)
- return retval;
- else
- return COM_OK_NOPROMPT;
-}
-
-PUBLIC int com_simopen(int p, param_list param)
-{
- int retval;
- ASSERT(param[0].type == TYPE_NULL);
- if ((retval = pcommand(p, "set simopen")) != COM_OK)
- return retval;
- else
- return COM_OK_NOPROMPT;
-}
-
-PUBLIC int com_bell(int p, param_list param)
-{
- int retval;
- ASSERT(param[0].type == TYPE_NULL);
- if ((retval = pcommand(p, "set bell")) != COM_OK)
- return retval;
- else
- return COM_OK_NOPROMPT;
-}
-
-PUBLIC int com_flip(int p, param_list param)
-{
- int retval;
- ASSERT(param[0].type == TYPE_NULL);
- if ((retval = pcommand(p, "set flip")) != COM_OK)
- return retval;
- else
- return COM_OK_NOPROMPT;
-}
-
-PUBLIC int com_highlight(int p, param_list param)
-{
- pprintf(p, "Obsolete command. Please do set highlight <0-15>.\n");
- return COM_OK;
-}
-
-PUBLIC int com_style(int p, param_list param)
-{
- int retval;
- ASSERT(param[0].type == TYPE_INT);
- if ((retval = pcommand(p, "set style %d", param[0].val.integer)) != COM_OK)
- return retval;
- else
- return COM_OK_NOPROMPT;
-}
-
-PUBLIC int com_promote(int p, param_list param)
-{
- int retval;
- ASSERT(param[0].type == TYPE_WORD);
- if ((retval = pcommand(p, "set promote %s", param[0].val.word)) != COM_OK)
- return retval;
- else
- return COM_OK_NOPROMPT;
-}
-
-PUBLIC int com_alias(int p, param_list param)
-{
- int al;
-
- if (param[0].type == TYPE_NULL) {
- for (al = 0; al < parray[p].numAlias; al++) {
- pprintf(p, "%s -> %s\n", parray[p].alias_list[al].comm_name,
- parray[p].alias_list[al].alias);
- }
- return COM_OK;
- }
- al = alias_lookup(param[0].val.word, parray[p].alias_list, parray[p].numAlias);
- if (param[1].type == TYPE_NULL) {
- if (al < 0) {
- pprintf(p, "You have no alias named '%s'.\n", param[0].val.word);
- } else {
- pprintf(p, "%s -> %s\n", parray[p].alias_list[al].comm_name,
- parray[p].alias_list[al].alias);
- }
- } else {
- if (al < 0) {
- if (parray[p].numAlias >= MAX_ALIASES - 1) {
- pprintf(p, "You have your maximum of %d aliases.\n", MAX_ALIASES - 1);
- } else {
-
- if (!strcmp(param[0].val.string, "quit")) { /* making sure they
- can't alias quit */
- pprintf(p, "You can't alias this command.\n");
- } else if (!strcmp(param[0].val.string, "unalias")) { /* making sure they
- can't alias unalias
- :) */
- pprintf(p, "You can't alias this command.\n");
- } else {
- parray[p].alias_list[parray[p].numAlias].comm_name =
- strdup(param[0].val.word);
- parray[p].alias_list[parray[p].numAlias].alias =
- strdup(param[1].val.string);
- parray[p].numAlias++;
- pprintf(p, "Alias set.\n");
-
- }
- }
- } else {
- rfree(parray[p].alias_list[al].alias);
- parray[p].alias_list[al].alias = strdup(param[1].val.string);
- pprintf(p, "Alias replaced.\n");
- }
- parray[p].alias_list[parray[p].numAlias].comm_name = NULL;
- }
- return COM_OK;
-}
-
-PUBLIC int com_unalias(int p, param_list param)
-{
- int al;
- int i;
-
- ASSERT(param[0].type == TYPE_WORD);
- al = alias_lookup(param[0].val.word, parray[p].alias_list, parray[p].numAlias);
- if (al < 0) {
- pprintf(p, "You have no alias named '%s'.\n", param[0].val.word);
- } else {
- rfree(parray[p].alias_list[al].comm_name);
- rfree(parray[p].alias_list[al].alias);
- for (i = al; i < parray[p].numAlias; i++) {
- parray[p].alias_list[i].comm_name = parray[p].alias_list[i + 1].comm_name;
- parray[p].alias_list[i].alias = parray[p].alias_list[i + 1].alias;
- }
- parray[p].numAlias--;
- parray[p].alias_list[parray[p].numAlias].comm_name = NULL;
- pprintf(p, "Alias removed.\n");
- }
- return COM_OK;
-}
-
-PUBLIC int com_servers(int p, param_list param)
-{
-/*
- int i;
-
- ASSERT(param[0].type == TYPE_NULL);
- if (numServers == 0) {
- */ pprintf(p, "There are no other servers known to this server.\n");
- return COM_OK;
-}
- /* pprintf(p, "There are %d known servers.\n", numServers); pprintf(p, "(Not
- all of these may be active)\n"); pprintf(p, "%-30s%-7s\n", "HOST",
- "PORT"); for (i = 0; i < numServers; i++) pprintf(p, "%-30s%-7d\n",
- serverNames[i], serverPorts[i]); return COM_OK; } */
-
-PUBLIC int com_index(int p, param_list param)
-{
- int i;
- char index_default[] = "_index";
- char *iwant, *filenames[100]; /* enough for all index filenames */
-
- if (param[0].type == TYPE_NULL) {
- iwant = index_default;
- } else {
- iwant = param[0].val.word;
- if (!safestring(iwant)) {
- pprintf(p, "Illegal character in category %s.\n", iwant);
- return COM_OK;
- }
- }
-
- i = search_directory(index_dir, iwant, filenames, 1000);
- if (i == 0) {
- pprintf(p, "No index entry for \"%s\".\n", iwant);
- } else if ((i == 1) || !strcmp(*filenames, iwant)) {
- if (psend_file(p, index_dir, *filenames)) {
- /* we should never reach this unless the file was just deleted */
- pprintf(p, "Index file %s could not be found! ", *filenames);
- pprintf(p, "Please inform an admin of this. Thank you.\n");
- }
- } else {
- pprintf(p, "Matches:");
- display_directory(p, filenames, i);
- }
- return COM_OK;
-}
-
-PUBLIC int com_help(int p, param_list param)
-{
- int i, UseLang = parray[p].language;
- char help_default[] = "_help";
- char *iwant, *filenames[1000]; /* enough for all helpfile names */
-
- if (param[0].type == TYPE_NULL) {
- iwant = help_default;
- } else {
- iwant = param[0].val.word;
- if (!safestring(iwant)) {
- pprintf(p, "Illegal character in command %s.\n", iwant);
- return COM_OK;
- }
- }
- i = search_directory(help_dir[UseLang], iwant, filenames, 1000);
- if (i == 0) {
- if (UseLang != LANG_DEFAULT) {
- i += search_directory(help_dir[LANG_DEFAULT], iwant, filenames, 1000);
- if (i > 0) {
- pprintf(p, "No help available in %s; using %s instead.\n",
- Language(UseLang), Language(LANG_DEFAULT));
- UseLang = LANG_DEFAULT;
- }
- }
- if (i==0) {
- pprintf(p, "No help available on \"%s\".\n", iwant);
- return COM_OK;
- }
- }
- if ((i == 1) || !strcmp(*filenames, iwant)) {
- if (psend_file(p, help_dir[UseLang], *filenames)) {
- /* we should never reach this unless the file was just deleted */
- pprintf(p, "Helpfile %s could not be found! ", *filenames);
- pprintf(p, "Please inform an admin of this. Thank you.\n");
- }
- } else {
- pprintf(p, "Matches:");
- display_directory(p, filenames, i);
- pprintf(p, "[Type \"info\" for a list of FICS general information files.]\n");
- }
- return COM_OK;
-}
-
-PUBLIC int com_info(int p, param_list param)
-{
- int n;
- char *filenames[1000];
-
- if ((n = search_directory(info_dir, NULL, filenames, 1000)) > 0)
- display_directory(p, filenames, n);
- return COM_OK;
-}
-
-PUBLIC int com_adhelp(int p, param_list param)
-{
- int i;
- static char nullify = '\0';
- char *iwant, *filenames[1000]; /* enough for all helpfile names */
-
- if (param[0].type == TYPE_NULL) {
- iwant = &nullify;
- } else {
- iwant = param[0].val.word;
- if (!safestring(iwant)) {
- pprintf(p, "Illegal character in command %s.\n", iwant);
- return COM_OK;
- }
- }
-
- i = search_directory(adhelp_dir, iwant, filenames, 1000);
- if (i == 0) {
- pprintf(p, "No help available on \"%s\".\n", iwant);
- } else if ((i == 1) || !strcmp(*filenames, iwant)) {
- if (psend_file(p, adhelp_dir, *filenames)) {
- /* we should never reach this unless the file was just deleted */
- pprintf(p, "Helpfile %s could not be found! ", *filenames);
- pprintf(p, "Please inform an admin of this. Thank you.\n");
- }
- } else {
- if (*iwant)
- pprintf(p, "Matches:\n");
- display_directory(p, filenames, i);
- }
- return COM_OK;
-}
-
-PUBLIC int com_mailsource(int p, param_list param)
-{
- static char nullify = '\0';
- char *iwant, *buffer[1000];
- char subj[81], fname[MAX_FILENAME_SIZE];
- int count;
-
- if (!parray[p].registered) {
- pprintf(p, "Only registered people can use the mailsource command.\n");
- return COM_OK;
- }
-
- if (param[0].type == TYPE_NULL) {
- iwant = &nullify;
- } else {
- iwant = param[0].val.word;
- }
-
- count = search_directory(source_dir, iwant, buffer, 1000);
- if (count == 0) {
- pprintf(p, "Found no source file matching \"%s\".\n", iwant);
- } else if ((count == 1) || !strcmp(iwant, *buffer)) {
- sprintf(subj, "FICS source file from server %s: %s",fics_hostname,*buffer);
- sprintf(fname, "%s/%s",source_dir, *buffer);
- mail_file_to_user (p, subj, fname);
- pprintf(p, "Source file %s sent to %s\n", *buffer, parray[p].emailAddress);
- } else {
- pprintf(p, "Found %d source files matching that:\n", count);
- if (*iwant)
- display_directory(p, buffer, count);
- else { /* this junk is to get *.c *.h */
- multicol *m = multicol_start(count);
- char *s;
- int i;
- for (i=0; i < count; i++) {
- if (((s = buffer[i] + strlen(buffer[i]) - 2) >= buffer[i]) && (!strcmp(s, ".c") || !strcmp(s, ".h")))
- multicol_store(m, buffer[i]);
- }
- multicol_pprint(m, p, 78, 1);
- multicol_end(m);
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_mailhelp(int p, param_list param)
-{ /* Sparky */
- char subj[81], fname[MAX_FILENAME_SIZE];
- char *iwant, *buffer[1000];
-
- int count;
- static char nullify = '\0';
-
- if (!parray[p].registered) {
- pprintf(p, "Only registered people can use the mailhelp command.\n");
- return COM_OK;
- }
- if (param[0].type == TYPE_NULL)
- iwant = &nullify;
- else
- iwant = param[0].val.word;
-
- count = search_directory(help_dir[parray[p].language], iwant, buffer, 1000);
- if (count == 0) {
- pprintf(p, "Found no help file matching \"%s\".\n", iwant);
- } else if (count == 1) {
- sprintf(subj, "FICS help file from server %s: %s", fics_hostname, *buffer);
- sprintf(fname, "%s/%s",help_dir[parray[p].language], *buffer);
- mail_file_to_user (p, subj, fname);
- pprintf(p, "Help file %s sent to %s\n", *buffer, parray[p].emailAddress);
- } else {
- pprintf(p, "Found %d helpfiles matching that:\n", count);
- display_directory(p, buffer, count);
- }
-
- return COM_OK;
-}
-
-PUBLIC int com_handles(int p, param_list param)
-{
- char *buffer[1000];
- char pdir[MAX_FILENAME_SIZE];
- int count;
-
- sprintf(pdir, "%s/%c", player_dir, param[0].val.word[0]);
- count = search_directory(pdir, param[0].val.word, buffer, 1000);
- pprintf(p, "Found %d names.\n", count);
- if (count > 0)
- display_directory(p, buffer, count);
- return COM_OK;
-}
-
-PUBLIC int com_getpi(int p, param_list param)
-{
- int p1;
-
- if (!in_list("td", parray[p].name)) {
- pprintf(p, "Only TD programs are allowed to use this command.\n");
- return COM_OK;
- }
- if (((p1 = player_find_bylogin(param[0].val.word)) < 0) || (parray[p1].registered == 0)) {
- /* Darkside suggested not to return anything */
- return COM_OK;
- }
- if (!parray[p1].registered) {
- pprintf(p, "*getpi %s -1 -1 -1*\n", parray[p1].name);
- } else {
- pprintf(p, "*getpi %s %d %d %d*\n", parray[p1].name,
- parray[p1].w_stats.rating,
- parray[p1].b_stats.rating,
- parray[p1].s_stats.rating);
- }
- return COM_OK;
-}
-
-PUBLIC int com_getps(int p, param_list param)
-{
- int p1;
-
- if ((((p1 = player_find_bylogin(param[0].val.word)) < 0) || (parray[p1].registered == 0)) || (parray[p1].game < 0)) {
- pprintf(p, "*status %s 1*\n", param[0].val.word);
- return COM_OK;
- }
- pprintf(p, "*status %s 0 %s*\n", parray[p1].name, parray[(parray[p1].opponent)].name);
- return COM_OK;
-}
-PUBLIC int com_limits(int p, param_list param)
-{
- pprintf(p, "\nCurrent hardcoded limits:\n");
- pprintf(p, " Max number of players: %d\n", MAX_PLAYER);
- pprintf(p, " Max number of channels and max capacity: %d\n", MAX_CHANNELS);
- pprintf(p, " Max number of channels one can be in: %d\n", MAX_INCHANNELS);
- pprintf(p, " Max number of people on the notify list: %d\n", MAX_NOTIFY);
- pprintf(p, " Max number of aliases: %d\n", MAX_ALIASES - 1);
- pprintf(p, " Max number of games you can observe at a time: %d\n", MAX_OBSERVE);
- pprintf(p, " Max number of requests pending: %d\n", MAX_PENDING);
- pprintf(p, " Max number of people on the censor list: %d\n", MAX_CENSOR);
- pprintf(p, " Max number of people in a simul game: %d\n", MAX_SIMUL);
- pprintf(p, " Max number of messages one can receive: %d\n", MAX_MESSAGES);
- pprintf(p, " Min number of games to be active: %d\n", PROVISIONAL);
- pprintf(p, "\nAdmin settable limits:\n");
- pprintf(p, " Quota list gives two shouts per %d seconds.\n", quota_time);
- return COM_OK;
-}
diff --git a/FICS/ficsmain.c.orig b/FICS/ficsmain.c.orig
deleted file mode 100644
index d8ad0a1..0000000
--- a/FICS/ficsmain.c.orig
+++ /dev/null
@@ -1,171 +0,0 @@
-/* ficsmain.c
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-
-#include "stdinclude.h"
-
-#include "common.h"
-#include "ficsmain.h"
-#include "config.h"
-#include "network.h"
-#include "command.h"
-#include "channel.h"
-#include "playerdb.h"
-#include "ratings.h"
-#include "utils.h"
-/*#include "hostinfo.h" */
-#include "board.h"
-#include "talkproc.h"
-#include "comproc.h"
-#include "eco.h"
-
-/* Arguments */
-PUBLIC int port;
-PUBLIC int withConsole;
-
-/* grimm */
-void player_array_init(void);
-/* for warning */
-
-PRIVATE void usage(char *progname)
-{
- fprintf(stderr, "Usage: %s [-p port] [-C] [-h]\n", progname);
- fprintf(stderr, "\t\t-p port\t\tSpecify port. (Default=5000)\n");
- fprintf(stderr, "\t\t-C\t\tStart with console player connected to stdin.\n");
- fprintf(stderr, "\t\t-h\t\tDisplay this information.\n");
- exit(1);
-}
-
-PRIVATE void GetArgs(int argc, char *argv[])
-{
- int i;
-
- port = DEFAULT_PORT;
- withConsole = 0;
-
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-') {
- switch (argv[i][1]) {
- case 'p':
- if (i == argc - 1)
- usage(argv[0]);
- i++;
- if (sscanf(argv[i], "%d", &port) != 1)
- usage(argv[0]);
- break;
- case 'C':
- fprintf(stderr, "-C Not implemented!\n");
- exit(1);
- withConsole = 1;
- break;
- case 'h':
- usage(argv[0]);
- break;
- }
- } else {
- usage(argv[0]);
- }
- }
-}
-
-PRIVATE void main_event_loop(void) {
-int current_socket;
-char command_string[MAX_STRING_LENGTH];
-
- while (1) {
- ngc2(command_string, HEARTBEATTIME);
- if (process_heartbeat(&current_socket) == COM_LOGOUT) {
- process_disconnection(current_socket);
- net_close_connection(current_socket);
- }
- }
-}
-
-void TerminateServer(int sig)
-{
- fprintf(stderr, "FICS: Got signal %d\n", sig);
- TerminateCleanup();
- net_close();
- exit(1);
-}
-
-void BrokenPipe(int sig)
-{
- fprintf(stderr, "FICS: Got Broken Pipe\n");
-}
-
-PUBLIC int main(int argc, char *argv[])
-{
-#ifdef SYSTEM_NEXT
-#ifdef DEBUG
- malloc_debug(16);
-#endif
-#endif
- GetArgs(argc, argv);
- signal(SIGTERM, TerminateServer);
- signal(SIGINT, TerminateServer);
- signal(SIGPIPE, BrokenPipe);
- if (net_init(port)) {
- fprintf(stderr, "FICS: Network initialize failed on port %d.\n", port);
- exit(1);
- }
- startuptime = time(0);
- gethostname(fics_hostname, 80);
- quota_time = 60;
- player_high = 0;
- game_high = 0;
- srand(startuptime);
- fprintf(stderr, "FICS: Initialized on port %d at %s.\n", port, strltime(&startuptime));
-/* iamserver = 0; */
-/* if (hostinfo_init()) {
- MailGameResult = 0;
- fprintf(stderr, "FICS: No ratings server connection.\n");
- } else {
- if (iamserver) {
- fprintf(stderr, "FICS: I don't know how to be a ratings server, refusing.\n");
- MailGameResult = 0;
- } else {
- fprintf(stderr, "FICS: Ratings server set to: %s\n", hArray[0].email_address);
- MailGameResult = 1;
- }
- } */
-/* if (mail_log_file)
- fclose(mail_log_file); */
- fprintf(stderr, "FICS: commands_init()\n");
- commands_init();
- fprintf(stderr, "FICS: channel_init()\n");
- channel_init();
- fprintf(stderr, "FICS: rating_init()\n");
- rating_init();
- fprintf(stderr, "FICS: wild_init()\n");
- wild_init();
- fprintf(stderr, "FICS: book init()\n");
- BookInit();
- fprintf(stderr, "FICS: player_array_init()\n");
- player_array_init();
- player_init(withConsole);
- main_event_loop();
- fprintf(stderr, "FICS: Closing down.\n");
- net_close();
- return 0;
-}
diff --git a/FICS/gameproc.c.orig b/FICS/gameproc.c.orig
deleted file mode 100644
index 832f5c9..0000000
--- a/FICS/gameproc.c.orig
+++ /dev/null
@@ -1,2826 +0,0 @@
-/* gameproc.c
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-
-#include "stdinclude.h"
-
-#include "common.h"
-#include "command.h"
-#include "ficsmain.h"
-#include "config.h"
-#include "playerdb.h"
-#include "gamedb.h"
-#include "gameproc.h"
-#include "movecheck.h"
-#include "utils.h"
-#include "ratings.h"
-#include "rmalloc.h"
-#include "comproc.h"
-#include "matchproc.h"
-#include "formula.h"
-#include "eco.h"
-#include "network.h"
-/* #include "hostinfo.h" */
-
-PUBLIC void game_ended(int g, int winner, int why)
-{
- char outstr[200];
- char tmp[200];
- int p;
- int rate_change = 0;
- int isDraw = 0;
- int whiteResult;
- char winSymbol[10];
- char EndSymbol[10];
- char *NameOfWinner, *NameOfLoser;
- int beingplayed = 0; /* i.e. it wasn't loaded for adjudication */
-
- beingplayed = (parray[garray[g].black].game == g);
-
- sprintf(outstr, "\n{Game %d (%s vs. %s) ", g + 1,
- parray[garray[g].white].name,
- parray[garray[g].black].name);
- garray[g].result = why;
- garray[g].winner = winner;
- if (winner == WHITE) {
- whiteResult = RESULT_WIN;
- strcpy(winSymbol, "1-0");
- NameOfWinner = parray[garray[g].white].name;
- NameOfLoser = parray[garray[g].black].name;
- } else {
- whiteResult = RESULT_LOSS;
- strcpy(winSymbol, "0-1");
- NameOfWinner = parray[garray[g].black].name;
- NameOfLoser = parray[garray[g].white].name;
- }
- switch (why) {
- case END_CHECKMATE:
- sprintf(tmp, "%s checkmated} %s\n", NameOfLoser, winSymbol);
- strcpy(EndSymbol, "Mat");
- rate_change = 1;
- break;
- case END_RESIGN:
- sprintf(tmp, "%s resigns} %s\n", NameOfLoser, winSymbol);
- strcpy(EndSymbol, "Res");
- rate_change = 1;
- break;
- case END_FLAG:
- sprintf(tmp, "%s forfeits on time} %s\n", NameOfLoser, winSymbol);
- strcpy(EndSymbol, "Fla");
- rate_change = 1;
- break;
- case END_STALEMATE:
- sprintf(tmp, "Game drawn by stalemate} 1/2-1/2\n");
- isDraw = 1;
- strcpy(EndSymbol, "Sta");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_AGREEDDRAW:
- sprintf(tmp, "Game drawn by mutual agreement} 1/2-1/2\n");
- isDraw = 1;
- strcpy(EndSymbol, "Agr");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_BOTHFLAG:
- sprintf(tmp, "Game drawn because both players ran out of time} 1/2-1/2\n");
- isDraw = 1;
- strcpy(EndSymbol, "Fla");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_REPETITION:
- sprintf(tmp, "Game drawn by repetition} 1/2-1/2\n");
- isDraw = 1;
- strcpy(EndSymbol, "Rep");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_50MOVERULE:
- sprintf(tmp, "Game drawn by the 50 move rule} 1/2-1/2\n");
- isDraw = 1;
- strcpy(EndSymbol, "50");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_ADJOURN:
- sprintf(tmp, "Game adjourned by mutual agreement} *\n");
- game_save(g);
- break;
- case END_LOSTCONNECTION:
- sprintf(tmp, "%s lost connection; game ", NameOfWinner);
- if (parray[garray[g].white].registered && parray[garray[g].black].registered) {
- sprintf(tmp, "adjourned} *\n");
- game_save(g);
- } else
- sprintf(tmp, "aborted} *\n");
- whiteResult = RESULT_ABORT;
- break;
- case END_ABORT:
- sprintf(tmp, "Game aborted by mutual agreement} *\n");
- whiteResult = RESULT_ABORT;
- break;
- case END_COURTESY:
- sprintf(tmp, "Game courtesyaborted by %s} *\n", NameOfWinner);
- whiteResult = RESULT_ABORT;
- break;
- case END_COURTESYADJOURN:
- sprintf(tmp, "Game courtesyadjourned by %s} *\n", NameOfWinner);
- game_save(g);
- break;
- case END_NOMATERIAL:
- /* Draw by insufficient material (e.g., lone K vs. lone K) */
- sprintf(tmp, "Neither player has mating material} 1/2-1/2\n");
- isDraw = 1;
- strcpy(EndSymbol, "NM ");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_FLAGNOMATERIAL:
- sprintf(tmp, "%s ran out of time and %s has no material to mate} 1/2-1/2\n",
- NameOfLoser, NameOfWinner);
- isDraw = 1;
- strcpy(EndSymbol, "TM ");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_ADJWIN:
- sprintf(tmp, "%s wins by adjudication} %s\n", NameOfWinner, winSymbol);
- strcpy(EndSymbol, "Adj");
- rate_change = 1;
- break;
- case END_ADJDRAW:
- sprintf(tmp, "Game drawn by adjudication} 1/2-1/2\n");
- isDraw = 1;
- strcpy(EndSymbol, "Adj");
- rate_change = 1;
- whiteResult = RESULT_DRAW;
- break;
- case END_ADJABORT:
- sprintf(tmp, "Game aborted by adjudication} *\n");
- whiteResult = RESULT_ABORT;
- break;
- default:
- sprintf(tmp, "Hmm, the game ended and I don't know why} *\n");
- break;
- }
- strcat(outstr, tmp);
- if (beingplayed) {
- pprintf_noformat(garray[g].white, outstr);
- pprintf_noformat(garray[g].black, outstr);
-
- for (p = 0; p < p_num; p++) {
- if ((p == garray[g].white) || (p == garray[g].black))
- continue;
- if (parray[p].status != PLAYER_PROMPT)
- continue;
- if (!parray[p].i_game && !player_is_observe(p, g))
- continue;
- pprintf_noformat(p, outstr);
- pprintf_prompt(p, "");
- }
- }
- if ((garray[g].rated) && (rate_change)) {
- /* Adjust ratings */
- rating_update(g);
- if (parray[garray[g].white].network_player &&
- parray[garray[g].black].network_player) {
- if (MailGameResult) { /* Send to ratings server */
- if (isDraw) {
- /* hostinfo_mailresults(garray[g].type == TYPE_BLITZ ? "blitz" :
- garray[g].type == TYPE_WILD ? "wild " : "stand", "
- parray[garray[g].white].name, parray[garray[g].black].name,
- "draw"); */
- } else {
-/* hostinfo_mailresults(garray[g].type == TYPE_BLITZ ? "blitz" : garray[g].type == TYPE_WILD ? "wild " : "stand",
- parray[garray[g].white].name,
- parray[garray[g].black].name,
- (winner == WHITE) ? parray[garray[g].white].name :
- parray[garray[g].black].name); */
- }
- }
- }
- } else {
- if (beingplayed) {
- pprintf(garray[g].white, "No ratings adjustment done.\n");
- pprintf(garray[g].black, "No ratings adjustment done.\n");
- }
- }
- if (rate_change)
- game_write_complete(g, isDraw, EndSymbol);
- /* Mail off the moves */
- if (parray[garray[g].white].automail) {
- pcommand(garray[g].white, "mailmoves");
- }
- if (parray[garray[g].black].automail) {
- pcommand(garray[g].black, "mailmoves");
- }
- parray[garray[g].white].num_white++;
- parray[garray[g].white].lastColor = WHITE;
- parray[garray[g].black].num_black++;
- parray[garray[g].black].lastColor = BLACK;
- parray[garray[g].white].last_opponent = garray[g].black;
- parray[garray[g].black].last_opponent = garray[g].white;
- if (beingplayed) {
- parray[garray[g].white].game = -1;
- parray[garray[g].black].game = -1;
- parray[garray[g].white].opponent = -1;
- parray[garray[g].black].opponent = -1;
- if (garray[g].white != commanding_player)
- pprintf_prompt(garray[g].white, "");
- if (garray[g].black != commanding_player)
- pprintf_prompt(garray[g].black, "");
- if (parray[garray[g].white].simul_info.numBoards) {
- player_simul_over(garray[g].white, g, whiteResult);
- }
- }
- game_finish(g);
-}
-
-PUBLIC void process_move(int p, char *command)
-{
- int g;
- move_t move;
- int result;
- unsigned now;
- int len; /* loon: for lame promotion hack */
- int i;
-
- if (parray[p].game <0) {
- pprintf(p, "You are not playing a game.\n");
- return;
- }
- player_decline_offers(p, -1, -PEND_SIMUL);
- g = parray[p].game;
-
- if (garray[g].status != GAME_EXAMINE) {
- if (parray[p].side != garray[g].game_state.onMove) {
- pprintf(p, "It is not your move.\n");
- return;
- }
- if (garray[g].clockStopped) {
- pprintf(p, "Game clock is paused, use \"unpause\" to resume.\n");
- return;
- }
- }
- if ((len = strlen(command)) > 1) {
- if (command[len - 2] == '=') {
- switch (tolower(command[strlen(command) - 1])) {
- case 'n':
- parray[p].promote = KNIGHT;
- break;
- case 'b':
- parray[p].promote = BISHOP;
- break;
- case 'r':
- parray[p].promote = ROOK;
- break;
- case 'q':
- parray[p].promote = QUEEN;
- break;
- default:
- pprintf(p, "Don't understand that move.\n");
- return;
- break;
- }
- }
- }
- switch (parse_move(command, &garray[g].game_state, &move, parray[p].promote)) {
- case MOVE_ILLEGAL:
- pprintf(p, "Illegal move.\n");
- return;
- break;
- case MOVE_AMBIGUOUS:
- pprintf(p, "Ambiguous move.\n");
- return;
- break;
- default:
- break;
- }
-
- if (garray[g].status == GAME_EXAMINE) {
- garray[g].numHalfMoves++;
- if (garray[g].numHalfMoves > garray[g].examMoveListSize) {
- garray[g].examMoveListSize += 20; /* Allocate 20 moves at a time */
- if (!garray[g].examMoveList) {
- garray[g].examMoveList = (move_t *) rmalloc(sizeof(move_t) * garray[g].examMoveListSize);
- } else {
- garray[g].examMoveList = (move_t *) rrealloc(garray[g].examMoveList, sizeof(move_t) * garray[g].examMoveListSize);
- }
- }
- result = execute_move(&garray[g].game_state, &move, 1);
- move.atTime = now;
- move.tookTime = 0;
- garray[g].examMoveList[garray[g].numHalfMoves - 1] = move;
- /* roll back time */
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- } else {
- garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- }
- now = tenth_secs();
- if (garray[g].numHalfMoves == 0)
- garray[g].timeOfStart = now;
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
-
- } else { /* real game */
- i = parray[p].opponent;
- if (parray[i].simul_info.numBoards &&
- (parray[i].simul_info.boards[parray[i].simul_info.onBoard] != g)) {
- pprintf(p, "It isn't your turn: wait until the simul giver is at your board.\n");
- return;
- }
-#ifdef TIMESEAL
-
-
- if (con[parray[p].socket].timeseal) { /* does he use timeseal? */
- if (parray[p].side == WHITE) {
- garray[g].wLastRealTime = garray[g].wRealTime;
- garray[g].wTimeWhenMoved = con[parray[p].socket].time;
- if (((garray[g].wTimeWhenMoved - garray[g].wTimeWhenReceivedMove) < 0) ||
- (garray[g].wTimeWhenReceivedMove == 0)) {
- /* might seem weird - but could be caused by a person moving BEFORE
- he receives the board pos (this is possible due to lag) but it's
- safe to say he moved in 0 secs :-) */
- garray[g].wTimeWhenReceivedMove = garray[g].wTimeWhenMoved;
- } else {
- garray[g].wRealTime -= garray[g].wTimeWhenMoved - garray[g].wTimeWhenReceivedMove;
- }
- } else if (parray[p].side == BLACK) {
- garray[g].bLastRealTime = garray[g].bRealTime;
- garray[g].bTimeWhenMoved = con[parray[p].socket].time;
- if (((garray[g].bTimeWhenMoved - garray[g].bTimeWhenReceivedMove) < 0) ||
- (garray[g].bTimeWhenReceivedMove == 0)) {
- /* might seem weird - but could be caused by a person moving BEFORE
- he receives the board pos (this is possible due to lag) but it's
- safe to say he moved in 0 secs :-) */
- garray[g].bTimeWhenReceivedMove = garray[g].bTimeWhenMoved;
- } else {
- garray[g].bRealTime -= garray[g].bTimeWhenMoved - garray[g].bTimeWhenReceivedMove;
- }
- }
- }
- if (parray[p].side == WHITE) {
- /* we need to reset the opp's time for receiving the board since the
- timeseal decoder only alters the time if it's 0 Otherwise the time
- would be changed if the player did a refresh which would screw up
- the timings */
- garray[g].bTimeWhenReceivedMove = 0;
- } else {
- /* we need to reset the opp's time for receiving the board since the
- timeseal decoder only alters the time if it's 0 Otherwise the time
- would be changed if the player did a refresh which would screw up
- the timings */
- garray[g].wTimeWhenReceivedMove = 0;
- }
-
-#endif
-
- game_update_time(g);
-
- /* maybe add autoflag here in the future? */
-
-#ifdef TIMESEAL
-
- if (con[parray[p].socket].timeseal) { /* does he use timeseal? */
- if (parray[p].side == WHITE) {
- garray[g].wRealTime += garray[g].wIncrement * 100;
- garray[g].wTime = garray[g].wRealTime / 100; /* remember to conv to
- tenth secs */
- } else if (parray[p].side == BLACK) {
- garray[g].bRealTime += garray[g].bIncrement * 100; /* conv to ms */
- garray[g].bTime = garray[g].bRealTime / 100; /* remember to conv to
- tenth secs */
- }
- } else {
- if (garray[g].game_state.onMove == BLACK) {
- garray[g].bTime += garray[g].bIncrement;
- }
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += garray[g].wIncrement;
- }
- }
-
-#else
-
- if (garray[g].game_state.onMove == BLACK) {
- garray[g].bTime += garray[g].bIncrement;
- }
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += garray[g].wIncrement;
- }
-#endif
-
- /* Do the move */
- garray[g].numHalfMoves++;
- if (garray[g].numHalfMoves > garray[g].moveListSize) {
- garray[g].moveListSize += 20; /* Allocate 20 moves at a time */
- if (!garray[g].moveList) {
- garray[g].moveList = (move_t *) rmalloc(sizeof(move_t) * garray[g].moveListSize);
- } else {
- garray[g].moveList = (move_t *) rrealloc(garray[g].moveList, sizeof(move_t) * garray[g].moveListSize);
- }
- }
- result = execute_move(&garray[g].game_state, &move, 1);
- now = tenth_secs();
- move.atTime = now;
- if (garray[g].numHalfMoves > 1) {
- move.tookTime = move.atTime - garray[g].lastMoveTime;
- } else {
- move.tookTime = move.atTime - garray[g].startTime;
- }
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
-
-#ifdef TIMESEAL
-
- if (con[parray[p].socket].timeseal) { /* does he use timeseal? */
- if (parray[p].side == WHITE) {
- move.tookTime = (garray[parray[p].game].wTimeWhenMoved -
- garray[parray[p].game].wTimeWhenReceivedMove) / 100;
- } else {
- move.tookTime = (garray[parray[p].game].bTimeWhenMoved -
- garray[parray[p].game].bTimeWhenReceivedMove) / 100;
- }
- }
-#endif
-
- garray[g].moveList[garray[g].numHalfMoves - 1] = move;
- }
-
- send_boards(g);
-
- strcpy(garray[g].boardList[garray[g].numHalfMoves], boardToFEN(g));
-
- if (result == MOVE_ILLEGAL) {
- pprintf(p, "Internal error, illegal move accepted!\n");
- }
- if ((result == MOVE_OK) && (garray[g].status == GAME_EXAMINE)) {
- int p1;
-
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf_prompt(p1, "%s moves: %s\n", parray[p].name, move.algString);
- }
- }
- }
- if (result == MOVE_CHECKMATE) {
- if (garray[g].status == GAME_EXAMINE) {
- int p1;
-
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "%s has been checkmated.\n",
- (CToggle(garray[g].game_state.onMove) == BLACK) ? "White" : "Black");
- }
- }
- } else {
- game_ended(g, CToggle(garray[g].game_state.onMove), END_CHECKMATE);
- }
- }
- if (result == MOVE_STALEMATE) {
- if (garray[g].status == GAME_EXAMINE) {
- int p1;
-
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "Stalemate.\n");
- }
- }
- } else {
- game_ended(g, CToggle(garray[g].game_state.onMove), END_STALEMATE);
- }
- }
- if (result == MOVE_NOMATERIAL) {
- if (garray[g].status == GAME_EXAMINE) {
- int p1;
-
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "No mating material.\n");
- }
- }
- } else {
- game_ended(g, CToggle(garray[g].game_state.onMove), END_NOMATERIAL);
- }
- }
-}
-
-int GameNumFromParam(int p, int *p1, parameter *param)
-{
- if (param->type == TYPE_WORD) {
- *p1 = player_find_part_login(param->val.word);
- if (*p1 < 0) {
- pprintf(p, "No user named \"%s\" is logged in.\n", param->val.word);
- return -1;
- }
- if (parray[*p1].game <0)
- pprintf(p, "%s is not playing a game.\n", parray[*p1].name);
- return parray[*p1].game;
- } else { /* Must be an integer */
- *p1 = -1;
- if (param->val.integer <= 0)
- pprintf(p, "%d is not a valid game number.\n", param->val.integer);
- return param->val.integer - 1;
- }
-}
-
-PUBLIC int com_resign(int p, param_list param)
-{
- int g, o, oconnected, confused = 0;
-
- if (param[0].type == TYPE_NULL) {
- g = parray[p].game;
- if ((g < 0) || (garray[g].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- } else {
- player_decline_offers(p, -1, -1);
- game_ended(g, (garray[g].white == p) ? BLACK : WHITE, END_RESIGN);
- }
- } else if (FindPlayer(p, &param[0], &o, &oconnected)) {
- g = game_new();
- if (game_read(g, p, o) < 0) {
- if (game_read(g, o, p) < 0) {
- confused = 1;
- pprintf(p, "You have no stored game with %s\n", parray[o].name);
- } else {
- garray[g].white = o;
- garray[g].black = p;
- }
- } else {
- garray[g].white = p;
- garray[g].black = o;
- }
- if (!confused) {
- pprintf(p, "You resign your stored game with %s\n", parray[o].name);
- game_delete(garray[g].white, garray[g].black);
- game_ended(g, (garray[g].white == p) ? BLACK : WHITE, END_RESIGN);
- pcommand(p, "message %s I have resigned our stored game \"%s vs. %s.\"",
- parray[o].name,
- parray[garray[g].white].name,
- parray[garray[g].black].name);
- if (!oconnected)
- player_remove(o);
- }
- }
- return COM_OK;
-}
-
-/*
-PUBLIC int com_resign(int p, param_list param)
-{
- ASSERT(param[0].type == TYPE_NULL);
- if ((parray[p].game <0) || (garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- player_decline_offers(p, -1, -1);
- game_ended(parray[p].game, (garray[parray[p].game].white == p) ? BLACK : WHITE, END_RESIGN);
- return COM_OK;
-}
-*/
-
-PUBLIC int com_draw(int p, param_list param)
-{
- int p1;
- int move_num = 0;
- int i = 0, flag = 0;
-
- ASSERT(param[0].type == TYPE_NULL);
- if ((parray[p].game <0) ||(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- if (garray[parray[p].game].numHalfMoves - ((garray[parray[p].game].game_state.lastIrreversable == -1) ? 0 : garray[parray[p].game].game_state.lastIrreversable) > 99) {
- game_ended(parray[p].game, (garray[parray[p].game].white == p) ? BLACK : WHITE, END_50MOVERULE);
- return COM_OK;
- }
- if (garray[parray[p].game].game_state.lastIrreversable != -1)
- move_num = garray[parray[p].game].game_state.lastIrreversable;
-
- for (i = (garray[parray[p].game].numHalfMoves - 1); i <= garray[parray[p].game].numHalfMoves; i++) {
- flag = 0;
- if (garray[parray[p].game].game_state.lastIrreversable != -1)
- move_num = garray[parray[p].game].game_state.lastIrreversable;
- for (; move_num <= garray[parray[p].game].numHalfMoves; move_num++) {
- if ((strlen(garray[parray[p].game].boardList[move_num])) !=
- (strlen(garray[parray[p].game].boardList[i])))
- continue;
-
- if (!strcmp(garray[parray[p].game].boardList[move_num],
- garray[parray[p].game].boardList[i]))
- flag++;
- }
- if (flag >= 3) {
- if (player_find_pendfrom(p, parray[p].opponent, PEND_DRAW) >= 0) {
- player_remove_request(parray[p].opponent, p, PEND_DRAW);
- player_decline_offers(p, -1, -1);
- }
- game_ended(parray[p].game, (garray[parray[p].game].white == p) ? BLACK : WHITE, END_REPETITION);
- return COM_OK;
- }
- }
-
- p1 = parray[p].opponent;
- if (parray[p1].simul_info.numBoards &&
- parray[p1].simul_info.boards[parray[p1].simul_info.onBoard] !=
- parray[p].game) {
- pprintf(p, "You can only make requests when the simul player is at your board.\n");
- return COM_OK;
- }
- if (player_find_pendfrom(p, parray[p].opponent, PEND_DRAW) >= 0) {
- player_remove_request(parray[p].opponent, p, PEND_DRAW);
- player_decline_offers(p, -1, -1);
- game_ended(parray[p].game, (garray[parray[p].game].white == p) ? BLACK : WHITE, END_AGREEDDRAW);
- } else {
- pprintf(parray[p].opponent, "\n");
- pprintf_highlight(parray[p].opponent, "%s", parray[p].name);
- pprintf_prompt(parray[p].opponent, " offers you a draw.\n");
- pprintf(p, "Draw request sent.\n");
- player_add_request(p, parray[p].opponent, PEND_DRAW, 0);
- }
- return COM_OK;
-}
-
-PUBLIC int com_pause(int p, param_list param)
-{
- int g;
- int now;
-
- ASSERT(param[0].type == TYPE_NULL);
- if ((parray[p].game <0) ||(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- g = parray[p].game;
- if (garray[g].wTime == 0) {
- pprintf(p, "You can't pause untimed games.\n");
- return COM_OK;
- }
- if (garray[g].clockStopped) {
- pprintf(p, "Game is already paused, use \"unpause\" to resume.\n");
- return COM_OK;
- }
- if (player_find_pendfrom(p, parray[p].opponent, PEND_PAUSE) >= 0) {
- player_remove_request(parray[p].opponent, p, PEND_PAUSE);
- garray[g].clockStopped = 1;
- /* Roll back the time */
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- } else {
- garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- }
- now = tenth_secs();
- if (garray[g].numHalfMoves == 0)
- garray[g].timeOfStart = now;
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
- send_boards(g);
- pprintf_prompt(parray[p].opponent, "\n%s accepted pause. Game clock paused.\n",
- parray[p].name);
- pprintf(p, "Game clock paused.\n");
- } else {
- pprintf(parray[p].opponent, "\n");
- pprintf_highlight(parray[p].opponent, "%s", parray[p].name);
- pprintf_prompt(parray[p].opponent, " requests to pause the game.\n");
- pprintf(p, "Pause request sent.\n");
- player_add_request(p, parray[p].opponent, PEND_PAUSE, 0);
- }
- return COM_OK;
-}
-
-PUBLIC int com_unpause(int p, param_list param)
-{
- int now;
- int g;
-
- ASSERT(param[0].type == TYPE_NULL);
- if ((parray[p].game <0) ||(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- g = parray[p].game;
- if (!garray[g].clockStopped) {
- pprintf(p, "Game is not paused.\n");
- return COM_OK;
- }
- garray[g].clockStopped = 0;
- now = tenth_secs();
- if (garray[g].numHalfMoves == 0)
- garray[g].timeOfStart = now;
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
- send_boards(g);
- pprintf(p, "Game clock resumed.\n");
- pprintf_prompt(parray[p].opponent, "\nGame clock resumed.\n");
- return COM_OK;
-}
-
-PUBLIC int com_abort(int p, param_list param)
-{
- int p1, g, myColor, yourColor;
-
- ASSERT(param[0].type == TYPE_NULL);
-
- g = parray[p].game;
- if ((g < 0) || (garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- p1 = parray[p].opponent;
- myColor = (p == garray[g].white ? WHITE : BLACK);
- yourColor = (myColor == WHITE ? BLACK : WHITE);
-
- if (parray[p1].simul_info.numBoards &&
- parray[p1].simul_info.boards[parray[p1].simul_info.onBoard] != g) {
- pprintf(p, "You can only make requests when the simul player is at your board.\n");
- return COM_OK;
- }
- if (player_find_pendfrom(p, p1, PEND_ABORT) >= 0) {
- player_remove_request(p1, p, PEND_ABORT);
- player_decline_offers(p, -1, -1);
- game_ended(g, yourColor, END_ABORT);
- } else {
- game_update_time(g);
-
-#ifdef TIMESEAL
-
- if (con[parray[parray[p].opponent].socket].timeseal) { /* opp uses timeseal? */
-
- /* If opponent has timeseal - we have no use for courtesyabort since
- courtesyabort was used when opponent lagged out of time which cannot
- happen with timeseal - only courtesyadjourn should be possible.
- Thus: the request can only be for a normal abort of the game. */
-
- pprintf(p1, "\n");
- pprintf_highlight(p1, "%s", parray[p].name);
- pprintf_prompt(p1, " would like to abort the game.\n");
- pprintf(p, "Abort request sent.\n");
- player_add_request(p, p1, PEND_ABORT, 0);
- } else {
- if ((myColor == WHITE && garray[g].wTime > 0 && garray[g].bTime <= 0)
- || (myColor == BLACK && garray[g].bTime > 0 && garray[g].wTime <= 0)) {
- /* player wants to abort + opponent is out of time = courtesyabort */
- pprintf(p, "Since you have time, and your opponent has none, the game has been aborted.");
- pprintf(p1, "Your opponent has aborted the game rather than calling your flag.");
- player_decline_offers(p, -1, -1);
- game_ended(g, myColor, END_COURTESY);
- } else {
- pprintf(p1, "\n");
- pprintf_highlight(p1, "%s", parray[p].name);
- pprintf_prompt(p1, " would like to abort the game.\n");
- pprintf(p, "Abort request sent.\n");
- player_add_request(p, p1, PEND_ABORT, 0);
- }
- }
-
-#else
-
- if ((myColor == WHITE && garray[g].wTime > 0 && garray[g].bTime <= 0)
- || (myColor == BLACK && garray[g].bTime > 0 && garray[g].wTime <= 0)) {
- /* player wants to abort + opponent is out of time = courtesyabort */
- pprintf(p, "Since you have time, and your opponent has none, the game has been aborted.");
- pprintf(p1, "Your opponent has aborted the game rather than calling your flag.");
- player_decline_offers(p, -1, -1);
- game_ended(g, myColor, END_COURTESY);
- } else {
- pprintf(p1, "\n");
- pprintf_highlight(p1, "%s", parray[p].name);
- pprintf(p1, " would like to abort the game; ");
- pprintf_prompt(p1, "type \"abort\" to accept.\n");
- pprintf(p, "Abort request sent.\n");
- player_add_request(p, p1, PEND_ABORT, 0);
- }
-
-#endif
-
- }
- return COM_OK;
-}
-
-#if 0
-int Courtesy(int p, int type)
-{
- int g;
-
- if (parray[p].game <0) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- g = parray[p].game;
- if (garray[g].wInitTime == 0) {
- if (type == END_COURTESY)
- pprintf(p, "You can't courtesy abort an untimed game, just resign.\n");
- else if (type == END_COURTESYADJOURN)
- pprintf(p, "You can't courtesy adjourn an untimed game, just resign.\n");
- return COM_OK;
- }
- game_update_time(g);
- if (((garray[g].white == p) && (garray[g].bTime <= 0) && (garray[g].wTime > 0)) ||
- ((garray[g].black == p) && (garray[g].wTime <= 0) && (garray[g].bTime > 0))) {
- player_decline_offers(p, -1, -1);
- game_ended(parray[p].game, (garray[g].white == p) ? WHITE : BLACK, type);
- } else {
- if (type == END_COURTESY)
- pprintf(p, "Game not aborted.\n");
- else if (type == END_COURTESYADJOURN)
- pprintf(p, "Game not adjourned.\n");
- pprintf(p, "Either your opponent still has time, or you are out of time also.\n");
- }
- return COM_OK;
-}
-
-PUBLIC int com_courtesyabort(int p, param_list param)
-{
- ASSERT(param[0].type == TYPE_NULL);
- return Courtesy(p, END_COURTESY);
-}
-
-PUBLIC int com_courtesyadjourn(int p, param_list param)
-{
- ASSERT(param[0].type == TYPE_NULL);
- if (!garray[parray[p].game].rated) {
- pprintf(p, "You cannot adjourn an unrated game. Use \"courtesyabort\".\n");
- return COM_OK;
- }
- return Courtesy(p, END_COURTESYADJOURN);
-}
-#endif
-
-PUBLIC int com_courtesyabort(int p, param_list param)
-{
- pprintf(p, "Courtesyabort is obsolete; use \"abort\" instead.\n");
- return COM_OK;
-}
-
-PUBLIC int com_courtesyadjourn(int p, param_list param)
-{
- pprintf(p, "Use \"adjourn\" to courtesyadjourn a game.\n");
- return COM_OK;
-}
-
-PRIVATE int player_has_mating_material(game_state_t *gs, int color)
-{
- int i, j;
- int piece;
- int minor_pieces = 0;
-
- for (i = 0; i < 8; i++)
- for (j = 0; j < 8; j++) {
- piece = gs->board[i][j];
- switch (piecetype(piece)) {
- case BISHOP:
- case KNIGHT:
- if (iscolor(piece, color))
- minor_pieces++;
- break;
- case KING:
- case NOPIECE:
- break;
- default:
- if (iscolor(piece, color))
- return 1;
- }
- }
- return ((minor_pieces > 1) ? 1 : 0);
-}
-
-PUBLIC int com_flag(int p, param_list param)
-{
- int g;
- int myColor;
-
- ASSERT(param[0].type == TYPE_NULL);
- if ((parray[p].game <0) ||(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- g = parray[p].game;
- myColor = (p == garray[g].white ? WHITE : BLACK);
- if (garray[g].wInitTime == 0) {
- pprintf(p, "You can't flag an untimed game.\n");
- return COM_OK;
- }
- if (garray[g].numHalfMoves < 2) {
- pprintf(p, "You cannot flag if your opponent has not moved.\nYou can use abort instead.\n");
- return COM_OK;
- }
- game_update_time(g);
-
-#ifdef TIMESEAL
-
- {
- int wt, bt;
-
- if (con[parray[p].socket].timeseal) { /* do caller use timeseal? */
- if (myColor == WHITE) {
- wt = garray[g].wRealTime;
- } else {
- bt = garray[g].bRealTime;
- }
- } else {
- if (myColor == WHITE) {
- wt = garray[g].wTime;
- } else {
- bt = garray[g].bTime;
- }
- }
-
- if (con[parray[parray[p].opponent].socket].timeseal) { /* opp uses timeseal? */
- if (myColor == WHITE) {
- bt = garray[g].bRealTime;
- } else {
- wt = garray[g].wRealTime;
- }
- } else {
- if (myColor == WHITE) {
- bt = garray[g].bTime;
- } else {
- wt = garray[g].wTime;
- }
- }
-
- /* the clocks to compare is now in wt and bt */
-
- if ((wt <= 0) && (bt <= 0)) {
- player_decline_offers(p, -1, -1);
- game_ended(g, myColor, END_BOTHFLAG);
- return COM_OK;
- }
- if (myColor == WHITE) {
- if (bt > 0) {
- pprintf(p, "Your opponent is not out of time!\n");
- return COM_OK;
- }
- } else {
- if (wt > 0) {
- pprintf(p, "Your opponent is not out of time!\n");
- return COM_OK;
- }
- }
- }
-
-#else
-
- if ((garray[g].wTime <= 0) && (garray[g].bTime <= 0)) {
- player_decline_offers(p, -1, -1);
- game_ended(g, myColor, END_BOTHFLAG);
- return COM_OK;
- }
- if (myColor == WHITE) {
- if (garray[g].bTime > 0) {
- pprintf(p, "Your opponent is not out of time!\n");
- return COM_OK;
- }
- } else {
- if (garray[g].wTime > 0) {
- pprintf(p, "Your opponent is not out of time!\n");
- return COM_OK;
- }
- }
-
-#endif
-
- player_decline_offers(p, -1, -1);
- if (player_has_mating_material(&garray[g].game_state, myColor))
- game_ended(g, myColor, END_FLAG);
- else
- game_ended(g, myColor, END_FLAGNOMATERIAL);
- return COM_OK;
-}
-
-PUBLIC int com_adjourn(int p, param_list param)
-{
- int p1, g, myColor, yourColor;
-
- ASSERT(param[0].type == TYPE_NULL);
- g = parray[p].game;
- if ((g < 0) || (garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- p1 = parray[p].opponent;
- if (!(parray[p].registered && parray[p1].registered)) {
- pprintf(p, "Both players must be registered to adjorn a game. Use \"abort\".\n");
- return COM_OK;
- }
- myColor = (p == garray[g].white ? WHITE : BLACK);
- yourColor = (myColor == WHITE ? BLACK : WHITE);
-
- if (player_find_pendfrom(p, p1, PEND_ADJOURN) >= 0) {
- player_remove_request(p1, p, PEND_ADJOURN);
- player_decline_offers(p, -1, -1);
- game_ended(parray[p].game, yourColor, END_ADJOURN);
- } else {
- game_update_time(g);
- if (((myColor == WHITE) && (garray[g].wTime > 0) && (garray[g].bTime <= 0))
- || ((myColor == BLACK) && (garray[g].bTime > 0) && (garray[g].wTime <= 0))) {
-/* player wants to adjourn + opponent is out of time = courtesyadjourn */
- pprintf(p, "Since you have time, and your opponent has none, the game has been adjourned.");
- pprintf(p1, "Your opponent has adjourned the game rather than calling your flag.");
- player_decline_offers(p, -1, -1);
- game_ended(g, myColor, END_COURTESYADJOURN);
- } else {
- pprintf(p1, "\n");
- pprintf_highlight(p1, "%s", parray[p].name);
- pprintf(p1, " would like to adjourn the game; ");
- pprintf_prompt(p1, "type \"adjourn\" to accept.\n");
- pprintf(p, "Adjourn request sent.\n");
- player_add_request(p, p1, PEND_ADJOURN, 0);
- }
- }
- return COM_OK;
-}
-
-PRIVATE int gamesortfunc(const void *i, const void *j)
-{
- return (GetRating(&parray[garray[*(int *) i].white], garray[*(int *) i].type) +
- GetRating(&parray[garray[*(int *) i].black], garray[*(int *) i].type) +
- ((garray[*(int *) i].status == GAME_EXAMINE) ? 10000 : 0) -
- GetRating(&parray[garray[*(int *) j].white], garray[*(int *) j].type) -
- GetRating(&parray[garray[*(int *) j].black], garray[*(int *) j].type) -
- ((garray[*(int *) j].status == GAME_EXAMINE) ? 10000 : 0));
-}
-
-
-PUBLIC int com_games(int p, param_list param)
-{
- int i, j;
- int wp, bp;
- int ws, bs;
- int selected = 0;
- int count = 0;
- int totalcount;
- char *s = NULL;
- int slen = 0;
- int *sortedgames; /* for qsort */
-
- totalcount = game_count();
- if (totalcount == 0) {
- pprintf(p, "There are no games in progress.\n");
- } else {
- sortedgames = rmalloc(totalcount * sizeof(int)); /* for qsort */
-
- if (param[0].type == TYPE_WORD) {
- s = param[0].val.word;
- slen = strlen(s);
- selected = atoi(s);
- if (selected < 0)
- selected = 0;
- }
- for (i = 0; i < g_num; i++) {
- if ((garray[i].status != GAME_ACTIVE) && (garray[i].status != GAME_EXAMINE))
- continue;
- if ((selected) && (selected != i + 1))
- continue; /* not selected game number */
- wp = garray[i].white;
- bp = garray[i].black;
- if ((!selected) && s && strncasecmp(s, garray[i].white_name, slen) &&
- strncasecmp(s, garray[i].black_name, slen))
- continue; /* player names did not match */
- sortedgames[count++] = i;
- }
- if (!count)
- pprintf(p, "No matching games were found (of %d in progress).\n", totalcount);
- else {
- qsort(sortedgames, count, sizeof(int), gamesortfunc);
- pprintf(p, "\n");
- for (j = 0; j < count; j++) {
- i = sortedgames[j];
- wp = garray[i].white;
- bp = garray[i].black;
- board_calc_strength(&garray[i].game_state, &ws, &bs);
- if (garray[i].status != GAME_EXAMINE) {
- pprintf_noformat(p, "%2d %4s %-11.11s %4s %-10.10s [%c%c%c%3d %3d] ",
- i + 1,
- ratstrii(GetRating(&parray[wp],
- garray[i].type),
- parray[wp].registered),
- parray[wp].name,
- ratstrii(GetRating(&parray[bp],
- garray[i].type),
- parray[bp].registered),
- parray[bp].name,
- (garray[i].private) ? 'p' : ' ',
- *bstr[garray[i].type],
- *rstr[garray[i].rated],
- garray[i].wInitTime / 600,
- garray[i].wIncrement / 10);
- game_update_time(i);
- pprintf_noformat(p, "%6s -",
- tenth_str((garray[i].wTime > 0 ? garray[i].wTime : 0), 0));
- pprintf_noformat(p, "%6s (%2d-%2d) %c: %2d\n",
- tenth_str((garray[i].bTime > 0 ? garray[i].bTime : 0), 0),
- ws, bs,
- (garray[i].game_state.onMove == WHITE) ? 'W' : 'B',
- garray[i].game_state.moveNum);
- } else {
- pprintf_noformat(p, "%2d (Exam. %4d %-11.11s %4d %-10.10s) [%c%c%c%3d %3d] ",
- i + 1,
- garray[i].white_rating,
- garray[i].white_name,
- garray[i].black_rating,
- garray[i].black_name,
- (garray[i].private) ? 'p' : ' ',
- *bstr[garray[i].type],
- *rstr[garray[i].rated],
- garray[i].wInitTime / 600,
- garray[i].wIncrement / 10);
- pprintf_noformat(p, "%c: %2d\n",
- (garray[i].game_state.onMove == WHITE) ? 'W' : 'B',
- garray[i].game_state.moveNum);
- }
- }
- if (count < totalcount)
- pprintf(p, "\n %d game%s displayed (of %d in progress).\n", count,
- (count == 1) ? "" : "s", totalcount);
- else
- pprintf(p, "\n %d game%s displayed.\n", totalcount, (totalcount == 1) ? "" : "s");
- }
- rfree(sortedgames);
- }
- return COM_OK;
-}
-
-PRIVATE int do_observe(int p, int obgame)
-{
- if ((garray[obgame].private) && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, game %d is a private game.\n", obgame + 1);
- return COM_OK;
- }
- if ((garray[obgame].white == p) || (garray[obgame].black == p)) {
- if (garray[obgame].status != GAME_EXAMINE) {
- pprintf(p, "You cannot observe a game that you are playing.\n");
- return COM_OK;
- }
- }
- if (player_is_observe(p, obgame)) {
- pprintf(p, "Removing game %d from observation list.\n", obgame + 1);
- player_remove_observe(p, obgame);
- } else {
- if (!player_add_observe(p, obgame)) {
- pprintf(p, "You are now observing game %d.\n", obgame + 1);
- send_board_to(obgame, p);
- } else {
- pprintf(p, "You are already observing the maximum number of games.\n");
- }
- }
- return COM_OK;
-}
-
-PUBLIC void unobserveAll(int p)
-{
- int i;
-
- for (i = 0; i < parray[p].num_observe; i++) {
- pprintf(p, "Removing game %d from observation list.\n", parray[p].observe_list[i] + 1);
- }
- parray[p].num_observe = 0;
- return;
-}
-
-PUBLIC int com_unobserve(int p, param_list param)
-{
- int gNum, p1;
-
- if (param[0].type == TYPE_NULL) {
- unobserveAll(p);
- return COM_OK;
- }
- gNum = GameNumFromParam(p, &p1, &param[0]);
- if (gNum < 0)
- return COM_OK;
- if (!player_is_observe(p, gNum)) {
- pprintf(p, "You are not observing game %d.\n", gNum);
- } else {
- player_remove_observe(p, gNum);
- pprintf(p, "Removing game %d from observation list.\n", gNum + 1);
- }
- return COM_OK;
-}
-
-PUBLIC int com_observe(int p, param_list param)
-{
- int i;
- int p1, obgame;
-
- if ((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are still examining a game.\n");
- return COM_OK;
- }
- if (param[0].type == TYPE_NULL) {
- unobserveAll(p);
- return COM_OK;
- }
- obgame = GameNumFromParam(p, &p1, &param[0]);
- if (obgame < 0)
- return COM_OK;
-
- if ((obgame >= g_num) || ((garray[obgame].status != GAME_ACTIVE) &&
- (garray[obgame].status != GAME_EXAMINE))) {
- pprintf(p, "There is no such game.\n");
- return COM_OK;
- }
- if ((p1 >= 0) && parray[p1].simul_info.numBoards) {
- for (i = 0; i < parray[p1].simul_info.numBoards; i++)
- if (parray[p1].simul_info.boards[i] >= 0)
- do_observe(p, parray[p1].simul_info.boards[i]);
- } else {
- do_observe(p, obgame);
- }
- return COM_OK;
-}
-
-PUBLIC int com_allobservers(int p, param_list param)
-{
- int obgame;
- int p1;
- int start, end;
- int g;
- int first;
-
- if (param[0].type == TYPE_NULL) {
- obgame = -1;
- } else {
- obgame = GameNumFromParam(p, &p1, &param[0]);
- if (obgame < 0)
- return COM_OK;
- }
- if (obgame == -1) {
- start = 0;
- end = g_num;
- } else if ((obgame >= g_num) || ((obgame < g_num)
- && ((garray[obgame].status != GAME_ACTIVE)
- && (garray[obgame].status != GAME_EXAMINE)))) {
- pprintf(p, "There is no such game.\n");
- return COM_OK;
- } else {
- start = obgame;
- end = obgame + 1;
- }
-
- /* list games being played */
-
- for (g = start; g < end; g++) {
- if ((garray[g].status == GAME_ACTIVE) &&
- ((parray[p].adminLevel > 0) || (garray[g].private == 0))) {
- for (first = 1, p1 = 0; p1 < p_num; p1++) {
- if ((parray[p1].status != PLAYER_EMPTY) && (player_is_observe(p1, g))) {
- if (first) {
- pprintf(p, "Observing %2d [%s vs. %s]:",
- g + 1,
- parray[garray[g].white].name,
- parray[garray[g].black].name);
- first = 0;
- }
- pprintf(p, " %s%s", (parray[p1].game >=0) ? "#" : "", parray[p1].name);
- }
- }
- if (!first)
- pprintf(p, "\n");
- }
- }
-
- /* list games being examined last */
-
- for (g = start; g < end; g++) {
- if ((garray[g].status == GAME_EXAMINE) &&
- ((parray[p].adminLevel > 0) || (garray[g].private == 0))) {
- for (first = 1, p1 = 0; p1 < p_num; p1++) {
- if ((parray[p1].status != PLAYER_EMPTY) && (player_is_observe(p1, g) ||
- (parray[p1].game == g))) {
- if (first) {
- if (strcmp(garray[g].white_name, garray[g].black_name)) {
- pprintf(p, "Examining %2d [%s vs %s]:", g + 1,
- garray[g].white_name, garray[g].black_name);
- } else {
- pprintf(p, "Examining %2d (scratch):", g + 1);
- }
- first = 0;
- }
- pprintf(p, " %s%s", (parray[p1].game == g) ? "#" : "", parray[p1].name);
- }
- }
- if (!first)
- pprintf(p, "\n");
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_unexamine(int p, param_list param)
-{
- int g, p1, flag = 0;
-
- if ((parray[p].game <0) ||(garray[parray[p].game].status != GAME_EXAMINE)) {
- pprintf(p, "You are not examining any games.\n");
- return COM_OK;
- }
- g = parray[p].game;
- parray[p].game = -1;
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if ((parray[p1].game == g) &&(p != p1)) {
- /* ok - there are other examiners to take over the game */
- flag = 1;
- }
- if ((player_is_observe(p1, g)) || (parray[p1].game == g)) {
- pprintf(p1, "%s stopped examining game %d.\n", parray[p].name, g + 1);
- }
- }
- if (!flag) {
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g)) {
- pprintf(p1, "There are no examiners.\n");
- pcommand(p1, "unobserve %d", g + 1);
- }
- }
- game_remove(g);
- }
- pprintf(p, "You are no longer examining game %d.\n", g + 1);
- return COM_OK;
-}
-
-PUBLIC int com_mexamine(int p, param_list param)
-{
- int g, p1, p2;
-
- if ((parray[p].game <0) ||(garray[parray[p].game].status != GAME_EXAMINE)) {
- pprintf(p, "You are not examining any games.\n");
- return COM_OK;
- }
- p1 = player_find_part_login(param[0].val.word);
- if (p1 < 0) {
- pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
- return COM_OK;
- }
- g = parray[p].game;
- if (!player_is_observe(p1, g)) {
- pprintf(p, "%s must observe the game you are analysing.\n", parray[p1].name);
- return COM_OK;
- } else {
- if (parray[p1].game >=0) {
- pprintf(p, "%s is already analysing the game.\n", parray[p1].name);
- return COM_OK;
- }
- /* if we get here - let's make him examiner of the game */
- unobserveAll(p1); /* fix for Xboard */
- player_decline_offers(p1, -1, PEND_MATCH);
- player_withdraw_offers(p1, -1, PEND_MATCH);
- player_withdraw_offers(p1, -1, PEND_SIMUL);
-
- parray[p1].game = g; /* yep - it really is that easy :-) */
- pprintf(p1, "You are now examiner of game %d.\n", g + 1);
- send_board_to(g, p1); /* pos not changed - but fixes Xboard */
- for (p2 = 0; p2 < p_num; p2++) {
- if (parray[p2].status != PLAYER_PROMPT)
- continue;
- if (p2 == p1)
- continue;
- if ((player_is_observe(p2, g)) || (parray[p2].game == g)) {
- pprintf_prompt(p2, "%s is now examiner of game %d.\n", parray[p1].name, g + 1);
- }
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_moves(int p, param_list param)
-{
- int g;
- int p1;
-
- if (param[0].type == TYPE_NULL) {
- if (parray[p].game >=0) {
- g = parray[p].game;
- } else if (parray[p].num_observe) {
- for (g = 0; g < parray[p].num_observe; g++) {
- pprintf(p, "%s\n", movesToString(parray[p].observe_list[g], 0));
- }
- return COM_OK;
- } else {
- pprintf(p, "You are neither playing, observing nor examining a game.\n");
- return COM_OK;
- }
- } else {
- g = GameNumFromParam(p, &p1, &param[0]);
- if (g < 0)
- return COM_OK;
- }
- if ((g < 0) || (g >= g_num) || ((garray[g].status != GAME_ACTIVE) &&
- (garray[g].status != GAME_EXAMINE))) {
- pprintf(p, "There is no such game.\n");
- return COM_OK;
- }
- if ((garray[g].white != p) && (garray[g].black != p) && (garray[g].private) && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, that is a private game.\n");
- return COM_OK;
- }
- pprintf(p, "%s\n", movesToString(g, 0)); /* pgn may break interfaces? */
- return COM_OK;
-}
-
-PUBLIC int com_mailmoves(int p, param_list param)
-{
- int g;
- int p1;
- char subj[81];
-
- if (!parray[p].registered) {
- pprintf(p, "Only registered people can use the mailhelp command.\n");
- return COM_OK;
- }
-
- if (param[0].type == TYPE_NULL) {
- if (parray[p].game >=0) {
- g = parray[p].game;
- } else {
- pprintf(p, "You are neither playing, observing nor examining a game.\n");
- return COM_OK;
- }
- } else {
- g = GameNumFromParam(p, &p1, &param[0]);
- if (g < 0)
- return COM_OK;
- }
- if ((g < 0) || (g >= g_num) || ((garray[g].status != GAME_ACTIVE) && (garray[g].status != GAME_EXAMINE))) {
- pprintf(p, "There is no such game.\n");
- return COM_OK;
- }
- if ((garray[g].white != p) && (garray[g].black != p) && (garray[g].private) && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, that is a private game.\n");
- return COM_OK;
- }
- sprintf(subj, "FICS game report %s vs %s", garray[g].white_name, garray[g].black_name);
- if (mail_string_to_user(p, subj, movesToString(g, parray[p].pgn))) {
- pprintf(p, "Moves NOT mailed, perhaps your address is incorrect.\n");
- } else {
- pprintf(p, "Moves mailed.\n");
- }
- return COM_OK;
-}
-
-PUBLIC int com_oldmoves(int p, param_list param)
-{
- int g;
- int p1 = p;
-
- if (param[0].type == TYPE_NULL) {
- p1 = p;
- } else if (param[0].type == TYPE_WORD) {
- p1 = player_find_part_login(param[0].val.word);
- if (p1 < 0) {
- pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
- return COM_OK;
- }
- }
- g = FindOldGameFor(p1);
- if (g < 0) {
- pprintf(p, "There is no old game for %s.\n", parray[p1].name);
- return COM_OK;
- }
- if ((garray[g].white != p) && (garray[g].black != p) && (garray[g].private) && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, that is a private game.\n");
- return COM_OK;
- }
- pprintf(p, "%s\n", movesToString(g, 0)); /* pgn may break interfaces? */
- return COM_OK;
-}
-
-PUBLIC int com_mailoldmoves(int p, param_list param)
-{
- int g;
- int p1 = p;
- char subj[81];
-
- if (!parray[p].registered) {
- pprintf(p, "Only registered people can use the mailhelp command.\n");
- return COM_OK;
- }
-
- if (param[0].type == TYPE_NULL) {
- p1 = p;
- } else if (param[0].type == TYPE_WORD) {
- p1 = player_find_part_login(param[0].val.word);
- if (p1 < 0) {
- pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
- return COM_OK;
- }
- }
- g = FindOldGameFor(p1);
- if (g < 0) {
- pprintf(p, "There is no old game for %s.\n", parray[p1].name);
- return COM_OK;
- }
- if ((garray[g].white != p) && (garray[g].black != p) && (garray[g].private) && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, that is a private game.\n");
- return COM_OK;
- }
- sprintf(subj, "FICS game report %s vs %s", garray[g].white_name, garray[g].black_name);
- if (mail_string_to_user(p, subj, movesToString(g, parray[p].pgn))) {
- pprintf(p, "Moves NOT mailed, perhaps your address is incorrect.\n");
- } else {
- pprintf(p, "Moves mailed.\n");
- }
- return COM_OK;
-}
-
-PUBLIC int com_load(int p, param_list param)
-{
- pprintf(p, "Obsolete command, please use match <opponent>.\n");
- return COM_OK;
-}
-
-void ExamineScratch(int p)
-{
- char category, board;
- int g = game_new();
-
- unobserveAll(p);
-
- player_decline_offers(p, -1, PEND_MATCH);
- player_withdraw_offers(p, -1, PEND_MATCH);
- player_withdraw_offers(p, -1, PEND_SIMUL);
-
- garray[g].wInitTime = garray[g].wIncrement = 0;
- garray[g].bInitTime = garray[g].bIncrement = 0;
- garray[g].timeOfStart = tenth_secs();
- garray[g].wTime = garray[g].bTime = 0;
- garray[g].rated = 0;
- garray[g].clockStopped = 0;
- garray[g].type = TYPE_UNTIMED;
- garray[g].white = garray[g].black = p;
- garray[g].status = GAME_EXAMINE;
- garray[g].startTime = tenth_secs();
- garray[g].lastMoveTime = garray[g].startTime;
- garray[g].lastDecTime = garray[g].startTime;
- garray[g].totalHalfMoves = 0;
-
- parray[p].side = WHITE; /* oh well... */
- parray[p].game = g;
-
- category = board = '\0';
- if (board_init(&garray[g].game_state, &category, &board)) {
- pprintf(p, "PROBLEM LOADING BOARD. Game Aborted.\n");
- fprintf(stderr, "FICS: PROBLEM LOADING BOARD. Game Aborted.\n");
- }
- garray[g].game_state.gameNum = g;
- strcpy(garray[g].white_name, parray[p].name);
- strcpy(garray[g].black_name, parray[p].name);
-
- send_boards(g);
-
- strcpy(garray[g].boardList[garray[g].numHalfMoves], boardToFEN(g));
-}
-
-PRIVATE int ExamineStored(FILE * fp, int p, char *filename)
-{
- int g;
- char category[100], board[100];
- game *gg;
-
- unobserveAll(p);
-
- player_decline_offers(p, -1, PEND_MATCH);
- player_withdraw_offers(p, -1, PEND_MATCH);
- player_withdraw_offers(p, -1, PEND_SIMUL);
-
- g = game_new();
- gg = &garray[g];
- category[0] = '\0';
- board[0] = '\0';
- if (board_init(&gg->game_state, category, board)) {
- pprintf(p, "PROBLEM LOADING BOARD. Game Aborted.\n");
- fprintf(stderr, "FICS: PROBLEM LOADING BOARD %s %s. Game Aborted.\n",
- category, board);
- return -1;
- }
- gg->status = GAME_EXAMINE;
- if (ReadGameAttrs(fp, filename, g) < 0) {
- pprintf(p, "Gamefile is corrupt; please notify an admin.\n");
- return -1;
- }
- gg->totalHalfMoves = gg->numHalfMoves;
- gg->numHalfMoves = 0;
- gg->revertHalfMove = 0;
- gg->white = p;
- gg->black = p;
- gg->game_state.gameNum = g;
-
- gg->startTime = tenth_secs();
- gg->lastMoveTime = gg->startTime;
- gg->lastDecTime = gg->startTime;
-
- parray[p].side = WHITE; /* oh well... */
- parray[p].game = g;
-
- send_boards(g);
-
- strcpy(gg->boardList[gg->numHalfMoves], boardToFEN(g));
- return g;
-}
-
-void ExamineAdjourned(int p, int p1, int p2)
-{
- FILE *fp;
- char filename[1024];
- char *p1Login, *p2Login;
- int g;
-
- p1Login = parray[p1].login;
- p2Login = parray[p2].login;
-
- sprintf(filename, "%s/%c/%s-%s", adj_dir, *p1Login, p1Login, p2Login);
- fp = fopen(filename, "r");
- if (!fp) {
- sprintf(filename, "%s/%c/%s-%s", adj_dir, *p2Login, p1Login, p2Login);
- fp = fopen(filename, "r");
- if (!fp) {
- sprintf(filename, "%s/%c/%s-%s", adj_dir, *p2Login, p2Login, p1Login);
- fp = fopen(filename, "r");
- if (!fp) {
- sprintf(filename, "%s/%c/%s-%s", adj_dir, *p1Login, p2Login, p1Login);
- fp = fopen(filename, "r");
- if (!fp) {
- pprintf(p, "No stored game between \"%s\" and \"%s\".\n",
- parray[p1].name, parray[p2].name);
- return;
- }
- }
- }
- }
- g = ExamineStored(fp, p, filename);
- fclose(fp);
-
- if (g >= 0) {
- if (garray[g].white_name[0] == '\0')
- strcpy(garray[g].white_name, p1Login);
- if (garray[g].black_name[0] == '\0')
- strcpy(garray[g].black_name, p2Login);
- }
- return;
-}
-
-char *FindHistory(int p, int p1, int game)
-{
- FILE *fpHist;
- static char fileName[MAX_FILENAME_SIZE];
- int index;
- long when;
-
- sprintf(fileName, "%s/player_data/%c/%s.%s", stats_dir,
- parray[p1].login[0], parray[p1].login, STATS_GAMES);
- fpHist = fopen(fileName, "r");
- if (fpHist == NULL) {
- pprintf(p, "No games in history for %s.\n", parray[p1].name);
- return(NULL);
- }
- do {
- fscanf(fpHist, "%d %*c %*d %*c %*d %*s %*s %*d %*d %*d %*d %*s %*s %ld",
- &index, &when);
- } while (!feof(fpHist) && index != game);
-
- if (feof(fpHist)) {
- pprintf(p, "There is no history game %d for %s.\n", game, parray[p1].name);
- fclose(fpHist);
- return(NULL);
- }
- fclose(fpHist);
-
- sprintf(fileName, "%s/%ld/%ld", hist_dir, when % 100, when);
- return(fileName);
-}
-
-void ExamineHistory(int p, int p1, int game)
-{
- char *fileName;
-
- fileName = FindHistory(p, p1, game);
- if (fileName != NULL) {
- FILE *fpGame = fopen(fileName, "r");
- if (fpGame == NULL) {
- pprintf(p, "History game %d not available for %s.\n", game, parray[p1].name);
- } else {
- ExamineStored(fpGame, p, fileName);
- }
- }
- return;
-}
-
-PUBLIC int com_examine(int p, param_list param)
-{
- int p1, p2 = p, p1conn, p2conn = 1;
-
- if ((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are already examining a game.\n");
- } else if (parray[p].game >=0) {
- pprintf(p, "You are playing a game.\n");
- } else if (param[0].type == TYPE_NULL) {
- ExamineScratch(p);
- } else if (param[0].type == TYPE_WORD) {
- if (!FindPlayer(p, &param[0], &p1, &p1conn))
- return COM_OK;
-
- if (param[1].type == TYPE_INT)
- ExamineHistory(p, p1, param[1].val.integer);
- else {
- if (param[1].type == TYPE_WORD
- && !FindPlayer(p, &param[1], &p2, &p2conn))
- return COM_OK;
-
- ExamineAdjourned(p, p1, p2);
- if (!p2conn)
- player_remove(p2);
- }
- if (!p1conn)
- player_remove(p1);
- }
- return COM_OK;
-}
-
-PUBLIC int com_stored(int p, param_list param)
-{
- DIR *dirp;
-#ifdef USE_DIRENT
- struct dirent *dp;
-#else
- struct direct *dp;
-#endif
- int p1, connected;
- char dname[MAX_FILENAME_SIZE];
-#if 0 /* replacing all the code below with a
- FindPlayer call; This stuff was buggy
- anyway. */
- if (param[0].type == TYPE_WORD) {
- if ((p1 = player_find_part_login(param[0].val.word)) < 0) { /* not logged in */
- connected = 0;
- p1 = player_new();
- if (player_read(p1, param[0].val.word)) {
- player_remove(p1);
- pprintf(p, "There is no player by that name.\n");
- return COM_OK;
- }
- } else {
- connected = 1;
- }
- } else {
- p1 = p;
- connected = 1;
- }
-#endif
- if (!FindPlayer(p, &param[0], &p1, &connected))
- return COM_OK;
-
- sprintf(dname, "%s/%c", adj_dir, parray[p1].login[0]);
- dirp = opendir(dname);
- if (!dirp) {
- pprintf(p, "Player %s has no games stored.\n", parray[p1].name);
- if (!connected)
- player_remove(p1);
- return COM_OK;
- }
- pprintf(p, "Stored games for %s:\n", parray[p1].name);
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
- if (file_has_pname(dp->d_name, parray[p1].login)) {
- pprintf(p, " %s vs. %s\n", file_wplayer(dp->d_name), file_bplayer(dp->d_name));
- }
- }
-
- closedir(dirp);
- pprintf(p, "\n");
- if (!connected)
- player_remove(p1);
- return COM_OK;
-}
-
-PUBLIC int com_mailstored(int p, param_list param)
-{
- int wp, wconnected, bp, bconnected, gotit = 0;
- int g = -1;
-
- if (!FindPlayer(p, &param[0], &wp, &wconnected))
- return (COM_OK);
-
- if (param[1].type == TYPE_INT) { /* look for a game from history */
- char *fileName = FindHistory(p, wp, param[1].val.integer);
- if (fileName != NULL) {
- FILE *fpGame = fopen(fileName, "r");
- if (fpGame == NULL) {
- pprintf(p, "History game %d not available for %s.\n", param[1].val.integer, parray[wp].name);
- } else {
- g = game_new();
- if (ReadGameAttrs(fpGame, fileName, g) < 0)
- pprintf(p, "Gamefile is corrupt; please notify an admin.\n");
- else
- gotit = 1;
- }
- fclose(fpGame);
- }
- } else { /* look for a stored game between the players */
- if (FindPlayer(p, &param[1], &bp, &bconnected)) {
-
- g = game_new();
- if (game_read(g, wp, bp) >= 0) { /* look for a game white-black, */
- gotit = 1;
- } else if (game_read(g, bp, wp) >= 0) { /* or black-white */
- gotit = 1;
- } else {
- pprintf(p, "There is no stored game %s vs. %s\n", parray[wp].name, parray[bp].name);
- }
- if (!bconnected)
- player_remove(bp);
- }
- }
-
- if (gotit) {
- if (strcasecmp(parray[p].name, garray[g].white_name) && strcasecmp(parray[p]
-.name, garray[g].black_name) && garray[g].private && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, that is a private game.\n");
- } else {
- char subj[81];
- if (param[1].type == TYPE_INT)
- sprintf(subj, "FICS history game: %s %d", parray[wp].name, param[1].val.integer);
- else
- sprintf(subj, "FICS adjourned game %s vs %s", garray[g].white_name, garray[g].black_name);
- if (mail_string_to_user(p, subj, movesToString(g, parray[p].pgn)))
- pprintf(p, "Moves NOT mailed, perhaps your address is incorrect.\n");
- else
- pprintf(p, "Moves mailed.\n");
- }
- }
- if (!wconnected)
- player_remove(wp);
- if (g != -1)
- game_remove(g);
- return(COM_OK);
-}
-
-/* it would be good to write a FindStored and nuke all the game_read(foo,bar)
- game_read(bar,foo) etc. this stuff is a mess... */
-
-PUBLIC int com_smoves(int p, param_list param)
-{
- int wp, wconnected, bp, bconnected, gotit = 0;
- int g = -1;
-
- if (!FindPlayer(p, &param[0], &wp, &wconnected))
- return(COM_OK);
-
- if (param[1].type == TYPE_INT) {
-/* look for a game from history */
- char *fileName = FindHistory(p, wp, param[1].val.integer);
- if (fileName != NULL) {
- FILE *fpGame = fopen(fileName, "r");
- if (fpGame == NULL) {
- pprintf(p, "History game %d not available for %s.\n", param[1].val.integer, parray[wp].name);
- } else {
- g = game_new();
- if (ReadGameAttrs(fpGame, fileName, g) < 0) {
- pprintf(p, "Gamefile is corrupt; please notify an admin.\n");
- } else {
- gotit = 1;
- }
- }
- fclose(fpGame);
- }
- } else {
-/* look for a stored game between the players */
- if (FindPlayer(p, &param[1], &bp, &bconnected)) {
-
- g = game_new();
- if (game_read(g, wp, bp) >= 0) { /* look for a game white-black, */
- gotit = 1;
- } else if (game_read(g, bp, wp) >= 0) { /* or black-white */
- gotit = 1;
- } else {
- pprintf(p, "There is no stored game %s vs. %s\n", parray[wp].name, parray[bp].name);
- }
- if (!bconnected)
- player_remove(bp);
- }
- }
-
- if (gotit) {
- if (strcasecmp(parray[p].name, garray[g].white_name) && strcasecmp(parray[p].name, garray[g].black_name) && garray[g].private && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, that is a private game.\n");
- } else {
- pprintf(p, "%s\n", movesToString(g, 0));
- }
- }
- if (!wconnected)
- player_remove(wp);
- if (g != -1)
- game_remove(g);
- return(COM_OK);
-}
-
-PUBLIC int com_sposition(int p, param_list param)
-{
- int wp, wconnected, bp, bconnected, confused = 0;
- int g;
-
- if (!FindPlayer(p, &param[0], &wp, &wconnected))
- return (COM_OK);
- if (!FindPlayer(p, &param[1], &bp, &bconnected))
- return COM_OK;
-
- g = game_new();
- if (game_read(g, wp, bp) < 0) { /* if no game white-black, */
- if (game_read(g, bp, wp) < 0) { /* look for black-white */
- confused = 1;
- pprintf(p, "There is no stored game %s vs. %s\n", parray[wp].name, parray[bp].name);
- } else {
- int tmp;
- tmp = wp;
- wp = bp;
- bp = tmp;
- tmp = wconnected;
- wconnected = bconnected;
- bconnected = tmp;
- }
- }
- if (!confused) {
- if ((wp != p) && (bp != p) && (garray[g].private) && (parray[p].adminLevel < ADMIN_ADMIN)) {
- pprintf(p, "Sorry, that is a private game.\n");
- } else {
- garray[g].white = wp;
- garray[g].black = bp;
- garray[g].startTime = tenth_secs();
- garray[g].lastMoveTime = garray[g].startTime;
- garray[g].lastDecTime = garray[g].startTime;
- pprintf(p, "Position of stored game %s vs. %s\n", parray[wp].name, parray[bp].name);
- send_board_to(g, p);
- }
- }
- game_remove(g);
- if (!wconnected)
- player_remove(wp);
- if (!bconnected)
- player_remove(bp);
- return COM_OK;
-}
-
-PUBLIC int com_forward(int p, param_list param)
-{
- int nHalfMoves = 1;
- int g, i;
- int p1;
- unsigned now;
-
- if (!((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE))) {
- pprintf(p, "You are not examining any games.\n");
- return COM_OK;
- }
- g = parray[p].game;
- if (!strcmp(garray[g].white_name, garray[g].black_name)) {
- pprintf(p, "You cannot go forward; no moves are stored.\n");
- return COM_OK;
- }
- if (param[0].type == TYPE_INT) {
- nHalfMoves = param[0].val.integer;
- }
- if (garray[g].numHalfMoves > garray[g].revertHalfMove) {
- pprintf(p, "No more moves.\n");
- return COM_OK;
- }
- if (garray[g].numHalfMoves < garray[g].totalHalfMoves) {
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "%s goes forward %d move%s.\n",
- parray[p].name, nHalfMoves, (nHalfMoves == 1) ? "" : "s");
- }
- }
- }
- for (i = 0; i < nHalfMoves; i++) {
- if (garray[g].numHalfMoves < garray[g].totalHalfMoves) {
- execute_move(&garray[g].game_state, &garray[g].moveList[garray[g].numHalfMoves], 1);
- if (garray[g].numHalfMoves + 1 > garray[g].examMoveListSize) {
- garray[g].examMoveListSize += 20; /* Allocate 20 moves at a
- time */
- if (!garray[g].examMoveList) {
- garray[g].examMoveList = (move_t *) rmalloc(sizeof(move_t) * garray[g].examMoveListSize);
- } else {
- garray[g].examMoveList = (move_t *) rrealloc(garray[g].examMoveList, sizeof(move_t) * garray[g].examMoveListSize);
- }
- }
- garray[g].examMoveList[garray[g].numHalfMoves] = garray[g].moveList[garray[g].numHalfMoves];
- garray[g].revertHalfMove++;
- garray[g].numHalfMoves++;
- } else {
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "End of game.\n");
- }
- }
- break;
- }
- }
- /* roll back time */
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- } else {
- garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- }
- now = tenth_secs();
- if (garray[g].numHalfMoves == 0)
- garray[g].timeOfStart = now;
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
- send_boards(g);
- return COM_OK;
-}
-
-PUBLIC int com_backward(int p, param_list param)
-{
- int nHalfMoves = 1;
- int g, i;
- int p1;
- unsigned now;
-
- if (!((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE))) {
- pprintf(p, "You are not examining any games.\n");
- return COM_OK;
- }
- g = parray[p].game;
- if (param[0].type == TYPE_INT) {
- nHalfMoves = param[0].val.integer;
- }
- if (garray[g].numHalfMoves != 0) {
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "%s backs up %d move%s.\n",
- parray[p].name, nHalfMoves, (nHalfMoves == 1) ? "" : "s");
- }
- }
- }
- for (i = 0; i < nHalfMoves; i++) {
- if (backup_move(g, REL_EXAMINE) != MOVE_OK) {
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "Beginning of game.\n");
- }
- }
-
- break;
- }
- }
- if (garray[g].numHalfMoves < garray[g].revertHalfMove) {
- garray[g].revertHalfMove = garray[g].numHalfMoves;
- }
- /* roll back time */
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- } else {
- garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- }
- now = tenth_secs();
- if (garray[g].numHalfMoves == 0)
- garray[g].timeOfStart = now;
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
- send_boards(g);
- return COM_OK;
-}
-
-PUBLIC int com_revert(int p, param_list param)
-{
- int nHalfMoves = 1;
- int g, i;
- int p1;
- unsigned now;
-
- if (!((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE))) {
- pprintf(p, "You are not examining any games.\n");
- return COM_OK;
- }
- g = parray[p].game;
- nHalfMoves = garray[g].numHalfMoves - garray[g].revertHalfMove;
- if (nHalfMoves == 0) {
- pprintf(p, "Already at mainline.\n");
- return COM_OK;
- }
- if (nHalfMoves < 0) { /* eek - should NEVER happen! */
- fprintf(stderr, "OUCH! in com_revert: nHalfMoves < 0\n");
- return COM_OK;
- }
- for (p1 = 0; p1 < p_num; p1++) {
- if (parray[p1].status != PLAYER_PROMPT)
- continue;
- if (player_is_observe(p1, g) || parray[p1].game == g) {
- pprintf(p1, "%s reverts to mainline.\n", parray[p].name);
- }
- }
- for (i = 0; i < nHalfMoves; i++) {
- backup_move(g, REL_EXAMINE);/* should never return error */
- }
- /* roll back time */
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- } else {
- garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- }
- now = tenth_secs();
- if (garray[g].numHalfMoves == 0)
- garray[g].timeOfStart = now;
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
- send_boards(g);
- return COM_OK;
-}
-
-PUBLIC int com_takeback(int p, param_list param)
-{
- int nHalfMoves = 1;
- int from;
- int g, i;
- int p1;
-
- if ((parray[p].game <0) ||(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- p1 = parray[p].opponent;
- if (parray[p1].simul_info.numBoards &&
- parray[p1].simul_info.boards[parray[p1].simul_info.onBoard] !=
- parray[p].game) {
- pprintf(p, "You can only make requests when the simul player is at your board.\n");
- return COM_OK;
- }
- g = parray[p].game;
- if (param[0].type == TYPE_INT) {
- nHalfMoves = param[0].val.integer;
- }
- if ((from = player_find_pendfrom(p, parray[p].opponent, PEND_TAKEBACK)) >= 0) {
- player_remove_request(parray[p].opponent, p, PEND_TAKEBACK);
- if (parray[p].p_from_list[from].param1 == nHalfMoves) {
- /* Doing the takeback */
- player_decline_offers(p, -1, -PEND_SIMUL);
- for (i = 0; i < nHalfMoves; i++) {
- if (backup_move(g, REL_GAME) != MOVE_OK) {
- pprintf(garray[g].white, "Can only backup %d moves\n", i);
- pprintf(garray[g].black, "Can only backup %d moves\n", i);
- break;
- }
- }
-
-#ifdef TIMESEAL
-
- garray[g].wTimeWhenReceivedMove = 0;
- garray[g].bTimeWhenReceivedMove = 0;
-
-#endif
-
- send_boards(g);
- } else {
- if (garray[g].numHalfMoves < nHalfMoves) {
- pprintf(p, "There are only %d half moves in your game.\n", garray[g].numHalfMoves);
- pprintf_prompt(parray[p].opponent, "\n%s has declined the takeback request.\n", parray[p].name, nHalfMoves);
- return COM_OK;
- }
- pprintf(p, "You disagree on the number of half-moves to takeback.\n");
- pprintf(p, "Alternate takeback request sent.\n");
- pprintf_prompt(parray[p].opponent, "\n%s proposes a different number (%d) of half-move(s).\n", parray[p].name, nHalfMoves);
- player_add_request(p, parray[p].opponent, PEND_TAKEBACK, nHalfMoves);
- }
- } else {
- if (garray[g].numHalfMoves < nHalfMoves) {
- pprintf(p, "There are only %d half moves in your game.\n", garray[g].numHalfMoves);
- return COM_OK;
- }
- pprintf(parray[p].opponent, "\n");
- pprintf_highlight(parray[p].opponent, "%s", parray[p].name);
- pprintf_prompt(parray[p].opponent, " would like to take back %d half move(s).\n",
- nHalfMoves);
- pprintf(p, "Takeback request sent.\n");
- player_add_request(p, parray[p].opponent, PEND_TAKEBACK, nHalfMoves);
- }
- return COM_OK;
-}
-
-
-PUBLIC int com_switch(int p, param_list param)
-{
- int g = parray[p].game;
- int tmp, now;
- int p1;
- char *strTmp;
-
- if ((g < 0) || (garray[g].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- p1 = parray[p].opponent;
- if (parray[p1].simul_info.numBoards &&
- parray[p1].simul_info.boards[parray[p1].simul_info.onBoard] != g) {
- pprintf(p, "You can only make requests when the simul player is at your board.\n");
- return COM_OK;
- }
- if (player_find_pendfrom(p, parray[p].opponent, PEND_SWITCH) >= 0) {
- player_remove_request(parray[p].opponent, p, PEND_SWITCH);
- /* Doing the switch */
- player_decline_offers(p, -1, -PEND_SIMUL);
-
- tmp = garray[g].white;
- garray[g].white = garray[g].black;
- garray[g].black = tmp;
- parray[p].side = (parray[p].side == WHITE) ? BLACK : WHITE;
- strTmp = strdup(garray[g].white_name);
- strcpy(garray[g].white_name, garray[g].black_name);
- strcpy(garray[g].black_name, strTmp);
- strfree(strTmp);
-
- parray[parray[p].opponent].side =
- (parray[parray[p].opponent].side == WHITE) ? BLACK : WHITE;
- /* Roll back the time */
- if (garray[g].game_state.onMove == WHITE) {
- garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- } else {
- garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime);
- }
- now = tenth_secs();
- if (garray[g].numHalfMoves == 0)
- garray[g].timeOfStart = now;
- garray[g].lastMoveTime = now;
- garray[g].lastDecTime = now;
- send_boards(g);
- return COM_OK;
- }
- if (garray[g].rated && garray[g].numHalfMoves > 0) {
- pprintf(p, "You cannot switch sides once a rated game is underway.\n");
- return COM_OK;
- }
- pprintf(parray[p].opponent, "\n");
- pprintf_highlight(parray[p].opponent, "%s", parray[p].name);
- pprintf_prompt(parray[p].opponent, " would like to switch sides.\nType \"accept\" to switch sides, or \"decline\" to refuse.\n");
- pprintf(p, "Switch request sent.\n");
- player_add_request(p, parray[p].opponent, PEND_SWITCH, 0);
- return COM_OK;
-}
-
-
-PUBLIC int com_history(int p, param_list param)
-{
- int p1, connected;
- char fname[MAX_FILENAME_SIZE];
-
- if (!FindPlayer(p, &param[0], &p1, &connected))
- return COM_OK;
-
- sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, parray[p1].login[0],
- parray[p1].login, STATS_GAMES);
- pgames(p, p1, fname);
- if (!connected)
- player_remove(p1);
- return COM_OK;
-}
-
-PUBLIC int com_time(int p, param_list param)
-{
- int p1, g;
-
- if (param[0].type == TYPE_NULL) {
- g = parray[p].game;
- if ((g < 0) || (garray[g].status == GAME_EXAMINE)) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- } else {
- g = GameNumFromParam(p, &p1, &param[0]);
- if (g < 0)
- return COM_OK;
- }
- if ((g < 0) || (g >= g_num) || (garray[g].status != GAME_ACTIVE)) {
- pprintf(p, "There is no such game.\n");
- return COM_OK;
- }
- game_update_time(g);
- pprintf(p, "White (%s) : %d mins, %d secs\n",
- parray[garray[g].white].name,
- garray[g].wTime / 600,
- (garray[g].wTime - ((garray[g].wTime / 600) * 600)) / 10);
- pprintf(p, "Black (%s) : %d mins, %d secs\n",
- parray[garray[g].black].name,
- garray[g].bTime / 600,
- (garray[g].bTime - ((garray[g].bTime / 600) * 600)) / 10);
- return COM_OK;
-}
-
-PUBLIC int com_boards(int p, param_list param)
-{
- char *category = NULL;
- char dname[MAX_FILENAME_SIZE];
- DIR *dirp;
-#ifdef USE_DIRENT
- struct dirent *dp;
-#else
- struct direct *dp;
-#endif
-
- if (param[0].type == TYPE_WORD)
- category = param[0].val.word;
- if (category) {
- pprintf(p, "Boards Available For Category %s:\n", category);
- sprintf(dname, "%s/%s", board_dir, category);
- } else {
- pprintf(p, "Categories Available:\n");
- sprintf(dname, "%s", board_dir);
- }
- dirp = opendir(dname);
- if (!dirp) {
- pprintf(p, "No such category %s, try \"boards\".\n", category);
- return COM_OK;
- }
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
- if (!strcmp(dp->d_name, "."))
- continue;
- if (!strcmp(dp->d_name, ".."))
- continue;
- pprintf(p, "%s\n", dp->d_name);
- }
- closedir(dirp);
- return COM_OK;
-}
-
-PUBLIC int com_simmatch(int p, param_list param)
-{
- int p1, g, adjourned;
- int num;
- char tmp[100];
-
- if ((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You are still examining a game.\n");
- return COM_OK;
- }
- p1 = player_find_part_login(param[0].val.word);
- if (p1 < 0) {
- pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
- return COM_OK;
- }
- if (p == p1) {
- pprintf(p, "You can't simmatch yourself!\n");
- return COM_OK;
- }
- if (player_find_pendfrom(p, p1, PEND_SIMUL) >= 0) {
- player_remove_request(p, p1, PEND_MATCH);
- player_remove_request(p1, p, PEND_MATCH);
- player_remove_request(p, p1, PEND_SIMUL);
- player_remove_request(p1, p, PEND_SIMUL);
- player_withdraw_offers(p, -1, PEND_SIMUL);
- player_decline_offers(p1, -1, PEND_SIMUL);
- player_withdraw_offers(p1, -1, PEND_SIMUL);
- player_decline_offers(p, -1, PEND_MATCH);
- player_withdraw_offers(p, -1, PEND_MATCH);
- player_decline_offers(p1, -1, PEND_MATCH);
- player_withdraw_offers(p1, -1, PEND_MATCH);
-
-
-
- /* Accepting Simul ! */
-
-
- if (parray[p].simul_info.numBoards >= MAX_SIMUL) {
- pprintf(p, "You are already playing the maximum of %d boards.\n", MAX_SIMUL);
- pprintf(p1, "Simul request removed, boards filled.\n");
- return COM_OK;
- }
- unobserveAll(p); /* stop observing when match starts */
- unobserveAll(p1);
-
- g = game_new();
- adjourned = 0;
- if (game_read(g, p, p1) >= 0)
- adjourned = 1;
- if (!adjourned) { /* no adjourned game, so begin a new game */
- game_remove(g);
-
- if (create_new_match(p, p1, 0, 0, 0, 0, 0, "standard", "standard", 1)) {
- pprintf(p, "There was a problem creating the new match.\n");
- pprintf_prompt(p1, "There was a problem creating the new match.\n");
- return COM_OK;
- }
- } else { /* resume adjourned game */
- game_delete(p, p1);
-
- sprintf(tmp, "{Game %d (%s vs. %s) Continuing %s %s simul.}\n", g + 1, parray[p].name, parray[p1].name, rstr[garray[g].rated], bstr[garray[g].type]);
- pprintf(p, tmp);
- pprintf(p1, tmp);
-
- garray[g].white = p;
- garray[g].black = p1;
- garray[g].status = GAME_ACTIVE;
- garray[g].startTime = tenth_secs();
- garray[g].lastMoveTime = garray[g].startTime;
- garray[g].lastDecTime = garray[g].startTime;
- parray[p].game = g;
- parray[p].opponent = p1;
- parray[p].side = WHITE;
- parray[p1].game = g;
- parray[p1].opponent = p;
- parray[p1].side = BLACK;
- send_boards(g);
- }
-
- num = parray[p].simul_info.numBoards;
- parray[p].simul_info.results[num] = -1;
- parray[p].simul_info.boards[num] = parray[p].game;
- parray[p].simul_info.numBoards++;
- if (parray[p].simul_info.numBoards > 1 &&
- parray[p].simul_info.onBoard >= 0)
- player_goto_board(p, parray[p].simul_info.onBoard);
- else
- parray[p].simul_info.onBoard = 0;
- return COM_OK;
- }
- if (player_find_pendfrom(p, -1, PEND_SIMUL) >= 0) {
- pprintf(p, "You cannot be the simul giver and request to join another simul.\nThat would just be too confusing for me and you.\n");
- return COM_OK;
- }
- if (parray[p].simul_info.numBoards) {
- pprintf(p, "You cannot be the simul giver and request to join another simul.\nThat would just be too confusing for me and you.\n");
- return COM_OK;
- }
- if (parray[p].game >=0) {
- pprintf(p, "You are already playing a game.\n");
- return COM_OK;
- }
- if (!parray[p1].sopen) {
- pprintf_highlight(p, "%s", parray[p1].name);
- pprintf(p, " is not open to receiving simul requests.\n");
- return COM_OK;
- }
- if (parray[p1].simul_info.numBoards >= MAX_SIMUL) {
- pprintf_highlight(p, "%s", parray[p1].name);
- pprintf(p, " is already playing the maximum of %d boards.\n", MAX_SIMUL);
- return COM_OK;
- }
-/* loon: checking for some crazy situations we can't allow :) */
-
- if ((parray[p1].game >=0) &&(parray[p1].simul_info.numBoards == 0)) {
- pprintf_highlight(p, "%s", parray[p1].name);
- if (parray[garray[parray[p1].game].white].simul_info.numBoards) {
- pprintf(p, " is playing in ");
- pprintf_highlight(p, "%s", parray[parray[p1].opponent].name);
- pprintf(p, "'s simul, and can't accept.\n");
- } else {
- pprintf(p, " can't begin a simul while playing a non-simul game.\n");
- }
- return COM_OK;
- }
-/* loon: this was (p, p1, PEND_SIMUL) but player_add_request needs 4 args...
-if 0 is the incorrect 4th arg, please fix :) */
-
- g = game_new(); /* Check if an adjourned untimed game */
- adjourned = ((game_read(g, p, p1) < 0) && (game_read(g, p1, p) < 0)) ? 0 : 1;
- if (adjourned) {
- if (!(garray[g].type == TYPE_UNTIMED))
- adjourned = 0;
- }
- game_remove(g);
-
- if (player_add_request(p, p1, PEND_SIMUL, 0)) {
- pprintf(p, "Maximum number of pending actions reached. Your request was not sent.\nTry again later.\n");
- return COM_OK;
- } else {
- pprintf(p1, "\n");
- pprintf_highlight(p1, "%s", parray[p].name);
- if (adjourned) {
- pprintf_prompt(p1, " requests to continue an adjourned simul game.\n");
- pprintf(p, "Request to resume simul sent. Adjourned game found.\n");
- } else {
- pprintf_prompt(p1, " requests to join a simul match with you.\n");
- pprintf(p, "Simul match request sent.\n");
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_goboard(int p, param_list param)
-{
- int on, g, p1;
-
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- p1 = player_find_part_login(param[0].val.word);
- if (p1 < 0) {
- pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
- return COM_OK;
- }
- if (p == p1) {
- pprintf(p, "You can't goboard yourself!\n");
- return COM_OK;
- }
- on = parray[p].simul_info.onBoard;
- g = parray[p].simul_info.boards[on];
- if (p1 == garray[g].black) {
- pprintf(p, "You are already at that board!\n");
- return COM_OK;
- }
- if (parray[p].simul_info.numBoards > 1) {
- player_decline_offers(p, -1, -PEND_SIMUL);
- if (player_goto_simulgame_bynum(p, parray[p1].game) !=-1) {
- if (g >= 0) {
- pprintf(garray[g].black, "\n");
- pprintf_highlight(garray[g].black, "%s", parray[p].name);
- pprintf_prompt(garray[g].black, " has moved away from your board.\n");
- }
- }
- } else
- pprintf(p, "You are only playing one board!\n");
- return COM_OK;
-}
-
-PUBLIC int com_gonum(int p, param_list param)
-{
- int on, g, gamenum;
-
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- on = parray[p].simul_info.onBoard;
- g = parray[p].simul_info.boards[on];
- gamenum = param[0].val.integer - 1;
- if (gamenum < 0)
- gamenum = 0;
- if (on == gamenum) {
- pprintf(p, "You are already at that board!\n");
- return COM_OK;
- }
- if (parray[p].simul_info.numBoards > 1) {
- player_decline_offers(p, -1, -PEND_SIMUL);
- if (player_goto_simulgame_bynum(p, gamenum) != -1) {
- if (g >= 0) {
- pprintf(garray[g].black, "\n");
- pprintf_highlight(garray[g].black, "%s", parray[p].name);
- pprintf_prompt(garray[g].black, " has moved away from your board.\n");
- }
- }
- } else
- pprintf(p, "You are only playing one board!\n");
- return COM_OK;
-}
-
-PUBLIC int com_simnext(int p, param_list param)
-{
- int on, g;
-
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- if (parray[p].simul_info.numBoards > 1) {
- player_decline_offers(p, -1, -PEND_SIMUL);
- on = parray[p].simul_info.onBoard;
- g = parray[p].simul_info.boards[on];
- if (g >= 0) {
- pprintf(garray[g].black, "\n");
- pprintf_highlight(garray[g].black, "%s", parray[p].name);
- pprintf_prompt(garray[g].black, " is moving away from your board.\n");
- player_goto_next_board(p);
- }
- } else
- pprintf(p, "You are only playing one board!\n");
- return COM_OK;
-}
-
-
-PUBLIC int com_simprev(int p, param_list param)
-{
- int on, g;
-
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- if (parray[p].simul_info.numBoards > 1) {
- player_decline_offers(p, -1, -PEND_SIMUL);
- on = parray[p].simul_info.onBoard;
- g = parray[p].simul_info.boards[on];
- if (g >= 0) {
- pprintf(garray[g].black, "\n");
- pprintf_highlight(garray[g].black, "%s", parray[p].name);
- pprintf_prompt(garray[g].black, " is moving back to the previous board.\n");
- }
- player_goto_prev_board(p);
- } else
- pprintf(p, "You are only playing one board!\n");
- return COM_OK;
-}
-
-PUBLIC int com_simgames(int p, param_list param)
-{
- int p1 = p;
-
- if (param[0].type == TYPE_WORD) {
- if ((p1 = player_find_part_login(param[0].val.word)) < 0) {
- pprintf(p, "No player named %s is logged in.\n", param[0].val.word);
- return COM_OK;
- }
- }
- if (p1 == p)
- pprintf(p, "You are playing %d simultaneous games.\n",
- player_num_active_boards(p1));
- else
- pprintf(p, "%s is playing %d simultaneous games.\n", parray[p1].name,
- player_num_active_boards(p1));
- return COM_OK;
-}
-
-PUBLIC int com_simpass(int p, param_list param)
-{
- int g, p1, on;
-
- if (parray[p].game <0) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- g = parray[p].game;
- p1 = garray[g].white;
- if (!parray[p1].simul_info.numBoards) {
- pprintf(p, "You are not participating in a simul.\n");
- return COM_OK;
- }
- if (p == p1) {
- pprintf(p, "You are the simul holder and cannot pass!\n");
- return COM_OK;
- }
- if (player_num_active_boards(p1) == 1) {
- pprintf(p, "This is the only game, so passing is futile.\n");
- return COM_OK;
- }
- on = parray[p1].simul_info.onBoard;
- if (on != g) {
- pprintf(p, "You cannot pass until the simul holder arrives!\n");
- return COM_OK;
- }
- if (garray[g].passes >= MAX_SIMPASS) {
- if (parray[p].bell)
- pprintf(p, "\a");
- pprintf(p, "You have reached your maximum of %d passes.\n", MAX_SIMPASS);
- pprintf(p, "Please move IMMEDIATELY!\n");
- pprintf_highlight(p1, "%s", parray[p].name);
- pprintf_prompt(p1, " tried to pass, but is out of passes.\n");
- return COM_OK;
- }
- player_decline_offers(p, -1, -PEND_SIMUL);
-
- garray[g].passes++;
- pprintf(p, "You have passed and have %d passes left.\n",
- (MAX_SIMPASS - garray[g].passes));
- pprintf_highlight(p1, "%s", parray[p].name);
- pprintf_prompt(p1, " has decided to pass and has %d passes left.\n",
- (MAX_SIMPASS - garray[g].passes));
- player_goto_next_board(p1);
- return COM_OK;
-}
-
-PUBLIC int com_simabort(int p, param_list param)
-{
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- player_decline_offers(p, -1, -PEND_SIMUL);
- game_ended(parray[p].simul_info.boards[parray[p].simul_info.onBoard],
- WHITE, END_ABORT);
- return COM_OK;
-}
-
-PUBLIC int com_simallabort(int p, param_list param)
-{
- int i;
-
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- player_decline_offers(p, -1, -PEND_SIMUL);
- for (i = 0; i < parray[p].simul_info.numBoards; i++) {
- if (parray[p].simul_info.boards[i] >= 0) {
- game_ended(parray[p].simul_info.boards[i],
- WHITE, END_ABORT);
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_simadjourn(int p, param_list param)
-{
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- player_decline_offers(p, -1, -PEND_SIMUL);
- game_ended(parray[p].simul_info.boards[parray[p].simul_info.onBoard],
- WHITE, END_ADJOURN);
- return COM_OK;
-}
-
-PUBLIC int com_simalladjourn(int p, param_list param)
-{
- int i;
-
- if (!parray[p].simul_info.numBoards) {
- pprintf(p, "You are not giving a simul.\n");
- return COM_OK;
- }
- player_decline_offers(p, -1, -PEND_SIMUL);
- for (i = 0; i < parray[p].simul_info.numBoards; i++) {
- if (parray[p].simul_info.boards[i] >= 0) {
- game_ended(parray[p].simul_info.boards[i],
- WHITE, END_ADJOURN);
- }
- }
- return COM_OK;
-}
-
-PUBLIC int com_moretime(int p, param_list param)
-{
- int g, increment;
-
- ASSERT(param[0].type == TYPE_INT);
- if ((parray[p].game >=0) &&(garray[parray[p].game].status == GAME_EXAMINE)) {
- pprintf(p, "You cannot use moretime in an examined game.\n");
- return COM_OK;
- }
- increment = param[0].val.integer;
- if (increment <= 0) {
- pprintf(p, "Moretime requires an integer value greater than zero.\n");
- return COM_OK;
- }
- if (parray[p].game <0) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- }
- if (increment > 600) {
- pprintf(p, "Moretime has a maximum limit of 600 seconds.\n");
- increment = 600;
- }
- g = parray[p].game;
- if (garray[g].white == p) {
- garray[g].bTime += increment * 10;
-#ifdef TIMESEAL
- garray[g].bRealTime += increment * 10 * 100;
-#endif
- pprintf(p, "%d seconds were added to your opponents clock\n",
- increment);
- pprintf_prompt(parray[p].opponent,
- "\nYour opponent has added %d seconds to your clock.\n",
- increment);
- }
- if (garray[g].black == p) {
- garray[g].wTime += increment * 10;;
-#ifdef TIMESEAL
- garray[g].wRealTime += increment * 10 * 100;
-#endif
- pprintf(p, "%d seconds were added to your opponents clock\n",
- increment);
- pprintf_prompt(parray[p].opponent,
- "\nYour opponent has added %d seconds to your clock.\n",
- increment);
- }
- return COM_OK;
-}
diff --git a/FICS/multicol.c.orig b/FICS/multicol.c.orig
deleted file mode 100644
index 8d52b04..0000000
--- a/FICS/multicol.c.orig
+++ /dev/null
@@ -1,153 +0,0 @@
-/* multicol.c
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-
-#include "stdinclude.h"
-
-#include "common.h"
-#include "multicol.h"
-#include "utils.h"
-#include "rmalloc.h"
-
-/* grimm */
-#if defined(SGI)
-#else
-/* char *strchr( char *s, int c); */
-#endif
-/* added for warning */
-
-PUBLIC multicol *multicol_start(int maxArray)
-{
- int i;
- multicol *m;
-
- m = (multicol *) rmalloc(sizeof(multicol));
- m->arraySize = maxArray;
- m->num = 0;
- m->strArray = (char **) rmalloc(sizeof(char *) * m->arraySize);
- for (i = 0; i < m->arraySize; i++)
- m->strArray[i] = NULL;
- return m;
-}
-
-PUBLIC int multicol_store(multicol * m, char *str)
-{
- if (m->num >= m->arraySize)
- return -1;
- if (!str)
- return -1;
- m->strArray[m->num] = strdup(str);
- m->num++;
- return 0;
-}
-
-PUBLIC int multicol_store_sorted(multicol * m, char *str)
-/* use this instead of milticol_store to print a list sorted */
-{
- int i;
- int found = 0;
- if (m->num >= m->arraySize)
- return -1;
- if (!str)
- return -1;
- for (i = m->num; (i > 0) && (!found); i--) {
- if (strcasecmp(str, m->strArray[i - 1]) >= 0) {
- found = 1;
- m->strArray[i] = strdup(str);
- } else {
- m->strArray[i] = m->strArray[i - 1];
- }
- }
- if (!found)
- m->strArray[0] = strdup(str);
- m->num++;
- return 0;
-}
-
-PUBLIC int multicol_pprint(multicol * m, int player, int cols, int space)
-{
- int i;
- int maxWidth = 0;
- int numPerLine;
- int numLines;
- int on, theone, len;
- int done;
- int temp;
- char *tempptr;
-
- pprintf(player, "\n");
- for (i = 0; i < m->num; i++) {
- tempptr = m->strArray[i];
- temp = strlen(tempptr); /* loon: yes, this is pathetic */
- for (; *tempptr; tempptr++) {
- if (*tempptr == '\033')
- temp -= 4;
- }
- if (temp > maxWidth)
- maxWidth = temp;
- }
- maxWidth += space;
- numPerLine = cols / maxWidth;
- numLines = m->num / numPerLine;
- if (numLines * numPerLine < m->num)
- numLines++;
- on = 0;
- done = 0;
- while (!done) {
- for (i = 0; i < numPerLine; i++) {
- theone = on + numLines * i;
- if (theone >= m->num) {
- break;
- }
- tempptr = m->strArray[theone];
- temp = strlen(tempptr); /* loon: yes, still pathetic */
- for (; *tempptr; tempptr++) {
- if (*tempptr == '\033')
- temp -= 4;
- }
- len = maxWidth - temp;
- if (i == numPerLine - 1)
- len -= space;
- pprintf(player, "%s", m->strArray[theone]);
- while (len) {
- pprintf(player, " ");
- len--;
- }
- }
- pprintf(player, "\n");
- on += 1;
- if (on >= numLines)
- break;
- }
- return 0;
-}
-
-PUBLIC int multicol_end(multicol * m)
-{
- int i;
- for (i = 0; i < m->num; i++)
- rfree(m->strArray[i]);
- rfree(m->strArray);
- rfree(m);
- return 0;
-}
diff --git a/FICS/network.c.orig b/FICS/network.c.orig
deleted file mode 100644
index eed60c8..0000000
--- a/FICS/network.c.orig
+++ /dev/null
@@ -1,657 +0,0 @@
-/* network.c
- *
- */
-
-#include "stdinclude.h"
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/telnet.h>
-
-#include "common.h"
-#include "utils.h"
-#include "playerdb.h"
-#include "network.h"
-#include "rmalloc.h"
-#ifdef TIMESEAL
-#include "timeseal.h"
-#endif
-
-extern int errno;
-
-/* grimm */
-#if defined(SGI)
-#else
-/*
-int send(int s, char *msg, int len, int flags);
-int recv(int s, char *buf, int len, int flags);
-char *memset(char *s, int c, int n);
-int setsockopt( int s, int level, int optname, char *optval, int optlen);
-int accept(int s, struct sockaddr *addr, size_t *addrlen);
-void *memmove(void *dst0, const void *src0, register size_t length);
-int bind(int s, struct sockaddr *name, int namelen);
-int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- struct timeval *timeout);
-int listen(int s, int level);
-*/
-#endif
-/* added for warning */
-
-PRIVATE int sockfd = 0; /* The socket */
-PRIVATE int numConnections = 0;
-/* Sparse array */
-PUBLIC connection con[256];
-
-PUBLIC int no_file;
-PUBLIC int max_connections;
-
-/* Index == fd, for sparse array, quick lookups! wasted memory :( */
-PUBLIC int findConnection(int fd)
-{
- if (con[fd].status == NETSTAT_EMPTY)
- return -1;
- else
- return fd;
-}
-
-PUBLIC int net_addConnection(int fd, unsigned int fromHost)
-{
- int noblock = 1;
-
- if (findConnection(fd) >= 0) {
- fprintf(stderr, "FICS: FD already in connection table!\n");
- return -1;
- }
- if (numConnections == max_connections)
- return -1;
- if (ioctl(fd, FIONBIO, &noblock) == -1) {
- fprintf(stderr, "Error setting nonblocking mode errno=%d\n", errno);
- }
- con[fd].fd = fd;
- if (fd != 0)
- con[fd].outFd = fd;
- else
- con[fd].outFd = 1;
- con[fd].fromHost = fromHost;
- con[fd].status = NETSTAT_CONNECTED;
-#ifdef TIMESEAL
- con[fd].user[0]='\0';
- con[fd].sys[0]='\0';
- con[fd].timeseal = 0;
- con[fd].time = 0;
-#endif
- con[fd].numPending = 0;
- con[fd].processed = 0;
- con[fd].outPos = 0;
- if (con[fd].sndbuf == NULL) {
-#ifdef DEBUG
- fprintf(stderr, "FICS: nac(%d) allocating sndbuf.\n", fd);
-#endif
- con[fd].sndbufpos = 0;
- con[fd].sndbufsize = MAX_STRING_LENGTH;
- con[fd].sndbuf = rmalloc(MAX_STRING_LENGTH);
- } else {
-#ifdef DEBUG
- fprintf(stderr, "FICS: nac(%d) reusing old sndbuf size %d pos %d.\n", fd, con[fd].sndbufsize, con[fd].sndbufpos);
-#endif
- }
- con[fd].state = 0;
- numConnections++;
-
-#ifdef DEBUG
- fprintf(stderr, "FICS: fd: %d connections: %d descriptors: %d \n", fd, numConnections, getdtablesize()); /* sparky 3/13/95 */
-#endif
-
- return 0;
-}
-
-PRIVATE int remConnection(int fd)
-{
- int which;
- if ((which = findConnection(fd)) < 0) {
- return -1;
- }
- numConnections--;
- con[fd].status = NETSTAT_EMPTY;
- if (con[fd].sndbuf == NULL) {
- fprintf(stderr, "FICS: remcon(%d) totally screwed, this shouldn't happen.\n", fd);
- } else {
- if (con[fd].sndbufsize > MAX_STRING_LENGTH) {
- con[fd].sndbufsize = MAX_STRING_LENGTH;
- con[fd].sndbuf = rrealloc(con[fd].sndbuf, MAX_STRING_LENGTH);
- }
- if (con[fd].sndbufpos) { /* didn't send everything, bummer */
- con[fd].sndbufpos = 0;
- }
- }
- return 0;
-}
-
-PRIVATE void net_flushme(int which)
-{
- int sent;
-
- sent = send(con[which].outFd, con[which].sndbuf, con[which].sndbufpos, 0);
- if (sent == -1) {
- if (errno != EPIPE) /* EPIPE = they've disconnected */
- fprintf(stderr, "FICS: net_flushme(%d) couldn't send, errno=%d.\n", which, errno);
- con[which].sndbufpos = 0;
- } else {
- con[which].sndbufpos -= sent;
- if (con[which].sndbufpos)
- memmove(con[which].sndbuf, con[which].sndbuf + sent, con[which].sndbufpos);
- }
- if (con[which].sndbufsize > MAX_STRING_LENGTH && con[which].sndbufpos < MAX_STRING_LENGTH) {
- /* time to shrink the buffer */
- con[which].sndbuf = rrealloc(con[which].sndbuf, MAX_STRING_LENGTH);
- con[which].sndbufsize = MAX_STRING_LENGTH;
- }
-}
-
-PRIVATE void net_flush_all_connections(void)
-{
- int which;
- fd_set writefds;
- struct timeval to;
-
- FD_ZERO(&writefds);
- for (which = 0; which < max_connections; which++)
- if (con[which].status == NETSTAT_CONNECTED && con[which].sndbufpos)
- FD_SET(con[which].outFd, &writefds);
-
- to.tv_usec = 0;
- to.tv_sec = 0;
- select(no_file, NULL, &writefds, NULL, &to);
- for (which = 0; which < max_connections; which++) {
- if (FD_ISSET(con[which].outFd, &writefds)) {
- net_flushme(which);
- }
- }
-}
-
-PRIVATE void net_flush_connection(int fd)
-{
- int which;
- fd_set writefds;
- struct timeval to;
-
- if (((which = findConnection(fd)) >= 0) && (con[which].sndbufpos)) {
- FD_ZERO(&writefds);
- FD_SET(con[which].outFd, &writefds);
- to.tv_usec = 0;
- to.tv_sec = 0;
- select(no_file, NULL, &writefds, NULL, &to);
- if (FD_ISSET(con[which].outFd, &writefds)) {
- net_flushme(which);
- }
- }
- return;
-}
-
-PRIVATE int sendme(int which, char *str, int len)
-{
- int i, count;
- fd_set writefds;
- struct timeval to;
- count = len;
-
- while ((i = ((con[which].sndbufsize - con[which].sndbufpos) < len) ? (con[which].sndbufsize - con[which].sndbufpos) : len) > 0) {
- memmove(con[which].sndbuf + con[which].sndbufpos, str, i);
- con[which].sndbufpos += i;
- if (con[which].sndbufpos == con[which].sndbufsize) {
-
- FD_ZERO(&writefds);
- FD_SET(con[which].outFd, &writefds);
- to.tv_usec = 0;
- to.tv_sec = 0;
- select(no_file, NULL, &writefds, NULL, &to);
- if (FD_ISSET(con[which].outFd, &writefds)) {
- net_flushme(which);
- } else {
- /* time to grow the buffer */
- con[which].sndbufsize += MAX_STRING_LENGTH;
- con[which].sndbuf = rrealloc(con[which].sndbuf, con[which].sndbufsize);
- }
- }
- str += i;
- len -= i;
- }
- return count;
-}
-
-/*
- * -1 for an error other than EWOULDBLOCK.
- * Put <lf> after every <cr> and put \ at the end of overlength lines.
- * Doesn't send anything unless the buffer fills, output waits until
- * flushed
-*/
-PUBLIC int net_send_string(int fd, char *str, int format)
-{
- int which, i, j;
-
- if ((which = findConnection(fd)) < 0) {
- return -1;
- }
- while (*str) {
- for (i = 0; str[i] >= ' '; i++);
- if (i) {
- if (format && (i >= (j = LINE_WIDTH - con[which].outPos))) { /* word wrap */
- i = j;
- while (i > 0 && str[i - 1] != ' ')
- i--;
- while (i > 0 && str[i - 1] == ' ')
- i--;
- if (i == 0)
- i = j - 1;
- sendme(which, str, i);
- sendme(which, "\n\r\\ ", 6);
- con[which].outPos = 4;
- while (str[i] == ' ') /* eat the leading spaces after we wrap */
- i++;
- } else {
- sendme(which, str, i);
- con[which].outPos += i;
- }
- str += i;
- } else { /* non-printable stuff handled here */
- switch (*str) {
- case '\t':
- sendme(which, " ", 8 - (con[which].outPos & 7));
- con[which].outPos &= ~7;
- if (con[which].outPos += 8 >= LINE_WIDTH)
- con[which].outPos = 0;
- break;
- case '\n':
- sendme(which, "\n\r", 2);
- con[which].outPos = 0;
- break;
- case '\033':
- con[which].outPos -= 3;
- default:
- sendme(which, str, 1);
- }
- str++;
- }
- }
- return 0;
-}
-
-/* if we get a complete line (something terminated by \n), copy it to com
- and return 1.
- if we don't get a complete line, but there is no error, return 0.
- if some error, return -1.
- */
-PUBLIC int readline2(char *com, int who)
-{
- unsigned char *start, *s, *d;
- int howmany, state, fd, pending;
-
- static unsigned char will_tm[] = {IAC, WILL, TELOPT_TM, '\0'};
- static unsigned char will_sga[] = {IAC, WILL, TELOPT_SGA, '\0'};
- static unsigned char ayt[] = "[Responding to AYT: Yes, I'm here.]\n";
-
- state = con[who].state;
- if ((state == 2) || (state > 4)) {
- fprintf(stderr, "FICS: state screwed for con[%d], this is a bug.\n", who);
- state = 0;
- }
- s = start = con[who].inBuf;
- pending = con[who].numPending;
- fd = con[who].fd;
-
- howmany = recv(fd, start + pending, MAX_STRING_LENGTH - 1 - pending, 0);
- if (howmany == 0) /* error: they've disconnected */
- return (-1);
- else if (howmany == -1) {
- if (errno != EWOULDBLOCK) { /* some other error */
- return (-1);
- } else if (con[who].processed) { /* nothing new and nothing old */
- return (0);
- } else { /* nothing new, but some unprocessed old */
- howmany = 0;
- }
- }
- if (con[who].processed)
- s += pending;
- else
- howmany += pending;
- d = s;
-
- for (; howmany-- > 0; s++) {
- switch (state) {
- case 0: /* Haven't skipped over any control chars or
- telnet commands */
- if (*s == IAC) {
- d = s;
- state = 1;
- } else if (*s == '\n') {
- *s = '\0';
- strcpy(com, start);
- if (howmany)
- bcopy(s + 1, start, howmany);
- con[who].state = 0;
- con[who].numPending = howmany;
- con[who].processed = 0;
- con[who].outPos = 0;
- return (1);
- } else if ((*s > (0xff - 0x20)) || (*s < 0x20)) {
- d = s;
- state = 2;
- }
- break;
- case 1: /* got telnet IAC */
- if (*s == IP)
- return (-1); /* ^C = logout */
- else if (*s == DO)
- state = 4;
- else if ((*s == WILL) || (*s == DONT) || (*s == WONT))
- state = 3; /* this is cheesy, but we aren't using em */
- else if (*s == AYT) {
- send(fd, (char *) ayt, strlen((char *) ayt), 0);
- state = 2;
- } else if (*s == EL) { /* erase line */
- d = start;
- state = 2;
- } else /* dunno what it is, so ignore it */
- state = 2;
- break;
- case 2: /* we've skipped over something, need to
- shuffle processed chars down */
- if (*s == IAC)
- state = 1;
- else if (*s == '\n') {
- *d = '\0';
- strcpy(com, start);
- if (howmany)
- memmove(start, s + 1, howmany);
- con[who].state = 0;
- con[who].numPending = howmany;
- con[who].processed = 0;
- con[who].outPos = 0;
- return (1);
- } else if (*s >= ' ')
- *(d++) = *s;
- break;
- case 3: /* some telnet junk we're ignoring */
- state = 2;
- break;
- case 4: /* got IAC DO */
- if (*s == TELOPT_TM)
- send(fd, (char *) will_tm, strlen((char *) will_tm), 0);
- else if (*s == TELOPT_SGA)
- send(fd, (char *) will_sga, strlen((char *) will_sga), 0);
- state = 2;
- break;
- }
- }
- if (state == 0)
- d = s;
- else if (state == 2)
- state = 0;
- con[who].state = state;
- con[who].numPending = d - start;
- con[who].processed = 1;
- if (con[who].numPending == MAX_STRING_LENGTH - 1) { /* buffer full */
- *d = '\0';
- strcpy(com, start);
- con[who].state = 0;
- con[who].numPending = 0;
- con[who].processed = 0;
- return (1);
- }
- return (0);
-}
-
-/*
-PRIVATE int readline(int who)
-{
- int e, fd = con[who].fd;
- char *t = con[who].inBuf;
- int recvCount;
- int totalCount = 0;
- unsigned char c;
- static unsigned char will_tm[] = {IAC, WILL, TELOPT_TM, '\0'};
- static unsigned char will_sga[] = {IAC, WILL, TELOPT_SGA, '\0'};
-
- t += con[who].numPending;
-
- while ((recvCount = recv(fd, (char *) &c, 1, 0)) == 1) {
- totalCount += recvCount;
- if (c == IAC) {
- recvCount = recv(fd, (char *) &c, 1, 0);
- if (recvCount == 1) {
- totalCount += recvCount;
- switch (c) {
- case IP:
- c = '\3';
- break;
- case DO:
- recvCount = recv(fd, (char *) &c, 1, 0);
- if (recvCount == 1) {
- totalCount += recvCount;
- if (c == TELOPT_TM) {
- send(fd, (char *) will_tm, strlen((char *) will_tm), 0);
- } else if (c == TELOPT_SGA) {
- send(fd, (char *) will_sga, strlen((char *) will_sga), 0);
- }
- }
- c = '\0';
- break;
- case DONT:
- recvCount = recv(fd, (char *) &c, 1, 0);
- break;
- c = '\0';
- default:
- recvCount = recv(fd, (char *) &c, 1, 0);
- c = '\0';
- break;
- }
- }
- }
- if (c != '\r' && c > 2) {
- if (isprint(c) || (c == '\n')) {
- *t++ = c;
- con[who].numPending++;
- }
- }
- if (c == '\n' || con[who].numPending >= MAX_STRING_LENGTH - 1) {
- *--t = '\0';
- con[who].numPending = 0;
- con[fd].outPos = 0;
- return 1;
- }
- }
-
- *t = '\0';
- e = ((totalCount == 0) || (errno != EWOULDBLOCK)) ? -1 : 0;
- return (e);
-}
-*/
-
-PUBLIC int net_init(int port)
-{
- int i;
- int opt;
- struct sockaddr_in serv_addr;
- struct linger lingeropt;
-
- no_file = getdtablesize();
-/* Although we have 256 descriptors to work with for opening sockets,
- * we can only use 126 maximum of them for some reason... built in
- * limitation of the socket libs? Sparky 3/13/95
- */
- if (no_file > MAX_PLAYER + 10)
- no_file = MAX_PLAYER + 10;
- max_connections = no_file - 10;
- for (i = 0; i < no_file; i++) {
- con[i].status = NETSTAT_EMPTY;
- con[i].sndbuf = NULL;
- con[i].sndbufsize = con[i].sndbufpos = 0;
- }
- /* Open a TCP socket (an Internet stream socket). */
- if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "FICS: can't open stream socket\n");
- return -1;
- }
- /* Bind our local address so that the client can send to us */
- memset((char *) &serv_addr, 0, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_port = htons(port);
-
- /** added in an attempt to allow rebinding to the port **/
-
- opt = 1;
- setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt));
- opt = 1;
- setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, sizeof(opt));
- lingeropt.l_onoff = 0;
- lingeropt.l_linger = 0;
- setsockopt(sockfd, SOL_SOCKET, SO_LINGER, (char *) &lingeropt, sizeof(lingeropt));
-
-/*
-#ifdef DEBUG
- opt = 1;
- setsockopt(sockfd, SOL_SOCKET, SO_DEBUG, (char *)&opt, sizeof(opt));
-#endif
-*/
-
- if (bind(sockfd, (struct sockaddr *) & serv_addr, sizeof(serv_addr)) < 0) {
- fprintf(stderr, "FICS: can't bind local address. errno=%d\n", errno);
- return -1;
- }
- opt = 1;
- ioctl(sockfd, FIONBIO, &opt);
- listen(sockfd, 5);
- return 0;
-}
-
-PUBLIC void net_close(void)
-{
- int i;
- for (i = 0; i < no_file; i++) {
- if (con[i].status != NETSTAT_EMPTY)
- net_close_connection(con[i].fd);
- }
-}
-
-PUBLIC void net_close_connection(int fd)
-{
- if (con[fd].status == NETSTAT_CONNECTED)
- net_flush_connection(fd);
- if (!remConnection(fd)) {
- if (fd > 2)
- close(fd);
- }
-}
-
-PUBLIC void turn_echo_on(int fd)
-{
- static unsigned char wont_echo[] = {IAC, WONT, TELOPT_ECHO, '\0'};
-
- send(fd, (char *) wont_echo, strlen((char *) wont_echo), 0);
-}
-
-PUBLIC void turn_echo_off(int fd)
-{
- static unsigned char will_echo[] = {IAC, WILL, TELOPT_ECHO, '\0'};
-
- send(fd, (char *) will_echo, strlen((char *) will_echo), 0);
-}
-
-PUBLIC unsigned int net_connected_host(int fd)
-{
- int which;
-
- if ((which = findConnection(fd)) < 0) {
- fprintf(stderr, "FICS: FD not in connection table!\n");
- return -1;
- }
- return con[which].fromHost;
-}
-
-PUBLIC void ngc2(char *com, int timeout)
-{
- struct sockaddr_in cli_addr;
- size_t cli_len = sizeof(struct sockaddr_in);
-
- int fd, loop, nfound, lineComplete;
- fd_set readfds;
- struct timeval to;
-
- while ((fd = accept(sockfd, (struct sockaddr *) & cli_addr, &cli_len)) != -1) {
- if (net_addConnection(fd, cli_addr.sin_addr.s_addr)) {
- char *woo =
-"FICS is currently full. Please try one of the following sites:\n\r\n\r"
-"E-FICS: krypton.daimi.aau.dk 5000 (130.225.18.157 5000) Main EURO server\n\r"
-"D-FICS: dds.hacktic.nl 5000 (193.78.33.69 5000) Dutch server\n\r"
-"B-FICS: holly.csv.warwick.ac.uk 5000 (137.205.192.12 5000) British server\n\r"
-"?-FICS: chess.unix-ag.uni-kl.de 5000 (131.246.89.3 5000) German server\n\r"
-"M-FICS: wisdom.weizmann.ac.il 5000 (132.76.80.77 5000) Mid-east server\n\r\n\r";
- fprintf(stderr, "FICS is full. fd = %d\n");
- write (fd, woo, strlen(woo));
- sleep(1);
- close(fd);
- } else {
-/* int opt, optlen;
-
- opt = 1024;
- setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&opt, sizeof(opt));
- opt = 8192;
- setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &opt, sizeof(opt));
- optlen = sizeof(opt);
- getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&opt, &optlen);
- fprintf(stderr, "%d sndbuf: %d", fd, opt);
- optlen = sizeof(opt);
- getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&opt, &optlen);
- fprintf(stderr, " rcvbuf: %d\n", opt);
-*/
- process_new_connection(fd, net_connected_host(fd));
- }
- }
- if (errno != EWOULDBLOCK)
- fprintf(stderr, "FICS: Problem with accept(). errno=%d\n", errno);
-
- net_flush_all_connections();
-
- FD_ZERO(&readfds);
- for (loop = 0; loop < no_file; loop++)
- if (con[loop].status != NETSTAT_EMPTY)
- FD_SET(con[loop].fd, &readfds);
-
- to.tv_usec = 0;
- to.tv_sec = timeout;
- nfound = select(no_file, &readfds, NULL, NULL, &to);
- for (loop = 0; loop < no_file; loop++) {
- if (con[loop].status != NETSTAT_EMPTY) {
- fd = con[loop].fd;
- lineComplete = readline2(com, fd);
- if (lineComplete == 0) /* partial line: do nothing with it */
- continue;
- if (lineComplete > 0) { /* complete line: process it */
-#ifdef TIMESEAL
- if (!(parseInput(com, &con[loop]))) continue;
-#endif
- if (process_input(fd, com) != COM_LOGOUT) {
- net_flush_connection(fd);
- continue;
- }
- }
- /* Disconnect anyone who gets here */
- process_disconnection(fd);
- net_close_connection(fd);
- }
- }
-}
-
-PUBLIC int net_consize(void)
-{
- int i, total;
-
- total = sizeof(con);
- for (i=0; i < no_file; i++)
- total += con[i].sndbufsize;
-
- return(total);
-}
diff --git a/FICS/ratings.c.orig b/FICS/ratings.c.orig
deleted file mode 100644
index 37e26f9..0000000
--- a/FICS/ratings.c.orig
+++ /dev/null
@@ -1,1432 +0,0 @@
-/*
- ratings.c
-
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
- vek leeds@math.gatech.edu 95/04/05 Glicko system, with sterr
-*/
-
-#include "stdinclude.h"
-
-#include "common.h"
-#include "playerdb.h"
-#include "ratings.h"
-#include "gamedb.h"
-#include "command.h"
-#include "comproc.h"
-#include "lists.h"
-#include "ficsmain.h"
-#include "config.h"
-#include "utils.h"
-
-/* grimm */
-#if defined(SGI)
-#else
-/* int system(char *arg); */
-/* int rewind(FILE *stream); */
-#endif
-
-
-PUBLIC double Ratings_B_Average;
-PUBLIC double Ratings_B_StdDev;
-
-PUBLIC double Ratings_S_Average;
-PUBLIC double Ratings_S_StdDev;
-
-PUBLIC double Ratings_W_Average;
-PUBLIC double Ratings_W_StdDev;
-
-PRIVATE double Rb_M = 0.0, Rb_S = 0.0, Rb_total = 0.0;
-PRIVATE int Rb_count = 0;
-
-PRIVATE double Rs_M = 0.0, Rs_S = 0.0, Rs_total = 0.0;
-PRIVATE int Rs_count = 0;
-
-PRIVATE double Rw_M = 0.0, Rw_S = 0.0, Rw_total = 0.0;
-PRIVATE int Rw_count = 0;
-
-/*
-PUBLIC rateStruct bestS[MAX_BEST];
-PUBLIC int numS = 0;
-PUBLIC rateStruct bestB[MAX_BEST];
-PUBLIC int numB = 0;
-PUBLIC rateStruct bestW[MAX_BEST];
-PUBLIC int numW = 0;
-*/
-
-#define MAXHIST 30
-#define LOWESTHIST 800
-PUBLIC int sHist[MAXHIST];
-PUBLIC int bHist[MAXHIST];
-PUBLIC int wHist[MAXHIST];
-
-char sdir[] = DEFAULT_STATS;
-
-PUBLIC int is_active(int Games)
-{
- return (Games >= PROVISIONAL);
-}
-
-
-PUBLIC void rating_add(int rating, int type)
-{
- int which;
-
- which = (rating - LOWESTHIST) / 100;
- if (which < 0)
- which = 0;
- if (which >= MAXHIST)
- which = MAXHIST - 1;
- if (type == TYPE_BLITZ) {
- bHist[which] += 1;
- Rb_count++;
- Rb_total += rating;
- if (Rb_count == 1) {
- Rb_M = rating;
- } else {
- Rb_S = Rb_S + (rating - Rb_M) * (rating - Rb_M);
- Rb_M = Rb_M + (rating - Rb_M) / (Rb_count);
- }
- Ratings_B_StdDev = sqrt(Rb_S / Rb_count);
- Ratings_B_Average = Rb_total / (double) Rb_count;
- } else if (type == TYPE_WILD) { /* TYPE_WILD */
- wHist[which] += 1;
- Rw_count++;
- Rw_total += rating;
- if (Rw_count == 1) {
- Rw_M = rating;
- } else {
- Rw_S = Rw_S + (rating - Rw_M) * (rating - Rw_M);
- Rw_M = Rw_M + (rating - Rw_M) / (Rw_count);
- }
- Ratings_W_StdDev = sqrt(Rw_S / Rw_count);
- Ratings_W_Average = Rw_total / (double) Rw_count;
- } else { /* TYPE_STAND */
- sHist[which] += 1;
- Rs_count++;
- Rs_total += rating;
- if (Rs_count == 1) {
- Rs_M = rating;
- } else {
- Rs_S = Rs_S + (rating - Rs_M) * (rating - Rs_M);
- Rs_M = Rs_M + (rating - Rs_M) / (Rs_count);
- }
- Ratings_S_StdDev = sqrt(Rs_S / Rs_count);
- Ratings_S_Average = Rs_total / (double) Rs_count;
- }
-}
-
-PUBLIC void rating_remove(int rating, int type)
-{
- int which;
-
- which = (rating - LOWESTHIST) / 100;
- if (which < 0)
- which = 0;
- if (which >= MAXHIST)
- which = MAXHIST - 1;
- if (type == TYPE_BLITZ) {
- bHist[which] = bHist[which] - 1;
- if (bHist[which] < 0)
- bHist[which] = 0;
- if (Rb_count == 0)
- return;
- Rb_count--;
- Rb_total -= rating;
- if (Rb_count == 0) {
- Rb_M = 0;
- Rb_S = 0;
- } else {
- Rb_M = Rb_M - (rating - Rb_M) / (Rb_count);
- Rb_S = Rb_S - (rating - Rb_M) * (rating - Rb_M);
- /* added this 3.11.95 foxbat */ if (Rb_S < 0)
- Rb_S = 0;
- }
- if (Rb_count) {
- Ratings_B_StdDev = sqrt(Rb_S / Rb_count);
- Ratings_B_Average = Rb_total / (double) Rb_count;
- } else {
- Ratings_B_StdDev = 0;
- Ratings_B_Average = 0;
- }
- } else if (type == TYPE_WILD) { /* TYPE_WILD */
- wHist[which] = wHist[which] - 1;
- if (wHist[which] < 0)
- wHist[which] = 0;
- if (Rw_count == 0)
- return;
- Rw_count--;
- Rw_total -= rating;
- if (Rw_count == 0) {
- Rw_M = 0;
- Rw_S = 0;
- } else {
- Rw_M = Rw_M - (rating - Rw_M) / (Rw_count);
- Rw_S = Rw_S - (rating - Rw_M) * (rating - Rw_M);
- /* added this 3.10.95 foxbat */ if (Rw_S < 0)
- Rw_S = 0;
- }
- if (Rw_count) {
- Ratings_W_StdDev = sqrt(Rw_S / Rw_count);
- Ratings_W_Average = Rw_total / (double) Rw_count;
- } else {
- Ratings_W_StdDev = 0;
- Ratings_W_Average = 0;
- }
- } else { /* TYPE_STAND */
- sHist[which] = sHist[which] - 1;
- if (sHist[which] < 0)
- sHist[which] = 0;
- if (Rs_count == 0)
- return;
- Rs_count--;
- Rs_total -= rating;
- if (Rs_count == 0) {
- Rs_M = 0;
- Rs_S = 0;
- } else {
- Rs_M = Rs_M - (rating - Rs_M) / (Rs_count);
- Rs_S = Rs_S - (rating - Rs_M) * (rating - Rs_M);
- /* added this 3.10.95 foxbat */ if (Rs_S < 0)
- Rs_S = 0;
- }
- if (Rs_count) {
- Ratings_S_StdDev = sqrt(Rs_S / Rs_count);
- Ratings_S_Average = Rs_total / (double) Rs_count;
- } else {
- Ratings_S_StdDev = 0;
- Ratings_S_Average = 0;
- }
- }
-}
-
-PRIVATE void load_ratings(void)
-{
- FILE *fp;
- char fname[MAX_FILENAME_SIZE];
- int i;
-
- sprintf(fname, "%s/newratings_data", stats_dir);
- fp = fopen(fname, "r");
- if (!fp) {
- fprintf(stderr, "FICS: Can't read ratings data!\n");
- return;
- }
- fscanf(fp, "%lf %lf %lf %d", &Rb_M, &Rb_S, &Rb_total, &Rb_count);
- fscanf(fp, "%lf %lf %lf %d", &Rs_M, &Rs_S, &Rs_total, &Rs_count);
- fscanf(fp, "%lf %lf %lf %d", &Rw_M, &Rw_S, &Rw_total, &Rw_count);
-/* loon testing
- fscanf(fp, "%d", &numB);
- for (i = 0; i < numB; i++) {
- fscanf(fp, "%s %d", bestB[i].name, &(bestB[i].rating));
- }
- fscanf(fp, "%d", &numS);
- for (i = 0; i < numS; i++) {
- fscanf(fp, "%s %d", bestS[i].name, &bestS[i].rating);
- }
- fscanf(fp, "%d", &numW);
- for (i = 0; i < numW; i++) {
- fscanf(fp, "%s %d", bestW[i].name, &bestW[i].rating);
- }
-*/
- for (i = 0; i < MAXHIST; i++) {
- fscanf(fp, "%d %d %d", &sHist[i], &bHist[i], &wHist[i]);
- }
- fclose(fp);
- if (Rs_count) {
- Ratings_S_StdDev = sqrt(Rs_S / Rs_count);
- Ratings_S_Average = Rs_total / (double) Rs_count;
- } else {
- Ratings_S_StdDev = 0;
- Ratings_S_Average = 0;
- }
- if (Rb_count) {
- Ratings_B_StdDev = sqrt(Rb_S / Rb_count);
- Ratings_B_Average = Rb_total / (double) Rb_count;
- } else {
- Ratings_B_StdDev = 0;
- Ratings_B_Average = 0;
- }
- if (Rw_count) {
- Ratings_W_StdDev = sqrt(Rw_S / Rw_count);
- Ratings_W_Average = Rw_total / (double) Rw_count;
- } else {
- Ratings_W_StdDev = 0;
- Ratings_W_Average = 0;
- }
-}
-
-PUBLIC void save_ratings(void)
-{
- FILE *fp;
- char fname[MAX_FILENAME_SIZE];
- int i;
-
- sprintf(fname, "%s/newratings_data", stats_dir);
- fp = fopen(fname, "w");
- if (!fp) {
- fprintf(stderr, "FICS: Can't write ratings data!\n");
- return;
- }
- fprintf(fp, "%10f %10f %10f %d\n", Rb_M, Rb_S, Rb_total, Rb_count);
- fprintf(fp, "%10f %10f %10f %d\n", Rs_M, Rs_S, Rs_total, Rs_count);
- fprintf(fp, "%10f %10f %10f %d\n", Rw_M, Rw_S, Rw_total, Rw_count);
-/* loon testing
- fprintf(fp, "%d\n", numB);
- for (i = 0; i < numB; i++) {
- fprintf(fp, "%s %d\n", bestB[i].name, bestB[i].rating);
- }
- fprintf(fp, "%d\n", numS);
- for (i = 0; i < numS; i++) {
- fprintf(fp, "%s %d\n", bestS[i].name, bestS[i].rating);
- }
- fprintf(fp, "%d\n", numW);
- for (i = 0; i < numW; i++) {
- fprintf(fp, "%s %d\n", bestW[i].name, bestW[i].rating);
- }
-*/
- for (i = 0; i < MAXHIST; i++) {
- fprintf(fp, "%d %d %d\n", sHist[i], bHist[i], wHist[i]);
- }
- fclose(fp);
-}
-
-/*
-PRIVATE void BestRemove(int p)
-{
- int i;
-
- for (i = 0; i < numB; i++) {
- if (!strcmp(bestB[i].name, parray[p].name))
- break;
- }
- if (i < numB) {
- for (; i < numB - 1; i++) {
- strcpy(bestB[i].name, bestB[i + 1].name);
- bestB[i].rating = bestB[i + 1].rating;
- }
- numB--;
- }
- for (i = 0; i < numS; i++) {
- if (!strcmp(bestS[i].name, parray[p].name))
- break;
- }
- if (i < numS) {
- for (; i < numS - 1; i++) {
- strcpy(bestS[i].name, bestS[i + 1].name);
- bestS[i].rating = bestS[i + 1].rating;
- }
- numS--;
- }
- for (i = 0; i < numW; i++) {
- if (!strcmp(bestW[i].name, parray[p].name))
- break;
- }
- if (i < numW) {
- for (; i < numW - 1; i++) {
- strcpy(bestW[i].name, bestW[i + 1].name);
- bestW[i].rating = bestW[i + 1].rating;
- }
- numW--;
- }
-}
-
-PRIVATE void BestAdd(int p)
-{
- int where, j;
-
- if ((parray[p].b_stats.rating > 0) && (parray[p].b_stats.num > 19)) {
- for (where = 0; where < numB; where++) {
- if (parray[p].b_stats.rating > bestB[where].rating)
- break;
- }
- if (where < MAX_BEST) {
- for (j = numB; j > where; j--) {
- if (j == MAX_BEST)
- continue;
- strcpy(bestB[j].name, bestB[j - 1].name);
- bestB[j].rating = bestB[j - 1].rating;
- }
- strcpy(bestB[where].name, parray[p].name);
- bestB[where].rating = parray[p].b_stats.rating;
- if (numB < MAX_BEST)
- numB++;
- }
- }
- if ((parray[p].s_stats.rating > 0) && (parray[p].s_stats.num > 19)) {
- for (where = 0; where < numS; where++) {
- if (parray[p].s_stats.rating > bestS[where].rating)
- break;
- }
- if (where < MAX_BEST) {
- for (j = numS; j > where; j--) {
- if (j == MAX_BEST)
- continue;
- strcpy(bestS[j].name, bestS[j - 1].name);
- bestS[j].rating = bestS[j - 1].rating;
- }
- strcpy(bestS[where].name, parray[p].name);
- bestS[where].rating = parray[p].s_stats.rating;
- if (numS < MAX_BEST)
- numS++;
- }
- }
- if ((parray[p].w_stats.rating > 0) && (parray[p].w_stats.num > 19)) {
- for (where = 0; where < numW; where++) {
- if (parray[p].w_stats.rating > bestW[where].rating)
- break;
- }
- if (where < MAX_BEST) {
- for (j = numW; j > where; j--) {
- if (j == MAX_BEST)
- continue;
- strcpy(bestW[j].name, bestW[j - 1].name);
- bestW[j].rating = bestW[j - 1].rating;
- }
- strcpy(bestW[where].name, parray[p].name);
- bestW[where].rating = parray[p].w_stats.rating;
- if (numW < MAX_BEST)
- numW++;
- }
- }
-}
-
-PUBLIC void BestUpdate(int p)
-{
- BestRemove(p);
- BestAdd(p);
-}
-
-*/
-
-PUBLIC void zero_stats(void)
-{
- int i;
- for (i = 0; i < MAXHIST; i++) {
- sHist[i] = 0;
- bHist[i] = 0;
- wHist[i] = 0;
- }
- Rb_M = 0.0, Rb_S = 0.0, Rb_total = 0.0;
- Rb_count = 0;
-
- Rs_M = 0.0, Rs_S = 0.0, Rs_total = 0.0;
- Rs_count = 0;
-
- Rw_M = 0.0, Rw_S = 0.0, Rw_total = 0.0;
- Rw_count = 0;
-
-/*
- numS = 0;
- numB = 0;
- numW = 0;
-*/
-}
-
-PUBLIC void rating_init(void)
-{
- zero_stats();
- load_ratings();
-}
-
-/* This recalculates the rating info from the player data, it can take
- a long time! */
-PUBLIC void rating_recalc(void)
-{
- char dname[MAX_FILENAME_SIZE];
- int p1;
- int c;
- int t = time(0);
- DIR *dirp;
-#if USE_DIRENT
- struct dirent *dp;
-#else
- struct direct *dp;
-#endif
-
- fprintf(stderr, "FICS: Recalculating ratings at %s\n", strltime(&t));
- zero_stats();
- for (c = 'a'; c <= 'z'; c++) {
- /* Never done as ratings server */
- sprintf(dname, "%s/%c", player_dir, c);
- dirp = opendir(dname);
- if (!dirp)
- continue;
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
- if (dp->d_name[0] != '.') {
- p1 = player_new();
- if (player_read(p1, dp->d_name)) {
- player_remove(p1);
- fprintf(stderr, "FICS: Problem reading player %s.\n", dp->d_name);
- continue;
- }
- if (parray[p1].b_stats.rating > 0) {
- rating_add(parray[p1].b_stats.rating, TYPE_BLITZ);
- }
- if (parray[p1].s_stats.rating > 0) {
- rating_add(parray[p1].s_stats.rating, TYPE_STAND);
- }
- if (parray[p1].w_stats.rating > 0) {
- rating_add(parray[p1].w_stats.rating, TYPE_WILD);
- }
- player_remove(p1);
- }
- }
- closedir(dirp);
- }
- if (Rs_count) {
- Ratings_S_StdDev = sqrt(Rs_S / Rs_count);
- Ratings_S_Average = Rs_total / (double) Rs_count;
- } else {
- Ratings_S_StdDev = 0;
- Ratings_S_Average = 0;
- }
- if (Rb_count) {
- Ratings_B_StdDev = sqrt(Rb_S / Rb_count);
- Ratings_B_Average = Rb_total / (double) Rb_count;
- } else {
- Ratings_B_StdDev = 0;
- Ratings_B_Average = 0;
- }
- if (Rw_count) {
- Ratings_W_StdDev = sqrt(Rw_S / Rw_count);
- Ratings_W_Average = Rw_total / (double) Rw_count;
- } else {
- Ratings_W_StdDev = 0;
- Ratings_W_Average = 0;
- }
- save_ratings();
- t = time(0);
- fprintf(stderr, "FICS: Finished at %s\n", strltime(&t));
-}
-
-/* Constants for Glicko system */
-#define Gd 3.25
-#define Gr0 1720
-#define Gs0 350
-#define Gq 0.00575646273249
-#define Gp 0.000010072398601964
-
-/* End of Glicko system variables */
-
-PRIVATE double Gf(double ss)
-{
- return (1.0 / sqrt(1.0 + Gp * ss * ss));
-}
-
-/* Confusing but economical: calculate error and attenuation function together */
-PRIVATE double GE(int r, int rr, double ss, double *fss)
-{
- *fss = Gf(ss);
- return (1.0 / (1.0 + pow(10.0, (rr - r) * (*fss) / 400.0)));
-}
-
-PUBLIC double current_sterr(double s, int t)
-{
- if (t < 0)
- t = 0; /* this shouldn't happen */
- return (sqrt(s * s + Gd * Gd * log(1.0 + t / 60.0)));
-}
-
-/* Calculates new rating and standard error. By vek. The person */
-/* who invented the ratings system is Mark E. Glickman, Ph.D. */
-/* His e-mail address is glickman@hustat.harvard.edu as of April '95. */
-/* Postscript copy of the note I coded this from should be available */
-/* for ftp from ics.onenet.net, if not elsewhere. */
-
-PUBLIC void rating_sterr_delta(int p1, int p2, int type, int gtime, int result,
- int *deltarating, double *newsterr)
-{
- statistics *p1_stats;
- statistics *p2_stats;
-
- double s1, s2;
- int t1, r1, t2, r2; /* Initial sterrs and ratings */
- double E, fs2, denominator, GK, w; /* Parts of fancy formulas */
- double delta, sigma; /* Results to return */
-
- if (type == TYPE_BLITZ) {
- p1_stats = &parray[p1].b_stats;
- p2_stats = &parray[p2].b_stats;
- } else if (type == TYPE_WILD) {
- p1_stats = &parray[p1].w_stats;
- p2_stats = &parray[p2].w_stats;
- } else {
- p1_stats = &parray[p1].s_stats;
- p2_stats = &parray[p2].s_stats;
- }
-
- /* Calculate effective pre-game sterrs. ltime==0 implies never had sterr. */
-
- if (p1_stats->ltime == 0)
- s1 = Gs0;
- else {
- t1 = gtime - p1_stats->ltime;
- s1 = current_sterr(p1_stats->sterr, t1);
- if (s1 > Gs0)
- s1 = Gs0;
- }
-
- if (p2_stats->ltime == 0)
- s2 = Gs0;
- else {
- t2 = gtime - p2_stats->ltime;
- s2 = current_sterr(p2_stats->sterr, t2);
- if (s2 > Gs0)
- s2 = Gs0;
- }
-
- /* pre-game ratings */
- if (p1_stats->rating == 0 && p1_stats->num == 0)
- r1 = Gr0;
- else
- r1 = p1_stats->rating;
-
- if (p2_stats->rating == 0 && p2_stats->num == 0)
- r2 = Gr0;
- else
- r2 = p2_stats->rating;
-
- /* now crunch */
-
- if (result == RESULT_WIN) {
- w = 1.0;
- } else if (result == RESULT_DRAW) {
- w = 0.5;
- } else {
- w = 0.0;
- }
-
- E = GE(r1, r2, s2, &fs2); /* side effect: calculate fs2 */
-
- denominator = 1.0 / (s1 * s1) + Gq * Gq * fs2 * fs2 * E * (1.0 - E);
- GK = Gq * fs2 / denominator;
-
- delta = GK * (w - E);
- if (p1_stats->rating == 0 && p1_stats->num == 0)
- *deltarating = (int) (Gr0 + delta + 0.5);
- else
- *deltarating = (int) delta + 0.5; /* Returned values: deltarating,
- newsterr */
-
- sigma = 1.0 / sqrt(denominator);
- *newsterr = (double) sigma;
-
-}
-
-/* vek: Next is for when we want just the delta, and not the sigma. */
-
-PUBLIC int rating_delta(int p1, int p2, int type, int result, int gtime)
-{
- int delta;
- double sigma;
-
- rating_sterr_delta(p1, p2, type, gtime, result, &delta, &sigma);
- return (delta);
-
-}
-
-PUBLIC int rating_update(int g)
-{
- int wDelta, bDelta;
- double wSigma, bSigma; /* vek */
-
- int wRes, bRes;
- statistics *w_stats;
- statistics *b_stats;
-
- int gtime;
-
- int inprogress = (g == parray[garray[g].black].game);
- /* if this is adjudication of stored game, be quiet about ratings change */
-
- if (garray[g].type == TYPE_BLITZ) {
- w_stats = &parray[garray[g].white].b_stats;
- b_stats = &parray[garray[g].black].b_stats;
- } else if (garray[g].type == TYPE_STAND) {
- w_stats = &parray[garray[g].white].s_stats;
- b_stats = &parray[garray[g].black].s_stats;
- } else if (garray[g].type == TYPE_WILD) {
- w_stats = &parray[garray[g].white].w_stats;
- b_stats = &parray[garray[g].black].w_stats;
- } else {
- fprintf(stderr, "FICS: Can't update untimed ratings!\n");
- return -1;
- }
-
- switch (garray[g].result) {
- case END_CHECKMATE:
- case END_RESIGN:
- case END_FLAG:
- case END_ADJWIN:
- if (garray[g].winner == WHITE) {
- wRes = RESULT_WIN;
- bRes = RESULT_LOSS;
- } else {
- bRes = RESULT_WIN;
- wRes = RESULT_LOSS;
- }
- break;
- case END_AGREEDDRAW:
- case END_REPETITION:
- case END_50MOVERULE:
- case END_STALEMATE:
- case END_NOMATERIAL:
- case END_BOTHFLAG:
- case END_ADJDRAW:
- case END_FLAGNOMATERIAL:
- wRes = bRes = RESULT_DRAW;
- break;
- default:
- fprintf(stderr, "FICS: Update undecided game %d?\n", garray[g].result);
- return -1;
- }
- gtime = untenths(garray[g].timeOfStart);
- rating_sterr_delta(garray[g].white, garray[g].black,
- garray[g].type, gtime, wRes,
- &wDelta, &wSigma);
-
- rating_sterr_delta(garray[g].black, garray[g].white,
- garray[g].type, gtime, bRes,
- &bDelta, &bSigma);
-
- /* vek: Update time of last rated game played, for future ratings calcs. */
- /* Kept independently for blitz and standard. */
- w_stats->ltime = gtime;
- b_stats->ltime = gtime;
- /* end vek add 4/5/95 */
-
- if (wRes == RESULT_WIN) {
- w_stats->win++;
- } else if (wRes == RESULT_LOSS) {
- w_stats->los++;
- } else {
- w_stats->dra++;
- }
- w_stats->num++;
- if (bRes == RESULT_WIN) {
- b_stats->win++;
- } else if (bRes == RESULT_LOSS) {
- b_stats->los++;
- } else {
- b_stats->dra++;
- }
- b_stats->num++;
- rating_remove(w_stats->rating, garray[g].type);
- rating_remove(b_stats->rating, garray[g].type);
-
- if (inprogress) {
- pprintf(garray[g].white, "%s rating adjustment: %d ",
- ((garray[g].type == TYPE_BLITZ) ? "Blitz" : ((garray[g].type == TYPE_WILD) ? "Wild" : "Standard")), w_stats->rating);
- pprintf(garray[g].black, "%s rating adjustment: %d ",
- ((garray[g].type == TYPE_BLITZ) ? "Blitz" : ((garray[g].type == TYPE_WILD) ? "Wild" : "Standard")), b_stats->rating);
- }
- if (wDelta < -1000) {
- pprintf(garray[g].white, "not changed due to bug (way too small)! sorry!\n");
- fprintf(stderr, "FICS: Got too small ratings bug for %s (w) vs. %s\n",
- parray[garray[g].white].login, parray[garray[g].black].login);
- } else if (wDelta > 3000) {
- pprintf(garray[g].white, "not changed due to bug (way too big)! sorry!\n");
- fprintf(stderr, "FICS: Got too big ratings bug for %s (w) vs. %s\n",
- parray[garray[g].white].login, parray[garray[g].black].login);
- } else {
- w_stats->rating += wDelta;
- w_stats->sterr = wSigma;
- }
-
- if (bDelta < -1000) {
- pprintf(garray[g].black, "not changed due to bug (way too small)! sorry! ");
- fprintf(stderr, "FICS: Got too small ratings bug for %s (b) vs. %s\n",
- parray[garray[g].black].login, parray[garray[g].white].login);
- } else if (bDelta > 3000) {
- pprintf(garray[g].black, "not changed due to bug (way too big)! sorry! ");
- fprintf(stderr, "FICS: Got too big ratings bug for %s (b) vs. %s\n",
- parray[garray[g].black].login, parray[garray[g].white].login);
- } else {
- b_stats->rating += bDelta;
- b_stats->sterr = bSigma;
- } /* error messages down to vek */
-
- rating_add(w_stats->rating, garray[g].type);
- rating_add(b_stats->rating, garray[g].type);
-
- if ((w_stats->rating > w_stats->best) && (is_active(w_stats->num))) {
- w_stats->best = w_stats->rating;
- w_stats->whenbest = time(NULL);
- }
- if ((b_stats->rating > b_stats->best) && (is_active(b_stats->num))) {
- b_stats->best = b_stats->rating;
- b_stats->whenbest = time(NULL);
- }
-/* Ratings are now saved to disk after each game */
- player_save(garray[g].white);
- player_save(garray[g].black);
-
-/* foxbat 3.11.95 */
- if (garray[g].type == TYPE_BLITZ) {
- Rb_count++;
- Rb_total += (w_stats->rating + b_stats->rating) / 2.0;
- } else if (garray[g].type == TYPE_STAND) {
- Rs_count++;
- Rs_total += (w_stats->rating + b_stats->rating) / 2.0;
- } else if (garray[g].type == TYPE_WILD) {
- Rw_count++;
- Rw_total += (w_stats->rating + b_stats->rating) / 2.0;
- }
-/* end add */
-/* loon testing
- BestUpdate(garray[g].white);
- BestUpdate(garray[g].black);
-*/
- if (inprogress) {
- pprintf(garray[g].white, "--> %d\n", w_stats->rating);
- pprintf(garray[g].black, "--> %d\n", b_stats->rating);
- }
- save_ratings();
- UpdateRank(garray[g].type, parray[garray[g].white].name,
- w_stats, parray[garray[g].white].name);
- UpdateRank(garray[g].type, parray[garray[g].black].name,
- b_stats, parray[garray[g].black].name);
- return 0;
-}
-
-PUBLIC int com_assess(int p, param_list param)
-{
- int p1 = p, p2, nowtime;
- int p1_connected = 1, p2_connected = 1;
- int win1, draw1, loss1;
- double newsterr1;
- int win2, draw2, loss2;
- double newsterr2;
-
- nowtime = time(0);
-
-/* Hawk: Now assess can be used with players not */
-/* logged on -- I wonder if anyone doesn't */
-/* get just a bit confused here :) */
-
- if (param[0].type == TYPE_NULL) {
- if (parray[p].game <0) {
- pprintf(p, "You are not playing a game.\n");
- return COM_OK;
- } else if (garray[parray[p].game].status == GAME_EXAMINE) {
- if (!strcmp(garray[parray[p].game].black_name, parray[p].name)) {
- pcommand(p, "assess %s\n", garray[parray[p].game].white_name);
- } else {
- pcommand(p, "assess %s %s\n",
- garray[parray[p].game].white_name,
- garray[parray[p].game].black_name);
- }
- return COM_OK;
- } else {
- p2 = parray[p].opponent;
- }
- } else {
- if (!FindPlayer(p, &param[0], &p2, &p2_connected)) {
- pprintf(p, "No user named \"%s\" was found.\n", param[0].val.word);
- return COM_OK;
- }
- if (param[1].type != TYPE_NULL) {
- p1 = p2;
- p1_connected = p2_connected;
- if (!FindPlayer(p, &param[1], &p2, &p2_connected)) {
- pprintf(p, "No user named \"%s\" was found.\n", param[1].val.word);
- if (!p1_connected)
- player_remove(p1);
- return COM_OK;
- }
- }
- }
- if (p1 == p2) {
- pprintf(p, "You can't assess the same players.\n");
- if (!p1_connected)
- player_remove(p1);
- if (!p2_connected)
- player_remove(p2);
- return COM_OK;
- }
- rating_sterr_delta(p1, p2, TYPE_BLITZ, nowtime, RESULT_WIN, &win1, &newsterr1);
- rating_sterr_delta(p1, p2, TYPE_BLITZ, nowtime, RESULT_DRAW, &draw1, &newsterr1);
- rating_sterr_delta(p1, p2, TYPE_BLITZ, nowtime, RESULT_LOSS, &loss1, &newsterr1);
- rating_sterr_delta(p2, p1, TYPE_BLITZ, nowtime, RESULT_WIN, &win2, &newsterr2);
- rating_sterr_delta(p2, p1, TYPE_BLITZ, nowtime, RESULT_DRAW, &draw2, &newsterr2);
- rating_sterr_delta(p2, p1, TYPE_BLITZ, nowtime, RESULT_LOSS, &loss2, &newsterr2);
-
- pprintf(p, "\nBlitz\n %10s (%4s, RD: %5.1f) %10s (%4s, RD: %5.1f)\n",
- parray[p1].name, ratstrii(parray[p1].b_stats.rating, parray[p1].registered), parray[p1].b_stats.sterr,
- parray[p2].name, ratstrii(parray[p2].b_stats.rating, parray[p2].registered), parray[p2].b_stats.sterr);
- pprintf(p, "Win : %4d %4d\n", win1, loss2);
- pprintf(p, "Draw: %4d %4d\n", draw1, draw2);
- pprintf(p, "Loss: %4d %4d\n", loss1, win2);
- pprintf(p, "New RD: %5.1f %5.1f\n", newsterr1, newsterr2);
-
- rating_sterr_delta(p1, p2, TYPE_STAND, nowtime, RESULT_WIN, &win1, &newsterr1);
- rating_sterr_delta(p1, p2, TYPE_STAND, nowtime, RESULT_DRAW, &draw1, &newsterr1);
- rating_sterr_delta(p1, p2, TYPE_STAND, nowtime, RESULT_LOSS, &loss1, &newsterr1);
- rating_sterr_delta(p2, p1, TYPE_STAND, nowtime, RESULT_WIN, &win2, &newsterr2);
- rating_sterr_delta(p2, p1, TYPE_STAND, nowtime, RESULT_DRAW, &draw2, &newsterr2);
- rating_sterr_delta(p2, p1, TYPE_STAND, nowtime, RESULT_LOSS, &loss2, &newsterr2);
-
- pprintf(p, "\nStandard\n %10s (%4s, RD: %5.1f) %10s (%4s, RD: %5.1f)\n",
- parray[p1].name, ratstrii(parray[p1].s_stats.rating, parray[p1].registered), parray[p1].s_stats.sterr,
- parray[p2].name, ratstrii(parray[p2].s_stats.rating, parray[p2].registered), parray[p2].s_stats.sterr);
- pprintf(p, "Win : %4d %4d\n", win1, loss2);
- pprintf(p, "Draw: %4d %4d\n", draw1, draw2);
- pprintf(p, "Loss: %4d %4d\n", loss1, win2);
- pprintf(p, "New RD: %5.1f %5.1f\n", newsterr1, newsterr2);
-
- rating_sterr_delta(p1, p2, TYPE_WILD, nowtime, RESULT_WIN, &win1, &newsterr1);
- rating_sterr_delta(p1, p2, TYPE_WILD, nowtime, RESULT_DRAW, &draw1, &newsterr1);
- rating_sterr_delta(p1, p2, TYPE_WILD, nowtime, RESULT_LOSS, &loss1, &newsterr1);
- rating_sterr_delta(p2, p1, TYPE_WILD, nowtime, RESULT_WIN, &win2, &newsterr2);
- rating_sterr_delta(p2, p1, TYPE_WILD, nowtime, RESULT_DRAW, &draw2, &newsterr2);
- rating_sterr_delta(p2, p1, TYPE_WILD, nowtime, RESULT_LOSS, &loss2, &newsterr2);
-
- pprintf(p, "\nWild\n %10s (%4s, RD: %5.1f) %10s (%4s, RD: %5.1f)\n",
- parray[p1].name, ratstrii(parray[p1].w_stats.rating, parray[p1].registered), parray[p1].w_stats.sterr,
- parray[p2].name, ratstrii(parray[p2].w_stats.rating, parray[p2].registered), parray[p2].w_stats.sterr);
- pprintf(p, "Win : %4d %4d\n", win1, loss2);
- pprintf(p, "Draw: %4d %4d\n", draw1, draw2);
- pprintf(p, "Loss: %4d %4d\n", loss1, win2);
- pprintf(p, "New RD: %5.1f %5.1f\n", newsterr1, newsterr2);
-
- if (!p1_connected)
- player_remove(p1);
- if (!p2_connected)
- player_remove(p2);
- return COM_OK;
-}
-
-
-PUBLIC int com_best(int p, param_list param)
-{
- return Best(p, param, 1);
-}
-
-PUBLIC int com_hbest(int p, param_list param)
-{
- return Best(p, param, 0);
-}
-
-#if 0
-PUBLIC int com_best(int p, param_list param)
-{
- int i;
-
- pprintf(p, "Standard Blitz Wild\n");
- for (i = 0; i < MAX_BEST; i++) {
- if ((i >= numS) && (i >= numB))
- break;
- if (i < numS) {
- pprintf(p, "%4d %-17s ", bestS[i].rating, bestS[i].name);
- } else {
- pprintf(p, " ");
- }
- if (i < numB) {
- pprintf(p, "%4d %-17s ", bestB[i].rating, bestB[i].name);
- } else {
- pprintf(p, " ");
- }
- if (i < numW) {
- pprintf(p, "%4d %-17s\n", bestW[i].rating, bestW[i].name);
- } else {
- pprintf(p, "\n");
- }
- }
- return COM_OK;
-}
-#endif
-
-PUBLIC int com_statistics(int p, param_list param)
-{
- pprintf(p, " Standard Blitz Wild\n");
- pprintf(p, "average: %7.2f %7.2f %7.2f\n", Ratings_S_Average, Ratings_B_Average, Ratings_W_Average);
- pprintf(p, "std dev: %7.2f %7.2f %7.2f\n", Ratings_S_StdDev, Ratings_B_StdDev, Ratings_W_StdDev);
- pprintf(p, "number : %7d %7d %7d\n", Rs_count, Rb_count, Rw_count);
- return COM_OK;
-}
-
-PUBLIC int com_fixrank(int p, param_list param)
-{
- int p1, connected;
-
- if (!FindPlayer(p, &param[0], &p1, &connected))
- return COM_OK;
- UpdateRank(TYPE_BLITZ, parray[p1].name, &parray[p1].b_stats,
- parray[p1].name);
- UpdateRank(TYPE_STAND, parray[p1].name, &parray[p1].s_stats,
- parray[p1].name);
- UpdateRank(TYPE_WILD, parray[p1].name, &parray[p1].w_stats,
- parray[p1].name);
- if (!connected)
- player_remove(p1);
- return COM_OK;
-}
-
-PUBLIC int com_rank(int p, param_list param)
-{
- return DisplayRank(p, param, 1);
-}
-
-PUBLIC int com_hrank(int p, param_list param)
-{
- return DisplayRank(p, param, 0);
-}
-
-PUBLIC int DisplayRank(int p, param_list param, int showComputers)
-{
- int start, end, target, connected;
- int show = SHOW_BLITZ | SHOW_STANDARD | SHOW_WILD;
-
- if (param[0].type == TYPE_NULL) {
- DisplayTargetRank(p, parray[p].name, show, showComputers);
- return COM_OK;
- } else if (isdigit(param[0].val.word[0])) {
- end = -1;
- sscanf(param[0].val.word, "%d-%d", &start, &end);
- if (end > 0 && (param[1].type != TYPE_NULL))
- show = ShowFromString(param[1].val.word);
- DisplayRankedPlayers(p, start, end, show, showComputers);
- return COM_OK;
- } else {
- target = player_search(p, param[0].val.word);
- if (target == 0) {
- pprintf(p, "Target %s not found.\n", param[0].val.word);
- return COM_OK;
- }
- connected = (target > 0);
- if (!connected)
- target = -target - 1;
- else
- target--;
-
- if (param[1].type != TYPE_NULL)
- show = ShowFromString(param[1].val.word);
- DisplayTargetRank(p, parray[target].name, show, showComputers);
- if (!connected)
- player_remove(target);
- return COM_OK;
- }
-}
-
-/* CompareStats returns 1 if s1 comes first, -1 if s2 comes first, and 0
- if neither takes precedence. */
-PRIVATE int CompareStats(char *name1, statistics *s1,
- char *name2, statistics *s2)
-{
- int i, l1;
-
- if (s1 == NULL)
- if (s2 == NULL)
- return 0;
- else
- return -1;
- else if (s2 == NULL)
- return 1;
-
- if (s1->rating > s2->rating)
- return 1;
- if (s1->rating < s2->rating)
- return -1;
- l1 = strlen(name1);
- for (i = 0; i < l1; i++) {
- if (name2[i] == '\0')
- return -1;
- if (tolower(name1[i]) < tolower(name2[i]))
- return 1;
- if (tolower(name1[i]) > tolower(name2[i]))
- return -1;
- }
- if (name2[i] != '\0')
- return 1;
-/* if (s1->sterr < s2->sterr) return 1;
- if (s1->sterr > s2->sterr) return -1;
- if (s1->num > s2->num) return 1;
- if (s1->num < s2->num) return -1;
-*/
- fprintf(stderr, "Duplicate entries found: %s.\n", name1);
- return 0;
-}
-
-PRIVATE int GetRankFileName(char *out, int type)
-{
- switch (type) {
- case TYPE_BLITZ:sprintf(out, "%s/rank.blitz", sdir);
- return type;
- case TYPE_STAND:
- sprintf(out, "%s/rank.std", sdir);
- return type;
- case TYPE_WILD:
- sprintf(out, "%s/rank.wild", sdir);
- return type;
- default:
- return -1;
- }
-}
-
-PUBLIC void UpdateRank(int type, char *addName,
- statistics *sNew, char *delName)
-{
- char RankFile[MAX_FILENAME_SIZE];
- char TmpRankFile[MAX_FILENAME_SIZE];
- char line[MAX_RANK_LINE];
- char login[MAX_LOGIN_NAME];
- char command[MAX_STRING_LENGTH];
- int comp;
- statistics sCur;
- FILE *fp;
- FILE *fptemp;
-
- if (GetRankFileName(RankFile, type) < 0)
- return;
- fp = fopen(RankFile, "r");
- if (fp == NULL) {
- fprintf(stderr, "Can't open rank file to update.\n");
- return;
- }
- sprintf(TmpRankFile, "%s/tmpRank", sdir);
- fptemp = fopen(TmpRankFile, "w");
-
- while (fgets(line, MAX_RANK_LINE - 1, fp)) {
- sscanf(line, "%s %d %d %d", login, &sCur.rating,
- &sCur.num, &comp);
- if (delName != NULL && !strcasecmp(delName, login)) { /* Kill name. */
- delName = NULL;
- continue;
- }
- if (addName != NULL && CompareStats(addName, sNew, login, &sCur) > 0) {
- int computer = in_list("computer", addName);
- fprintf(fptemp, "%s %d %d %d\n", addName, sNew->rating,
- sNew->num, computer);
- addName = NULL;
- }
- fprintf(fptemp, "%s %d %d %d\n", login, sCur.rating, sCur.num, comp);
- }
- fclose(fptemp);
- fclose(fp);
-
- sprintf(command, "mv %s %s", TmpRankFile, RankFile);
- system(command);
-}
-
-PRIVATE void DisplayRankHead(int p, int show)
-{
- char Line[MAX_STRING_LENGTH];
-
- Line[0] = '\0';
- if (CheckFlag(show, SHOW_BLITZ))
- strcat(Line, " Blitz ");
- if (CheckFlag(show, SHOW_STANDARD))
- strcat(Line, " Standard ");
- if (CheckFlag(show, SHOW_WILD))
- strcat(Line, " Wild");
- pprintf(p, "%s\n\n", Line);
-}
-
-PRIVATE int CountRankLine(int countComp, char *loginName,
- int num, int is_computer)
-{
- if (loginName == NULL || loginName[0] == '\0')
- return 0;
- return (countComp || !is_computer) && (is_active(num));
-}
-
-PRIVATE int GetRank(FILE * fp, char *target, int countComp)
-{
- int count = 0;
- int nGames, is_computer;
- int playerFound = 0;
- char line[MAX_RANK_LINE];
- char login[MAX_LOGIN_NAME];
-
- while (fgets(line, MAX_RANK_LINE - 1, fp) && !playerFound) {
- sscanf(line, "%s %*d %d %d", login, &nGames, &is_computer);
- if ((playerFound = !strcasecmp(login, target))
- || CountRankLine(countComp, login, nGames, is_computer))
- count++;
- }
- return (playerFound ? count : -1);
-}
-
-PRIVATE void PositionFilePtr(FILE * fp, int count, int *last,
- int *nTied, int showComp)
-{
- int i, rating, nGames, is_computer;
- char login[MAX_LOGIN_NAME];
- char line[MAX_RANK_LINE];
-
- if (fp == NULL)
- return;
- rewind(fp);
- for (i = 1; i < count; i++) {
- do {
- fgets(line, MAX_RANK_LINE - 1, fp);
- if (feof(fp))
- break;
- sscanf(line, "%s %d %d %d", login, &rating, &nGames, &is_computer);
- } while (!CountRankLine(showComp, login, nGames, is_computer));
- if (rating != *last) {
- *nTied = 1;
- *last = rating;
- } else
- (*nTied)++;
- }
-}
-
-PRIVATE int ShowRankEntry(int p, FILE * fp, int count, int comp,
- char *target, int *lastRating, int *nTied)
-{
- char newLine[MAX_RANK_LINE];
- char login[MAX_LOGIN_NAME];
- int rating, findable, nGames, is_comp;
-
- findable = (count > 0) && !feof(fp);
- if (findable) {
- do {
- fgets(newLine, MAX_RANK_LINE - 1, fp);
- if (feof(fp))
- findable = 0;
- else if (newLine[0] != '\0')
- sscanf(newLine, "%s %d %d %d",
- login, &rating, &nGames, &is_comp);
- else
- login[0] = '\0';
- } while (!CountRankLine(comp, login, nGames, is_comp) && findable
- && strcasecmp(login, target));
- }
- if (findable) {
- if (!strcasecmp(login, target)
- && !CountRankLine(comp, login, nGames, is_comp)) {
- pprintf_highlight(p, "---- %-12.12s %4s", login, ratstr(rating));
- pprintf(p, " ");
- return 0;
- } else if (*lastRating == rating && *nTied < 1) {
- pprintf(p, " ");
- if (!strcasecmp(login, target))
- pprintf_highlight(p, "%-12.12s %4s", login, ratstr(rating));
- else
- pprintf(p, "%-12.12s %4s", login, ratstr(rating));
- pprintf(p, " ");
- return 1;
- } else {
- if (*nTied >= 1) {
- if (*lastRating == rating)
- count -= *nTied;
- *nTied = -1;
- }
- if (!strcasecmp(login, target))
- pprintf_highlight(p, "%4d. %-12.12s %4s",
- count, login, ratstr(rating));
- else
- pprintf(p, "%4d. %-12.12s %4s",
- count, login, ratstr(rating));
- pprintf(p, " ");
- *lastRating = rating;
- return 1;
- }
- } else {
- pprintf(p, "%25s", "");
- return 1;
- }
-}
-
-PRIVATE int CountAbove(int num, int blitz, int std, int wild, int which)
-{
- int max = blitz;
-
- if (max < std)
- max = std;
- if (max < wild)
- max = wild;
- return (max <= (num + 1) / 2 ? max - 1 : (num + 1) / 2);
-}
-
-PRIVATE int ShowRankLines(int p, FILE * fb, FILE * fs, FILE * fw, int bCount,
- int sCount, int wCount, int n, int showComp, int show, char *target)
-{
- int lastBlitz = 9999, nTiedBlitz = 0;
- int lastStd = 9999, nTiedStd = 0;
- int lastWild = 9999, nTiedWild = 0;
- int i;
-
- if (n <= 0)
- return 0;
- if (CheckFlag(show, SHOW_BLITZ)) {
- PositionFilePtr(fb, bCount, &lastBlitz, &nTiedBlitz, showComp);
- if (feof(fb))
- ClearFlag(show, SHOW_BLITZ);
- }
- if (CheckFlag(show, SHOW_STANDARD)) {
- PositionFilePtr(fs, sCount, &lastStd, &nTiedStd, showComp);
- if (feof(fs))
- ClearFlag(show, SHOW_STANDARD);
- }
- if (CheckFlag(show, SHOW_WILD)) {
- PositionFilePtr(fw, wCount, &lastWild, &nTiedWild, showComp);
- if (feof(fw))
- ClearFlag(show, SHOW_WILD);
- }
- if (!CheckFlag(show, SHOW_BLITZ | SHOW_STANDARD | SHOW_WILD))
- return 0;
- DisplayRankHead(p, show);
-
- for (i = 0; i < n && show; i++) {
- if (CheckFlag(show, SHOW_BLITZ))
- bCount += ShowRankEntry(p, fb, bCount, showComp, target,
- &lastBlitz, &nTiedBlitz);
- if (CheckFlag(show, SHOW_STANDARD))
- sCount += ShowRankEntry(p, fs, sCount, showComp, target,
- &lastStd, &nTiedStd);
- if (CheckFlag(show, SHOW_WILD))
- wCount += ShowRankEntry(p, fw, wCount, showComp, target,
- &lastWild, &nTiedWild);
- pprintf(p, "\n");
- }
- return 1;
-}
-
-PUBLIC int DisplayTargetRank(int p, char *target, int show, int showComp)
-{
- int numToShow = 20;
- int blitzRank = -1, blitzCount;
- int stdRank = -1, stdCount;
- int wildRank = -1, wildCount;
- int numAbove;
- char Path[MAX_FILENAME_SIZE];
- FILE *fb = NULL, *fs = NULL, *fw = NULL;
-
- if (CheckFlag(show, SHOW_BLITZ)) {
- GetRankFileName(Path, TYPE_BLITZ);
- fb = (FILE *) fopen(Path, "r");
- if (fb != NULL)
- blitzRank = GetRank(fb, target, showComp);
- if (blitzRank < 0)
- ClearFlag(show, SHOW_BLITZ);
- }
- if (CheckFlag(show, SHOW_STANDARD)) {
- GetRankFileName(Path, TYPE_STAND);
- fs = (FILE *) fopen(Path, "r");
- if (fs != NULL)
- stdRank = GetRank(fs, target, showComp);
- if (stdRank < 0)
- ClearFlag(show, SHOW_STANDARD);
- }
- if (CheckFlag(show, SHOW_WILD)) {
- GetRankFileName(Path, TYPE_WILD);
- if (CheckFlag(show, SHOW_WILD))
- fw = (FILE *) fopen(Path, "r");
- if (fw != NULL)
- wildRank = GetRank(fw, target, showComp);
- if (wildRank < 0)
- ClearFlag(show, SHOW_WILD);
- }
- if (!CheckFlag(show, SHOW_BLITZ | SHOW_STANDARD | SHOW_WILD)) {
- pprintf(p, "No ratings to show.\n");
- return (0);
- }
- numAbove = CountAbove(numToShow, blitzRank, stdRank, wildRank, show);
- blitzCount = blitzRank - numAbove;
- stdCount = stdRank - numAbove;
- wildCount = wildRank - numAbove;
-
- ShowRankLines(p, fb, fs, fw, blitzCount, stdCount, wildCount,
- numToShow, showComp, show, target);
- if (fb != NULL)
- fclose(fb);
- if (fs != NULL)
- fclose(fs);
- if (fw != NULL)
- fclose(fw);
- return (1);
-}
-
-PUBLIC int DisplayRankedPlayers(int p, int start, int end,
- int show, int showComp)
-{
- int num = end - start + 1;
- FILE *fb = NULL, *fs = NULL, *fw = NULL;
- char Path[MAX_FILENAME_SIZE];
-
- if (start <= 0)
- start = 1;
- if (num <= 0)
- return 0;
- if (num > 100)
- num = 100;
- if (CheckFlag(show, SHOW_BLITZ)) {
- GetRankFileName(Path, TYPE_BLITZ);
- fb = (FILE *) fopen(Path, "r");
- if (fb == NULL)
- ClearFlag(show, SHOW_BLITZ);
- }
- if (CheckFlag(show, SHOW_STANDARD)) {
- GetRankFileName(Path, TYPE_STAND);
- fs = (FILE *) fopen(Path, "r");
- if (fs == NULL)
- ClearFlag(show, SHOW_STANDARD);
- }
- if (CheckFlag(show, SHOW_WILD)) {
- GetRankFileName(Path, TYPE_WILD);
- fw = (FILE *) fopen(Path, "r");
- if (fw == NULL)
- ClearFlag(show, SHOW_WILD);
- }
- ShowRankLines(p, fb, fs, fw, start, start, start,
- num, showComp, show, "");
- if (fb)
- fclose(fb);
- if (fs)
- fclose(fs);
- if (fw)
- fclose(fw);
- return 1;
-}
-
-PUBLIC int ShowFromString(char *s)
-{
- int i, len = strlen(s);
- int show = 0;
-
- if (s == NULL || s[0] == '\0')
- return SHOW_BLITZ | SHOW_STANDARD | SHOW_WILD;
- for (i = 0; i < len; i++) {
- switch (s[i]) {
- case 'b':
- SetFlag(show, SHOW_BLITZ);
- break;
- case 's':
- SetFlag(show, SHOW_STANDARD);
- break;
- case 'w':
- SetFlag(show, SHOW_WILD);
- break;
- }
- }
- return (show);
-}
-
-PUBLIC int Best(int p, param_list param, int ShowComp)
-{
- int show = SHOW_BLITZ | SHOW_STANDARD | SHOW_WILD;
-
- if (param[0].type != TYPE_NULL)
- show = ShowFromString(param[0].val.word);
-
- DisplayRankedPlayers(p, 1, 20, show, ShowComp);
- return COM_OK;
-}
diff --git a/FICS/stdinclude.h.orig b/FICS/stdinclude.h.orig
deleted file mode 100644
index 394b007..0000000
--- a/FICS/stdinclude.h.orig
+++ /dev/null
@@ -1,164 +0,0 @@
-/* stdinclude.h
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-#include <sys/types.h>
-
-/* Set up system specific defines */
-#if defined(SYSTEM_NEXT)
-
-#define HASMALLOCSIZE
-#include <sys/vfs.h>
-
-#elif defined(SYSTEM_ULTRIX)
-
-#include <sys/param.h>
-#include <sys/mount.h>
-
-#endif
-
-#ifdef SYSTEM_USL
-# define NO_TM_ZONE
-#endif
-
-#ifdef SYSTEM_SUN4
-# define USE_VARARGS
-#endif
-
-#ifdef SGI
-#define _BSD_SIGNALS
-#include <fcntl.h>
-#include <bstring.h>
-#endif
-
-#if defined(SYSTEM_RS6K)
-#include <sys/select.h>
-#include <dirent.h>
-#define USE_DIRENT
-#endif
-
-/* These are included into every .c file */
-#if defined(SYSTEM_SUN5)
-#define USE_RLIMIT
-#define USE_TIMES
-#define USE_WAITPID
-#define GOOD_STDIO
-#define NO_TM_ZONE
-#include <string.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/filio.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#define direct dirent
-
-#else
-#include <strings.h>
-#include <sys/dir.h>
-#endif
-
-#include <sys/stat.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/errno.h>
-#include <signal.h>
-#include <time.h>
-#include <math.h>
-#include <sys/time.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-
-/* Forward declare the functions that aren't defined above */
-
-#if defined(SGI)
-#include <errno.h>
-#define GOOD_STDIO
-#define NO_TM_ZONE
-#else
-#define GOOD_STDIO
-/*
-extern FILE *popen(char *, char *);
-extern int pclose(FILE *);
-extern int fputs(char *, FILE *);
-extern int fseek(FILE *, long, int);
-extern int fread(char *, int, int, FILE *);
-extern int fwrite(char *, int, int, FILE *);
-extern int socket(int, int, int);
-extern int atoi (char *nptr);
-extern long atol (char *nptr);
-extern int truncate(char *, off_t), ftruncate(int, off_t);
-*/
-#endif
-
-#ifndef GOOD_STDIO
-extern int fclose(FILE *);
-extern int fscanf(FILE *, char *, ...);
-extern int fprintf(FILE *, char *, ...);
-extern int printf(char *, ...);
-#endif
-
-extern time_t time(time_t *);
-extern int rand(void);
-extern int close(int);
-extern char *crypt (char *key, char *salt);
-extern size_t malloc_size(void *ptr);
-
-#ifdef __STDC__
-/* extern fcntl(int fildes, int cmd, ...); */
-/* extern open(char *path, int oflag, ...); */
-/* extern int ioctl(int, long, ...); */
-
-#else
- extern fcntl();
- extern open();
- extern int ioctl();
-
-#endif /* __STDC__ */
-/* extern void *malloc(unsigned int size); */
-/* extern void *calloc(unsigned int num, unsigned int size); */
-/* extern void *realloc(void *addr, unsigned int size); */
-/* extern void free(void *data); */
-/* extern void malloc_good_size(unsigned int size); */
-/* extern int link(); */
-/* extern int unlink(); */
-/* extern int rename(); */
-/* extern int getpid(); */
-/* extern int kill(); */
-/* extern int fork(); */
-/* extern int access(); */
-/* extern int getdtablesize(); */
-/* extern int write(); */
-#if !defined(SYSTEM_ULTRIX)
-/* extern int sleep(); */
-/* extern int getuid(); */
-extern int statfs();
-#endif
-
diff --git a/FICS/utils.c.orig b/FICS/utils.c.orig
deleted file mode 100644
index 1d4fdaa..0000000
--- a/FICS/utils.c.orig
+++ /dev/null
@@ -1,991 +0,0 @@
-/* utils.c
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-
-#include "stdinclude.h"
-
-#include "common.h"
-#include "utils.h"
-#include "playerdb.h"
-#include "network.h"
-#include "rmalloc.h"
-#include "config.h"
-#if defined(SYSTEM_SUN4)
-/* #include <sys/vfs.h> */
-#endif
-
-/*
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-*/
-
-/* grimm */
-#if defined(SGI)
-#else
-/* char vsprintf(char *tmp, va_list format, va_list ap); */
-int gettimeofday(struct timeval * tp, struct timezone * tzp);
-#endif
-/* added for warnings */
-
-PUBLIC int count_lines(FILE *fp)
-{
- int c, nl = 0;
-
- while ((c = fgetc(fp)) != EOF)
- if (c == '\n')
- ++nl;
-
- return nl;
-}
-
-PUBLIC int iswhitespace(int c)
-{
- if ((c < ' ') || (c == '\b') || (c == '\n') ||
- (c == '\t') || (c == ' ')) { /* white */
- return 1;
- } else {
- return 0;
- }
-}
-
-PUBLIC char *getword(char *str)
-{
- int i;
- static char word[MAX_WORD_SIZE];
-
- i = 0;
- while (*str && !iswhitespace(*str)) {
- word[i] = *str;
- str++;
- i++;
- if (i == MAX_WORD_SIZE) {
- i = i - 1;
- break;
- }
- }
- word[i] = '\0';
- return word;
-}
-
-PUBLIC char *eatword(char *str)
-{
- while (*str && !iswhitespace(*str))
- str++;
- return str;
-}
-
-PUBLIC char *eatwhite(char *str)
-{
- while (*str && iswhitespace(*str))
- str++;
- return str;
-}
-
-PUBLIC char *eattailwhite(char *str)
-{
- int len;
- if (str == NULL)
- return NULL;
-
- len = strlen(str);
- while (len > 0 && iswhitespace(str[len - 1]))
- len--;
- str[len] = '\0';
- return (str);
-}
-
-PUBLIC char *nextword(char *str)
-{
- return eatwhite(eatword(str));
-}
-
-/* check_the_email_address function: */
-/*
-PUBLIC int check_emailaddr(char *email)
-{
- int qbuflen;
- char qabuf[5120];
-
- if ((email = strchr(email, '@')) == NULL)
- return 2;
- email++;
-
- res_init();
- _res.options = (RES_INIT | RES_RECURSE);
- if ((qbuflen = res_mkquery(QUERY, email, C_IN, T_ANY, NULL, 0, NULL, qabuf, sizeof(qabuf))) == -1)
- return 1;
-
- if (res_send(qabuf, qbuflen, qabuf, sizeof(qabuf)) == -1)
- return 1;
-
- return (_getshort(qabuf + 6) ? 0 : 2);
-}
-*/
-
-PUBLIC int mail_string_to_address(char *addr, char *subj, char *str)
-{
- char com[1000];
- FILE *fp;
-
-#ifdef SENDMAILPROG
- sprintf(com, "%s\n", SENDMAILPROG);
-#else
- sprintf(com, "%s -s \"%s\" %s", MAILPROGRAM, subj, addr);
-#endif
- fp = popen(com, "w");
- if (!fp)
- return -1;
-#ifdef SENDMAILPROG
- fprintf(fp, "To: %s\nSubject: %s\n%s", addr, subj, str);
-#else
- fprintf(fp, "%s", str);
-#endif
- pclose(fp);
- return 0;
-}
-
-PUBLIC int mail_string_to_user(int p, char *subj, char *str)
-{
-
- if (parray[p].emailAddress &&
- parray[p].emailAddress[0] &&
- safestring(parray[p].emailAddress)) {
- return mail_string_to_address(parray[p].emailAddress, subj, str);
- } else {
- return -1;
- }
-}
-
-PUBLIC int mail_file_to_address(char *addr, char *subj, char *fname)
-{
- char com[1000];
- char tmp[MAX_LINE_SIZE];
- FILE *fp;
- FILE *file_fp;
-
-#ifdef SENDMAILPROG
- sprintf(com, "%s\n", SENDMAILPROG);
-#else
- sprintf(com, "%s -s \"%s\" %s < %s&", MAILPROGRAM, subj, addr, fname);
-#endif
- fp = popen(com, "w");
- if (!fp)
- return -1;
-#ifdef SENDMAILPROG
- fprintf(fp, "To: %s\nSubject: %s\n", addr, subj);
- file_fp = fopen(fname, "r");
- if (!file_fp)
- return -1;
- while (!feof(file_fp)) {
- fgets(tmp, MAX_LINE_SIZE - 1, file_fp);
- if (!feof(file_fp)) {
- fputs(tmp, fp);
- }
- }
- fclose(file_fp);
-
-#endif
- pclose(fp);
- return 0;
-}
-
-PUBLIC int mail_file_to_user(int p, char *subj, char *fname)
-{
-
- if (parray[p].emailAddress &&
- parray[p].emailAddress[0] &&
- safestring(parray[p].emailAddress)) {
- return mail_file_to_address(parray[p].emailAddress, subj, fname);
- } else {
- return -1;
- }
-}
-
-
-/* Process a command for a user */
-PUBLIC int pcommand(int p, char *comstr,...)
-{
- char tmp[MAX_LINE_SIZE];
- int retval;
- int current_socket = parray[p].socket;
- va_list ap;
- va_start(ap, comstr);
-
- vsprintf(tmp, comstr, ap);
- retval = process_input(current_socket, tmp);
- if (retval == COM_LOGOUT) {
- process_disconnection(current_socket);
- net_close_connection(current_socket);
- }
- va_end(ap);
- return retval;
-}
-
-PUBLIC int pprintf(int p, char *format,...)
-{
- char tmp[10 * MAX_LINE_SIZE]; /* Make sure you can handle 10 lines worth of
- stuff */
- int retval;
- va_list ap;
- va_start(ap, format);
-
- retval = vsprintf(tmp, format, ap);
- if (strlen(tmp) > 10 * MAX_LINE_SIZE) {
- fprintf(stderr, "FICS: pprintf buffer overflow\n");
- }
- net_send_string(parray[p].socket, tmp, 1);
- va_end(ap);
- return retval;
-}
-
-PUBLIC void pprintf_dohightlight(int p)
-{
- if (parray[p].highlight & 0x01)
- pprintf(p, "\033[7m");
- if (parray[p].highlight & 0x02)
- pprintf(p, "\033[1m");
- if (parray[p].highlight & 0x04)
- pprintf(p, "\033[4m");
- if (parray[p].highlight & 0x08)
- pprintf(p, "\033[2m");
-}
-
-PUBLIC int pprintf_highlight(int p, char *format,...)
-{
- char tmp[10 * MAX_LINE_SIZE];
- int retval;
- va_list ap;
-
- va_start(ap, format);
- pprintf_dohightlight(p);
- retval = vsprintf(tmp, format, ap);
- if (strlen(tmp) > 10 * MAX_LINE_SIZE) {
- fprintf(stderr, "FICS: pprintf buffer overflow\n");
- }
- net_send_string(parray[p].socket, tmp, 1);
- va_end(ap);
- if (parray[p].highlight)
- pprintf(p, "\033[0m");
- return retval;
-}
-
-PUBLIC void sprintf_dohightlight(int p, char *s)
-{
-
- if (parray[p].highlight & 0x01)
- strcat(s, "\033[7m");
- if (parray[p].highlight & 0x02)
- strcat(s, "\033[1m");
- if (parray[p].highlight & 0x04)
- strcat(s, "\033[4m");
- if (parray[p].highlight & 0x08)
- strcat(s, "\033[2m");
-}
-
-PUBLIC int psprintf_highlight(int p, char *s, char *format,...)
-{
- int retval;
- va_list ap;
-
- va_start(ap, format);
- if (parray[p].highlight) {
- sprintf_dohightlight(p, s);
- retval = vsprintf(s + strlen(s), format, ap);
- strcat(s, "\033[0m");
- } else {
- retval = vsprintf(s, format, ap);
- }
- va_end(ap);
- return retval;
-}
-
-PUBLIC int pprintf_prompt(int p, char *format,...)
-{
- char tmp[10 * MAX_LINE_SIZE]; /* Make sure you can handle 10 lines worth of
- stuff */
- int retval;
- va_list ap;
-
- va_start(ap, format);
-
- retval = vsprintf(tmp, format, ap);
- if (strlen(tmp) > 10 * MAX_LINE_SIZE) {
- fprintf(stderr, "FICS: pprintf_prompt buffer overflow\n");
- }
- net_send_string(parray[p].socket, tmp, 1);
- net_send_string(parray[p].socket, parray[p].prompt, 1);
- va_end(ap);
- return retval;
-}
-
-PUBLIC int pprintf_noformat(int p, char *format,...)
-{
- char tmp[10 * MAX_LINE_SIZE]; /* Make sure you can handle 10 lines worth of
- stuff */
- int retval;
- va_list ap;
-
- va_start(ap, format);
-
- retval = vsprintf(tmp, format, ap);
- if (strlen(tmp) > 10 * MAX_LINE_SIZE) {
- fprintf(stderr, "FICS: pprintf_noformat buffer overflow\n");
- }
- net_send_string(parray[p].socket, tmp, 0);
- va_end(ap);
- return retval;
-}
-
-
-/******************* grimm *************/
-/******************* added below *************/
-PUBLIC int psend_raw_file(int p, char *dir, char *file)
-{
- FILE *fp;
- char tmp[MAX_LINE_SIZE];
- char fname[MAX_FILENAME_SIZE];
- int num;
-
- if (dir)
- sprintf(fname, "%s/%s", dir, file);
- else
- strcpy(fname, file);
- fp = fopen(fname, "r");
- if (!fp)
- return -1;
- while ((num = fread(tmp, sizeof(char), MAX_LINE_SIZE - 1, fp)) > 0) {
- tmp[num] = '\0';
- net_send_string(parray[p].socket, tmp, 1);
- }
- fclose(fp);
- return 0;
-}
-
-PUBLIC int psend_file(int p, char *dir, char *file)
-{
- FILE *fp;
- char tmp[MAX_LINE_SIZE];
- char fname[MAX_FILENAME_SIZE];
- int lcount = parray[p].d_height - 1;
-
- if (parray[p].last_file)
- rfree(parray[p].last_file);
- parray[p].last_file = NULL;
- parray[p].last_file_byte = 0L;
-
- if (dir)
- sprintf(fname, "%s/%s", dir, file);
- else
- strcpy(fname, file);
- fp = fopen(fname, "r");
- if (!fp)
- return -1;
- while (!feof(fp) && (--lcount > 0)) {
- fgets(tmp, MAX_LINE_SIZE - 1, fp);
- if (!feof(fp)) {
- net_send_string(parray[p].socket, tmp, 1);
- }
- }
- if (!feof(fp)) {
- parray[p].last_file = strdup(fname);
- parray[p].last_file_byte = ftell(fp);
- pprintf(p, "Type [next] to see next page.\n");
- }
- fclose(fp);
- return 0;
-}
-
-/*
- * Marsalis added on 8/27/95 so that [next] does not
- * appear in the logout process for those that have
- * a short screen height. (Fixed due to complaint
- * in Bug's messages).
- */
-PUBLIC int psend_logoutfile(int p, char *dir, char *file)
-{
- FILE *fp;
- char tmp[MAX_LINE_SIZE];
- char fname[MAX_FILENAME_SIZE];
-
- if (parray[p].last_file)
- rfree(parray[p].last_file);
- parray[p].last_file = NULL;
- parray[p].last_file_byte = 0L;
-
- if (dir)
- sprintf(fname, "%s/%s", dir, file);
- else
- strcpy(fname, file);
- fp = fopen(fname, "r");
- if (!fp)
- return -1;
- while (!feof(fp)) {
- fgets(tmp, MAX_LINE_SIZE - 1, fp);
- if (!feof(fp)) {
- net_send_string(parray[p].socket, tmp, 1);
- }
- }
-
- fclose(fp);
- return 0;
-}
-
-PUBLIC int pmore_file(int p)
-{
- FILE *fp;
- char tmp[MAX_LINE_SIZE];
- int lcount = parray[p].d_height - 1;
-
- if (!parray[p].last_file) {
- pprintf(p, "There is no more.\n");
- return -1;
- }
- fp = fopen(parray[p].last_file, "r");
- if (!fp) {
- pprintf(p, "File not found!\n");
- return -1;
- }
- fseek(fp, parray[p].last_file_byte, SEEK_SET);
-
- while (!feof(fp) && (--lcount > 0)) {
- fgets(tmp, MAX_LINE_SIZE - 1, fp);
- if (!feof(fp)) {
- net_send_string(parray[p].socket, tmp, 1);
- }
- }
- if (!feof(fp)) {
- parray[p].last_file_byte = ftell(fp);
- pprintf(p, "Type [next] to see next page.\n");
- } else {
- rfree(parray[p].last_file);
- parray[p].last_file = NULL;
- parray[p].last_file_byte = 0L;
- }
- fclose(fp);
- return 0;
-}
-
-PUBLIC int psend_command(int p, char *command, char *input)
-{
- FILE *fp;
- char tmp[MAX_LINE_SIZE];
- int num;
-
- if (input)
- fp = popen(command, "w");
- else
- fp = popen(command, "r");
- if (!fp)
- return -1;
- if (input) {
- fwrite(input, sizeof(char), strlen(input), fp);
- } else {
- while (!feof(fp)) {
- num = fread(tmp, sizeof(char), MAX_LINE_SIZE - 1, fp);
- tmp[num] = '\0';
- net_send_string(parray[p].socket, tmp, 1);
- }
- }
- pclose(fp);
- return 0;
-}
-
-PUBLIC char *stolower(char *str)
-{
- int i;
-
- if (!str)
- return NULL;
- for (i = 0; str[i]; i++) {
- if (isupper(str[i])) {
- str[i] = tolower(str[i]);
- }
- }
- return str;
-}
-
-PUBLIC int safechar(int c)
-{
- if ((c == '>') || (c == '!') || (c == '&') || (c == '*') || (c == '?') ||
- (c == '/') || (c == '<') || (c == '|') || (c == '`') || (c == '$'))
- return 0;
- return 1;
-}
-
-PUBLIC int safestring(char *str)
-{
- int i;
-
- if (!str)
- return 1;
- for (i = 0; str[i]; i++) {
- if (!safechar(str[i]))
- return 0;
- }
- return 1;
-}
-
-PUBLIC int alphastring(char *str)
-{
- int i;
-
- if (!str)
- return 1;
- for (i = 0; str[i]; i++) {
- if (!isalpha(str[i])) {
- return 0;
- }
- }
- return 1;
-}
-
-PUBLIC int printablestring(char *str)
-{
- int i;
-
- if (!str)
- return 1;
- for (i = 0; str[i]; i++) {
- if ((!isprint(str[i])) && (str[i] != '\t') && (str[i] != '\n'))
- return 0;
- }
- return 1;
-}
-
-
-/*#if defined(SGI)
-#else*/
-/* This version of strdup must be used, or the count of allocs
- in "uptime" will omit them. Maybe we change the name to
- rstrdup and replace all calls, if the name is causing a conflict
- with anyone's libraries. --mann
-*/
-PUBLIC char *strdup(const char *str)
-{
- char *tmp;
-
- if (!str)
- return NULL;
- tmp = rmalloc(strlen(str) + 1);
- strcpy(tmp, str);
- return tmp;
-}
-/*#endif*/
-
-PUBLIC char *hms(int t, int showhour, int showseconds, int spaces)
-{
- static char tstr[20];
- char tmp[10];
- int h, m, s;
-
- h = t / 3600;
- t = t % 3600;
- m = t / 60;
- s = t % 60;
- if (h || showhour) {
- if (spaces)
- sprintf(tstr, "%d : %02d", h, m);
- else
- sprintf(tstr, "%d:%02d", h, m);
- } else {
- sprintf(tstr, "%d", m);
- }
- if (showseconds) {
- if (spaces)
- sprintf(tmp, " : %02d", s);
- else
- sprintf(tmp, ":%02d", s);
- strcat(tstr, tmp);
- }
- return tstr;
-}
-
-PRIVATE char *strtime(struct tm * stm)
-{
- static char tstr[100];
-
-#if defined (SGI)
- strftime(tstr, sizeof(tstr), "%a %b %e, %H:%M %Z", stm);
-#else
- strftime(tstr, sizeof(tstr), "%a %b %e, %k:%M %Z", stm);
-#endif
- return (tstr);
-}
-
-PUBLIC char *strltime(time_t *clock)
-{
- struct tm *stm = localtime(clock);
- return strtime(stm);
-}
-
-PUBLIC char *strgtime(time_t *clock)
-{
- struct tm *stm = gmtime(clock);
- return strtime(stm);
-}
-
-/* This is used only for relative timeing since it reports seconds since
- * about 5:00pm on Feb 16, 1994
- */
-PUBLIC unsigned tenth_secs(void)
-{
- struct timeval tp;
- struct timezone tzp;
-
- gettimeofday(&tp, &tzp);
-/* .1 seconds since 1970 almost fills a 32 bit int! So lets subtract off
- * the time right now */
- return ((tp.tv_sec - 331939277) * 10L) + (tp.tv_usec / 100000);
-}
-
-/* This is to translate tenths-secs time back into 1/1/70 time in full
- * seconds, because vek didn't read utils.c when he programmed new ratings.
- 1 sec since 1970 fits into a 32 bit int OK.
-*/
-PUBLIC int untenths(unsigned tenths)
-{
- return (tenths / 10 + 331939277 + 0xffffffff / 10 + 1);
-}
-
-PUBLIC char *tenth_str(unsigned t, int spaces)
-{
- return hms((t + 5) / 10, 0, 1, spaces); /* Round it */
-}
-
-#define MAX_TRUNC_SIZE 100
-
-/* Warning, if lines in the file are greater than 1024 bytes in length, this
- won't work! */
-/* nasty bug fixed by mann, 3-12-95 */
-PUBLIC int truncate_file(char *file, int lines)
-{
- FILE *fp;
- int bptr = 0, trunc = 0, i;
- char tBuf[MAX_TRUNC_SIZE][MAX_LINE_SIZE];
-
- if (lines > MAX_TRUNC_SIZE)
- lines = MAX_TRUNC_SIZE;
- fp = fopen(file, "r");
- if (!fp)
- return 1;
- while (!feof(fp)) {
- fgets(tBuf[bptr], MAX_LINE_SIZE, fp);
- if (feof(fp))
- break;
- if (tBuf[bptr][strlen(tBuf[bptr]) - 1] != '\n') { /* Line too long */
- fclose(fp);
- return -1;
- }
- bptr++;
- if (bptr == lines) {
- trunc = 1;
- bptr = 0;
- }
- }
- fclose(fp);
- if (trunc) {
- fp = fopen(file, "w");
- for (i = 0; i < lines; i++) {
- fputs(tBuf[bptr], fp);
- bptr++;
- if (bptr == lines) {
- bptr = 0;
- }
- }
- fclose(fp);
- }
- return 0;
-}
-
-/* Warning, if lines in the file are greater than 1024 bytes in length, this
- won't work! */
-PUBLIC int lines_file(char *file)
-{
- FILE *fp;
- int lcount = 0;
- char tmp[MAX_LINE_SIZE];
-
- fp = fopen(file, "r");
- if (!fp)
- return 0;
- while (!feof(fp)) {
- if (fgets(tmp, MAX_LINE_SIZE, fp))
- lcount++;
- }
- fclose(fp);
- return lcount;
-}
-
-PUBLIC int file_has_pname(char *fname, char *plogin)
-{
- if (!strcmp(file_wplayer(fname), plogin))
- return 1;
- if (!strcmp(file_bplayer(fname), plogin))
- return 1;
- return 0;
-}
-
-PUBLIC char *file_wplayer(char *fname)
-{
- static char tmp[MAX_FILENAME_SIZE];
- char *ptr;
- strcpy(tmp, fname);
- ptr = rindex(tmp, '-');
- if (!ptr)
- return "";
- *ptr = '\0';
- return tmp;
-}
-
-PUBLIC char *file_bplayer(char *fname)
-{
- char *ptr;
-
- ptr = rindex(fname, '-');
- if (!ptr)
- return "";
- return ptr + 1;
-}
-
-
-/* Hey, leave this code alone. "a" is always in network byte order,
- which is big-endian, even on a little-endian machine. I fixed this
- code to handle that correctly a while ago, and someone
- gratuitiously changed it so that it would work correctly only on a
- big-endian machine (like a Sun). I have now changed it back. --mann
-*/
-PUBLIC char *dotQuad(unsigned int a)
-{
- static char tmp[20];
- unsigned char *aa = (unsigned char *) &a;
-
- sprintf(tmp, "%d.%d.%d.%d", aa[0], aa[1], aa[2], aa[3]);
- return tmp;
-}
-
-PUBLIC int available_space(void)
-{
-#if defined(SYSTEM_NEXT)
- struct statfs buf;
-
- statfs(player_dir, &buf);
- return ((buf.f_bsize * buf.f_bavail));
-#elif defined(SYSTEM_ULTRIX)
- struct fs_data buf;
-
- statfs(player_dir, &buf);
- return ((1024 * buf.bfreen));
-#elif defined(SYSTEM_SUN4)
-/*
- struct statfs buf;
-
- statfs(player_dir, buf);
- return (1024 * buf.f_bfree); */
- return 100000000; /* Infinite space */
-#else
- return 100000000; /* Infinite space */
-#endif
-}
-
-PUBLIC int file_exists(char *fname)
-{
- FILE *fp;
-
- fp = fopen(fname, "r");
- if (!fp)
- return 0;
- fclose(fp);
- return 1;
-}
-
-PUBLIC char *ratstr(int rat)
-{
- static int on = 0;
- static char tmp[20][10];
-
- if (on == 20)
- on = 0;
- if (rat) {
- sprintf(tmp[on], "%4d", rat);
- } else {
- sprintf(tmp[on], "----");
-
- }
- on++;
- return tmp[on - 1];
-}
-
-PUBLIC char *ratstrii(int rat, int reg)
-{
- static int on = 0;
- static char tmp[20][10];
-
- if (on == 20)
- on = 0;
- if (rat) {
- sprintf(tmp[on], "%4d", rat);
- } else {
- if (reg) {
- sprintf(tmp[on], "----");
- } else {
- sprintf(tmp[on], "++++");
- }
- }
- on++;
- return tmp[on - 1];
-}
-
-struct t_tree {
- struct t_tree *left, *right;
- char name; /* Not just 1 char - space for whole name */
-}; /* is allocated. Maybe a little cheesy? */
-
-struct t_dirs {
- struct t_dirs *left, *right;
- time_t mtime; /* dir's modification time */
- struct t_tree *files;
- char name; /* ditto */
-};
-
-PRIVATE char **t_buffer = NULL; /* pointer to next space in return buffer */
-PRIVATE int t_buffersize = 0; /* size of return buffer */
-
-/* fill t_buffer with anything matching "want*" in file tree t_tree */
-PRIVATE void t_sft(char *want, struct t_tree *t)
-{
- if (t) {
- int cmp = strncmp(want, &t->name, strlen(want));
- if (cmp <= 0) /* if want <= this one, look left */
- t_sft(want, t->left);
- if (t_buffersize && (cmp == 0)) { /* if a match, add it to buffer */
- t_buffersize--;
- *t_buffer++ = &(t->name);
- }
- if (cmp >= 0) /* if want >= this one, look right */
- t_sft(want, t->right);
- }
-}
-
-/* delete file tree t_tree */
-PRIVATE void t_cft(struct t_tree **t)
-{
- if (*t) {
- t_cft(&(*t)->left);
- t_cft(&(*t)->right);
- rfree(*t);
- *t = NULL;
- }
-}
-
-/* make file tree for dir d */
-PRIVATE void t_mft(struct t_dirs *d)
-{
- DIR *dirp;
- struct dirent *dp;
- struct t_tree **t;
-
- if ((dirp = opendir(&(d->name))) == NULL) {
- fprintf(stderr, "FICS:mft() couldn't opendir.\n");
- } else {
- while ((dp = readdir(dirp))) {
- t = &d->files;
- if (dp->d_name[0] != '.') { /* skip anything starting with . */
- while (*t) {
- if (strcmp(dp->d_name, &(*t)->name) < 0) {
- t = &(*t)->left;
- } else {
- t = &(*t)->right;
- }
- }
- *t = rmalloc(sizeof(struct t_tree) + strlen(dp->d_name));
- (*t)->right = (*t)->left = NULL;
- strcpy(&(*t)->name, dp->d_name);
- }
- }
- closedir(dirp);
- }
-}
-
-PUBLIC int search_directory(char *dir, char *filter, char **buffer, int buffersize)
-{
-/* dir = directory to search
- filter = what to search for
- buffer = where to store pointers to matches
- buffersize = how many pointers will fit inside buffer */
-
- static struct t_dirs *ramdirs = NULL;
- struct t_dirs **i;
- int cmp;
- static char nullify = '\0';
- struct stat statbuf;
-
- t_buffer = buffer;
- t_buffersize = buffersize;
-
- if (!stat(dir, &statbuf)) {
- if (filter == NULL) /* NULL becomes pointer to null string */
- filter = &nullify;
- i = &ramdirs;
- while (*i) { /* find dir in dir tree */
- cmp = strcmp(dir, &(*i)->name);
- if (cmp == 0)
- break;
- else if (cmp < 0)
- i = &(*i)->left;
- else
- i = &(*i)->right;
- }
- if (!*i) { /* if dir isn't in dir tree, add him */
- *i = rmalloc(sizeof(struct t_dirs) + strlen(dir));
- (*i)->left = (*i)->right = NULL;
- (*i)->files = NULL;
- strcpy(&(*i)->name, dir);
- }
- if ((*i)->files) { /* delete any obsolete file tree */
- if ((*i)->mtime != statbuf.st_mtime) {
- t_cft(&(*i)->files);
- }
- }
- if ((*i)->files == NULL) { /* if no file tree for him, make one */
- (*i)->mtime = statbuf.st_mtime;
- t_mft(*i);
- }
- t_sft(filter, (*i)->files); /* finally, search for matches */
- }
- return (buffersize - t_buffersize);
-}
-
-PUBLIC int display_directory(int p, char **buffer, int count)
-/* buffer contains 'count' string pointers */
-{
- int i;
- multicol *m = multicol_start(count);
-
- for (i = 0; (i < count); i++)
- multicol_store(m, *buffer++);
- multicol_pprint(m, p, 78, 1);
- multicol_end(m);
- return (i);
-}
diff --git a/FICS/utils.h.orig b/FICS/utils.h.orig
deleted file mode 100644
index 68f042f..0000000
--- a/FICS/utils.h.orig
+++ /dev/null
@@ -1,115 +0,0 @@
-/* utils.h
- *
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-
-#ifndef _UTILS_H
-#define _UTILS_H
-
-#include <stdio.h>
-#include "multicol.h"
-
-#define MAX_WORD_SIZE 1024
-
-/* Maximum length of an output line */
-#define MAX_LINE_SIZE 1024
-
-/* Maximum size of a filename */
-#ifdef FILENAME_MAX
-# define MAX_FILENAME_SIZE FILENAME_MAX
-#else
-# define MAX_FILENAME_SIZE 1024
-#endif
-
-#define SetFlag(VAR, FLAG) (VAR |= (FLAG))
-#define ClearFlag(VAR, FLAG) (VAR &= ~(FLAG))
-#define CheckFlag(VAR, FLAG) (VAR & (FLAG))
-
-extern int count_lines(FILE *);
-extern int iswhitespace( );
-extern char *getword( );
-/* Returns a pointer to the first whitespace in the argument */
-extern char *eatword( );
-/* Returns a pointer to the first non-whitespace char in the argument */
-extern char *eatwhite( );
-/* Returns a pointer to the same string with trailing spaces removed */
-extern char *eattailwhite( );
-/* Returns the next word in a given string >eatwhite(eatword(foo))< */
-extern char *nextword( );
-
-extern int check_emailaddr(char *);
-extern int mail_string_to_address();
-extern int mail_string_to_user();
-extern int mail_file_to_address();
-extern int mail_file_to_user();
-extern int pcommand(int, char *, ...);
-extern int pprintf(int, char *, ...);
-extern void pprintf_dohightlight(int);
-extern void sprintf_dohightlight(int,char *);
-extern int pprintf_highlight(int, char *, ...);
-extern int psprintf_highlight(int, char *, char *, ...);
-extern int pprintf_prompt(int, char *, ...);
-extern int pprintf_noformat(int, char *, ...);
-extern int psend_raw_file( );
-extern int psend_file( );
-extern int psend_logoutfile( );
-extern int pmore_file( );
-extern int pmail_file( );
-extern int psend_command( );
-
-extern char *stolower( );
-
-extern int safechar( );
-extern int safestring( );
-extern int alphastring( );
-extern int printablestring( );
-#if defined(SGI)
-#else
-/* extern char *strdup( ); */
-#endif
-
-extern char *hms();
-extern char *strltime();
-extern char *strgtime();
-extern unsigned tenth_secs();
-extern char *tenth_str();
-extern int untenths();
-
-extern int truncate_file();
-extern int lines_file();
-
-extern int file_has_pname();
-extern char *file_wplayer();
-extern char *file_bplayer();
-
-extern char *dotQuad();
-
-extern int available_space();
-extern int file_exists();
-extern char *ratstr();
-extern char *ratstrii();
-
-extern int search_directory(char *, char *, char **, int);
-extern int display_directory(int, char **, int);
-
-#endif /* _UTILS_H */
-
diff --git a/FICS/vers.h.orig b/FICS/vers.h.orig
deleted file mode 100644
index df005ac..0000000
--- a/FICS/vers.h.orig
+++ /dev/null
@@ -1,31 +0,0 @@
-/* vers.h
- */
-
-/*
- fics - An internet chess server.
- Copyright (C) 1993 Richard V. Nash
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-*/
-
-/* Revision history:
- name email yy/mm/dd Change
- Richard Nash 93/10/22 Created
-*/
-
-#ifndef _VERS_H
-#define _VERS_H
-
-extern char SGS_VERS[];
-extern char VERS_NUM[];
-extern char COMP_DATE[];
-
-#endif /* _VERS_H */