[NeoStats-Devel] [Commits] r2684 - in trunk: include modules/perltest src
[email protected] Mon, 1 Aug 2005 21:05:26 +1000
Newsgroups
gmane.comp.neostats.devel
Message-ID
<[email protected] >
Author: Fish
Date: Mon Aug 1 19:05:19 2005
New Revision: 2684
Modified:
trunk/include/commands.h
trunk/modules/perltest/test.pl
trunk/src/NeoStats.pm
trunk/src/commands.c
trunk/src/modules.c
trunk/src/neostats.pm.h
trunk/src/perl.c
Log:
more perl updates
Modified: trunk/include/commands.h
==============================================================================
--- trunk/include/commands.h (original)
+++ trunk/include/commands.h Mon Aug 1 19:05:19 2005
@@ -27,6 +27,9 @@
int add_bot_cmd_list( Bot *bot_ptr, bot_cmd *bot_cmd_list );
int del_bot_cmd_list( Bot *bot_ptr, bot_cmd *bot_cmd_list );
int del_all_bot_cmds( Bot* bot_ptr );
+int add_bot_cmd( hash_t *cmd_hash, bot_cmd *cmd_ptr );
+bot_cmd *find_bot_cmd( Bot *bot_ptr, char *cmd);
+int del_bot_cmd( hash_t *cmd_hash, bot_cmd *cmd_ptr );
int run_bot_cmd( CmdParams * cmdparams, int ischancmd );
int getuserlevel( CmdParams *cmdparams );
void msg_permission_denied( CmdParams *cmdparams, char *subcommand );
Modified: trunk/modules/perltest/test.pl
==============================================================================
--- trunk/modules/perltest/test.pl (original)
+++ trunk/modules/perltest/test.pl Mon Aug 1 19:05:19 2005
@@ -344,6 +344,14 @@
flags => '0',
};
NeoStats::AddCmd($bot, $cmd, 'cmd_cb_test');
+ $cmd = {
+ cmd => 'test2',
+ minparams => '1',
+ ulevel => '0',
+ flags => '0',
+ };
+ NeoStats::AddCmd($bot, $cmd, 'cmd_cb_test');
+ NeoStats::print(NeoStats::DelCmd($bot, $cmd->{cmd}));
}
sub cmd_cb_test {
Modified: trunk/src/NeoStats.pm
==============================================================================
--- trunk/src/NeoStats.pm (original)
+++ trunk/src/NeoStats.pm Mon Aug 1 19:05:19 2005
@@ -236,6 +236,17 @@
return $ret;
}
+ sub DelCmd {
+ if (@_ < 2) {
+ NeoStats::print("Invalid Number of arguments to DelCmd");
+ return NeoStats::NS_FAILURE;
+ }
+ my $bot = shift;
+ my $botcmd = shift;
+NeoStats::print("$bot $botcmd");
+ return NeoStats::Internal::DelCommand($bot, $botcmd);
+ }
+
sub print {
my $text = shift @_;
Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c (original)
+++ trunk/src/commands.c Mon Aug 1 19:05:19 2005
@@ -243,6 +243,25 @@
return NS_SUCCESS;
}
+/** @brief find_bot_cmd finds the bot command structure
+ *
+ * @return bot_cmd structure or NULL if not found
+ */
+
+
+bot_cmd *find_bot_cmd( Bot *bot_ptr, char *cmd)
+{
+ hnode_t *cmdnode;
+
+ /* Find the command */
+ cmdnode = hash_lookup( bot_ptr->botcmds, cmd );
+ if( cmdnode ) {
+ return hnode_get(cmdnode);
+ }
+ return NULL;
+}
+
+
/** @brief del_bot_cmd deltes a single command to the command hash
*
* @return NS_SUCCESS if succeeds, NS_FAILURE if not
@@ -735,7 +754,13 @@
static int bot_cmd_about( CmdParams *cmdparams )
{
if( cmdparams->bot->moduleptr ) {
- irc_prefmsg_list( cmdparams->bot, cmdparams->source, cmdparams->bot->moduleptr->info->about_text );
+ if (IS_STD_MOD(cmdparams->bot->moduleptr)) {
+ irc_prefmsg_list( cmdparams->bot, cmdparams->source, cmdparams->bot->moduleptr->info->about_text );
+#if USE_PERL
+ } else {
+ irc_prefmsg(cmdparams->bot, cmdparams->source, "Not Available");
+#endif
+ }
}
return NS_SUCCESS;
}
@@ -760,8 +785,14 @@
static int bot_cmd_credits( CmdParams *cmdparams )
{
if( cmdparams->bot->moduleptr ) {
- irc_prefmsg_list( cmdparams->bot, cmdparams->source,
- cmdparams->bot->moduleptr->info->copyright );
+ if (IS_STD_MOD(cmdparams->bot->moduleptr)) {
+ irc_prefmsg_list( cmdparams->bot, cmdparams->source,
+ cmdparams->bot->moduleptr->info->copyright );
+#if USE_PERL
+ } else {
+ irc_prefmsg(cmdparams->bot, cmdparams->source, "Not Available");
+#endif
+ }
}
return NS_SUCCESS;
}
Modified: trunk/src/modules.c
==============================================================================
--- trunk/src/modules.c (original)
+++ trunk/src/modules.c Mon Aug 1 19:05:19 2005
@@ -405,6 +405,7 @@
char path[255];
char loadmodname[255];
struct stat buf;
+ Module *mod;
strlcpy (loadmodname, modfilename, 255);
strlwr (loadmodname);
@@ -415,7 +416,12 @@
#ifdef USE_PERL
ircsnprintf (path, 255, "%s/%s%s", MOD_PATH, loadmodname, MOD_PERLEXT);
if (stat(path, &buf) != -1) {
- return load_perlmodule(path, u);
+ mod = load_perlmodule(path, u);
+ mod->info->build_date = ns_malloc(10);
+ strftime((char *)mod->info->build_date, 9, "%d/%m/%y", gmtime(&buf.st_mtime));
+ mod->info->build_time = ns_malloc(11);
+ strftime((char *)mod->info->build_time, 10, "%H:%M", gmtime(&buf.st_mtime));
+ return mod;
}
#endif
/* if we get here, ehhh, doesn't exist */
Modified: trunk/src/neostats.pm.h
==============================================================================
--- trunk/src/neostats.pm.h (original)
+++ trunk/src/neostats.pm.h Mon Aug 1 19:05:19 2005
@@ -236,6 +236,17 @@
"return $ret;\n"
"}\n"
"\n"
+"sub DelCmd {\n"
+"if (@_ < 2) {\n"
+"NeoStats::print(\"Invalid Number of arguments to DelCmd\");\n"
+"return NeoStats::NS_FAILURE;\n"
+"}\n"
+"my $bot = shift;\n"
+"my $botcmd = shift;\n"
+"NeoStats::print(\"$bot $botcmd\");\n"
+"return NeoStats::Internal::DelCommand($bot, $botcmd);\n"
+"}\n"
+"\n"
"sub print {\n"
"\n"
"my $text = shift @_;\n"
Modified: trunk/src/perl.c
==============================================================================
--- trunk/src/perl.c (original)
+++ trunk/src/perl.c Mon Aug 1 19:05:19 2005
@@ -28,6 +28,7 @@
#include "neostats.h"
#include "services.h"
#include "modules.h"
+#include "commands.h"
#undef _
#define PERLDEFINES
#include "perlmod.h"
@@ -300,7 +301,7 @@
int
perl_command_cb(CmdParams *cmdparams) {
-
+ return NS_SUCCESS;
}
@@ -419,6 +420,7 @@
mod->info->version = SvPV_nolen (ST (1));
mod->info->description = SvPV_nolen (ST (2));
#if 0
+XXX TODO Credits and about
name = SvPV_nolen (ST (0));
version = SvPV_nolen (ST (1));
desc = SvPV_nolen (ST (2));
@@ -680,7 +682,6 @@
Module *mod;
HV * rethash;
SV *ret;
- int flags;
SV *value;
bot_cmd *bc;
Bot *bot;
@@ -719,21 +720,39 @@
strlcpy(bc->moddata, SvPV_nolen(ST(2)), SvLEN(ST(2))+1);
bc->modptr = mod;
bc->handler = perl_command_cb;
-printf("Adding %s to bot %s\n", bc->cmd, SvPV_nolen(ST(0)));
bot = FindBot(SvPV_nolen(ST(0)));
if (bot) {
if (bot->botcmds == NULL) {
bot->botcmds = hash_create(-1, 0, 0);
}
XSRETURN_UV(add_bot_cmd(bot->botcmds, bc));
- } else {
-printf("Empty\n");
- XSRETURN_EMPTY;
}
}
XSRETURN_UV(NS_FAILURE);
}
+static
+XS (XS_NeoStats_DelCommand)
+{
+ Module *mod;
+ Bot *bot;
+ bot_cmd *cmd_ptr = NULL;
+
+ dXSARGS;
+ mod = GET_CUR_MODULE();
+ if (items < 2) {
+ nlog(LOG_WARNING, "Usage: NeoStats:Internal:DelCommand(bot, botcmd)");
+ } else {
+ bot = FindBot(SvPV_nolen(ST(0)));
+ if (bot)
+ cmd_ptr = find_bot_cmd(bot, SvPV_nolen(ST(1)));
+ if (cmd_ptr)
+ XSRETURN_UV(del_bot_cmd(bot->botcmds, cmd_ptr));
+ }
+ XSRETURN_UV(NS_FAILURE);
+}
+
+
#if 0
static
@@ -856,6 +875,7 @@
newXS ("NeoStats::Internal::FindServer", XS_NeoStats_FindServer, __FILE__);
newXS ("NeoStats::Internal::FindChannel", XS_NeoStats_FindChannel, __FILE__);
newXS ("NeoStats::Internal::AddCommand", XS_NeoStats_AddCommand, __FILE__);
+ newXS ("NeoStats::Internal::DelCommand", XS_NeoStats_DelCommand, __FILE__);
stash = get_hv ("NeoStats::", TRUE);
if (stash == NULL) {
@@ -1050,6 +1070,10 @@
free((void *)mod->info->description);
free((void *)mod->info->version);
+
+ free((void *)mod->info->build_date);
+
+ free((void *)mod->info->build_time);
free(mod->info);