Author: Mark
Date: Wed May 18 06:54:18 2005
New Revision: 2595
Added:
trunk/modules/textserv/loveserv (contents, props changed)
Modified:
trunk/ChangeLog
trunk/include/neostats.h
trunk/modules/textserv/main.c
trunk/src/commands.c
Log:
textserv updates plus loveserv and moraleserv databases
Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Wed May 18 06:54:18 2005
@@ -4,6 +4,9 @@
Fish (F), Mark (M), DeadNotBuried (D)
===============================================================================
* NeoStats * Version 3.0.a3-dev
+ - TextServ: Add moraleserv database. (M)
+ - TextServ: Add loveserv database. (M)
+ - TextServ: Add database reading support. (M)
- DCC fixes and move partyline support to an external module to aid
development of the DCC module API. (M)
- Add support to set topic from NeoStats. (M)
Modified: trunk/include/neostats.h
==============================================================================
--- trunk/include/neostats.h (original)
+++ trunk/include/neostats.h Wed May 18 06:54:18 2005
@@ -685,12 +685,15 @@
void *modvalue[NUM_MODULES];
} Channel;
+typedef struct _bot_cmd bot_cmd;
+
typedef struct CmdParams {
Client *source; /* pointer to client triggering command */
Client *target; /* pointer to client command acts on */
Bot *bot; /* pointer to associated bot where appropriate */
char *param; /* command parameter */
char *cmd; /* command */
+ bot_cmd *cmd_ptr; /* pointer to associated command structure */
Channel *channel; /* pointer to channel struct where appropriate */
char **av; /* command parameter list */
int ac; /* count of command parameter list */
@@ -726,7 +729,7 @@
/** @brief bot_cmd structure
* defines command lists for bots
*/
-typedef struct bot_cmd {
+typedef struct _bot_cmd {
const char *cmd; /* command string */
bot_cmd_handler handler; /* handler */
int minparams; /* min num params */
@@ -734,8 +737,9 @@
const char **helptext; /* pointer to help text */
const char *onelinehelp;/* single line help for generic help function */
int flags; /* command flags */
+ void *moddata; /* pointer for module use */
Module *modptr; /* NeoStats internal use only */
-}bot_cmd;
+}_bot_cmd;
/** @brief flags for bots
* flags to influence how bots are managed
@@ -769,6 +773,10 @@
* are created.
*/
#define BOT_FLAG_PERSIST 0x00000010
+/* Prevent addition of LEVELS command to a service bot
+ * E.g. TextServ db bots
+ */
+#define BOT_FLAG_NOINTRINSICLEVELS 0x00000020
/* This defines a "NULL" string for the purpose of BotInfo structures that
* want to inherit the main host used by NeoStats and still make the info
@@ -1089,6 +1097,8 @@
int set_ulevel;
/* Link back to user struct associated with this bot*/
Client *u;
+ /* pointer for module use */
+ void *moddata;
}_Bot;
/* load configuration associated with this bot_setting list */
@@ -1555,5 +1565,9 @@
EXPORTFUNC void ClearServerModValue( Client *s );
EXPORTFUNC void SetServerModValue( Client *s, void *data );
EXPORTFUNC void *GetServerModValue( Client *s );
+/* Module Data Value Interface Bot */
+#define ClearBotModValue( b ) b->moddata = 0
+#define SetBotModValue( b, data ) b->moddata = data
+#define GetBotModValue( b ) b->moddata
#endif /* NEOSTATS_H */
Added: trunk/modules/textserv/loveserv
==============================================================================
--- (empty file)
+++ trunk/modules/textserv/loveserv Wed May 18 06:54:18 2005
@@ -0,0 +1,13 @@
+VERSION|3.0.a3-dev
+ABOUT|Send presents and messages to loved ones on IRC.
+CREDITS|Copyright (c) 1999-2005, NeoStats. http://www.neostats.net/
+ROSE|<TARGET>|Send a rose to a loved one.|%F has sent you this beautiful rose! 3--<--<--<{4@
+KISS|<TARGET>|Send a kiss to that special someone.|%F has virtually kissed you!
+TONSIL|<TARGET>|Send a deep tonsil penitrating kiss to someone.|%F would like to send a SLoW..LoNG..DeeP..PeNeTRaTiNG..ToNSiL-TiCKLiNG.. HaiR STRaiGHTeNiNG..Toe-CuRLiNG..NeRVe-JaNGLiNG..LiFe-aLTeRiNG.. FaNTaSY-CauSiNG..i JuST SaW GoD!..GoSH, DiD MY CLoTHeS FaLL oFF?.. YeS, i'M GLaD i CaMe oN iRC..KiSS oN Da LiPS!!!
+HUG|<TARGET>|Send a hug to someone.|%F has sent you a *BIG WARM HUG*!
+ADMIRER|<TARGET>|Tell someone they have a secret admirer.|You have a secret admirer! ;)
+CHOCOLATE|<TARGET>|Send a big yummy box of candy to someone.|%F would like you to have this yummy box of chocolates
+CANDY|<TARGET>|Send someone a box of yummy heart shaped candies.|%F would like you to have this big yummy bag of heart shaped candies
+LOVENOTE|<TARGET><MSG>|Send that special someone a love note.|%F has sent you a love note which reads: %M
+APOLOGY|<TARGET><MSG>|Send an apology to someone.|%F is sorry, and would like to apologise for %M
+THANKYOU|<TARGET><MSG>|Send a thank you message to someone.|%F wishes to thank you for %M
Modified: trunk/modules/textserv/main.c
==============================================================================
--- trunk/modules/textserv/main.c (original)
+++ trunk/modules/textserv/main.c Wed May 18 06:54:18 2005
@@ -34,6 +34,9 @@
dbentry database;
BotInfo botinfo;
Bot *botptr;
+ char *abouttext;
+ char *creditstext;
+ char *versiontext;
char **stringlist;
int stringcount;
}dbbot;
@@ -43,6 +46,11 @@
static int ts_cmd_list( CmdParams *cmdparams );
static int ts_cmd_del( CmdParams *cmdparams );
+static int ts_cmd_msg( CmdParams* cmdparams );
+static int ts_cmd_about( CmdParams* cmdparams );
+static int ts_cmd_credits( CmdParams* cmdparams );
+static int ts_cmd_version( CmdParams* cmdparams );
+
/** hash to store database and bot info */
static hash_t *tshash;
@@ -87,6 +95,9 @@
/** Sub bot comand table template */
const char ts_help_cmd_oneline[] ="oneline";
+const char ts_help_about_oneline[] = "Display about text";
+const char ts_help_credits_oneline[] = "Display credits";
+const char ts_help_version_oneline[] = "Display version";
const char *ts_help_cmd[] = {
"Syntax: \2CMD\2",
@@ -95,10 +106,45 @@
NULL
};
+const char *ts_help_about[] = {
+ "Syntax: \2ABOUT\2",
+ "",
+ "Display information about the database",
+ NULL
+};
+
+const char *ts_help_credits[] = {
+ "Syntax: \2CREDITS\2",
+ "",
+ "Display credits",
+ NULL
+};
+
+const char *ts_help_version[] = {
+ "Syntax: \2VERSION\2",
+ "",
+ "Display version",
+ NULL
+};
static bot_cmd ts_commandtemplate[]=
{
- {NULL, NULL, 0, 0, ts_help_cmd, ts_help_cmd_oneline },
+ {NULL, ts_cmd_msg, 1, 0, ts_help_cmd, ts_help_cmd_oneline },
+};
+
+static bot_cmd ts_commandtemplateabout[]=
+{
+ {"ABOUT", ts_cmd_about, 0, 0, ts_help_about, ts_help_about_oneline },
+};
+
+static bot_cmd ts_commandtemplatecredits[]=
+{
+ {"CREDITS", ts_cmd_credits, 0, 0, ts_help_credits, ts_help_credits_oneline },
+};
+
+static bot_cmd ts_commandtemplateversion[]=
+{
+ {"VERSION", ts_cmd_version, 0, 0, ts_help_version, ts_help_version_oneline },
};
/** Sub bot setting table template */
@@ -189,6 +235,20 @@
/* next char... */
fmt++;
break;
+ /* handle %M (message) */
+ case 'M':
+ str = va_arg( args, char * );
+ /* If NULL string point to our null output string */
+ if( str == NULL ) {
+ str = nullstring;
+ }
+ /* copy string to output observing limit */
+ while( *str && len < size ) {
+ buf[len++] = *str++;
+ }
+ /* next char... */
+ fmt++;
+ break;
default:
buf[len++] = c;
break;
@@ -210,6 +270,72 @@
return len;
}
+/** @brief parse_line
+ *
+ * parse line of database file
+ *
+ * @param none
+ *
+ * @return NS_SUCCESS if succeeds, else NS_FAILURE
+ */
+static int parse_line( dbbot *db, char *buf, int *commandreadcount )
+{
+ int readcount = 0;
+ char *ptr;
+ char *ptr2;
+
+ /* Get command text */
+ ptr = strtok( buf, "|" );
+ if( !ptr )
+ return NS_FAILURE;
+ if( ircstrcasecmp( ptr, "ABOUT" ) == 0 )
+ {
+ ptr = strtok( NULL, "|" );
+ if( !ptr )
+ return NS_FAILURE;
+ dlog( DEBUG1, "about %s", ptr );
+ ptr2 = ns_malloc( strlen( ptr ) );
+ strcpy( ptr2, ptr );
+ db->abouttext = ptr2;
+ return NS_SUCCESS;
+ }
+ if( ircstrcasecmp( ptr, "CREDITS" ) == 0 )
+ {
+ ptr = strtok( NULL, "|" );
+ if( !ptr )
+ return NS_FAILURE;
+ dlog( DEBUG1, "credits %s", ptr );
+ ptr2 = ns_malloc( strlen( ptr ) );
+ strcpy( ptr2, ptr );
+ db->creditstext = ptr2;
+ return NS_SUCCESS;
+ }
+ if( ircstrcasecmp( ptr, "VERSION" ) == 0 )
+ {
+ ptr = strtok( NULL, "|" );
+ if( !ptr )
+ return NS_FAILURE;
+ dlog( DEBUG1, "credits %s", ptr );
+ ptr2 = ns_malloc( strlen( ptr ) );
+ strcpy( ptr2, ptr );
+ db->versiontext = ptr2;
+ return NS_SUCCESS;
+ }
+ while( ptr )
+ {
+ readcount++;
+ dlog( DEBUG1, "read %s", ptr );
+ ptr2 = ns_malloc( strlen( ptr ) );
+ strcpy( ptr2, ptr );
+ AddStringToList( &db->stringlist, ptr2, &db->stringcount );
+ ptr = strtok( NULL, "|" );
+ }
+ if( readcount != 4 )
+ return NS_FAILURE;
+ (*commandreadcount)++;
+ return NS_SUCCESS;
+}
+
/** @brief ts_read_database
*
* Read a database file
@@ -221,65 +347,36 @@
static int ts_read_database( dbbot *db )
{
- static char buf[BUFSIZE];
+ static char filename[MAXPATH];
+ static char buf[BUFSIZE*4];
FILE *fp;
- int commandcount;
int commandreadcount = 0;
int i;
- fp = os_fopen( db->database.name, "rt" );
+ strlcpy( filename, "data/", MAXPATH );
+ strlcat( filename, db->database.name, MAXPATH );
+ fp = os_fopen( filename, "rt" );
if( !fp )
return NS_SUCCESS;
- /* Get command count */
- os_fgets(buf, BUFSIZE, fp);
- commandcount = atoi(buf);
- while( os_fgets( buf, BUFSIZE, fp ) != NULL )
+ while( os_fgets( buf, BUFSIZE*4, fp ) != NULL )
{
- char *ptr;
- char *ptr2;
-
/* comment char */
if( buf[0] == '#' )
continue;
- /* Get command text */
- ptr = strtok( buf, "|" );
- if( !ptr )
- break;
- dlog( DEBUG1, "command %s", ptr );
- ptr2 = ns_malloc( strlen( ptr ) );
- AddStringToList( &db->stringlist, ptr2, &db->stringcount );
- /* Get param text */
- ptr = strtok( NULL, "|" );
- if( !ptr )
- break;
- dlog( DEBUG1, "params %s", ptr );
- ptr2 = ns_malloc( strlen( ptr ) );
- AddStringToList( &db->stringlist, ptr2, &db->stringcount );
- /* Get help text */
- ptr = strtok( NULL, "|" );
- if( !ptr )
- break;
- dlog( DEBUG1, "desc %s", ptr );
- ptr2 = ns_malloc( strlen( ptr ) );
- AddStringToList( &db->stringlist, ptr2, &db->stringcount );
- /* Get output text */
- ptr = strtok( NULL, "|" );
- if( !ptr )
- break;
- ptr2 = ns_malloc( strlen( ptr ) );
- AddStringToList( &db->stringlist, ptr2, &db->stringcount );
- dlog( DEBUG1, "text %s", ptr );
- commandreadcount++;
+ parse_line( db, buf, &commandreadcount );
}
os_fclose( fp );
- if( commandreadcount != commandcount )
+ db->botinfo.bot_cmd_list = ns_calloc( sizeof( bot_cmd ) * ( ( db->stringcount / 4 ) + 4 ) );
+ for( i = 0; i < commandreadcount; i ++ )
{
- for( i = 0; i < db->stringcount; i++ )
- {
- ns_free( db->stringlist[i] );
- }
- return NS_FAILURE;
- }
+ os_memcpy( &db->botinfo.bot_cmd_list[i], &ts_commandtemplate, sizeof( bot_cmd ) );
+ db->botinfo.bot_cmd_list[i].cmd = db->stringlist[( i * 4 ) + 0];
+ db->botinfo.bot_cmd_list[i].onelinehelp = db->stringlist[( i * 4 ) + 2];
+ db->botinfo.bot_cmd_list[i].moddata = ( void * )db->stringlist[( i * 4 ) + 3];
+ }
+ os_memcpy( &db->botinfo.bot_cmd_list[i++], &ts_commandtemplateabout, sizeof( bot_cmd ) );
+ os_memcpy( &db->botinfo.bot_cmd_list[i++], &ts_commandtemplatecredits, sizeof( bot_cmd ) );
+ os_memcpy( &db->botinfo.bot_cmd_list[i++], &ts_commandtemplateversion, sizeof( bot_cmd ) );
return NS_SUCCESS;
}
@@ -291,14 +388,15 @@
*
* @return none
*/
+
void BuildBot( dbbot *db )
{
strlcpy( db->botinfo.nick, db->database.nick, MAXNICK );
strlcpy( db->botinfo.user, "ts", MAXUSER );
- strlcpy( db->botinfo.realname, db->database.name, MAXREALNAME );
+ strlcat( db->botinfo.realname, db->database.name, MAXREALNAME );
db->botinfo.bot_setting_list = ns_calloc( sizeof (ts_settingstemplate) );
os_memcpy( db->botinfo.bot_setting_list, ts_settingstemplate, sizeof (ts_settingstemplate) );
- db->botinfo.flags = BOT_FLAG_SERVICEBOT;
+ db->botinfo.flags = BOT_FLAG_SERVICEBOT|BOT_FLAG_NOINTRINSICLEVELS;
ts_read_database( db );
}
@@ -314,6 +412,7 @@
void JoinBot( dbbot *db )
{
db->botptr = AddBot( &db->botinfo );
+ SetBotModValue( db->botptr, (void *) db );
if( *db->database.channel )
irc_join( db->botptr, db->database.channel, NULL );
}
@@ -341,6 +440,9 @@
{
ns_free( db->stringlist[i] );
}
+ ns_free( db->abouttext );
+ ns_free( db->creditstext );
+ ns_free( db->versiontext );
}
/** @brief load_dbentry
@@ -455,6 +557,7 @@
static int ts_cmd_add( CmdParams *cmdparams )
{
+ static char filename[MAXPATH];
FILE *fp;
dbbot *db;
@@ -465,24 +568,23 @@
"%s already exists in the database list", cmdparams->av[0] );
return NS_SUCCESS;
}
- fp = os_fopen( cmdparams->av[0], "rt" );
+ strlcpy( filename, "data/", MAXPATH );
+ strlcat( filename, cmdparams->av[0], MAXPATH );
+ fp = os_fopen( filename, "rt" );
if( !fp )
{
- irc_prefmsg( ts_bot, cmdparams->source,
- "%s not found", cmdparams->av[0] );
+ irc_prefmsg( ts_bot, cmdparams->source, "%s not found", cmdparams->av[0] );
return NS_SUCCESS;
}
os_fclose( fp );
if( cmdparams->ac > 1 && ValidateNick( cmdparams->av[1] ) != NS_SUCCESS )
{
- irc_prefmsg( ts_bot, cmdparams->source,
- "%s is an invalid nick", cmdparams->av[1] );
+ irc_prefmsg( ts_bot, cmdparams->source, "%s is an invalid nick", cmdparams->av[1] );
return NS_SUCCESS;
}
if( cmdparams->ac > 2 && ValidateChannel( cmdparams->av[2] ) != NS_SUCCESS )
{
- irc_prefmsg( ts_bot, cmdparams->source,
- "%s is an invalid channel", cmdparams->av[2] );
+ irc_prefmsg( ts_bot, cmdparams->source, "%s is an invalid channel", cmdparams->av[2] );
return NS_SUCCESS;
}
db = ns_calloc( sizeof( dbbot ) );
@@ -570,3 +672,74 @@
irc_prefmsg( ts_bot, cmdparams->source, "No entry for %s", cmdparams->av[0] );
return NS_SUCCESS;
}
+
+/** @brief ts_cmd_msg
+ *
+ * ts_cmd_msg
+ * cmdparams->av[0] = target nick
+ * cmdparams->av[1 - cmdparams->ac] = message
+ *
+ * @cmdparams pointer to commands param struct
+ *
+ * @return NS_SUCCESS if suceeds else NS_FAILURE
+ */
+
+static int ts_cmd_msg( CmdParams* cmdparams )
+{
+ static char buf[BUFSIZE];
+ dbbot *db;
+ Client *target;
+
+ SET_SEGV_LOCATION();
+ db = (dbbot *) GetBotModValue( cmdparams->bot );
+ target = FindValidUser( cmdparams->bot, cmdparams->source, cmdparams->av[0] );
+ if( !target )
+ {
+ return NS_FAILURE;
+ }
+ irc_prefmsg( cmdparams->bot, cmdparams->source, "%s has been sent to %s", cmdparams->cmd, target->name );
+ if( cmdparams->ac > 1)
+ {
+ char *message;
+
+ message = joinbuf( cmdparams->av, cmdparams->ac, 1 );
+ tsprintf( cmdparams->bot->u->name, cmdparams->source->name, target->name, buf, BUFSIZE, ( char * ) cmdparams->cmd_ptr->moddata, message );
+ ns_free( message );
+ }
+ else
+ {
+ tsprintf( cmdparams->bot->u->name, cmdparams->source->name, target->name, buf, BUFSIZE, ( char * ) cmdparams->cmd_ptr->moddata );
+ }
+ irc_prefmsg( cmdparams->bot, cmdparams->source, buf );
+ return NS_SUCCESS;
+}
+
+static int ts_cmd_about( CmdParams* cmdparams )
+{
+ dbbot *db;
+
+ SET_SEGV_LOCATION();
+ db = (dbbot *) GetBotModValue( cmdparams->bot );
+ irc_prefmsg( cmdparams->bot, cmdparams->source, db->abouttext );
+ return NS_SUCCESS;
+}
+
+static int ts_cmd_credits( CmdParams* cmdparams )
+{
+ dbbot *db;
+
+ SET_SEGV_LOCATION();
+ db = (dbbot *) GetBotModValue( cmdparams->bot );
+ irc_prefmsg( cmdparams->bot, cmdparams->source, db->creditstext );
+ return NS_SUCCESS;
+}
+
+static int ts_cmd_version( CmdParams* cmdparams )
+{
+ dbbot *db;
+
+ SET_SEGV_LOCATION();
+ db = (dbbot *) GetBotModValue( cmdparams->bot );
+ irc_prefmsg( cmdparams->bot, cmdparams->source, db->versiontext );
+ return NS_SUCCESS;
+}
Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c (original)
+++ trunk/src/commands.c Wed May 18 06:54:18 2005
@@ -391,6 +391,8 @@
}
/* Handle intrinsic commands */
cmd_ptr = intrinsic_commands;
+ if( !ircstrcasecmp( cmd, "LEVELS" ) && cmdparams->bot->flags & BOT_FLAG_NOINTRINSICLEVELS )
+ return NS_FAILURE;
while( cmd_ptr->cmd ) {
if( !ircstrcasecmp( cmd, cmd_ptr->cmd ) ) {
intrinsic_handler( cmdparams, cmd_ptr->handler );
@@ -455,6 +457,7 @@
cmd_ptr = ( bot_cmd * ) hnode_find( cmdparams->bot->botcmds, av[0] );
if( cmd_ptr )
{
+ cmdparams->cmd_ptr = cmd_ptr;
processed = 1;
if( ischancmd && ( cmd_ptr->flags & CMD_FLAG_PRIVMSGONLY ) )
{
@@ -593,6 +596,11 @@
cmd_ptr = intrinsic_commands;
while( cmd_ptr->cmd ) {
/* Check for module override */
+ if( !ircstrcasecmp( cmd_ptr->cmd, "LEVELS" ) && cmdparams->bot->flags & BOT_FLAG_NOINTRINSICLEVELS )
+ {
+ cmd_ptr++;
+ continue;
+ }
if( !cmdparams->bot->botcmds || !hash_lookup( cmdparams->bot->botcmds, cmd_ptr->cmd ) ) {
irc_prefmsg( cmdparams->bot, cmdparams->source, " %-20s %s", cmd_ptr->cmd, cmd_ptr->onelinehelp );
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.