comm.c
toc/code/comm.c · 321.6 KB
From the archive fear2.1.3.tar.gz
Download the archive « Back to the archive contents
/****************************************************************************
* [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame | \\._.// *
* -----------------------------------------------------------| (0...0) *
* SMAUG 1.4 (C) 1994, 1995, 1996, 1998 by Derek Snider | ).:.( *
* -----------------------------------------------------------| {o o} *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, | / ' ' \ *
* Scryn, Rennard, Swordbearer, Gorog, Grishnakh, Nivek, |~'~.VxvxV.~'~*
* Tricops and Fireblade | *
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* ------------------------------------------------------------------------ *
* Low-level communication module *
****************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <dirent.h>
#include "mud.h"
#ifdef DNS_SLAVE /* DNS slave stuff, more sections like this follow - Samson 12-21-00 */
#include "dns_slave.h"
#endif
/*
* Socket and TCP/IP stuff.
*/
#ifdef WIN32
#include <io.h>
#undef EINTR
#undef EMFILE
#define EINTR WSAEINTR
#define EMFILE WSAEMFILE
#define EWOULDBLOCK WSAEWOULDBLOCK
#define MAXHOSTNAMELEN 32
#define TELOPT_ECHO '\x01'
#define GA '\xF9'
#define SE '\xF0'
#define SB '\xFA'
#define WILL '\xFB'
#define WONT '\xFC'
#define DO '\xFD'
#define DONT '\xFE'
#define IAC '\xFF'
void bailout(void);
void shutdown_checkpoint(void);
#else
#include <sys/socket.h>
#include <netinet/in.h>
/*#include <netinet/in_systm.h> */
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <arpa/telnet.h>
#include <netdb.h>
#define closesocket close
#endif
#define TELOPT_MXP '\x5B'
#ifdef sun
int gethostname(char *name, int namelen);
#endif
const unsigned char echo_off_str [] = { IAC, WILL, TELOPT_ECHO, '\0' };
const unsigned char echo_on_str [] = { IAC, WONT, TELOPT_ECHO, '\0' };
const unsigned char go_ahead_str [] = { IAC, GA, '\0' };
const unsigned char will_mxp_str [] = { IAC, WILL, TELOPT_MXP, '\0' };
const unsigned char start_mxp_str [] = { IAC, SB, TELOPT_MXP, IAC, SE, '\0' };
const unsigned char do_mxp_str [] = { IAC, DO, TELOPT_MXP, '\0' };
const unsigned char dont_mxp_str [] = { IAC, DONT, TELOPT_MXP, '\0' };
void save_sysdata args((SYSTEM_DATA sys));
#ifdef MCCP
#define TELOPT_COMPRESS 85
#define TELOPT_COMPRESS2 86
const char eor_on_str [] = { IAC, WILL, TELOPT_EOR, '\0' };
const char compress_on_str [] = { IAC, WILL, TELOPT_COMPRESS, '\0' };
const char compress2_on_str [] = { IAC, WILL, TELOPT_COMPRESS2, '\0' };
bool compressStart args( ( DESCRIPTOR_DATA *d, unsigned char telopt ) );
bool compressEnd args( ( DESCRIPTOR_DATA *d ) );
#endif
void auth_maxdesc args((int *md, fd_set * ins, fd_set * outs, fd_set * excs));
void auth_check args((fd_set * ins, fd_set * outs, fd_set * excs));
void set_auth args((DESCRIPTOR_DATA * d));
void kill_auth args((DESCRIPTOR_DATA * d));
/*
* Global variables.
*/
IMMORTAL_HOST *immortal_host_start; /* Start of Immortal legal domains */
IMMORTAL_HOST *immortal_host_end; /* End of Immortal legal domains */
DESCRIPTOR_DATA *first_descriptor; /* First descriptor */
DESCRIPTOR_DATA *last_descriptor; /* Last descriptor */
DESCRIPTOR_DATA *d_next; /* Next descriptor in loop */
int num_descriptors;
FILE *fpReserve; /* Reserved file handle */
bool mud_down; /* Shutdown */
bool service_shut_down; /* Shutdown by operator closing down service */
bool wizlock; /* Game is wizlocked */
time_t boot_time;
HOUR_MIN_SEC set_boot_time_struct;
HOUR_MIN_SEC *set_boot_time;
struct tm *new_boot_time;
struct tm new_boot_struct;
char str_boot_time[MIL];
char lastplayercmd[MIL * 2];
time_t current_time; /* Time of this pulse */
int control; /* Controlling descriptor */
int control2; /* Controlling descriptor #2 */
int conclient; /* MUDClient controlling desc */
int conjava; /* JavaMUD controlling desc */
int newdesc; /* New descriptor */
fd_set in_set; /* Set of desc's for reading */
fd_set out_set; /* Set of desc's for writing */
fd_set exc_set; /* Set of desc's with errors */
int maxdesc;
char *alarm_section = "(unknown)";
#ifdef DNS_SLAVE
pid_t slave_pid;
pid_t pastslave_pid;
static int slave_socket = -1;
#endif
/*
* OS-dependent local functions.
*/
void game_loop args(());
int init_socket args((int port));
void new_descriptor args((int new_desc));
bool read_from_descriptor args((DESCRIPTOR_DATA * d));
bool write_to_descriptor args((int desc, char *txt, int length));
/*
* Other local functions (OS-independent).
*/
bool check_parse_name args((char *name, bool newchar));
bool check_reconnect args((DESCRIPTOR_DATA * d, char *name, bool fConn));
bool check_playing args((DESCRIPTOR_DATA * d, char *name, bool kick));
int main args((int argc, char **argv));
void nanny args((DESCRIPTOR_DATA * d, char *argument));
bool flush_buffer args((DESCRIPTOR_DATA * d, bool fPrompt));
void read_from_buffer args((DESCRIPTOR_DATA * d));
void stop_idling args((CHAR_DATA * ch));
void free_desc args((DESCRIPTOR_DATA * d));
void display_prompt args((DESCRIPTOR_DATA * d));
int make_color_sequence args((const char *col, char *buf, DESCRIPTOR_DATA * d));
void set_pager_input args((DESCRIPTOR_DATA * d, char *argument));
bool pager_output args((DESCRIPTOR_DATA * d));
void mail_count args((CHAR_DATA * ch));
void tax_player args((CHAR_DATA * ch));
int port;
int base_resis_values args((CHAR_DATA *ch, int type));
#ifdef DNS_SLAVE
#define MAX_HOST 60
#define MAX_OPEN_FILES 128
bool get_slave_result(void);
void slave_timeout(void);
void boot_slave(void)
{
int i, sv[2];
if (slave_socket != -1)
{
close(slave_socket);
slave_socket = -1;
}
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv) < 0)
{
bug("boot_slave: socketpair: %s", strerror(errno));
return;
}
/* set to nonblocking */
if (fcntl(sv[0], F_SETFL, FNDELAY) == -1)
{
bug("boot_slave: fcntl( F_SETFL, FNDELAY ): %s", strerror(errno));
close(sv[0]);
close(sv[1]);
return;
}
slave_pid = fork();
switch (slave_pid)
{
case -1:
bug("boot_slave: fork: %s", strerror(errno));
close(sv[0]);
close(sv[1]);
return;
case 0: /* child */
close(sv[0]);
close(0);
close(1);
if (dup2(sv[1], 0) == -1)
{
bug("boot_slave: child: unable to dup stdin: %s", strerror(errno));
_exit(1);
}
if (dup2(sv[1], 1) == -1)
{
bug("boot_slave: child: unable to dup stdout: %s", strerror(errno));
_exit(1);
}
for (i = 3; i < MAX_OPEN_FILES; ++i)
close(i);
execlp("../src/dns_slave", "dns_slave", NULL);
bug("boot_slave: child: unable to exec: %s", strerror(errno));
_exit(1);
}
close(sv[1]);
if (fcntl(sv[0], F_SETFL, FNDELAY) == -1)
{
bug("boot_slave: fcntl: %s", strerror(errno));
close(sv[0]);
return;
}
slave_socket = sv[0];
}
char *printhostaddr(char *hostbuf, struct in_addr *addr)
{
char *tmp;
tmp = inet_ntoa(*addr);
strcpy(hostbuf, tmp);
return (hostbuf + strlen(hostbuf));
}
void make_slave_request(struct sockaddr_in *sock)
{
char buf[512];
int num;
sprintf(buf, "%c%s\n", SLAVE_IPTONAME, inet_ntoa(sock->sin_addr));
if (slave_socket != -1)
{
/* ask slave to do a hostname lookup for us */
if (write(slave_socket, buf, (num = strlen(buf))) != num)
{
bug("[SLAVE] make_slave_request: Losing slave on write: %s", strerror(errno));
close(slave_socket);
slave_socket = -1;
return;
}
}
}
void check_desc_state(DESCRIPTOR_DATA * d)
{
if ((d->site_info & (HostName | HostNameFail)))
{
if (d->connected == CON_GETDNS)
{
d->wait = 0;
d->connected = CON_GET_ACCOUNT;
write_to_buffer(d, "Please enter your account name, or type new for a new account: ", 0);
}
}
}
bool get_slave_result(void)
{
DESCRIPTOR_DATA *d, *n;
char buf[MSL + 1], token[MAX_STRING_LENGTH];
int len, octet[4];
long addr;
len = read(slave_socket, buf, MSL);
if (len < 0)
{
if (errno == EAGAIN || errno == EWOULDBLOCK)
return TRUE;
bug("[SLAVE] get_slave_result: Losing slave on read: %s", strerror(errno));
close(slave_socket);
slave_socket = -1;
return TRUE;
}
else if (!len)
return TRUE;
buf[len] = 0;
switch (buf[0])
{
case SLAVE_IPTONAME_FAIL:
if (sscanf(buf + 1, "%d.%d.%d.%d", &octet[0], &octet[1], &octet[2], &octet[3]) >= 4)
{
addr = (octet[0] << 24) + (octet[1] << 16) + (octet[2] << 8) + (octet[3]);
addr = ntohl(addr);
for (d = first_descriptor; d; d = n)
{
n = d->next;
if (d->site_info & (HostName | HostNameFail))
continue;
if (d->addr != addr)
continue;
/* Do nothing to host name, addr is still there */
d->site_info |= HostNameFail;
check_desc_state(d);
}
}
else
bug("[SLAVE] Invalid: '%s'", buf);
break;
case SLAVE_IPTONAME:
if (sscanf(buf + 1, "%d.%d.%d.%d %s", &octet[0], &octet[1], &octet[2], &octet[3], token) != 5)
{
bug("[SLAVE] Invalid: %s", buf);
return TRUE;
}
addr = (octet[0] << 24) + (octet[1] << 16) + (octet[2] << 8) + (octet[3]);
addr = ntohl(addr);
for (d = first_descriptor; d; d = n)
{
n = d->next;
if (d->site_info & HostName)
continue;
if (d->addr != addr)
continue;
strncpy(d->host, token, MAX_HOST);
d->host[MAX_HOST] = 0;
d->site_info |= HostName;
check_desc_state(d);
}
break;
default:
bug("[SLAVE] Invalid: %s", buf);
break;
}
return FALSE;
}
void slave_timeout(void)
{
DESCRIPTOR_DATA *d, *n;
time_t nowtime, tdiff;
nowtime = time(0);
for (d = first_descriptor; d; d = n)
{
n = d->next;
if (d->connected == CON_GETDNS)
{
/* Worst case, one minute wait */
tdiff = nowtime - d->contime;
/* hostname timeout: 60 seconds */
if ((tdiff > 60) || ((tdiff > 10) && (d->site_info & (HostName | HostNameFail))))
{
d->wait = 0;
d->connected = CON_GET_ACCOUNT;
write_to_buffer(d, "Please enter your account name, or type new for a new account: ", 0);
}
}
}
}
#endif
#ifdef WIN32
int mainthread(int argc, char **argv)
#else
int main(int argc, char **argv)
#endif
{
struct timeval now_time;
char hostn[128];
bool fCopyOver = !TRUE;
/*
* Memory debugging if needed.
*/
#if defined(MALLOC_DEBUG)
malloc_debug(2);
#endif
/*#ifdef MTRACE
setenv( "MALLOC_TRACE", "mtrace_log.log", 0 );
mtrace();
#endif */
num_descriptors = 0;
first_descriptor = NULL;
last_descriptor = NULL;
sysdata.NO_NAME_RESOLVING = TRUE;
sysdata.WAIT_FOR_AUTH = TRUE;
/*
* Init time.
*/
gettimeofday(&now_time, NULL);
current_time = (time_t) now_time.tv_sec;
/* gettimeofday( &boot_time, NULL); okay, so it's kludgy, sue me :) */
boot_time = time(0); /* <-- I think this is what you wanted */
strcpy(str_boot_time, ctime(¤t_time));
/*
* 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;
/* Bug fix submitted by Gabe Yoder */
new_boot_time_t = mktime(new_boot_time);
reboot_check(mktime(new_boot_time));
/* Set reboot time string for do_time */
get_reboot_string();
init_pfile_scan_time(); /* Pfile autocleanup initializer - Samson 5-8-99 */
/*
* Reserve two channels for our use.
*/
if ((fpReserve = fopen(NULL_FILE, "r")) == NULL)
{
perror(NULL_FILE);
exit(1);
}
if ((fpLOG = fopen(NULL_FILE, "r")) == NULL)
{
perror(NULL_FILE);
exit(1);
}
/*
* Get the port number.
*/
port = 4000;
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);
}
}
if (argv[2] && argv[2][0])
{
fCopyOver = TRUE;
control = atoi(argv[3]);
control2 = atoi(argv[4]);
}
else
fCopyOver = FALSE;
/*
* Run the game.
*/
#ifdef WIN32
{
/* Initialise Windows sockets library */
unsigned short wVersionRequested = MAKEWORD(1, 1);
WSADATA wsadata;
int err;
/* Need to include library: wsock32.lib for Windows Sockets */
err = WSAStartup(wVersionRequested, &wsadata);
if (err)
{
fprintf(stderr, "Error %i on WSAStartup\n", err);
exit(1);
}
/* standard termination signals */
signal(SIGINT, (void *) bailout);
signal(SIGTERM, (void *) bailout);
}
#endif /* WIN32 */
#ifdef DNS_SLAVE
log_string("Booting DNS Slave process");
boot_slave();
#endif
log_string("Booting Database");
boot_db(fCopyOver);
log_string("Initializing socket");
if (!fCopyOver) /* We have already the port if copyover'ed */
{
control = init_socket(port);
}
// control = init_socket( port );
/* control2 = init_socket( port+1 );
conclient= init_socket( port+10);
conjava = init_socket( port+20);
*/
/* I don't know how well this will work on an unnamed machine as I don't
have one handy, and the man pages are ever-so-helpful.. -- Alty */
if (gethostname(hostn, sizeof(hostn)) < 0)
{
perror("main: gethostname");
strcpy(hostn, "unresolved");
}
sprintf(log_buf, "%s ready at address %s on port %d.", sysdata.mud_name, hostn, port);
/*
sprintf( log_buf, "Realms of Despair ready at address %s on port %d.",
hostn, port );
*/
log_string(log_buf);
game_loop();
closesocket(control);
closesocket(control2);
closesocket(conclient);
closesocket(conjava);
#ifdef WIN32
if (service_shut_down)
{
CHAR_DATA *vch;
/* Save all characters before booting. */
for (vch = first_char; vch; vch = vch->next)
if (!IS_NPC(vch))
{
shutdown_checkpoint();
save_char_obj(vch);
}
}
/* Shut down Windows sockets */
WSACleanup(); /* clean up */
kill_timer(); /* stop timer thread */
#endif
#ifdef DNS_SLAVE
if (slave_socket != -1)
{
log_string("Terminating DNS Slave process.");
kill(slave_pid, SIGKILL);
}
#endif
/*
* That's all, folks.
*/
log_string("Normal termination of game.");
exit(0);
return 0;
}
int init_socket(int port)
{
char hostname[64];
struct sockaddr_in sa;
int x = 1;
int fd;
gethostname(hostname, sizeof(hostname));
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
perror("Init_socket: socket");
exit(1);
}
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &x, sizeof(x)) < 0)
{
perror("Init_socket: SO_REUSEADDR");
closesocket(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, (void *) &ld, sizeof(ld)) < 0)
{
perror("Init_socket: SO_DONTLINGER");
closesocket(fd);
exit(1);
}
}
#endif
memset(&sa, '\0', sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1)
{
perror("Init_socket: bind");
closesocket(fd);
exit(1);
}
if (listen(fd, 50) < 0)
{
perror("Init_socket: listen");
closesocket(fd);
exit(1);
}
return fd;
}
/* set up MXP */
void turn_on_mxp (DESCRIPTOR_DATA *d)
{
char buf[MSL];
char line[MSL];
SLAB_DATA *slab;
int x;
d->mxp = TRUE; /* turn it on now */
write_to_buffer( d, (char *) start_mxp_str, 0 );
write_to_buffer( d, MXPTAG ("!-- Set up MXP elements --"), 0);
/* Exit tag */
write_to_buffer( d, MXPTAG ("!ELEMENT Ex '<send>' FLAG=RoomExit"), 0);
/* Room description tag */
write_to_buffer( d, MXPTAG ("!ELEMENT rdesc '<p>' FLAG=RoomDesc"), 0);
/* Get an item tag (for things on the ground) */
write_to_buffer( d, MXPTAG
("!ELEMENT Get \"<send href='"
"get '&name;'|"
"examine '&name;'|"
"drink '&name;'|"
"sacrifice '&name;'"
"' "
"hint='RH mouse click to use this object|"
"Get &name;|"
"Examine &name;|"
"Drink from &desc;|"
"Sacrifice &desc;"
"'>\" ATT='name'"),
0);
write_to_buffer( d, MXPTAG
("!ELEMENT Learn \"<send href='"
"learn '&name;' '&skill;' 1|"
"learn '&name;' '&skill;' 2|"
"learn '&name;' '&skill;' 3|"
"learn '&name;' '&skill;' 4|"
"learn '&name;' '&skill;' 5|"
"learn '&name;' '&skill;' 6"
"' "
"hint='RH mouse click to choose mastery level|"
"Learn &skill; from &name; at Beginner|"
"Learn &skill; from &name; at Novice|"
"Learn &skill; from &name; at Expert|"
"Learn &skill; from &name; at Master|"
"Learn &skill; from &name; at Elite|"
"Learn &skill; from &name; at Flawless"
"'>\" ATT='name skill'"),
0);
sprintf(buf, "%s!ELEMENT Forge \"<send href='", MXP_BEG);
x = 1;
for (slab = first_slab; slab ; slab = slab->next)
{
if (!slab->next)
sprintf(line, "forge create %d &name;", x);
else
sprintf(line, "forge create %d &name;|", x);
strcat(buf, line);
x++;
}
strcat(buf, "' hint='RH mouse click to forge this item with the ore in the list|");
for (slab = first_slab; slab ; slab = slab->next)
{
if (!slab->next)
sprintf(line, "Forge &name; out of %s", slab->adj);
else
sprintf(line, "Forge &name; out of %s|", slab->adj);
strcat(buf, line);
}
sprintf(line, "'>\" ATT='name'%s", MXP_END);
strcat(buf, line);
write_to_buffer(d, buf, 0);
/*write_to_buffer(d, MXPTAG
("!ELEMENT Forge \"<send href='"
"forge create 1 &name;;"
"' "
"hint='RH mouse click to use this object|"
"forge &name; out of copper;"
"'>\" ATT='name desc'"), 0); */
//write_to_buffer(d, MXPTAG(buf), 0);
// Output to a Mob
write_to_buffer( d, MXPTAG
("!ELEMENT Mobile \"<send href='"
"attack '&name;' body|"
"examine '&name;'|"
"consider '&name;'|"
"steal coins '&name;'|"
"backstab '&name;'|"
"fire '&name;'"
"' "
"hint='RH mouse click to use this object|"
"Attack &desc;|"
"Examine &desc;|"
"Consider &desc;|"
"Steal Coins from &desc;|"
"Backstab &desc;|"
"Fire on &desc;"
"'>\" ATT='name desc'"),
0);
// Output to a Player on look
write_to_buffer( d, MXPTAG
("!ELEMENT Look \"<send href='"
"glance '&name;'|"
"look '&name;'|"
"introduce self &name;|"
"attack '&name;'|"
"steal coins '&name;'|"
"backstab '&name;'|"
"fire '&name;'"
"' "
"hint='RH mouse click to use this object|"
"Glance at &desc;|"
"Look at &desc;|"
"Introduce yourself to &desc;|"
"Attack &desc;|"
"Steal coins from &desc;|"
"Backstab &desc;|"
"Fire on &desc;"
"'>\" ATT='name desc'"),
0);
/* Drop an item tag (for things in the inventory) */
write_to_buffer( d, MXPTAG
("!ELEMENT Drop \"<send href='"
"drop '&name;'|"
"examine '&name;'|"
"look in '&name;'|"
"wear '&name;'|"
"eat '&name;'|"
"drink '&name;'|"
"repair &name;|"
"c 'identify' &name;"
"' "
"hint='RH mouse click to use this object|"
"Drop &name;|"
"Examine &name;|"
"Look inside &name;|"
"Wear &name;|"
"Eat &name;|"
"Drink &name;|"
"Repair &name;|"
"Identify &name;"
"'>\" ATT='name'"),
0);
write_to_buffer( d, MXPTAG
("!ELEMENT Listgroups \"<send href='"
"listgroups '&name;'|"
"listgroups toadvance &name;"
"' "
"hint='Default is listgroups <group>, right click for more options|"
"Listgroups &name;|"
"Listgroups toadvance &name;"
"'>\" ATT='name'"),
0);
// Used in listgroups on the groups
/* Bid an item tag (for things in the auction) */
write_to_buffer( d, MXPTAG
("!ELEMENT Bid \"<send href='bid '&name;'' "
"hint='Bid for &name;'>\" "
"ATT='name'"),
0);
// Click on a helpfile to view it
write_to_buffer( d, MXPTAG
("!ELEMENT Help \"<send href='help '&name;'' "
"hint='Help &name;'>\" "
"ATT='name'"),
0);
// For any generic command where you don't really need any options but one that is passed
write_to_buffer( d, MXPTAG
("!ELEMENT Command \"<send href='&command;' "
"hint='&desc;'>\" "
"ATT='command desc'"),
0);
// Same as command put sends the text to the prompt
write_to_buffer( d, MXPTAG
("!ELEMENT PCommand \"<send href='&command;' "
"hint='&desc;' prompt>\" "
"ATT='command desc'"),
0);
// Click on a help index to view it
write_to_buffer( d, MXPTAG
("!ELEMENT Hindex \"<send href='hindex '&name;'' "
"hint='hindex &name;'>\" "
"ATT='name'"),
0);
/* List an item tag (for things in a shop) */
write_to_buffer( d, MXPTAG
("!ELEMENT List \"<send href='buy '&name;'' "
"hint='Buy &desc;'>\" "
"ATT='name desc'"),
0);
/* Player tag (for who lists, tells etc.) */
write_to_buffer( d, MXPTAG
("!ELEMENT Player \"<send href='tell '&name;' ' "
"hint='Send a message to &name; (No Menu)' prompt>\" "
"ATT='name'"),
0);
} /* end of turn_on_mxp */
/*
static void SegVio()
{
CHAR_DATA *ch;
char buf[MSL];
log_string( "SEGMENTATION VIOLATION" );
log_string( lastplayercmd );
for ( ch = first_char; ch; ch = ch->next )
{
sprintf( buf, "%cPC: %-20s room: %d", IS_NPC(ch) ? 'N' : ' ',
ch->name, ch->in_room->vnum );
log_string( buf );
}
exit(0);
}
*/
/*
* LAG alarm! -Thoric
*/
void caught_alarm()
{
char buf[MSL];
sprintf(buf, "ALARM CLOCK! In section %s", alarm_section);
bug(buf);
strcpy(buf, "Alas, the hideous malevalent entity known only as 'Lag' rises once more!\n\r");
echo_to_all(AT_IMMORT, buf, ECHOTAR_ALL);
if (newdesc)
{
FD_CLR(newdesc, &in_set);
FD_CLR(newdesc, &out_set);
FD_CLR(newdesc, &exc_set);
log_string("clearing newdesc");
}
}
bool check_bad_desc(int desc)
{
if (FD_ISSET(desc, &exc_set))
{
FD_CLR(desc, &in_set);
FD_CLR(desc, &out_set);
log_string("Bad FD caught and disposed.");
return TRUE;
}
return FALSE;
}
/*
* Determine whether this player is to be watched --Gorog
*/
bool chk_watch(sh_int player_level, char *player_name, char *player_site)
{
WATCH_DATA *pw;
/*
char buf[MIL];
sprintf( buf, "che_watch entry: plev=%d pname=%s psite=%s",
player_level, player_name, player_site);
log_string(buf);
*/
if (!first_watch)
return FALSE;
for (pw = first_watch; pw; pw = pw->next)
{
if (pw->target_name)
{
if (!str_cmp(pw->target_name, player_name) && player_level < pw->imm_level)
return TRUE;
}
else if (pw->player_site)
{
if (!str_prefix(pw->player_site, player_site) && player_level < pw->imm_level)
return TRUE;
}
}
return FALSE;
}
void accept_new(int ctrl)
{
static struct timeval null_time;
DESCRIPTOR_DATA *d;
/* int maxdesc; Moved up for use with id.c as extern */
#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( ctrl, &in_set );
maxdesc = ctrl;
newdesc = 0;
for ( d = first_descriptor; d; 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 ( d == last_descriptor )
break;
}
auth_maxdesc(&maxdesc, &in_set, &out_set, &exc_set);
//maxdesc = imc_fill_fdsets(maxdesc, &in_set, &out_set, &exc_set);
if (select(maxdesc + 1, &in_set, &out_set, &exc_set, &null_time) < 0)
{
perror("accept_new: select: poll");
exit(1);
}
#ifdef DNS_SLAVE
/* slave result? */
if (slave_socket != -1)
{
if (FD_ISSET(slave_socket, &in_set))
{
{
while (!get_slave_result())
;
}
}
}
else
slave_timeout();
#endif
if (FD_ISSET(ctrl, &exc_set))
{
bug("Exception raise on controlling descriptor %d", ctrl);
FD_CLR(ctrl, &in_set);
FD_CLR(ctrl, &out_set);
}
else if (FD_ISSET(ctrl, &in_set))
{
newdesc = ctrl;
new_descriptor(newdesc);
}
}
void game_loop()
{
struct timeval last_time;
char cmdline[MIL];
DESCRIPTOR_DATA *d;
/* time_t last_check = 0; */
#ifndef WIN32
signal(SIGPIPE, SIG_IGN);
signal(SIGALRM, caught_alarm);
#endif
/* signal( SIGSEGV, SegVio ); */
gettimeofday(&last_time, NULL);
current_time = (time_t) last_time.tv_sec;
/* Main loop */
while (!mud_down)
{
accept_new(control);
accept_new(control2);
accept_new(conclient);
accept_new(conjava);
auth_check(&in_set, &out_set, &exc_set);
/*
* Kick out descriptors with raised exceptions
* or have been idle, then check for input.
*/
for (d = first_descriptor; d; d = d_next)
{
int tlogin, tnotes, tidle;
if (d == d->next)
{
bug("descriptor_loop: loop found & fixed");
d->next = NULL;
}
d_next = d->next;
d->idle++; /* make it so a descriptor can idle out */
if (d && d->character && d->character->pcdata)
{
tlogin = d->character->pcdata->timeout_login;
tnotes = d->character->pcdata->timeout_notes;
tidle = d->character->pcdata->timeout_idle;
}
else
{
tlogin = sysdata.timeout_login;
tnotes = sysdata.timeout_notes;
tidle = sysdata.timeout_idle;
}
if (tlogin == 0)
tlogin = 720;
if (tnotes == 0)
tnotes = 2000000000; //Not forever, but damn close;
if (tidle == 0)
tidle = 2000000000; //Not forever, but damn close;
if (tlogin < 60)
tlogin = 60;
if (FD_ISSET(d->descriptor, &exc_set))
{
FD_CLR(d->descriptor, &in_set);
FD_CLR(d->descriptor, &out_set);
if (d->character && (d->connected == CON_PLAYING || d->connected == CON_EDITING))
save_char_obj(d->character);
d->outtop = 0;
close_socket(d, TRUE);
continue;
}
else if ((d->connected < CON_SHOW_ACCOUNT_MENU && d->connected > CON_LAST_MENU_OPTION && !d->character && d->idle > tlogin) /* 3 mins */
|| (d->connected != CON_PLAYING && d->idle > tnotes) /* 10 mins */ //buffer and menu
|| d->idle > tidle) /* 20 min */
{
write_to_descriptor(d->descriptor, "Idle timeout... disconnecting.\n\r", 0);
d->outtop = 0;
close_socket(d, TRUE);
continue;
}
else
{
d->fcommand = FALSE;
if (FD_ISSET(d->descriptor, &in_set))
{
d->idle = 0;
if (d->character)
d->character->timer = 0;
if (!read_from_descriptor(d))
{
FD_CLR(d->descriptor, &out_set);
if (d->character && (d->connected == CON_PLAYING || d->connected == CON_EDITING))
save_char_obj(d->character);
d->outtop = 0;
close_socket(d, FALSE);
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 && d->character->wait > 0)
{
--d->character->wait;
continue;
}
read_from_buffer(d);
#ifdef DNS_SLAVE /* Fix here provided by Senir */
if (d->incomm[0] != '\0' && d->connected != CON_GETDNS)
#else
if (d->incomm[0] != '\0')
#endif
{
d->fcommand = TRUE;
stop_idling(d->character);
strcpy(cmdline, d->incomm);
d->incomm[0] = '\0';
if (d->character)
set_cur_char(d->character);
if (d->pagepoint)
set_pager_input(d, cmdline);
else
switch (d->connected)
{
default:
nanny(d, cmdline);
break;
case CON_PLAYING:
interpret(d->character, cmdline);
break;
case CON_EDITING:
edit_buffer(d->character, cmdline);
break;
}
}
}
if (d == last_descriptor)
break;
}
/*
* Autonomous game motion.
*/
update_handler();
/*
* Check REQUESTS pipe
*/
check_requests();
/*
* Output.
*/
for (d = first_descriptor; d; d = d_next)
{
d_next = d->next;
if ((d->fcommand || d->outtop > 0) && FD_ISSET(d->descriptor, &out_set))
{
if (d->pagepoint)
{
if (!pager_output(d))
{
if (d->character && (d->connected == CON_PLAYING || d->connected == CON_EDITING))
save_char_obj(d->character);
d->outtop = 0;
close_socket(d, FALSE);
}
}
else if (!flush_buffer(d, TRUE))
{
if (d->character && (d->connected == CON_PLAYING || d->connected == CON_EDITING))
save_char_obj(d->character);
d->outtop = 0;
close_socket(d, FALSE);
}
}
if (d == last_descriptor)
break;
}
/*
* 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;
#ifdef WIN32
Sleep((stall_time.tv_sec * 1000L) + (stall_time.tv_usec / 1000L));
#else
if (select(0, NULL, NULL, NULL, &stall_time) < 0 && errno != EINTR)
{
perror("game_loop: select: stall");
exit(1);
}
#endif
}
}
gettimeofday(&last_time, NULL);
current_time = (time_t) last_time.tv_sec;
/* Check every 5 seconds... (don't need it right now)
if ( last_check+5 < current_time )
{
CHECK_LINKS(first_descriptor, last_descriptor, next, prev,
DESCRIPTOR_DATA);
last_check = current_time;
}
*/
}
/* Save morphs so can sort later. --Shaddai */
if (sysdata.morph_opt)
save_morphs();
fflush(stderr); /* make sure strerr is flushed */
return;
}
void init_descriptor(DESCRIPTOR_DATA * dnew, int desc)
{
dnew->next = NULL;
dnew->descriptor = desc;
dnew->connected = CON_GET_ACCOUNT;
dnew->outsize = 2000;
dnew->idle = 0;
dnew->lines = 0;
dnew->scrlen = 24;
dnew->user = STRALLOC("unknown");
dnew->ifd = -1; /* Descriptor pipes, used for DNS resolution and such */
dnew->ipid = -1;
dnew->newstate = 0;
dnew->prevcolor = 0x07;
dnew->mxp = FALSE; /* NJG - initially MXP is off */
CREATE(dnew->outbuf, char, dnew->outsize);
}
void new_descriptor(int new_desc)
{
char buf[MSL];
DESCRIPTOR_DATA *dnew;
struct sockaddr_in sock;
int desc;
int size;
/* char bugbuf[MSL]; */
#ifdef WIN32
unsigned long arg = 1;
#endif
size = sizeof(sock);
if (check_bad_desc(new_desc))
{
set_alarm(0);
return;
}
set_alarm(20);
alarm_section = "new_descriptor::accept";
if ((desc = accept(new_desc, (struct sockaddr *) &sock, (socklen_t *) &size)) < 0)
{
set_alarm(0);
return;
}
if ( check_bad_desc( new_desc ) )
{
set_alarm( 0 );
return;
}
#if !defined(FNDELAY)
#define FNDELAY O_NDELAY
#endif
set_alarm(20);
alarm_section = "new_descriptor: after accept";
#ifdef WIN32
if (ioctlsocket(desc, FIONBIO, &arg) == -1)
#else
if (fcntl(desc, F_SETFL, FNDELAY) == -1)
#endif
{
perror("New_descriptor: fcntl: FNDELAY");
set_alarm(0);
return;
}
if (check_bad_desc(new_desc))
return;
CREATE(dnew, DESCRIPTOR_DATA, 1);
init_descriptor(dnew, desc);
dnew->port = ntohs(sock.sin_port);
strcpy(buf, inet_ntoa(sock.sin_addr));
sprintf(log_buf, "Sock.sinaddr: %s, port %hd.", buf, dnew->port);
log_string_plus(log_buf, LOG_COMM, sysdata.log_level);
CREATE( dnew->outbuf, char, dnew->outsize );
strcpy( log_buf, inet_ntoa( sock.sin_addr ) );
dnew->host = STRALLOC( log_buf );
if ( !sysdata.NO_NAME_RESOLVING )
{
strcpy( buf, in_dns_cache( log_buf ) );
if( buf[0] == '\0' )
resolve_dns( dnew, sock.sin_addr.s_addr );
else
{
STRFREE( dnew->host );
dnew->host = STRALLOC( buf );
}
}
if (check_total_bans(dnew))
{
write_to_descriptor(desc, "Your site has been banned from this Mud.\n\r", 0);
free_desc(dnew);
set_alarm(0);
return;
}
/*
* Init descriptor data.
*/
if (!last_descriptor && first_descriptor)
{
DESCRIPTOR_DATA *d;
bug("New_descriptor: last_desc is NULL, but first_desc is not! ...fixing");
for (d = first_descriptor; d; d = d->next)
if (!d->next)
last_descriptor = d;
}
#ifdef MCCP
write_to_buffer(dnew, eor_on_str, 0);
write_to_buffer(dnew, compress2_on_str, 0);
write_to_buffer(dnew, compress_on_str, 0);
#endif
LINK(dnew, first_descriptor, last_descriptor, next, prev);
/*
* Send the greeting.
*/
{
extern char *help_greeting;
if (help_greeting[0] == '.')
write_to_buffer(dnew, help_greeting + 1, 0);
else
write_to_buffer(dnew, help_greeting, 0);
}
#ifdef DNS_SLAVE
if (!sysdata.NO_NAME_RESOLVING)
{
make_slave_request(&sock);
write_to_buffer(dnew, "Please wait - looking up DNS information.\n\r", 0);
/* Make 'em wait, don't wanna lose site info */
dnew->wait = 1 << 24;
dnew->connected = CON_GETDNS;
}
else
{
write_to_buffer(dnew, "Please enter your account name, or type new for a new account: ", 0);
}
#else
write_to_buffer(dnew, "Please enter your account name, or type new for a new account: ", 0);
#endif
alarm_section = "new_descriptor: set_auth";
set_auth(dnew);
alarm_section = "new_descriptor: after set_auth";
if (++num_descriptors > sysdata.maxplayers)
sysdata.maxplayers = num_descriptors;
if (sysdata.maxplayers > sysdata.alltimemax)
{
if (sysdata.time_of_max)
DISPOSE(sysdata.time_of_max);
sprintf(buf, "%24.24s", ctime(¤t_time));
sysdata.time_of_max = str_dup(buf);
sysdata.alltimemax = sysdata.maxplayers;
sprintf(log_buf, "Broke all-time maximum player record: %d", sysdata.alltimemax);
log_string_plus(log_buf, LOG_COMM, sysdata.log_level);
to_channel(log_buf, CHANNEL_MONITOR, "Monitor", LEVEL_IMMORTAL);
save_sysdata(sysdata);
}
set_alarm(0);
return;
}
void free_desc(DESCRIPTOR_DATA * d)
{
kill_auth(d);
closesocket(d->descriptor);
#ifndef DNS_SLAVE
STRFREE(d->host);
#endif
DISPOSE(d->outbuf);
if (d->account)
{
ACCOUNT_NAME *aname;
ACCOUNT_NAME *anext;
//Don't want to lock them out of their account by getting disconnected, laugh
if (d->account->editing == 1)
{
d->account->editing = 0;
save_account(d, 0);
}
for (aname = d->account->first_player; aname; aname = anext)
{
anext = aname->next;
if (aname->name)
STRFREE(aname->name);
DISPOSE(aname);
}
if (d->account->name)
STRFREE(d->account->name);
if (d->account->passwd)
STRFREE(d->account->passwd);
if (d->account->email)
STRFREE(d->account->email);
DISPOSE(d->account);
}
STRFREE(d->user); /* identd */
if (d->pagebuf)
DISPOSE(d->pagebuf);
#ifdef MCCP
compressEnd(d);
#endif
DISPOSE(d);
/* --num_descriptors; This is called from more than close_socket -- Alty */
return;
}
void close_socket(DESCRIPTOR_DATA * dclose, bool force)
{
CHAR_DATA *ch;
DESCRIPTOR_DATA *d;
bool DoNotUnlink = FALSE;
if( dclose->ipid != -1 )
{
int status;
kill( dclose->ipid, SIGKILL );
waitpid( dclose->ipid, &status, 0 );
}
if( dclose->ifd != -1 )
close( dclose->ifd );
/* flush outbuf */
if (!force && dclose->outtop > 0)
flush_buffer(dclose, FALSE);
/* say bye to whoever's snooping this descriptor */
if (dclose->snoop_by)
write_to_buffer(dclose->snoop_by, "Your victim has left the game.\n\r", 0);
/* stop snooping everyone else */
for (d = first_descriptor; d; d = d->next)
if (d->snoop_by == dclose)
d->snoop_by = NULL;
/* Check for switched people who go link-dead. -- Altrag */
if (dclose->original)
{
if ((ch = dclose->character) != NULL)
do_return(ch, "");
else
{
bug("Close_socket: dclose->original without character %s", (dclose->original->name ? dclose->original->name : "unknown"));
dclose->character = dclose->original;
dclose->original = NULL;
}
}
ch = dclose->character;
/* sanity check :( */
if (!dclose->prev && dclose != first_descriptor)
{
DESCRIPTOR_DATA *dp, *dn;
bug("Close_socket: %s desc:%p != first_desc:%p and desc->prev = NULL!", ch ? ch->name : d->host, dclose, first_descriptor);
dp = NULL;
for (d = first_descriptor; d; d = dn)
{
dn = d->next;
if (d == dclose)
{
bug("Close_socket: %s desc:%p found, prev should be:%p, fixing.", ch ? ch->name : d->host, dclose, dp);
dclose->prev = dp;
break;
}
dp = d;
}
if (!dclose->prev)
{
bug("Close_socket: %s desc:%p could not be found!.", ch ? ch->name : dclose->host, dclose);
DoNotUnlink = TRUE;
}
}
if (!dclose->next && dclose != last_descriptor)
{
DESCRIPTOR_DATA *dp, *dn;
bug("Close_socket: %s desc:%p != last_desc:%p and desc->next = NULL!", ch ? ch->name : d->host, dclose, last_descriptor);
dn = NULL;
for (d = last_descriptor; d; d = dp)
{
dp = d->prev;
if (d == dclose)
{
bug("Close_socket: %s desc:%p found, next should be:%p, fixing.", ch ? ch->name : d->host, dclose, dn);
dclose->next = dn;
break;
}
dn = d;
}
if (!dclose->next)
{
bug("Close_socket: %s desc:%p could not be found!.", ch ? ch->name : dclose->host, dclose);
DoNotUnlink = TRUE;
}
}
if (dclose->character)
{
if ((dclose->connected == CON_PLAYING
|| dclose->connected == CON_ROLL_STATS
|| dclose->connected == CON_EDITING) || (dclose->connected >= CON_NOTE_TO && dclose->connected <= CON_NOTE_FINISH))
{
if (xIS_SET(ch->act, PLR_GAMBLER))
{
act(AT_ACTION, "Because $n lost $s link, $e forfeits $s bet.", ch, NULL, NULL, TO_CANSEE);
xREMOVE_BIT(ch->act, PLR_GAMBLER); /* Removes gambler bit in player */
}
act(AT_ACTION, "$n has lost $s link.", ch, NULL, NULL, TO_CANSEE);
ch->desc = NULL;
}
/* else if ( dclose->connected == CON_PLAYING )
{
if ( dclose->character->position == POS_FIGHTING
|| dclose->character->position == POS_EVASIVE
|| dclose->character->position == POS_DEFENSIVE
|| dclose->character->position == POS_AGGRESSIVE
|| dclose->character->position == POS_BERSERK )
{
act( AT_ACTION, "$n has lost $s link.", ch, NULL, NULL, TO_CANSEE );
ch->desc = NULL;
}
else
{
ch->desc = NULL;
ld_punt( ch );
}
} */
else
{
sprintf(log_buf, "Closing link to %s.", ch->pcdata->filename);
log_string_plus(log_buf, LOG_COMM, UMAX(sysdata.log_level, ch->level));
/* clear descriptor pointer to get rid of bug message in log */
dclose->character->desc = NULL;
free_char(dclose->character);
}
}
if (!DoNotUnlink)
{
free_runbuf(dclose);
/* make sure loop doesn't get messed up */
if (d_next == dclose)
d_next = d_next->next;
UNLINK(dclose, first_descriptor, last_descriptor, next, prev);
}
if (dclose->mxpclient)
STRFREE(dclose->mxpclient);
#ifdef MCCP
compressEnd(dclose);
#endif
if (dclose->descriptor == maxdesc)
--maxdesc;
free_desc(dclose);
--num_descriptors;
return;
}
bool read_from_descriptor(DESCRIPTOR_DATA * d)
{
int iStart, iErr;
/* Hold horses if pending command already. */
if (d->incomm[0] != '\0')
return TRUE;
/* Check for overflow. */
iStart = strlen(d->inbuf);
if (iStart >= sizeof(d->inbuf) - 10)
{
sprintf(log_buf, "%s input overflow!", d->host);
log_string(log_buf);
write_to_descriptor(d->descriptor,
"\n\r*** PUT A LID ON IT!!! ***\n\rYou cannot enter the same command more than 20 consecutive times!\n\r", 0);
return FALSE;
}
for (;;)
{
int nRead;
nRead = recv(d->descriptor, d->inbuf + iStart, sizeof(d->inbuf) - 10 - iStart, 0);
#ifdef WIN32
iErr = WSAGetLastError();
#else
iErr = errno;
#endif
if (nRead > 0)
{
iStart += nRead;
if (d->inbuf[iStart - 1] == '\n' || d->inbuf[iStart - 1] == '\r')
break;
}
else if (nRead == 0)
{
log_string_plus("EOF encountered on read.", LOG_COMM, sysdata.log_level);
return FALSE;
}
else if (iErr == EWOULDBLOCK)
break;
else
{
perror("Read_from_descriptor");
return FALSE;
}
}
d->inbuf[iStart] = '\0';
return TRUE;
}
/*
* Transfer one line from input buffer to input line.
*/
void read_from_buffer(DESCRIPTOR_DATA * d)
{
CHAR_DATA *ch;
char buf[MSL];
char *c;
int i, j, k;
#ifdef MCCP
int iac = 0;
#endif
unsigned char *p;
buf[0] = '\0';
ch = d->original ? d->original : d->character; /* Defined pointer ch -- Xerves 4/16/99 */
/*
* Hold horses if pending command already.
*/
if (d->incomm[0] != '\0')
return;
if (d->run_buf)
{
while (isdigit(*d->run_head) && *d->run_head != '\0')
{
char *s, *e;
s = d->run_head;
while (isdigit(*s))
s++;
e = s;
while (*(--s) == '0' && s != d->run_head) ;
if (isdigit(*s) && *s != '0' && *e != 'o')
{
if (*(e + 1) == '+')
{
c = e;
e++;
switch (*(++e))
{
case 'e':
case 'w':
case 's':
case 'n':
sprintf(buf, "%c%c", *c, *e);
break;
default:
return;
}
strcpy(d->incomm, buf);
}
else
{
d->incomm[0] = *e;
d->incomm[1] = '\0';
}
s[0]--;
while (isdigit(*(++s)))
*s = '9';
return;
}
if (*e == 'o')
d->run_head = e;
else
{
if (*(++e) == '+')
{
e++;
e++;
}
d->run_head = e;
}
}
if (*d->run_head != '\0')
{
if (*d->run_head != 'o')
{
if (*(d->run_head + 1) == '+')
{
c = d->run_head;
d->run_head++;
switch (*(++d->run_head))
{
case 'e':
case 'w':
case 's':
case 'n':
sprintf(buf, "%c%c", *c, *d->run_head++);
break;
default:
return;
}
strcpy(d->incomm, buf);
}
else
{
d->incomm[0] = *d->run_head++;
d->incomm[1] = '\0';
}
return;
}
else
{
char buf2[MIL];
d->run_head++;
c = d->run_head;
sprintf(buf, "open ");
if (*(d->run_head + 1) == '+')
{
d->run_head++;
switch (*(++d->run_head))
{
case 'e':
case 'w':
case 's':
case 'n':
sprintf(buf2, "%c%c", *c, *d->run_head);
switch (buf2[0])
{
case 'n':
if ((buf2[1]) == 'w')
{
sprintf(buf + strlen(buf), "northwest");
break;
}
if ((buf2[1]) == 'e')
{
sprintf(buf + strlen(buf), "northeast");
break;
}
case 'e':
if ((buf2[1]) == 'n')
{
sprintf(buf + strlen(buf), "northeast");
break;
}
if ((buf2[1]) == 's')
{
sprintf(buf + strlen(buf), "southeast");
break;
}
case 'w':
if ((buf2[1]) == 'n')
{
sprintf(buf + strlen(buf), "northwest");
break;
}
if ((buf2[1]) == 's')
{
sprintf(buf + strlen(buf), "southwest");
break;
}
case 's':
if ((buf2[1]) == 'e')
{
sprintf(buf + strlen(buf), "southeast");
break;
}
if ((buf2[1]) == 'w')
{
sprintf(buf + strlen(buf), "southwest");
break;
}
default:
return;
}
break;
default:
return;
}
}
else
{
switch (*d->run_head)
{
case 'n':
sprintf(buf + strlen(buf), "north");
break;
case 's':
sprintf(buf + strlen(buf), "south");
break;
case 'e':
sprintf(buf + strlen(buf), "east");
break;
case 'w':
sprintf(buf + strlen(buf), "west");
break;
case 'u':
sprintf(buf + strlen(buf), "up");
break;
case 'd':
sprintf(buf + strlen(buf), "down");
break;
default:
return;
}
}
strcpy(d->incomm, buf);
d->run_head++;
return;
}
}
free_runbuf(d);
}
/*
Look for incoming telnet negotiation
*/
for (p = d->inbuf; *p; p++)
if (*p == IAC)
{
if (memcmp (p, do_mxp_str, strlen ((char *) do_mxp_str)) == 0)
{
turn_on_mxp (d);
/* remove string from input buffer */
memmove (p, &p [strlen ((char *) do_mxp_str)], strlen ((char *) &p [strlen ((char *) do_mxp_str)]) + 1);
p--; /* adjust to allow for discarded bytes */
} /* end of turning on MXP */
else if (memcmp (p, dont_mxp_str, strlen ((char *) dont_mxp_str)) == 0)
{
d->mxp = FALSE;
/* remove string from input buffer */
memmove (p, &p [strlen ((char *) dont_mxp_str)], strlen ((char *) &p [strlen ((char *) dont_mxp_str)]) + 1);
p--; /* adjust to allow for discarded bytes */
} /* end of turning off MXP */
} /* end of finding an IAC */
/*
* Look for at least one new line.
*/
for (i = 0; d->inbuf[i] != '\n' && d->inbuf[i] != '\r' && i < MAX_INBUF_SIZE; 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 >= 254)
{
write_to_descriptor(d->descriptor, "Line too long.\n\r", 0);
/* skip the rest of the line */
/*
for ( ; d->inbuf[i] != '\0' || i>= MAX_INBUF_SIZE ; i++ )
{
if ( d->inbuf[i] == '\n' || d->inbuf[i] == '\r' )
break;
}
*/
d->inbuf[i] = '\n';
d->inbuf[i + 1] = '\0';
break;
}
#ifdef MCCP
if ( d->inbuf[i] == (signed char)IAC )
iac=1;
else if ( iac==1 && (d->inbuf[i] == (signed char)DO || d->inbuf[i] == (signed char)DONT) )
iac=2;
else if ( iac==2 )
{
iac = 0;
/*if ( d->inbuf[i] == (signed char)TELOPT_COMPRESS )
{
if ( d->inbuf[i-1] == (signed char)DO )
compressStart(d, TELOPT_COMPRESS);
else if ( d->inbuf[i-1] == (signed char)DONT )
compressEnd(d);
}
else */if ( d->inbuf[i] == (signed char)TELOPT_COMPRESS2 )
{
if ( d->inbuf[i-1] == (signed char)DO )
compressStart(d, TELOPT_COMPRESS2);
else if ( d->inbuf[i-1] == (signed char)DONT )
compressEnd(d);
}
}
else
#endif
if (d->inbuf[i] == '\b' && k > 0)
--k;
else if (isascii(d->inbuf[i]) && isprint(d->inbuf[i]))
d->incomm[k++] = d->inbuf[i];
}
/*
* 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))
{
d->repeat = 0;
}
else
{
if (++d->repeat >= 50 && ch && ch->level < LEVEL_IMMORTAL)
{
write_to_descriptor(d->descriptor, "\n\r*** PUT A LID ON IT!!! ***\n\rYou cannot enter the same command more than 50 consecutive times!\n\r", 0);
strcpy(d->incomm, "quit");
}
}
}
/*
* 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;
}
sh_int client_speed( sh_int speed)
{
switch ( speed )
{
default:
break;
case 1:
return 512;
case 2:
return 1024;
case 3:
return 2048;
case 4:
return 3584;
case 5:
return 5120;
case 6:
return 7680;
case 7:
return 10240;
}
return 512; // Better than a mere default case.
}
void do_speed( CHAR_DATA *ch, char *argument)
{
sh_int speed=atoi(argument);
if (!ch->desc)
return; // Don't send messages to people who don't exist. duh.
if (argument[0] == '\0')
{
ch_printf( ch, "Your present speed is a %d, which equates to %d bytes per second.\n\r", ch->desc->speed, client_speed(ch->desc->speed) );
return;
}
if (speed > 6 || speed < 0)
{
send_to_char("Speed is between 0 and 6.\n\r", ch);
return;
}
ch->speed = speed;
ch->desc->speed = speed;
ch_printf( ch, "The MUD will now send output to you at %d bytes per second.\n\r", client_speed( speed) );
if ( client_speed(speed) > 2048)
ch_printf( ch, "You should be aware %d is fast enough to lag you if you have a slow connection.\n\r", client_speed( speed) );
return;
}
/*
* Low level output function.
*/
bool flush_buffer(DESCRIPTOR_DATA * d, bool fPrompt)
{
char buf[MIL * UMAX( 1, d->speed)];
extern bool mud_down;
/*
* If buffer has more than their max, send max every second.
*/
if (!mud_down && d->outtop > UMAX(MAX_INBUF_SIZE*4,client_speed( d->speed )))
{
memcpy(buf, d->outbuf, client_speed( d->speed ));
memmove(d->outbuf, d->outbuf + client_speed( d->speed ), d->outtop - client_speed( d->speed ));
d->outtop -= client_speed( d->speed );
if (d->snoop_by)
{
char snoopbuf[MIL * UMAX( 1, d->speed)];
buf[client_speed( d->speed )] = '\0';
if (d->character && d->character->name)
{
if (d->original && d->original->name)
sprintf(snoopbuf, "%s (%s)", d->character->name, d->original->name);
else
sprintf(snoopbuf, "%s", d->character->name);
write_to_buffer(d->snoop_by, snoopbuf, 0);
}
write_to_buffer(d->snoop_by, "% ", 2);
write_to_buffer(d->snoop_by, buf, 0);
}
if (!write_to_descriptor(d->descriptor, buf, client_speed( d->speed )))
{
d->outtop = 0;
return FALSE;
}
return TRUE;
}
/*
* Bust a prompt.
*/
if (fPrompt && !mud_down && d->connected == CON_PLAYING)
{
CHAR_DATA *ch;
ch = d->original ? d->original : d->character;
if (xIS_SET(ch->act, PLR_BLANK))
write_to_buffer(d, "\n\r", 2);
if (xIS_SET(ch->act, PLR_PROMPT))
display_prompt(d);
if (xIS_SET(ch->act, PLR_TELNET_GA))
write_to_buffer(d, (char *) go_ahead_str, 0);
}
/*
* Short-circuit if nothing to write.
*/
if (d->outtop == 0)
return TRUE;
/*
* Snoop-o-rama.
*/
if (d->snoop_by)
{
/* without check, 'force mortal quit' while snooped caused crash, -h */
if (d->character && d->character->name)
{
/* Show original snooped names. -- Altrag */
if (d->original && d->original->name)
sprintf(buf, "%s (%s)", d->character->name, d->original->name);
else
sprintf(buf, "%s", d->character->name);
write_to_buffer(d->snoop_by, buf, 0);
}
write_to_buffer(d->snoop_by, "% ", 2);
write_to_buffer(d->snoop_by, d->outbuf, d->outtop);
}
/*
* OS-dependent output.
*/
if (!write_to_descriptor(d->descriptor, d->outbuf, d->outtop))
{
d->outtop = 0;
return FALSE;
}
else
{
d->outtop = 0;
return TRUE;
}
}
/*
* Count number of mxp tags need converting
* ie. < becomes <
* > becomes >
* & becomes &
*/
int count_mxp_tags (const int bMXP, const char *txt, int length)
{
char c;
const char * p;
int count;
int bInTag = FALSE;
int bInEntity = FALSE;
for (p = txt, count = 0;
length > 0;
p++, length--)
{
c = *p;
if (bInTag) /* in a tag, eg. <send> */
{
if (!bMXP)
count--; /* not output if not MXP */
if (c == MXP_ENDc)
bInTag = FALSE;
} /* end of being inside a tag */
else if (bInEntity) /* in a tag, eg. <send> */
{
if (!bMXP)
count--; /* not output if not MXP */
if (c == ';')
bInEntity = FALSE;
} /* end of being inside a tag */
else switch (c)
{
case MXP_BEGc:
bInTag = TRUE;
if (!bMXP)
count--; /* not output if not MXP */
else
count += 4; /* allow for ESC [1z */
break;
case MXP_ENDc: /* shouldn't get this case */
if (!bMXP)
count--; /* not output if not MXP */
break;
case MXP_AMPc:
bInEntity = TRUE;
if (!bMXP)
count--; /* not output if not MXP */
break;
default:
if (bMXP)
{
switch (c)
{
case '<': /* < becomes < */
case '>': /* > becomes > */
count += 3;
break;
case '&':
count += 4; /* & becomes & */
break;
case '"': /* " becomes " */
count += 5;
break;
} /* end of inner switch */
} /* end of MXP enabled */
} /* end of switch on character */
} /* end of counting special characters */
return count;
} /* end of count_mxp_tags */
void convert_mxp_tags (const int bMXP, char * dest, const char *src, int length)
{
char c;
const char * ps;
char * pd;
int bInTag = FALSE;
int bInEntity = FALSE;
for (ps = src, pd = dest;
length > 0;
ps++, length--)
{
c = *ps;
if (bInTag) /* in a tag, eg. <send> */
{
if (c == MXP_ENDc)
{
bInTag = FALSE;
if (bMXP)
*pd++ = '>';
}
else if (bMXP)
*pd++ = c; /* copy tag only in MXP mode */
} /* end of being inside a tag */
else if (bInEntity) /* in a tag, eg. <send> */
{
if (bMXP)
*pd++ = c; /* copy tag only in MXP mode */
if (c == ';')
bInEntity = FALSE;
} /* end of being inside a tag */
else switch (c)
{
case MXP_BEGc:
bInTag = TRUE;
if (bMXP)
{
memcpy (pd, MXPMODE (1), 4);
pd += 4;
*pd++ = '<';
}
break;
case MXP_ENDc: /* shouldn't get this case */
if (bMXP)
*pd++ = '>';
break;
case MXP_AMPc:
bInEntity = TRUE;
if (bMXP)
*pd++ = '&';
break;
default:
if (bMXP)
{
switch (c)
{
case '<':
memcpy (pd, "<", 4);
pd += 4;
break;
case '>':
memcpy (pd, ">", 4);
pd += 4;
break;
case '&':
memcpy (pd, "&", 5);
pd += 5;
break;
case '"':
memcpy (pd, """, 6);
pd += 6;
break;
default:
*pd++ = c;
break; /* end of default */
} /* end of inner switch */
}
else
*pd++ = c; /* not MXP - just copy character */
break;
} /* end of switch on character */
} /* end of converting special characters */
} /* end of convert_mxp_tags */
/*
* Append onto an output buffer.
*/
void write_to_buffer(DESCRIPTOR_DATA * d, const char *txt, int length)
{
int origlength;
if (!d)
{
bug("Write_to_buffer: NULL descriptor");
return;
}
/*
* Normally a bug... but can happen if loadup is used.
*/
if (!d->outbuf)
return;
/*
* Find length in case caller didn't.
*/
if (length <= 0)
length = strlen(txt);
/* Uncomment if debugging or something
if ( length != strlen(txt) )
{
bug( "Write_to_buffer: length(%d) != strlen(txt)!", length );
length = strlen(txt);
}
*/
origlength = length;
/* work out how much we need to expand/contract it */
length += count_mxp_tags (d->mxp, txt, length);
/*
* Initial \n\r if needed.
*/
if (d->outtop == 0 && !d->fcommand)
{
d->outbuf[0] = '\n';
d->outbuf[1] = '\r';
d->outtop = 2;
}
/*
* Expand the buffer as needed.
*/
while (d->outtop + length >= d->outsize)
{
if (d->outsize > 64000)
{
/* empty buffer */
d->outtop = 0;
close_socket(d, TRUE);
bug("Buffer overflow. Closing (%s).", d->character ? d->character->name : "???");
return;
}
d->outsize *= 2;
RECREATE(d->outbuf, char, d->outsize);
}
/*
* Copy.
*/
convert_mxp_tags (d->mxp, d->outbuf + d->outtop, txt, origlength );
d->outtop += length;
d->outbuf[d->outtop] = '\0';
return;
}
#ifdef MCCP
#define COMPRESS_BUF_SIZE MAX_INBUF_SIZE
bool write_to_descriptor( int desc, char *txt, int length )
{
DESCRIPTOR_DATA *d;
int iStart = 0;
int nWrite = 0;
int nBlock;
int len;
if (length <= 0)
length = strlen(txt);
for (d = first_descriptor; d; d = d->next)
if (d->descriptor == desc)
break;
if (!d || d->descriptor != desc)
d = NULL;
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)
{
int status = deflate(d->out_compress, Z_SYNC_FLUSH);
if (status != Z_OK)
return FALSE;
}
len = d->out_compress->next_out - d->out_compress_buf;
if (len > 0)
{
for (iStart = 0; iStart < len; iStart += nWrite)
{
nBlock = UMIN (len - iStart, MAX_INBUF_SIZE*4);
if ((nWrite = write(d->descriptor, d->out_compress_buf + iStart, nBlock)) < 0)
{
perror( "Write_to_descriptor: compressed" );
return FALSE;
}
if (!nWrite)
break;
}
if (!iStart)
break;
if (iStart < len)
memmove(d->out_compress_buf, d->out_compress_buf+iStart, len - iStart);
d->out_compress->next_out = d->out_compress_buf + len - iStart;
}
}
return TRUE;
}
for (iStart = 0; iStart < length; iStart += nWrite)
{
nBlock = UMIN (length - iStart, MAX_INBUF_SIZE*4);
if ((nWrite = write(desc, txt + iStart, nBlock)) < 0)
{
perror( "Write_to_descriptor" );
return FALSE;
}
}
return TRUE;
}
#else
/*
* 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(int desc, char *txt, int length)
{
int iStart;
int nWrite;
int nBlock;
if (length <= 0)
length = strlen(txt);
for (iStart = 0; iStart < length; iStart += nWrite)
{
nBlock = UMIN(length - iStart, MAX_INBUF_SIZE*4);
if ((nWrite = send(desc, txt + iStart, nBlock, 0)) < 0)
{
perror("Write_to_descriptor");
return FALSE;
}
}
return TRUE;
}
#endif
#ifdef MCCP
/*
* Ported to SMAUG by Garil of DOTDII Mud
* aka Jesse DeFer <dotd@dotd.com> http://www.dotd.com
*
* revision 1: MCCP v1 support
* revision 2: MCCP v2 support
* revision 3: Correct MMCP v2 support
* revision 4: clean up of write_to_descriptor() suggested by Noplex@CB
*
* See the web site below for more info.
*/
/*
* mccp.c - support functions for mccp (the Mud Client Compression Protocol)
*
* see http://homepages.ihug.co.nz/~icecube/compress/ and README.Rom24-mccp
*
* Copyright (c) 1999, Oliver Jowett <icecube@ihug.co.nz>.
*
* This code may be freely distributed and used if this copyright notice is
* retained intact.
*/
void *zlib_alloc(void *opaque, unsigned int items, unsigned int size)
{
return calloc(items, size);
}
void zlib_free(void *opaque, void *address)
{
DISPOSE(address);
}
bool process_compressed(DESCRIPTOR_DATA *d)
{
int iStart = 0, nBlock, nWrite, len;
if (!d->out_compress)
return TRUE;
// Try to write out some data..
len = d->out_compress->next_out - d->out_compress_buf;
if (len > 0)
{
// we have some data to write
for (iStart = 0; iStart < len; iStart += nWrite)
{
nBlock = UMIN (len - iStart, 4096);
if ((nWrite = write(d->descriptor, d->out_compress_buf + iStart, nBlock)) < 0)
{
if (errno == EAGAIN ||
errno == ENOSR)
break;
return FALSE;
}
if (!nWrite)
break;
}
if (iStart)
{
// We wrote "iStart" bytes
if (iStart < len)
memmove(d->out_compress_buf, d->out_compress_buf+iStart, len - iStart);
d->out_compress->next_out = d->out_compress_buf + len - iStart;
}
}
return TRUE;
}
char enable_compress[] =
{
IAC, SB, TELOPT_COMPRESS, WILL, SE, 0
};
char enable_compress2[] =
{
IAC, SB, TELOPT_COMPRESS2, IAC, SE, 0
};
bool compressStart(DESCRIPTOR_DATA *d, unsigned char telopt)
{
z_stream *s;
if (d->out_compress)
return TRUE;
bug("Starting compression for descriptor %d", d->descriptor);
CREATE(s, z_stream, 1);
CREATE(d->out_compress_buf, unsigned char, COMPRESS_BUF_SIZE);
s->next_in = NULL;
s->avail_in = 0;
s->next_out = d->out_compress_buf;
s->avail_out = COMPRESS_BUF_SIZE;
s->zalloc = zlib_alloc;
s->zfree = zlib_free;
s->opaque = NULL;
if (deflateInit(s, 9) != Z_OK)
{
DISPOSE(d->out_compress_buf);
DISPOSE(s);
return FALSE;
}
if (telopt == TELOPT_COMPRESS)
write_to_descriptor(d->descriptor, enable_compress, 0);
else if (telopt == TELOPT_COMPRESS2)
write_to_descriptor(d->descriptor, enable_compress2, 0);
else
bug("compressStart: bad TELOPT passed");
d->compressing = telopt;
d->out_compress = s;
return TRUE;
}
bool compressEnd(DESCRIPTOR_DATA *d)
{
unsigned char dummy[1];
if (!d->out_compress)
return TRUE;
bug("Stopping compression for descriptor %d", d->descriptor);
d->out_compress->avail_in = 0;
d->out_compress->next_in = dummy;
if (deflate(d->out_compress, Z_FINISH) != Z_STREAM_END)
return FALSE;
if (!process_compressed(d)) /* try to send any residual data */
return FALSE;
deflateEnd(d->out_compress);
DISPOSE(d->out_compress_buf);
DISPOSE(d->out_compress);
d->compressing = 0;
return TRUE;
}
void do_compress( CHAR_DATA *ch, char *argument )
{
if (!ch->desc)
{
send_to_char("What descriptor?!\n", ch);
return;
}
if (argument[0] == '\0')
{
send_to_char("Syntax: compress [toggle/stats]\n\r", ch);
if (ch->desc->out_compress)
send_to_char("&w&WMCCP compression is &w&PON&w\n\r", ch);
else
send_to_char("&w&WMCCP compression is &w&zOFF&w\n\r", ch);
return;
}
if (!str_cmp(argument, "stats"))
{
if ( ch->desc->out_compress && ch->desc->out_compress->total_in)
ch_printf(ch, "Total size of input compressed: &B[&w%d&B]&D\n\r", ch->desc->out_compress->total_in);
if ( ch->desc->out_compress && ch->desc->out_compress->total_out)
ch_printf(ch, "Total size of output compressed: &B[&w%d&B]&D\n\r", ch->desc->out_compress->total_out);
if ( ch->desc->out_compress && ch->desc->out_compress->total_in && ch->desc->out_compress->total_out)
ch_printf(ch, "Current compression ratio: &B[&w%.2f%&B]&D&D\n\r",
(float)ch->desc->out_compress->total_out / (float)ch->desc->out_compress->total_in * (float)100);
return;
}
if (!str_cmp(argument, "toggle"))
{
if (!ch->desc->out_compress)
{
send_to_char("Initiating compression.\n\r", ch);
write_to_buffer( ch->desc, compress2_on_str, 0 );
write_to_buffer( ch->desc, compress_on_str, 0 );
}
else
{
send_to_char("Terminating compression.\n\r", ch);
compressEnd(ch->desc);
}
}
do_compress(ch, "");
}
#else
//Putting a MCCP check would of screwed up insertskills program, just put in an empty
//compress routine instead
void do_compress( CHAR_DATA *ch, char *argument )
{
return;
}
#endif
void skill_addition(CHAR_DATA * ch, sh_int group)
{
sh_int sn;
if ((group < 23 || group > 29) && (group < 31 || group > 34))
{
ch->pcdata->spellgroups[group] = 1;
ch->pcdata->spellpoints[group] = 1;
}
else
{
for (sn = 0; sn < top_sn && skill_table[sn] && skill_table[sn]->name; sn++)
{
if (skill_table[sn]->group[0] == group)
{
if (skill_table[sn]->masterydiff[0] == 1)
{
ch->pcdata->learned[sn] = 1;
ch->pcdata->ranking[sn] = 1;
}
}
}
}
}
char *get_skin_colors(int race)
{
static char buf[MIL];
if (race == RACE_HUMAN || race == RACE_ELF || race == RACE_DWARF || race == RACE_HOBBIT)
{
sprintf(buf, "\n\r[1] Pale White [2] Fair White [3] White [4] Light Tan [5] Moderate Tan\n\r");
strcat(buf, "[6] Tanned [7] Soft Brown [8] Light Brown [9] Fair Brown [10] Brown \n\r");
strcat(buf, "[11] Light Black [12] Fair Black [13] Black [14] Dark Black [15] Pure Black\n\r");
}
if (race == RACE_OGRE)
{
sprintf(buf, "\n\r[1] Pale Green [2] Fair Green [3] Green [4] Dark Green [5] Pure Green\n\r");
strcat(buf, "[6] Soft Brown [7] Light Brown [8] Fair Brown [9] Brown [10] Light Black\n\r");
strcat(buf, "[11] Fair Black [12] Black [13] Dark Black [14] Pure Black\n\r");
}
if (race == RACE_FAIRY)
{
sprintf(buf, "\n\r[1] Pale Blue [2] Fair Blue [3] Blue [4] Dark Blue [5] Pure Blue\n\r");
strcat(buf, "[6] Pale Green [7] Fair Green [8] Green [9] Dark Green [10] Pure Green\n\r");
strcat(buf, "[11] Pale Pink [12] Fair Pink [13] Pink [14] Pale Red [15] Fair Red\n\r");
}
return &buf[0];
}
char *get_hair_color()
{
static char buf[MIL];
sprintf(buf, "\n\r[1] Soft White [2] Fair White [3] White [4] Soft Grey [5] Fair Grey\n\r");
strcat(buf, "[6] Grey [7] Dark Grey [8] Soft Brown [9] Fair Brown [10] Brown \n\r");
strcat(buf, "[11] Dark Brown [12] Soft Black [13] Fair Black [14] Black [15] Dark Black\n\r");
strcat(buf, "[16] Pure Black [17] Soft Blonde [18] Fair Blonde [19] Blonde [20] True Blonde\n\r");
strcat(buf, "[21] Soft Red [22] Fair Red [23] Red [24] Dark Red [25] Pure Red\n\r");
strcat(buf, "[26] Soft Green [27] Fair Green [28] Green [29] Dark Green [30] Pure Green\n\r");
strcat(buf, "[31] Soft Blue [32] Fair Blue [33] Blue [34] Dark Blue [35] Pure Blue\n\r");
strcat(buf, "[36] Soft Purple [37] Fair Purple [38] Purple [28] Dark Purple [40] Pure Purple\n\r");
return &buf[0];
}
char *get_hair_length()
{
static char buf[MIL];
sprintf(buf, "\n\r[1] Bald [2] Freshly Shaved [3] Light Stubble [4] Crew Cut [5] Short\n\r");
strcat(buf, "[6] Temple Length [7] Below Ears [8] Shoulders [9] Upper Back [10] Middle Back\n\r");
strcat(buf, "[11] Lower Back [12] Legs [13] Ground\n\r");
return &buf[0];
}
char *get_hair_style(CHAR_DATA *ch)
{
static char buf[MIL];
if (ch->pcdata->hairlength >=1 && ch->pcdata->hairlength <= 3)
{
sprintf(buf, "\n\r[1] Straight Thin [2] Straight Normal [3] Straight Thick [4] Curled Thin [5] Curled Normal\n\r");
strcat(buf, "[6] Curled Thick\n\r");
}
if (ch->pcdata->hairlength >=4 && ch->pcdata->hairlength <= 6)
{
sprintf(buf, "\n\r[1] Straight Thin [2] Straight Normal [3] Straight Thick [4] Curled Thin [5] Curled Normal\n\r");
strcat(buf, "[6] Curled Thick [7] Permed [8] Spiked [9] Mohawk\n\r");
}
if (ch->pcdata->hairlength >= 7 && ch->pcdata->hairlength <= 9)
{
sprintf(buf, "\n\r[1] Straight Thin [2] Straight Normal [3] Straight Thick [4] Curled Thin [5] Curled Normal\n\r");
strcat(buf, "[6] Curled Thick [7] Permed [8] Spiked [9] Mohawk [10] Mullet Straight\n\r");
strcat(buf, "[11] Mullet Curled [12] Mullet Permed [13] Dreadlocks [14] Braided [15] Afro\n\r");
}
if (ch->pcdata->hairlength > 9)
{
sprintf(buf, "\n\r[1] Straight Thin [2] Straight Normal [3] Straight Thick [4] Curled Thin [5] Curled Normal\n\r");
strcat(buf, "[6] Curled Thick [7] Permed [10] Mullet Straight [11] Mullet Curled [12] Mullet Permed\n\r");
strcat(buf, "[13] Dreadlocks [14] Braided\n\r");
}
return &buf[0];
}
char *get_eye_color()
{
static char buf[MIL];
sprintf(buf, "\n\r[1] Dull Blue [2] Blue [3] Radiant Blue [4] Dull Green [5] Green [6] Radiant Green\n\r");
strcat(buf, "[7] Dull Brown [8] Brown [9] Radiant Brown [10] Dull Red [11] Red [12] Radiant Red\n\r");
strcat(buf, "[13] Dull Black [14] Black [15] Radiant Black [16] Dull White [17] White [18] Radiant White\n\r");
strcat(buf, "[19] Dull Yellow [20] Yellow [21] Radiant Yellow [22] Dull Purple [23] Purple [24] Radiant Purple\n\r");
return &buf[0];
}
char *get_char_height()
{
static char buf[MIL];
sprintf(buf, "\n\r[1] Extremely Short [2] Moderately Short [3] Adequately Short\n\r");
strcat(buf, "[4] Short [5] Below Average [6] Slightly below Average\n\r");
strcat(buf, "[7] Average [8] Slightly Above Average [9] Above Average\n\r");
strcat(buf, "[10] Tall [11] Adequately Towering [12] Moderately Towering\n\r");
strcat(buf, "[13] Extremely Towering\n\r");
return &buf[0];
}
char *get_char_weight()
{
static char buf[MIL];
sprintf(buf, "\n\r[1] Extremely Slender [2] Moderately Slender [3] Adequately Slender\n\r");
strcat(buf, "[4] Slender [5] Below Average [6] Slightly below Average\n\r");
strcat(buf, "[7] Average [8] Slightly Above Average [9] Above Average\n\r");
strcat(buf, "[10] Thick [11] Adequately Thick [12] Moderately Thick\n\r");
strcat(buf, "[13] Extremely Thick\n\r");
return &buf[0];
}
int get_heightweight_percent(int value)
{
if (value == 1)
return 80;
if (value == 2)
return 85;
if (value == 3)
return 88;
if (value == 4)
return 92;
if (value == 5)
return 95;
if (value == 6)
return 97;
if (value == 7)
return 100;
if (value == 8)
return 104;
if (value == 9)
return 108;
if (value == 10)
return 112;
if (value == 11)
return 115;
if (value == 12)
return 118;
if (value == 13)
return 122;
return 100;
}
char *clean_message(char *str)
{
static char cleanstring[1000];
int x = 0;
strcpy(cleanstring, "");
for (;;)
{
if (*str == '\0')
{
cleanstring[x] = *str;
return &cleanstring[0];
}
if (*str != '\r')
{
cleanstring[x]= *str;
str++;
x++;
}
else
str++;
}
return NULL;
}
void send_email(char *subject, char *email, char *message, CHAR_DATA *ch, DESCRIPTOR_DATA *d)
{
static char sendstring[1000];
FILE *fp;
FILE *mfp;
DESCRIPTOR_DATA *nd = NULL;
#define MAIL_ROOT_DIR "/bin/mail"
if (sysdata.accountemail == 0 || sysdata.accountemail == 2)
{
if (ch && ch->desc)
nd = ch->desc;
else if (d)
nd = d;
if (nd && (sysdata.accountemail == 0 || (sysdata.accountemail == 2 && nd->account->noemail == 1)))
{
if (ch && ch->desc)
{
write_to_buffer(ch->desc, message, 0);
return;
}
else if (d)
{
write_to_buffer(d, message, 0);
return;
}
}
}
strcpy(sendstring, "");
message = clean_message(message); //gets rid of the /r in the message if there are any..
fp = fopen(EMAIL_FILE, "w");
fprintf(fp, "%s", message);
fclose(fp);
//sprintf(sendstring, "mail -s \"%s\" \"%s\" < %s", subject, email, EMAIL_FILE);
//system(&sendstring[0]);
sprintf(sendstring, "%s -s \"%s\" \"%s\" < %s", MAIL_ROOT_DIR, subject, email, EMAIL_FILE);
if ((mfp = popen( sendstring, "w" )) == NULL)
{
if (ch)
send_to_char("The message was not sent because the mail program could not be found.\n\r", ch);
bug("send_email: Could not location mail.");
return;
}
pclose(mfp);
remove(EMAIL_FILE);
if (ch)
ch_printf(ch, "Your email has been sent to %s\n\r", email);
}
int check_email_syntax(char *arg1, char *arg2)
{
int x;
for (x=0;;x++)
{
if (arg1[x] == 34 || arg1[x] == 39) // a " and a '
return FALSE;
if (arg1[x] == '\0')
break;
}
for (x=0;;x++)
{
if (arg2[x] == 34 || arg2[x] == 39) // a " and a '
return FALSE;
if (arg2[x] == '\0')
break;
}
return TRUE;
}
void do_sendmail(CHAR_DATA *ch, char *argument)
{
char arg1[100];
char arg2[100];
static char *passargument;
if (ch->dest_buf)
{
argument = ch->dest_buf;
}
else
{
passargument = "";
}
passargument = argument;
if (IS_NPC(ch))
{
send_to_char("Huh?\n\r", ch);
return;
}
if (argument[0] == '\0')
{
send_to_char("Syntax: sendmail \"<subject>\" \"<recepient's email address>\"\n\r", ch);
send_to_char("Once that is typed, you will be sent into the buffer.\n\r", ch);
return;
}
argument = one_argument(argument, arg1);
argument = one_argument(argument, arg2);
if (arg1[0] == '\0')
{
send_to_char("You need to supply a subject.\n\r", ch);
return;
}
if (arg2[0] == '\0')
{
send_to_char("You need to supply an email address.\n\r", ch);
return;
}
if (strlen(arg1) > 95)
{
send_to_char("Subject cannot be longer than 95 characters.\n\r", ch);
return;
}
if (strlen(arg2) > 95)
{
send_to_char("recepient's email address cannot be longer than 95 characters.\n\r", ch);
return;
}
if (!check_email_syntax(arg1, arg2))
{
send_to_char("You cannot supply any \" or \' in your subject or recepient.\n\r", ch);
return;
}
switch (ch->substate)
{
default:
bug("do_description: illegal substate", 0);
return;
case SUB_RESTRICTED:
send_to_char("You cannot use this command from within another command.\n\r", ch);
return;
case SUB_NONE:
if (ch->pcdata->sendmail)
STRFREE(ch->pcdata->sendmail);
ch->pcdata->sendmail = STRALLOC("");
ch->substate = SUB_WRITING_EMAIL;
ch->dest_buf = passargument;
start_editing(ch, ch->pcdata->sendmail);
return;
case SUB_WRITING_EMAIL:
STRFREE(ch->pcdata->sendmail);
passargument = "";
ch->pcdata->sendmail = copy_buffer(ch);
send_email(&arg1[0], &arg2[0], ch->pcdata->sendmail, ch, NULL);
bug("-------------%s is sending an email to %s-------------\n\r", ch->name, arg2);
stop_editing(ch);
return;
}
}
char *generate_new_pass()
{
static char passwd[8];
int x;
int num;
for (x = 0; x <= 6; x++)
{
num = number_range(1, 3);
if (num == 1)
passwd[x] = number_range(48, 57); //numbers
else if (num == 2)
passwd[x] = number_range(65, 90); //uppercase letters
else
passwd[x] = number_range(97, 122); //lowercase letters
}
passwd[x] = '\0';
return passwd;
}
void close_area args((AREA_DATA * pArea));
void delete_character(DESCRIPTOR_DATA *d, CHAR_DATA * ch)
{
char buf[MSL];
char buf2[MSL];
char *name;
set_char_color(AT_RED, ch);
if (ch->last_name && ch->name)
{
remove_from_lastname_file(ch->last_name, ch->name); //remove the player from the lastname file
}
else
bug("do_destroy: That player's lastname could not be removed, need to do it manually");
name = capitalize(ch->name);
sprintf(buf, "%s%c/%s", PLAYER_DIR, tolower(name[0]), name);
sprintf(buf2, "%s%c/%s", BACKUP_DIR, tolower(name[0]), name);
if (!rename(buf, buf2))
{
AREA_DATA *pArea;
set_char_color(AT_RED, ch);
sprintf(buf2, "Player %s destroyed. Pfile saved in backup directory.\n\r", name);
write_to_buffer(d, buf2, 0);
sprintf(buf, "%s%s", GOD_DIR, name);
if (!remove(buf))
write_to_buffer(d, "Player's immortal data destroyed.\n\r", 0);
else if (errno != ENOENT)
{
sprintf(buf2, "Unknown error #%d - %s (immortal data). Report to the Administrator.\n\r", errno, strerror(errno));
write_to_buffer(d, buf2, 0);
sprintf(buf2, "%s destroying %s", ch->name, buf);
perror(buf2);
}
sprintf(buf2, "%s.are", name);
for (pArea = first_build; pArea; pArea = pArea->next)
{
if (!str_cmp(pArea->filename, buf2))
{
sprintf(buf, "%s%s", BUILD_DIR, buf2);
if (IS_SET(pArea->status, AREA_LOADED))
fold_area(pArea, buf, FALSE, 0);
close_area(pArea);
sprintf(buf2, "%s.bak", buf);
set_char_color(AT_RED, ch); /* Log message changes colors */
if (!rename(buf, buf2))
{
write_to_buffer(d, "Player's area data destroyed. Area saved as backup.\n\r", 0);
}
else if (errno != ENOENT)
{
sprintf(buf2, "Unknown error #%d - %s (area data). Report to the Administrator.\n\r", errno, strerror(errno));
write_to_buffer(d, buf2, 0);
sprintf(buf2, "%s destroying %s", ch->name, buf);
perror(buf2);
}
break;
}
}
}
else if (errno == ENOENT)
{
set_char_color(AT_PLAIN, ch);
write_to_buffer(d, "Player does not exist.\n\r", 0);
}
else
{
set_char_color(AT_WHITE, ch);
sprintf(buf2, "Unknown error #%d - %s. Report to the Administrator.\n\r", errno, strerror(errno));
write_to_buffer(d, buf2, 0);
sprintf(buf, "Account %s deleted %s", d->account->name, ch->name);
perror(buf);
}
return;
}
void send_account_menu(DESCRIPTOR_DATA *d)
{
char buf[220];
if (d->account)
{
if (d->account->qplayer1[0] != '\0')
{
sprintf(buf, "[1] Login %-13s ", d->account->qplayer1);
write_to_buffer(d, buf, 0);
}
else
{
write_to_buffer(d, "[1] Empty ", 0);
}
if (d->account->qplayer2[0] != '\0')
{
sprintf(buf, "[2] Login %-13s \n\r", d->account->qplayer2);
write_to_buffer(d, buf, 0);
}
else
{
write_to_buffer(d, "[2] Empty\n\r", 0);
}
if (d->account->qplayer3[0] != '\0')
{
sprintf(buf, "[3] Login %-13s ", d->account->qplayer3);
write_to_buffer(d, buf, 0);
}
else
{
write_to_buffer(d, "[3] Empty ", 0);
}
if (d->account->qplayer4[0] != '\0')
{
sprintf(buf, "[4] Login %-13s \n\r", d->account->qplayer4);
write_to_buffer(d, buf, 0);
}
else
{
write_to_buffer(d, "[4] Empty\n\r", 0);
}
}
write_to_buffer(d, "\n\r[C] Create a New Player [I] Import an old Player\n\r", 0);
write_to_buffer(d, "[D] Delete a Player [P] Change your password\n\r", 0);
write_to_buffer(d, "[L] Login with a Player [S] Get a List of your Players\n\r", 0);
write_to_buffer(d, "[Q] Logout [K] Delete this Account\n\r", 0);
write_to_buffer(d, "[E] Change your email [R] Release a Player\n\r", 0);
write_to_buffer(d, "[B] Set Bypass Login [M] Toggle Player Menu\n\r", 0);
if (sysdata.accountemail == 2)
write_to_buffer(d, "[N] Toggle NoEmail Status \n\r", 0);
}
//In order to make changes you can be the only one logged in.
bool check_connected_accounts(DESCRIPTOR_DATA *d)
{
DESCRIPTOR_DATA *od;
for (od = first_descriptor; od; od = od->next)
{
if (od != d && od->account && !str_cmp(od->account->name, d->account->name))
{
write_to_buffer(d, "You cannot make changes to your account while others are logged on to it.\n\r"
"Have everyone disconnect then try again.\n\r\n\r", 0);
send_account_menu(d);
return 0;
}
}
if (d->account->changes >= sysdata.max_account_changes)
{
write_to_buffer(d, "You have made too many changes this hour, wait till the next hour to make more.\n\r\n\r", 0);
send_account_menu(d);
return 0;
}
d->account->changes++;
for (od = first_descriptor; od; od = od->next)
{
if (od != d && od->account && !str_cmp(od->account->name, d->account->name))
{
od->account->changes++;
}
}
//Don't really need this editing line, but oh well
d->account->editing = 1;
save_account(d, 1);
return 1;
}
void save_char_account(CHAR_DATA *ch, int value, char *password)
{
char strsave[MIL];
char strcopy[MIL];
FILE *fp;
FILE *wfp;
char *ln;
int pnext = 0;
sprintf(strsave, "%s%c/%s", PLAYER_DIR, tolower(ch->pcdata->filename[0]), capitalize(ch->pcdata->filename));
if ((fp = fopen(strsave, "r")) == NULL)
{
bug("Save_char_account: fopen", 0);
perror(strsave);
}
sprintf(strcopy, "%s%c/%s.ac", PLAYER_DIR, tolower(ch->pcdata->filename[0]), capitalize(ch->pcdata->filename));
wfp = fopen(strcopy, "w");
for (;;)
{
if (feof(fp))
break;
ln = fread_line(fp);
if (!strncmp(ln, "Password", 8))
{
if (value == 1)
{
fprintf(wfp, "Password %s~\n", password);
pnext = 0;
continue;
}
else
{
pnext = 0;
continue;
}
}
if (pnext == 1)
{
if (value == 1)
{
fprintf(wfp, "Password %s~\n", password);
pnext = 0;
}
else
pnext = 0;
}
if (!strncmp(ln, "Title", 5))
pnext = 1;
fprintf(wfp, "%s", ln);
}
fclose(wfp);
fclose(fp);
remove(strsave);
rename(strcopy, strsave);
}
void alter_all_forge_items(CHAR_DATA *ch, OBJ_DATA *sobj)
{
OBJ_DATA *obj;
OBJ_DATA *slabobj;
SLAB_DATA *slab;
char arg1[MIL];
for (obj = sobj; obj; obj = obj->next_content)
{
if (xIS_SET(obj->extra_flags, ITEM_FORGEABLE))
{
one_argument(obj->name, arg1);
for (slab = first_slab; slab; slab = slab->next)
{
if (!str_cmp(slab->adj, arg1))
{
slabobj = create_object(get_obj_index(slab->vnum), 1);
ore_alter(ch, obj, slabobj);
extract_obj(slabobj);
}
}
}
if (obj->first_content)
alter_all_forge_items(ch, obj->first_content);
}
}
int get_maxstat args((CHAR_DATA *ch, int stat));
void prepare_to_login(CHAR_DATA *ch, DESCRIPTOR_DATA *d)
{
char motdbuf[MSL];
char buf[MSL];
QUEST_DATA *quest;
sprintf(motdbuf, "\n\rWelcome to %s...\n\r", sysdata.mud_name);
write_to_buffer(d, motdbuf, 0);
add_char(ch);
d->connected = CON_PLAYING;
if (ch->level == 0)
{
OBJ_DATA *obj;
ch->pcdata->clan_name = STRALLOC("");
ch->pcdata->clan = NULL;
/*
ch->alignment += race_table[ch->race]->alignment;
--Taken out for now, might put something back in a bit later..Xerves 8/1/99 */
ch->attacks = race_table[ch->race]->attacks;
ch->defenses = race_table[ch->race]->defenses;
ch->saving_poison_death = race_table[ch->race]->saving_poison_death;
ch->saving_wand = race_table[ch->race]->saving_wand;
ch->saving_para_petri = race_table[ch->race]->saving_para_petri;
ch->saving_breath = race_table[ch->race]->saving_breath;
ch->saving_spell_staff = race_table[ch->race]->saving_spell_staff;
ch->pcdata->hometown = 0; //Automatic part of Rafermand City
ch->pcdata->authwait = 2; // 1 to 2 minute Auth Wait.
/* Moved up top so you cannot pick these two languages out of your selection
-- Xerves 2/00
if ( (iLang = skill_lookup( "common" )) < 0 )
bug( "Nanny: cannot find common language." );
else
{
ch->pcdata->learned[iLang] = 20;
ch->pcdata->ranking[iLang] = 4;
}
for ( iLang = 0; lang_array[iLang] != LANG_UNKNOWN; iLang++ )
if ( lang_array[iLang] == race_table[ch->race]->language )
break;
if ( lang_array[iLang] == LANG_UNKNOWN )
bug( "Nanny: invalid racial language." );
else
{
if ( (iLang = skill_lookup( lang_names[iLang] )) < 0 )
bug( "Nanny: cannot find racial language." );
else
{
ch->pcdata->learned[iLang] = 20;
ch->pcdata->ranking[iLang] = 4;
}
} */
/* ch->resist += race_table[ch->race]->resist; drats */
/* ch->susceptible += race_table[ch->race]->suscept; drats */
if (ch->pcdata->tier < 2)
reset_colors(ch);
/*name_stamp_stats( ch ); -- Removed for Statrolled -- Xerves */
ch->level = 1;
/* Added by Narn. Start new characters with autoexit and autgold
already turned on. Very few people don't use those. */
xSET_BIT(ch->act, PLR_AUTOGOLD);
xSET_BIT(ch->act, PLR_AUTOEXIT);
//Set the pid, used to identify players in RP and other stuff, DO NOT REMOVE
sysdata.top_pid++;
ch->pcdata->pid = sysdata.top_pid;
save_sysdata(sysdata);
if (xIS_SET(ch->act, PLR_REMORT))
xREMOVE_BIT(ch->act, PLR_REMORT);
/* Added by Brittany, Nov 24/96. The object is the adventurer's guide
to the realms of despair, part of Academy.are. */
{
OBJ_INDEX_DATA *obj_ind;
OBJ_DATA *sobj = NULL;
OBJ_DATA *backpack = NULL;
int lcnt;
if (first_slab)
sobj = create_object(get_obj_index(first_slab->vnum), 1);
obj_ind = NULL;
//Brown Cloak
obj_ind = get_obj_index(21241);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
equip_char(ch, obj, WEAR_BACK);
}
obj_ind = NULL;
//Lantern
obj_ind = get_obj_index(21211);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
equip_char(ch, obj, WEAR_LIGHT);
}
obj_ind = NULL;
//Backpack
obj_ind = get_obj_index(21221);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
backpack = obj;
}
obj_ind = NULL;
//beef slabs for food
obj_ind = get_obj_index(21218);
for (lcnt = 1; lcnt <= 10; lcnt++)
{
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
if (backpack)
obj_to_obj(obj, backpack);
else
obj_to_char(obj, ch);
}
}
obj_ind = NULL;
//Dragonskin for water
obj_ind = get_obj_index(21212);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
if (backpack)
obj_to_obj(obj, backpack);
else
obj_to_char(obj, ch);
}
obj_ind = NULL;
//Katana
obj_ind = get_obj_index(21010);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
if (first_slab)
{
alter_forge_obj(ch, obj, sobj, first_slab);
}
}
obj_ind = NULL;
//Hammer
obj_ind = get_obj_index(21031);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
if (first_slab && sobj)
{
alter_forge_obj(ch, obj, sobj, first_slab);
}
}
obj_ind = NULL;
//Kris
obj_ind = get_obj_index(21019);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
if (first_slab && sobj)
{
alter_forge_obj(ch, obj, sobj, first_slab);
}
}
obj_ind = NULL;
//Round Shield
obj_ind = get_obj_index(21068);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
if (first_slab && sobj)
{
alter_forge_obj(ch, obj, sobj, first_slab);
}
}
obj_ind = NULL;
//Chain Mail
obj_ind = get_obj_index(21045);
if (obj_ind != NULL)
{
obj = create_object(obj_ind, 0);
obj_to_char(obj, ch);
if (first_slab && sobj)
{
alter_forge_obj(ch, obj, sobj, first_slab);
}
equip_char(ch, obj, WEAR_BODY);
}
}
if (!sysdata.WAIT_FOR_AUTH)
char_to_room(ch, get_room_index(ROOM_VNUM_SCHOOL));
else
{
char_to_room(ch, get_room_index(ROOM_AUTH_START));
ch->pcdata->auth_state = 1;
SET_BIT(ch->pcdata->flags, PCFLAG_UNAUTHED);
auth_update();
}
}
else if (!IS_IMMORTAL(ch) && ch->pcdata->release_date > 0 && ch->pcdata->release_date > current_time)
{
if (ch->in_room->vnum == 6 || ch->in_room->vnum == 8 || ch->in_room->vnum == 1206)
char_to_room(ch, ch->in_room);
else
char_to_room(ch, get_room_index(8));
}
else if (ch->in_room)
{
if( xIS_SET(ch->in_room->room_flags, ROOM_FORGEROOM))
{
char_to_room(ch, get_room_index(ROOM_VNUM_TEMPLE));
if (ch->pcdata->mount)
{
char_from_room(ch->pcdata->mount);
char_to_room(ch->pcdata->mount, ch->in_room);
}
}
else
{
char_to_room(ch, ch->in_room);
}
}
else if (IS_IMMORTAL(ch))
{
char_to_room(ch, get_room_index(ROOM_VNUM_CHAT));
}
else
{
char_to_room(ch, get_room_index(ROOM_VNUM_TEMPLE));
}
if (IN_WILDERNESS(ch) && !IS_IMMORTAL(ch))
{
if (ch->coord->x >= 1040 && ch->coord->x <= 1500 && ch->coord->y >= 430 && ch->coord->y <= 940)
{
ch->coord->x -= 1000;
}
}
if (get_timer(ch, TIMER_SHOVEDRAG) > 0)
remove_timer(ch, TIMER_SHOVEDRAG);
if (xIS_SET(ch->act, PLR_PKRESET)) //Just toggle this flag if you EVER need to reset pk status mud wide, it works well
{
ch->pcdata->pkills = 0;
ch->pcdata->pdeaths = 0;
ch->pcdata->pranking = 0;
//PLEASE NOTE!!!! Do not reset pkpower, it will update itself automatically
xREMOVE_BIT(ch->act, PLR_PKRESET);
}
if (xIS_SET(ch->act, PLR_KRESET)) //Used now to fix forge equipment on players, should be set if you have played before
{
xREMOVE_BIT(ch->act, PLR_KRESET);
alter_all_forge_items(ch, ch->first_carrying);
}
//str dex int wis con agi
//Need to fix stats from the old system.....
if (ch->perm_str > get_maxstat(ch, 1))
ch->perm_str = get_maxstat(ch, 1);
if (ch->perm_dex > get_maxstat(ch, 2))
ch->perm_dex = get_maxstat(ch, 2);
if (ch->perm_int > get_maxstat(ch, 3))
ch->perm_int = get_maxstat(ch, 3);
if (ch->perm_wis > get_maxstat(ch, 4))
ch->perm_wis = get_maxstat(ch, 4);
if (ch->perm_con > get_maxstat(ch, 5))
ch->perm_con = get_maxstat(ch, 5);
if (ch->perm_con > get_maxstat(ch, 6))
ch->perm_con = get_maxstat(ch, 6);
if (ch->perm_agi > get_maxstat(ch, 7))
ch->perm_agi = get_maxstat(ch, 7);
if (ch->perm_str < (14 + race_table[ch->race]->str_plus - 5 + race_table[ch->race]->str_Showing the first 100 KB of 321.6 KB. Download the archive for the full file.