comm.c
legend/src/comm.c · 190.8 KB
From the archive LoCRelease.tgz
Download the archive « Back to the archive contents
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Thanks to abaddon for proof-reading our comm.c and pointing out bugs. *
* Any remaining bugs are, of course, our work, not his. :) *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
/***************************************************************************
* God Wars Mud copyright (C) 1994, 1995, 1996 by Richard Woolcock *
* *
* Legend of Chrystancia copyright (C) 1999, 2000, 2001 by Matthew Little *
* This mud is NOT to be copied in whole or in part, or to be run without *
* the permission of Matthew Little. Nobody else has permission to *
* authorise the use of this code. *
***************************************************************************/
/*
* This file contains all of the OS-dependent stuff:
* startup, signals, BSD sockets for tcp/ip, i/o, timing.
*
* The data flow for input is:
* Game_loop ---> Read_from_descriptor ---> Read
* Game_loop ---> Read_from_buffer
*
* The data flow for output is:
* Game_loop ---> Process_Output ---> Write_to_descriptor -> Write
*
* The OS-dependent functions are Read_from_descriptor and Write_to_descriptor.
* -- Furey 26 Jan 1993
*/
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <arpa/inet.h>
#include <stdarg.h> /* printf_to_char */
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/wait.h>
#include "merc.h"
#include "opas.h"
#include "mudinfo.h"
#include "version.h"
#include "build.h"
NCLANS_DATA *nclans_table;
/*
* Malloc debugging stuff.
*/
#if defined(sun)
#undef MALLOC_DEBUG
#endif
#if defined(MALLOC_DEBUG)
#include <malloc.h>
extern int malloc_debug args ((int));
extern int malloc_verify args ((void));
#endif
/*
* Signal handling.
* Apollo has a problem with __attribute(atomic) in signal.h,
* I dance around it.
*/
#if defined(apollo)
#define __attribute(x)
#endif
#if defined(unix)
#include <signal.h>
#include <unistd.h>
#include <sys/resource.h> /* for RLIMIT_NOFILE */
#endif
#if defined(apollo)
#undef __attribute
#endif
/*
* Socket and TCP/IP stuff.
*/
#if defined(macintosh) || defined(MSDOS)
const char echo_off_str[] = { '\0' };
const char echo_on_str[] = { '\0' };
const char go_ahead_str[] = { '\0' };
#endif
#if defined(unix)
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/telnet.h>
const char echo_off_str[] = { IAC, WILL, TELOPT_ECHO, '\0' };
const char echo_on_str[] = { IAC, WONT, TELOPT_ECHO, '\0' };
const char go_ahead_str[] = { IAC, GA, '\0' };
#endif
/* MCCP */
const char compress_will[] = { IAC, WILL, TELOPT_COMPRESS, '\0' };
const char compress_will2[] = { IAC, WILL, TELOPT_COMPRESS2, '\0' };
const char compress_do[] = { IAC, DO, TELOPT_COMPRESS, '\0' };
const char compress_do2[] = { IAC, DO, TELOPT_COMPRESS2, '\0' };
const char compress_dont[] = { IAC, DONT, TELOPT_COMPRESS, '\0' };
const char compress_dont2[] = { IAC, DONT, TELOPT_COMPRESS2, '\0' };
/*
* OS-dependent declarations.
*/
#if defined(_AIX)
#include <sys/select.h>
/*
int accept args( ( int s, struct sockaddr *addr, int *addrlen ) );
int bind args( ( int s, struct sockaddr *name, int namelen ) );
*/
void bzero args ((char *b, int length));
int getpeername args ((int s, struct sockaddr * name, int *namelen));
int getsockname args ((int s, struct sockaddr * name, int *namelen));
float gettimeofday args ((struct timeval * tp, struct timezone * tzp));
int listen args ((int s, int backlog));
int setsockopt args ((int s, int level, int optname, void *optval,
int optlen));
int socket args ((int domain, int type, int protocol));
#endif
#if defined(apollo)
#include <unistd.h>
void bzero args ((char *b, int length));
#endif
#if defined(__hpux)
/*
int accept args( ( int s, void *addr, int *addrlen ) );
int bind args( ( int s, const void *addr, int addrlen ) );
*/
void bzero args ((char *b, int length));
int getpeername args ((int s, void *addr, int *addrlen));
int getsockname args ((int s, void *name, int *addrlen));
float gettimeofday args ((struct timeval * tp, struct timezone * tzp));
int listen args ((int s, int backlog));
int setsockopt args ((int s, int level, int optname,
const void *optval, int optlen));
int socket args ((int domain, int type, int protocol));
#endif
#if defined(interactive)
#include <net/errno.h>
#include <sys/fcntl.h>
#endif
#if defined(linux)
/* mercpoint: commented out to enable compiling
int accept args( ( int s, struct sockaddr *addr, int *addrlen ) );
int bind args( ( int s, struct sockaddr *name, int namelen ) );
*/
int close args ((int fd));
/*int getpeername args( ( int s, struct sockaddr *name, int *namelen ) );
int getsockname args( ( int s, struct sockaddr *name, int *namelen ) );
*/
float gettimeofday args ((struct timeval * tp, struct timezone * tzp));
/*int listen args( ( int s, int backlog ) );
*/
/* kavirpoint: put this in for nin site.
int read args( ( int fd, char *buf, int nbyte ) );
*/
int select args ((int width, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval * timeout));
int socket args ((int domain, int type, int protocol));
/* kavirpoint: put this in for nin site.
int write args( ( int fd, char *buf, int nbyte ) );
*/
#endif
#if defined(macintosh)
#include <console.h>
#include <fcntl.h>
#include <unix.h>
struct timeval
{
time_t tv_sec;
time_t tv_usec;
};
#if !defined(isascii)
#define isascii(c) ( (c) < 0200 )
#endif
static long theKeys[4];
float gettimeofday args ((struct timeval * tp, void *tzp));
#endif
#if defined(MIPS_OS)
extern int errno;
#endif
#if defined(MSDOS)
float gettimeofday args ((struct timeval * tp, void *tzp));
int kbhit args ((void));
#endif
#if defined(NeXT)
int close args ((int fd));
int fcntl args ((int fd, int cmd, int arg));
#if !defined(htons)
u_short htons args ((u_short hostshort));
#endif
#if !defined(ntohl)
u_long ntohl args ((u_long hostlong));
#endif
int read args ((int fd, char *buf, int nbyte));
int select args ((int width, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval * timeout));
int write args ((int fd, char *buf, int nbyte));
#endif
#if defined(sequent)
/*
int accept args( ( int s, struct sockaddr *addr, int *addrlen ) );
int bind args( ( int s, struct sockaddr *name, int namelen ) );
*/
int close args ((int fd));
int fcntl args ((int fd, int cmd, int arg));
int getpeername args ((int s, struct sockaddr * name, int *namelen));
int getsockname args ((int s, struct sockaddr * name, int *namelen));
float gettimeofday args ((struct timeval * tp, struct timezone * tzp));
#if !defined(htons)
u_short htons args ((u_short hostshort));
#endif
int listen args ((int s, int backlog));
#if !defined(ntohl)
u_long ntohl args ((u_long hostlong));
#endif
int read args ((int fd, char *buf, int nbyte));
int select args ((int width, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval * timeout));
int setsockopt args ((int s, int level, int optname, caddr_t optval,
int optlen));
int socket args ((int domain, int type, int protocol));
int write args ((int fd, char *buf, int nbyte));
#endif
/*
* This includes Solaris SYSV as well.
*/
#if defined(sun)
/*
int accept args( ( int s, struct sockaddr *addr, int *addrlen ) );
int bind args( ( int s, struct sockaddr *name, int namelen ) );
*/
void bzero args ((char *b, int length));
int close args ((int fd));
int getpeername args ((int s, struct sockaddr * name, int *namelen));
int getsockname args ((int s, struct sockaddr * name, int *namelen));
float gettimeofday args ((struct timeval * tp, struct timezone * tzp));
int listen args ((int s, int backlog));
int read args ((int fd, char *buf, int nbyte));
int select args ((int width, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval * timeout));
#if defined(SYSV)
int setsockopt args ((int s, int level, int optname,
const char *optval, int optlen));
#else
int setsockopt args ((int s, int level, int optname, void *optval,
int optlen));
#endif
int socket args ((int domain, int type, int protocol));
int write args ((int fd, char *buf, int nbyte));
#endif
#if defined(ultrix)
/*
int accept args( ( int s, struct sockaddr *addr, int *addrlen ) );
int bind args( ( int s, struct sockaddr *name, int namelen ) );
*/
void bzero args ((char *b, int length));
int close args ((int fd));
int getpeername args ((int s, struct sockaddr * name, int *namelen));
int getsockname args ((int s, struct sockaddr * name, int *namelen));
float gettimeofday args ((struct timeval * tp, struct timezone * tzp));
int listen args ((int s, int backlog));
int read args ((int fd, char *buf, int nbyte));
int select args ((int width, fd_set * readfds, fd_set * writefds,
fd_set * exceptfds, struct timeval * timeout));
int setsockopt args ((int s, int level, int optname, void *optval,
int optlen));
int socket args ((int domain, int type, int protocol));
int write args ((int fd, char *buf, int nbyte));
#endif
/*
* Global variables.
*/
DESCRIPTOR_DATA * descriptor_free; /* Free list for descriptors */
DESCRIPTOR_DATA * first_descriptor; /* First open descriptor */
DESCRIPTOR_DATA * last_descriptor; /* Last open descriptor */
DESCRIPTOR_DATA *descriptor_free; /* Free list for descriptors */
DESCRIPTOR_DATA *d_next; /* Next descriptor in loop */
FILE *fpReserve; /* Reserved file handle */
bool god; /* All new chars are gods! */
bool merc_down; /* Shutdown */
bool nosafe; /* Game is wizlocked */
bool wizlock; /* Game is wizlocked */
int numlock = 0; /* Game is numlocked at <level> */
char crypt_pwd[MAX_INPUT_LENGTH];
time_t current_time; /* Time of this pulse */
time_t boot_time; /* Time of this pulse */
char copy_time[MAX_INPUT_LENGTH];
time_t current_time; /* Time of this pulse */
time_t boot_time; /* Time of this pulse */
time_t hboot_time; /* Time of this pulse */
HOUR_MIN_SEC set_boot_time_struct;
HOUR_MIN_SEC * set_boot_time;
struct tm * new_boot_time;
time_t new_boot_time_t;
struct tm new_boot_struct;
int arena; /* State of the Arena */
int min_kingdom_members;
int world_affects = 0; /* World Affect bits */
int bootcount = 0; /* Used for timed reboots */
int nosafecount = 0; /* Used for timed reboots */
int dailycount = DAILYCOUNT;
int copycount = 0; /* Used for timed copyovers */
int doublecount = 0; /* Double Exp Timer */
int chars_logged_in; /* Stores the types of char */
int total_number_login; /* Stores the total logins */
int high_number_login; /* Stores most logins at once */
char first_place[40]; /* Name of best score on */
char second_place[40]; /* Name of 2nd best score on */
char third_place[40]; /* Name of 3rd best score on */
long long int score_1 = 0; /* Actual scores */
long long int score_2 = 0; /* Actual scores */
long long int score_3 = 0; /* Actual scores */
int decaps = 0; /* Total Decaps This Boot */
int proc_pid = 0;
int pulse_weather = PULSE_WEATHER; /* Used to keep time steady */
WIZCONFIG_DATA *WizConfig; /* WizConfig, obviously ;) */
bool quest; /* Is there a quest running? */
bool auto_quest; /* Quests start on their own? */
CHAR_DATA *quest_mob; /* Mob which started quest */
CHAR_DATA *quest_target; /* Target of the quest */
OBJ_DATA *aquest_object; /* Object to recover */
int quest_timer; /* Time left to get object */
int quest_wait = 0; /* Min time until next quest */
sh_int quest_personality; /* mob's crusade personality :) */
int mudinfo[MUDINFO_MAX];
#define PK_RANGE WizConfig->paradoxlimit
/* Colour scale char list - Calamar */
bool fCopyOver = 0;
char *scale[SCALE_COLS] = {
L_RED,
L_BLUE,
L_GREEN,
YELLOW
};
/*
* OS-dependent local functions.
*/
#if defined(macintosh) || defined(MSDOS)
void game_loop_mac_msdos args ((void));
bool read_from_descriptor args ((DESCRIPTOR_DATA * d));
bool write_to_descriptor args ((DESCRIPTOR_DATA * d, char *txt, int length));
#endif
#if defined(unix)
void game_loop_unix args ((int control));
int init_socket args ((int port));
void new_descriptor args ((int control));
bool read_from_descriptor args ((DESCRIPTOR_DATA * d));
bool write_to_descriptor args ((DESCRIPTOR_DATA * d, char *txt, int length));
#endif
extern bool SLOWNS;
/*
* Other local functions (OS-independent).
*/
bool check_playing2 args ((DESCRIPTOR_DATA * d, char *name));
bool check_playing args ((DESCRIPTOR_DATA * d, char *name));
bool check_reconnect args ((DESCRIPTOR_DATA * d, char *name, bool fConn));
bool check_kickoff args ((DESCRIPTOR_DATA * d, char *name, bool fConn));
int main args ((int argc, char **argv));
void nanny args ((DESCRIPTOR_DATA * d, char *argument));
bool process_output args ((DESCRIPTOR_DATA * d, bool fPrompt));
void read_from_buffer args ((DESCRIPTOR_DATA * d));
void stop_idling args ((CHAR_DATA * ch));
void bust_a_prompt args ((DESCRIPTOR_DATA * d));
void call_all args ((CHAR_DATA * ch));
const char *versionToString (int version);
int find_arti_pos args ((int vnum));
void init_signals (void)
{
signal (SIGBUS, crashrecov);
signal (SIGSEGV, crashrecov);
signal (SIGILL, crashrecov);
signal (SIGINT, crashrecov);
signal (SIGFPE, crashrecov);
signal (SIGUSR1, crashrecov);
signal (SIGTERM, crashrecov);
signal (SIGABRT, crashrecov);
signal (SIGTERM, panic_shutdown);
}
void do_crashmud (CHAR_DATA * ch, char *argument)
{
return;
}
struct tm *update_time(struct tm *old_time)
{
time_t time;
time = mktime(old_time);
return localtime(&time);
}
int port, control, opt;
int main (int argc, char **argv)
{
struct timeval now_time;
/*
* Memory debugging if needed.
*/
#if defined(MALLOC_DEBUG)
malloc_debug (2);
#endif
#ifdef RLIMIT_NOFILE
#ifndef min
# define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
{
struct rlimit rlp;
(void) getrlimit (RLIMIT_NOFILE, &rlp);
rlp.rlim_cur = min (rlp.rlim_max, FD_SETSIZE);
(void) setrlimit (RLIMIT_NOFILE, &rlp);
}
#endif
proc_pid = getpid ();
/*
* Init time and encryption.
*/
gettimeofday (&now_time, NULL);
current_time = (time_t) now_time.tv_sec;
// strcpy (str_boot_time, ctime (¤t_time));
// strcpy (copy_time, ctime (¤t_time));
strcpy( str_boot_time, new_date( current_time ) );
strcpy( copy_time, new_date( current_time ) );
boot_time = current_time;
hboot_time = current_time;
strcpy (crypt_pwd, "MaHXsRntBBTe6");
strcpy (first_place, "No One");
strcpy (second_place, "No One");
strcpy (third_place, "No One");
/*
* Init boot time.
*/
set_boot_time = &set_boot_time_struct;
set_boot_time->manual = 0;
new_boot_time = update_time(localtime(¤t_time));
/* Copies *new_boot_time to new_boot_struct, and then points
new_boot_time to new_boot_struct again. -- Alty */
new_boot_struct = *new_boot_time;
new_boot_time = &new_boot_struct;
new_boot_time->tm_mday += 1;
if (new_boot_time->tm_hour > 12)
new_boot_time->tm_mday += 1;
new_boot_time->tm_sec = 0;
new_boot_time->tm_min = 0;
new_boot_time->tm_hour = 6;
/* Update new_boot_time (due to day increment) */
new_boot_time = update_time(new_boot_time);
new_boot_struct = *new_boot_time;
new_boot_time = &new_boot_struct;
new_boot_time_t = mktime(new_boot_time);
immspar = FALSE;
balancing = FALSE; /* knocks off weapon flags when TRUE, for immspar */
/*
* Macintosh console initialization.
*/
#if defined(macintosh)
console_options.nrows = 31;
cshow (stdout);
csetmode (C_RAW, stdin);
cecho2file ("log file", 1, stderr);
#endif
/*
* Reserve one channel for our use.
*/
if ((fpReserve = fopen (NULL_FILE, "r")) == NULL)
{
perror (NULL_FILE);
exit (1);
}
/*
* Get the port number.
*/
port = 6500;
if (argc > 1)
{
if (!is_number (argv[1]))
{
fprintf (stderr, "Usage: %s [port #]\n", argv[0]);
exit (1);
}
else if ((port = atoi (argv[1])) <= 1024)
{
fprintf (stderr, "Port number must be above 1024.\n");
exit (1);
}
/* Are we recovering from a copyover? */
if (argv[2] && argv[2][0])
{
fCopyOver = 1;
control = atoi (argv[3]);
}
else
{
fCopyOver = 0;
}
}
//here
/*
* Start IMC and ICE
*/
/*
* Run the game.
*/
#if defined(macintosh) || defined(MSDOS)
boot_db (fCopyOver);
log_string ("God Wars is ready to rock.", NULL);
game_loop_mac_msdos ();
#endif
#if defined(unix)
if (!fCopyOver)
control = init_socket (port);
boot_db (fCopyOver);
log_string ("Wiping Inactive Pfiles", NULL);
wipe_pfiles ();
if (!fCopyOver)
{
sprintf (log_buf, "Legend of Chystancia is ready on port %d.", port);
log_string (log_buf, NULL);
}
else
{
sprintf (str_boot_time, "%s", argv[4]);
hboot_time = atol (argv[5]);
sprintf (log_buf,
"Legend of Chrystancia has recovered from the Copyover.");
log_string (log_buf, NULL);
}
game_loop_unix (control);
close (control);
#endif
/*
* That's all, folks.
*/
log_string ("Normal termination of game.", NULL);
exit (0);
return 0;
}
#if defined(unix)
int init_socket (int port)
{
static struct sockaddr_in sa_zero;
struct sockaddr_in sa;
int x = 1;
int fd;
if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
{
perror ("Init_socket: socket");
exit (1);
}
if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *) &x, sizeof (x)) < 0)
{
perror ("Init_socket: SO_REUSEADDR");
close (fd);
exit (1);
}
#if defined(SO_DONTLINGER) && !defined(SYSV)
{
struct linger ld;
ld.l_onoff = 1;
ld.l_linger = 1000;
if ( setsockopt( fd, SOL_SOCKET, SO_DONTLINGER,
(char *) &ld, sizeof(ld) ) < 0 )
{
perror( "Init_socket: SO_DONTLINGER" );
close( fd );
exit( 1 );
}
}
#endif
sa = sa_zero;
sa.sin_family = AF_INET;
sa.sin_port = htons (port);
if (bind (fd, (struct sockaddr *) &sa, sizeof (sa)) < 0)
{
perror ("Init_socket: bind");
close (fd);
exit (1);
}
if (listen (fd, 3) < 0)
{
perror ("Init_socket: listen");
close (fd);
exit (1);
}
return fd;
}
#endif
#if defined(unix)
void excessive_cpu (int blx)
{
CHAR_DATA *vch;
CHAR_DATA *vch_next;
for (vch = char_list; vch != NULL; vch = vch_next)
{
vch_next = vch->next;
if (!IS_NPC (vch))
{
send_to_char
("Mud frozen: Autosave and quit. The mud will reboot in 2 seconds.\n\r",
vch);
do_quit (vch, "");
}
}
exit (1);
}
void game_loop_unix (int control)
{
static struct timeval null_time;
struct timeval last_time;
signal (SIGPIPE, SIG_IGN);
gettimeofday (&last_time, NULL);
current_time = (time_t) last_time.tv_sec;
/* Main loop */
while (!merc_down)
{
fd_set in_set;
fd_set out_set;
fd_set exc_set;
DESCRIPTOR_DATA *d;
int maxdesc;
//// FIRST JUMP POINT ////
setjmp (safepoint);
init_signals ();
#if defined(MALLOC_DEBUG)
if (malloc_verify () != 1)
abort ();
#endif
/*
* Poll all active descriptors.
*/
FD_ZERO (&in_set);
FD_ZERO (&out_set);
FD_ZERO (&exc_set);
FD_SET (control, &in_set);
maxdesc = control;
for (d = first_descriptor; d != NULL; d = d->next)
{
maxdesc = UMAX (maxdesc, d->descriptor);
FD_SET (d->descriptor, &in_set);
FD_SET (d->descriptor, &out_set);
FD_SET (d->descriptor, &exc_set);
if( d->ifd != -1 && d->ipid != -1 )
{
maxdesc = UMAX( maxdesc, d->ifd );
FD_SET( d->ifd, &in_set );
}
}
if (select (maxdesc + 1, &in_set, &out_set, &exc_set, &null_time) < 0)
{
perror ("Game_loop: select: poll");
exit (1);
}
/*
* New connection?
*/
if (FD_ISSET (control, &in_set))
new_descriptor (control);
/*
* Kick out the freaky folks.
*/
for (d = first_descriptor; d != NULL; d = d_next)
{
d_next = d->next;
if (FD_ISSET (d->descriptor, &exc_set))
{
FD_CLR (d->descriptor, &in_set);
FD_CLR (d->descriptor, &out_set);
if (d->character)
save_char_obj (d->character);
d->outtop = 0;
close_socket (d);
}
}
/*
//// FIRST JUMP POINT ////
setjmp(safepoint);init_signals();
*/
/*
* Process input.
*/
for (d = first_descriptor; d != NULL; d = d_next)
{
d_next = d->next;
d->fcommand = FALSE;
if (FD_ISSET (d->descriptor, &in_set))
{
if (d->character != NULL)
d->character->timer = 0;
if (!read_from_descriptor (d))
{
FD_CLR (d->descriptor, &out_set);
if (d->character != NULL)
save_char_obj (d->character);
d->outtop = 0;
close_socket (d);
continue;
}
}
/* check for input from the dns */
if( ( d->connected == CON_PLAYING || d->character != NULL ) && d->ifd != -1 && FD_ISSET( d->ifd, &in_set ) )
process_dns( d );
if (d->character != NULL && d->character->wait > 0)
{
--d->character->wait;
continue;
}
read_from_buffer (d);
if (d->incomm[0] != '\0')
{
d->fcommand = TRUE;
stop_idling (d->character);
if (d->showstr_point)
show_string (d, d->incomm);
else if (d->pString != NULL)
string_add (d->character, d->incomm); /* OLC */
else
{
switch (d->connected)
{
case CON_PFILE:
jope_interp (d->character, d->incomm);
break;
case CON_PLAYING:
interpret (d->character, d->incomm);
break;
/*
case CON_KEDITOR:
kedit (d->character, d->incomm);
break;
*/
case CON_AEDITOR:
aedit (d->character, d->incomm);
break;
case CON_REDITOR:
redit (d->character, d->incomm);
break;
case CON_OEDITOR:
oedit (d->character, d->incomm);
break;
case CON_MEDITOR:
medit (d->character, d->incomm);
break;
case CON_HEDITOR:
hedit (d->character, d->incomm);
break;
default:
nanny (d, d->incomm);
break;
}
}
d->incomm[0] = '\0';
}
}
/*
* Autonomous game motion.
*/
update_handler ();
/*
* Output.
*/
for (d = first_descriptor; d != NULL; d = d_next)
{
d_next = d->next;
if ((d->fcommand || d->outtop > 0)
&& FD_ISSET (d->descriptor, &out_set))
{
if (!process_output (d, TRUE))
{
if (d->character != NULL)
save_char_obj (d->character);
d->outtop = 0;
close_socket (d);
}
}
}
/*
* Synchronize to a clock.
* Sleep( last_time + 1/PULSE_PER_SECOND - now ).
* Careful here of signed versus unsigned arithmetic.
*/
{
struct timeval now_time;
long secDelta;
long usecDelta;
gettimeofday (&now_time, NULL);
usecDelta = ((int) last_time.tv_usec) - ((int) now_time.tv_usec)
+ 1000000 / PULSE_PER_SECOND;
secDelta = ((int) last_time.tv_sec) - ((int) now_time.tv_sec);
while (usecDelta < 0)
{
usecDelta += 1000000;
secDelta -= 1;
}
while (usecDelta >= 1000000)
{
usecDelta -= 1000000;
secDelta += 1;
}
if (secDelta > 0 || (secDelta == 0 && usecDelta > 0))
{
struct timeval stall_time;
stall_time.tv_usec = usecDelta;
stall_time.tv_sec = secDelta;
if (select (0, NULL, NULL, NULL, &stall_time) < 0)
{
perror ("Game_loop: select: stall");
exit (1);
}
}
}
gettimeofday (&last_time, NULL);
current_time = (time_t) last_time.tv_sec;
}
return;
}
#endif
char *txtconstate (int con)
{
char buf[MSL];
switch (con)
{
case 1:
sprintf (buf, "CON_PLAYING");
break;
case 2:
sprintf (buf, "CON_GET_NAME");
break;
case 3:
sprintf (buf, "CON_GET_OLD_PASSWORD");
break;
case 4:
sprintf (buf, "CON_CONFIRM_NEW_NAME");
break;
case 5:
sprintf (buf, "CON_CONFIRM_NEW_PASSWORD");
break;
case 6:
sprintf (buf, "CON_GET_NEW_SEX");
break;
case 7:
sprintf (buf, "CON_GET_NEW_CLASS");
break;
case 8:
sprintf (buf, "CON_READ_MOTD");
break;
case 9:
sprintf (buf, "CON_NOT_PLAYING");
break;
case 10:
sprintf (buf, "CON_GET_NEW_ANSI");
break;
case 11:
sprintf (buf, "CON_COPYOVER_RECOVER");
break;
case -1:
sprintf (buf, "CON_AEDITOR");
break;
case -2:
sprintf (buf, "CON_REDITOR");
break;
case -3:
sprintf (buf, "CON_MEDITOR");
break;
case -4:
sprintf (buf, "CON_OEDITOR");
break;
case 14:
sprintf (buf, "CON_NOTE_TO");
break;
case 15:
sprintf (buf, "CON_NOTE_SUBJECT");
break;
case 16:
sprintf (buf, "CON_NOTE_EXPIRE");
break;
case 17:
sprintf (buf, "CON_NOTE_TEXT");
break;
case 18:
sprintf (buf, "CON_NOTE_FINISH");
break;
default:
sprintf (buf, "Unknown");
break;
}
return str_dup (buf);
}
void uptime (DESCRIPTOR_DATA * d)
{
extern char str_boot_time[];
extern char copy_time[];
extern time_t boot_time;
extern time_t hboot_time;
extern time_t current_time;
int days;
int hours;
int minutes;
int seconds;
int tdays;
int thours;
int tminutes;
int tseconds;
int time;
int ttime;
DESCRIPTOR_DATA *dcheck;
int c_plr = 0;
char buf[MAX_STRING_LENGTH];
char boot[MAX_STRING_LENGTH];
char tboot[MAX_STRING_LENGTH];
time = (int) (current_time - boot_time);
ttime = (int) (current_time - hboot_time);
days = (time / 86400);
hours = ((time / 3600) % 24);
minutes = ((time / 60) % 60);
seconds = ((time) % 60);
tdays = (ttime / 86400);
thours = ((ttime / 3600) % 24);
tminutes = ((ttime / 60) % 60);
tseconds = ((ttime) % 60);
for (dcheck = first_descriptor; dcheck; dcheck = dcheck->next)
{
if (dcheck->connected != CON_PLAYING)
continue;
if (IS_IMMORTAL (dcheck->character))
continue;
c_plr++;
}
if (days > 0)
{
sprintf (boot,
"#r%d #eday%s, #r%d #ehour%s, #r%d #eminute%s, #r%d #esecond%s ago",
days, days == 1 ? "" : "s", hours, hours == 1 ? "" : "s",
minutes, minutes == 1 ? "" : "s", seconds,
seconds == 1 ? "" : "s");
}
else if (hours > 0)
{
sprintf (boot,
"#r%d #ehour%s, #r%d #eminute%s,#r%d #esecond%s ago",
hours, hours == 1 ? "" : "s", minutes,
minutes == 1 ? "" : "s", seconds, seconds == 1 ? "" : "s");
}
else if (minutes > 0)
{
sprintf (boot,
"#r%d #eminute%s, #r%d #esecond%s ago", minutes,
minutes == 1 ? "" : "s", seconds, seconds == 1 ? "" : "s");
}
else
{
sprintf (boot, "#r%d#e second%s ago", seconds, seconds == 1 ? "" : "s");
}
if (tdays > 0)
{
sprintf (tboot,
"#r%d #eday%s, #r%d #ehour%s, #r%d #eminute%s, #r%d #esecond%s ago",
tdays, tdays == 1 ? "" : "s", thours, thours == 1 ? "" : "s",
tminutes, tminutes == 1 ? "" : "s", tseconds,
tseconds == 1 ? "" : "s");
}
else if (thours > 0)
{
sprintf (tboot,
"#r%d #ehour%s, #r%d #eminute%s,#r%d #esecond%s ago",
thours, thours == 1 ? "" : "s", tminutes,
tminutes == 1 ? "" : "s", tseconds, tseconds == 1 ? "" : "s");
}
else if (tminutes > 0)
{
sprintf (tboot,
"#r%d #eminute%s, #r%d #esecond%s ago", tminutes,
tminutes == 1 ? "" : "s", tseconds, tseconds == 1 ? "" : "s");
}
else
{
sprintf (tboot,
"#r%d#e second%s ago", tseconds, tseconds == 1 ? "" : "s");
}
sprintf (buf, "#wLast Startup: #r%s #e(%s)\n\r",
(str_boot_time), tboot);
write_to_buffer (d, buf, 0);
sprintf (buf, "#wLast Copyover: #r%s #e(%s)\n\r",
(copy_time), boot);
write_to_buffer (d, buf, 0);
sprintf (buf, "#wSystem Time: #r%s\n\r", new_date (current_time));
write_to_buffer (d, buf, 0);
sprintf(buf, "#wCurrent Status Window: #r%d\n\r", WizConfig->paradoxlimit);
write_to_buffer (d, buf, 0);
sprintf(buf, "#wPlayers Online: #r%d\n\r", c_plr);
write_to_buffer (d, buf, 0);
sprintf(buf, "\n\r");
write_to_buffer(d,buf,0);
write_to_buffer(d, "[#e?#w] #rThy name that thou wish to die by: #n", 0);
}
#if defined(unix)
void new_descriptor (int control)
{
char buf[MAX_STRING_LENGTH];
DESCRIPTOR_DATA *dnew;
struct sockaddr_in sock;
struct hostent *from;
// int desc;
// int size;
size_t desc, size;
size = sizeof(sock);
getsockname( control, (struct sockaddr *) &sock, &size );
if ( ( desc = accept( control, (struct sockaddr *) &sock, &size) ) < 0 )
{
perror( "New_descriptor: accept" );
return;
}
#if !defined(FNDELAY)
#define FNDELAY O_NDELAY
#endif
if ( fcntl( desc, F_SETFL, FNDELAY ) == -1 )
{
perror( "New_descriptor: fcntl: FNDELAY" );
return;
}
/*
* Cons a new descriptor.
*/
if ( descriptor_free == NULL )
{
dnew = alloc_perm( sizeof(*dnew) );
}
else
{
dnew = descriptor_free;
descriptor_free = descriptor_free->next;
}
init_descriptor (dnew, desc);
size = sizeof(sock);
if ( getpeername( desc, (struct sockaddr *) &sock, &size ) < 0 )
{
perror( "New_descriptor: getpeername" );
dnew->host = str_dup( "(unknown)" );
}
else
{
/*
* Would be nice to use inet_ntoa here but it takes a struct arg,
* which ain't very compatible between gcc and system libraries.
*/
char addr[MAX_STRING_LENGTH];
addr[0] = '\0';
sprintf( addr, inet_ntoa( sock.sin_addr ) );
if (!str_cmp(addr, "127.0.0.1"))
dnew->host = str_dup( addr );
else
{
dnew->host = STRALLOC( addr );
if (str_cmp(addr, "127.0.0.1"))
{
sprintf( log_buf, "Sock.sinaddr: %s", addr );
log_string( log_buf, 0 );
}
buf[0] = '\0';
strcpy( buf, in_dns_cache( addr ) );
if( buf[0] == '\0' )
resolve_dns( dnew, sock.sin_addr.s_addr );
else
{
free_string( dnew->host );
dnew->host = STRALLOC( buf );
}
}
from = NULL;
}
/*
* Init descriptor data.
*/
/*
dnew->next = first_descriptor;
first_descriptor = dnew;
*/
LINK(dnew, first_descriptor, last_descriptor, next, prev);
if (check_ban (dnew))
{
close_socket (dnew);
return;
}
/* MCCP */
write_to_buffer (dnew, compress_will2, 0);
write_to_buffer (dnew, compress_will, 0);
write_to_buffer (dnew, mxp_will, 0);
sprintf(buf, "#wVersion: #r%s #wBuild: #r%d #wLast Update : #r%s#n\n\r", versionToString (VERSION), LINKCOUNT, compdate(COMPILE_TIME));
write_to_buffer(dnew, buf, 0);
/*
* Send the greeting.
* Mac - Random Greetings
*/
{
extern char *help_greeting;
extern char *help_greeting1;
extern char *help_greeting2;
extern char *help_greeting3;
extern char *help_greeting4;
extern char *help_greeting5;
extern char *help_greeting6;
switch (number_range (0, 6))
{
default:
if (help_greeting[0] == '.')
write_to_buffer (dnew, help_greeting + 1, 0);
else
write_to_buffer (dnew, help_greeting, 0);
break;
case 0:
if (help_greeting[0] == '.')
write_to_buffer (dnew, help_greeting + 1, 0);
else
write_to_buffer (dnew, help_greeting, 0);
break;
case 1:
if (help_greeting1[0] == '.')
write_to_buffer (dnew, help_greeting1 + 1, 0);
else
write_to_buffer (dnew, help_greeting1, 0);
break;
case 2:
if (help_greeting2[0] == '.')
write_to_buffer (dnew, help_greeting2 + 1, 0);
else
write_to_buffer (dnew, help_greeting3, 0);
break;
case 3:
if (help_greeting3[0] == '.')
write_to_buffer (dnew, help_greeting3 + 1, 0);
else
write_to_buffer (dnew, help_greeting3, 0);
break;
case 4:
if (help_greeting4[0] == '.')
write_to_buffer (dnew, help_greeting4 + 1, 0);
else
write_to_buffer (dnew, help_greeting4, 0);
break;
case 5:
if (help_greeting5[0] == '.')
write_to_buffer (dnew, help_greeting5 + 1, 0);
else
write_to_buffer (dnew, help_greeting5, 0);
break;
case 6:
if (help_greeting6[0] == '.')
write_to_buffer (dnew, help_greeting6 + 1, 0);
else
write_to_buffer (dnew, help_greeting6, 0);
break;
}
}
extern char *help_lowcredits;
if (help_lowcredits[0] == '.')
write_to_buffer (dnew, help_lowcredits + 1, 0);
else
write_to_buffer (dnew, help_lowcredits, 0);
// close_socket(dnew);
uptime (dnew);
return;
}
#endif
void init_descriptor (DESCRIPTOR_DATA * dnew, int desc)
{
static DESCRIPTOR_DATA d_zero;
*dnew = d_zero;
dnew->descriptor = desc;
dnew->connected = CON_GET_NAME;
dnew->showstr_head = str_dup ("");
dnew->showstr_point = 0;
dnew->outsize = 2000;
dnew->pEdit = NULL; /* OLC */
dnew->pString = NULL; /* OLC */
dnew->outbuf = alloc_mem (dnew->outsize);
dnew->ifd = -1; /* Descriptor pipes, used for DNS resolution and such */
dnew->ipid = -1;
dnew->login = D_LOGIN_TIME;
dnew->total_login = D_TOTAL_LOGIN_TIME;
dnew->mxp = FALSE;
}
void close_socket (DESCRIPTOR_DATA * dclose)
{
CHAR_DATA *ch;
char buf[MAX_STRING_LENGTH];
if( dclose->ipid != -1 )
{
int status;
kill( dclose->ipid, SIGKILL );
waitpid( dclose->ipid, &status, 0 );
}
if( dclose->ifd != -1 )
close( dclose->ifd );
if (dclose->outtop > 0)
process_output (dclose, FALSE);
if (dclose->snoop_by != NULL)
{
write_to_buffer (dclose->snoop_by,
"Your victim has left the game.\n\r", 0);
}
if (dclose->connected < CON_PLAYING)
{
dclose->pEdit = NULL;
dclose->connected = CON_PLAYING;
}
if (dclose->character != NULL && dclose->connected == CON_PLAYING &&
IS_NPC (dclose->character))
do_return (dclose->character, "");
if (dclose->connected == CON_PFILE)
jope_done (dclose->character, "");
{
DESCRIPTOR_DATA *d;
for (d = first_descriptor; d != NULL; d = d->next)
{
if (d->snoop_by == dclose)
d->snoop_by = NULL;
}
}
if ((ch = dclose->character) != NULL)
{
if (dclose->character->fight_timer > 0)
sprintf (log_buf, "Closing link to %s (Fight Timer).", ch->name);
else if (dclose->character->position == POS_FIGHTING)
sprintf (log_buf, "Closing link to %s (Fighting).", ch->name);
else
sprintf (log_buf, "Closing link to %s.", ch->name);
log_string_sil (log_buf);
wiznet (NULL, WIZ_LOGINS, 7, log_buf);
/* If ch is writing note or
playing, just lose link otherwise clear char */
if ((dclose->connected == CON_PLAYING) ||
((dclose->connected >= CON_NOTE_TO) &&
(dclose->connected <= CON_NOTE_FINISH)))
{
if (IS_NPC (ch) || ch->pcdata->obj_vnum == 0)
act ("$n has lost $s link.", ch, NULL, NULL, TO_ROOM);
//log_string("Not Cleared.", ch);
if (IS_SET (ch->flag2, AFF2_INARENA)
|| IS_SET (ch->flag2, AFF2_CHALLENGED)
|| IS_SET (ch->flag2, AFF2_CHALLENGER))
{
REMOVE_BIT (ch->flag2, AFF2_CHALLENGED);
REMOVE_BIT (ch->flag2, AFF2_CHALLENGER);
REMOVE_BIT (ch->flag2, AFF2_INARENA);
undo_arena (ch);
arena = FIGHT_CLEAR;
sprintf (buf, "The arena is no longer busy!");
do_info (ch, buf);
{
DESCRIPTOR_DATA *d;
for (d = first_descriptor; d; d = d->next)
if (d->connected == CON_PLAYING)
{
stc ("Due to loss of link of challenger, the Arena has been cleared!\n\r", ch);
}
}
}
if (IS_SET (ch->newbits, NEW_NOTEWRITE))
REMOVE_BIT (ch->newbits, NEW_NOTEWRITE);
if (!IS_NPC (ch) && ch->pcdata->chobj != NULL)
strip_obj (ch);
ch->desc = NULL;
}
else
{
free_char (dclose->character, FALSE);
}
}
if ( d_next == dclose )
d_next = d_next->next;
/*
if (dclose == first_descriptor)
{
first_descriptor = first_descriptor->next;
}
else
{
DESCRIPTOR_DATA *d;
for (d = first_descriptor; d && d->next != dclose; d = d->next)
;
if (d != NULL)
d->next = dclose->next;
else
bug ("Close_socket: dclose not found.", 0);
}
*/
UNLINK(dclose, first_descriptor, last_descriptor, next, prev);
compressEnd (dclose, TELOPT_COMPRESS2, TRUE);
compressEnd (dclose, TELOPT_COMPRESS, TRUE);
close (dclose->descriptor);
free_string (dclose->host);
/* RT socket leak fix */
free_mem (dclose->outbuf, dclose->outsize);
dclose->next = descriptor_free;
descriptor_free = dclose;
#if defined(MSDOS) || defined(macintosh)
exit (1);
#endif
return;
}
/* For a better kickoff message :) KaVir */
void close_socket2 (DESCRIPTOR_DATA * dclose, bool kickoff)
{
CHAR_DATA *ch;
if( dclose->ipid != -1 )
{
int status;
kill( dclose->ipid, SIGKILL );
waitpid( dclose->ipid, &status, 0 );
}
if( dclose->ifd != -1 )
close( dclose->ifd );
if (dclose->outtop > 0)
process_output (dclose, FALSE);
if (dclose->snoop_by != NULL)
{
write_to_buffer (dclose->snoop_by,
"Your victim has left the game.\n\r", 0);
}
if (dclose->connected < CON_PLAYING)
{
dclose->pEdit = NULL;
dclose->connected = CON_PLAYING;
}
if (dclose->character != NULL && dclose->connected == CON_PLAYING &&
IS_NPC (dclose->character))
do_return (dclose->character, "");
if (dclose->connected == CON_PFILE)
jope_done (dclose->character, "");
{
DESCRIPTOR_DATA *d;
for (d = first_descriptor; d != NULL; d = d->next)
{
if (d->snoop_by == dclose)
d->snoop_by = NULL;
}
}
if ((ch = dclose->character) != NULL)
{
if (dclose->connected == CON_PLAYING)
{
if (kickoff)
act ("$n doubles over in agony and $s eyes roll up into $s head.",
ch, NULL, NULL, TO_ROOM);
save_char_obj (ch);
ch->desc = NULL;
}
else
{
free_char (dclose->character, FALSE);
}
}
if (d_next == dclose)
d_next = d_next->next;
if (dclose == first_descriptor)
{
first_descriptor = first_descriptor->next;
}
else
{
DESCRIPTOR_DATA *d;
for (d = first_descriptor; d && d->next != dclose; d = d->next)
;
if (d != NULL)
d->next = dclose->next;
else
bug ("Close_socket: dclose not found.", 0);
}
UNLINK(dclose, first_descriptor, last_descriptor, next, prev);
compressEnd (dclose, TELOPT_COMPRESS2, TRUE);
compressEnd (dclose, TELOPT_COMPRESS, TRUE);
close (dclose->descriptor);
free_string (dclose->host);
dclose->next = descriptor_free;
descriptor_free = dclose;
#if defined(MSDOS) || defined(macintosh)
exit (1);
#endif
return;
}
void ch_printf( CHAR_DATA *ch, char *fmt, ... )
{
char buf [ MAX_STRING_LENGTH ];
va_list args;
va_start ( args, fmt );
vsprintf ( buf, fmt, args );
va_end ( args );
stc( buf, ch );
return;
}
bool read_from_descriptor (DESCRIPTOR_DATA * d)
{
int iStart;
/* Hold horses if pending command already. */
if (d->incomm[0] != '\0')
return TRUE;
if (d->connected == CON_NOT_PLAYING)
return TRUE;
/* Check for overflow. */
iStart = strlen (d->inbuf);
if (iStart >= sizeof (d->inbuf) - 10)
{
if (d != NULL && d->character != NULL)
sprintf (log_buf, "%s input overflow!", d->character->lasthost);
else
sprintf (log_buf, "%s input overflow!", d->host);
log_string (log_buf, d->character);
write_to_descriptor (d, "\n\r*** PUT A LID ON IT!!! ***\n\r", 0);
return FALSE;
}
/* Snarf input. */
#if defined(macintosh)
for (;;)
{
int c;
c = getc (stdin);
if (c == '\0' || c == EOF)
break;
putc (c, stdout);
if (c == '\r')
putc ('\n', stdout);
d->inbuf[iStart++] = c;
if (iStart > sizeof (d->inbuf) - 10)
break;
}
#endif
#if defined(MSDOS) || defined(unix)
for (;;)
{
int nRead;
nRead = read (d->descriptor, d->inbuf + iStart,
sizeof (d->inbuf) - 10 - iStart);
if (nRead > 0)
{
iStart += nRead;
if (d->inbuf[iStart - 1] == '\n' || d->inbuf[iStart - 1] == '\r')
break;
}
else if (nRead == 0)
{
log_string_sil ("EOF encountered on read.");
return FALSE;
}
else if (errno == EWOULDBLOCK)
break;
else
{
perror ("Read_from_descriptor");
return FALSE;
}
}
#endif
d->inbuf[iStart] = '\0';
return TRUE;
}
/*
* Transfer one line from input buffer to input line.
*/
void read_from_buffer (DESCRIPTOR_DATA * d)
{
int i, j, k;
/*
* Hold horses if pending command already.
*/
if (d->incomm[0] != '\0')
return;
//current_player = d;
/*
* Look for at least one new line.
*/
for (i = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r'; i++)
{
if (d->inbuf[i] == '\0')
return;
}
/*
* Canonical input processing.
*/
for (i = 0, k = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r'; i++)
{
if (k >= MAX_INPUT_LENGTH - 2)
{
write_to_descriptor (d, "Line too long.\n\r", 0);
/* skip the rest of the line */
for (; d->inbuf[i] != '\0'; i++)
{
if (d->inbuf[i] == '\n' || d->inbuf[i] == '\r')
break;
}
d->inbuf[i] = '\n';
d->inbuf[i + 1] = '\0';
break;
}
if (d->inbuf[i] == '\b' && k > 0)
--k;
else if (d->inbuf[i] == (signed char) IAC)
{
if (!memcmp (&d->inbuf[i], compress_do, strlen (compress_do)))
{
i += strlen (compress_do) - 1;
compressStart (d, TELOPT_COMPRESS); /* enable mccp version 1 */
}
else if (!memcmp (&d->inbuf[i], compress_do2, strlen (compress_do2)))
{
i += strlen (compress_do2) - 1;
compressStart (d, TELOPT_COMPRESS2); /* enable mccp version 2 */
}
if (!memcmp (&d->inbuf[i], compress_dont, strlen (compress_dont)))
{
i += strlen (compress_dont) - 1;
compressEnd (d, TELOPT_COMPRESS, FALSE); /* disable mccp version 1 */
}
else
if (!memcmp
(&d->inbuf[i], compress_dont2, strlen (compress_dont2)))
{
i += strlen (compress_dont2) - 1;
compressEnd (d, TELOPT_COMPRESS2, FALSE); /* disable mccp version 2 */
}
else if (!memcmp (&d->inbuf[i], mxp_do, strlen (mxp_do)))
{
i += strlen (mxp_do) - 1;
init_mxp (d);
}
else if (!memcmp (&d->inbuf[i], mxp_dont, strlen (mxp_dont)))
{
i += strlen (mxp_dont) - 1;
shutdown_mxp (d);
}
}
else if (isascii (d->inbuf[i]) &&
(isprint (d->inbuf[i]) || d->inbuf[i] == 'Æ'))
d->incomm[k++] = d->inbuf[i];
/* handling vt100 feedback * */
else if (d->inbuf[i] == '\e')
{
char xbuf[30]; // plenty
char *xptr;
int xk = 1;
xbuf[0] = '\0';
xptr = xbuf;
while (d->inbuf[i + xk] != 'R' && xk < 10)
xk++;
if (xk < 10)
{
i += 2;
xk = 0;
while (d->inbuf[i] != ';' && d->inbuf[i] != '\0' && ++xk < 30)
{
*xptr = d->inbuf[i];
xptr++;
i++;
}
*xptr = '\0';
init_vt100 (d, xbuf);
}
}
}
/*
* Finish off the line.
*/
if (k == 0)
d->incomm[k++] = ' ';
d->incomm[k] = '\0';
/*
* Deal with bozos with #repeat 1000 ...
*/
if (k > 1 || d->incomm[0] == '!')
{
if (d->incomm[0] != '!' && strcmp (d->incomm, d->inlast))
{
if (d->repeat > 6 && strlen(d->inlast) > 5)
{
sprintf(log_buf,"%s input spam[%d]: %s", d->character ? d->character->name: "", d->repeat + 1, d->inlast);
wiznet(d->character, WIZ_SPAM, 7, log_buf);
}
d->repeat = 0;
}
else
{
if (++d->repeat >= 40 && d->character && d->connected == CON_PLAYING)
{
if (!IS_IMMORTAL(d->character))
{
write_to_buffer(d, "\n\r*** PUT A LID ON IT !!! ***\n\r", 0);
d->repeat = 0;
close_socket(d);
}
sprintf(log_buf,"%s input spam[%d]: %s", d->character ? d->character->name: "", d->repeat + 1, d->inlast);
wiznet(d->character, WIZ_SPAM, 7, log_buf);
}
}
}
/*
* Do '!' substitution.
*/
if (d->incomm[0] == '!')
strcpy (d->incomm, d->inlast);
else
strcpy (d->inlast, d->incomm);
/*
* Shift the input buffer.
*/
while (d->inbuf[i] == '\n' || d->inbuf[i] == '\r')
i++;
for (j = 0; (d->inbuf[j] = d->inbuf[i + j]) != '\0'; j++)
;
return;
}
/* Commarize */
char *set_comma (long long init)
{
char buf[MSL];
char buf2[MSL];
char argument[MSL];
char *string;
int x;
int y;
int z;
sprintf (argument, "%lli", init);
buf[0] = '\0';
buf2[0] = '\0';
if (strlen (argument) <= 3)
sprintf (buf, "%s", argument);
if (strlen (argument) > 3)
{
x = strlen (argument) % 3;
if (x == 0)
x = 3;
y = 0;
while (y != x)
{
sprintf (buf2, "%c", argument[y]);
strcat (buf, buf2);
y += 1;
}
sprintf (buf2, ",");
strcat (buf, buf2);
z = 1;
for (y = x; y < strlen (argument); y++)
{
sprintf (buf2, "%c", argument[y]);
strcat (buf, buf2);
if ((z % 3 == 0) && (y != strlen (argument) - 1))
{
sprintf (buf2, ",");
strcat (buf, buf2);
z = 0;
}
z++;
}
}
string = str_dup (buf);
return string;
}
/*
* Low level output function.
*/
bool process_output (DESCRIPTOR_DATA * d, bool fPrompt)
{
extern bool merc_down;
char vtbuf[MSL];
char dbuf[MSL];
/*
* Bust a prompt.
*/
if (d->pString != NULL) /* OLC */
write_to_buffer (d, "<[OLC]> ", 0);
if (fPrompt && !merc_down
&& (d->connected == CON_PLAYING || d->connected == CON_PFILE))
{
if (d->showstr_point)
{
char buf[MAX_INPUT_LENGTH];
char *ptr;
int total_lines, shown_lines = 0;
for (ptr = d->showstr_head; ptr != d->showstr_point; ptr++)
if (*ptr == '\n')
shown_lines++;
total_lines = shown_lines;
for (ptr = d->showstr_point; *ptr != '\0'; ptr++)
if (*ptr == '\n')
total_lines++;
sprintf (buf,
"\n\r#e[#w%d%%#e][#rPlease type (#wC#r)ontinue, (#wR#r)efresh, (#wB#r)ack, (#wH#r)elp, (#wQ#r)uit, or #wRETURN#e]\n\r",
shown_lines * 100 / total_lines);
write_to_buffer (d, buf, 0);
}
else
{
CHAR_DATA *ch;
CHAR_DATA *victim;
ch = d->original ? d->original : d->character;
/* this is placed right before we send the prompt stuff
* notice that the PLR_BLANK part was slightly modified
*/
if (IS_SET (ch->more, SHORT_COMBAT))
{
if (ch->amount_attacks_dealt > 0)
{
sprintf (dbuf,
"#cYou dealt #r%d #cattacks causing #r%d #cdamage. #w(#r%d #waverage)#n\n\r",
ch->amount_attacks_dealt, ch->amount_damage_dealt,
ch->amount_damage_dealt / ch->amount_attacks_dealt);
send_to_char (dbuf, ch);
}
if (ch->amount_attacks_received > 0)
{
sprintf (dbuf,
"#cYou were struck by #r%d #cattacks, causing #r%d #cdamage. #w(#r%d #waverage)#n\n\r",
ch->amount_attacks_received,
ch->amount_damage_received,
ch->amount_damage_received /
ch->amount_attacks_received);
send_to_char (dbuf, ch);
}
ch->amount_damage_dealt = 0;
ch->amount_damage_received = 0;
ch->amount_attacks_dealt = 0;
ch->amount_attacks_received = 0;
}
if (ch->combined_exp > 0)
show_combined_exp (ch);
if (!IS_NPC (ch) && IS_SET (ch->pcdata->tempflag, TEMP_VT100))
{
sprintf (vtbuf, "%s\e[%d;1H", VT_SAVECURSOR,
ch->pcdata->vt100_size);
write_to_buffer (d, vtbuf, 0);
}
if (!IS_NPC (ch) && IS_SET (ch->act, PLR_BLANK)
&& !IS_SET (ch->pcdata->tempflag, TEMP_VT100))
write_to_buffer (d, "\n\r", 2);
// if ( IS_SET(ch->act, PLR_BLANK) )
// write_to_buffer( d, "\n\r", 2 );
if (IS_SET (ch->act, PLR_PROMPT) && IS_EXTRA (ch, EXTRA_PROMPT))
{
stc ("#n", ch);
bust_a_prompt (d);
}
else if (IS_SET (ch->act, PLR_PROMPT))
{
char buf[MAX_STRING_LENGTH];
char cond[MAX_INPUT_LENGTH];
char hit_str[MAX_INPUT_LENGTH];
char mana_str[MAX_INPUT_LENGTH];
char move_str[MAX_INPUT_LENGTH];
char exp_str[MAX_INPUT_LENGTH];
ch = d->character;
if (IS_HEAD (ch, LOST_HEAD) || IS_EXTRA (ch, EXTRA_OSWITCH))
{
if (IS_SET(ch->flag2, EXTRA_AFK))
sprintf(exp_str, "#cAFK#n");
else
sprintf (exp_str, "%s", set_comma (ch->exp));
COL_SCALE (exp_str, ch, ch->exp, 1000);
sprintf (buf, "#n<[%sX] [?H ?M ?V]> ", exp_str);
}
else if (ch->position == POS_FIGHTING)
{
victim = ch->fighting;
/*
if (victim->hit < 1 || victim->max_hit < 1)
{
strcpy(cond, "Incapacitated #w[#r0]",);
ADD_COLOUR(ch, cond, L_RED);
}
else if ((victim->hit*100/victim->max_hit) < 17)
{
strcpy(cond, "Crippled #w[#r%d#w]", victim->hit*100/victim->hit);
ADD_COLOUR(ch, cond, L_RED);
}
else if ((victim->hit*100/victim->max_hit) < 34)
{
strcpy(cond, "Mauled", victim->hit*100/victim->hit);
ADD_COLOUR(ch, cond, L_BLUE);
}
else if ((victim->hit*100/victim->max_hit) < 50)
{
strcpy(cond, "Wounded", victim->hit*100/victim->hit);
ADD_COLOUR(ch, cond, L_BLUE);
}
else if ((victim->hit*100/victim->max_hit) < 67)
{
strcpy(cond, "Injured", victim->hit*100/victim->hit);
ADD_COLOUR(ch, cond, L_GREEN);
}
else if ((victim->hit*100/victim->max_hit) < 83)
{
strcpy(cond, "Hurt");
ADD_COLOUR(ch, cond, L_GREEN);
}
else if ((victim->hit*100/victim->max_hit) < 100)
{
strcpy(cond, "Bruised");
ADD_COLOUR(ch, cond, YELLOW);
}
else
{
strcpy(cond, "Perfect");
ADD_COLOUR(ch, cond, L_CYAN);
}
*/
if (victim != NULL)
{
if (((victim->hit * 100) / victim->max_hit) >= 100)
sprintf (cond,
"#r++#R+#g+#g+#G+#b+#b+#b+#B+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 90)
sprintf (cond,
"#r++#R+#g+#g+#G+#b+#b+#b+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 80)
sprintf (cond, "#r++#R+#g+#g+#G+#b+#b+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 70)
sprintf (cond, "#r++#R+#g+#g+#G+#b+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 60)
sprintf (cond, "#r++#R+#g+#g+#G+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 50)
sprintf (cond, "#r++#R+#g+#g+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 40)
sprintf (cond, "#r++#R+#g+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 30)
sprintf (cond, "#r++#R+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 20)
sprintf (cond, "#r++ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else if (((victim->hit * 100) / victim->max_hit) >= 10)
sprintf (cond, "#r+ #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
else // ( ( ( victim->hit * 100 ) / victim->max_hit ) < 10 )
sprintf (cond, " #y[#7%d%%#y]",
((victim->hit * 100) / victim->max_hit));
}
else
{
sprintf (cond, "<?><?><?><?>");
}
sprintf (hit_str, "%d", ch->hit);
COL_SCALE (hit_str, ch, ch->hit, ch->max_hit);
sprintf (mana_str, "%d", ch->mana);
COL_SCALE (mana_str, ch, ch->mana, ch->max_mana);
sprintf (move_str, "%d", ch->move);
COL_SCALE (move_str, ch, ch->move, ch->max_move);
sprintf (buf, "<[%s#n] [%sH %sM %sV]> ", cond, hit_str,
mana_str, move_str);
}
else
{
sprintf (hit_str, "%d", ch->hit);
COL_SCALE (hit_str, ch, ch->hit, ch->max_hit);
sprintf (mana_str, "%d", ch->mana);
COL_SCALE (mana_str, ch, ch->mana, ch->max_mana);
sprintf (move_str, "%d", ch->move);
COL_SCALE (move_str, ch, ch->move, ch->max_move);
sprintf (exp_str, "%s", set_comma (ch->exp));
COL_SCALE (exp_str, ch, ch->exp, 1000);
sprintf (buf, "#n<[%s] [%sH %sM %sV]> ", exp_str, hit_str,
mana_str, move_str);
}
/*
if (ch->registerred == 0 && ch->email_set != 2)
{
sprintf (buf, "#n<[#cU R : #wType 'help register'#n] [%sH %sM %sV]> ", hit_str,
mana_str, move_str);
}
*/
write_to_buffer (d, buf, 0);
}
/* then inside the the same scope, before we send the PLR_TELNET_GA seqence,
* we restore the cursor position, allowing the normal output to go to
* the right window.
*/
if (!IS_NPC (ch) && IS_SET (ch->pcdata->tempflag, TEMP_VT100))
{
write_to_buffer (d, VT_RESTORECURSOR, 0);
}
if (IS_SET (ch->act, PLR_TELNET_GA))
write_to_buffer (d, go_ahead_str, 0);
}
}
/*
* Short-circuit if nothing to write.
*/
if (d->outtop == 0)
return TRUE;
/*
* Snoop-o-rama.
*/
if (d->snoop_by != NULL)
{
if (d->snoop_by->character != NULL &&
IS_IMMORTAL (d->snoop_by->character))
{
//THIS IS WHERE LOG_NEVER NEEDS TO GO
write_to_buffer (d->snoop_by, "<", 2);
write_to_buffer (d->snoop_by, d->character->name, 0);
write_to_buffer (d->snoop_by, "> ", 2);
write_to_buffer (d->snoop_by, d->outbuf, d->outtop);
/*
sprintf(snooper, "%s %% ", d->character->name);
write_to_buffer (d->snoop_by,snooper, 2);
write_to_buffer (d->snoop_by, d->outbuf, d->outtop);
*/
}
}
/*
* OS-dependent output.
*/
if (!write_to_descriptor (d, d->outbuf, d->outtop))
{
d->outtop = 0;
return FALSE;
}
else
{
d->outtop = 0;
return TRUE;
}
}
/*
* Append onto an output buffer.
*/
char *format_buffer (DESCRIPTOR_DATA * d, char *txt)
{
char show[32000];
char *p = '\0';
int cnt = 0;
if (strlen (txt) < 10000)
{
bug ("Format_buffer: Invalid size %d", strlen (txt));
return txt;
}
p = show;
for (;;)
{
if (cnt++ < 10000)
*p++ = *txt++;
else
{
if (*txt != ' ')
p--, txt--;
else
break;
}
}
p = '\0';
cnt = strlen (show);
write_to_descriptor (d, show, cnt);
return txt;
}
#define BG_COLOR_TAG '^'
#define COLOR_TAG '#'
#define ANSI_STRING "0123456789bBcCdDefFgGiIlLnNopPrRsuvVwWyYxz()@/."
#define REPLACE_STRING "-#+^"
bool is_color(char code)
{
int i = 0, j = 0;
while (ANSI_STRING[i] != '\0')
{
if (ANSI_STRING[i] == code) return TRUE;
i++;
}
while (REPLACE_STRING[j] != '\0')
{
if (REPLACE_STRING[j] == code) return TRUE;
j++;
}
return FALSE;
}
void write_to_buffer (DESCRIPTOR_DATA * d, const char *txt, int length)
{
char tb[32000], ccode[20];
int i, j, cnt;
int safe = 0;
bool ansi;
if (length <= 0)
length = strlen (txt);
if (d->character == NULL || d->connected != CON_PLAYING)
ansi = TRUE;
else
ansi = (IS_SET (d->character->act, PLR_ANSI)) ? TRUE : FALSE;
if (d->outtop == 0 && !d->fcommand)
{
d->outbuf[0] = '\n';
d->outbuf[1] = '\r';
d->outtop = 2;
}
j = 0;
tb[0] = '\0';
for (i = 0; i < length; i++)
{
ccode[0] = '\0';
if (txt[i] == COLOR_TAG && txt[i+1] != BG_COLOR_TAG && is_color(txt[i+1]))
{
/*
if (txt[i] == 'K')
txt[i] = txt[i++];
*/
switch (txt[++i])
{
default:
sprintf(ccode, "#%c", txt[i]);
break;
case '-':
sprintf (ccode, "%c", '~');
break;
case '+':
sprintf (ccode, "%c", '%');
break;
case '#':
sprintf (ccode, "%c", '#');
break;
case '0':
if (!ansi)
continue;
strcpy (ccode, GREY);
break;
case '1':
if (!ansi)
continue;
strcpy (ccode, L_RED);
break;
case '2':
if (!ansi)
continue;
strcpy (ccode, L_GREEN);
break;
case '3':
if (!ansi)
continue;
strcpy (ccode, YELLOW);
break;
case '4':
if (!ansi)
continue;
strcpy (ccode, L_BLUE);
break;
case '5':
if (!ansi)
continue;
strcpy (ccode, PINK);
break;
case '6':
if (!ansi)
continue;
strcpy (ccode, L_CYAN);
break;
case '7':
if (!ansi)
continue;
strcpy (ccode, WHITE);
break;
case '8':
if (!ansi)
continue;
strcpy (ccode, D_WHITE);
break;
case '9':
if (!ansi)
continue;
strcpy (ccode, INVERTED);
break;
case 'B':
if (!ansi)
continue;
strcpy (ccode, D_BLUE);
break;
case 'b':
if (!ansi)
continue;
strcpy (ccode, L_BLUE);
break;
case 'C':
if (!ansi)
continue;
strcpy (ccode, D_CYAN);
break;
case 'c':
if (!ansi)
continue;
strcpy (ccode, L_CYAN);
break;
case 'e':
if (!ansi)
continue;
strcpy (ccode, GREY);
break;
case 'F':
if (!ansi)
continue;
strcpy (ccode, FLASHING);
break;
case 'G':
if (!ansi)
continue;
strcpy (ccode, D_GREEN);
break;
case 'g':
if (!ansi)
continue;
strcpy (ccode, L_GREEN);
break;
case 'I':
case 'i':
if (!ansi)
continue;
strcpy (ccode, INVERTED);
break;
case 'N':
strcpy (ccode, NO_COLOUR);
break;
case 'n':
strcpy (ccode, NO_COLOUR);
break;
case 'o':
if (!ansi)
continue;
strcpy (ccode, BROWN);
break;
case 'P':
if (!ansi)
continue;
strcpy (ccode, MAGENTA);
break;
case 'p':
if (!ansi)
continue;
strcpy (ccode, PINK);
break;
case 'R':
if (!ansi)
continue;
strcpy (ccode, D_RED);
break;
case 'r':
if (!ansi)
continue;
strcpy (ccode, L_RED);
break;
case '.':
switch (number_range (1, 15))
{
case 1:
if (!ansi)
continue;
strcpy (ccode, L_RED);
break;
case 2:
if (!ansi)
continue;
strcpy (ccode, L_CYAN);
break;
case 3:
if (!ansi)
continue;
strcpy (ccode, L_BLUE);
break;
case 4:
if (!ansi)
continue;
strcpy (ccode, L_GREEN);
break;
case 5:
if (!ansi)
continue;
strcpy (ccode, PINK);
break;
case 6:
if (!ansi)
continue;
strcpy (ccode, YELLOW);
break;
case 7:
if (!ansi)
continue;
strcpy (ccode, WHITE);
break;
case 8:
if (!ansi)
continue;
strcpy (ccode, D_RED);
break;
case 9:
if (!ansi)
continue;
strcpy (ccode, D_CYAN);
break;
case 10:
if (!ansi)
continue;
strcpy (ccode, D_BLUE);
break;
case 11:
if (!ansi)
continue;
strcpy (ccode, D_GREEN);
break;
case 12:
if (!ansi)
continue;
strcpy (ccode, MAGENTA);
break;
case 13:
if (!ansi)
continue;
strcpy (ccode, BROWN);
break;
case 14:
if (!ansi)
continue;
strcpy (ccode, D_WHITE);
break;
case 15:
if (!ansi)
continue;
strcpy (ccode, GREY);
break;
default:
if (!ansi)
continue;
strcpy (ccode, GREY);
break;
}
break;
case 'u':
if (!ansi)
continue;
strcpy (ccode, UNDERLINE);
break;
case 'w':
if (!ansi)
continue;
strcpy (ccode, WHITE);
break;
case 'W':
if (!ansi)
continue;
strcpy (ccode, D_WHITE);
break;
case 'y':
if (!ansi)
continue;
strcpy (ccode, YELLOW);
break;
case 'Y':
if (!ansi)
continue;
strcpy (ccode, BROWN);
break;
}
if (ccode[0] != '\0')
{
for (cnt = 0; cnt < strlen (ccode); cnt++)
tb[j++] = ccode[cnt];
}
}
else if (txt[i] == BG_COLOR_TAG && txt[i+1] != COLOR_TAG)
{
switch (txt[++i])
{
default:
sprintf (ccode, "^%c", txt[i]);
break;
case '^':
sprintf (ccode, "%c", '^');
break;
case 'A':
sprintf (ccode, "%c", 'Æ');
break;
case 'Y':
sprintf (ccode, "%c", '¥');
break;
case '*':
sprintf (ccode, "%c", '¤');
break;
case 'C':
sprintf (ccode, "%c", '¢');
break;
case 'B':
sprintf (ccode, "%c", 'ß');
break;
case 'L':
sprintf (ccode, "%c", '£');
break;
case 'P':
sprintf (ccode, "%c", 'þ');
break;
case 'S':
sprintf (ccode, "%c", 'Ç');
break;
case '?':
sprintf (ccode, "%c", '¿');
break;
case '!':
sprintf (ccode, "%c", '«');
break;
case '$':
sprintf (ccode, "%c", '»');
break;
case 'y':
sprintf (ccode, "%c", '®');
break;
case '(':
sprintf (ccode, "%c", '±');
break;
case ')':
sprintf (ccode, "%c", '§');
break;
case 'a':
sprintf (ccode, "%c", 'Ã');
break;
case '=':
sprintf (ccode, "%c", 'Ç');
break;
case 'f':
sprintf (ccode, "%c", 'Ê');
break;
case 'h':
sprintf (ccode, "%c", 'Ï');
break;
case 'j':
sprintf (ccode, "%c", 'Ð');
break;
case 'k':
sprintf (ccode, "%c", 'Þ');
break;
case 'q':
sprintf (ccode, "%c", 'á');
break;
case 't':
sprintf (ccode, "%c", 'ç');
break;
case 'x':
sprintf (ccode, "%c", 'è');
break;
case '&':
sprintf (ccode, "%c", '©');
break;
case 'v':
sprintf (ccode, "%c", 'ð');
break;
case 'N':
case 'n':
strcpy (ccode, BG_CLEAR);
break;
case '1':
strcpy (ccode, BG_RED);
break;
case '2':
strcpy (ccode, BG_GREEN);
break;
case '3':
strcpy (ccode, BG_BROWN);
break;
case '4':
strcpy (ccode, BG_BLUE);
break;
case '5':
strcpy (ccode, BG_PURPLE);
break;
case '6':
strcpy (ccode, BG_CYAN);
break;
case '7':
strcpy (ccode, BG_WHITE);
break;
case '.':
if (!ansi) continue;
switch(number_range(1,7))
{
case 1: strcpy(ccode, BG_RED); break;
case 2: strcpy(ccode, BG_CYAN); break;
case 3: strcpy(ccode, BG_BLUE); break;
case 4: strcpy(ccode, BG_GREEN); break;
case 5: strcpy(ccode, BG_PURPLE); break;
case 6: strcpy(ccode, BG_BROWN); break;
case 7: strcpy(ccode, BG_WHITE); break;
default: strcpy(ccode, BG_WHITE); break;
}
}
if (ansi)
{
for (cnt = 0; cnt < strlen (ccode); cnt++)
tb[j++] = ccode[cnt];
}
}
else if (txt[i] == '' || safe > 0)
{
if (safe > 0) safe--;
else safe = 8;
tb[j++] = txt[i];
}
else if (d->character != NULL &&
isdigit(txt[i]) &&
IS_SET (d->character->extra2, DEMENTED))
{
char number[MSL];
char hex[MSL];
int digits = 0;
int change = 0;
int complete = 0;
number[digits++] = txt[i];
while (isdigit(txt[i+1]))
number[digits++] = txt[++i];
complete = atoi(number);
if (complete != 0)
{
change = 0;
while (number[change] != '\0')
number[change++] = '\0';
itoa(complete, hex, 16);
}
else strcpy(hex, number);
change = 0;
while (hex[change] != '\0')
tb[j++] = hex[change++];
if (strlen(hex) < digits)
{
int added = 0;
while ((added++) + strlen(hex) < digits)
tb[j++] = ' ';
}
}
else if (d->character != NULL && IS_SET (d->character->extra2, DEMENTED))
{
char temp[1];
temp[0] = txt[i];
temp[0] = UPPER(temp[0]);
switch (temp[0])
{
default : break;
case 'A': temp[0] = 'e'; break;
case 'B': temp[0] = 'p'; break;
case 'C': temp[0] = 's'; break;
case 'D': temp[0] = 't'; break;
case 'E': temp[0] = 'i'; break;
case 'F': temp[0] = 'w'; break;
case 'G': temp[0] = 'k'; break;
case 'H': temp[0] = 'n'; break;
case 'I': temp[0] = 'u'; break;
case 'J': temp[0] = 'v'; break;
case 'K': temp[0] = 'g'; break;
case 'L': temp[0] = 'c'; break;
case 'M': temp[0] = 'l'; break;
case 'N': temp[0] = 'r'; break;
case 'O': temp[0] = 'y'; break;
case 'P': temp[0] = 'b'; break;
case 'Q': temp[0] = 'x'; break;
case 'R': temp[0] = 'h'; break;
case 'S': temp[0] = 'm'; break;
case 'T': temp[0] = 'd'; break;
case 'U': temp[0] = 'o'; break;
case 'V': temp[0] = 'f'; break;
case 'W': temp[0] = 'z'; break;
case 'X': temp[0] = 'q'; break;
case 'Y': temp[0] = 'a'; break;
case 'Z': temp[0] = 'j'; break;
}
if (txt[i] == UPPER(txt[i])) temp[0] = UPPER(temp[0]);
tb[j++] = temp[0];
}
else
tb[j++] = txt[i];
}
/*
strcpy(ccode, NO_COLOUR);
*/
if (ansi)
{
tb[j++] = 27;
tb[j++] = '[';
tb[j++] = '0';
tb[j++] = 'm';
}
tb[j] = '\0';
length = strlen (tb);
if ((d->outtop + length) >= 10000)
{
write_to_descriptor (d, d->outbuf, d->outtop);
d->connected = CON_PLAYING;
d->outtop = 0;
}
while (length >= 10000)
{
char tmp[MSL];
sprintf (tmp, "%s", format_buffer (d, tb));
tb[0] = '\0';
strcat (tb, tmp);
length = strlen (tb);
}
while (d->outtop + length >= d->outsize)
{
char *outbuf;
outbuf = alloc_mem (2 * d->outsize);
strncpy (outbuf, d->outbuf, d->outtop);
free_mem (d->outbuf, d->outsize);
d->outbuf = outbuf;
d->outsize *= 2;
}
/* Copy. */
strncpy (d->outbuf + d->outtop, tb, length);
d->outtop += length;
return;
}
/* New Write to Buffer (C) Jobo - Brian Graverson */
/* Messed with by Matthew Little - for Legend of Chrystancia */
void oldverwrite_to_buffer (DESCRIPTOR_DATA * d, const char *txt, int length)
{
static char output[32000];
char *ptr;
int i = 0;
bool ansi;
// clear the output buffer, and set the pointer
output[0] = '\0';
ptr = output;
if (length <= 0)
length = strlen (txt);
if (length >= MAX_STRING_LENGTH)
{
return;
}
if (d->connected == CON_GET_NAME)
ansi = TRUE;
else if (d->connected == CON_GET_OLD_PASSWORD)
ansi = TRUE;
else if (d->connected == CON_CONFIRM_NEW_NAME)
ansi = TRUE;
else if (d->connected == CON_CONFIRM_NEW_PASSWORD)
ansi = TRUE;
else if (d->connected == CON_GET_NEW_PASSWORD)
ansi = TRUE;
else if (d->connected == CON_GET_NEW_SEX)
ansi = TRUE;
else if (d->connected == CON_GET_NEW_ANSI)
ansi = TRUE;
else if (d->character == NULL)
ansi = FALSE;
else
ansi = (IS_SET (d->character->act, PLR_ANSI)) ? TRUE : FALSE;
// initial linebreak
if (d->outtop == 0 && !d->fcommand)
{
d->outbuf[0] = '\n';
d->outbuf[1] = '\r';
d->outtop = 2;
}
while (*txt != '\0' && i++ < length)
{
switch (*txt)
{
default:
*ptr++ = *txt++;
break;
case '^':
i++;
switch (*++txt)
{
case '^':
*ptr++ = '^';
txt++;
break;
case 'A':
*ptr++ = 'Æ';
txt++;
break;
case 'Y':
*ptr++ = '¥';
txt++;
break;
case '*':
*ptr++ = '¤';
txt++;
break;
case 'C':
*ptr++ = '¢';
txt++;
break;
case 'B':
*ptr++ = 'ß';
txt++;
break;
case 'L':
*ptr++ = '£';
txt++;
break;
case 'P':
*ptr++ = 'þ';
txt++;
break;
case 'S':
*ptr++ = 'Ç';
txt++;
break;
case '?':
*ptr++ = '¿';
txt++;
break;
case '!':
*ptr++ = '«';
txt++;
break;
case '$':
*ptr++ = '»';
txt++;
break;
case 'y':
*ptr++ = '®';
txt++;
break;
case '&':
*ptr++ = '©';
txt++;
break;
case '(':
*ptr++ = '±';
txt++;
break;
case ')':
*ptr++ = '§';
txt++;
break;
case 'a':
*ptr++ = 'Ã';
txt++;
break;
case '=':
*ptr++ = 'Ç';
txt++;
break;
case 'f':
*ptr++ = 'Ê';
txt++;
break;
case 'h':
*ptr++ = 'Ï';
txt++;
break;
case 'j':
*ptr++ = 'Ð';
txt++;
break;
case 'k':
*ptr++ = 'Þ';
txt++;
break;
case 'q':
*ptr++ = 'á';
txt++;
break;
case 't':
*ptr++ = 'ç';
txt++;
break;
case 'x':
*ptr++ = 'è';
txt++;
break;
case 'v':
*ptr++ = 'ð';
txt++;
break;
default:
txt++;
break;
}
break;
case '#':
case '`':
i++;
switch (*++txt)
{
default:
txt++;
break;
case '#':
*ptr++ = '#';
txt++;
break;
case '^':
*ptr++ = '^';
txt++;
break;
case '`':
*ptr++ = '`';
txt++;
break;
case '-':
*ptr++ = '~';
txt++;
break;
case '+':
*ptr++ = '%';
txt++;
break;
case 'i':
if (!ansi)
{
txt++;
continue;
}
// bold
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '7';
*ptr++ = 'm';
txt++;
break;
case 'F':
if (!ansi)
{
txt++;
continue;
}
// Flashing
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '5';
*ptr++ = 'm';
txt++;
break;
case 'u':
if (!ansi)
{
txt++;
continue;
}
// underline
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '4';
*ptr++ = 'm';
txt++;
break;
case 'n':
if (!ansi)
{
txt++;
continue;
}
// stock color
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = 'm';
txt++;
break;
case 'W':
if (!ansi)
{
txt++;
continue;
}
// White
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '7';
*ptr++ = 'm';
txt++;
break;
case 'l':
if (!ansi)
{
txt++;
continue;
}
// Black
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '0';
*ptr++ = 'm';
txt++;
break;
case 'w':
if (!ansi)
{
txt++;
continue;
}
// White 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '7';
*ptr++ = 'm';
txt++;
break;
case 'e':
if (!ansi)
{
txt++;
continue;
}
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '0';
*ptr++ = 'm';
txt++;
break;
case 0:
if (!ansi)
{
txt++;
continue;
}
// Black 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '0';
*ptr++ = 'm';
txt++;
break;
case 'R':
if (!ansi)
{
txt++;
continue;
}
//red
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '1';
*ptr++ = 'm';
txt++;
break;
case 'r':
if (!ansi)
{
txt++;
continue;
}
// red 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '1';
*ptr++ = 'm';
txt++;
break;
case 1:
if (!ansi)
{
txt++;
continue;
}
// red 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '1';
*ptr++ = 'm';
txt++;
break;
case 'G':
if (!ansi)
{
txt++;
continue;
}
// Green
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '2';
*ptr++ = 'm';
txt++;
break;
case 2:
if (!ansi)
{
txt++;
continue;
}
// Green 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '2';
*ptr++ = 'm';
txt++;
break;
case 'g':
if (!ansi)
{
txt++;
continue;
}
// Green 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '2';
*ptr++ = 'm';
txt++;
break;
case 'y':
if (!ansi)
{
txt++;
continue;
}
// Yellow
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '3';
*ptr++ = 'm';
txt++;
break;
case 'o':
if (!ansi)
{
txt++;
continue;
}
// Yellow (Brown)
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '3';
*ptr++ = 'm';
txt++;
break;
case 'B':
if (!ansi)
{
txt++;
continue;
}
// Blue
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '4';
*ptr++ = 'm';
txt++;
break;
case 'b':
if (!ansi)
{
txt++;
continue;
}
// Blue 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '4';
*ptr++ = 'm';
txt++;
break;
case 'P':
if (!ansi)
{
txt++;
continue;
}
//Purple
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '5';
*ptr++ = 'm';
txt++;
break;
case 'p':
if (!ansi)
{
txt++;
continue;
}
// Purple 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '5';
*ptr++ = 'm';
txt++;
break;
case 'C':
if (!ansi)
{
txt++;
continue;
}
// Cyan
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '6';
*ptr++ = 'm';
txt++;
break;
case 'c':
if (!ansi)
{
txt++;
continue;
}
// Cyan 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '6';
*ptr++ = 'm';
txt++;
break;
case '.':
if (!ansi)
{
txt++;
continue;
}
switch (number_range (1, 15))
{
case 1: // White
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '7';
*ptr++ = 'm';
break;
case 2: // Black
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '0';
*ptr++ = 'm';
break;
case 3: // Black 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '0';
*ptr++ = 'm';
break;
case 4: // Red
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '1';
*ptr++ = 'm';
break;
case 5: // red 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '1';
*ptr++ = 'm';
break;
case 6: // Green
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '2';
*ptr++ = 'm';
break;
case 7: // Green 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '2';
*ptr++ = 'm';
break;
case 8: // Yellow (Brown)
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '3';
*ptr++ = 'm';
break;
case 9: // Yellow 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '3';
*ptr++ = 'm';
break;
case 10: // Blue
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '4';
*ptr++ = 'm';
break;
case 11: // Blue 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '4';
*ptr++ = 'm';
break;
case 12: // Purple
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '5';
*ptr++ = 'm';
break;
case 13: // Purple 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '5';
*ptr++ = 'm';
break;
case 14: // Cyan
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '6';
*ptr++ = 'm';
case 15: // Cyan 2
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = ';';
*ptr++ = '1';
*ptr++ = ';';
*ptr++ = '3';
*ptr++ = '6';
*ptr++ = 'm';
break;
}
txt++;
break;
}
break;
}
}
// and terminate it with the standard color
*ptr++ = 27;
*ptr++ = '[';
*ptr++ = '0';
*ptr++ = 'm';
// terminate
*ptr = '\0';
length = strlen (output);
// Expand the buffer as needed.
while (d->outtop + length >= d->outsize)
{
char *obuf;
// There is a limit to our patience
if (length >= MSL || ((d->outtop + length) >= 32000))
{
write_to_descriptor (d, d->outbuf, d->outtop);
d->connected = CON_PLAYING;
d->outsize = 2000;
d->outbuf = alloc_mem (d->outsize);
d->outtop = 0;
length = strlen (output);
}
obuf = alloc_mem (2 * d->outsize);
strncpy (obuf, d->outbuf, d->outtop);
free_mem (d->outbuf, d->outsize);
d->outbuf = obuf;
d->outsize *= 2;
}
// Copy.
strncpy (d->outbuf + d->outtop, output, length);
d->outtop += length;
return;
}
/*
* Lowest level output function.
* Write a block of text to the file descriptor.
* If this gives errors on very long blocks (like 'ofind all'),
* try lowering the max block size.
*/
bool write_to_descriptor (DESCRIPTOR_DATA * d, char *txt, int length)
{
int iStart, iPtr;
int nWrite, iWrt = 0;
int nBlock, iBlck;
int control = d->descriptor;
if (length <= 0)
length = strlen (txt);
if (d && d->out_compress)
{
d->out_compress->next_in = (unsigned char *) txt;
d->out_compress->avail_in = length;
while (d->out_compress->avail_in)
{
d->out_compress->avail_out =
COMPRESS_BUF_SIZE - (d->out_compress->next_out -
d->out_compress_buf);
if (d->out_compress->avail_out)
{
if (deflate (d->out_compress, Z_SYNC_FLUSH) != Z_OK)
return FALSE;
}
length = d->out_compress->next_out - d->out_compress_buf;
if (length > 0)
{
for (iPtr = 0; iPtr < length; iPtr += iWrt)
{
iBlck = UMIN (length - iPtr, 4096);
if ((iWrt = write (control, d->out_compress_buf + iPtr, iBlck))
< 0)
{
perror ("write_to_descriptor (compressed):");
return FALSE;
}
increase_total_output (iBlck);
}
if (iWrt <= 0)
break;
if (iPtr > 0)
{
if (iPtr < length)
memmove (d->out_compress_buf, d->out_compress_buf + iPtr,
length - iPtr);
d->out_compress->next_out =
d->out_compress_buf + length - iPtr;
}
}
}
return TRUE;
}
increase_total_output (length);
for (iStart = 0; iStart < length; iStart += nWrite)
{
nBlock = UMIN (length - iStart, 4096);
if ((nWrite = write (control, txt + iStart, nBlock)) < 0)
{
perror ("Write_to_descriptor");
return FALSE;
}
}
return TRUE;
}
void reason (CHAR_DATA * ch, char *argument)
{
sprintf (log_buf, "%s Reason] %s", ch->name, argument);
log_string (log_buf, ch);
append_file (ch, "../db/reasons.db", argument);
}
/*
* Deal with sockets that haven't logged in yet.
*/
void nanny (DESCRIPTOR_DATA * d, char *argument)
{
DESCRIPTOR_DATA *d_copy;
char buf[MAX_STRING_LENGTH];
char kav[MAX_STRING_LENGTH];
char tij_buf[MSL]; /* For ltf connection file */
CHAR_DATA *ch;
char *pwdnew;
char *p;
char *strtime;
char *lasttime;
int char_age = 17;
int plcnt;
bool fOld;
char pwdbuf[MAX_STRING_LENGTH];
CHAR_DATA *gch;
// int i;
// bool fnd = FALSE;
if (d->connected != CON_NOTE_TEXT)
{
while (isspace (*argument))
argument++;
}
ch = d->character;
switch (d->connected)
{
default:
bug ("Nanny: bad d->connected %d.", d->connected);
close_socket (d);
return;
case CON_GET_NAME:
if (argument[0] == '\0')
{
close_socket (d);
return;
}
argument[0] = UPPER (argument[0]);
if (!check_parse_name (argument))
{
write_to_buffer (d, "#w[#e!#w] Illegal name\n\r", 0);
write_to_buffer (d,
"#w[#e!#w] If you have previously used this name here, log on an alt and post a note to immortal.\n\r",
0);
write_to_buffer (d, "#w[#e?#w] Name: ", 0);
return;
}
/*
if (dude_exists(argument))
{
write_to_buffer (d,
"#w[#e!#w] That name belongs to a character retired from this MUD, and may not be.\n\r",
0);
write_to_buffer (d,
"#w[#e!#w] taken in use again. Log on an alt and post a note to immortals if you\n\r",
0);
write_to_buffer (d,
"#w[#e!#w] have opinions about this specific name being disabled through retirement.\n\r",
0);
write_to_buffer (d, "#w[#e?#w] Name: ", 0);
return;
}
*/
if (check_shitlist (d, argument))
{
close_socket (d);
return;
}
if (!str_cmp (argument, "who"))
{
int total = 0;
int col = 0;
DESCRIPTOR_DATA *di;
if (WizConfig->wizlock)
{
do_help(d->character, "WIZLOCKED");
write_to_buffer (d,
"#w[#e!#w] The game is wizlocked, quit spamming us with connection attempts.\n\r\n\r",
0);
close_socket (d);
return;
}
write_to_buffer (d, "\n\r#wWho request:\n\r", 0);
write_to_buffer (d,
"#C---------------=[ #yL e g e n d o f C h r y s t a n c i a #C]=---------------#n\n\r\n\r",
0);
for (di = first_descriptor; di != NULL; di = di->next)
{
if (di->connected != CON_PLAYING)
continue;
if IS_IMMORTAL
(di->character) continue;
total++;
sprintf (kav, "#w%12s#n", di->character->name);;
write_to_buffer (d, kav, 0);
if (++col % 6 == 0)
write_to_buffer (d, "\n\r", 0);
}
if (col % 6 != 0)
write_to_buffer (d, "\n\r", 0);
sprintf (kav, "Who request from site %s.", d->host);
log_string_sil (kav);
write_to_buffer (d,
"\n\r#C---------------------------------------------------------------------------#n\n\r",
0);
sprintf (kav,
"#w There are %d total players connected.`n\n\r",
total);
write_to_buffer (d, kav, 0);
sprintf (kav,
"#w Peak of %d players connected.`n\n\r",
mudinfo[MUDINFO_PEAK_USERS]);
write_to_buffer (d, kav, 0);
write_to_buffer (d,
"#C---------------------------------------------------------------------------#n\n\r",
0);
d->connected = CON_GET_NAME;
write_to_buffer (d,
"#w[#e?#w] Thy name that thou wish to die by: #n",
0);
return;
}
else
{
sprintf (kav, "%s trying to connect.", argument);
log_string (kav, NULL);
d->login = D_LOGIN_TIME;
fOld = load_char_short (d, argument);
if (!d->character)
{
sprintf (log_buf, "Bad player file %s@%s.", argument, d->host);
log_string (log_buf, NULL);
write_to_buffer (d,
"*****************************************************************\n\r"
"** Your player file has become corrupted since you last played **\n\r"
"** Email legend@insurrection.wolfpaw.net explaining that your **\n\r"
"** player file is bugged. Someone shall try and fix it as soon **\n\r"
"** as possible **\n\r"
"*****************************************************************\n\r",
0);
close_socket (d);
return;
}
ch = d->character;
char_age = years_old (ch);
if (!IS_NPC (ch) && ch->pcdata->denydate > 0)
{
if (!play_yet (ch))
{
sprintf (log_buf, "Denying access to %s@%s.", argument,
ch->lasthost);
log_string (log_buf, ch);
wiznet (ch, WIZ_LOGINS, LEVEL_JUDGE, log_buf);
close_socket (d);
return;
}
}
/* temp removed
else if (IS_EXTRA (ch, EXTRA_BORN) && char_age < 15)
{
char agebuf[MAX_INPUT_LENGTH];
if (char_age == 14)
sprintf (agebuf,
"#w[#e!#w] You cannot play for another year.\n\r");
else
sprintf (agebuf,
"#w[#e!#w] You cannot play for another %d years.\n\r",
(15 - years_old (ch)));
write_to_buffer (d, agebuf, 0);
close_socket (d);
return;
}
*/
//1
if (check_reconnect (d, argument, FALSE))
{
fOld = TRUE;
}
else
{
/* Check max number of players - KaVir */
DESCRIPTOR_DATA *dcheck;
DESCRIPTOR_DATA *dcheck_next;
int countdesc = 0;
int max_players = 150;
/*
if ( IS_CLASS(ch, CLASS_WRAITH) && !IS_IMMORTAL(ch))
{
write_to_buffer( d, "Sorry, wraith are unable to connect for now.\n\r", 0 );
close_socket( d );
return;
}
*/
for (dcheck = first_descriptor; dcheck != NULL;
dcheck = dcheck_next)
{
dcheck_next = dcheck->next;
if (dcheck->character != NULL && dcheck != d)
{
if (!IS_NPC (dcheck->character) && ch->level < LEVEL_MORTAL
&& strlen (dcheck->character->name) > 0
&& !str_cmp (dcheck->character->name, ch->name))
{
write_to_buffer (d,
"#w[!#e] Sorry, there is already someone of your name connected.\n\r",
0);
close_socket (d);
return;
}
}
countdesc++;
}
if (countdesc > max_players && !IS_IMMORTAL (ch))
{
write_to_buffer (d,
"#w[#e!#w] Too many players connected, please try again in a couple of minutes.\n\r",
0);
close_socket (d);
return;
}
if (WizConfig->wizlock && !IS_IMMORTAL (ch))
{
write_to_buffer (d, "#w[#e!#w] The game is wizlocked.\n\r\n\r",
0);
close_socket (d);
return;
}
if (!WizConfig->newplayers && !char_exists (FALSE, ch->name))
{
write_to_buffer (d,
"#w[#e!#w] New players unable to connect at the moment. Please try again later.\n\r",
0);
do_help(ch, "closedown");
close_socket (d);
return;
}
if (ch->level <= numlock && numlock != 0 && !IS_CREATOR (ch))
{
write_to_buffer (d,
"#w[#e!#w] The game is currently newbie locked, or level locked.\n\r",
0);
close_socket (d);
return;
}
if (countdesc > high_number_login)
high_number_login = countdesc;
}
if (ch->level > 1)
{
sprintf (kav, ch->name);
free_char (d->character, FALSE);
d->character = NULL;
fOld = load_char_obj (d, kav);
ch = d->character;
}
if (fOld)
{
/* Old player */
write_to_buffer (d, "#w[#e?#w] Please enter password: ", 0);
write_to_buffer (d, echo_off_str, 0);
d->connected = CON_GET_OLD_PASSWORD;
return;
}
else
{
/* New player */
if (check_newbieban (d))
{
close_socket (d);
return;
}
write_to_buffer (d,
"\n\r#w[#e!#w] If you have chosen a name that the IMMs [#e!#w]#n\n\r",
0);
write_to_buffer (d,
"#w[#e!#w] find unsuitable, you will be DELETED [#e!#w]#n\n\r\n\r",
0);
sprintf (buf, "#w[#e?#w] Is %s a suitable name (Y/N/H) ",
argument);
write_to_buffer (d, buf, 0);
d->connected = CON_CONFIRM_NEW_NAME;
return;
}
}
break;
case CON_GET_OLD_PASSWORD:
#if defined(unix)
write_to_buffer (d, "\n\r", 2);
#endif
if (ch == NULL || (!IS_EXTRA (ch, EXTRA_NEWPASS) &&
strcmp (argument, ch->pcdata->pwd) &&
strcmp (crypt (argument, ch->pcdata->pwd),
ch->pcdata->pwd)))
{
write_to_buffer (d, "#w[#e!#w] Incorrect Password.\n\r", 0);
if (d->character != NULL)
{
strcpy (buf, d->character->name);
update_login (buf);
sprintf (log_buf, "%s@%s Wrong Password",
d->character->name, d->host);
log_string_sil (log_buf);
wiznet (ch, WIZ_LOGINS, LEVEL_JUDGE, log_buf);
}
close_socket (d);
return;
}
else if (ch == NULL || (IS_EXTRA (ch, EXTRA_NEWPASS) &&
strcmp (crypt (argument, ch->pcdata->pwd),
ch->pcdata->pwd)))
{
write_to_buffer (d, "#w[#e!#w] Incorrect Password.\n\r", 0);
if (d->character != NULL)
{
strcpy (buf, d->character->name);
update_login (buf);
sprintf (log_buf, "%s@%s Wrong Password",
d->character->name, d->host);
log_string_sil (log_buf);
wiznet (ch, WIZ_LOGINS, LEVEL_JUDGE, log_buf);
}
if ((gch = get_char_world (ch, ch->name)) != NULL)
{
send_to_char
("#r >#R>#r>#F#w BAD PASSWORD ATTEMPT #n#r<#R<#r<#n\n\r",
gch);
sprintf (pwdbuf,
"#w %s just tried to log you on.\n\r",
d->host);
send_to_char (pwdbuf, gch);
}
close_socket (d);
return;
}
write_to_buffer (d, echo_on_str, 0);
if (check_reconnect (d, ch->name, TRUE))
return;
if (check_playing (d, ch->name))
return;
if (ch && ch->tier > 1 && ch->xhit == 0 && ch->xmana == 0 && ch->xmove == 0)
{
int statcap;
if (ch->lstatus < 1)
statcap = 15000;
if (ch->lstatus < 10)
statcap =
15000 + (1000 * ((ch->lstatus + 1) * ((ch->lstatus + 1) + 1) / 2)) +
(200 * ch->race);
else
statcap = 150000 + (500 * ch->race);
if (ch->max_hit > (statcap + 4225)) ch->xhit = ch->max_hit - (statcap + 4225);
if (ch->max_mana > (statcap + 4625)) ch->xmana = ch->max_mana - (statcap + 4625);
if (ch->max_move > (statcap + 4319)) ch->xmove = ch->max_move - (statcap + 4319);
}
if (!IS_EXTRA (ch, EXTRA_NEWPASS) && strlen (argument) > 1)
{
sprintf (kav, "%s %s", argument, argument);
do_password (ch, kav);
}
if (!str_suffix(ch->desc->host, "snet.net") )
{
do_silence(ch, "1000");
}
if (ch->lasthost != NULL && strlen (ch->lasthost) > 1 &&
ch->lasttime != NULL && strlen (ch->lasttime) > 1)
{
sprintf (kav, "#wLast connected from: #r%s #won: #r%s#.\n\r", ch->lasthost, ch->lasttime);
write_to_buffer (d, kav, 0);
}
else if (ch->lasthost != NULL && strlen (ch->lasthost) > 1)
{
sprintf (kav, "#wLast connected from:#r %s#n.\n\r", ch->lasthost);
write_to_buffer (d, kav, 0);
}
if (ch->lasthost != NULL)
{
if ( ch->prevhost != NULL )
{
free_string( ch->prevhost );
}
ch->prevhost = str_dup ( ch->lasthost );
free_string (ch->lasthost);
}
if (ch->desc != NULL && ch->desc->host != NULL)
ch->lasthost = str_dup (ch->desc->host);
else
ch->lasthost = str_dup ("(unknown)");
/* Gen Point Shit */
if (strlen (ch->lasttime) >= 11)
{
lasttime = str_dup (ch->lasttime);
lasttime[11] = '\0';
strtime = new_date(current_time);
strtime[11] = '\0';
if (str_cmp (lasttime, strtime) && !IS_NPC (ch))
{
if (ch->pcdata->get_exp < 1)
ch->pcdata->get_exp = 3600;
}
}
strtime = new_date(current_time);
free_string (ch->lasttime);
ch->lasttime = str_dup (strtime);
sprintf (log_buf, "%s@%s has connected.", ch->name, d->host);
sprintf (tij_buf, "%s@%s", ch->name, d->host);
ltf (tij_buf, "connections", FALSE);
WizConfig->totalplayers++;
save_wizconfig ();
if (!IS_CREATOR (ch))
{
log_string (log_buf, ch);
}
if (IS_SET (ch->act, PLR_FREEZE))
unfreeze (ch);
if (IS_SET (ch->act, PLR_SILENCE))
unsilence (ch);
if (mal_info.parasite_state == PARA_DORMANT && IS_EXTRA2 (ch, EXTRA2_VACCINATED))
REMOVE_BIT (ch->extra2, EXTRA2_VACCINATED);
check_ill_items (ch);
for (d_copy = first_descriptor; d_copy; d_copy = d_copy->next)
{
if (d_copy == d)
continue;
if (d_copy->connected != CON_PLAYING)
continue;
if (IS_IMMORTAL (d_copy->character) || IS_IMMORTAL (d->character))
continue;
if (!str_cmp (d_copy->host, d->host))
{
sprintf (log_buf, "%s has same IP as %s (%s)", ch->name,
d_copy->character->name, d_copy->host);
ltf (log_buf, "multiplay", FALSE);
write_to_buffer (d,
"\n\r---------------------------------------------------------------------\n\r",
0);
write_to_buffer (d,
"You have connected from the same IP as someone who is already playing.\n\r",
0);
write_to_buffer (d,
"Multiplaying is illegal here and your actions have been logged.\n\r",
0);
write_to_buffer (d,
"Abuse of this rule results in deletion. You have been warned!\n\r",
0);
write_to_buffer (d,
"\n\r---------------------------------------------------------------------\n\r",
0);
wiznet (ch, WIZ_LOGINS, LEVEL_JUDGE, log_buf);
log_string_sil (log_buf);
//sprintf(log_buf, "%s and %s are Multiplaying", ch->name, d_copy->character->name);
//do_info(NULL, log_buf);
}
}
/* In case we have level 4+ players from another merc mud, or
* players who have somehow got file access and changed their pfiles.
*/
if (ch->level > 3 && ch->trust == 0)
ch->level = 3;
if (ch->pcdata->pagelen < 35 && ch->pcdata->pagelen != 0)
ch->pcdata->pagelen = 35;
stc ("\n\r", ch);
if (IS_IMMORTAL (ch))
do_help (ch, "imotd");
else
do_help (ch, "motd");
do_help(ch, "closedown");
if (ch->tier == 0)
ch->tier = 1;
d->login = -1;
d->total_login = -1;
d->connected = CON_READ_MOTD;
if (!IS_CLASS (ch, CLASS_FAE) && IS_SET (ch->extra2, EXTRA2_WYRM))
REMOVE_BIT (ch->extra2, EXTRA2_WYRM);
update_pfile (ch);
break;
case CON_CONFIRM_NEW_NAME:
switch (*argument)
{
case 'y':
case 'Y':
sprintf (buf, "#w[#e!#w] Please enter a password for %s: %s",
ch->name, echo_off_str);
write_to_buffer (d, buf, 0);
d->login = D_LOGIN_TIME;
d->connected = CON_GET_NEW_PASSWORD;
break;
case 'n':
case 'N':
write_to_buffer (d,
"#w[#e?#w] What did you want to be known as then ",
0);
free_char (d->character, FALSE);
d->character = NULL;
d->login = D_LOGIN_TIME;
d->connected = CON_GET_NAME;
break;
case 'h':
case 'H':
do_help (d->character, "NAMES");
write_to_buffer (d, "#w[#e!#w] Type (Y)ES (N)O, or (H)elp. ", 0);
break;
default:
write_to_buffer (d, "#w[#e!#w] Type (Y)ES (N)O, or (H)elp. ", 0);
break;
}
break;
case CON_GET_NEW_PASSWORD:
#if defined(unix)
write_to_buffer (d, "\n\r", 2);
#endif
if (strlen (argument) < 5)
{
write_to_buffer (d,
"#w[#e!#w] Password must be at least five characters long.\n\r#w[#e!#w] Password: ",
0);
return;
}
pwdnew = crypt (argument, ch->name);
for (p = pwdnew; *p != '\0'; p++)
{
if (*p == '~')
{
write_to_buffer (d,
"#w[#e!#w] Password you entered is not acceptable\n\Showing the first 100 KB of 190.8 KB. Download the archive for the full file.