This commit is contained in:
joonicks 2018-04-02 18:33:49 +02:00
parent d9fac6178c
commit f50111b895
14 changed files with 433 additions and 255 deletions

2
.gitignore vendored
View File

@ -6,6 +6,7 @@ src/Makefile
src/config.h
src/mcmd.h
src/usercombo.h
trivia/*.index
# compiled files
energymech
@ -14,6 +15,7 @@ src/*.o
src/gencmd
src/aliastest
src/safepathtest
trivia/mkindex
# mech typical user config files
*~

View File

@ -18,7 +18,9 @@
#
MISCFILES = CREDITS LICENSE README README.TCL TODO VERSIONS VERSIONS-1 Makefile configure \
checkmech sample.conf sample.py sample.tcl sample.userfile default.bigchars public/README
checkmech sample.conf sample.py sample.tcl sample.userfile default.bigchars public/README trivia/README
ASCIIFILES = ascii/README ascii/bbw ascii/camel ascii/goatse ascii/mech ascii/phooler
HELPFILES = help/8BALL help/ACCESS help/ALIAS help/AWAY help/BAN help/BANLIST help/BYE \
help/CCHAN help/CHACCESS help/CHANBAN help/CHANNELS help/CHAT help/CLEARSHIT \
@ -47,11 +49,9 @@ RANDFILES = messages/8ball.txt messages/away.txt messages/insult.txt \
STUBFILES = src/Makefile.in src/config.h.in src/ld/README src/ld/elf32-i386 src/ld/elf64-x86-64
TESTFILES = config/cc.c config/endian.c config/inet_addr.c config/ldtest.c \
config/ptr_size.c config/socket.c config/tcl.c config/which \
config/md5.h config/md5_internal.c config/pw.c \
config/sha_internal.c config/sha1.h \
config/inet_aton.c config/unaligned.c config/python.c
TESTFILES = config/cc.c config/endian.c config/inet_addr.c config/inet_aton.c config/ldtest.c config/md5.h config/md5_internal.c \
config/perl.c config/ptr_size.c config/python.c config/pw.c config/sha1.h config/sha_internal.c config/socket.c config/tcl.c \
config/unaligned.c config/which
TRIVFILES = trivia/mkindex.c
@ -69,46 +69,48 @@ HDRFILES = src/defines.h src/global.h src/h.h src/settings.h src/structs.h src/t
CONFFILES = src/Makefile src/config.h
DISTFILES = $(MISCFILES) $(RANDFILES) $(SRCFILES) $(HELPFILES) \
DISTFILES = $(MISCFILES) $(RANDFILES) $(SRCFILES) $(HELPFILES) $(ASCIIFILES) \
$(STUBFILES) $(HDRFILES) $(TRIVFILES) $(TESTFILES)
#
# simple make rules
#
.PHONY: clean install mech mega mega-install test dist dist2
mech: $(SRCFILES) $(CONFFILES)
$(MAKE) -C src energymech
energymech: $(SRCFILES) $(CONFFILES)
$(MAKE) -C src energymech
clean: FORCE
clean:
$(MAKE) -C src clean
install: FORCE
install:
$(MAKE) -C src install
mega: FORCE
mega:
$(MAKE) -C src mega
mega-install: FORCE
mega-install:
$(MAKE) -C src mega-install
#
# code validation tests
#
test: FORCE
test:
$(MAKE) -C src test
#
# packing things up for distribution
#
dist: FORCE
dist:
$(MAKE) dist2 DISTDIR=`sed 's/^.*VERSION.*"\(.*\)".*$$/emech-\1/p; d;' src/global.h`
dist2: FORCE
dist2:
rm -rf /tmp/$(DISTDIR)
mkdir /tmp/$(DISTDIR)
tar cf - $(DISTFILES) | ( cd /tmp/$(DISTDIR) ; tar --preserve-permissions -xf - )
@ -116,4 +118,3 @@ dist2: FORCE
rm -rf /tmp/$(DISTDIR)
chmod 644 /tmp/$(DISTDIR).tar.gz
FORCE:

5
README
View File

@ -37,6 +37,10 @@ To compile the source:
export CROSS_COMPILE="armv7a-hardfloat-linux-gnueabi-"
4) make clean install
-- On a modern multi-core cpu, you can run make with the appropriate
-j switch to shave off a few seconds of compile time.
For example:
``make -j4'' for a 4 core cpu system.
If all went well you should now have an executable called
``energymech''.
@ -88,6 +92,7 @@ to see what's going on with...
If you get an 'Unknown option -d', you need to answer 'Y' to debug
support when running ./configure from the compiling section above.
Or run with ``./configure --with-debug''.
---*---

View File

@ -1,5 +1,8 @@
3.0.99p4 -- WORK IN PROGRESS (~March, 2018)
* Added: Energymech can now link with libmusl (--with-libmusl[=/PATH/TO/musl-gcc])
* Added: (ALPHA) Perl scripting support (PERL, PERLSCRIPT)
* Changed: Trivia question file must be placed in ./trivia/*
* Changed: If compiled with debug, Free() on unknown memory no longer shuts down the bot,
now it just ignores the panic and swallows the (possible) leak.
* Added: Experimental code to suppress certain commands to run on only one bot even

17
config/perl.c Normal file
View File

@ -0,0 +1,17 @@
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int main(int argc, char **argv, char **env)
{
PERL_SYS_INIT3(&argc,&argv,&env);
my_perl = perl_alloc();
perl_construct(my_perl);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_parse(my_perl, NULL, argc, argv, (char **)NULL);
perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}

215
configure vendored
View File

@ -20,15 +20,50 @@
umask 077
# perl still unsupported
#has_perl=no
compile=no
install=no
silentopt=no
try_libmusl=no
# default optimization goal, speed = -O2, size = -Os
optitype=size
set_feature_defaults() {
ft_alias=$ft_default
ft_botnet=$ft_default
ft_bounce=$ft_default
ft_chanban=$ft_default
ft_ctcp=$ft_default
ft_dccfile=$ft_default
ft_debug=$ft_default
ft_dynamode=$ft_default
ft_dyncmd=$ft_default
ft_greet=$ft_default
ft_hostinfo=$ft_default
ft_ircd_ext=$ft_default
ft_md5=$ft_default
ft_newbie=$ft_default
ft_note=$ft_default
ft_notify=$ft_default
ft_perl=$ft_default
ft_python=$ft_default
ft_rawdns=$ft_default
ft_redirect=$ft_default
ft_seen=$ft_default
ft_session=$ft_default
ft_sha=$ft_default
ft_stats=$ft_default
ft_suppress=$ft_default
ft_tcl=$ft_default
ft_telnet=$ft_default
ft_toybox=$ft_default
ft_trivia=$ft_default
ft_uptime=$ft_default
ft_urlcapture=$ft_default
ft_web=$ft_default
ft_wingate=$ft_default
}
for opt
do
@ -115,17 +150,20 @@ do
esac
case "$feature" in
debug | botnet | telnet | alias | seen | session | dyncmd | newbie | wingate | md5 | sha \
| ctcp | dccfile | uptime | redirect | greet | perl | profiling | tcl | dynamode | web | hostinfo \
| note | notify | trivia | toybox | bounce | stats | suppress | rawdns | ircd_ext | idwrap | chanban | python | urlcapture )
alias | botnet | bounce | chanban | ctcp | dccfile | debug | dynamode | dyncmd | greet | hostinfo | idwrap | ircd_ext | libmusl | md5 | newbie | note | notify | perl \
| profiling | python | rawdns | redirect | seen | session | sha | stats | suppress | tcl | telnet | toybox | trivia | uptime | urlcapture | web | wingate )
case _"$optarg"_ in
_yes_ | _no_ | __ )
;;
*)
if [ "$feature" = libmusl ]; then
try_libmusl="$optarg"
else
echo "unknown argument for $feature":" $optarg"
echo "Usage: configure [options]"
echo "use \"$0 --help\" for help"
exit 1
fi
esac
;;
___none___ )
@ -254,6 +292,7 @@ do
;;
--compile) compile=yes ;;
--install) install=yes ;;
--with-libmusl) try_libmusl=/usr/local/musl/bin/musl-gcc ;;
--silence=options) silentopt=yes ;;
--md5=internal) ft_md5=internal ;;
--sha=internal) ft_sha=internal ;;
@ -271,39 +310,8 @@ do
--no-pipeflag) cc_pipe_opt=no ;;
--use-ofp) cc_ofp_opt=yes ;;
--no-ofp) cc_ofp_opt=no ;;
--yes) ft_alias=yes
ft_botnet=yes
ft_bounce=yes
ft_chanban=yes
ft_ctcp=yes
ft_dccfile=yes
ft_debug=yes
ft_dynamode=yes
ft_dyncmd=yes
ft_greet=yes
ft_hostinfo=yes
ft_ircd_ext=yes
ft_md5=yes
ft_newbie=yes
ft_note=yes
ft_notify=yes
ft_python=yes
ft_rawdns=yes
ft_redirect=yes
ft_seen=yes
ft_session=yes
ft_sha=yes
ft_stats=yes
ft_suppress=yes
ft_tcl=yes
ft_telnet=yes
ft_toybox=yes
ft_trivia=yes
ft_uptime=yes
ft_urlcapture=yes
ft_web=yes
ft_wingate=yes
;;
--default-yes) ft_default=yes set_feature_defaults ;;
--default-no) ft_default=no set_feature_defaults ;;
--help | -h)
cat <<__EOT__
Usage: configure [options]
@ -312,29 +320,49 @@ Configuration:
Features and packages:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--with-FEATURE[=ARG] use FEATURE [ARG=yes]
--without-FEATURE do not use FEATURE (same as --with-FEATURE=no)
--with-FEATURE[=ARG] include FEATURE [ARG=yes]
--without-FEATURE do not include FEATURE (same as --with-FEATURE=no)
--default-yes Default answer for all feature selections is Yes
--default-no Default answer for all feature selections is No
--md5=internal Use internal routines for MD5 password hashes instead of system libraries
--sha=internal Use internal routines for SHA password hashes instead of system libraries
--use-ofp Try to use compiler flag -fomit-frame-pointer
--no-ofp Do not use compiler flag -fomit-frame-pointer
#md5 | ctcp | dccfile | uptime | redirect | greet | perl | dynamode | web \
#note | notify | trivia | toybox | bounce | stats | rawdns | ircd_ext | idwrap | chanban | python )
--with-alias ALIAS support
--with-botnet Botnet support
--with-bounce
--with-chanban
--with-ctcp
--with-dccfile
--with-debug Debug support
--with-dynamode
--with-dyncmd Dynamic command levels support
--with-hostinfo Support for code that reveals/displays/shares information about the host
that the bot is running on
--with-newbie Newbie support
--with-greet
--with-hostinfo Support for code that reveals/displays/shares information about the host that the bot is running on
--with-ircd_ext
--with-libmusl[=/PATH/TO/musl-gcc]
Try to use libmusl instead of system default
--with-md5
--with-newbie Newbie support for extra sanity checks and error messages
--with-note
--with-notify
--with-perl
--with-profiling Profiling (gcc+gprof)
--with-python
--with-rawdns
--with-redirect
--with-seen SEEN support
--with-session Session support
--with-sha
--with-stats
--with-suppress Command duplication suppression
--with-tcl Tcl support
--with-tcl Tcl scripting support
--with-telnet Telnet support
--with-toybox
--with-trivia
--with-uptime Include code that sends uptime reports to the IRC bot uptime contest server
--with-urlcapture URL capture support
--with-web
--with-wingate Wingate support
__EOT__
exit 0
@ -434,6 +462,32 @@ TESTO=./test$$.o
TESTP=./test$$
rm -f $TESTO $TESTP
has_musl=no
#
# if directed to use libmusl instead of (g)libc ...
#
if [ ! "$try_libmusl" = no ]; then
echo $ac_n "checking for libmusl ... "$ac_c
mgcc=`config/which musl-gcc`
if [ -x "$mgcc" ]; then
CC="$mgcc"
fi
if [ -x "$try_musl" ]; then
CC="$try_musl"
fi
if [ -x "$try_musl/musl-gcc" ]; then
CC="$try_musl/musl-gcc"
fi
if [ -x "$try_musl/bin/musl-gcc" ]; then
CC="$try_musl/bin/musl-gcc"
fi
if [ -x /opt/musl/bin/musl-gcc ]; then
CC=/opt/musl/bin/musl-gcc
fi
CCshort=$CC
echo $ac_t yes
fi
#
# does the C compile work?
#
@ -829,6 +883,29 @@ elif [ ! "$ft_md5" = no ]; then
rm -f $TESTP
fi
#
# check for perl scripting support
#
has_perl=no
perlinclude=
libperl=
if [ ! "$ft_perl" = no ]; then
echo $ac_n "checking for perl ... "$ac_c
pinc1=`perl -MConfig -e 'print $Config{archlib}'`
if [ -r $pinc1/CORE/perl.h -a -r $pinc1/CORE/EXTERN.h -a -r $pinc1/CORE/XSUB.h ]; then
perlinclude=$pinc1/CORE
TESTC=config/perl.c
if $CC -o $TESTP $TESTC -I$perlinclude -L$perlinclude -lperl 1> /dev/null 2> /dev/null; then
has_perl=yes
libperl=-lperl
I_PERL=-I$perlinclude
L_PERL=-L$perlinclude
fi
rm -f $TESTP
fi
echo $ac_t "$has_perl"
fi
#
# check for tcl
#
@ -977,6 +1054,28 @@ if [ "$silentopt" = yes ]; then
out=/bin/true
fi
#
# is this a git environment
#
echo $ac_n "checking for git ... "$ac_c
GITEXE=`config/which git`
echo $ac_t "$GITEXE"
#
# multiple cpus/cores for multiple parallell compiler jobs (make -j#)
#
cores=1
if [ -r /proc/cpuinfo ]; then
echo $ac_n "checking for multiple cpus or multiple cores ... "$ac_c
cores=`cat /proc/cpuinfo | grep '^processor' | wc -l`
echo $ac_t "$cores cpus/cores"
fi
makejobs=
if [ ! "$cores" = 1 ]; then
makejobs="-j$cores"
fi
echo
$out "Do you want ..."
$out
@ -1141,11 +1240,11 @@ fi
#
def_perl='#undef PERL'
unset ans
echo $ac_n "[ ALPHA] Perl scripting support? .................... [y/N] "$ac_c
$out $ac_n "[ ALPHA] Perl scripting support? .................... [y/N] "$ac_c
if [ "$has_perl" = no ]; then
echo 'no (unsupported)'
$out 'no (unsupported)'
else
test "$ft_perl" && echo "$ft_perl" && ans=$ft_perl
test "$ft_perl" && $out "$ft_perl" && ans=$ft_perl
test -z "$ft_perl" && read ans
test "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ans" = Yes && def_perl='#define PERL'
fi
@ -1248,7 +1347,7 @@ echo "Creating src/Makefile"
O_FLAGS="$cc_optimize_flag $cc_arch_flag $cc_march_flag $cc_ofp_flag"
W_FLAGS="$cc_wall_flag $cc_wshadow_flag $cc_fnostrictalias"
libflags="$libcrypt $libtcl $libnsl $libsocket $libresolv $libpython"
libflags="$libcrypt $libtcl $libnsl $libsocket $libresolv $libpython $libperl"
lflags="$cc_g_flag -o"
cprof="$cc_pg_flag $cc_pg_define"
lprof="$cc_pg_flag $cc_pg_define $libpgdl"
@ -1265,12 +1364,15 @@ s%@gdbflag@%$cc_g_flag%;
/@libflags@/ { s,@libflags@,$libflags,; };
/@W_FLAGS@/ { s/@W_FLAGS@/$W_FLAGS/; };
/@O_FLAGS@/ { s/@O_FLAGS@/$O_FLAGS/; };
/@I_PERL@/ { s,@I_PERL@,$I_PERL,; };
/@L_PERL@/ { s,@L_PERL@,$L_PERL,; };
/@PYINCLUDE@/ { s,@PYINCLUDE@,$incpython,; };
/@TCLINCLUDE@/ { s,@TCLINCLUDE@,$inctcl,; };
s|@MD5_O@|$MD5_O|;
s|@SHA_O@|$SHA_O|;
s%@oc@%$objcomment%;
s%@sz@%$sizecomment%;
s%@makejobs@%$makejobs%;
s/[ ]*\$//g;
" < src/Makefile.in >> src/Makefile || exit 1
@ -1333,19 +1435,26 @@ s|@UNALIGNED_MEM@|$UNALIGNED_MEM|;
" < src/config.h.in >> src/config.h
if [ "$install" = yes ]; then
make -C src energymech
make $makejobs -C src energymech
exit
fi
if [ "$compile" = yes ]; then
make -C src energymech
make $makejobs -C src energymech
exit
fi
echo ''
echo 'All done. You can now "make clean install"'
echo 'All done. You can now "make install"'
if [ ! "$cores" = 1 ]; then
echo "For speedy compiling, use \`\`make -j$cores''"
fi
echo ''
echo 'Submit your bugreports at https://github.com/MadCamel/energymech/issues'
echo ''
echo 'You have read the README file I hope?'
echo ''
# make: 7.962u 0.870s 0:08.52 103.6% 0+0k 0+0io 0pf+0w
# make -j4: 8.779u 1.069s 0:03.11 316.0% 0+0k 0+0io 0pf+0w
# make -j8: 8.977u 1.064s 0:02.92 343.4% 0+0k 0+0io 0pf+0w

View File

@ -31,6 +31,8 @@ WARNFLAG = @W_FLAGS@
OPTIMIZE = @O_FLAGS@
PYINCLUDE = @PYINCLUDE@
TCLINCLUDE = @TCLINCLUDE@
I_PERL = @I_PERL@
L_PERL = @L_PERL@
CFLAGS = $(PIPEFLAG) $(GDBFLAG) $(WARNFLAG) $(OPTIMIZE)
LFLAGS = $(PIPEFLAG) $(GDBFLAG)
@ -58,6 +60,8 @@ SRCFILES = alias.c auth.c bounce.c chanban.c channel.c core.c \
spy.c stats.c tcl.c telnet.c toybox.c trivia.c uptime.c urlcap.c \
user.c vars.c web.c
.PHONY: all clean mega-install mega mega-static test commands
all: $(INSTALLNAME)
#
@ -78,16 +82,16 @@ install: $(INSTALLNAME)
$(CHMOD) $(INSTALLMODE) $(INSTALLNAME)
$(MV) $(INSTALLNAME) $(INSTALLDIR)
clean: FORCE
clean:
$(RM) $(INSTALLNAME) gencmd mcmd.h usercombo.h core $(TESTFILES) $(OFILES)
$(INSTALLNAME): $(OFILES)
$(CROSS_COMPILE)$(CC) $(LFLAGS) -o $(INSTALLNAME) $(OFILES) $(LPROF) $(LIBS) $(LDSCRIPT)
$(CROSS_COMPILE)$(CC) $(LFLAGS) -o $(INSTALLNAME) $(OFILES) $(LPROF) $(LIBS) $(LDSCRIPT) $(L_PERL)
@oc@ $(CROSS_COMPILE)objcopy -R .note -R .comment $(INSTALLNAME)
@sz@ size $(INSTALLNAME)
$(INSTALLNAME)-static: $(OFILES)
$(CROSS_COMPILE)$(CC) $(LFLAGS) -o $(INSTALLNAME) $(OFILES) $(LPROF) $(LIBS) $(LDSCRIPT) -static
$(CROSS_COMPILE)$(CC) $(LFLAGS) -o $(INSTALLNAME) $(OFILES) $(LPROF) $(LIBS) $(LDSCRIPT) $(L_PERL) -static
@oc@ $(CROSS_COMPILE)objcopy -R .note -R .comment $(INSTALLNAME)
@sz@ size $(INSTALLNAME)
@ -103,12 +107,12 @@ mega-install: mega $(SRCFILES) $(INCS) usage.h
$(MV) $(INSTALLNAME) $(INSTALLDIR)
mega: $(SRCFILES) $(INCS) usage.h
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o $(INSTALLNAME) mega.c $(LPROF) $(LIBS) $(LDSCRIPT) $(PYINCLUDE) $(TCLINCLUDE)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o $(INSTALLNAME) mega.c $(LPROF) $(LIBS) $(LDSCRIPT) $(PYINCLUDE) $(TCLINCLUDE) $(I_PERL) $(L_PERL)
@oc@ $(CROSS_COMPILE)objcopy -R .note -R .comment $(INSTALLNAME)
@sz@ size $(INSTALLNAME)
mega-static: $(SRCFILES) $(INCS) usage.h
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o $(INSTALLNAME) mega.c $(LPROF) $(LIBS) $(LDSCRIPT) $(PYINCLUDE) $(TCLINCLUDE) -static
$(CROSS_COMPILE)$(CC) $(CFLAGS) -o $(INSTALLNAME) mega.c $(LPROF) $(LIBS) $(LDSCRIPT) $(PYINCLUDE) $(TCLINCLUDE) $(I_PERL) $(L_PERL) -static
@oc@ $(CROSS_COMPILE)objcopy -R .note -R .comment $(INSTALLNAME)
@sz@ size $(INSTALLNAME)
@ -203,7 +207,7 @@ parse.o: parse.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
perl.o: perl.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
$(CROSS_COMPILE)$(CC) $(CFLAGS) $(I_PERL) -c $< $(CPROF)
prot.o: prot.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
@ -265,4 +269,3 @@ md5/md5.o: md5/md5.c $(INCS)
sha/sha1.o: sha/sha1.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< -o $@ -Isha1 $(CPROF)
FORCE:

View File

@ -1238,7 +1238,7 @@ void debug_rawdns(void)
#endif /* RAWDNS */
#if defined(TCL) || defined(PYTHON)
#if defined(TCL) || defined(PYTHON) || defined(PERL)
#if 0
typedef struct

