i3.c
muddy/src/intermud/i3.c · 207.8 KB
From the archive astrum.tar.bz2
Download the archive « Back to the archive contents
/* $Id: i3.c,v 1.666 2004/09/20 10:50:24 shrike Exp $ */
/************************************************************************************
* Copyright 2004 Astrum Metaphora consortium *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
************************************************************************************/
/*
* Copyright (c) 2000 Fatal Dimensions
*
* See the file "LICENSE" or information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
*/
/* Ported to Smaug 1.4a by Samson of Alsherok.
* Consolidated for cross-codebase compatibility by Samson of Alsherok.
* Modifications and enhancements to the code
* Copyright (c)2001-2003 Roger Libiez ( Samson )
* Registered with the United States Copyright Office
* TX 5-562-404
*
* I condensed the 14 or so Fatal Dimensions source code files into this
* one file, because I for one find it far easier to maintain when all of
* the functions are right here in one file.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <fnmatch.h>
#if defined(sun)
#include <strings.h>
#endif
#if defined(I3CIRCLE)
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "db.h"
#include "handler.h"
#include "interpreter.h"
#include "i3.h"
#endif
#if defined(I3SMAUG) || defined(I3CHRONICLES)
#include "mud.h"
#ifdef I3CHRONICLES
#include "factions.h"
#include "files.h"
#include "i3.h"
#endif
#endif
#if defined(I3ROM) || defined(I3MERC) || defined(I3UENVY)
#include "merc.h"
#ifdef I3ROM
#include "tables.h"
#endif
#endif
#ifdef I3ACK
#include "ack.h"
#endif
/* Global variables for I3 */
char I3_input_buffer[IPS];
char I3_output_buffer[OPS];
char I3_currentpacket[IPS];
bool packetdebug = FALSE; /* Packet debugging toggle, can be turned on to check outgoing packets */
long I3_input_pointer = 0;
long I3_output_pointer = 4;
const char *I3_THISMUD;
char *I3_ROUTER_NAME;
const char *manual_router;
int I3_socket;
int i3wait; /* Number of game loops to wait before attempting to reconnect when a socket dies */
int i3timeout; /* Number of loops to wait before giving up on an initial router connection */
time_t ucache_clock; /* Timer for pruning the ucache */
I3_MUD *this_mud;
I3_MUD *first_mud;
I3_MUD *last_mud;
I3_CHANNEL *first_I3chan;
I3_CHANNEL *last_I3chan;
I3_BAN *first_i3ban;
I3_BAN *last_i3ban;
UCACHE_DATA *first_ucache;
UCACHE_DATA *last_ucache;
ROUTER_DATA *first_router;
ROUTER_DATA *last_router;
void i3_printf( CHAR_DATA *ch, const char *fmt, ... ) __attribute__ ( ( format( printf, 2, 3 ) ) );
void i3pager_printf( CHAR_DATA *ch, const char *fmt, ... ) __attribute__ ( ( format( printf, 2, 3 ) ) );
void i3bug( const char *format, ... ) __attribute__ ( ( format( printf, 1, 2 ) ) );
void i3log( const char *format, ... ) __attribute__ ( ( format( printf, 1, 2 ) ) );
void I3_send_channel_listen( I3_CHANNEL *channel, bool lconnect );
void I3_write_channel_config( void );
/* Wrapper function - Makes sure to NULL terminate any string passed to it.
* Used in place of simple calls to strncpy.
*/
void i3strncpy( char *dest, const char *src, size_t size )
{
strncpy( dest, src, size-1 );
dest[size-1] = '\0';
}
/* Wrapper function - Makes sure to NULL terminate any string passed to it.
* Used in place of simple calls to strncat.
*/
void i3strncat( char *dest, const char *src, size_t size )
{
strncat( dest, src, size-1 );
dest[size-1] = '\0';
}
bool i3str_prefix( const char *astr, const char *bstr )
{
if ( !astr )
{
i3bug( "Strn_cmp: null astr." );
return TRUE;
}
if ( !bstr )
{
i3bug( "Strn_cmp: null bstr." );
return TRUE;
}
for ( ; *astr; astr++, bstr++ )
{
if( LOWER(*astr) != LOWER(*bstr) )
return TRUE;
}
return FALSE;
}
char *rankbuffer( CHAR_DATA *ch )
{
static char rbuf[LGST];
if( I3PERM(ch) >= I3PERM_IMM )
{
strcpy( rbuf, "&YStaff" );
if( CH_I3RANK(ch) && CH_I3RANK(ch)[0] != '\0' )
snprintf( rbuf, LGST, "&Y%s", CH_I3RANK(ch) );
}
else
{
strcpy( rbuf, "&BPlayer" );
if( CH_I3RANK(ch) && CH_I3RANK(ch)[0] != '\0' )
snprintf( rbuf, LGST, "&B%s", CH_I3RANK(ch) );
}
return rbuf;
}
char *const perm_names[] =
{
"Notset", "None", "Mort", "Imm", "Admin", "Imp"
};
int get_permvalue( const char *flag )
{
unsigned int x;
for ( x = 0; x < (sizeof(perm_names) / sizeof(perm_names[0])); x++ )
if ( !str_cmp(flag, perm_names[x]) )
return x;
return -1;
}
/*
* Pick off one argument from a string and return the rest.
* Understands quotes. do not mess with case.
* as opposed to native one_argument which ignores case.
*/
const char *i3one_argument( const char *argument, char *arg_first )
{
char cEnd;
int count;
count = 0;
while ( isspace(*argument) )
argument++;
cEnd = ' ';
if ( *argument == '\'' || *argument == '"' )
cEnd = *argument++;
while ( *argument != '\0' || ++count >= 255 )
{
if ( *argument == cEnd )
{
argument++;
break;
}
*arg_first = (*argument);
arg_first++;
argument++;
}
*arg_first = '\0';
while ( isspace(*argument) )
argument++;
return argument;
}
/* Generic log function which will route the log messages to the appropriate system logging function */
void i3log( const char *format, ... )
{
char buf[LGST];
va_list ap;
va_start( ap, format );
vsnprintf( buf, LGST, format, ap );
va_end( ap );
#ifndef I3CIRCLE
log(buf);
#else
basic_mud_log( buf );
#endif
return;
}
/* Generic bug logging function which will route the message to the appropriate function that handles bug logs */
void i3bug( const char *format, ... )
{
char buf[LGST];
va_list ap;
va_start( ap, format );
vsnprintf( buf, LGST, format, ap );
va_end( ap );
#if defined(I3SMAUG)
bug( "%s", buf );
#elif defined(I3CIRCLE)
basic_mud_log( buf );
#else
bug( buf, 0 );
#endif
return;
}
void escape_smaug_color( char *buffer, const char *txt )
{
const char *point;
for( point = txt ; *point ; point++ )
{
*buffer = *point;
if( *point == '&' )
*++buffer = '&';
*++buffer = '\0';
}
*buffer = '\0';
return;
}
/* You need to change the &, } and { tokens in the table below, and in the if statement
* in i3_tagtofish to match what your mud uses to identify a color token with.
*
* & is the foreground text token.
* } is the blink text token.
* { is the background text token.
*/
#define I3MAX_ANSI 50
#define COL_INVALID -1
const char *i3ansi_conversion[I3MAX_ANSI][3] =
{
/*
* Conversion Format Below:
*
* { "<MUD TRANSLATION>", "PINKFISH", "ANSI TRANSLATION" }
*
* Foreground Standard Colors
*/
{ "&x", "%^BLACK%^", "\033[0;0;30m" }, /* Black */
{ "&r", "%^RED%^", "\033[0;0;31m" }, /* Dark Red */
{ "&g", "%^GREEN%^", "\033[0;0;32m" }, /* Dark Green */
{ "&O", "%^ORANGE%^", "\033[0;0;33m" }, /* Orange/Brown */
{ "&b", "%^BLUE%^", "\033[0;0;34m" }, /* Dark Blue */
{ "&p", "%^MAGENTA%^", "\033[0;0;35m" }, /* Purple/Magenta */
{ "&c", "%^CYAN%^", "\033[0;0;36m" }, /* Cyan */
{ "&w", "%^WHITE%^", "\033[0;0;37m" }, /* Grey */
/* Background colors */
{ "{x", "%^B_BLACK%^", "\033[40m" }, /* Black */
{ "{r", "%^B_RED%^", "\033[41m" }, /* Red */
{ "{g", "%^B_GREEN%^", "\033[42m" }, /* Green */
{ "{O", "%^B_ORANGE%^", "\033[43m" }, /* Orange */
{ "{Y", "%^B_YELLOW%^", "\033[43m" }, /* Yellow, which may as well be orange since ANSI doesn't do that */
{ "{B", "%^B_BLUE%^", "\033[44m" }, /* Blue */
{ "{p", "%^B_MAGENTA%^", "\033[45m" }, /* Purple/Magenta */
{ "{c", "%^B_CYAN%^", "\033[46m" }, /* Cyan */
{ "{w", "%^B_WHITE%^", "\033[47m" }, /* White */
/* Text Affects */
{ "&d", "%^RESET%^", "\033[0m" }, /* Reset Text */
{ "&D", "%^RESET%^", "\033[0m" }, /* Reset Text */
{ "&L", "%^BOLD%^", "\033[1m" }, /* Bolden Text(Brightens it) */
{ "&*", "%^EBOLD%^", "\033[0m" }, /* Assumed to be a reset tag to stop bold */
{ "&u", "%^UNDERLINE%^", "\033[4m" }, /* Underline Text */
{ "&$", "%^FLASH%^", "\033[5m" }, /* Blink Text */
{ "&i", "%^ITALIC%^", "\033[3m" }, /* Italic Text */
{ "&v", "%^REVERSE%^", "\033[7m" }, /* Reverse Background and Foreground Colors */
{ "&s", "%^STRIKEOUT%^", "\033[9m" }, /* Strikeover */
/* Foreground extended colors */
{ "&z", "%^BLACK%^%^BOLD%^", "\033[0;1;30m" }, /* Dark Grey */
{ "&R", "%^RED%^%^BOLD%^", "\033[0;1;31m" }, /* Red */
{ "&G", "%^GREEN%^%^BOLD%^", "\033[0;1;32m" }, /* Green */
{ "&Y", "%^YELLOW%^", "\033[0;1;33m" }, /* Yellow */
{ "&B", "%^BLUE%^%^BOLD%^", "\033[0;1;34m" }, /* Blue */
{ "&P", "%^MAGENTA%^%^BOLD%^", "\033[0;1;35m" }, /* Pink */
{ "&C", "%^CYAN%^%^BOLD%^", "\033[0;1;36m" }, /* Light Blue */
{ "&W", "%^WHITE%^%^BOLD%^", "\033[0;1;37m" }, /* White */
/* Blinking foreground standard color */
{ "}x", "%^BLACK%^%^FLASH%^", "\033[0;5;30m" }, /* Black */
{ "}r", "%^RED%^%^FLASH%^", "\033[0;5;31m" }, /* Dark Red */
{ "}g", "%^GREEN%^%^FLASH%^", "\033[0;5;32m" }, /* Dark Green */
{ "}O", "%^ORANGE%^%^FLASH%^", "\033[0;5;33m" }, /* Orange/Brown */
{ "}b", "%^BLUE%^%^FLASH%^", "\033[0;5;34m" }, /* Dark Blue */
{ "}p", "%^MAGENTA%^%^FLASH%^", "\033[0;5;35m" }, /* Magenta/Purple */
{ "}c", "%^CYAN%^%^FLASH%^", "\033[0;5;36m" }, /* Cyan */
{ "}w", "%^WHITE%^%^FLASH%^", "\033[0;5;37m" }, /* Grey */
{ "}z", "%^BLACK%^%^BOLD%^%^FLASH%^", "\033[1;5;30m" }, /* Dark Grey */
{ "}R", "%^RED%^%^BOLD%^%^FLASH%^", "\033[1;5;31m" }, /* Red */
{ "}G", "%^GREEN%^%^BOLD%^%^FLASH%^", "\033[1;5;32m" }, /* Green */
{ "}Y", "%^YELLOW%^%^FLASH%^", "\033[1;5;33m" }, /* Yellow */
{ "}B", "%^BLUE%^%^BOLD%^%^FLASH%^", "\033[1;5;34m" }, /* Blue */
{ "}P", "%^MAGENTA%^%^BOLD%^%^FLASH%^", "\033[1;5;35m" }, /* Pink */
{ "}C", "%^CYAN%^%^BOLD%^%^FLASH%^", "\033[1;5;36m" }, /* Light Blue */
{ "}W", "%^WHITE%^%^BOLD%^%^FLASH%^", "\033[1;5;37m" } /* White */
};
/*
* Simple check to test if a particular code is a valid color. If not, then we can find
* other things to do, in some cases. -Orion
*/
int I3_validcolor( char code[3] )
{
int c = 0, colmatch = COL_INVALID;
if ( code[0] && code[1] && ( code[0] == '&' || code[0] == '{' || code[0] == '}' ) )
{
for( c = 0; c < I3MAX_ANSI; c++ )
{
if( i3ansi_conversion[c][0][0] == code[0] && i3ansi_conversion[c][0][1] == code[1] )
{
colmatch = c;
break;
}
}
}
return colmatch;
}
/*
* Convert txt into pinkfish valid color codes, while parsing the color code information in
* the proper manner. Color codes should be changed to reflect local color. & is the basic
* color, { is the background color, and } is blinking color. -Orion
*/
char *I3_tagtofish( const char *txt )
{
int c, x, count = 0;
static char tbuf[LGST*3];
char code[3];
if( !txt || *txt == '\0' )
return "";
tbuf[0] = '\0';
for( count = 0; count < LGST; count++, txt++ )
{
if( *txt == '\0' )
break;
if( *txt != '&' && *txt != '{' && *txt != '}' )
{
tbuf[count] = *txt;
}
else
{
code[0] = *txt;
code[1] = *(++txt);
code[2] = '\0';
if ( !code[1] || code[1] == '\0' )
{
tbuf[count] = code[0];
count++;
break;
}
else if ( code[0] == code[1] )
{
tbuf[count] = code[0];
}
else if ( ( c = I3_validcolor( code ) ) != COL_INVALID )
{
for( x = 0; i3ansi_conversion[c][1][x]; x++, count++ )
{
tbuf[count] = i3ansi_conversion[c][1][x];
}
count--;
}
else
{
tbuf[count] = code[0];
tbuf[++count] = code[1];
}
}
}
tbuf[count] = '\0';
return tbuf;
}
/* Takes the string you pass it and converts its Pinkfish color tags into ANSI codes */
char *I3_fishtoansi( const char *inbuf, CHAR_DATA *ch )
{
char *cp, *cp2;
char col[30];
static char abuf[LGST*3];
int len;
bool found = FALSE;
/* catch the trivial case first (for speed) */
cp = strstr( inbuf, "%^" );
if( !cp )
{
strcpy( abuf, inbuf );
return abuf;
}
abuf[0] = '\0';
col[0] = '\0';
do
{
cp2 = strstr( cp+2, "%^" );
if (!cp2) break; /* unmatched single %^ */
/* ok, we have 2 delimiters now.
* get the converted color and its length */
len = cp2 - cp + 2;
if( len == 4 )
{ /* means "%^%^" which is the escape */
len = 2;
strcpy( col, "%^" );
}
else
{
if( I3IS_SET( I3FLAG(ch), I3_COLOR ) )
{
int c;
for( c = 0; c < I3MAX_ANSI; c++ )
{
if( !strncmp( cp, i3ansi_conversion[c][1], len ) )
{
strcpy( col, i3ansi_conversion[c][2] );
len = strlen( col );
found = TRUE;
break;
}
}
}
else
{
strcpy( col, "" );
len = 0;
found = TRUE;
}
}
if( !found )
strcpy( col, cp );
/* copy the first part into the buffer and add the converted color code */
strncat( abuf, inbuf, cp-inbuf );
strncat( abuf, col, len );
inbuf = cp2+2;
} while( (cp = strstr( inbuf, "%^" )) );
/* copy the rest */
strcat( abuf, inbuf );
return abuf;
}
/* Generic substitute for write_to_buffer since not all codebases seem to have it */
void to_char_buffer( DESCRIPTOR_DATA *d, const char *txt, int length )
{
write_to_buffer( d, txt, 0 );
return;
}
/* Generic substitute for send_to_char with color support */
void i3_to_char( const char *txt, CHAR_DATA *ch )
{
char buf[LGST*3];
char buf2[LGST*3];
if( !ch )
{
i3bug( "%s", "i3_to_char: NULL ch!" );
return;
}
if( IS_NPC( ch ) )
return;
if( !ch->desc )
{
i3bug( "i3_to_char: NULL descriptor for %s!", CH_I3NAME(ch) );
return;
}
snprintf( buf, LGST*3, "%s", I3_tagtofish( txt ) );
snprintf( buf2, LGST*3, "%s", I3_fishtoansi( buf, ch ) );
to_char_buffer( ch->desc, buf2, 0 );
to_char_buffer( ch->desc, "\033[0m", 0 ); /* Reset color to stop bleeding */
return;
}
/* Generic substitute for ch_printf that passes to i3_to_char for color support */
void i3_printf( CHAR_DATA *ch, const char *fmt, ... )
{
char buf[LGST*2];
va_list args;
va_start( args, fmt );
vsprintf( buf, fmt, args );
va_end( args );
i3_to_char( buf, ch );
}
/* Generic send_to_pager type function to send to the proper code for each codebase */
void i3send_to_pager( const char *txt, CHAR_DATA *ch )
{
#if defined(I3SMAUG) || defined(I3CHRONICLES) || defined(I3ROM)
char buf[LGST*3];
char buf2[LGST*3];
snprintf( buf, LGST*3, "%s", I3_tagtofish( txt ) );
snprintf( buf2, LGST*3, "%s\e[0m", I3_fishtoansi( buf, ch ) );
#endif
#if defined(I3SMAUG) || defined(I3CHRONICLES)
send_to_pager_color( buf2, ch );
#elif defined(I3ROM)
page_to_char( buf2, ch );
#else
i3_to_char( txt, ch );
#endif
return;
}
/* Generic pager_printf type function */
void i3pager_printf( CHAR_DATA *ch, const char *fmt, ... )
{
char buf[LGST*2];
va_list args;
va_start( args, fmt );
vsprintf( buf, fmt, args );
va_end( args );
i3send_to_pager( buf, ch );
return;
}
/* I3_getarg: extract a single argument (with given max length) from
* argument to arg; if arg==NULL, just skip an arg, don't copy it out
*/
const char *I3_getarg( const char *argument, char *arg, int length )
{
int len = 0;
if( !argument || argument[0] == '\0' )
{
if( arg )
arg[0] = '\0';
return argument;
}
while (*argument && isspace( *argument ) )
argument++;
if( arg )
while( *argument && !isspace( *argument ) && len < length-1 )
*arg++ = *argument++, len++;
else
while( *argument && !isspace( *argument ) )
argument++;
while( *argument && !isspace( *argument ) )
argument++;
while( *argument && isspace( *argument ) )
argument++;
if( arg )
*arg = '\0';
return argument;
}
/* Check for a name in a list */
bool I3_hasname( const char *list, const char *name )
{
const char *p;
char arg[SMST];
if( !list )
return FALSE;
p = I3_getarg( list, arg, SMST );
while( arg[0] )
{
if( !strcasecmp( name, arg ) )
return TRUE;
p = I3_getarg( p, arg, SMST );
}
return FALSE;
}
/* Add a name to a list */
void I3_flagchan( const char **list, const char *name )
{
char buf[LGST];
if( I3_hasname( *list, name ) )
return;
if( *list && *list[0] != '\0' )
sprintf( buf, "%s %s", *list, name );
else
strcpy( buf, name );
// I3STRFREE( *list );
if (*list != NULL)
free_string(*list);
*list = I3STRALLOC( buf );
}
/* Remove a name from a list */
void I3_unflagchan( const char **list, const char *name )
{
char buf[LGST], arg[SMST];
const char *p;
buf[0] = '\0';
p = I3_getarg( *list, arg, SMST );
while( arg[0] )
{
if( strcasecmp( arg, name ) )
{
if( buf[0] )
strcat( buf, " " );
strcat( buf, arg );
}
p = I3_getarg( p, arg, SMST );
}
// I3STRFREE( *list );
if (*list != NULL)
free_string(*list);
*list = I3STRALLOC( buf );
}
/*
* You need to change the & and { tokens to match what your mud uses to identify color tags.
* & is the forgound color, { is the background color, and } is the blinking color. Returns
* the string length of an argument, excluding valid color codes. -Orion
*/
int I3_strlen_color( const char *argument )
{
unsigned int i, length;
const char *str;
char code[3];
str = argument;
if( argument[0] == '\0' )
return 0;
for( length = i = 0; i < strlen( argument ); i++ )
{
if( str[i] != '&' && str[i] != '{' && str[i] != '}' )
{
length++;
continue;
}
code[0] = str[i];
code[1] = str[++i];
code[2] = '\0';
if ( I3_validcolor( code ) == COL_INVALID )
{
if ( !code[1] || code[1] == '\0' || code[0] == code[1] )
length++;
else
length += 2;
}
}
return length;
}
/*
* You need to change the & and { tokens to match what your mud uses to identify color tags.
* & is the forgound color, { is the background color, and } is the blinking color. This
* function returns the max length of a field up to a certain point. Color codes included or
* excluded at your leisure. -Orion
*/
int I3_strnlen_color( const char *argument, int maxsize, bool total )
{
unsigned int i, length;
const char *str;
char code[3];
str = argument;
if( argument[0] == '\0' )
return 0;
for( length = i = 0; i < strlen( argument ); i++ )
{
if ( length >= (unsigned int)maxsize )
break;
if( str[i] != '&' && str[i] != '{' && str[i] != '}' )
{
length++;
continue;
}
code[0] = str[i];
code[1] = str[++i];
code[2] = '\0';
if ( I3_validcolor( code ) == COL_INVALID )
{
if ( !code[1] || code[1] == '\0' || code[0] == code[1] )
length++;
else
length += 2;
}
}
if ( total )
return i;
return length;
}
/*
* Returns an initial-capped string.
*/
char *i3capitalize( const char *str )
{
static char strcap[LGST];
int i;
for ( i = 0; str[i] != '\0'; i++ )
strcap[i] = tolower( str[i] );
strcap[i] = '\0';
strcap[0] = toupper( strcap[0] );
return strcap;
}
/* Borrowed from Samson's new_auth snippet - checks to see if a particular player exists in the mud.
* This is called from i3locate and i3finger to report on offline characters.
*/
bool i3exists_player( char *name )
{
struct stat fst;
char buf[LGST];
#ifdef I3CIRCLE
return FALSE;
#else
/* Stands to reason that if there ain't a name to look at, they damn well don't exist! */
if( !name || !str_cmp( name, "" ) )
return FALSE;
sprintf( buf, "%s%c/%s", PLAYER_PATH, tolower( name[0] ), i3capitalize( name ) );
if( stat( buf, &fst ) != -1 )
return TRUE;
else
return FALSE;
#endif
}
bool verify_i3layout( const char *fmt, int number )
{
const char *c;
int i = 0;
c = fmt;
while( ( c = strchr(c, '%') ) != NULL )
{
if( *( c+1 ) == '%' ) /* %% */
{
c += 2;
continue;
}
if( *(c+1) != 's' ) /* not %s */
return FALSE;
c++;
i++;
}
if( i != number )
return FALSE;
return TRUE;
}
/* Fixed this function yet again. If the socket is negative or 0, then it will return
* a FALSE. Used to just check to see if the socket was positive, and that just wasn't
* working for the way some places checked for this. Any negative value is an indication
* that the socket never existed.
*/
bool I3_is_connected( void )
{
if( I3_socket < 1 )
return FALSE;
return TRUE;
}
/*
* Add backslashes in front of the " and \'s
*/
char *I3_escape( const char *ps )
{
static char xnew[LGST];
char *pnew = xnew;
while( ps[0] )
{
if( ps[0] == '"' )
{
pnew[0]= '\\';
pnew++;
}
if( ps[0] == '\\' )
{
pnew[0] = '\\';
pnew++;
}
pnew[0] = ps[0];
pnew++;
ps++;
}
pnew[0] = '\0';
return xnew;
}
/*
* Remove "'s at begin/end of string
* If a character is prefixed by \'s it also will be unescaped
*/
void I3_remove_quotes( char **ps )
{
char *ps1, *ps2;
if( *ps[0] == '"' )
(*ps)++;
if( (*ps)[strlen(*ps)-1] == '"' )
(*ps)[strlen(*ps)-1] = 0;
ps1 = ps2 = *ps;
while( ps2[0] )
{
if( ps2[0] == '\\' )
{
ps2++;
}
ps1[0] = ps2[0];
ps1++;
ps2++;
}
ps1[0] = '\0';
}
/* Searches through the channel list to see if one exists with the localname supplied to it. */
I3_CHANNEL *find_I3_channel_by_localname( const char *name )
{
I3_CHANNEL *channel = NULL;
for( channel = first_I3chan; channel; channel = channel->next )
{
if( !channel->local_name )
continue;
if( !str_cmp( channel->local_name, name ) )
return channel;
}
return NULL;
}
/* Searches through the channel list to see if one exists with the I3 channel name supplied to it.*/
I3_CHANNEL *find_I3_channel_by_name( const char *name )
{
I3_CHANNEL *channel = NULL;
for( channel = first_I3chan; channel; channel = channel->next )
{
if( !str_cmp( channel->I3_name, name ) )
return channel;
}
return NULL;
}
/* Sets up a channel on the mud for the first time, configuring its default layout.
* If you don't like the default layout of channels, this is where you should edit it to your liking.
*/
I3_CHANNEL *new_I3_channel( void )
{
I3_CHANNEL *cnew;
I3CREATE( cnew, I3_CHANNEL, 1 );
I3LINK( cnew, first_I3chan, last_I3chan, next, prev );
return cnew;
}
/* Deletes a channel's information from the mud. */
void destroy_I3_channel( I3_CHANNEL *channel )
{
int x;
if ( channel == NULL )
{
i3bug( "%s", "destroy_I3_channel: Null parameter" );
return;
}
I3STRFREE( channel->local_name );
I3STRFREE( channel->host_mud );
I3STRFREE( channel->I3_name );
I3STRFREE( channel->layout_m );
I3STRFREE( channel->layout_e );
for( x = 0; x < MAX_I3HISTORY; x++ )
{
if( channel->history[x] && channel->history[x] != '\0' )
I3STRFREE( channel->history[x] );
}
I3UNLINK( channel, first_I3chan, last_I3chan, next, prev );
I3DISPOSE( channel );
}
/* Finds a mud with the name supplied on the mudlist */
I3_MUD *find_I3_mud_by_name( const char *name )
{
I3_MUD *mud;
for( mud = first_mud; mud; mud = mud->next )
{
if( !str_cmp( mud->name, name ) )
return mud;
}
return NULL;
}
I3_MUD *new_I3_mud( char *name )
{
I3_MUD *cnew, *mud_prev;
I3CREATE( cnew, I3_MUD, 1 );
cnew->name = I3STRALLOC( name );
for( mud_prev = first_mud; mud_prev; mud_prev = mud_prev->next )
if( strcasecmp( mud_prev->name, name ) >= 0 )
break;
if( !mud_prev )
I3LINK( cnew, first_mud, last_mud, next, prev );
else
I3INSERT( cnew, mud_prev, first_mud, next, prev );
return cnew;
}
void destroy_I3_mud( I3_MUD *mud )
{
if( mud == NULL )
{
i3bug( "%s", "destroy_I3_mud: Null parameter" );
return;
}
I3STRFREE( mud->name );
I3STRFREE( mud->ipaddress );
I3STRFREE( mud->mudlib );
I3STRFREE( mud->base_mudlib );
I3STRFREE( mud->driver );
I3STRFREE( mud->mud_type );
I3STRFREE( mud->open_status );
I3STRFREE( mud->admin_email );
I3STRFREE( mud->telnet );
I3STRFREE( mud->web_wrong );
I3STRFREE( mud->banner );
I3STRFREE( mud->web );
I3STRFREE( mud->time );
I3STRFREE( mud->daemon );
I3STRFREE( mud->routerName );
I3STRFREE( mud->routerIP );
if( mud != this_mud )
I3UNLINK( mud, first_mud, last_mud, next, prev );
I3DISPOSE( mud );
}
/*
* Close the socket to the router.
*/
void I3_connection_close( bool reconnect )
{
ROUTER_DATA *router = NULL;
bool rfound = FALSE;
for( router = first_router; router; router = router->next )
if( !str_cmp( router->name, I3_ROUTER_NAME ) )
{
rfound = TRUE;
break;
}
if( !rfound )
{
i3log( "%s", "I3_connection_close: Disconnecting from router." );
close( I3_socket );
I3_socket = -1;
return;
}
i3log( "Closing connection to Intermud-3 router %s", router->name );
close( I3_socket );
I3_socket = -1;
if( reconnect )
{
if( router->reconattempts <= 3 )
{
i3wait = 100; /* Wait for 100 game loops */
i3log( "%s", "Will attempt to reconnect in approximately 15 seconds." );
}
else if( router->next != NULL )
{
i3wait = 100;
i3log( "Will attempt new connection to %s in approximately 15 seconds.", router->next->name );
}
else
{
i3wait = -2;
i3log( "%s", "Unable to reconnect. No routers responding." );
return;
}
}
return;
}
/*
* Write a string into the send-buffer. Does not yet send it.
*/
void I3_write_buffer( const char *msg )
{
long newsize = I3_output_pointer+strlen( msg );
if( newsize > OPS-1 )
{
i3bug( "I3_write_buffer: buffer too large (would become %ld)", newsize );
return;
}
i3strncpy( I3_output_buffer + I3_output_pointer, msg, newsize );
I3_output_pointer = newsize;
}
/* Use this function in place of I3_write_buffer ONLY if the text to be sent could
* contain color tags to parse into ANSI codes. Otherwise it will mess up the packet.
*/
void send_to_i3( const char *text )
{
char buf[LGST*3];
snprintf( buf, LGST*3, "%s", I3_tagtofish( text ) );
I3_write_buffer( buf );
}
/*
* Put a I3-header in the send-buffer. If a field is NULL it will
* be replaced by a 0 (zero).
*/
void I3_write_header( char *identifier, const char *originator_mudname, const char *originator_username, char *target_mudname, const char *target_username )
{
I3_write_buffer( "({\"" );
I3_write_buffer( identifier );
I3_write_buffer( "\",5," );
if( originator_mudname )
{
I3_write_buffer( "\"" );
I3_write_buffer( originator_mudname );
I3_write_buffer( "\"," );
}
else I3_write_buffer( "0," );
if( originator_username )
{
I3_write_buffer( "\"" );
I3_write_buffer( originator_username );
I3_write_buffer( "\"," );
}
else I3_write_buffer( "0," );
if( target_mudname )
{
I3_write_buffer( "\"" );
I3_write_buffer( target_mudname );
I3_write_buffer( "\"," );
}
else I3_write_buffer( "0," );
if( target_username )
{
I3_write_buffer( "\"" );
I3_write_buffer( target_username );
I3_write_buffer( "\"," );
}
else I3_write_buffer( "0," );
}
/*
* Gets the next I3 field, that is when the amount of {[("'s and
* ")]}'s match each other when a , is read. It's not foolproof, it
* should honestly be some kind of statemachine, which does error-
* checking. Right now I trust the I3-router to send proper packets
* only. How naive :-) [Indeed Edwin, but I suppose we have little choice :P - Samson]
*
* ps will point to the beginning of the next field.
*
*/
char *I3_get_field( char *packet, char **ps )
{
int count[256];
char has_apostrophe = 0, has_backslash = 0;
char foundit = 0;
bzero( count, sizeof(count) );
*ps = packet;
while( 1 )
{
switch( *ps[0] )
{
case '{': if( !has_apostrophe ) count[(int)'{']++; break;
case '}': if( !has_apostrophe ) count[(int)'}']++; break;
case '[': if( !has_apostrophe ) count[(int)'[']++; break;
case ']': if( !has_apostrophe ) count[(int)']']++; break;
case '(': if( !has_apostrophe ) count[(int)'(']++; break;
case ')': if( !has_apostrophe ) count[(int)')']++; break;
case '\\':
if( has_backslash )
has_backslash = 0;
else
has_backslash = 1;
break;
case '"':
if( has_backslash )
{
has_backslash = 0;
}
else
{
if( has_apostrophe )
has_apostrophe = 0;
else
has_apostrophe = 1;
}
break;
case ',':
case ':':
if( has_apostrophe )
break;
if( has_backslash )
break;
if( count[(int)'{'] != count[(int)'}'] )
break;
if( count[(int)'['] != count[(int)']'] )
break;
if( count[(int)'('] != count[(int)')'] )
break;
foundit = 1;
break;
}
if( foundit )
break;
(*ps)++;
}
*ps[0] = '\0';
(*ps)++;
return *ps;
}
/*
* Returns a CHAR_DATA structure which matches the string
*
*/
CHAR_DATA *I3_find_user( const char *name )
{
DESCRIPTOR_DATA *d;
for ( d = first_descriptor; d; d = d->next )
{
if( d->character && !str_cmp( CH_I3NAME(d->character), name ) )
return d->character;
}
return NULL;
}
/* Beefed up to include wildcard ignores and user-level IP ignores.
* Be careful when setting IP based ignores - Last resort measure, etc.
*/
bool i3ignoring( CHAR_DATA *ch, const char *ignore )
{
I3_IGNORE *temp;
I3_MUD *mud;
char *ps;
char ipbuf[LGST], mudname[LGST];
/* Wildcard support thanks to Xorith */
for( temp = FIRST_I3IGNORE(ch); temp; temp = temp->next )
{
if( !fnmatch( temp->name, ignore, 0 ) )
return TRUE;
}
/* In theory, getting this far should be the result of an IP:Port ban */
ps = strchr( ignore, '@' );
if( ignore[0] == '\0' || ps == NULL )
return FALSE;
ps[0] = '\0';
strcpy( mudname, ps+1 );
for( mud = first_mud; mud; mud = mud->next )
{
if( !str_cmp( mud->name, mudname ) )
{
sprintf( ipbuf, "%s:%d", mud->ipaddress, mud->player_port );
for( temp = FIRST_I3IGNORE(ch); temp; temp = temp->next )
{
if( !str_cmp( temp->name, ipbuf ) )
return TRUE;
}
}
}
return FALSE;
}
/*
* Writes the string into the socket, prefixed by the size.
*/
bool I3_write_packet( char *msg )
{
int oldsize, size, check, x;
char *s = I3_output_buffer;
oldsize = size = strlen( msg+4 );
s[3] = size%256;
size >>= 8;
s[2] = size%256;
size >>= 8;
s[1] = size%256;
size >>= 8;
s[0] = size%256;
/* Scan for \r used in Diku client packets and change to NULL */
for( x = 0; x < oldsize+4; x++ )
if( msg[x] == '\r' && x > 3 )
msg[x] = '\0';
check = send( I3_socket, msg, oldsize + 4, 0 );
if( !check || ( check < 0 && errno != EAGAIN && errno != EWOULDBLOCK ) )
{
if( check < 0 )
i3log( "%s", "Write error on socket." );
else
i3log( "%s", "EOF encountered on socket write." );
I3_connection_close( TRUE );
return FALSE;
}
if( check < 0 ) /* EAGAIN */
return TRUE;
if( packetdebug )
{
i3log( "Size: %d. Bytes Sent: %d.", oldsize, check );
i3log( "Packet Sent: %s", msg+4 );
}
I3_output_pointer = 4;
return TRUE;
}
void I3_send_packet( void )
{
I3_write_packet( I3_output_buffer );
return;
}
/* The all important startup packet. This is what will be initially sent upon trying to connect
* to the I3 router. It is therefore quite important that the information here be exactly correct.
* If anything is wrong, your packet will be dropped by the router as invalid and your mud simply
* won't connect to I3. DO NOT USE COLOR TAGS FOR ANY OF THIS INFORMATION!!!
* Bugs fixed in this on 8-31-03 for improperly sent tags. Streamlined for less packet bloat.
*/
void I3_startup_packet( void )
{
char s[SMST];
char *strtime;
if( !I3_is_connected() )
return;
I3_output_pointer = 4;
I3_output_buffer[0] = '\0';
i3log( "Sending startup_packet to %s", I3_ROUTER_NAME );
I3_write_header( "startup-req-3", this_mud->name, NULL, I3_ROUTER_NAME, NULL );
sprintf( s, "%d", this_mud->password );
I3_write_buffer( s );
I3_write_buffer( "," );
sprintf( s, "%d", this_mud->mudlist_id );
I3_write_buffer( s );
I3_write_buffer( "," );
sprintf( s, "%d", this_mud->chanlist_id );
I3_write_buffer( s );
I3_write_buffer( "," );
sprintf( s, "%d", this_mud->player_port );
I3_write_buffer( s );
I3_write_buffer( ",0,0,\"" );
I3_write_buffer( this_mud->mudlib );
I3_write_buffer( "\",\"" );
I3_write_buffer( this_mud->base_mudlib );
I3_write_buffer( "\",\"" );
I3_write_buffer( this_mud->driver );
I3_write_buffer( "\",\"" );
I3_write_buffer( this_mud->mud_type );
I3_write_buffer( "\",\"" );
I3_write_buffer( this_mud->open_status );
I3_write_buffer( "\",\"" );
I3_write_buffer( this_mud->admin_email );
I3_write_buffer( "\"," );
/* Begin first mapping set */
I3_write_buffer( "([" );
if( this_mud->emoteto )
I3_write_buffer( "\"emoteto\":1," );
if( this_mud->news )
I3_write_buffer( "\"news\":1," );
if( this_mud->ucache )
I3_write_buffer( "\"ucache\":1," );
if( this_mud->auth )
I3_write_buffer( "\"auth\":1," );
if( this_mud->locate )
I3_write_buffer( "\"locate\":1," );
if( this_mud->finger )
I3_write_buffer( "\"finger\":1," );
if( this_mud->channel )
I3_write_buffer( "\"channel\":1," );
if( this_mud->who )
I3_write_buffer( "\"who\":1," );
if( this_mud->tell )
I3_write_buffer( "\"tell\":1," );
if( this_mud->beep )
I3_write_buffer( "\"beep\":1," );
if( this_mud->mail )
I3_write_buffer( "\"mail\":1," );
if( this_mud->file )
I3_write_buffer( "\"file\":1," );
if( this_mud->http )
{
sprintf( s, "\"http\":%d,", this_mud->http );
I3_write_buffer( s );
}
if( this_mud->smtp )
{
sprintf( s, "\"smtp\":%d,", this_mud->smtp );
I3_write_buffer( s );
}
if( this_mud->pop3 )
{
sprintf( s, "\"pop3\":%d,", this_mud->pop3 );
I3_write_buffer( s );
}
if( this_mud->ftp )
{
sprintf( s, "\"ftp\":%d,", this_mud->ftp );
I3_write_buffer( s );
}
if( this_mud->nntp )
{
sprintf( s, "\"nntp\":%d,", this_mud->nntp );
I3_write_buffer( s );
}
if( this_mud->rcp )
{
sprintf( s, "\"rcp\":%d,", this_mud->rcp );
I3_write_buffer( s );
}
if( this_mud->amrcp )
{
sprintf( s, "\"amrcp\":%d,", this_mud->amrcp );
I3_write_buffer( s );
}
I3_write_buffer( "]),([" );
/* END first set of "mappings", start of second set */
if( this_mud->web && this_mud->web[0] != '\0' )
{
sprintf( s, "\"url\":\"%s\",", this_mud->web );
I3_write_buffer( s );
}
strtime = ctime( ¤t_time );
strtime[strlen(strtime)-1] = '\0';
sprintf( s, "\"time\":\"%s\",", strtime );
I3_write_buffer( s );
I3_write_buffer( "]),})\r" );
I3_send_packet( );
}
/* This function saves the password, mudlist ID, and chanlist ID that are used by the mud.
* The password value is returned from the I3 router upon your initial connection.
* The mudlist and chanlist ID values are updated as needed while your mud is connected.
* Do not modify the file it generates because doing so may prevent your mud from reconnecting
* to the router in the future. This file will be rewritten each time the I3_shutdown function
* is called, or any of the id values change.
*/
void I3_save_id( void )
{
FILE *fp;
if( ( fp = fopen( I3_PASSWORD_FILE, "w" ) ) == NULL )
{
i3log( "%s", "Couldn't write to I3 password file." );
return;
}
fprintf( fp, "%s", "#PASSWORD\n" );
fprintf( fp, "%d %d %d\n", this_mud->password, this_mud->mudlist_id, this_mud->chanlist_id );
I3FCLOSE( fp );
}
/* The second most important packet your mud will deal with. If you never get this
* coming back from the I3 router, something was wrong with your startup packet
* or the router may be jammed up. Whatever the case, if you don't get a reply back
* your mud won't be acknowledged as connected.
*/
void I3_process_startup_reply( I3_HEADER *header, char *s )
{
ROUTER_DATA *router;
I3_CHANNEL *channel;
char *ps = s, *next_ps;
/* Recevies the router list. Nothing much to do here until there's more than 1 router. */
I3_get_field( ps, &next_ps );
i3log( "%s", ps ); /* Just checking for now */
ps = next_ps;
/* Receives your mud's updated password, which may or may not be the same as what it sent out before */
I3_get_field( ps, &next_ps );
this_mud->password = atoi( ps );
ps = next_ps;
i3log( "Received startup_reply from %s", header->originator_mudname );
I3_save_id( );
for( router = first_router; router; router = router->next )
{
if( !str_cmp( router->name, header->originator_mudname ) )
{
router->reconattempts = 0;
I3_ROUTER_NAME = router->name;
break;
}
}
i3wait = 0;
i3timeout = 0;
i3log( "%s", "Intermud-3 Network connection complete." );
for( channel = first_I3chan; channel; channel = channel->next )
{
if( channel->local_name && channel->local_name[0] != '\0' )
{
i3log( "Subscribing to %s", channel->local_name );
I3_send_channel_listen( channel, TRUE );
}
}
return;
}
void I3_process_chanack( I3_HEADER *header, char *s )
{
CHAR_DATA *ch;
char *next_ps, *ps = s;
char message[LGST];
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( message, ps );
ps = next_ps;
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
i3log( "%s", message );
else
i3_printf( ch, "&G%s\n\r", message );
return;
}
void I3_send_error( char *mud, char *user, char *code, char *message )
{
if( !I3_is_connected() )
return;
I3_write_header( "error", I3_THISMUD, 0, mud, user );
I3_write_buffer( "\"" );
I3_write_buffer( code );
I3_write_buffer( "\",\"" );
I3_write_buffer( message );
I3_write_buffer( "\",0,})\r" );
I3_send_packet( );
}
void I3_process_error( I3_HEADER *header, char *s )
{
CHAR_DATA *ch;
char *next_ps, *ps = s;
char type[LGST], message[LGST], error[LGST];
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( type, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( message, ps );
/* Since VargonMUD likes to spew errors for no good reason.... */
if( !str_cmp( header->originator_mudname, "VargonMUD" ) )
return;
sprintf( error, "Error: from %s to %s@%s\n\r%s: %s",
header->originator_mudname, header->target_username, header->target_mudname, type, message );
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
i3log( "%s", error );
else
i3_printf( ch, "%s\n\r", error );
}
int i3todikugender( int gender )
{
int sex = 0;
if( gender == 0 )
sex = SEX_MALE;
if( gender == 1 )
sex = SEX_FEMALE;
if( gender > 1 )
sex = SEX_NEUTRAL;
return sex;
}
int dikutoi3gender( int gender )
{
int sex = 0;
if( gender > 2 || gender < 0 )
sex = 2; /* I3 neuter */
if( gender == SEX_MALE )
sex = 0; /* I3 Male */
if( gender == SEX_FEMALE )
sex = 1; /* I3 Female */
return sex;
}
/* This is very possibly going to be spammy as hell */
void I3_show_ucache_contents( CHAR_DATA *ch, const char *argument )
{
UCACHE_DATA *user;
int users = 0;
i3send_to_pager( "Cached user information\n\r", ch );
i3send_to_pager( "User | Gender ( 0 = Male, 1 = Female, 2 = Neuter )\n\r", ch );
i3send_to_pager( "---------------------------------------------------------------------------\n\r", ch );
for( user = first_ucache; user; user = user->next )
{
i3pager_printf( ch, "%-30s %d\n\r", user->name, user->gender );
users++;
}
i3pager_printf( ch, "%d users being cached.\n\r", users );
return;
}
int I3_get_ucache_gender( char *name )
{
UCACHE_DATA *user;
for( user = first_ucache; user; user = user->next )
{
if( !str_cmp( user->name, name ) )
return user->gender;
}
/* -1 means you aren't in the list and need to be put there. */
return -1;
}
/* Saves the ucache info to disk because it would just be spamcity otherwise */
void I3_save_ucache( void )
{
FILE *fp;
UCACHE_DATA *user;
if( ( fp = fopen( I3_UCACHE_FILE, "w" ) ) == NULL )
{
i3log( "%s", "Couldn't write to I3 ucache file." );
return;
}
for( user = first_ucache; user; user = user->next )
{
fprintf( fp, "%s", "#UCACHE\n" );
fprintf( fp, "Name %s~\n", user->name );
fprintf( fp, "Sex %d\n", user->gender );
fprintf( fp, "Time %ld\n", (long int)user->time );
fprintf( fp, "%s", "End\n\n" );
}
fprintf( fp, "%s", "#END\n" );
I3FCLOSE( fp );
return;
}
void I3_prune_ucache( void )
{
UCACHE_DATA *ucache, *next_ucache;
for( ucache = first_ucache; ucache; ucache = next_ucache )
{
next_ucache = ucache->next;
/* Info older than 30 days is removed since this person likely hasn't logged in at all */
if( current_time - ucache->time >= 2592000 )
{
I3STRFREE( ucache->name );
I3UNLINK( ucache, first_ucache, last_ucache, next, prev );
I3DISPOSE( ucache );
}
}
I3_save_ucache( );
return;
}
/* Updates user info if they exist, adds them if they don't. */
void I3_ucache_update( char *name, int gender )
{
UCACHE_DATA *user;
for( user = first_ucache; user; user = user->next )
{
if( !str_cmp( user->name, name ) )
{
user->gender = gender;
user->time = current_time;
return;
}
}
I3CREATE( user, UCACHE_DATA, 1 );
user->name = I3STRALLOC( name );
user->gender = gender;
user->time = current_time;
I3LINK( user, first_ucache, last_ucache, next, prev );
I3_save_ucache( );
return;
}
void I3_send_ucache_update( const char *visname, int gender )
{
char buf[10];
if( !I3_is_connected() )
return;
I3_write_header( "ucache-update", I3_THISMUD, NULL, NULL, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( visname );
I3_write_buffer( "\",\"" );
I3_write_buffer( visname );
I3_write_buffer( "\"," );
sprintf( buf, "%d", gender );
I3_write_buffer( buf );
I3_write_buffer( ",})\r" );
I3_send_packet( );
return;
}
void I3_process_ucache_update( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
char username[LGST], visname[LGST], buf[LGST];
int sex, gender;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( username, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( visname, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
gender = atoi( ps );
sprintf( buf, "%s@%s", visname, header->originator_mudname );
sex = I3_get_ucache_gender( buf );
if( sex == gender )
return;
I3_ucache_update( buf, gender );
return;
}
void I3_send_chan_user_req( char *targetmud, char *targetuser )
{
if( !I3_is_connected() )
return;
I3_write_header( "chan-user-req", I3_THISMUD, NULL, targetmud, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( targetuser );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_process_chan_user_req( I3_HEADER *header, char *s )
{
char buf[LGST];
char *ps = s, *next_ps;
CHAR_DATA *ch;
int sex, gender;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( buf, "%s@%s", header->originator_username, header->originator_mudname );
if( ( ch = I3_find_user( ps ) ) == NULL )
{
if( !i3exists_player( ps ) )
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
else
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3PERM(ch) < I3PERM_MORT )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
return;
}
if( I3ISINVIS(ch) || i3ignoring( ch, buf ) )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
/* Since this is a gender thing, we need to gather that info. It's assumed anything above 2
* is generally referred to as an "it" anyway, so send them a neuter if it's above 2.
* And I3 genders are in a different order from standard Diku genders, so this complicates matters some.
*/
gender = CH_I3SEX(ch);
sex = dikutoi3gender( gender );
I3_write_header( "chan-user-reply", I3_THISMUD, NULL, header->originator_mudname, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( CH_I3NAME(ch) );
I3_write_buffer( "\",\"" );
I3_write_buffer( CH_I3NAME(ch) );
I3_write_buffer( "\"," );
sprintf( buf, "%d", sex );
I3_write_buffer( buf );
I3_write_buffer( ",})\r" );
I3_send_packet( );
return;
}
void I3_process_chan_user_reply( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
char username[LGST], visname[LGST], buf[LGST];
int sex, gender;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( username, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( visname, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
gender = atoi( ps );
sprintf( buf, "%s@%s", visname, header->originator_mudname );
sex = I3_get_ucache_gender( buf );
if( sex == gender )
return;
I3_ucache_update( buf, gender );
return;
}
void I3_process_mudlist( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
I3_MUD *mud = NULL;
char mud_name[SMST];
I3_get_field( ps, &next_ps );
this_mud->mudlist_id = atoi( ps );
I3_save_id( );
ps = next_ps;
ps += 2;
while( 1 )
{
char *next_ps2;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3strncpy( mud_name, ps, SMST );
ps = next_ps;
I3_get_field( ps, &next_ps2 );
if( ps[0] != '0' )
{
mud = find_I3_mud_by_name( mud_name );
if( !mud )
mud = new_I3_mud( mud_name );
ps += 2;
I3_get_field( ps, &next_ps );
mud->status = atoi( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( mud->ipaddress );
mud->ipaddress = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
mud->player_port = atoi( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
mud->imud_tcp_port = atoi( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
mud->imud_udp_port = atoi( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( mud->mudlib );
mud->mudlib = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( mud->base_mudlib );
mud->base_mudlib = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( mud->driver );
mud->driver = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( mud->mud_type );
mud->mud_type = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( mud->open_status );
mud->open_status = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( mud->admin_email );
mud->admin_email = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
ps += 2;
while( 1 )
{
char *next_ps3;
char key[SMST];
if( ps[0] == ']' )
break;
I3_get_field( ps, &next_ps3 );
I3_remove_quotes( &ps );
strcpy( key, ps );
ps = next_ps3;
I3_get_field( ps, &next_ps3 );
switch( key[0] )
{
case 'a':
if( !str_cmp( key, "auth" ) )
{
mud->auth = ps[0] == '0' ? 0 : 1;
break;
}
if( !str_cmp( key, "amrcp" ) )
{
mud->amrcp = atoi( ps );
break;
}
break;
case 'b':
if( !str_cmp( key, "beep" ) )
{
mud->beep = ps[0] == '0' ? 0 : 1;
break;
}
break;
case 'c':
if( !str_cmp( key, "channel" ) )
{
mud->channel = ps[0] == '0' ? 0 : 1;
break;
}
break;
case 'e':
if( !str_cmp( key, "emoteto" ) )
{
mud->emoteto = ps[0] == '0' ? 0 : 1;
break;
}
break;
case 'f':
if( !str_cmp( key, "file" ) )
{
mud->file = ps[0] == '0' ? 0 : 1;
break;
}
if( !str_cmp( key, "finger" ) )
{
mud->finger = ps[0] == '0' ? 0 : 1;
break;
}
if( !str_cmp( key, "ftp" ) )
{
mud->ftp = atoi( ps );
break;
}
break;
case 'h':
if( !str_cmp( key, "http" ) )
{
mud->http = atoi( ps );
break;
}
break;
case 'l':
if( !str_cmp( key, "locate" ) )
{
mud->locate = ps[0] == '0' ? 0 : 1;
break;
}
break;
case 'm':
if( !str_cmp( key, "mail" ) )
{
mud->mail = ps[0] == '0' ? 0 : 1;
break;
}
break;
case 'n':
if( !str_cmp( key, "news" ) )
{
mud->news = ps[0] == '0' ? 0 : 1;
break;
}
if( !str_cmp( key, "nntp" ) )
{
mud->nntp = atoi( ps );
break;
}
break;
case 'p':
if( !str_cmp( key, "pop3" ) )
{
mud->pop3 = atoi( ps );
break;
}
break;
case 'r':
if( !str_cmp( key, "rcp" ) )
{
mud->rcp = atoi( ps );
break;
}
break;
case 's':
if( !str_cmp( key, "smtp" ) )
{
mud->smtp = atoi( ps );
break;
}
break;
case 't':
if( !str_cmp( key, "tell" ) )
{
mud->tell = ps[0] == '0' ? 0 : 1;
break;
}
break;
case 'u':
if( !str_cmp( key, "ucache" ) )
{
mud->ucache = ps[0] == '0' ? 0 : 1;
break;
}
if( !str_cmp( key, "url" ) )
{
I3_remove_quotes( &ps );
I3STRFREE( mud->web_wrong );
mud->web_wrong = I3STRALLOC( ps );
break;
}
break;
case 'w':
if( !str_cmp( key, "who" ) )
{
mud->who = ps[0] == '0' ? 0 : 1;
break;
}
break;
default:
break;
}
ps = next_ps3;
if( ps[0] == ']' )
break;
}
ps = next_ps;
I3_get_field( ps, &next_ps );
ps = next_ps;
}
else
{
if( ( mud = find_I3_mud_by_name( mud_name ) ) != NULL )
destroy_I3_mud( mud );
}
ps = next_ps2;
if( ps[0] == ']' )
break;
}
return;
}
void I3_process_chanlist_reply( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
I3_CHANNEL *channel;
char chan[SMST];
I3_get_field( ps, &next_ps );
this_mud->chanlist_id = atoi( ps );
I3_save_id( );
ps = next_ps;
ps += 2;
while( 1 )
{
char *next_ps2;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3strncpy( chan, ps, SMST );
ps = next_ps;
I3_get_field( ps, &next_ps2 );
if( ps[0] != '0' )
{
if( !( channel = find_I3_channel_by_name( ps ) ) )
{
channel = new_I3_channel();
channel->I3_name = I3STRALLOC( chan );
}
ps += 2;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
I3STRFREE( channel->host_mud );
channel->host_mud = I3STRALLOC( ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
channel->status = atoi( ps );
}
else
{
if( ( channel = find_I3_channel_by_name( chan ) ) != NULL )
{
if( channel->local_name && channel->local_name[0] != '\0' )
i3log( "Locally configured channel %s has been purged from router %s", channel->local_name, I3_ROUTER_NAME );
destroy_I3_channel( channel );
I3_write_channel_config();
}
}
ps = next_ps2;
if( ps[0] == ']' )
break;
}
return;
}
void I3_send_channel_message( I3_CHANNEL *channel, const char *name, const char *message )
{
if( !I3_is_connected() )
return;
I3_write_header( "channel-m", I3_THISMUD, name, NULL, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( channel->I3_name );
I3_write_buffer( "\",\"" );
I3_write_buffer( name );
I3_write_buffer( "\",\"" );
send_to_i3( I3_escape( message ) );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_send_channel_emote( I3_CHANNEL *channel, const char *name, const char *message )
{
char buf[LGST];
if( !I3_is_connected() )
return;
if( strstr( message, "$N" ) == NULL )
sprintf( buf, "$N %s", message );
else
strcpy( buf, message );
I3_write_header( "channel-e", I3_THISMUD, name, NULL, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( channel->I3_name );
I3_write_buffer( "\",\"" );
I3_write_buffer( name );
I3_write_buffer( "\",\"" );
send_to_i3( I3_escape( buf ) );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_send_channel_t( I3_CHANNEL *channel, const char *name, char *tmud, char *tuser, char *msg_o, char *msg_t, char *tvis )
{
if( !I3_is_connected() )
return;
I3_write_header( "channel-t", I3_THISMUD, name, NULL, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( channel->I3_name );
I3_write_buffer( "\",\"" );
I3_write_buffer( tmud );
I3_write_buffer( "\",\"" );
I3_write_buffer( tuser );
I3_write_buffer( "\",\"" );
send_to_i3( I3_escape( msg_o ) );
I3_write_buffer( "\",\"" );
send_to_i3( I3_escape( msg_t ) );
I3_write_buffer( "\",\"" );
I3_write_buffer( name );
I3_write_buffer( "\",\"" );
I3_write_buffer( tvis );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
int I3_token( char type, char *string, char *oname, char *tname )
{
char code[51];
char *p = '\0';
switch( type )
{
default:
code[0] = type;
code[1] = '\0';
return 1;
case '$':
strcpy( code, "$" );
break;
case ' ':
strcpy( code, " " );
break;
case 'N': /* Originator's name */
strncpy( code, oname, 49 );
code[50] = '\0';
break;
case 'O': /* Target's name */
strncpy( code, tname, 49 );
code[50] = '\0';
break;
}
p = code;
while( *p != '\0' )
{
*string = *p++;
*++string = '\0';
}
return( strlen( code ) );
}
void I3_message_convert( char *buffer, const char *txt, char *oname, char *tname )
{
const char *point;
int skip = 0;
for( point = txt ; *point ; point++ )
{
if( *point == '$' )
{
point++;
if( *point == '\0' )
point--;
else
skip = I3_token( *point, buffer, oname, tname );
while( skip-- > 0 )
++buffer;
continue;
}
*buffer = *point;
*++buffer = '\0';
}
*buffer = '\0';
return;
}
char *I3_convert_channel_message( const char *message, char *sname, char *tname )
{
static char msgbuf[LGST];
/* Sanity checks - if any of these are NULL, bad things will happen - Samson 6-29-01 */
if( !message )
{
i3bug( "%s", "I3_convert_channel_message: NULL message!" );
return "ERROR";
}
if( !sname )
{
i3bug( "%s", "I3_convert_channel_message: NULL sname!" );
return "ERROR";
}
if( !tname )
{
i3bug( "%s", "I3_convert_channel_message: NULL tname!" );
return "ERROR";
}
I3_message_convert( msgbuf, message, sname, tname );
return msgbuf;
}
void update_chanhistory( I3_CHANNEL *channel, char *message )
{
char msg[LGST], buf[LGST];
struct tm *local;
time_t t;
int x;
if( !channel )
{
i3bug( "%s", "update_chanhistory: NULL channel received!" );
return;
}
if( !message || message[0] == '\0' )
{
i3bug( "%s", "update_chanhistory: NULL message received!" );
return;
}
strcpy( msg, message );
for( x = 0; x < MAX_I3HISTORY; x++ )
{
if( channel->history[x] == NULL )
{
t = time( NULL );
local = localtime( &t );
sprintf( buf, "&R[%-2.2d/%-2.2d %-2.2d:%-2.2d] &G%s\n\r",
local->tm_mon+1, local->tm_mday, local->tm_hour, local->tm_min, msg );
channel->history[x] = I3STRALLOC( buf );
if( IS_SET( channel->flags, I3CHAN_LOG ) )
{
FILE *fp;
sprintf( buf, "etc/i3/%s.log", channel->local_name );
if ( ( fp = fopen( buf, "a" ) ) == NULL )
{
perror( buf );
i3bug( "Could not open file %s!", buf );
}
else
{
fprintf( fp, "%s\n", channel->history[x] );
I3FCLOSE( fp );
}
}
break;
}
if( x == MAX_I3HISTORY - 1 )
{
int y;
for( y = 1; y < MAX_I3HISTORY; y++ )
{
int z = y-1;
if( channel->history[z] != NULL )
{
I3STRFREE( channel->history[z] );
channel->history[z] = I3STRALLOC( channel->history[y] );
}
}
t = time( NULL );
local = localtime( &t );
sprintf( buf, "&R[%-2.2d/%-2.2d %-2.2d:%-2.2d] &G%s\n\r",
local->tm_mon+1, local->tm_mday, local->tm_hour, local->tm_min, msg );
I3STRFREE( channel->history[x] );
channel->history[x] = I3STRALLOC( buf );
if( IS_SET( channel->flags, I3CHAN_LOG ) )
{
FILE *fp;
sprintf( buf, "etc/i3/%s.log", channel->local_name );
if ( ( fp = fopen( buf, "a" ) ) == NULL )
{
perror( buf );
i3bug( "Could not open file %s!", buf );
}
else
{
fprintf( fp, "%s\n", channel->history[x] );
I3FCLOSE( fp );
}
}
}
}
return;
}
void I3_process_channel_t( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
DESCRIPTOR_DATA *d;
CHAR_DATA *vch = NULL;
char targetmud[SMST], targetuser[SMST], message_o[LGST], message_t[LGST], buf[LGST];
char visname_o[SMST], visname_t[SMST], sname[SMST], tname[SMST], lname[SMST], tmsg[LGST], omsg[LGST];
I3_CHANNEL *channel = NULL;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
if( ( channel = find_I3_channel_by_name( ps ) ) == NULL )
{
i3log( "I3_process_channel_t: received unknown channel (%s)", ps );
return;
}
if( !channel->local_name )
return;
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( targetmud, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( targetuser, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( message_o, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( message_t, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( visname_o, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( visname_t, ps );
sprintf( sname, "%s@%s", visname_o, header->originator_mudname );
sprintf( tname, "%s@%s", visname_t, targetmud );
sprintf( omsg, "%s", I3_convert_channel_message( message_o, sname, tname ) );
sprintf( tmsg, "%s", I3_convert_channel_message( message_t, sname, tname ) );
for( d = first_descriptor; d; d = d->next )
{
if( !d->character )
continue;
vch = d->original ? d->original : d->character;
if( !I3_hasname( I3LISTEN(vch), channel->local_name ) || I3_hasname( I3DENY(vch), channel->local_name ) )
continue;
sprintf( lname, "%s@%s", CH_I3NAME(vch), I3_THISMUD );
if( d->connected == CON_PLAYING && !i3ignoring( vch, sname ) )
{
if( !str_cmp( lname, tname ) )
{
sprintf( buf, channel->layout_e, channel->local_name, tmsg );
i3_printf( vch, "%s\n\r", buf );
}
else
{
sprintf( buf, channel->layout_e, channel->local_name, omsg );
i3_printf( vch, "%s\n\r", buf );
}
}
}
update_chanhistory( channel, omsg );
return;
}
void I3_process_channel_m( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
DESCRIPTOR_DATA *d;
CHAR_DATA *vch = NULL;
char visname[LGST], message[LGST], buf[LGST];
I3_CHANNEL *channel;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
if( ( channel = find_I3_channel_by_name( ps ) ) == NULL )
{
i3log( "channel_m: received unknown channel (%s)", ps );
return;
}
if( !channel->local_name )
return;
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( visname, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( message, ps );
sprintf( buf, channel->layout_m, channel->local_name, visname, header->originator_mudname, message );
for( d = first_descriptor; d; d = d->next )
{
if( !d->character )
continue;
vch = d->original ? d->original : d->character;
if( !I3_hasname( I3LISTEN(vch), channel->local_name ) || I3_hasname( I3DENY(vch), channel->local_name ) )
continue;
if( d->connected == CON_PLAYING && !i3ignoring( vch, visname ) )
i3_printf( vch, "%s\n\r", buf );
}
update_chanhistory( channel, buf );
return;
}
void I3_process_channel_e( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
DESCRIPTOR_DATA *d;
CHAR_DATA *vch = NULL;
char visname[LGST], message[LGST], msg[LGST], buf[LGST];
I3_CHANNEL *channel;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
if( ( channel = find_I3_channel_by_name( ps ) ) == NULL )
{
i3log( "channel_e: received unknown channel (%s)", ps );
return;
}
if( !channel->local_name )
return;
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( visname, "%s@%s", ps, header->originator_mudname );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( message, ps );
sprintf( msg, "%s", I3_convert_channel_message( message, visname, visname ) );
sprintf( buf, channel->layout_e, channel->local_name, msg );
for( d = first_descriptor; d; d = d->next )
{
if( !d->character )
continue;
vch = d->original ? d->original : d->character;
if( !I3_hasname( I3LISTEN(vch), channel->local_name ) || I3_hasname( I3DENY(vch), channel->local_name ) )
continue;
if( d->connected == CON_PLAYING && !i3ignoring( vch, visname ) )
i3_printf( vch, "%s\n\r", buf );
}
update_chanhistory( channel, buf );
return;
}
void I3_process_chan_who_req( I3_HEADER *header, char *s )
{
DESCRIPTOR_DATA *d;
char *ps = s, *next_ps;
char buf[LGST], ibuf[LGST];
I3_CHANNEL *channel;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( ibuf, "%s@%s", header->originator_username, header->originator_mudname );
if( ( channel = find_I3_channel_by_name( ps ) ) == NULL )
{
sprintf( buf, "The channel you specified (%s) is unknown at %s", ps, I3_THISMUD );
I3_escape( buf );
I3_send_error( header->originator_mudname, header->originator_username, "unk-channel", buf );
i3log( "chan_who_req: received unknown channel (%s)", ps );
return;
}
if( !channel->local_name )
{
sprintf( buf, "The channel you specified (%s) is not registered at %s", ps, I3_THISMUD );
I3_escape( buf );
I3_send_error( header->originator_mudname, header->originator_username, "unk-channel", buf );
return;
}
I3_write_header( "chan-who-reply", I3_THISMUD, NULL, header->originator_mudname, header->originator_username );
I3_write_buffer( "\"" );
I3_write_buffer( channel->I3_name );
I3_write_buffer( "\",({" );
for( d = first_descriptor; d; d = d->next )
{
if( !d->character )
continue;
if( I3ISINVIS(d->character) )
continue;
if( I3_hasname( I3LISTEN(d->character), channel->local_name ) && !i3ignoring( d->character, ibuf )
&& !I3_hasname( I3DENY(d->character), channel->local_name ) )
{
I3_write_buffer( "\"" );
I3_write_buffer( CH_I3NAME(d->character) );
I3_write_buffer( "\"," );
}
}
I3_write_buffer( "}),})\r" );
I3_send_packet( );
return;
}
void I3_process_chan_who_reply( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
CHAR_DATA *ch;
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
{
i3bug( "I3_process_chan_who_reply(): user %s not found.", header->target_username );
return;
}
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3_printf( ch, "I3 reply from %s for %s\n\r", header->originator_mudname, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
ps += 2;
while( 1 )
{
if( ps[0] == '}' )
{
i3_to_char( "No information returned or no people listening.\n\r", ch );
return;
}
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3_printf( ch, "- %s\n\r", ps );
ps = next_ps;
if( ps[0]== '}' )
break;
}
return;
}
void I3_send_chan_who( CHAR_DATA *ch, I3_CHANNEL *channel, I3_MUD *mud )
{
if( !I3_is_connected() )
return;
I3_write_header( "chan-who-req", I3_THISMUD, CH_I3NAME(ch), mud->name, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( channel->I3_name );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_send_beep( CHAR_DATA *ch, const char *to, I3_MUD *mud )
{
if( !I3_is_connected() )
return;
I3_escape( to );
I3_write_header( "beep", I3_THISMUD, CH_I3NAME(ch), mud->name, to );
I3_write_buffer( "\"" );
I3_write_buffer( CH_I3NAME(ch) );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_process_beep( I3_HEADER *header, char *s )
{
char buf[LGST];
char *ps = s, *next_ps;
CHAR_DATA *ch;
sprintf( buf, "%s@%s", header->originator_username, header->originator_mudname );
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
{
if( !i3exists_player( header->target_username ) )
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
else
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3PERM(ch) < I3PERM_MORT )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
return;
}
if( I3ISINVIS(ch) || i3ignoring( ch, buf ) )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3IS_SET( I3FLAG(ch), I3_BEEP ) )
{
sprintf( buf, "%s is not accepting beeps.", CH_I3NAME(ch) );
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", buf );
return;
}
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3_printf( ch, "&Y\a%s@%s beeps you.\n\r", ps, header->originator_mudname );
return;
}
void I3_beep( CHAR_DATA *ch, const char *argument )
{
char *ps;
char mud[SMST];
I3_MUD *pmud;
if( I3IS_SET( I3FLAG(ch), I3_DENYBEEP ) )
{
i3_to_char( "You are not allowed to use i3beeps.\n\r", ch );
return;
}
if( !argument || argument[0] == '\0' )
{
i3_to_char( "Usage: i3beep user@mud\n\r", ch );
i3_to_char( "Usage: i3beep [on]/[off]\n\r", ch );
return;
}
if( !str_cmp( argument, "on" ) )
{
I3REMOVE_BIT( I3FLAG(ch), I3_BEEP );
i3_to_char( "You now send and receive i3beeps.\n\r", ch );
return;
}
if( !str_cmp( argument, "off" ) )
{
I3SET_BIT( I3FLAG(ch), I3_BEEP );
i3_to_char( "You no longer send and receive i3beeps.\n\r", ch );
return;
}
if( I3IS_SET( I3FLAG(ch), I3_BEEP ) )
{
i3_to_char( "Your i3beeps are turned off.\n\r", ch );
return;
}
if( I3ISINVIS(ch) )
{
i3_to_char( "You are invisible.\n\r", ch );
return;
}
ps = strchr( argument, '@' );
if( argument[0] == '\0' || ps == NULL )
{
i3_to_char( "&YYou should specify a person and a mud.\n\r"
"(use &Wi3mudlist&Y to get an overview of the muds available)\n\r", ch);
return;
}
ps[0] = '\0';
ps++;
strcpy( mud, ps );
if( ( pmud = find_I3_mud_by_name( mud ) ) == NULL )
{
i3_to_char( "&YNo such mud known.\n\r"
"(use &Wi3mudlist&Y to get an overview of the muds available)\n\r", ch );
return;
}
if( !str_cmp( I3_THISMUD, pmud->name ) )
{
i3_to_char( "Use your mud's own internal system for that.\n\r", ch );
return;
}
if( pmud->status >= 0 )
{
i3_printf( ch, "%s is marked as down.\n\r", pmud->name );
return;
}
if( pmud->beep == 0 )
i3_printf( ch, "%s does not support the 'beep' command. Sending anyway.\n\r", pmud->name );
I3_send_beep( ch, argument, pmud );
i3_printf( ch, "&YYou beep %s@%s.\n\r", i3capitalize( argument ), pmud->name );
}
void I3_send_tell( CHAR_DATA *ch, char *to, I3_MUD *mud, const char *message )
{
if( !I3_is_connected() )
return;
I3_escape( to );
I3_write_header( "tell", I3_THISMUD, CH_I3NAME(ch), mud->name, to );
I3_write_buffer( "\"" );
I3_write_buffer( CH_I3NAME(ch) );
I3_write_buffer( "\",\"" );
send_to_i3( I3_escape( message ) );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_process_tell( I3_HEADER *header, char *s )
{
char buf[LGST];
char *ps = s, *next_ps;
CHAR_DATA *ch;
sprintf( buf, "%s@%s", header->originator_username, header->originator_mudname );
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
{
if( !i3exists_player( header->target_username ) )
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
else
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3PERM(ch) < I3PERM_MORT )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
return;
}
if( I3ISINVIS(ch) || i3ignoring( ch, buf ) )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3IS_SET( I3FLAG(ch), I3_TELL ) )
{
sprintf( buf, "%s is not accepting tells.", CH_I3NAME(ch) );
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", buf );
return;
}
if( CH_I3AFK(ch) )
{
sprintf( buf, "%s is currently AFK. Try back later.", CH_I3NAME(ch) );
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", buf );
return;
}
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3_printf( ch, "&Y%s@%s tells you: ", ps, header->originator_mudname );
sprintf( buf, "'%s@%s'", ps, header->originator_mudname );
I3STRFREE( I3REPLY(ch) );
I3REPLY(ch) = I3STRALLOC( buf );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3_printf( ch, "&c%s\n\r", ps );
return;
}
void I3_tell( CHAR_DATA *ch, const char *argument )
{
char to[SMST], *ps;
char mud[SMST];
I3_MUD *pmud;
if( I3IS_SET( I3FLAG(ch), I3_DENYTELL ) )
{
i3_to_char( "You are not allowed to use i3tells.\n\r", ch );
return;
}
if( !argument || argument[0] == '\0' )
{
i3_to_char( "Usage: i3tell <user@mud> <message>\n\r", ch );
i3_to_char( "Usage: i3tell [on]/[off]\n\r", ch );
return;
}
if( !str_cmp( argument, "on" ) )
{
I3REMOVE_BIT( I3FLAG(ch), I3_TELL );
i3_to_char( "You now send and receive i3tells.\n\r", ch );
return;
}
if( !str_cmp( argument, "off" ) )
{
I3SET_BIT( I3FLAG(ch), I3_TELL );
i3_to_char( "You no longer send and receive i3tells.\n\r", ch );
return;
}
if( I3IS_SET( I3FLAG(ch), I3_TELL ) )
{
i3_to_char( "Your i3tells are turned off.\n\r", ch );
return;
}
if( I3ISINVIS(ch) )
{
i3_to_char( "You are invisible.\n\r", ch );
return;
}
argument = i3one_argument( argument, to );
ps = strchr( to, '@' );
if( to[0] == '\0' || argument[0] == '\0' || ps == NULL )
{
i3_to_char( "&YYou should specify a person and a mud.\n\r"
"(use &Wi3mudlist&Y to get an overview of the muds available)\n\r", ch);
return;
}
ps[0] = '\0';
ps++;
strcpy( mud, ps );
if( ( pmud = find_I3_mud_by_name( mud ) ) == NULL )
{
i3_to_char( "&YNo such mud known.\n\r"
"(use &Wi3mudlist&Y to get an overview of the muds available)\n\r", ch );
return;
}
if( !str_cmp( I3_THISMUD, pmud->name ) )
{
i3_to_char( "Use your mud's own internal system for that.\n\r", ch );
return;
}
if( pmud->status >= 0 )
{
i3_printf( ch, "%s is marked as down.\n\r", pmud->name );
return;
}
if( pmud->tell == 0 )
{
i3_printf( ch, "%s does not support the 'tell' command.\n\r", pmud->name );
return;
}
I3_send_tell( ch, to, pmud, argument );
i3_printf( ch, "&YYou tell %s@%s: &c%s\n\r", i3capitalize( to ), pmud->name, argument );
}
void I3_reply( CHAR_DATA *ch, const char *argument )
{
char buf[LGST];
if( I3IS_SET( I3FLAG(ch), I3_DENYTELL ) )
{
i3_to_char( "You are not allowed to use i3tells.\n\r", ch );
return;
}
if( !argument || argument[0] == '\0' )
{
i3_to_char( "Usage: i3reply <message>\n\r", ch );
return;
}
if( I3IS_SET( I3FLAG(ch), I3_TELL ) )
{
i3_to_char( "Your i3tells are turned off.\n\r", ch );
return;
}
if( I3ISINVIS(ch) )
{
i3_to_char( "You are invisible.\n\r", ch );
return;
}
if( !I3REPLY(ch) )
{
i3_to_char( "You have not yet received an i3tell?!?\n\r", ch );
return;
}
sprintf( buf, "%s %s", I3REPLY(ch), argument );
I3_tell( ch, buf );
return;
}
void I3_send_who( CHAR_DATA *ch, char *mud )
{
if( !I3_is_connected() )
return;
I3_escape( mud );
I3_write_header( "who-req", I3_THISMUD, CH_I3NAME(ch), mud, NULL );
I3_write_buffer( "})\r" );
I3_send_packet( );
return;
}
/* Color align functions by Justice@Aaern */
int i3const_color_str_len( const char *argument )
{
int str, count = 0;
bool IS_COLOR = FALSE;
for ( str = 0; argument[str] != '\0'; str++ )
{
if ( argument[str] == '&' )
{
if ( IS_COLOR == TRUE )
{
count++;
IS_COLOR = FALSE;
}
else
IS_COLOR = TRUE;
}
else if ( argument[str] == '{' )
{
if ( IS_COLOR == TRUE )
{
count++;
IS_COLOR = FALSE;
}
else
IS_COLOR = TRUE;
}
else if ( argument[str] == '}' )
{
if ( IS_COLOR == TRUE )
{
count++;
IS_COLOR = FALSE;
}
else
IS_COLOR = TRUE;
}
else
{
if ( IS_COLOR == FALSE ) count++;
else IS_COLOR = FALSE;
}
}
return count;
}
int i3const_color_strnlen( const char *argument, int maxlength )
{
int str, count = 0;
bool IS_COLOR = FALSE;
for ( str = 0; argument[str] != '\0'; str++ )
{
if ( argument[str] == '&' )
{
if ( IS_COLOR == TRUE )
{
count++;
IS_COLOR = FALSE;
}
else
IS_COLOR = TRUE;
}
else if ( argument[str] == '{' )
{
if ( IS_COLOR == TRUE )
{
count++;
IS_COLOR = FALSE;
}
else
IS_COLOR = TRUE;
}
else if ( argument[str] == '}' )
{
if ( IS_COLOR == TRUE )
{
count++;
IS_COLOR = FALSE;
}
else
IS_COLOR = TRUE;
}
else
{
if ( IS_COLOR == FALSE ) count++;
else IS_COLOR = FALSE;
}
if ( count >= maxlength ) break;
}
if ( count < maxlength ) return ((str - count) + maxlength);
str++;
return str;
}
const char *i3const_color_align( const char *argument, int size, int align )
{
int space = ( size - i3const_color_str_len( argument ) );
static char buf[LGST];
if ( align == I3_ALIGN_RIGHT || i3const_color_str_len( argument ) >= size )
sprintf( buf, "%*.*s", i3const_color_strnlen( argument, size ),
i3const_color_strnlen( argument, size ), argument );
else if ( align == I3_ALIGN_CENTER )
sprintf( buf, "%*s%s%*s", ( space/2 ),"",argument,
((space/2)*2)==space ? (space/2) : ((space/2)+1),"" );
else
sprintf( buf, "%s%*s", argument, space, "" );
return buf;
}
/* You can customize the output of this - to a point. Because of how the I3 packets are formatted
* you need to send even the listing header as a person+info packet. It should be fairly obvious
* how to change this around if you really want to. Use the bogusidle variable for the idle time
* on a divider, like what I've done here for headerbuf. If you wish to subvert this with your
* own custom who list, add a #define I3CUSTOMWHO to one of your H files, and make your own
* I3_process_who_req function somewhere else in your code.
*/
#ifndef I3CUSTOMWHO
void I3_process_who_req( I3_HEADER *header, char *s )
{
DESCRIPTOR_DATA *d;
CHAR_DATA *person;
char ibuf[LGST], personbuf[LGST], headerbuf[LGST], tailbuf[LGST], smallbuf[LGST], rank[LGST];
char buf[300], outbuf[400], stats[20];
int pcount, amount, XX, YY;
long int bogusidle;
pcount = 0;
bogusidle = 9999;
sprintf( ibuf, "%s@%s", header->originator_username, header->originator_mudname );
I3_write_header( "who-reply", I3_THISMUD, NULL, header->originator_mudname, header->originator_username );
I3_write_buffer( "({" );
I3_write_buffer( "({\"" );
{
outbuf[0] = '\0';
sprintf( buf, "&R-=[ &WPlayers on %s &R]=-", I3_THISMUD );
amount = 78 - I3_strlen_color( buf ); /* Determine amount to put in front of line */
if( amount < 1 )
amount = 1;
amount = amount / 2;
for( XX = 0 ; XX < amount ; XX++ )
strcat( outbuf, " " );
strcat( outbuf, buf );
send_to_i3( I3_escape( outbuf ) );
}
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", -1l );
I3_write_buffer( smallbuf );
I3_write_buffer( ",\"" );
send_to_i3( "&x-" );
I3_write_buffer( "\",}),({\"" );
{
outbuf[0] = '\0';
sprintf( buf, "&Y-=[ &Wtelnet://%s:%d &Y]=-", this_mud->telnet, this_mud->player_port );
amount = 78 - I3_strlen_color( buf ); /* Determine amount to put in front of line */
if( amount < 1 )
amount = 1;
amount = amount / 2;
for( XX = 0 ; XX < amount ; XX++ )
strcat( outbuf, " " );
strcat( outbuf, buf );
send_to_i3( I3_escape( outbuf ) );
}
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", bogusidle );
I3_write_buffer( smallbuf );
I3_write_buffer( ",\"" );
send_to_i3( "&x-" );
I3_write_buffer( "\",})," );
XX = 0;
for( d = first_descriptor; d; d = d->next )
{
if( d->character && d->connected == CON_PLAYING )
{
if( I3PERM(d->character) < I3PERM_MORT || I3PERM(d->character) >= I3PERM_IMM
|| I3ISINVIS(d->character) || i3ignoring( d->character, ibuf ) )
continue;
XX++;
}
}
if( XX > 0 )
{
I3_write_buffer( "({\"" );
strcpy( headerbuf, "&B--------------------------------=[ &WPlayers &B]=---------------------------------" );
send_to_i3( I3_escape( headerbuf ) );
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", bogusidle );
I3_write_buffer( smallbuf );
I3_write_buffer( ",\"" );
send_to_i3( "&x-" );
I3_write_buffer( "\",})," );
/* This section is displaying only players - not imms */
for( d = first_descriptor; d; d = d->next )
{
if( d->character && d->connected == CON_PLAYING )
{
if( I3PERM(d->character) < I3PERM_MORT || I3PERM(d->character) >= I3PERM_IMM
|| I3ISINVIS(d->character) || i3ignoring( d->character, ibuf ) )
continue;
person = d->character;
pcount++;
I3_write_buffer( "({\"" );
sprintf( rank, "%s", rankbuffer( person ) );
sprintf( outbuf, "%s", i3const_color_align( rank, 20, I3_ALIGN_CENTER ) );
send_to_i3( I3_escape( outbuf ) );
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", -1l );
I3_write_buffer( smallbuf );
I3_write_buffer( ",\"" );
strcpy( stats, "&z[" );
if( CH_I3AFK(person) )
strcat( stats, "AFK" );
else
strcat( stats, "---" );
strcat( stats, "]&G" );
sprintf( personbuf, "%s %s%s", stats, CH_I3NAME(person), CH_I3TITLE(person) );
send_to_i3( I3_escape( personbuf ) );
I3_write_buffer( "\",})," );
}
}
}
YY = 0;
for( d = first_descriptor; d; d = d->next )
{
if( d->character && d->connected == CON_PLAYING )
{
if( I3PERM(d->character) < I3PERM_IMM || I3ISINVIS(d->character) || i3ignoring( d->character, ibuf ) )
continue;
YY++;
}
}
if( YY > 0 )
{
I3_write_buffer( "({\"" );
strcpy( headerbuf, "&R-------------------------------=[ &WImmortals &R]=--------------------------------" );
send_to_i3( I3_escape( headerbuf ) );
I3_write_buffer( "\"," );
if( XX > 0 )
sprintf( smallbuf, "%ld", bogusidle * 3 );
else
sprintf( smallbuf, "%ld", bogusidle );
I3_write_buffer( smallbuf );
I3_write_buffer( ",\"" );
send_to_i3( "&x-" );
I3_write_buffer( "\",})," );
/* This section is displaying only immortals, not players */
for( d = first_descriptor; d; d = d->next )
{
if( d->character && d->connected == CON_PLAYING )
{
if( I3PERM(d->character) < I3PERM_IMM || I3ISINVIS(d->character) || i3ignoring( d->character, ibuf ) )
continue;
person = d->character;
pcount++;
I3_write_buffer( "({\"" );
sprintf( rank, "%s", rankbuffer( person ) );
sprintf( outbuf, "%s", i3const_color_align( rank, 20, I3_ALIGN_CENTER ) );
send_to_i3( I3_escape( outbuf ) );
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", -1l );
I3_write_buffer( smallbuf );
I3_write_buffer( ",\"" );
strcpy( stats, "&z[" );
if( CH_I3AFK(person) )
strcat( stats, "AFK" );
else
strcat( stats, "---" );
strcat( stats, "]&G" );
sprintf( personbuf, "%s %s%s", stats, CH_I3NAME(person), CH_I3TITLE(person) );
send_to_i3( I3_escape( personbuf ) );
I3_write_buffer( "\",})," );
}
}
}
I3_write_buffer( "({\"" );
sprintf( tailbuf, "&Y[&W%d Player%s&Y]", pcount, pcount == 1 ? "" : "s" );
send_to_i3( I3_escape( tailbuf ) );
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", bogusidle * 2 );
I3_write_buffer( smallbuf );
I3_write_buffer( ",\"" );
sprintf( tailbuf, "&Y[&WHomepage: %s&Y] [&W%3d Max Since Reboot&Y]", this_mud->web, I3MAXPLAYERS );
send_to_i3( I3_escape( tailbuf ) );
I3_write_buffer( "\",}),}),})\r" );
I3_send_packet( );
return;
}
#endif
/* This is where the incoming results of a who-reply packet are processed.
* Note that rather than just spit the names out, I've copied the packet fields into
* buffers to be output later. Also note that if it receives an idle value of 9999
* the normal 30 space output will be bypassed. This is so that muds who want to
* customize the listing headers in their who-reply packets can do so and the results
* won't get chopped off after the 30th character. If for some reason a person on
* the target mud just happens to have been idling for 9999 cycles, their data may
* be displayed strangely compared to the rest. But I don't expect that 9999 is a very
* common length of time to be idle either :P
* Receving an idle value of 19998 may also cause odd results since this is used
* to indicate receipt of the last line of a who, which is typically the number of
* visible players found.
*/
void I3_process_who_reply( I3_HEADER *header, char *s )
{
char *ps =s, *next_ps, *next_ps2;
CHAR_DATA *ch;
char person[LGST], title[SMST];
int idle;
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
{
return;
}
ps+=2;
while( 1 )
{
if( ps[0] == '}' )
{
i3_to_char( "No information returned.\n\r", ch );
return;
}
I3_get_field( ps, &next_ps );
ps += 2;
I3_get_field( ps, &next_ps2 );
I3_remove_quotes( &ps );
sprintf( person, "%s", ps );
ps = next_ps2;
I3_get_field( ps, &next_ps2 );
idle = atoi( ps );
ps = next_ps2;
I3_get_field( ps, &next_ps2 );
I3_remove_quotes( &ps );
sprintf( title, "%s", ps );
ps = next_ps2;
if( idle == 9999 )
i3_printf( ch, "%s %s\n\r\n\r", person, title );
else if( idle == 19998 )
i3_printf( ch, "\n\r%s %s\n\r", person, title );
else if( idle == 29997 )
i3_printf( ch, "\n\r%s %s\n\r\n\r", person, title );
else
i3_printf( ch, "%s %s\n\r", person, title );
ps = next_ps;
if( ps[0] == '}' )
break;
}
return;
}
void I3_send_emoteto( CHAR_DATA *ch, char *to, I3_MUD *mud, const char *message )
{
char buf[LGST];
if( !I3_is_connected() )
return;
if( strstr( message, "$N" ) == NULL )
sprintf( buf, "$N %s", message );
else
strcpy( buf, message );
I3_escape( to );
I3_write_header( "emoteto", I3_THISMUD, CH_I3NAME(ch), mud->name, to );
I3_write_buffer( "\"" );
I3_write_buffer( CH_I3NAME(ch) );
I3_write_buffer( "\",\"" );
send_to_i3( I3_escape( buf ) );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_process_emoteto( I3_HEADER *header, char *s )
{
CHAR_DATA *ch;
char *ps = s, *next_ps;
char visname[SMST];
char message[LGST], msg[LGST], buf[LGST];
sprintf( buf, "%s@%s", header->originator_username, header->originator_mudname );
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
{
if( !i3exists_player( header->target_username ) )
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
else
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3PERM(ch) < I3PERM_MORT )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
return;
}
if( I3ISINVIS(ch) || i3ignoring( ch, buf ) || !ch->desc )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( visname, "%s@%s", ps, header->originator_mudname );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( message, ps );
sprintf( msg, "&c%s\n\r", I3_convert_channel_message( message, visname, visname ) );
i3_to_char( msg, ch );
return;
}
void I3_send_finger( CHAR_DATA *ch, char *user, char *mud )
{
if( !I3_is_connected() )
return;
I3_escape( mud );
I3_escape( user );
I3_write_header( "finger-req", I3_THISMUD, CH_I3NAME(ch), mud, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( user );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
/* The output of this was slightly modified to resemble the Finger snippet */
void I3_process_finger_reply( I3_HEADER *header, char *s )
{
CHAR_DATA *ch;
char *ps = s, *next_ps;
char title[LGST], homepage[LGST], email[LGST], last[LGST], level[LGST];
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
{
return;
}
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
i3_printf( ch, "&wI3FINGER information for &G%s@%s\n\r", ps, header->originator_mudname );
i3_to_char( "&w-------------------------------------------------\n\r", ch );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( title, "%s", ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( email, "%s", ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( last, "%s", ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( level, "%s", ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( homepage, "%s", ps );
i3_printf( ch, "&wTitle: &G%s\n\r", title );
i3_printf( ch, "&wLevel: &G%s\n\r", level );
i3_printf( ch, "&wEmail: &G%s\n\r", email );
i3_printf( ch, "&wHTTP : &G%s\n\r", homepage );
i3_printf( ch, "&wLast on: &G%s\n\r", last );
return;
}
void I3_process_finger_req( I3_HEADER *header, char *s )
{
CHAR_DATA *ch;
char *ps = s, *next_ps;
char smallbuf[LGST], buf[LGST];
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( buf, "%s@%s", header->originator_username, header->originator_mudname );
if( ( ch = I3_find_user( ps ) ) == NULL )
{
if( !i3exists_player( ps ) )
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
else
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3PERM(ch) < I3PERM_MORT )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "No such player." );
return;
}
if( I3ISINVIS(ch) || i3ignoring( ch, buf ) )
{
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", "That player is offline." );
return;
}
if( I3IS_SET( I3FLAG(ch), I3_DENYFINGER ) || I3IS_SET( I3FLAG(ch), I3_PRIVACY ) )
{
sprintf( buf, "%s is not accepting fingers.", CH_I3NAME(ch) );
I3_send_error( header->originator_mudname, header->originator_username, "unk-user", buf );
return;
}
i3_printf( ch, "%s@%s has requested your i3finger information.\n\r",
header->originator_username, header->originator_mudname );
I3_write_header( "finger-reply", I3_THISMUD, NULL, header->originator_mudname, header->originator_username );
I3_write_buffer( "\"" );
I3_write_buffer( I3_escape( CH_I3NAME(ch) ) );
I3_write_buffer( "\",\"" );
I3_write_buffer( I3_escape( CH_I3NAME(ch) ) );
send_to_i3( I3_escape( CH_I3TITLE(ch) ) );
I3_write_buffer( "\",\"\",\"" ); /* real name */
#ifdef FINGERCODE
if( ch->pcdata->email )
{
if( !IS_SET( ch->pcdata->flags, PCFLAG_PRIVACY ) )
I3_write_buffer( ch->pcdata->email ); /* email address */
else
I3_write_buffer( "[Private]" );
}
#else
I3_write_buffer( "Not supported" );
#endif
I3_write_buffer( "\",\"" );
strcpy( smallbuf, "-1" ); /* online since */
I3_write_buffer( smallbuf );
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", -1l );
I3_write_buffer( smallbuf ); /* idle since */
I3_write_buffer( ",\"" );
I3_write_buffer( "[PRIVATE]" ); /* IP address */
I3_write_buffer( "\",\"" );
sprintf( buf, "%s", rankbuffer( ch ) );
send_to_i3( buf );
#ifdef FINGERCODE
I3_write_buffer( "\",\"" );
if( ch->pcdata->homepage )
I3_write_buffer( I3_escape( ch->pcdata->homepage ) );
else
I3_write_buffer( "Not Provided" );
I3_write_buffer( "\",})\r" );
#else
I3_write_buffer( "\",\"Not Suported\",})\r" ); /* No extra info */
#endif
I3_send_packet( );
return;
}
void I3_send_locate( CHAR_DATA *ch, const char *user )
{
if( !I3_is_connected() )
return;
I3_escape( user );
I3_write_header( "locate-req", I3_THISMUD, CH_I3NAME(ch), NULL, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( user );
I3_write_buffer( "\",})\r" );
I3_send_packet( );
return;
}
void I3_process_locate_reply( I3_HEADER *header, char *s )
{
char mud_name[LGST], user_name[LGST], status[LGST];
char *ps = s, *next_ps;
CHAR_DATA *ch;
if( ( ch = I3_find_user( header->target_username ) ) == NULL )
{
return;
}
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( mud_name, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( user_name, ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
ps = next_ps;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
strcpy( status, ps );
if( !str_cmp( status, "active" ) )
strcpy( status, "Online." );
if( !str_cmp( status, "exists, but not logged on" ) )
strcpy( status, "Offline." );
i3_printf( ch, "&RI3 Locate: &Y%s@%s: &c%s\n\r", user_name, mud_name, status );
return;
}
void I3_process_locate_req( I3_HEADER *header, char *s )
{
char *ps = s, *next_ps;
char smallbuf[LGST], buf[LGST];
CHAR_DATA *ch;
bool choffline = FALSE;
I3_get_field( ps, &next_ps );
I3_remove_quotes( &ps );
sprintf( buf, "%s@%s", header->originator_username, header->originator_mudname );
if( ( ch = I3_find_user( ps ) ) == NULL )
{
if( i3exists_player( ps ) )
choffline = TRUE;
else
return;
}
if( ch )
{
if( I3PERM(ch) < I3PERM_MORT )
return;
if( I3ISINVIS(ch) )
choffline = TRUE;
if( i3ignoring( ch, buf ) )
choffline = TRUE;
}
I3_write_header( "locate-reply", I3_THISMUD, NULL, header->originator_mudname, header->originator_username );
I3_write_buffer( "\"" );
I3_write_buffer( I3_THISMUD );
I3_write_buffer( "\",\"" );
if( !choffline )
I3_write_buffer( CH_I3NAME(ch) );
else
I3_write_buffer( i3capitalize(ps) );
I3_write_buffer( "\"," );
sprintf( smallbuf, "%ld", -1l );
I3_write_buffer( smallbuf );
if( !choffline )
I3_write_buffer( ",\"active\",})\r" );
else
I3_write_buffer( ",\"exists, but not logged on\",})\r" );
I3_send_packet( );
return;
}
void I3_send_channel_listen( I3_CHANNEL *channel, bool lconnect )
{
if( !I3_is_connected() )
return;
I3_write_header( "channel-listen", I3_THISMUD, NULL, I3_ROUTER_NAME, NULL );
I3_write_buffer( "\"" );
I3_write_buffer( channel->I3_name );
I3_write_buffer( "\"," );
if( lconnect )
I3_write_buffer( "1,})\r" );
else
I3_write_buffer( "0,})\r" );
I3_send_packet( );
return;
}
void I3_mudlisten( CHAR_DATA *ch, const char *argument )
{
I3_CHANNEL *channel;
char arg[SMST];
if( !argument || argument[0] == '\0' )
{
i3_to_char( "Usage: i3mudlisten [all/none]\n\r", ch );
i3_to_char( "Usage: i3mudlisten <localchannel> [on/off]\n\r", ch );
return;
}
if( !str_cmp( argument, "all" ) )
{
for( channel = first_I3chan; channel; channel = channel->next )
{
if( !channel->local_name || channel->local_name[0] == '\0' )
continue;
i3_printf( ch, "Subscribing to %s.\n\r", channel->local_name );
I3_send_channel_listen( channel, TRUE );
}
send_to_char( "&YThe mud is now subscribed to all available local I3 channels.\n\r", ch );
return;
}
if( !str_cmp( argument, "none" ) )
{
for( channel = first_I3chan; channel; channel = channel->next )
{
if( !channel->local_name || channel->local_name[0] == '\0' )
continue;
i3_printf( ch, "Unsubscribing from %s.\n\r", channel->local_name );
I3_send_channel_listen( channel, FALSE );
}
send_to_char( "&YThe mud is now unsubscribed from all available local I3 channels.\n\r", ch );
return;
}
argument = i3one_argument( argument, arg );
if( !( channel = find_I3_channel_by_localname( arg ) ) )
{
i3_to_char( "No such channel configured locally.\n\r", ch );
return;
}
if( !str_cmp( argument, "on" ) )
{
i3_printf( ch, "Turning %s channel on.\n\r", channel->local_name );
I3_send_channel_listen( channel, TRUE );
return;
}
if( !str_cmp( argument, "off" ) )
{
i3_printf( ch, "Turning %s channel off.\n\r", channel->local_name );
I3_send_channel_listen( channel, FALSE );
return;
}
I3_mudlisten( ch, "" );
return;
}
#if defined(KEY)
#undef KEY
#endif
#define KEY( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
field = value; \
fMatch = TRUE; \
break; \
}
/*
* Read a string from file fp using I3STRALLOC [Taken from Smaug's fread_string]
*/
char *i3fread_string( FILE *fp )
{
char buf[LGST];
char *plast;
char c;
int ln;
plast = buf;
buf[0] = '\0';
ln = 0;
/*
* Skip blanks.
* Read first char.
*/
do
{
if ( feof(fp) )
{
i3bug( "%s", "i3fread_string: EOF encountered on read." );
return I3STRALLOC( "" );
}
c = getc( fp );
}
while ( isspace(c) );
if ( ( *plast++ = c ) == '~' )
return I3STRALLOC( "" );
for ( ;; )
{
if ( ln >= (LGST - 1) )
{
i3bug( "%s", "i3fread_string: string too long" );
*plast = '\0';
return I3STRALLOC( buf );
}
switch ( *plast = getc( fp ) )
{
default:
plast++; ln++;
break;
case EOF:
i3bug( "%s", "i3fread_string: EOF" );
*plast = '\0';
return I3STRALLOC( buf );
case '\n':
plast++; ln++;
*plast++ = '\r'; ln++;
break;
case '\r':
break;
case '~':
*plast = '\0';
return I3STRALLOC( buf );
}
}
}
/*
* Read a number from a file. [Taken from Smaug's fread_number]
*/
int i3fread_number( FILE *fp )
{
int number;
bool sign;
char c;
do
{
if ( feof(fp) )
{
i3log( "%s", "i3fread_number: EOF encountered on read." );
return 0;
}
c = getc( fp );
}
while ( isspace(c) );
number = 0;
sign = FALSE;
if ( c == '+' )
{
c = getc( fp );
}
else if ( c == '-' )
{
sign = TRUE;
c = getc( fp );
}
if ( !isdigit(c) )
{
i3log( "i3fread_number: bad format. (%c)", c );
return 0;
}
while ( isdigit(c) )
{
if( feof(fp) )
{
i3log( "%s", "i3fread_number: EOF encountered on read." );
return number;
}
number = number * 10 + c - '0';
c = getc( fp );
}
if ( sign )
number = 0 - number;
if ( c == '|' )
number += i3fread_number( fp );
else if ( c != ' ' )
ungetc( c, fp );
return number;
}
/*
* Read to end of line into static buffer [Taken from Smaug's fread_line]
*/
char *i3fread_line( FILE *fp )
{
static char line[LGST];
char *pline;
char c;
int ln;
pline = line;
line[0] = '\0';
ln = 0;
/*
* Skip blanks.
* Read first char.
*/
do
{
if ( feof(fp) )
{
i3bug( "%s", "i3fread_line: EOF encountered on read." );
strcpy( line, "" );
return line;
}
c = getc( fp );
}
while ( isspace(c) );
ungetc( c, fp );
do
{
if ( feof(fp) )
{
i3bug( "%s", "i3fread_line: EOF encountered on read." );
*pline = '\0';
return line;
}
c = getc( fp );
*pline++ = c; ln++;
if ( ln >= (LGST - 1) )
{
i3bug( "%s", "i3fread_line: line too long" );
break;
}
}
while ( c != '\n' && c != '\r' );
do
{
c = getc( fp );
}
while ( c == '\n' || c == '\r' );
ungetc( c, fp );
*pline = '\0';
return line;
}
/*
* Read one word (into static buffer). [Taken from Smaug's fread_word]
*/
char *i3fread_word( FILE *fp )
{
static char word[SMST];
char *pword;
char cEnd;
do
{
if ( feof(fp) )
{
i3log( "%s", "i3fread_word: EOF encountered on read." );
word[0] = '\0';
return word;
}
cEnd = getc( fp );
}
while ( isspace( cEnd ) );
if ( cEnd == '\'' || cEnd == '"' )
{
pword = word;
}
else
{
word[0] = cEnd;
pword = word+1;
cEnd = ' ';
}
for ( ; pword < word + SMST; pword++ )
{
if ( feof(fp) )
{
i3log( "%s", "i3fread_word: EOF encountered on read." );
*pword = '\0';
return word;
}
*pword = getc( fp );
if ( cEnd == ' ' ? isspace(*pword) : *pword == cEnd )
{
if ( cEnd == ' ' )
ungetc( *pword, fp );
*pword = '\0';
retShowing the first 100 KB of 207.8 KB. Download the archive for the full file.