cryptmcs.c
cmcs/src/cryptmcs.c · 252.0 KB
From the archive cmcs-stable-6.0.tar.gz
Download the archive « Back to the archive contents
/*
The Crypt Multiline Chat System
(C)2005 Rick Collette & Steve Brock
Please see historical stuff below.
*/
/**************************************************************************/
/* Main code file for Crypt v5.3 */
/**************** (Was) Code file for NUTS version 3.2.1 ******************/
/**************************************************************************
This version released: October, 1997
This is the Crypt talker system v5.01 based on Nuts v3.2.1 by Neil Robertson,
as modified by Bryan McPhail, see the files README & COPYRIGHT for further
information.
This software is provided as is. It is not intended as any sort of bullet
proof system for commercial operation (though you may use it to set up a
pay-to-use system, just don't attempt to sell the code itself) and I accept
no liability for any problems that may arise from you using it. Since this is
freeware (NOT public domain , I have not relinquished the copyright) you may
distribute it as you see fit and you may alter the code to suit your needs.
Send mail about this package to either of these addresses (listed in order
of preference):
mish@tendril.force9.net
mish@mudhole.spodnet.uk.com
bmcphail@cs.strath.ac.uk
crypt@churchnet2.ucsm.ac.uk
The webpage for this package is at: http://www.tendril.force9.co.uk/crypt/
At the time of writing the Crypt runs at: churchnet2.ucsm.ac.uk 666
Webpage: http://churchnet2.ucsm.ac.uk/~crypt
Changes from last version:
Optimised use of 'destructed' variable
Altered reset_access()
Added add_where() command
Fixed bug in shutdown() (Windows version)
Fixed a subtle bug in get_level()
Altered messages for users that are denied login
Used (optional) DIRENT method for checking boards (including user boards)
Cleared up user message board count
80 char in board...?
site in clearline in syslog
BOld text in addsite in syslog
cleared number of baord messages...
broken sockets detection
Altered home room exit if home room owner logs out
Added rose command.
Fixed bug with name substrings, eg, if a user has a name that is a substring of another user.
Version 5.2: November/December 1997
Fixed probs in more()
Added NAWS window size
Fixed bug in examine() (Size of afk[] & rank[])
You can now do Quit, Who at login (as well as quit, who)
Add login counts, peak users, etc
...Clones..
Version 5.2a/b: April 1998
Added new .where stuff
Pager problems..
Fixed for RedHat 5 (Thanks to Werewolf :)
(May also need -lcrypt when compiling on RedHat 5)
Version 5.3: June 1998
Cron support (pid file)
Silent Ban for localhost/localnet
board?? password change -> syslog
argv name
*****************************************************************************/
/* Unix or Windows compile option is defined here */
#include "platform.h"
#define HAVE_DIRENT
/* General include files */
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <setjmp.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
/* Windows includes */
#ifdef WIN_NT
#include <winsock.h>
#include <stdlib.h>
#include <winnt.h>
#include <process.h>
#else
/* Unix includes */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#ifdef _AIX
#include <sys/select.h>
#endif
#endif
#ifdef UFC_CRYPT
#include "ufc.c"
#endif
#ifdef HAVE_DIRENT
#include <dirent.h>
#endif
#ifndef SOCKET_ERROR
#define SOCKET_ERROR -1
#endif
#include "cryptmcs.h"
main(argc,argv)
int argc;
char *argv[];
{
fd_set readmask;
int i,len,ret;
char inpstr[ARR_SIZE];
UR_OBJECT user,next;
FILE *pidlog;
#ifdef WIN_NT
WSADATA WsaData;
DWORD dwThreadId, dwThrdParam = 1;
DWORD alarm_thread(LPDWORD lpdwParam);
OSVERSIONINFO myinfo;
#else
struct utsname uname_info;
#endif
strcpy(progname,argv[0]);
if (argc<2) strcpy(confile,CONFIGFILE);
else strcpy(confile,argv[1]);
/* Startup */
write_syslog("\n*** SERVER BOOTING ***\n",0);
printf("\n*** Crypt %s server booting ***\n\n",VERSION);
init_globals();
/* Setup windows sockets library */
#ifdef WIN_NT
sprintf(inpstr,"Crypt Talker %s - Win32 Version",VERSION);
SetConsoleTitle(inpstr);
if (WSAStartup(MAKEWORD(1, 1), &WsaData))
boot_exit(4);
#endif
set_date_time();
init_signals();
load_and_parse_config();
init_sockets();
check_messages(1);
/* Run in background automatically. */
#ifndef WIN_NT
switch(fork()) {
case -1: boot_exit(11); /* fork failure */
case 0: break; /* child continues */
default: sleep(1); exit(0); /* parent dies */
}
/* Get operating system version */
uname(&uname_info);
strcpy(myos,uname_info.sysname);
strcat(myos," ");
strcat(myos,uname_info.release);
/* Set up interrupts */
reset_alarm();
#else
/* Start timer thread */
hThread = CreateThread(
NULL, /* no security attributes */
0, /* use default stack size */
(LPTHREAD_START_ROUTINE) alarm_thread, /* thread function */
&dwThrdParam, /* argument to thread function */
0, /* use default creation flags */
&dwThreadId); /* returns the thread identifier */
/* Check the return value for success. */
if (hThread == NULL)
boot_exit(7);
/* Get Windows version */
myinfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&myinfo);
sprintf(myos,"Windows v%d.%d",myinfo.dwMajorVersion,myinfo.dwMinorVersion);
#endif
/* Get hostname */
if (gethostname(myhost,80))
strcpy(myhost,"(Gethostname() failed!)");
#ifndef WIN_NT
if (!getdomainname(text,80)) {
strcat(myhost,".");
strcat(myhost,text);
}
#endif
printf("Running on %s at %s\n",myos,myhost);
printf("\n*** Booted with PID %d ***\n\n",getpid());
sprintf(text,"^*** ~FRBooted~RS successfully with PID %d on %s, %d %s, %02d:%02d:%02d ^***\n\n",getpid(),day[twday],tmday,month[tmonth],thour,tmin,tsec);
write_syslog(text,0);
/* Save pid to a file for possible use by a crontab */
pidlog=fopen("var/run/pid","w");
if (pidlog) {
fprintf(pidlog,"%d\n",getpid());
fclose(pidlog);
}
else
write_syslog("Failed to open pidlog\n",1);
/**** Main program loop. *****/
setjmp(jmpvar); /* rescue if we crash and crash_action = IGNORE */
while(1) {
/* set up mask then wait */
setup_readmask(&readmask);
ret=select(FD_SETSIZE,&readmask,NULL,NULL,NULL);
if (ret==SOCKET_ERROR || ret==0) continue;
/* check for connection to listen sockets */
for(i=0;i<2;++i)
if (FD_ISSET(listen_sock[i],&readmask))
accept_connection(listen_sock[i],i);
/* Cycle through users. Use a while loop instead of a for because
user structure may be destructed during loop in which case we
may lose the user->next link. */
next=user_first;
while(next!=NULL) {
user=next;
next=user->next; /* store in case user object is destructed */
/* Check for previously broken socket on this user */
if (user->autologout==5) {
disconnect_user(user);
continue;
}
/* If clone ignore */
if (user->type!=USER_TYPE)
continue;
/* see if any data on socket else continue */
if (!FD_ISSET(user->socket,&readmask))
continue;
/* see if client (eg, telnet) has closed socket */
inpstr[0]='\0';
len=READ_S(user->socket,inpstr,sizeof(inpstr));
if (!len || len==SOCKET_ERROR) {
if (len==SOCKET_ERROR)
user->autologout=5;
disconnect_user(user);
continue;
}
/* Telnet options */
if (strstr(inpstr,"\0xFF"))
telnet_option(user,inpstr,len);
/* Ignore control codes */
if ((unsigned char)inpstr[0]>127 || inpstr[0]==10)
continue;
/* Deal with input chars. If the following if test succeeds we
are dealing with a character mode client so call function. */
if (inpstr[len-1]>=32 || user->buffpos || inpstr[0]==8) {
if (get_charclient_line(user,inpstr,len))
goto GOT_LINE;
continue;
}
else terminate(inpstr);
GOT_LINE:
no_prompt=0;
com_num=-1;
force_listen=0;
destructed=0;
user->buff[0]='\0';
user->buffpos=0;
user->last_input=time(0);
if (user->login) {
login(user,inpstr); continue;
}
clear_words();
if (user->afk) {
write_user(user,"You are no longer AFK.\n");
if (user->vis) {
sprintf(text,"%s comes back from being ~FGAFK~RS.\n",user->name);
write_room_except(user->room,text,user);
}
user->afk=0;
}
if (!(word_count=wordfind(inpstr))) {
if (misc_ops(user,inpstr))
continue;
prompt(user);
continue;
}
if (misc_ops(user,inpstr))
continue;
com_num=-1;
if (user->command_mode || strchr(".;:!<>,-#\"",inpstr[0]))
exec_com(user,inpstr);
else
say(user,inpstr);
if (!destructed)
prompt(user);
}
} /* end while */
}
/************ MAIN LOOP FUNCTIONS ************/
/*** Set up readmask for select ***/
setup_readmask(mask)
fd_set *mask;
{
UR_OBJECT user;
int i;
FD_ZERO(mask);
/* Listen sockets */
for(i=0;i<2;++i) FD_SET(listen_sock[i],mask);
/* User sockets */
for (user=user_first;user!=NULL;user=user->next)
if (user->type==USER_TYPE) FD_SET(user->socket,mask);
}
/*** Accept incoming connections on listen sockets ***/
accept_connection(lsock,num)
int lsock,num;
{
UR_OBJECT user;
char *get_ip_address(),site[80];
struct sockaddr_in acc_addr;
int accept_sock,size;
size=sizeof(struct sockaddr_in);
accept_sock=accept(lsock,(struct sockaddr *)&acc_addr,&size);
strcpy(site,get_ip_address(acc_addr));
/* You can hardcode banned sites in at this point, just compare the
site to the banned site and CLOSE(accept_socket) */
/* Silent bans - the banned user does not even see motd screen */
if (silent_ban(site)) {
CLOSE(accept_sock);
sprintf(text,"Attempted login from ~FRsilent banned~RS site %s.\n",site);
write_syslog(text,1);
sprintf(text,"~OLSYSTEM: ~RSAttempted login from ~FRsilent banned~RS site %s\n",site);
write_room(NULL,text);
return;
}
/* Check for a TOTAL site ban... */
if (site_banned(site) && !num) { /* Allow banned logins on archport */
write_sock(accept_sock,"\n\rLogins from your site are banned.\n\n\r");
CLOSE(accept_sock);
sprintf(text,"Attempted login from ~FRbanned~RS site %s.\n",site);
write_syslog(text,1);
sprintf(text,"~OLSYSTEM: ~RSAttempted login from ~FRbanned~RS site %s\n",site);
write_room(NULL,text);
return;
}
/* send pre-login message */
more(NULL,accept_sock,"%s/%s",TEXTFILES,MOTD1);
if (num_of_users+num_of_logins>=max_users && !num) {
write_sock(accept_sock,"\n\rSorry, the talker is full at the moment. Please try again later.\n\n\r");
CLOSE(accept_sock);
sprintf(text,"~OLSYSTEM: ~RSLogin for user failed due to talker being full.\n");
write_wiz(ARCH,text,NULL);
return;
}
if ((user=create_user())==NULL) {
sprintf(text,"\n\r%s: unable to create session.\n\n\r",syserror);
write_sock(accept_sock,text);
CLOSE(accept_sock);
return;
}
user->socket=accept_sock;
user->login=1;
user->last_input=time(0);
if (!num) user->port=port[0];
else {
user->port=port[1];
write_user(user,"*** Archport login ***\n\n");
}
strcpy(user->site,site);
/* Get the local port number & network address for user */
strcpy(user->ip_num,(char *)inet_ntoa(acc_addr.sin_addr));
user->site_port=(int)ntohs(acc_addr.sin_port);
user->auth_addr=acc_addr.sin_addr.s_addr;
/* Ask for telnet options from users client */
telnet_init(user);
echo_on(user);
write_user(user,"Enter your name: ");
num_of_logins++;
}
/*** Get the .where entry from a text site name ***/
get_where_text(user,input)
UR_OBJECT user;
char *input;
{
FILE *fp;
char tmp[83];
int z;
sprintf(tmp,"%s/%s",DATAFILES, WHERE_TEXT);
if (!(fp=fopen(tmp,"r"))) {
user->ip_name[0]=0;
write_syslog("~FRWarning:~RS .where textfile not found\n",1);
return;
}
while (!feof(fp)) {
fgets(tmp,81,fp);
if (tmp[0]=='#')
continue;
if (strlen(tmp)<3) continue;
tmp[strlen(tmp)-2]=0;
if (strstr(input,tmp)) {
fgets(tmp,81,fp);
tmp[strlen(tmp)-2]=0;
strcpy(user->ip_name, tmp);
strcat(user->ip_name, "\n");
fclose(fp);
return;
}
}
/* This will be filled in by old IP method */
user->ip_name[0]=0;
fclose(fp);
}
/*** Get the name of a site from the ip address ***/
get_ip_text(user,input)
UR_OBJECT user;
char *input;
{
FILE *fp;
char tmp[83],*tok,class,new_text[20],input2[20];
int d;
strcpy(input2,input);
/* Get class of IP Address */
tok=strtok(input2,".");
d=atoi(tok);
if (d>191)
class='C';
else
if (d>127)
class='B';
else
class='A';
switch (class) {
case 'A': sprintf(tmp,"%s/%s",DATAFILES, WHERE_FILE_A); break;
case 'B': sprintf(tmp,"%s/%s",DATAFILES, WHERE_FILE_B); break;
case 'C': sprintf(tmp,"%s/%s",DATAFILES, WHERE_FILE_C); break;
}
if (!(fp=fopen(tmp,"r"))) {
strcpy(user->ip_name, "IP datafile missing!\n");
return;
}
strcpy(new_text,tok);
strcat(new_text,".");
if (class=='B' || class=='C') {
tok=strtok(NULL,".");
strcat(new_text,tok);
strcat(new_text,".");
}
if (class=='C') {
tok=strtok(NULL,".");
strcat(new_text,tok);
strcat(new_text,".");
}
while (!feof(fp)) {
fgets(tmp,81,fp);
if (!isdigit(tmp[0]))
continue;
if (!strncmp(new_text,tmp,strlen(new_text))) {
fgets(tmp,81,fp);
strcpy(user->ip_name, tmp);
fclose(fp);
return;
}
}
strcpy(user->ip_name, "Sorry, unknown location!\n");
fclose(fp);
/* Mark unknown locations to syslog */
sprintf(text,"~FRUnknown site~RS %s (%s) (~FG%s~RS)\n", user->site,user->ip_num,user->name);
write_syslog(text,1);
}
/*** Get net address of accepted connection ***/
char *get_ip_address(acc_addr)
struct sockaddr_in acc_addr;
{
static char site[80];
unsigned int addr;
struct hostent *host;
strcpy(site,(char *)inet_ntoa(acc_addr.sin_addr)); /* get number addr */
addr=inet_addr(site);
if ((host=gethostbyaddr((char *)&addr,4,AF_INET))!=NULL)
strcpy(site,host->h_name); /* copy name addr. */
strtolower(site);
return site;
}
/*** See if users site is banned ***/
silent_ban(site)
char *site;
{
FILE *fp;
char line[82],filename[80];
sprintf(filename,"%s/%s",DATAFILES,SILENTBAN);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%s",line);
while(!feof(fp)) {
if (strstr(site,line)) { fclose(fp); return 1; }
fscanf(fp,"%s",line);
}
fclose(fp);
return 0;
}
/*** See if users site is banned ***/
site_banned(site)
char *site;
{
FILE *fp;
char line[82],filename[80];
sprintf(filename,"%s/%s",DATAFILES,SITEBAN);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%s",line);
while(!feof(fp)) {
if (strstr(site,line)) { fclose(fp); return 1; }
fscanf(fp,"%s",line);
}
fclose(fp);
return 0;
}
/*** See if users site is banned ***/
partial_site_banned(site)
char *site;
{
FILE *fp;
char line[82],filename[80];
sprintf(filename,"%s/%s",DATAFILES,PARTIAL_SITEBAN);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%s",line);
while(!feof(fp)) {
if (strstr(site,line)) { fclose(fp); return 1; }
fscanf(fp,"%s",line);
}
fclose(fp);
return 0;
}
/*** See if user is banned ***/
user_banned(name)
char *name;
{
FILE *fp;
char line[82],filename[80];
sprintf(filename,"%s/%s",DATAFILES,USERBAN);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%s",line);
while(!feof(fp)) {
if (!strcmp(line,name)) { fclose(fp); return 1; }
fscanf(fp,"%s",line);
}
fclose(fp);
return 0;
}
/*** Attempt to get '\n' terminated line of input from a character
mode client else store data read so far in user buffer. ***/
get_charclient_line(user,inpstr,len)
UR_OBJECT user;
char *inpstr;
int len;
{
int l;
char *lf="\r";
for(l=0;l<len;++l) {
/* see if delete entered */
if (inpstr[l]==8 || inpstr[l]==127) {
if (user->buffpos) {
user->buffpos--;
if (user->charmode_echo) write_user(user,"\b \b");
}
continue;
}
user->buff[user->buffpos]=inpstr[l];
/* See if end of line */
if (inpstr[l]<32 || user->buffpos+3==ARR_SIZE) {
if (WRITE_S(user->socket,lf,1)==SOCKET_ERROR) {
user->autologout=5;
disconnect_user(user);
return 0;
}
terminate(user->buff);
strcpy(inpstr,user->buff);
if (user->charmode_echo) write_user(user,"\n\r");
return 1;
}
user->buffpos++;
}
if (user->charmode_echo && (user->login!=2 || password_echo)) {
if (WRITE_S(user->socket,inpstr,len)==SOCKET_ERROR) {
user->autologout=5;
disconnect_user(user);
return 0;
}
}
return 0;
}
/*** Put string terminate char. at first char < 32 || > 126 ***/
terminate(str)
char *str;
{
int i;
for (i=0;i<ARR_SIZE;++i)
if ((*(str+i)<32) || (*(str+i)>126)) { *(str+i)=0; return; }
str[i-1]=0;
}
/*** Get words from sentence. This function prevents the words in the
sentence from writing off the end of a word array element. This is
difficult to do with sscanf() hence I use this function instead. ***/
wordfind(inpstr)
char *inpstr;
{
int wn,wpos;
wn=0; wpos=0;
do {
while(*inpstr<33) if (!*inpstr++) return wn;
while(*inpstr>32 && wpos<WORD_LEN-1) {
word[wn][wpos]=*inpstr++; wpos++;
}
word[wn][wpos]='\0';
wn++; wpos=0;
} while (wn<MAX_WORDS);
return wn-1;
}
/* Copies the first word of a string into a buffer - used by > shortcut */
namecpy(dest,src)
char *dest;
char *src;
{
int i=0;
while (src[i]!='\0' && src[i]!=' ') {
dest[i]=src[i];
i++;
if (i==WORD_LEN-2)
break;
}
dest[i]='\0';
}
/*** clear word array etc. ***/
clear_words()
{
int w;
for(w=0;w<MAX_WORDS;++w) word[w][0]='\0';
word_count=0;
}
/************ PARSE CONFIG FILE **************/
load_and_parse_config()
{
FILE *fp;
char line[81]; /* Should be long enough */
char c,filename[80];
int i,section_in,got_init,got_rooms;
RM_OBJECT rm1,rm2;
section_in=0;
got_init=0;
got_rooms=0;
sprintf(filename,"%s/%s",DATAFILES,confile);
printf("Parsing config file \"%s\"...\n",filename);
if (!(fp=fopen(filename,"r"))) {
perror("NUTS: Can't open config file"); boot_exit(1);
}
/* Main reading loop */
config_line=0;
fgets(line,81,fp);
while(!feof(fp)) {
config_line++;
for(i=0;i<8;++i) wrd[i][0]='\0';
sscanf(line,"%s %s %s %s %s %s %s %s",wrd[0],wrd[1],wrd[2],wrd[3],wrd[4],wrd[5],wrd[6],wrd[7]);
if (wrd[0][0]=='#' || wrd[0][0]=='\0') {
fgets(line,100,fp); continue;
}
/* See if new section */
if (wrd[0][strlen(wrd[0])-1]==':') {
if (!strcmp(wrd[0],"INIT:")) section_in=1;
else if (!strcmp(wrd[0],"ROOMS:")) section_in=2;
else {
fprintf(stderr,"NUTS: Unknown section header on line %d.\n",config_line);
fclose(fp); boot_exit(1);
}
}
switch(section_in) {
case 1: parse_init_section(); got_init=1; break;
case 2: parse_rooms_section(); got_rooms=1; break;
default:
fprintf(stderr,"NUTS: Section header expected on line %d.\n",config_line);
boot_exit(1);
}
fgets(line,100,fp);
}
fclose(fp);
/* See if required sections were present and if required parameters were set.
*/
if (!got_init) {
fprintf(stderr,"NUTS: INIT section missing from config file.\n");
boot_exit(1);
}
if (!got_rooms) {
fprintf(stderr,"NUTS: ROOMS section missing from config file.\n");
boot_exit(1);
}
if (!port[0]) {
fprintf(stderr,"NUTS: Main port number not set in config file.\n");
boot_exit(1);
}
if (!port[1]) {
fprintf(stderr,"NUTS: Wiz port number not set in config file.\n");
boot_exit(1);
}
if (port[0]==port[1]) {
fprintf(stderr,"NUTS: Port numbers must be unique.\n");
boot_exit(1);
}
if (room_first==NULL) {
fprintf(stderr,"NUTS: No rooms configured in config file.\n");
boot_exit(1);
}
/* Parsing done, now check data is valid. Check room stuff first. */
for(rm1=room_first;rm1!=NULL;rm1=rm1->next) {
for(i=0;i<MAX_LINKS;++i) {
if (!rm1->link_label[i][0]) break;
for(rm2=room_first;rm2!=NULL;rm2=rm2->next) {
if (rm1==rm2) continue;
if (!strcmp(rm1->link_label[i],rm2->label)) {
rm1->link[i]=rm2; break;
}
}
if (rm1->link[i]==NULL) {
fprintf(stderr,"NUTS: Room %s has undefined link label '%s'.\n",rm1->name,rm1->link_label[i]);
boot_exit(1);
}
}
}
/*** Load room descriptions ***/
for(rm1=room_first;rm1!=NULL;rm1=rm1->next) {
sprintf(filename,"%s/%s.R",DATAFILES,rm1->name);
if (!(fp=fopen(filename,"r"))) {
fprintf(stderr,"NUTS: Can't open description file for room %s.\n",rm1->name);
sprintf(text,"Couldn't open description file for room %s.\n",rm1->name);
write_syslog(text,1);
continue;
}
i=0;
c=getc(fp);
while(!feof(fp)) {
if (i==ROOM_DESC_LEN) {
fprintf(stderr,"NUTS: Description too long for room %s.\n",rm1->name);
sprintf(text,"Description too long for room %s.\n",rm1->name);
write_syslog(text,1);
break;
}
rm1->desc[i]=c;
c=getc(fp); ++i;
}
rm1->desc[i]='\0';
fclose(fp);
}
/* Load atmospherics details.... */
sprintf(filename,"%s/%s",DATAFILES,ATMOS_FILE);
if (fp=fopen(filename,"r")) {
fscanf(fp, "%s\n", text);
atmos_no=atoi(text);
printf("Loading atmospherics - %d lines.\n",atmos_no);
if (!atmos_no)
return;
if (atmos_no>MAX_NO_OF_ATMOS) {
fprintf(stderr,"NUTS: Too many atmospheric lines found - allocate more memory in the .h file\n");
exit(1);
}
for (i=0; i<atmos_no; i++) {
fgets(line,81,fp);
strcpy(atmos_array[i], line);
}
fclose(fp);
}
else
fprintf(stderr,"NUTS: Cannot open atmospherics file.\n");
}
/*** Parse init section ***/
parse_init_section()
{
static int in_section=0;
int op,val;
char *options[]={
"mainport","wizport","linkport","logging","minlogin_level","mesg_life","wizport_level", \
"prompt_def","gatecrash_level","min_private","ignore_mp_level","mesg_check_time", \
"rem_user_min", "rem_user_max","verification","max_users","heartbeat","login_idle_time", \
"user_idle_time","password_echo","ignore_sigterm","auto_connect","max_clones", \
"ban_swearing","crash_action","colour_def","time_out_afks","allow_caps_in_name", \
"atmospherics","backup_check_time","spod_check_time","web_page","save_newbies", \
"ewtoo_default","autopromote","userweb","backups","*"
};
if (!strcmp(wrd[0],"INIT:")) {
if (++in_section>1) {
fprintf(stderr,"NUTS: Unexpected INIT section header on line %d.\n",config_line);
boot_exit(1);
}
return;
}
op=0;
while(strcmp(options[op],wrd[0])) {
if (options[op][0]=='*') {
fprintf(stderr,"NUTS: Unknown INIT option on line %d.\n",config_line);
boot_exit(1);
}
++op;
}
if (!wrd[1][0]) {
fprintf(stderr,"NUTS: Required parameter missing on line %d.\n",config_line);
boot_exit(1);
}
if (wrd[2][0] && wrd[2][0]!='#') {
fprintf(stderr,"NUTS: Unexpected word following init parameter on line %d.\n",config_line);
boot_exit(1);
}
val=atoi(wrd[1]);
switch(op) {
case 0: /* main port */
case 1:
if ((port[op]=val)<1 || val>65535) {
fprintf(stderr,"NUTS: Illegal port number on line %d.\n",config_line);
boot_exit(1);
}
return;
case 3:
if ((system_logging=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: System_logging must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 4:
if ((minlogin_level=get_level(wrd[1]))==-1) {
if (strcmp(wrd[1],"NONE")) {
fprintf(stderr,"NUTS: Unknown level specifier on line %d.\n",config_line);
boot_exit(1);
}
minlogin_level=-1;
}
return;
case 5: /* message lifetime */
if ((mesg_life=val)<1) {
fprintf(stderr,"NUTS: Illegal message lifetime on line %d.\n",config_line);
boot_exit(1);
}
return;
case 6: /* wizport_level */
if ((wizport_level=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier on line %d.\n",config_line);
boot_exit(1);
}
return;
case 7: /* prompt defaults - changed.. */
prompt_def=val;
if (val<0 || val>PROMPT_TYPES) {
fprintf(stderr,"NUTS: Invalid prompt type on line %d.\n",config_line);
boot_exit(1);
}
return;
case 8: /* gatecrash level */
if ((gatecrash_level=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier on line %d.\n",config_line);
boot_exit(1);
}
return;
case 9:
if (val<1) {
fprintf(stderr,"NUTS: Number too low on line %d.\n",config_line);
boot_exit(1);
}
min_private_users=val;
return;
case 10:
if ((ignore_mp_level=get_level(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Unknown level specifier on line %d.\n",config_line);
boot_exit(1);
} return;
case 11: return;
case 12: return;
case 13: return;
case 14: /* mesg_check_time */
if (wrd[1][2]!=':'
|| strlen(wrd[1])>5
|| !isdigit(wrd[1][0])
|| !isdigit(wrd[1][1])
|| !isdigit(wrd[1][3])
|| !isdigit(wrd[1][4])) {
fprintf(stderr,"NUTS: Invalid time on line %d.\n",config_line);
boot_exit(1);
}
wrd[1][2]=' ';
sscanf(wrd[1],"%d %d",&mesg_check_hour,&mesg_check_min);
if (mesg_check_hour>23 || mesg_check_min>59) {
fprintf(stderr,"NUTS: Invalid time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 15:
if ((max_users=val)<1) {
fprintf(stderr,"NUTS: Invalid value for max_users on line %d.\n",config_line);
boot_exit(1);
}
return;
case 16:
if ((heartbeat=val)<1) {
fprintf(stderr,"NUTS: Invalid value for heartbeat on line %d.\n",config_line);
boot_exit(1);
}
return;
case 17:
if ((login_idle_time=val)<10) {
fprintf(stderr,"NUTS: Invalid value for login_idle_time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 18:
if ((user_idle_time=val)<10) {
fprintf(stderr,"NUTS: Invalid value for user_idle_time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 19:
if ((password_echo=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Password_echo must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 20:
if ((ignore_sigterm=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Ignore_sigterm must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 21: return;
case 22:
if ((max_clones=val)<0) {
fprintf(stderr,"NUTS: Invalid value for max_clones on line %d.\n",config_line);
boot_exit(1);
}
return;
case 23:
if ((ban_swearing=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Ban_swearing must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 24:
if (!strcmp(wrd[1],"NONE")) crash_action=0;
else if (!strcmp(wrd[1],"IGNORE")) crash_action=1;
else if (!strcmp(wrd[1],"REBOOT")) crash_action=2;
else {
fprintf(stderr,"NUTS: Crash_action must be NONE, IGNORE or REBOOT on line %d.\n",config_line);
boot_exit(1);
}
return;
case 25:
if ((colour_def=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Colour_def must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 26:
if ((time_out_afks=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Time_out_afks must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 27:
if ((allow_caps_in_name=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Allow_caps_in_name must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
/* New INIT options here */
case 28:
if ((atmos=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Atmospherics must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 29: /* backup_check_time */
if (wrd[1][2]!=':'
|| strlen(wrd[1])>5
|| !isdigit(wrd[1][0])
|| !isdigit(wrd[1][1])
|| !isdigit(wrd[1][3])
|| !isdigit(wrd[1][4])) {
fprintf(stderr,"NUTS: Invalid time on line %d.\n",config_line);
boot_exit(1);
}
wrd[1][2]=' ';
sscanf(wrd[1],"%d %d",&backup_check_hour,&backup_check_min);
if (backup_check_hour>23 || backup_check_min>59) {
fprintf(stderr,"NUTS: Invalid time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 30: /* spod_check_time */
if (wrd[1][2]!=':'
|| strlen(wrd[1])>5
|| !isdigit(wrd[1][0])
|| !isdigit(wrd[1][1])
|| !isdigit(wrd[1][3])
|| !isdigit(wrd[1][4])) {
fprintf(stderr,"NUTS: Invalid time on line %d.\n",config_line);
boot_exit(1);
}
wrd[1][2]=' ';
sscanf(wrd[1],"%d %d",&spod_check_hour,&spod_check_min);
if (spod_check_hour>23 || spod_check_min>59) {
fprintf(stderr,"NUTS: Invalid time on line %d.\n",config_line);
boot_exit(1);
}
return;
case 31:
if ((web_page_on=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Web_page must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 32:
if ((save_newbies=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Save_newbies must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 33:
if ((command_mode_def=yn_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Ewtoo_default must be YES or NO on line %d.\n",config_line);
boot_exit(1);
}
return;
case 34:
if ((auto_promote=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Autopromote must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 35:
if ((userweb_on=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Userweb must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
case 36:
if ((backup_on=onoff_check(wrd[1]))==-1) {
fprintf(stderr,"NUTS: Backups must be ON or OFF on line %d.\n",config_line);
boot_exit(1);
}
return;
}
}
/*** Parse rooms section ***/
parse_rooms_section()
{
static int in_section=0;
int i;
char *ptr1,*ptr2,c;
RM_OBJECT room;
if (!strcmp(wrd[0],"ROOMS:")) {
if (++in_section>1) {
fprintf(stderr,"NUTS: Unexpected ROOMS section header on line %d.\n",config_line);
boot_exit(1);
}
return;
}
if (!wrd[2][0]) {
fprintf(stderr,"NUTS: Required parameter(s) missing on line %d.\n",config_line);
boot_exit(1);
}
if (strlen(wrd[0])>ROOM_LABEL_LEN) {
fprintf(stderr,"NUTS: Room label too long on line %d.\n",config_line);
boot_exit(1);
}
if (strlen(wrd[1])>ROOM_NAME_LEN) {
fprintf(stderr,"NUTS: Room name too long on line %d.\n",config_line);
boot_exit(1);
}
/* Check for duplicate label or name */
for(room=room_first;room!=NULL;room=room->next) {
if (!strcmp(room->label,wrd[0])) {
fprintf(stderr,"NUTS: Duplicate room label on line %d.\n",config_line);
boot_exit(1);
}
if (!strcmp(room->name,wrd[1])) {
fprintf(stderr,"NUTS: Duplicate room name on line %d.\n",config_line);
boot_exit(1);
}
}
room=create_room();
if (room==NULL)
boot_exit(1);
strcpy(room->label,wrd[0]);
strcpy(room->name,wrd[1]);
/* Parse internal links bit ie hl,gd,of etc. MUST NOT be any spaces between
the commas */
i=0;
ptr1=wrd[2];
ptr2=wrd[2];
while(1) {
while(*ptr2!=',' && *ptr2!='\0') ++ptr2;
if (*ptr2==',' && *(ptr2+1)=='\0') {
fprintf(stderr,"NUTS: Missing link label on line %d.\n",config_line);
boot_exit(1);
}
c=*ptr2; *ptr2='\0';
if (!strcmp(ptr1,room->label)) {
fprintf(stderr,"NUTS: Room has a link to itself on line %d.\n",config_line);
boot_exit(1);
}
strcpy(room->link_label[i],ptr1);
if (c=='\0') break;
if (++i>=MAX_LINKS) {
fprintf(stderr,"NUTS: Too many links on line %d.\n",config_line);
boot_exit(1);
}
*ptr2=c;
ptr1=++ptr2;
}
/* Parse access privs */
if (wrd[3][0]=='#') { room->access=PUBLIC; return; }
if (!wrd[3][0] || !strcmp(wrd[3],"BOTH")) room->access=PUBLIC;
else if (!strcmp(wrd[3],"PUB")) room->access=FIXED_PUBLIC;
else if (!strcmp(wrd[3],"PRIV")) room->access=FIXED_PRIVATE;
else {
fprintf(stderr,"NUTS: Unknown room access type on line %d.\n",config_line);
boot_exit(1);
}
if (!wrd[4][0] || wrd[4][0]=='#') return;
boot_exit(1);
}
yn_check(wd)
char *wd;
{
if (!strcmp(wd,"YES")) return 1;
if (!strcmp(wd,"NO")) return 0;
return -1;
}
onoff_check(wd)
char *wd;
{
if (!strcmp(wd,"ON")) return 1;
if (!strcmp(wd,"OFF")) return 0;
return -1;
}
/************ INITIALISATION FUNCTIONS *************/
/*** Initialise globals ***/
init_globals()
{
port[0]=0;
port[1]=0;
max_users=50;
max_clones=1;
ban_swearing=0;
heartbeat=2;
login_idle_time=180;
user_idle_time=300;
time_out_afks=0;
wizport_level=WIZ;
minlogin_level=-1;
mesg_life=1;
no_prompt=0;
num_of_users=0;
num_of_logins=0;
system_logging=1;
password_echo=0;
ignore_sigterm=0;
crash_action=2; /* reboot */
prompt_def=1;
command_mode_def=0;
colour_def=1;
mesg_check_hour=0;
mesg_check_min=0;
allow_caps_in_name=1;
gatecrash_level=GOD+2; /* minimum user level which can enter private rooms */
min_private_users=2; /* minimum num. of users in room before can set to priv */
ignore_mp_level=GOD; /* User level which can ignore the above var. */
user_first=NULL;
user_last=NULL;
room_first=NULL;
room_last=NULL;
atmos=0; /* Atmos turned off */
atmos_no=0;
backup_check_hour=2;
backup_check_min=0;
spod_check_hour=3;
spod_check_min=0;
web_page_on=1;
save_newbies=0;
auto_promote=1;
backup_on=0;
userweb_on=0;
total_logins=0;
peak_logins=0;
clear_words();
time(&boot_time);
}
/*** Initialise the signal traps etc ***/
init_signals()
{
void sig_handler();
/* Windows and Unix both support these signals */
signal(SIGILL,SIG_IGN);
signal(SIGSEGV,sig_handler);
signal(SIGTERM,sig_handler);
signal(SIGINT,SIG_IGN);
signal(SIGFPE,SIG_IGN);
signal(SIGABRT,SIG_IGN);
#ifndef WIN_NT
/* Unix only signals */
signal(SIGBUS,sig_handler);
signal(SIGTRAP,SIG_IGN);
signal(SIGIOT,SIG_IGN);
signal(SIGTSTP,SIG_IGN);
signal(SIGCONT,SIG_IGN);
signal(SIGHUP,SIG_IGN);
signal(SIGQUIT,SIG_IGN);
signal(SIGURG,SIG_IGN);
signal(SIGPIPE,SIG_IGN);
signal(SIGTTIN,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
#endif
}
/*** Some signal trapping functions ***/
void sig_handler(sig)
int sig;
{
force_listen=1;
switch(sig) {
case SIGTERM:
if (ignore_sigterm) {
write_syslog("SIGTERM signal received - ignoring.\n",1);
return;
}
write_room(NULL,"\n\n~OLSYSTEM:~FY~LI SIGTERM recieved, initiating shutdown.\n\n");
talker_shutdown(NULL,"a termination signal ~FY(SIGTERM)~RS",0);
case SIGSEGV:
switch(crash_action) {
case 0:
write_room(NULL,"\n\n\07~OLSYSTEM:~FR~LI PANIC - Segmentation fault, initiating shutdown!\n\n");
talker_shutdown(NULL,"a segmentation fault ~FY(SIGSEGV)~RS",0);
case 1:
write_room(NULL,"\n\n\07~OLSYSTEM:~FR~LI WARNING - A segmentation fault has just occured!\n\n");
write_syslog("WARNING: A segmentation fault occured!\n",1);
longjmp(jmpvar,0);
case 2:
write_room(NULL,"\n\n\07~OLSYSTEM:~FR~LI PANIC - Segmentation fault, initiating reboot!\n\n");
talker_shutdown(NULL,"a segmentation fault ~FY(SIGSEGV)~RS",1);
}
#ifndef WIN_NT
/* Windows doesn't support sigbus... */
case SIGBUS:
switch(crash_action) {
case 0:
write_room(NULL,"\n\n\07~OLSYSTEM:~FR~LI PANIC - Bus error, initiating shutdown!\n\n");
talker_shutdown(NULL,"a bus error ~FY(SIGBUS)~RS",0);
case 1:
write_room(NULL,"\n\n\07~OLSYSTEM:~FR~LI WARNING - A bus error has just occured!\n\n");
write_syslog("WARNING: A bus error occured!\n",1);
longjmp(jmpvar,0);
case 2:
write_room(NULL,"\n\n\07~OLSYSTEM:~FR~LI PANIC - Bus error, initiating reboot!\n\n");
talker_shutdown(NULL,"a bus error ~FY(SIGBUS)~RS",0);
}
#endif
}
}
/*** Initialise sockets on ports ***/
init_sockets()
{
struct sockaddr_in bind_addr;
int i,on,size;
printf("Initialising sockets on ports: %d, %d\n",port[0],port[1]);
size=sizeof(struct sockaddr_in);
bind_addr.sin_family=AF_INET;
bind_addr.sin_addr.s_addr=INADDR_ANY;
for(i=0;i<2;++i) {
/* create sockets */
#ifdef WIN_NT
if ((listen_sock[i]=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET) boot_exit(i+2);
#else
if ((listen_sock[i]=socket(AF_INET,SOCK_STREAM,0))==-1) boot_exit(i+2);
/* allow reboots on port even with TIME_WAITS */
on=1;
setsockopt(listen_sock[i],SOL_SOCKET,SO_REUSEADDR,(char *)&on,sizeof(on));
#endif
/* bind sockets and set up listen queues */
bind_addr.sin_port=htons(port[i]);
#ifdef WIN_NT
if (bind(listen_sock[i],(struct sockaddr *)&bind_addr,size)!=0) boot_exit(i+5);
if (listen(listen_sock[i],10)==SOCKET_ERROR) boot_exit(i+8);
#else
if (bind(listen_sock[i],(struct sockaddr *)&bind_addr,size)==-1) boot_exit(i+5);
if (listen(listen_sock[i],10)==-1) boot_exit(i+8);
/* Set to non-blocking , do we need this? not really */
fcntl(listen_sock[i],F_SETFL,O_NDELAY);
#endif
}
}
/************* WRITE FUNCTIONS ************/
/*** Write a NULL terminated string to a socket ***/
write_sock(sock,str)
int sock;
char *str;
{
WRITE_S(sock,str,strlen(str));
}
/*** Send message to user ***/
write_user(user,str)
UR_OBJECT user;
char *str;
{
int buffpos,sock,i;
char buff[OUT_BUFF_SIZE];
int bold_on=0;
if (user==NULL || user->autologout==5) return;
buffpos=0;
sock=user->socket;
/* Process string and write to buffer. We use pointers here instead of arrays
since these are supposedly much faster (though in reality I guess it depends
on the compiler) which is necessary since this routine is used all the
time. */
while(*str) {
if (*str=='\n') {
if (buffpos>OUT_BUFF_SIZE-6) {
if (WRITE_S(sock,buff,buffpos)==SOCKET_ERROR) {
user->autologout=5;
return;
}
buffpos=0;
}
/* Reset terminal before every newline */
if (user->colour) {
memcpy(buff+buffpos,"\033[0m",4); buffpos+=4;
}
*(buff+buffpos)='\n'; *(buff+buffpos+1)='\r';
buffpos+=2; ++str;
}
else {
/* Process colour commands eg ~FR. We have to strip out the commands
from the string even if user doesnt have colour switched on hence
the user->colour check isn't done just yet */
if (*str=='~') {
if (buffpos>OUT_BUFF_SIZE-6) {
if (WRITE_S(sock,buff,buffpos)==SOCKET_ERROR) {
user->autologout=5;
return;
}
buffpos=0;
}
++str;
for(i=0;i<NUM_COLS;++i) {
if (!strncmp(str,colcom[i],2)) {
if (user->colour) {
memcpy(buff+buffpos,colcode[i],strlen(colcode[i]));
buffpos+=strlen(colcode[i])-1;
}
else buffpos--;
++str;
goto CONT;
}
}
--str; *(buff+buffpos)=*str;
}
else
/* Mish - Check for 'old style' bold text */
if (*str=='^') {
if (buffpos>OUT_BUFF_SIZE-6) {
if (WRITE_S(sock,buff,buffpos)==SOCKET_ERROR) {
user->autologout=5;
return;
}
buffpos=0;
}
/* If colour isn't turned on then continue... */
if (!user->colour) {
buffpos--;
goto CONT;
}
if (*str=='^' && !bold_on) {
memcpy(buff+buffpos, colcode[1], strlen(colcode[1]));
buffpos+=strlen(colcode[1])-1;
bold_on=1;
}
else if (*str=='^' && bold_on) {
memcpy(buff+buffpos, colcode[0], strlen(colcode[0]));
buffpos+=strlen(colcode[0])-1;
bold_on=0;
}
}
else
*(buff+buffpos)=*str;
CONT:
++buffpos; ++str;
}
if (buffpos==OUT_BUFF_SIZE) {
if (WRITE_S(sock,buff,OUT_BUFF_SIZE)==SOCKET_ERROR) {
user->autologout=5;
return;
}
buffpos=0;
}
}
if (buffpos) {
if (WRITE_S(sock,buff,buffpos)==SOCKET_ERROR) {
user->autologout=5;
return;
}
}
/* Reset terminal at end of string */
if (user->colour) write_sock(sock,"\033[0m");
}
/*** Write to users of level 'level' and above. The function name is a bit of
a misnomer I guess. ***/
write_wiz(level,str,user)
int level;
char *str;
UR_OBJECT user;
{
UR_OBJECT u;
for(u=user_first;u!=NULL;u=u->next) {
if (u!=user && u->level>=level && !u->login && u->type!=CLONE_TYPE)
write_user(u,str);
}
}
/*** Write to all wizs in a particular room ***/
write_wiz_at_room(level,str,user,room)
int level;
char *str;
UR_OBJECT user;
RM_OBJECT room;
{
UR_OBJECT u;
for(u=user_first;u!=NULL;u=u->next) {
if (u!=user && u->level>=level && !u->login
&& u->type!=CLONE_TYPE
&& u->room==room
&& u->room
)
write_user(u,str);
}
}
/*** Subsid function to below but this one is used the most ***/
write_room(rm,str)
RM_OBJECT rm;
char *str;
{
write_room_except(rm,str,NULL);
}
/*** Write to everyone in room rm except for "user". If rm is NULL write
to all rooms. ***/
write_room_except(rm,str,user)
RM_OBJECT rm;
char *str;
UR_OBJECT user;
{
UR_OBJECT u;
char text2[ARR_SIZE];
for(u=user_first;u!=NULL;u=u->next) {
if (u->login
|| (u->room!=rm && rm!=NULL)
|| (u->ignall && !force_listen)
|| (u->ignshout && (com_num==SHOUT || com_num==SEMOTE))
|| u==user) continue;
if (u->type==CLONE_TYPE) {
if (u->clone_hear==CLONE_HEAR_NOTHING || u->owner->ignall) continue;
/* Ignore anything not in clones room, eg shouts, system messages
and semotes since the clones owner will hear them anyway. */
if (rm!=u->room || !u->room) continue;
if (u->clone_hear==CLONE_HEAR_SWEARS) {
if (!contains_swearing(str)) continue;
}
sprintf(text2,"~FT[ %s ]:~RS %s",u->room,str);
write_user(u->owner,text2);
}
else write_user(u,str);
}
}
/*** Write to everyone in room rm except for "user" and "user2", used for
promotion bit ***/
write_room_except2(rm,str,user,user2)
RM_OBJECT rm;
char *str;
UR_OBJECT user, user2;
{
UR_OBJECT u;
char text2[ARR_SIZE];
for(u=user_first;u!=NULL;u=u->next) {
if (u->login
|| (u->room!=rm && rm!=NULL)
|| (u->ignall && !force_listen)
|| (u->ignshout && (com_num==SHOUT || com_num==SEMOTE))
|| u==user
|| u==user2) continue;
if (u->type==CLONE_TYPE) {
if (u->clone_hear==CLONE_HEAR_NOTHING || u->owner->ignall) continue;
/* Ignore anything not in clones room, eg shouts, system messages
and semotes since the clones owner will hear them anyway. */
if (rm!=u->room || !u->room) continue;
if (u->clone_hear==CLONE_HEAR_SWEARS) {
if (!contains_swearing(str)) continue;
}
sprintf(text2,"~FT[ %s ]:~RS %s",u->room,str);
write_user(u->owner,text2);
}
else write_user(u,str);
}
}
/*** Write text figlets & intros ***/
write_text_figlet(fig_text,name,font)
char *fig_text;
char *name;
char *font;
{
UR_OBJECT u;
char fig1[ARR_SIZE];
char fig2[ARR_SIZE];
if (strcmp(font,"standard.flf"))
sprintf(fig1,"~FRBroadcast figlet from ~OL%s~RS~FR (%s font): ~RS%s\n",name,font,fig_text);
else
sprintf(fig1,"~FRBroadcast figlet from ~OL%s~RS~FR: ~RS%s\n",name,fig_text);
sprintf(fig2,"~FRBroadcast figlet from ~OL%s~RS~FR:\n",name);
record(room_first,fig1);
for(u=user_first;u!=NULL;u=u->next) {
if (u->login
|| (u->ignall && !force_listen)
|| u->type==CLONE_TYPE) continue;
if (u->figlet)
write_user(u,fig1);
else
write_user(u,fig2);
}
}
/*** Write figlet lines to users that want them ***/
write_broadcast_figlet(fig_text)
char *fig_text;
{
UR_OBJECT u;
for(u=user_first;u!=NULL;u=u->next) {
if (u->login
|| (u->ignall && !force_listen)
|| u->type==CLONE_TYPE
|| u->figlet) continue;
write_user(u,fig_text);
}
}
/*** Write a string to system log ***/
write_syslog(str,write_time)
char *str;
int write_time;
{
FILE *fp;
if (!system_logging || !(fp=fopen(SYSLOG,"a"))) return;
if (!write_time) fputs(str,fp);
else fprintf(fp,"%02d/%02d %02d:%02d:%02d: %s",tmday,tmonth+1,thour,tmin,tsec,str);
fclose(fp);
}
/******** LOGIN/LOGOUT FUNCTIONS ********/
/*** Login function - all mostly inline code ***/
login(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
UR_OBJECT u;
UR_OBJECT get_user_by_full(char *);
int i;
char name[ARR_SIZE],passwd[ARR_SIZE];
char tmp[ARR_SIZE];
name[0]='\0'; passwd[0]='\0';
switch(user->login) {
case 1:
sscanf(inpstr,"%s",name);
if(name[0]<33) {
write_user(user,"\nEnter your name: "); return;
}
name[0]=toupper(name[0]);
if (!strcmp(name,"Quit")) {
write_user(user,"\n\n*** Abandoning login attempt ***\n\n");
disconnect_user(user); return;
}
if (!strcmp(name,"Who")) {
who(user,0);
write_user(user,"\nEnter your name: ");
return;
}
if (!strcmp(name,"Version")) {
sprintf(text,"\nCrypt Talker version %s (Based on Nuts v3.2.1)\n\nEnter your name: ",VERSION);
write_user(user,text); return;
}
if (strlen(name)<MIN_USER_NAME_LEN) {
write_user(user,"\nName too short.\n\n");
attempts(user); return;
}
if (strlen(name)>USER_NAME_LEN) {
write_user(user,"\nName too long.\n\n");
attempts(user); return;
}
/* see if only letters in login */
for (i=0;i<strlen(name);++i) {
if (!isalpha(name[i])) {
write_user(user,"\nOnly letters are allowed in a name.\n\n");
attempts(user); return;
}
}
if (!allow_caps_in_name) strtolower(name);
name[0]=toupper(name[0]);
/* Prelogins get shown to arches & above */
sprintf(text,"~OL[PRE-LOGIN]~RS %s ~FT(%s)\n",name,user->site);
write_wiz(SHOW_PRE_LEVEL,text,NULL);
if (user_banned(name)) {
write_user(user,"\nYou are banned from this talker.\n\n");
disconnect_user(user);
sprintf(text,"Attempted login by banned user %s.\n",name);
write_syslog(text,1);
sprintf(text,"~OLSYSTEM:~RS Login denied for banned user %s\n",name);
write_room(NULL,text);
return;
}
/* Fix to stop users throwing off newbies by logging in under their name */
u=get_user_by_full(name);
if (u && u->level==NEW) {
write_user(user,"\nThat name is currently in use. Choose another.\n\n");
attempts(user);
return;
}
strcpy(user->name,name);
/* If user has hung on another login clear that session */
for(u=user_first;u!=NULL;u=u->next) {
if (u->login && u!=user && !strcmp(u->name,user->name)) {
disconnect_user(u); break;
}
}
if (!load_user_details(user)) {
if (user->port==port[1]) {
write_user(user,"\nSorry, new logins cannot be created on this port.\n\n");
disconnect_user(user);
return;
}
if (minlogin_level>-1) {
write_user(user,"\nSorry, new logins cannot be created at this time.\n\n");
sprintf(text,"~OLSYSTEM:~RS %s denied login due to current minlogin level ~FR(%s)\n",user->name,level_name[minlogin_level]);
write_room(NULL,text);
disconnect_user(user);
return;
}
if (partial_site_banned(user->site)) {
sprintf(text,"~OLSYSTEM:~RS %s denied login due to partial site ban\n",user->name);
write_room(NULL,text);
sprintf(text,"%s/%s",DATAFILES,PARTIALBAN_MOTD);
more(user,user->socket,text);
disconnect_user(user);
return;
}
if (!save_newbies)
write_user(user,"New user...Ask for promotion to USER if you want your details saved\n");
else
write_user(user,"New user...Welcome!\n");
}
else {
if (user->port==port[1] && user->level<wizport_level) {
sprintf(text,"\nSorry, only users of level %s or %s and above can log in on this port.\n\n",new_levels[1][wizport_level], new_levels[2][wizport_level]);
write_user(user,text);
disconnect_user(user);
return;
}
if (user->level<minlogin_level) {
sprintf(text,"\nSorry, the talker is only accepting logins from users of level %s or %s at the moment.\n\n",new_levels[1][wizport_level], new_levels[2][wizport_level]);
write_user(user,text);
sprintf(text,"~OLSYSTEM:~RS %s denied login due to current minlogin level ~FR(%s)\n",user->name,level_name[minlogin_level]);
write_room(NULL,text);
disconnect_user(user);
return;
}
}
if (user->level==NEW)
write_user(user,"Enter a password for yourself: ");
else
write_user(user,"Enter your password: ");
echo_off(user);
user->login=2;
return;
/* Deal with password */
case 2:
sscanf(inpstr,"%s",passwd);
if (strlen(passwd)<3) {
write_user(user,"\n\nPassword too short.\n\n");
attempts(user); return;
}
if (strlen(passwd)>PASS_LEN) {
write_user(user,"\n\nPassword too long.\n\n");
attempts(user); return;
}
/* if new user... */
if (!user->pass[0]) {
strcpy(user->pass,(char *)crypt(passwd,"NU"));
write_user(user,"\nPlease confirm password: ");
user->login=3;
}
else { /* Account user - final stage */
if (!strcmp(user->pass,(char *)crypt(passwd,"NU"))) {
echo_on(user);
connect_user(user);
return;
}
write_user(user,"\n\nIncorrect login.\n\n");
attempts(user);
}
return;
/* Confirm password for newusers... */
case 3:
sscanf(inpstr,"%s",passwd);
if (strcmp(user->pass,(char*)crypt(passwd,"NU"))) {
write_user(user,"\n\nPasswords do not match.\n\n");
attempts(user);
return;
}
echo_on(user);
sprintf(text,"\nEnter your sex - (M)ale, (F)emale, (N)either: ");
write_user(user,text);
user->login=4;
return;
/* Set gender */
case 4:
sscanf(inpstr,"%s",tmp);
tmp[0]=tolower(tmp[0]);
switch (tmp[0]) {
case 'm':
case 'M': user->sex=1; break;
case 'F':
case 'f': user->sex=2; break;
case 'N':
case 'n': user->sex=0; break;
default:
sprintf(text,"Error - Enter M, F or N\nEnter your sex - (M)ale, (F)emale, (N)either: ");
write_user(user,text);
return;
}
user->login=5;
sprintf(text,"%s/%s",TEXTFILES,NEWBIE_MOTD);
more(user,user->socket,text);
return;
/* Final stage for newusers */
case 5:
echo_on(user);
strcpy(user->desc,"- a new user");
strcpy(user->in_phrase,"enters");
strcpy(user->out_phrase,"goes");
strcpy(user->login_phrase,"enters the talker");
strcpy(user->logout_phrase,"leaves the talker");
strcpy(user->email,"Unknown");
strcpy(user->www,"None");
strcpy(user->rank,level_name[0]);
user->last_site[0]='\0';
user->pre_desc[0]='\0';
user->level=0;
user->prompt=prompt_def;
user->charmode_echo=0;
user->muzzled=0;
user->total_login=0;
save_user_details(user,1);
sprintf(text,"New user ~FG\"%s\"~RS created.\n",user->name);
write_syslog(text,1);
connect_user(user);
}
}
/*** Count up attempts made by user to login ***/
attempts(user)
UR_OBJECT user;
{
user->attempts++;
if (user->attempts==3) {
write_user(user,"\nMaximum attempts reached.\n\n");
disconnect_user(user); return;
}
user->login=1;
user->pass[0]='\0';
write_user(user,"Enter your name: ");
echo_on(user);
}
/*** Load the users stats ***/
load_user_details(user)
UR_OBJECT user;
{
FILE *fp;
char line[81],filename[80];
int temp1,temp2,temp3;
sprintf(filename,"%s/%s.D",USERFILES,user->name);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%s",user->pass); /* password */
fscanf(fp,"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",&temp1,&temp2,&user->last_login_len,&temp3,&user->level,&user->prompt,&user->muzzled,&user->charmode_echo,&user->command_mode,&user->colour,&user->sex,&user->termtype, &user->xterm, &user->figlet
, &user->vis_email, &user->examined);
user->last_login=(time_t)temp1;
user->total_login=(time_t)temp2;
user->read_mail=(time_t)temp3;
fscanf(fp,"%s\n",user->last_site);
/* Need to do the rest like this 'cos they may be more than 1 word each */
fgets(line,80,fp);
line[strlen(line)-1]=0;
strcpy(user->pre_desc,line);
if (!strcmp(user->pre_desc,"none"))
user->pre_desc[0]='\0';
fgets(line,80,fp);
line[strlen(line)-1]=0;
strcpy(user->desc,line);
fgets(line,PHRASE_LEN+2,fp);
line[strlen(line)-1]=0;
strcpy(user->in_phrase,line);
fgets(line,PHRASE_LEN+2,fp);
line[strlen(line)-1]=0;
strcpy(user->out_phrase,line);
fgets(line,LOG_PHRASE_LEN+2,fp);
line[strlen(line)-1]=0;
strcpy(user->login_phrase,line);
fgets(line,LOG_PHRASE_LEN+2,fp);
line[strlen(line)-1]=0;
strcpy(user->logout_phrase,line);
fscanf(fp,"%s\n",user->email);
fscanf(fp,"%s\n",user->www);
fgets(line,38,fp);
line[strlen(line)-1]=0;
strcpy(user->rank,line);
fclose(fp);
return 1;
}
/*** Save a users stats ***/
save_user_details(user,save_current)
UR_OBJECT user;
int save_current;
{
FILE *fp;
char filename[80];
char local[256];
if (!save_newbies) {
if (user->level==NEW && !(user->login)) {
sprintf(local,"Newbie %s ~FRnot~RS saved\n", user->name);
write_syslog(local,1);
sprintf(local,"Your details have not been saved! Ask for promotion to USER next time!");
write_user(user,local);
return 0;
}
if (user->level==NEW && user->login)
return 0;
}
sprintf(filename,"%s/%s.D",USERFILES,user->name);
if (!(fp=fopen(filename,"w"))) {
sprintf(local,"%s: failed to save your details.\n",syserror);
write_user(user,local);
sprintf(local,"SAVE_USER_STATS: Failed to save %s's details.\n",user->name);
write_syslog(local,1);
return 0;
}
/* Insurance against any odd values so we don't crash. Shouldn't be needed if
there are no bugs but it does no harm to have. */
if (user->level<0) user->level=0;
if (user->level>UBERGOTH) user->level=UBERGOTH;
if (user->muzzled<0) user->muzzled=0;
if (user->muzzled>GOD) user->muzzled=GOD;
fprintf(fp,"%s\n",user->pass);
if (save_current)
fprintf(fp,"%d %d %d ",(int)time(0),(int)user->total_login,(int)(time(0)-user->last_login));
else fprintf(fp,"%d %d %d ",(int)user->last_login,(int)user->total_login,user->last_login_len);
fprintf(fp,"%d %d %d %d %d %d %d %d %d %d %d %d %d\n",(int)user->read_mail,user->level,user->prompt,user->muzzled,user->charmode_echo,user->command_mode,user->colour,user->sex,user->termtype,user->xterm,user->figlet,user->vis_email,user->examined);
if (save_current)
fprintf(fp,"%s\n",user->site);
else
fprintf(fp,"%s\n",user->last_site);
if (user->pre_desc[0])
fprintf(fp,"%s\n",user->pre_desc);
else
fprintf(fp,"none\n",user->pre_desc);
fprintf(fp,"%s\n",user->desc);
fprintf(fp,"%s\n",user->in_phrase);
fprintf(fp,"%s\n",user->out_phrase);
fprintf(fp,"%s\n",user->login_phrase);
fprintf(fp,"%s\n",user->logout_phrase);
fprintf(fp,"%s\n",user->email);
fprintf(fp,"%s\n",user->www);
fprintf(fp,"%s\n\n",user->rank);
fclose(fp);
return 1;
}
/*** Connect the user to the talker proper ***/
connect_user(user)
UR_OBJECT user;
{
UR_OBJECT u,u2;
char temp[30];
/* Get the ip name here so lookups are only done for users that actually log
in */
get_where_text(user,user->site);
if (!user->ip_name[0]) get_ip_text(user, user->ip_num);
/* Update stats */
total_logins++;
/* See if user already connected */
for(u=user_first;u!=NULL;u=u->next) {
if (user!=u && user->type!=CLONE_TYPE && !strcmp(user->name,u->name)) {
write_user(user,"\n\nYou are already connected - switching to old session...\n");
sprintf(text,"%s swapped sessions (%s)\n",user->name,user->site);
write_user(u,"\n\nAnother login in your name - Switching sessions.\n");
write_syslog(text,1);
CLOSE(u->socket);
u->socket=user->socket;
/* Reset the sockets on any clones */
for(u2=user_first;u2!=NULL;u2=u2->next)
if (u2->type==CLONE_TYPE && !strcmp(u->name,u2->name))
u2->socket=u->socket;
sprintf(text,"~OL[+]~RS %s %s ~FG(Switched sessions)\n",user->name,user->desc);
write_room(NULL,text);
record(room_first,text); /* Record logins to rev buffer */
num_of_logins--;
strcpy(u->site,user->site);
strcpy(u->ip_name,user->ip_name);
u->site_port=user->site_port;
u->window_x=user->window_x;
u->window_y=user->window_y;
destruct_user(user);
destructed=1;
look(u);
prompt(u);
return;
}
}
if (user->muzzled)
sprintf(text,"~OL[+]~RS %s %s ~FR(Muzzled)\n",user->name,user->desc);
else
sprintf(text,"~OL[+]~RS %s %s\n",user->name,user->desc);
write_room(NULL,text);
record(room_first,text); /* Record logins to rev buffer */
write_user(user,"\n");
more(user,user->socket,"%s/%s",TEXTFILES,MOTD2); /* send post-login message */
sprintf(text,"\nWelcome ~FY%s~RS... You are visitor number ~FR%d~RS today.\nYour level is: ~FG%s~RS... Window size: ~FT%d %d\n",user->name,total_logins,new_levels[user->sex][user->level],user->window_x,user->window_y);
write_user(user,text);
if (user->last_site[0]) {
sprintf(temp,"%s",ctime(&user->last_login));
temp[strlen(temp)-1]=0;
sprintf(text,"\n~FBYou were last logged in on %s from %s\n",temp,user->last_site);
write_user(user,text);
}
user->room=room_first;
user->last_login=time(0); /* set to now */
look(user);
if (user->pre_desc[0])
sprintf(text,"%s~RS %s %s\n", user->pre_desc, user->name, user->login_phrase);
else
sprintf(text,"%s %s\n",user->name, user->login_phrase);
write_room(user->room, text);
record(user->room,text);
if (has_unread_mail(user)) write_user(user,"\07~OL~LI** YOU HAVE ~FGNEW~RS~LI~OL MAIL **\n");
prompt(user);
sprintf(text,"%s logged in on port %d from %s\n",user->name,user->port,user->site);
write_syslog(text,1);
num_of_users++;
if (num_of_users>peak_logins) peak_logins++;
num_of_logins--;
user->login=0;
if (web_page_on)
web_page();
}
/*** Disconnect user from talker ***/
disconnect_user(user)
UR_OBJECT user;
{
RM_OBJECT rm;
char local[256];
if (!user)
return;
if (user->login) {
CLOSE(user->socket);
destruct_user(user);
destructed=1;
num_of_logins--;
return;
}
rm=user->room;
/* Destroy clones before logout */
destroy_user_clones(user);
save_user_details(user,1);
write_user(user,"\nYou are removed from this reality... ~LIBut come back soon!\n\n");
/* No logout phrase for auto logouts */
if (user->logout_phrase[0] && !(user->autologout)) {
if (user->pre_desc[0])
sprintf(text,"%s~RS %s %s\n", user->pre_desc, user->name, user->logout_phrase);
else
sprintf(text,"%s %s\n",user->name,user->logout_phrase);
write_room_except(user->room,text,user);
record(user->room,text);
}
if (user->malloc_start!=NULL) free(user->malloc_start);
num_of_users--;
if (user->home)
destruct_room(user);
reset_access(rm);
CLOSE(user->socket);
switch (user->autologout) {
case 1:
sprintf(local,"%s logged out (Automatic).\n",user->name);
write_syslog(local,1);
sprintf(local,"~OL[-]~RS %s %s~RS ~FR(Automatic Logout)\n",user->name,user->desc);
break;
case 2:
sprintf(local,"%s logged out (Killed).\n",user->name);
write_syslog(local,1);
sprintf(local,"~OL[-]~RS %s %s~RS ~FR(Killed!)\n",user->name,user->desc);
break;
case 3:
sprintf(local,"%s logged out (Tongued!).\n",user->name);
write_syslog(local,1);
sprintf(local,"~OL[-]~RS %s %s~RS ~FR(Tongued!)\n",user->name,user->desc);
break;
case 4:
sprintf(local,"%s logged out ~FR(Suicide!)~RS.\n",user->name);
write_syslog(local,1);
sprintf(local,"~OL[-]~RS %s %s~RS ~FR(Suicide!!!)\n",user->name,user->desc);
break;
case 5:
sprintf(local,"%s logged out (Broken socket).\n",user->name);
write_syslog(local,1);
sprintf(local,"~OL[-]~RS %s %s~RS ~FR(Broken socket)\n",user->name,user->desc);
break;
case 0:
default:
sprintf(local,"%s logged out.\n",user->name);
write_syslog(local,1);
sprintf(local,"~OL[-]~RS %s %s\n",user->name,user->desc);
break;
}
write_room_except(NULL,local,user);
record(room_first,local); /* Record logouts to rev buffer */
destruct_user(user);
destructed=1;
if (web_page_on)
web_page();
}
/** THIS IS WHERE THE WEB_PAGE CODE USED TO LIVE **/
web_page()
{
UR_OBJECT u;
int total=0,mins;
FILE *fp;
char local[512];
fp=fopen(WEB_PAGE_FILE,"w");
if (!fp) {
write_wiz(GOD,"~OL~FRSYSTEM: ~RSCouldn't open web page file!!\n",NULL);
write_syslog("~FRSYSTEM:~RS Couldn't open web page file!!\n",1);
return;
}
/* Set up html stuff..... */
fprintf(fp,"<html><head><title>Users on the Crypt</title>\n<meta http-equiv=refresh content=30></head>\n<body background=b_silk.jpg TEXT=F0F0F0 VLINK=ADFF2F ALINK=F0A0A0 link=77EE22 bgcolor=000011>\n");
fprintf(fp,"<!--- Automatically generated web page... by Mish and Werewolf 1996 -->");
fprintf(fp,"\n<center><img src=onlineusers.gif height=39 width=320 alt=\"Online Users\"><p>\n\n<p><h5>Current users as of %s, %d %s, %02d:%02d </h5><p></center>\n\n",day[twday],tmday,month[tmonth],thour,tmin);
fprintf(fp,"<table align=center border=1 width=100%><tr align=center valign=top>\n<th width=20%>Name</th><th width=16%>Level</th><th width=12%>Time On</th><th width=52%>Where</th></tr>\n\n");
for(u=user_first;u!=NULL;u=u->next) {
if (u->type==CLONE_TYPE || u->login) continue;
mins=(int)(time(0) - u->last_login)/60;
++total;
sprintf(local,"<tr><td>%s</td><td align=left>%s</td><td align=right>%d mins</td><td align=center>%s</td></tr>\n",u->name,new_levels[u->sex][u->level],mins,u->ip_name);
fprintf(fp,local);
}
sprintf(local,"</table><p>There are a total of <b>%d</b> users.<p><p>",total);
fprintf(fp,local);
fprintf(fp,"<center><img src=bloodbar.gif><p>\n<a href=index.html>Crypt Homepage</a></body></html>\n");
fclose(fp);
/* Make the file readable to browsers... not needed on many systems... */
#ifndef WIN_NT
chmod(WEB_PAGE_FILE, 0755);
#endif
}
/*** Tell telnet not to echo characters - for password entry ***/
echo_off(user)
UR_OBJECT user;
{
char seq[4];
if (password_echo) return;
sprintf(seq,"%c%c%c",255,251,1);
write_user(user,seq);
}
/*** Tell telnet to echo characters ***/
echo_on(user)
UR_OBJECT user;
{
char seq[4];
if (password_echo) return;
sprintf(seq,"%c%c%c",255,252,1);
write_user(user,seq);
}
telnet_init(user)
UR_OBJECT user;
{
sprintf(text,"%c%c%c%c%c%c",255,253,31,255,253,24);
write_user(user,text);
}
telnet_option(user,inpstr,len)
UR_OBJECT user;
char *inpstr;
int len;
{
char *ptr;
int i=0;
while (i<len) {
if (*(inpstr+i)==(char)255) {
ptr=inpstr+i+1;
switch (*ptr) {
case (char)251: /* WILL */
switch (*(ptr+1)) {
case 31:
/* WILL NAWS */
break;
case 24:
/* WILL TTYPE
sprintf(text,"%c%c%c%c%c%c",255,250,24,1,255,240);
WRITE_S(user->socket,text,6); */
break;
}
break;
case (char)252: /* WONT */
switch (*(ptr+1)) {
case 31:
break;
/* printf("Wont NAWS");*/
}
break;
case (char)250:
switch (*(ptr+1)) {
case 31: {
int x,y;
if (*(ptr+2)) x=((unsigned char)*(ptr+2) * 256)+(unsigned char)*(ptr+3); else x=(unsigned char)*(ptr+3);
if (*(ptr+4)) y=((unsigned char)*(ptr+4) * 256)+(unsigned char)*(ptr+5); else y=(unsigned char)*(ptr+5);
set_winsize(user,x,y);
}
break;
case 24:
/* Get term type */
{
int z=0;
while (*(ptr+z+3)!=(char)255 && *(ptr+z+3)) {
text[z]=*(ptr+z+3);
z++;
}
text[z]=0;
}
/* printf("Got terminal type: %s\n",text); */
}
}
}
i++;
}
}
/************ MISCELLANEOUS FUNCTIONS *************/
/*** Miscellaneous operations from user that are not speech or commands ***/
misc_ops(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
switch(user->misc_op) {
case 1:
if (toupper(inpstr[0])=='Y') talker_shutdown(user,"by user\n",0);
user->misc_op=0; prompt(user);
return 1;
case 2:
if (toupper(inpstr[0])=='E'
|| more(user,user->socket,user->page_file)!=1) {
user->misc_op=0; user->filepos=0; user->page_file[0]='\0';
prompt(user);
}
return 1;
case 3: /* writing on board */
case 4: /* Writing mail */
case 5: /* doing profile */
case 8: /* Writing room desc */
case 9: /* Adding to A where database file */
case 10: /* Adding to B where database file */
case 11: /* Adding to C where database file */
editor(user,inpstr); return 1;
case 6: /* Suicide */
if (toupper(inpstr[0])=='Y') delete_user(user,1);
else {
user->misc_op=0; prompt(user);
}
return 1;
case 7:
if (toupper(inpstr[0])=='Y') talker_shutdown(user,"by user\n",1);
user->misc_op=0; prompt(user);
return 1;
}
return 0;
}
/*** The editor used for writing profiles, mail and messages on the boards ***/
editor(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
int cnt,line;
char *edprompt="\n~FGSave~RS, ~FYredo~RS or ~FRabort~RS (s/r/a): ";
char *ptr;
if (user->edit_op) {
switch(toupper(*inpstr)) {
case 'S':
switch(user->misc_op) {
case 3: write_board(user,NULL,1); break;
case 4: smail(user,NULL,1); break;
case 5: enter_profile(user,1); break;
case 8: edit_room(user,1); break;
case 9: add_where(user,1); break;
case 10: add_where(user,1); break;
case 11: add_where(user,1); break;
}
editor_done(user);
return;
case 'R':
user->edit_op=0;
user->edit_line=1;
user->charcnt=0;
user->malloc_end=user->malloc_start;
*user->malloc_start='\0';
sprintf(text,"\nRedo message...\n\n~FY%d>~RS",user->edit_line);
write_user(user,text);
return;
case 'A':
write_user(user,"\nMessage aborted.\n");
editor_done(user);
return;
default:
write_user(user,edprompt);
return;
}
}
if (user->malloc_start==NULL) {
if ((user->malloc_start=(char *)malloc(MAX_LINES*81))==NULL) {
sprintf(text,"%s: failed to allocate buffer memory.\n",syserror);
write_user(user,text);
write_syslog("ERROR: Failed to allocate memory in editor().\n",0);
user->misc_op=0;
prompt(user);
return;
}
user->ignall_store=user->ignall;
user->ignall=1; /* Don't want chat mucking up the edit screen */
user->edit_line=1;
user->charcnt=0;
user->malloc_end=user->malloc_start;
*user->malloc_start='\0';
sprintf(text,"~FTMaximum of %d lines, end with a '.' on a line by itself.\n\n~FY1>~RS",MAX_LINES);
write_user(user,text);
return;
}
/* Check for empty line */
if (!word_count) {
if (!user->charcnt) {
sprintf(text,"~FY%d>~RS",user->edit_line);
write_user(user,text);
return;
}
*user->malloc_end++='\n';
if (user->edit_line==MAX_LINES) goto END;
sprintf(text,"~FY%d>~RS",++user->edit_line);
write_user(user,text);
user->charcnt=0;
return;
}
/* If nothing carried over and a dot is entered then end */
if (!user->charcnt && !strcmp(inpstr,".")) goto END;
line=user->edit_line;
cnt=user->charcnt;
/* loop through input and store in allocated memory */
while(*inpstr) {
*user->malloc_end++=*inpstr++;
if (++cnt==80) { user->edit_line++; cnt=0; }
if (user->edit_line>MAX_LINES
|| user->malloc_end - user->malloc_start>=MAX_LINES*81) goto END;
}
if (line!=user->edit_line) {
ptr=(char *)(user->malloc_end-cnt);
*user->malloc_end='\0';
sprintf(text,"~FY%d>~RS%s",user->edit_line,ptr);
write_user(user,text);
user->charcnt=cnt;
return;
}
else {
*user->malloc_end++='\n';
user->charcnt=0;
}
if (user->edit_line!=MAX_LINES) {
sprintf(text,"~FY%d>~RS",++user->edit_line);
write_user(user,text);
return;
}
/* User has finished his message , prompt for what to do now */
END:
*user->malloc_end='\0';
if (*user->malloc_start) {
write_user(user,edprompt);
user->edit_op=1; return;
}
write_user(user,"\nNo text.\n");
editor_done(user);
}
editor_done(user)
UR_OBJECT user;
{
user->misc_op=0;
user->edit_op=0;
user->edit_line=0;
free(user->malloc_start);
user->malloc_start=NULL;
user->malloc_end=NULL;
user->ignall=user->ignall_store;
prompt(user);
}
/*** Record speech and emotes in the room. It stores 2 lines of speech
per room. ***/
record(rm,str)
RM_OBJECT rm;
char *str;
{
if (!rm) return;
strncpy(rm->conv_line[rm->cln],str,159);
rm->conv_line[rm->cln][159]='\n';
rm->conv_line[rm->cln][160]='\0';
rm->cln=(rm->cln+1)%CONV_LINES;
}
/*** Records tells and pemotes sent to the user. ***/
record_tell(user,str)
UR_OBJECT user;
char *str;
{
if (!user) return;
strncpy(user->revbuff[user->revline],str,REVIEW_LEN);
user->revbuff[user->revline][REVIEW_LEN]='\n';
user->revbuff[user->revline][REVIEW_LEN+1]='\0';
user->revline=(user->revline+1)%REVTELL_LINES;
}
/*** Set room access back to public if not enough users in room ***/
reset_access(rm)
RM_OBJECT rm;
{
UR_OBJECT u;
int cnt;
if (rm==NULL || rm->access!=PRIVATE)
return;
cnt=0;
for(u=user_first;u!=NULL;u=u->next) if (u->room==rm) ++cnt;
if (cnt<min_private_users) {
write_room(rm,"Room access returned to ~FGPUBLIC.\n");
rm->access=PUBLIC;
/* Reset any invites into the room & clear review buffer */
for(u=user_first;u!=NULL;u=u->next) {
if (u->invite_room==rm) u->invite_room=NULL;
}
clear_rbuff(rm);
}
}
/*** Exit cos of error during bootup ***/
boot_exit(code)
int code;
{
#ifdef WIN_NT
/* Shutdown winsock before exit */
WSACleanup();
#endif
switch(code) {
case 1:
write_syslog("BOOT FAILURE: Error while parsing configuration file.\n",0);
exit(1);
case 2:
write_syslog("BOOT FAILURE: Can't open main port listen socket.\n",0);
perror("NUTS: Can't open main listen socket");
exit(2);
case 3:
write_syslog("BOOT FAILURE: Can't open wiz port listen socket.\n",0);
perror("NUTS: Can't open wiz listen socket");
exit(3);
case 4:
write_syslog("BOOT FAILURE: Couldn't set up Winsock.\n",0);
perror("Crypt: Can't set up Winsock.\n");
exit(4);
case 5:
write_syslog("BOOT FAILURE: Can't bind to main port.\n",0);
perror("NUTS: Can't bind to main port");
exit(5);
case 6:
write_syslog("BOOT FAILURE: Can't bind to wiz port.\n",0);
perror("NUTS: Can't bind to wiz port");
exit(6);
case 7:
write_syslog("BOOT FAILURE: Couldn't start timer thread.\n",0);
perror("Crypt: Couldn't start timer thread");
exit(7);
case 8:
write_syslog("BOOT FAILURE: Listen error on main port.\n",0);
perror("NUTS: Listen error on main port");
exit(8);
case 9:
write_syslog("BOOT FAILURE: Listen error on wiz port.\n",0);
perror("NUTS: Listen error on wiz port");
exit(9);
case 11:
write_syslog("BOOT FAILURE: Failed to fork.\n",0);
perror("NUTS: Failed to fork");
exit(11);
}
}
/*** User prompt ***/
prompt(user)
UR_OBJECT user;
{
int hr,min;
if (no_prompt || !user) return;
if (!user->prompt || user->misc_op) return;
hr=(int)(time(0)-user->last_login)/3600;
min=((int)(time(0)-user->last_login)%3600)/60;
/* Different prompt types */
switch(user->prompt) {
case 1:
sprintf(text,"~FM<%02d:%02d, %02d:%02d, ~FY%s~FM",thour,tmin,hr,min,user->name);
break;
case 2:
sprintf(text,"~FM<%02d:%02d, ~FY%s~FM",thour,tmin,user->name);
break;
case 3:
if (user->old_tell[0])
sprintf(text,"~FM<%02d:%02d, ~FY%s~FM",thour,tmin,user->old_tell);
else
sprintf(text,"~FM<%02d:%02d, ~FYNo-one~FM",thour,tmin);
}
if (!user->vis)
strcat(text,", ~FB(Invisible)~FM");
if (user->muzzled)
strcat(text,", ~FR(Muzzled)~FM");
if (user->command_mode && !user->misc_op)
strcat(text,", EW-Too mode>\n");
else
strcat(text,">\n");
write_user(user,text);
}
/*** Page a file out to user. Colour commands in files will only work if the
user!=NULL since if NULL we dont know if his terminal can support colour
or not.
Return value 0=cannot find file, 1= found file, 2=found and finished ***/
more(user,sock,filename)
UR_OBJECT user;
int sock;
char *filename;
{
int i,buffpos,num_chars,lines,retval,len;
char buff[OUT_BUFF_SIZE],*str,*fname;
FILE *fp;
int bold_on=0,is_mail=0,is_news=0;
int page_y=23,page_x=80;
if (!(fp=fopen(filename,"r"))) {
if (user!=NULL) user->filepos=0;
return 0;
}
if (user) {
page_y=user->window_y-1;
page_x=user->window_x;
}
/* The /r method of saving times into board and mail files doesn't work
in windows so this check is used instead */
if (strlen(filename)>2) {
fname=filename+strlen(filename)-2;
if (!strncmp(fname,".B",2))
is_news=1;
if (!strncmp(fname,".M",2))
is_mail=1;
}
/* jump to reading posn in file */
if (user!=NULL) {
fseek(fp,user->filepos,0);
if (!user->filepos) /* If first page then reduce lines by two to keep header */
page_y=page_y-2;
}
if (page_y<1) page_y=1;
text[0]='\0';
buffpos=0;
num_chars=0;
retval=1;
lines=0;
fgets(text,sizeof(text)-1,fp);
/* Go through file */
while(!feof(fp) && (lines<page_y || user==NULL)) {
/* Check for board files... */
if (is_news) {
if (!strncmp(text,"PT: ",4)) {
#ifdef WIN_NT
num_chars+=strlen(text)+1;
#else
num_chars+=strlen(text);
#endif
fgets(text,sizeof(text)-1,fp);
continue;
}
}
/* Mail files always start with timestamp so ignore it */
if (is_mail && user->filepos==0) {
is_mail=0;
#ifdef WIN_NT
num_chars+=strlen(text)+1;
#else
num_chars+=strlen(text);
#endif
fgets(text,sizeof(text)-1,fp);
continue;
}
str=text;
/* Process line from file */
while(*str) {
if (*str=='\n') {
if (buffpos>OUT_BUFF_SIZE-6) {
WRITE_S(sock,buff,buffpos); buffpos=0;
}
/* Reset terminal before every newline */
if (user!=NULL && user->colour) {
memcpy(buff+buffpos,"\033[0m",4); buffpos+=4;
}
*(buff+buffpos)='\n'; *(buff+buffpos+1)='\r';
buffpos+=2; ++str;
}
else {
/* Process colour commands in the file */
if (*str=='~') {
if (buffpos>OUT_BUFF_SIZE-6) {
WRITE_S(sock,buff,buffpos); buffpos=0;
}
++str;
for(i=0;i<NUM_COLS;++i) {
if (!strncmp(str,colcom[i],2)) {
if (user!=NULL && user->colour) {
memcpy(buffpos+buff,colcode[i],strlen(colcode[i]));
buffpos+=strlen(colcode[i])-1;
}
else buffpos--;
++str;
goto CONT;
}
}
--str; *(buff+buffpos)=*str;
}
else
/* Mish - Check for 'old style' bold text */
if (*str=='^') {
if (buffpos>OUT_BUFF_SIZE-6) {
WRITE_S(sock,buff,buffpos); buffpos=0;
}
/* If colour isn't turned on then continue... */
if (!user->colour) {
buffpos--;
goto CONT;
}
if (*str=='^' && !bold_on) {
memcpy(buff+buffpos, colcode[1], strlen(colcode[1]));
buffpos+=strlen(colcode[1])-1;
bold_on=1;
}
else if (*str=='^' && bold_on) {
memcpy(buff+buffpos, colcode[0], strlen(colcode[0]));
buffpos+=strlen(colcode[0])-1;
bold_on=0;
}
}
else *(buff+buffpos)=*str;
CONT:
++buffpos; ++str;
}
if (buffpos==OUT_BUFF_SIZE) {
WRITE_S(sock,buff,OUT_BUFF_SIZE); buffpos=0;
}
}
/* Windows reports length-1 because of /n/r newline format instead of /n */
len=strlen(text);
#ifdef WIN_NT
num_chars+=len+1;
#else
num_chars+=len;
#endif
lines+=len/page_x;
len=len-(len/page_x);
if (len>0) lines++;
text[0]=0;
fgets(text,sizeof(text)-1,fp);
}
if (buffpos && sock!=-1) WRITE_S(sock,buff,buffpos);
/* if user is logging in don't page it */
if (user==NULL) { fclose(fp); return 2; };
if (feof(fp)) {
user->filepos=0; no_prompt=0; retval=2;
}
else {
/* store file position and file name */
user->filepos+=num_chars;
strcpy(user->page_file,filename);
write_user(user,"~FB*** ~FTPRESS ~FG<RETURN>~FT FOR MORE, ~FRE<RETURN>~FT TO EXIT ~FB***");
no_prompt=1;
}
fclose(fp);
return retval;
}
/*** Set global vars. hours,minutes,seconds,date,day,month ***/
set_date_time()
{
struct tm *tm_struct; /* structure is defined in time.h */
time_t tm_num;
/* Set up the structure */
time(&tm_num);
tm_struct=localtime(&tm_num);
/* Get the values */
tday=tm_struct->tm_yday;
tmonth=tm_struct->tm_mon;
tmday=tm_struct->tm_mday;
twday=tm_struct->tm_wday;
thour=tm_struct->tm_hour;
tmin=tm_struct->tm_min;
tsec=tm_struct->tm_sec;
}
/*** Return pos. of second word in inpstr ***/
char *remove_first(inpstr)
char *inpstr;
{
char *pos=inpstr;
while(*pos<33 && *pos) ++pos;
while(*pos>32) ++pos;
while(*pos<33 && *pos) ++pos;
return pos;
}
/*** Returns 1 if string is a positive number ***/
isnumber(str)
char *str;
{
while(*str) if (!isdigit(*str++)) return 0;
return 1;
}
/*** Get user struct pointer from full name (no abbrevs allowed) ***/
UR_OBJECT get_user_by_full(name)
char *name;
{
UR_OBJECT u;
name[0]=toupper(name[0]);
for(u=user_first;u!=NULL;u=u->next) {
if (u->type==CLONE_TYPE || u->login) continue;
if (!strcmp(u->name,name)) return u;
}
return NULL;
}
/*** Get user struct pointer from name ***/
UR_OBJECT get_user(name)
char *name;
{
UR_OBJECT u;
name[0]=toupper(name[0]);
/* Check for full names before short names to catch bug in users with simliar names, eg, Chris & Chrissie */
u=get_user_by_full(name);
if (u)
return u;
for(u=user_first;u!=NULL;u=u->next) {
if (u->type==CLONE_TYPE || u->login) continue;
if (!strncmp(u->name,name,strlen(name))) return u;
}
return NULL;
}
/*** Get room struct pointer from full name ***/
RM_OBJECT get_room_by_full(name)
char *name;
{
RM_OBJECT rm;
for(rm=room_first;rm!=NULL;rm=rm->next)
if (!strcmp(rm->name,name)) return rm;
return NULL;
}
/*** Get room struct pointer from abbreviated name ***/
RM_OBJECT get_room(name)
char *name;
{
RM_OBJECT rm;
rm=get_room_by_full(name);
if (rm)
return rm;
for(rm=room_first;rm!=NULL;rm=rm->next)
if (!strncmp(rm->name,name,strlen(name))) return rm;
return NULL;
}
/*** Return level value based on level name ***/
get_level(name)
char *name;
{
int i=0;
while(new_levels[0][i][0]!='*') {
if (!strcmp(level_name[i],name)) return i;
++i;
}
i=0;
while(new_levels[1][i][0]!='*') {
if (!strcmp(level_name[i],name)) return i;
++i;
}
i=0;
while(new_levels[2][i][0]!='*') {
if (!strcmp(level_name[i],name)) return i;
++i;
}
return -1;
}
/*** See if user has unread mail, mail file has last read time on its
first line ***/
has_unread_mail(user)
UR_OBJECT user;
{
FILE *fp;
int tm;
char filename[80];
sprintf(filename,"%s/%s.M",USERMAIL,user->name);
if (!(fp=fopen(filename,"r"))) return 0;
fscanf(fp,"%d",&tm);
fclose(fp);
if (tm>(int)user->read_mail) return 1;
return 0;
}
/*** This is function that sends mail to other users ***/
send_mail(user,to,ptr)
UR_OBJECT user;
char *to,*ptr;
{
FILE *infp,*outfp;
char d,filename[80],line[DNL+1];
char mailbuf[ARR_SIZE*2];
if (!(outfp=fopen("tempfile","w"))) {
write_user(user,"Error in mail delivery.\n");
write_syslog("ERROR: Couldn't open tempfile in send_mail().\n",0);
return;
}
/* Write current time on first line of tempfile */
fprintf(outfp,"%d\n",(int)time(0));
sprintf(filename,"%s/%s.M",USERMAIL,to);
if (infp=fopen(filename,"r")) {
/* Discard first line of mail file. */
fgets(line,DNL,infp);
/* Copy rest of file */
d=getc(infp);
while(!feof(infp)) { putc(d,outfp); d=getc(infp); }
fclose(infp);
}
if (user!=NULL)
fprintf(outfp,"~OLFrom:~RS ~FT%s~RS, %s %d %s, %02d:%02d\n",user->name,day[twday],tmday,month[tmonth],thour,tmin);
else
fprintf(outfp,"~OLFrom:~RS ~FTMAILER~RS, %s %d %s, %02d:%02d\n",day[twday],tmday,month[tmonth],thour,tmin);
fputs(ptr,outfp);
fputs("\n",outfp);
fclose(outfp);
unlink(filename); /* Bug fix so mail dir can work over symbolic link in solaris */
rename("tempfile",filename);
sprintf(mailbuf,"You send mail to ~OL%s~RS: %s",to,ptr);
write_user(user,mailbuf);
write_user(get_user(to),"\07~OL~LI** YOU HAVE ~FGNEW~RS~OL~LI MAIL **\n");
}
/*** Convert string to upper case ***/
strtoupper(str)
char *str;
{
while(*str) { *str=toupper(*str); str++; }
}
/*** Convert string to lower case ***/
strtolower(str)
char *str;
{
while(*str) { *str=tolower(*str); str++; }
}
/*** Clear the review buffer in the room ***/
clear_rbuff(rm)
RM_OBJECT rm;
{
int c;
if (!rm)
return;
for(c=0;c<CONV_LINES;++c) rm->conv_line[c][0]='\0';
rm->cln=0;
}
/*** See if string contains any swearing ***/
contains_swearing(str)
char *str;
{
char *s;
int i;
if ((s=(char *)malloc(strlen(str)+1))==NULL) return 0;
strcpy(s,str);
strtoupper(s);
i=0;
while(swear_words[i][0]!='*') {
if (strstr(s,swear_words[i])) { free(s); return 1; }
++i;
}
free(s);
return 0;
}
/*** Count the number of colour commands in a string ***/
colour_com_count(str)
char *str;
{
char *s;
int i,cnt;
s=str; cnt=0;
while(*s) {
/* Mish - For old style bold text */
if (*s=='^') {
++cnt;
++s;
continue;
}
if (*s=='~') {
++s;
for(i=0;i<NUM_COLS;++i) {
if (!strncmp(s,colcom[i],2)) {
cnt=cnt+3; s++; continue;
}
}
continue;
}
++s;
}
return cnt;
}
/************ OBJECT FUNCTIONS ************/
/*** Construct user/clone object ***/
UR_OBJECT create_user()
{
UR_OBJECT user;
int i;
if ((user=(UR_OBJECT)malloc(sizeof(struct user_struct)))==NULL) {
write_syslog("~FRCONSTRUCT: ~RSMemory allocation failure.\n",0);
write_room(NULL,"~FY~OLSYSTEM:~RS Failed to allocate memory in create_user()");
return NULL;
}
/* Append object into linked list. */
if (user_first==NULL) {
user_first=user; user->prev=NULL; user->next=NULL;
}
else {
user_last->next=user; user->next=NULL; user->prev=user_last;
}
user_last=user;
/* initialise users - general */
user->type=USER_TYPE;
user->name[0]='\0';
user->desc[0]='\0';
user->in_phrase[0]='\0';
user->out_phrase[0]='\0';
user->pass[0]='\0';
user->site[0]='\0';
user->last_site[0]='\0';
user->page_file[0]='\0';
user->mail_to[0]='\0';
user->buff[0]='\0';
user->buffpos=0;
user->filepos=0;
user->read_mail=time(0);
user->room=NULL;
user->invite_room=NULL;
user->port=0;
user->login=0;
user->socket=-1;
user->attempts=0;
user->command_mode=command_mode_def;
user->level=0;
user->vis=1;
user->ignall=0;
user->ignall_store=0;
user->ignshout=0;
user->igntell=0;
user->muzzled=0;
user->last_input=time(0);
user->last_login=time(0);
user->last_login_len=0;
user->total_login=0;
user->prompt=prompt_def;
user->charmode_echo=0;
user->misc_op=0;
user->edit_op=0;
user->edit_line=0;
user->charcnt=0;
user->warned=0;
user->accreq=0;
user->afk=0;
user->colour=colour_def;
user->clone_hear=CLONE_HEAR_ALL;
user->malloc_start=NULL;
user->malloc_end=NULL;
user->owner=NULL;
user->old_tell[0]='\0';
user->ip_name[0]='\0';
user->tell=0;
user->licked=0;
user->been_licked=0;
user->sex=0; /* An 'it'! */
user->autologout=0;
user->site_port=0;
user->termtype=0; /* Colour xterm */
user->xterm=1; /* Xterm titles on */
user->figlet=0;
user->revline=0;
user->auth_addr=0;
user->vis_email=0;
user->examined=0;
user->email[0]='\0';
user->www[0]='\0';
user->logout_phrase[0]='\0';
user->rank[0]='\0';
user->pre_desc[0]='\0';
user->afk_mesg[0]='\0';
user->ip_num[0]='\0';
user->home=0;
user->window_y=20;
user->window_x=80;
for(i=0; i<REVTELL_LINES; ++i) user->revbuff[i][0]='\0';
return user;
}
/*** Destruct a user object. ***/
destruct_user(user)
UR_OBJECT user;
{
/* Remove from linked list */
if (user!=user_first) {
user->prev->next=user->next;
if (user!=user_last) user->next->prev=user->prev;
else { user_last=user->prev; user_last->next=NULL; }
}
else {
user_first=user->next;
if (user!=user_last) user_first->prev=NULL;
else user_last=NULL;
}
free(user);
}
/*** Construct room object ***/
RM_OBJECT create_room()
{
RM_OBJECT room;
int i;
if ((room=(RM_OBJECT)malloc(sizeof(struct room_struct)))==NULL) {
write_syslog("~FRCONSTRUCT: ~RSMemory allocation failure.\n",0);
write_room(NULL,"~FY~OLSYSTEM:~RS Failed to allocate memory in create_room()");
return NULL;
}
room->name[0]='\0';
room->label[0]='\0';
room->desc[0]='\0';
room->topic[0]='\0';
room->access=-1;
room->cln=0;
room->mesg_cnt=0;
room->tlock=0;
room->prev=NULL;
room->next=NULL;
for(i=0;i<MAX_LINKS;++i) {
room->link_label[i][0]='\0'; room->link[i]=NULL;
}
for(i=0;i<CONV_LINES;++i) room->conv_line[i][0]='\0';
/* Add room into linked list */
if (room_first==NULL) {
room_first=room; room->prev=NULL; room->next=NULL;
}
else {
room_last->next=room; room->next=NULL; room->prev=room_last;
}
room_last=room;
return room;
}
/*** Destruct a room object. ***/
destruct_room(user)
UR_OBJECT user;
{
RM_OBJECT room;
UR_OBJECT u;
char *name;
/* Save struct lookups in loop */
name=user->name;
if (!name)
return;
/* Find the room to be destroyed */
for(room=room_first;room!=NULL;room=room->next) {
if (!strcmp(room->name,name)) {
/* Remove others in this room */
for (u=user_first;u!=NULL;u=u->next)
if (u->room==room && user!=u)
move_user(u,room_first,0);
/* Do we need this?... I dunno */
user->room=room_first;
/* Remove from linked list */
if (room!=room_first) {
room->prev->next=room->next;
if (room!=room_last) room->next->prev=room->prev;
else { room_last=room->prev; room_last->next=NULL; }
}
else {
room_first=room->next;
if (room!=room_last) room_first->prev=NULL;
else room_last=NULL;
}
free(room);
return;
}
}
}
/*** Destroy all clones belonging to given user ***/
destroy_user_clones(user)
UR_OBJECT user;
{
UR_OBJECT u;
char local[256];
for(u=user_first;u!=NULL;u=u->next) {
if (u->type==CLONE_TYPE && u->owner==user) {
sprintf(local,"~FBThe clone of %s shimmers and vanishes.\n",u->name);
write_room(u->room,local);
destruct_user(u);
destructed=1;
}
}
}
/************ START OF COMMAND FUNCTIONS AND THEIR SUBSIDS ************/
/*** Deal with user input ***/
exec_com(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
int i,len;
char *comword;
com_num=-1;
if (word[0][0]=='.') comword=(word[0]+1);
else comword=word[0];
if (!comword[0]) {
write_user(user,"Unknown command.\n"); return;
}
/* Sort out command aliases */
switch(inpstr[0]) {
case '>':
if (inpstr[1]=='>') {
user->tell=1;
inpstr[1]=' ';
}
else {
user->tell=0;
if (inpstr[1]!=' ') {
namecpy(word[1],inpstr+1);
word_count++;
}
else
inpstr=remove_first(inpstr);
}
strcpy(word[0],"tell");
break;
case '<':
if (inpstr[1]=='<') {
user->tell=1;
inpstr[1]=' ';
}
else {
user->tell=0;
if (inpstr[1]!=' ') {
namecpy(word[1],inpstr+1);
word_count++;
}
else
inpstr=remove_first(inpstr);
}
strcpy(word[0],"pemote");
break;
case '-':
if (inpstr[1]!=' ') {
inpstr++;
word_count++;
}
else
inpstr=remove_first(inpstr);
strcpy(word[0],"echo");
break;
case '!':
if (inpstr[1]!=' ') {
inpstr++;
word_count++;
}
else
inpstr=remove_first(inpstr);
strcpy(word[0],"shout");
break;
case '\"':
strcpy(word[0],"say");
inpstr++;
word_count++;
break;
case ':':
case ';':
strcpy(word[0],"emote");
break;
case '#':
if (inpstr[1]!=' ') {
inpstr++;
word_count++;
}
else
inpstr=remove_first(inpstr);
strcpy(word[0],"semote");
break;
case ',':
if (inpstr[1]!=' ') {
namecpy(word[1],inpstr+1);
word_count++;
}
else
inpstr=remove_first(inpstr);
strcpy(word[0],"dsay");
break;
default:
inpstr=remove_first(inpstr);
}
i=0;
len=strlen(comword);
while(command[i][0]!='*') {
if (!strncmp(command[i],comword,len)) { com_num=i; break; }
++i;
}
if (user->room!=NULL && (com_num==-1 || com_level[com_num] > user->level)) {
write_user(user,"Unknown command.\n"); return;
}
/* Main switch */
switch(com_num) {
/* General user commands */
case QUIT: disconnect_user(user); break;
case LOOK: look(user); break;
case SAY :
if (word_count<2) {
write_user(user,"Say what?\n"); return;
}
say(user,inpstr);
break;
case SHOUT : shout(user,inpstr); break;
case TELL : tell_user(user,inpstr); break;
case EMOTE : emote(user,inpstr); break;
case SEMOTE: semote(user,inpstr); break;
case PEMOTE: pemote(user,inpstr); break;
case ECHO : echo(user,inpstr); break;
case BCAST : bcast(user,inpstr); break;
case ACCREQ: account_request(user,inpstr); break;
case AFK : afk(user, inpstr); break;
case CLS:
for(i=0;i<5;++i) write_user(user,"\n\n\n\n\n\n\n\n\n\n");
break;
case SUICIDE : suicide(user); break;
case SOS: sos(user); break;
case MYXTERM : my_xterm(user, inpstr); break;
case REVTELL: revtell(user); break;
case FIGLET: figlet(user,inpstr); break;
case DSAY: dsay(user,inpstr); break;
case BEEP: beep(user,inpstr); break;
/* Files */
case NEWS:
case MAP:
case RANKS:
case FAQ:
case TALKERS:
case RULES:
page_file(user); break;
/* Boards */
case READ : read_board(user); break;
case WRITE : write_board(user,inpstr,0); break;
case WIPE : wipe_board(user); break;
case SEARCH: search_boards(user); break;
/* Info */
case WHO : who(user,0); break;
case SWHO: swho(user); break;
case PEOPLE : who(user,1); break;
case REVIEW: review(user); break;
case HELP : help(user); break;
case STATUS: status(user); break;
case EXAMINE : examine(user); break;
case WHERE : where(user); break;
/* User info stuff */
case ENTPRO : enter_profile(user,0); break;
case SETRANK: set_rank(user,inpstr); break;
case PASSWD : change_pass(user); break;
case PROMPT: toggle_prompt(user); break;
case PDESC: set_pre_desc(user,inpstr); break;
case DESC : set_desc(user,inpstr); break;
case INPHRASE :
case OUTPHRASE:
set_iophrase(user,inpstr); break;
case LOGIN: set_login(user,inpstr); break;
case LOGOUT: set_logout(user, inpstr); break;
case EMAIL: set_email(user); break;
case VEMAIL: set_vemail(user); break;
case WWW: set_www(user); break;
case COLOUR : toggle_colour(user); break;
case IGNFIG: ignore_figlet(user); break;
case IGNALL: toggle_ignall(user); break;
case IGNSHOUT: toggle_ignshout(user); break;
case IGNTELL : toggle_igntell(user); break;
case EWTOO: ewtoo_mode(user); break;
case NUTS: nuts_mode(user); break;
case MODE: toggle_mode(user); break;
case SEX : sex(user); break;
case TERMTYPE: set_term(user); break;
case VIS : visibility(user,1); break;
case INVIS : visibility(user,0); break;
case CHARECHO : charecho(user); break;
case WINDOW: window(user); break;
/* Mail */
case RMAIL : rmail(user); break;
case SMAIL : smail(user,inpstr,0); break;
case DMAIL : dmail(user); break;
case FROM : mail_from(user); break;
/* Room stuff */
case RMST : rooms(user); break;
case FIX : change_room_fix(user,1); break;
case UNFIX : change_room_fix(user,0); break;
case REVCLR: revclr(user); break;
case PUBCOM :
case PRIVCOM: set_room_access(user); break;
case LETMEIN: letmein(user); break;
case INVITE : invite(user); break;
case TOPIC : set_topic(user,inpstr); break;
case TLOCK: tlock(user); break;
case JOIN: join(user); break;
case GO : go(user); break;
case MOVE : move(user); break;
case HOME: home(user); break;
case EDIT: edit_room(user,0); break;
case BOOT: boot(user); break;
/* Admin stuff */
case KILL : kill_user(user); break;
case PROMOTE : promote(user); break;
case DEMOTE : demote(user); break;
case LISTBANS: listbans(user); break;
case BAN : ban(user); break;
case UNBAN : unban(user); break;
case SITE : site(user); break;
case WAKE : wake(user); break;
case WIZSHOUT: wizshout(user,inpstr); break;
case MUZZLE : muzzle(user); break;
case UNMUZZLE: unmuzzle(user); break;
case VIEWLOG : viewlog(user); break;
case THP: thp(user); break;
case SU: su(user); break;
case AUTH: auth_user(user); break;
case CLEARLINE: clearline(user); break;
case ALLXTERM : all_xterm(inpstr); break;
case NEWUSER: newuser(user); break;
case BSX : bsx(user); break;
case SINFO: sinfo(user,inpstr); break;
/* Clones stuff */
case CREATE: create_clone(user); break;
case DESTROY: destroy_clone(user); break;
case MYCLONES: myclones(user); break;
case ALLCLONES: allclones(user); break;
case SWITCH: clone_switch(user); break;
case CSAY : clone_say(user,inpstr); break;
case CEMOTE: clone_emote(user,inpstr); break;
case CHEAR : clone_hear(user); break;
/* Fun stuff :) */
case BANNER : banner(user, inpstr); break;
case SING : sing(user, inpstr); break;
case THINK : think(user, inpstr); break;
case LOTTERY : lottery(user); break;
case FLOWERS : flowers(user, inpstr); break;
case LICK : lick(user); break;
case NUMPTY: numpty(user); break;
case WHORE: whore(user); break;
case GP: godpidgeon(user,inpstr); break;
case GPEMOTE: gp_emote(user,inpstr); break;
case SHARK: shark(user); break;
case HUG: hug(user); break;
case HP: hp(user,inpstr); break;
case POKE: poke(user); break;
case ROSE: rose(user); break;
/* System Stuff */
case SYSTEM : system_details(user); break;
case SWBAN : swban(user); break;
case ATMOS: atmos_onoff(user); break;
case BACKUP: do_backup(1); break;
case DOWEB: do_web(1); break;
case DELETE_C : delete_user(user,0); break;
case REBOOT :
write_user(user,"\n\07~FR~OL~LI*** WARNING - This will reboot the talker! ***\n\nAre you sure about this (y/n)? ");
user->misc_op=7; no_prompt=1;
break;
case SHUTDOWN:
write_user(user,"\n\07~FR~OL~LI*** WARNING - This will shutdown the talker! ***\n\nAre you sure about this (y/n)? ");
user->misc_op=1; no_prompt=1;
break;
case LOGGING : logging(user); break;
case MINLOGIN : minlogin(user); break;
case VER:
sprintf(text,"~FRC~FMr~FGy~FTp~FYt~RS Talker version ~FB%s~RS (Based on Nuts v3.2.1)\n",VERSION);
write_user(user,text); break;
case WEBPAGE: onoffweb_page(); break;
case ADDWHERE: add_where(user,0); break;
default: write_user(user,"Command not executed in exec_com().\n");
}
}
/*** Page a file out to the user ***/
page_file(user)
UR_OBJECT user;
{
char filename[80];
switch (com_num) {
case NEWS: sprintf(filename,"%s/%s",TEXTFILES,NEWSFILE); break;
case MAP: sprintf(filename,"%s/%s",TEXTFILES,MAPFILE); break;
case RANKS: sprintf(filename,"%s/%s",TEXTFILES,RANKS_FILE); break;
case FAQ: sprintf(filename,"%s/%s",TEXTFILES,FAQ_FILE); break;
case TALKERS: sprintf(filename,"%s/%s",TEXTFILES,TALKERS_FILE); break;
case RULES: sprintf(filename,"%s/%s",TEXTFILES,RULES_FILE); break;
}
switch(more(user,user->socket,filename)) {
case 0:
sprintf(text,"Hmmm, '%s' file missing!\n",filename);
write_user(user,text); break;
case 1: user->misc_op=2;
}
}
/*** Afk ***/
afk(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
if (word_count<2) {
if (user->vis) {
sprintf(text,"~FG%s goes AFK...~RS\n",user->name);
write_room_except(user->room,text,user);
}
sprintf(text,"No message set\n");
}
else {
if (strlen(inpstr)>80) {
write_user(user,"AFK message too long.\n");
return;
}
if (user->vis) {
sprintf(text,"~FG(AFK) %s %s\n",user->name,inpstr);
write_room(user->room,text);
}
sprintf(text,"%s %s\n",user->name,inpstr);
}
strcpy(user->afk_mesg,text);
write_user(user,"You are now AFK, press <RETURN> to resume.\n");
user->afk=1;
}
/*** View the system log ***/
viewlog(user)
UR_OBJECT user;
{
FILE *fp;
char c,*emp="\nThe system log is empty.\n";
int lines,cnt,cnt2;
if (word_count==1) {
write_user(user,"\n~FB*** ~FTSystem Log~FB ***\n\n");
switch(more(user,user->socket,SYSLOG)) {
case 0: write_user(user,emp); return;
case 1: user->misc_op=2;
}
return;
}
if (!isnumber(word[1])) {
write_user(user,"Usage: viewlog [<lines from the end>]\n"); return;
}
/* Count total lines */
if (!(fp=fopen(SYSLOG,"r"))) { write_user(user,emp); return; }
cnt=0;
lines=atoi(word[1]);
c=getc(fp);
while(!feof(fp)) {
if (c=='\n') ++cnt;
c=getc(fp);
}
if (cnt<lines) {
sprintf(text,"There are only ~FG%d~RS lines in the log.\n",cnt);
write_user(user,text);
fclose(fp);
return;
}
if (cnt==lines) {
write_user(user,"\n~FB*** ~FTSystem Log~FB ***\n\n");
fclose(fp); more(user,user->socket,SYSLOG); return;
}
/* Find line to start on */
fseek(fp,0,0);
cnt2=0;
c=getc(fp);
while(!feof(fp)) {
if (c=='\n') ++cnt2;
c=getc(fp);
if (cnt2==cnt-lines) {
sprintf(text,"\n~FB*** ~FTSystem Log (last ~FG%d~FT lines)~FB ***\n\n",lines);
write_user(user,text);
user->filepos=ftell(fp)-1;
fclose(fp);
if (more(user,user->socket,SYSLOG)!=1) user->filepos=0;
else user->misc_op=2;
return;
}
}
fclose(fp);
sprintf(text,"~OL~FRSYSTEM: ~RSLine count error.\n");
write_user(user,text);
write_syslog("~OL~FRERROR: ~RSLine count error in viewlog().\n",0);
}
/*** Display details of room ***/
look(user)
UR_OBJECT user;
{
RM_OBJECT rm;
UR_OBJECT u;
char temp[81],null[1],*ptr;
char *afk="~FG(AFK)";
int i,exits,users;
rm=user->room;
sprintf(text,"\n~FTRoom: ~FG%s\n\n",rm->name);
write_user(user,text);
write_user(user,user->room->desc);
exits=0; null[0]='\0';
strcpy(text,"\n~FTExits are:");
for(i=0;i<MAX_LINKS;++i) {
if (rm->link[i]==NULL) break;
if (rm->link[i]->access & 1) sprintf(temp," ~FR%s",rm->link[i]->name);
else sprintf(temp," ~FG%s",rm->link[i]->name);
strcat(text,temp);
++exits;
}
if (!exits) strcpy(text,"\n~FTThere are no exits.");
strcat(text,"\n\n");
write_user(user,text);
users=0;
for(u=user_first;u!=NULL;u=u->next) {
if (u->room!=rm || u==user || (!u->vis && u->level>user->level))
continue;
if (!users++) write_user(user,"~FTYou can see:\n");
if (u->afk) ptr=afk; else ptr=null;
if (!u->vis)
sprintf(text," ~FR*~RS%s~RS %s %s~RS %s\n",u->pre_desc,u->name,u->desc,ptr);
else
sprintf(text," %s~RS %s %s~RS %s\n",u->pre_desc,u->name,u->desc,ptr);
write_user(user,text);
}
if (!users) write_user(user,"~FTYou are all alone here.\n");
write_user(user,"\n");
strcpy(text,"Room access is ");
switch(rm->access) {
case PUBLIC: strcat(text,"set to ~FGPUBLIC~RS"); break;
case PRIVATE: strcat(text,"set to ~FRPRIVATE~RS"); break;
case FIXED_PUBLIC: strcat(text,"~FRfixed~RS to ~FGPUBLIC~RS"); break;
case FIXED_PRIVATE: strcat(text,"~FRfixed~RS to ~FRPRIVATE~RS"); break;
case USER_ROOM: strcat(text,"set to ~FYROOM OWNER ONLY~RS"); break;
}
sprintf(temp," and there are ~FM%d~RS messages on the board.\n",rm->mesg_cnt);
strcat(text,temp);
write_user(user,text);
if (rm->topic[0]) {
sprintf(text,"Room topic: %s\n",rm->topic);
write_user(user,text);
if (rm->tlock) {
sprintf(text,"~FR(Topic locked at level: ~FM%s~FR)\n",level_name[rm->tlock]);
write_user(user,text);
}
return;
}
/* write_user(user,"No room topic has been set.\n"); */
}
/*** Switch between command and speech mode ***/
toggle_mode(user)
UR_OBJECT user;
{
if (user->command_mode) {
write_user(user,"Now in ~FRSPEECH ~FG(Nuts)~RS mode.\n");
user->command_mode=0; return;
}
write_user(user,"Now in ~FRCOMMAND ~FG(EW-Too)~RS mode.\n");
user->command_mode=1;
}
ewtoo_mode(user)
UR_OBJECT user;
{
write_user(user,"Now in ~FRCOMMAND ~FG(EW-Too)~RS mode.\n");
user->command_mode=1;
}
nuts_mode(user)
UR_OBJECT user;
{
write_user(user,"Now in ~FRSPEECH ~FG(Nuts)~RS mode.\n");
user->command_mode=0;
}
/*** Shutdown the talker ***/
talker_shutdown(user,str,reboot)
UR_OBJECT user;
char *str;
int reboot;
{
UR_OBJECT u;
int i;
char *ptr;
#ifdef WIN_NT
PROCESS_INFORMATION p_info;
STARTUPINFO s_info;
char args[256];
strcpy(args,progname); strcat(args," "); strcat(args,confile);
#else
char *args[]={
progname,confile,NULL
};
#endif
if (user!=NULL) ptr=user->name; else ptr=str;
if (reboot) {
write_room(NULL,"\07\n~OLSYSTEM:~FR~LI Rebooting now!!\n\n");
sprintf(text,"*** ~FRREBOOT~RS initiated by %s ***\n",ptr);
#ifdef WIN_NT
GetStartupInfo(&s_info);
#endif
}
else {
write_room(NULL,"\07\n~OLSYSTEM:~FR~LI Shutting down now!!\n\n");
sprintf(text,"*** ~FRSHUTDOWN~RS initiated by %s ***\n",ptr);
}
write_syslog(text,0);
for(u=user_first;u!=NULL;u=u->next) disconnect_user(u);
for(i=0;i<2;++i) CLOSE(listen_sock[i]);
#ifdef WIN_NT
/* Shutdown winsock + timer thread before exit */
WSACleanup();
TerminateThread(hThread,0);
#endif
if (reboot) {
sprintf(text,"*** Server exit at %02d:%02d:%02d ***\n\n",thour,tmin,tsec);
write_syslog(text,0);
/* If someone has changed the binary or the config filename while this
prog has been running this won't work */
#ifdef WIN_NT
CreateProcess(progname,args,NULL,NULL,0,
DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS,
NULL, NULL, &s_info, &p_info);
#else
execvp(progname,args);
#endif
/* If we get this far it hasn't worked
sprintf(text,"*** ~FRREBOOT~RS failed at %02d:%02d:%02d: %s ***\n\n",thour,tmin,tsec,sys_errlist[errno]);
*/
sprintf(text,"*** ~FRREBOOT~RS failed at %02d:%02d:%02d ***\n\n",thour,tmin,tsec);
write_syslog(text,0);
exit(12);
}
sprintf(text,"*** ~FRSHUTDOWN~RS complete at %02d:%02d:%02d ***\n\n",thour,tmin,tsec);
write_syslog(text,0);
exit(0);
}
/*** Dsay shortcut ***/
dsay(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
UR_OBJECT u;
char *name;
if (user->muzzled) {
write_user(user,"You are muzzled, you cannot speak.\n"); return;
}
if (word_count<2) {
write_user(user,"Usage: .dsay user text\n");
return;
}
if (word_count<3) {
write_user(user,"Say what and to who?\n");
return;
}
if (!(u=get_user(word[1]))) {
write_user(user,notloggedon); return;
}
if (u->room!=user->room) {
write_user(user,"They are not here.\n");
return;
}
inpstr=remove_first(inpstr);
if (user->vis) name=user->name; else name=invisname;
sprintf(text,"%s says to %s: %s\n",name,u->name,inpstr);
write_room_except(user->room,text,user);
record(user->room,text);
sprintf(text,"You say to %s: %s\n",u->name,inpstr);
write_user(user,text);
}
/*** Say user speech. ***/
say(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
char type[10],*name;
if (user->muzzled) {
write_user(user,"You are muzzled, you cannot speak.\n"); return;
}
if ((word_count<2 && user->command_mode) || inpstr[0]<32) {
write_user(user,"Say what?\n"); return;
}
switch(inpstr[strlen(inpstr)-1]) {
case '?': strcpy(type,"ask"); break;
case '!': strcpy(type,"exclaim"); break;
default : strcpy(type,"say");
}
if (user->type==CLONE_TYPE) {
sprintf(text,"Clone of %s %ss: %s\n",user->name,type,inpstr);
write_room(user->room,text);
record(user->room,text);
return;
}
if (ban_swearing && contains_swearing(inpstr)) {
write_user(user,noswearing); return;
}
sprintf(text,"You %s: %s\n",type,inpstr);
write_user(user,text);
if (user->vis) name=user->name; else name=invisname;
sprintf(text,"%s %ss: %s\n",name,type,inpstr);
write_room_except(user->room,text,user);
record(user->room,text);
}
/*** Shout something ***/
shout(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
char *name;
if (user->muzzled) {
write_user(user,"You are muzzled, you cannot shout.\n"); return;
}
if (word_count<2 || inpstr[0]<32) {
write_user(user,"Shout what?\n"); return;
}
if (!strcmp(user->room->name,"padded_cell")) {
write_user(user,"In the ~OLPadded Cell~RS no-one can hear you scream...\n");
return;
}
if (ban_swearing && contains_swearing(inpstr)) {
write_user(user,noswearing); return;
}
sprintf(text,"~OLYou shout:~RS %s\n",inpstr);
write_user(user,text);
if (user->vis) name=user->name; else name=invisname;
sprintf(text,"~OL%s shouts:~RS %s\n",name,inpstr);
write_room_except(NULL,text,user);
record(room_first,text);
}
/*** Tell another user something ***/
tell_user(user,inpstr)
UR_OBJECT user;
char *inpstr;
{
UR_OBJECT u;
char type[10],type2[10],*name;
int len;
if (user->muzzled) {
write_user(user,"You are muzzled, you cannot tell anyone anything.\n");
user->tell=0;
return;
}
if (word_count<3 && user->tell==0) {
write_user(user,"Tell who what?\n"); return;
}
/* Catch use of >> before > */
if (user->old_tell[0]=='\0' && user->tell==1) {
write_user(user,"Tell who what?\n");
user->tell=0;
return;
}
if (user->tell)
u=get_user(user->old_tell);
else
u=get_user(word[1]);
user->tell=0;
if (!u) {
write_user(user,notloggedon); return;
}
if (u==user) {
write_user(user,"Talking to yourself is the first sign of madness.\n");
return;
}
/* Make user u the subject of future >> */
strcpy(user->old_tell, u->name);
if (u->afk) {
sprintf(text,"%s is ~FRAFK~RS at the moment.\nMessage is: ~FY%s",u->name,u->afk_mesg);
write_user(user,text);
return;
}
if (u->ignall && (user->level<WIZ || u->level>user->level)) {
if (u->malloc_start!=NULL)
sprintf(text,"%s is using the editor at the moment.\n",u->name);
else sprintf(text,"%s is ignoring everyone at the moment.\n",u->name);
write_user(user,text);
return;
}
if (u->igntell && (user->level<WIZ || u->level>user->level)) {
sprintf(text,"%s is ignoring tells at the moment.\n",u->name);
write_user(user,text);
return;
}
inpstr=remove_first(inpstr);
len=strlen(inpstr);
switch (inpstr[len-1]) {
case '?':
strcpy(type,"ask");
strcpy(type2,"asks");
break;
case ')':
if (inpstr[len-2]==':') {
strcpShowing the first 100 KB of 252.0 KB. Download the archive for the full file.