View File

@ -179,7 +179,7 @@ struct
* Level 70 == JOINLEVEL
*/
{ 0, "CYCLE", "do_cycle", 70 | CCPW | CAXS | ACCHAN },
{ 0, "FORGET", "do_forget", 70 | CCPW | CARGS },
{ 0, "FORGET", "do_forget", 70 | CCPW | CAXS | CARGS },
{ 0, "JOIN", "do_join", 70 | CCPW | CARGS },
{ 0, "KS", "do_kicksay", 70 | CCPW | REDIR | LBUF },
{ 0, "PART", "do_part", 70 | CCPW | CAXS | ACCHAN },
@ -251,6 +251,12 @@ struct
{ 0, "DEBUG", "do_debug", 100 | CCPW | GAXS },
{ 0, "CRASH", "do_crash", 100 | CCPW | GAXS },
#endif /* DEBUG */
#ifdef PERL
#ifdef PLEASE_HACK_MY_SHELL
{ 0, "PERL", "do_perl", 100 | CCPW | GAXS | CARGS },
#endif /* PLEASE_HACK_MY_SHELL */
{ 0, "PERLSCRIPT", "do_perlscript", 100 | CCPW | GAXS | CARGS },
#endif /* PERL */
#ifdef PYTHON
#ifdef PLEASE_HACK_MY_SHELL
{ 0, "PYTHON", "do_python", 100 | CCPW | GAXS | CARGS },

View File

@ -190,6 +190,10 @@ LS void netchanSuppress(BotNet *, char *) __page(CORE_SEG);
/* ons.c */
/* parse.c */
/* perl.c */
LS void do_perl(COMMAND_ARGS) __page(CMD1_SEG);
LS void do_perlscript(COMMAND_ARGS) __page(CMD1_SEG);
/* prot.c */
/* python.c */
/* redirect.c */

View File

@ -948,6 +948,9 @@ execve( ./energymech, argv = { ./energymech <NULL> <NULL> <NULL> <NULL> }, envp
else
to_file(1,"error: Missing argument for -p <string>\n");
_exit(0);
case 't':
startup = 666;
break;
case 'X':
debug_on_exit = TRUE;
break;
@ -1120,6 +1123,8 @@ execve( ./energymech, argv = { ./energymech <NULL> <NULL> <NULL> <NULL> }, envp
#endif /* DEBUG */
}
if (startup == 666)
exit(0);
startup = FALSE;
doit();
}

View File

@ -1,8 +1,8 @@
/*
EnergyMech, IRC bot software
Copyright (c) 2001-2009 proton
Copyright (c) 2001 MadCamel
Copyright (c) 2001-2018 proton
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -19,11 +19,17 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define PERL_C
#include "config.h"
#ifdef PERL
#ifdef __x86_64__
typedef __off64_t off64_t;
#define __off64_t_defined
#endif /* __x86_64__ */
#include "defines.h"
#include "structs.h"
#include "global.h"
@ -31,12 +37,12 @@
#include "text.h"
#include "mcmd.h"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "EXTERN.h"
#include "XSUB.h"
#include "perl.h"
PerlInterpreter *energymech_perl = NULL;
#define my_perl energymech_perl
/*
* parse_jump() translates from C to perl
@ -55,8 +61,8 @@ int perl_parse_jump(char *from, char *rest, Hook *hook)
args[1] = rest;
args[2] = NULL;
/* Call_argv returns the # of args returned from perl */
if (call_argv(Hook->self, G_EVAL|G_SCALAR, args) < 1)
/* call_argv returns the # of args returned from perl */
if (call_argv(hook->self, G_EVAL|G_SCALAR, args) < 1)
return(0);
SPAGAIN; /* Rehash stack, it's probably been clobbered */
@ -86,29 +92,23 @@ XS(XS_perl_parse_hook)
* but I don't know if it's safe to point directly in to perl
* space like that.
*/
if ((name = strdup(SvPV(ST(0), i)))) == NULL)
if ((name = SvPV_nolen(ST(0))) == NULL)
XSRETURN_EMPTY;
if ((sub = strdup(SvPV(ST(0), i)))) == NULL)
{
free(name);
if ((sub = SvPV_nolen(ST(0))) == NULL)
XSRETURN_EMPTY;
}
/*
* make a Hook struct and link it into the parse hook list
*/
set_mallocdoer(perl_parse_hook);
set_mallocdoer(XS_perl_parse_hook);
hook = (Hook*)Calloc(sizeof(Hook) + Strlen2(name,sub)); // sub is never NULL
hook->func = perl_parse_jump;
hook->next = hooklist;
hooklist = hook;
hook->command = Strcpy(hook->self,sub) + 1;
Strcpy(hook->command,name);
free(name);
free(sub);
hook->type.command = Strcpy(hook->self,sub) + 1;
Strcpy(hook->type.command,name);
/*
* return successful status to script
@ -126,7 +126,7 @@ void init_perl(void)
/*
* make parse_hook() callable from scripts
*/
newXS("mech::parse_hook", XS_perl_parse_hook, "mech");
newXS("mech::hook", XS_perl_parse_hook, "mech");
}
void do_perl(COMMAND_ARGS)
@ -134,6 +134,8 @@ void do_perl(COMMAND_ARGS)
/*
* call init_perl() if the perl interpreter isnt initialized yet
*/
if (energymech_perl == NULL)
init_perl();
/*
* call the perl interpreter with the content of *rest
@ -152,6 +154,8 @@ void do_perlscript(COMMAND_ARGS)
/*
* call init_perl() if the perl interpreter isnt initialized yet
*/
if (energymech_perl == NULL)
init_perl();
/*
* chop(&rest) for name of script filename and load it into the perl interpreter
@ -160,10 +164,10 @@ void do_perlscript(COMMAND_ARGS)
args[1] = chop(&rest);
/* FIXME: Trap parse errors */
perl_parse(energymech_perl, NULL, 1, argv, (char **)NULL);
perl_parse(energymech_perl, NULL, 1, args, (char **)NULL);
/* Call sub named Init, what should contain
* mech::perl_parse_hook("PRIVMSG", "yoink_privmsg");
* mech::hook("PRIVMSG", "yoink_privmsg");
* Note to self: Wouldn't it be better to pass subs by
* Reference(perl ver of pointer) instead of name?
* How the fsck do i do that?!
@ -173,7 +177,7 @@ void do_perlscript(COMMAND_ARGS)
{
STRLEN n_a;
to_user(from, "perl script %s failed to init: %s",
argv[1], SvPV(ERRSV, n_a));
args[1], SvPV(ERRSV, n_a));
}
/*
* be verbose about success or fail to the user

View File

@ -325,7 +325,7 @@ void trivia_no_answer(void)
char *random_question(char *triv_rand)
{
char *p;
char *p,tmpname[120];
off_t sz;
int fd,ifd;
int n;
@ -336,10 +336,22 @@ char *random_question(char *triv_rand)
} entry;
if ((fd = open(triv_qfile,O_RDONLY)) < 0)
if (STRCHR(triv_qfile,'/') || strlen(triv_qfile) > 100) // really bad filenames...
return(NULL);
Strcpy(triv_rand,triv_qfile);
Strcat(Strcpy(tmpname,"trivia/"),triv_qfile);
if ((fd = open(tmpname,O_RDONLY)) < 0)
#ifdef DEBUG
{
debug("(random_question) %s: %s\n",tmpname,strerror(errno));
return(NULL);
}
#else
return(NULL);
#endif /* DEBUG */
Strcpy(triv_rand,tmpname);
if ((p = STRCHR(triv_rand,'.')) == NULL)
p = STREND(triv_rand);
Strcpy(p,".index");

7
trivia/README Normal file
View File

@ -0,0 +1,7 @@
Trivia game files
trivia question file needs to be 1 line per question, each line in the form ``question*answer''
compile mkindex and run ``./mkindex <triviafile>'' to build the necessary index
put ``set qfile <triviafile>'' in your mechs config file, the mech will try to open ``trivia/<triviafile>'' when you start trivia