repo
string | commit
string | message
string | diff
string |
---|---|---|---|
higepon/spon
|
668575758fcac34fa147c8dd3a2576a02f7f2735
|
preliminary support for ikarus.
|
diff --git a/compat.ikarus.sls b/compat.ikarus.sls
new file mode 100644
index 0000000..50bfa24
--- /dev/null
+++ b/compat.ikarus.sls
@@ -0,0 +1,46 @@
+(library (spon compat)
+ (export current-implementation-name
+ command
+ file-copy
+ make-directory
+ make-symbolic-link
+ current-directory
+ )
+ (import (rnrs)
+ (spon config)
+ (only (ikarus) current-directory)
+ (ikarus ipc))
+
+ (define (current-implementation-name) "ikarus")
+
+ (define (command cmd . args)
+ (let-values (([pid p-stdin p-stdout p-stderr] (apply process cmd args)))
+ (zero? ; for now
+ (wstatus-exit-status
+ (cond ((quiet?)
+ (waitpid pid))
+ (else
+ (let ((p-message (transcoded-port p-stdout (native-transcoder)))
+ (p-error (transcoded-port p-stderr (native-transcoder))))
+ (let loop ((status #f))
+ (when (verbose?)
+ (let ((message (get-string-all p-message)))
+ (unless (eof-object? message)
+ (display message)
+ (put-string (current-output-port) message))))
+ (let ((err (get-string-all p-error)))
+ (unless (eof-object? err)
+ (put-string (current-error-port) err)))
+ (or status (loop (waitpid pid #f)))))))))))
+
+ ;; copied from compat.ypsilon.sls for now.
+ ;; must be refactor.
+ (define (file-copy src dst mode)
+ (command "install" "-m" (number->string mode 8) src dst))
+
+ (define (make-directory dir mode)
+ (command "install" "-m" (number->string mode 8) "-d" dir))
+
+ (define (make-symbolic-link target link)
+ (command "ln" "-sf" target link))
+ )
diff --git a/compat.sls b/compat.sls
index e18b8ef..91e2148 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,31 +1,33 @@
(library (spon compat)
(export current-implementation-name
command
file-copy
make-directory
make-symbolic-link
current-directory
)
(import (rnrs)
(spon config))
(define (current-implementation-name) "scheme")
;; -- command :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
- ;; When `verbose?' procedure (in the library (spon base)) returns #f,
+ ;; When `verbose?' procedure (in the library (spon config)) returns #f,
;; standard output of the command is discarded.
+ ;; When `silent?' procedure (also in the same library) returns #f,
+ ;; standard error of the command is discarded.
(define (command cmd . args)
(raise (condition
(make-implementation-restriction-violation)
(make-who-condition 'command)
(make-message-condition
(string-append
"Compatibility layer is not implemented. "
(string-titlecase system-name)
" seems to be not supported by your implementation. "
"Please consult the author of your implementation."))
(make-irritants-condition (cons cmd args)))))
)
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index c9efb1d..0b3feb1 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,46 +1,47 @@
(library (spon compat)
(export current-implementation-name
command
file-copy
make-directory
make-symbolic-link
current-directory
)
(import (rnrs)
(only (core)
current-directory
destructuring-bind
process
process-wait)
(spon config))
(define (current-implementation-name) "ypsilon")
(define (command cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(zero?
- (cond ((verbose?)
+ (cond ((quiet?)
+ (process-wait pid #f)) ; nohang = #t
+ ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
- (let ((message (get-string-all p-message)))
- (unless (eof-object? message)
- (put-string (current-output-port) message)))
+ (when (verbose?)
+ (let ((message (get-string-all p-message)))
+ (unless (eof-object? message)
+ (put-string (current-output-port) message))))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
- (or status (loop (process-wait pid #t)))))) ; nohang = #t
- (else
- (process-wait pid #f)))))) ; nohang = #f
+ (or status (loop (process-wait pid #t)))))))))) ; nohang = #f
(define (file-copy src dst mode)
(command "install" "-m" (number->string mode 8) src dst))
(define (make-directory dir mode)
(command "install" "-m" (number->string mode 8) "-d" dir))
(define (make-symbolic-link target link)
(command "ln" "-sf" target link))
) ;[end]
|
higepon/spon
|
112dfc9d00a06fbbd23d5033ac0ac38db6fe7fa4
|
support BSD sed.
|
diff --git a/install.sh b/install.sh
index 322cb30..e3594a6 100755
--- a/install.sh
+++ b/install.sh
@@ -1,58 +1,59 @@
#!/bin/sh
LN=/bin/ln
-SED=/bin/sed
+SED=/usr/bin/sed
INSTALL=/usr/bin/install
SCHEME_SCRIPT=${1:-mosh}
PREFIX=${2:-/usr/local}
SPON_URI=http://scheme-users.jp/spon
SPON_HOME=$PREFIX/share/spon
SPON_COMMAND=$PREFIX/bin/spon
SPON_LIB=$SPON_HOME/lib
SPON_DOC=$SPON_HOME/doc
SPON_SRC=$SPON_HOME/src
SPON_SHARE=$SPON_HOME/share
SPON_TMP=/tmp
-$SED -e "18 c (define download-uri \"$SPON_URI\")" \
- -e "19 c (define base-path \"$SPON_HOME\")" \
- -e "20 c (define command-path \"$SPON_COMMAND\")" \
- -e "21 c (define library-path \"$SPON_LIB\")" \
- -e "22 c (define document-path \"$SPON_DOC\")" \
- -e "23 c (define source-path \"$SPON_SRC\")" \
- -e "24 c (define share-path \"$SPON_SHARE\")" \
- -e "25 c (define temporary-path \"$SPON_TMP\")" \
+$SED -e "18,25c\\
+(define download-uri \"$SPON_URI\")\\
+(define base-path \"$SPON_HOME\")\\
+(define command-path \"$SPON_COMMAND\")\\
+(define library-path \"$SPON_LIB\")\\
+(define document-path \"$SPON_DOC\")\\
+(define source-path \"$SPON_SRC\")\\
+(define share-path \"$SPON_SHARE\")\\
+(define temporary-path \"$SPON_TMP\")" \
config.tmpl.sls > config.sls
echo -e "#!/bin/sh\nmosh $SPON_HOME/spon.ss \$*" > spon.mosh.sh
echo -e "#!/bin/sh\nypsilon $SPON_HOME/spon.ss \$*" > spon.ypsilon.sh
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_LIB
$INSTALL -v -m 755 -d $SPON_LIB/spon
$INSTALL -v -m 755 -d $SPON_DOC
$INSTALL -v -m 755 -d $SPON_SRC
for f in spon.mosh.sh spon.ypsilon.sh; do
$INSTALL -v -m 755 $f $SPON_HOME
done
for f in spon.ss setup.mosh.ss setup.ypsilon.ss package-list.sds; do
$INSTALL -v -m 644 $f $SPON_HOME
done
for f in sponrc.sample; do
$INSTALL -v -m 644 $f $SPON_DOC
done
for f in compat.sls compat.mosh.sls compat.ypsilon.sls config.sls tools.sls; do
$INSTALL -v -m 644 $f $SPON_LIB/spon
done
CWD=`pwd`
cd $SPON_LIB
$SCHEME_SCRIPT $SPON_HOME/setup.$SCHEME_SCRIPT.ss
cd $CWD
$LN -sf $SPON_HOME/spon.$SCHEME_SCRIPT.sh $SPON_COMMAND
|
higepon/spon
|
7bfc52f6175d72b8ab164f1e12c515d8f11d384c
|
refactor
|
diff --git a/tools.sls b/tools.sls
index c66a9f0..9bc11cd 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,337 +1,331 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
current-directory)
(import (rnrs)
(srfi :39)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (read-package-list)
(define (get-version alis)
(cond ((assq 'version alis)
=> (lambda (xs)
(and (= (length (cdr xs)) 3)
- (number? (cadr xs))
- (number? (caddr xs))
- (number? (cadddr xs))
- (make-version (cadr xs) (caddr xs) (cadddr xs)))))
+ (for-all number? (cdr xs))
+ (apply make-version (cdr xs)))))
(else #f)))
(let ((ht (make-eq-hashtable)))
(let ((file (format #f "~A/~A" base-path "package-list.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
- (let loop ((i (read in)))
- (unless (eof-object? i)
- (let ((name (car i))
- (version (get-version (cdr i)))
- (depends (cond ((assq 'depends (cdr i)) => cdr)
- (else #f)))
- (description (let ((d (assq 'description (cdr i))))
- (and d (apply string-append (cdr d)))))
- (status #f))
- (hashtable-set! ht name
- (make-pkg-info name version depends description status)))
- (loop (read in))))))))
+ (do ((i (read in) (read in)))
+ ((eof-object? i))
+ (let ((name (car i))
+ (version (get-version (cdr i)))
+ (depends (cond ((assq 'depends (cdr i)) => cdr)
+ (else #f)))
+ (description (let ((d (assq 'description (cdr i))))
+ (and d (apply string-append (cdr d)))))
+ (status #f))
+ (hashtable-set! ht name
+ (make-pkg-info name version depends description status))))))))
(let ((file (format #f "~A/~A" base-path "install.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
- (let loop ((i (read in)))
- (unless (eof-object? i)
- (let ((name (car i))
- (status (and (cadr i) #t))
- (version (get-version (cddr i))))
- (if (hashtable-contains? ht name)
- (let ((p (hashtable-ref ht name)))
- (pkg-info-status-set! p
- (make-pkg-stat status version))
- (hashtable-set! ht name p))
- (hashtable-set! ht name
- (make-pkg-info name #f #f #f
- (make-pkg-stat status version)))))
- (loop (read in))))))))
+ (do ((i (read in) (read in)))
+ ((eof-object? i))
+ (let ((name (car i))
+ (status (and (cadr i) #t))
+ (version (get-version (cddr i))))
+ (if (hashtable-contains? ht name)
+ (let ((p (hashtable-ref ht name)))
+ (pkg-info-status-set! p
+ (make-pkg-stat status version))
+ (hashtable-set! ht name p))
+ (hashtable-set! ht name
+ (make-pkg-info name #f #f #f
+ (make-pkg-stat status version))))))))))
ht))
(define (write-install-status pkg-ht)
(let ((file (format #f "~A/~A" base-path "install.sds")))
(call-with-output-file file
(lambda (out)
(let-values (((ks vs) (hashtable-entries pkg-ht)))
(vector-for-each
(lambda (key val)
(let ((stat (pkg-info-status val)))
(when (pkg-stat? stat)
(write (cons*
key (pkg-stat-status stat)
(if (version? (pkg-stat-version stat))
(list (version->list (pkg-stat-version stat)))
'()))
out)
(newline out))))
ks vs))))))
(define (version<? v1 v2)
(cond ((< (version-major v1) (version-major v2)) #t)
((> (version-major v1) (version-major v2)) #f)
(else
(cond ((< (version-minor v1) (version-minor v2)) #t)
((> (version-minor v1) (version-minor v2)) #f)
(else
(cond ((< (version-patch v1) (version-patch v2)) #t)
(else #f)))))))
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list 'version
(version-major version)
(version-minor version)
(version-patch version)))
(define (package->symbol p)
(cond
((symbol? p) p)
((string? p) (string->symbol p))
((pkg-info? p) (pkg-info-name p))
(else #f)))
(define (package->string p)
(cond
((symbol? p) (symbol->string p))
((string? p) p)
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p))
"-"
(version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
(else #f)))
(define (package-installed? p ht)
(cond
((pkg-info? p)
(let ((stat (pkg-info-status p)))
(if (pkg-stat? stat) (pkg-stat-status stat) stat)))
((symbol? p) (package-installed? (hashtable-ref ht p #f) ht))
((string? p) (package-installed? (string->symbol p) ht))
(else #f)))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(cmd-wget pkg-uri src-path)
#f
"Failed to download the package")
((format "Downloading signature: ~A ..." sig-uri)
(cmd-wget sig-uri src-path)
#f
"Failed to download the signature"))))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package for ~A ..." (string-upcase system-name))
(parameterize ((current-directory pkg-path))
(command impl install.ss (symbol->string mode)))
#f
(format "error in ~A" install.ss)))))
(define (setup package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(parameterize ((current-directory pkg-path))
(command impl
(if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)
(symbol->string mode)))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(define (install-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
- (if (package-installed? pi pkg-ht)
- #f
- (begin
- (when (pkg-info? pi)
- (let ((depends (pkg-info-depends pi)))
- (when depends
- (for-each (lambda (dep)
- (install-rec dep pkg-ht))
- depends))))
- (let* ((p (if (pkg-info? pi) pi package))
- (package-name (package->string p)))
- (let ((r (do-procs
- ((format "Installing ~A" package-name)
- (and (download p)
- (verify p)
- (decompress p)
- (initialize p 'install)
- (setup p 'install))
- (format "~A is successfully installed.~%" package-name)
- (format "~A install failed.~%" package-name)))))
- (when r
- (if (pkg-info? pi)
- (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
- (hashtable-set! pkg-ht
- (package->symbol package)
- (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
- r))))))
+ (and (not (package-installed? pi pkg-ht))
+ (begin
+ (when (pkg-info? pi)
+ (let ((depends (pkg-info-depends pi)))
+ (when depends
+ (for-each (lambda (dep)
+ (install-rec dep pkg-ht))
+ depends))))
+ (let* ((p (if (pkg-info? pi) pi package))
+ (package-name (package->string p)))
+ (let ((r (do-procs
+ ((format "Installing ~A" package-name)
+ (and (download p)
+ (verify p)
+ (decompress p)
+ (initialize p 'install)
+ (setup p 'install))
+ (format "~A is successfully installed.~%" package-name)
+ (format "~A install failed.~%" package-name)))))
+ (when r
+ (if (pkg-info? pi)
+ (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
+ (hashtable-set! pkg-ht
+ (package->symbol package)
+ (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
+ r))))))
(let ((pkg-ht (read-package-list)))
(if (package-installed? package pkg-ht)
(begin
(format #t "----> ~A is already installed.~%" (package->string package))
#f)
(let ((r (install-rec package pkg-ht)))
(write-install-status pkg-ht)
r))))
(define (update package)
(define (updatable? pi)
(and (pkg-info? pi)
(let ((stat (pkg-info-status pi)))
(and (pkg-stat? stat)
(version<? (pkg-stat-version stat) (pkg-info-version pi))))))
(define (update-rec package pkg-ht)
(let* ((pi (hashtable-ref pkg-ht (package->symbol package) #f))
(package-name (package->string pi)))
- (if (updatable? pi)
- (begin
- (let ((depends (pkg-info-depends pi)))
- (when depends
- (for-each (lambda (dep)
- (update-rec dep pkg-ht))
- depends)))
- (let ((r (do-procs
- ((format "Updating ~A ..." package-name)
- (and (download pi)
- (verify pi)
- (decompress pi)
- (initialize pi 'update)
- (setup pi 'update))
- (format "~A is successfully update.~%" package-name)
- (format "~A update failed.~%" package-name)))))
- (when r
- (if (pkg-info? pi)
- (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
- (hashtable-set! pkg-ht
- (package->symbol package)
- (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
- r))
- #f)))
+ (and (updatable? pi)
+ (begin
+ (let ((depends (pkg-info-depends pi)))
+ (when depends
+ (for-each (lambda (dep)
+ (update-rec dep pkg-ht))
+ depends)))
+ (let ((r (do-procs
+ ((format "Updating ~A ..." package-name)
+ (and (download pi)
+ (verify pi)
+ (decompress pi)
+ (initialize pi 'update)
+ (setup pi 'update))
+ (format "~A is successfully update.~%" package-name)
+ (format "~A update failed.~%" package-name)))))
+ (when r
+ (if (pkg-info? pi)
+ (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
+ (hashtable-set! pkg-ht
+ (package->symbol package)
+ (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
+ r)))))
(let ((pkg-ht (read-package-list)))
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (updatable? pi)
(let ((r (update-rec package pkg-ht)))
(write-install-status pkg-ht)
r)
(begin
(format #t "----> ~A can't update." (package->string package))
#f)))))
(define (uninstall package)
#f)
)
|
higepon/spon
|
ed219694887a20bb487ad134f9ead94db3ddfbec
|
fix up broken codes
|
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 3ad87be..51b50b7 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,48 +1,49 @@
(library (spon compat)
(export current-implementation-name
command
file-copy
make-directory
make-symbolic-link
current-directory
)
(import (rnrs)
+ (srfi :39)
(prefix (only (mosh) current-directory set-current-directory!) mosh:)
(only (mosh process) spawn waitpid pipe)
(spon config))
(define (current-implementation-name) "mosh")
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
(let-values ([(pid cin cout cerr) (spawn command args (list #f out out))])
(close-port out)
(close-port in)
(waitpid pid))))
(define (command cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
(define (file-copy src dst mode)
(command "install" "-m" (number->string mode 8) src dst))
(define (make-directory dir mode)
(command "install" "-m" (number->string mode 8) "-d" dir))
(define (make-symbolic-link target link)
(command "ln" "-sf" target link))
(define current-directory
(make-parameter (mosh:current-directory)
(lambda (val)
(mosh:set-current-directory! val)
val)))
)
diff --git a/tools.sls b/tools.sls
index f427384..c66a9f0 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,336 +1,337 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
current-directory)
(import (rnrs)
+ (srfi :39)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (read-package-list)
(define (get-version alis)
(cond ((assq 'version alis)
=> (lambda (xs)
(and (= (length (cdr xs)) 3)
- (number? (cadr ys))
- (number? (caddr ys))
- (number? (cadddr ys))
- (make-version (cadr ys) (caddr ys) (cadddr ys)))))
+ (number? (cadr xs))
+ (number? (caddr xs))
+ (number? (cadddr xs))
+ (make-version (cadr xs) (caddr xs) (cadddr xs)))))
(else #f)))
(let ((ht (make-eq-hashtable)))
(let ((file (format #f "~A/~A" base-path "package-list.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(version (get-version (cdr i)))
- (depends (cond ((d (assq 'depends (cdr i))) => cdr)
+ (depends (cond ((assq 'depends (cdr i)) => cdr)
(else #f)))
(description (let ((d (assq 'description (cdr i))))
(and d (apply string-append (cdr d)))))
(status #f))
(hashtable-set! ht name
(make-pkg-info name version depends description status)))
(loop (read in))))))))
(let ((file (format #f "~A/~A" base-path "install.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(status (and (cadr i) #t))
(version (get-version (cddr i))))
(if (hashtable-contains? ht name)
(let ((p (hashtable-ref ht name)))
(pkg-info-status-set! p
(make-pkg-stat status version))
(hashtable-set! ht name p))
(hashtable-set! ht name
(make-pkg-info name #f #f #f
(make-pkg-stat status version)))))
(loop (read in))))))))
ht))
(define (write-install-status pkg-ht)
(let ((file (format #f "~A/~A" base-path "install.sds")))
(call-with-output-file file
(lambda (out)
(let-values (((ks vs) (hashtable-entries pkg-ht)))
(vector-for-each
(lambda (key val)
(let ((stat (pkg-info-status val)))
(when (pkg-stat? stat)
(write (cons*
key (pkg-stat-status stat)
(if (version? (pkg-stat-version stat))
(list (version->list (pkg-stat-version stat)))
'()))
out)
(newline out))))
ks vs))))))
(define (version<? v1 v2)
(cond ((< (version-major v1) (version-major v2)) #t)
((> (version-major v1) (version-major v2)) #f)
(else
(cond ((< (version-minor v1) (version-minor v2)) #t)
((> (version-minor v1) (version-minor v2)) #f)
(else
(cond ((< (version-patch v1) (version-patch v2)) #t)
(else #f)))))))
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list 'version
(version-major version)
(version-minor version)
(version-patch version)))
(define (package->symbol p)
(cond
((symbol? p) p)
((string? p) (string->symbol p))
((pkg-info? p) (pkg-info-name p))
(else #f)))
(define (package->string p)
(cond
((symbol? p) (symbol->string p))
((string? p) p)
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p))
"-"
(version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
(else #f)))
(define (package-installed? p ht)
(cond
((pkg-info? p)
(let ((stat (pkg-info-status p)))
(if (pkg-stat? stat) (pkg-stat-status stat) stat)))
((symbol? p) (package-installed? (hashtable-ref ht p #f) ht))
((string? p) (package-installed? (string->symbol p) ht))
(else #f)))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(cmd-wget pkg-uri src-path)
#f
"Failed to download the package")
((format "Downloading signature: ~A ..." sig-uri)
(cmd-wget sig-uri src-path)
#f
"Failed to download the signature"))))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package for ~A ..." (string-upcase system-name))
(parameterize ((current-directory pkg-path))
(command impl install.ss (symbol->string mode)))
#f
(format "error in ~A" install.ss)))))
(define (setup package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(parameterize ((current-directory pkg-path))
(command impl
(if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)
(symbol->string mode)))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(define (install-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (package-installed? pi pkg-ht)
#f
(begin
(when (pkg-info? pi)
(let ((depends (pkg-info-depends pi)))
(when depends
(for-each (lambda (dep)
(install-rec dep pkg-ht))
depends))))
(let* ((p (if (pkg-info? pi) pi package))
(package-name (package->string p)))
(let ((r (do-procs
((format "Installing ~A" package-name)
(and (download p)
(verify p)
(decompress p)
(initialize p 'install)
(setup p 'install))
(format "~A is successfully installed.~%" package-name)
(format "~A install failed.~%" package-name)))))
(when r
(if (pkg-info? pi)
(pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
(hashtable-set! pkg-ht
(package->symbol package)
(make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))))))
(let ((pkg-ht (read-package-list)))
(if (package-installed? package pkg-ht)
(begin
(format #t "----> ~A is already installed.~%" (package->string package))
#f)
(let ((r (install-rec package pkg-ht)))
(write-install-status pkg-ht)
r))))
(define (update package)
(define (updatable? pi)
(and (pkg-info? pi)
(let ((stat (pkg-info-status pi)))
(and (pkg-stat? stat)
(version<? (pkg-stat-version stat) (pkg-info-version pi))))))
(define (update-rec package pkg-ht)
(let* ((pi (hashtable-ref pkg-ht (package->symbol package) #f))
(package-name (package->string pi)))
(if (updatable? pi)
(begin
(let ((depends (pkg-info-depends pi)))
(when depends
(for-each (lambda (dep)
(update-rec dep pkg-ht))
depends)))
(let ((r (do-procs
((format "Updating ~A ..." package-name)
(and (download pi)
(verify pi)
(decompress pi)
(initialize pi 'update)
(setup pi 'update))
(format "~A is successfully update.~%" package-name)
(format "~A update failed.~%" package-name)))))
(when r
(if (pkg-info? pi)
(pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
(hashtable-set! pkg-ht
(package->symbol package)
(make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))
#f)))
(let ((pkg-ht (read-package-list)))
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (updatable? pi)
(let ((r (update-rec package pkg-ht)))
(write-install-status pkg-ht)
r)
(begin
(format #t "----> ~A can't update." (package->string package))
#f)))))
(define (uninstall package)
#f)
)
|
higepon/spon
|
c06d227896b937819ae2a0d8da33a40e25a236fe
|
refactor
|
diff --git a/tools.sls b/tools.sls
index bac34cc..f427384 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,346 +1,336 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
current-directory)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
- (immutable v1 version-major)
- (immutable v2 version-minor)
- (immutable v3 version-patch)))
+ (immutable v1 version-major)
+ (immutable v2 version-minor)
+ (immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
- (immutable status pkg-stat-status)
- (immutable version pkg-stat-version)))
+ (immutable status pkg-stat-status)
+ (immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
- (immutable name pkg-info-name)
- (immutable version pkg-info-version)
- (immutable depends pkg-info-depends)
- (immutable description pkg-info-description)
- (mutable status pkg-info-status pkg-info-status-set!)))
+ (immutable name pkg-info-name)
+ (immutable version pkg-info-version)
+ (immutable depends pkg-info-depends)
+ (immutable description pkg-info-description)
+ (mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (read-package-list)
+ (define (get-version alis)
+ (cond ((assq 'version alis)
+ => (lambda (xs)
+ (and (= (length (cdr xs)) 3)
+ (number? (cadr ys))
+ (number? (caddr ys))
+ (number? (cadddr ys))
+ (make-version (cadr ys) (caddr ys) (cadddr ys)))))
+ (else #f)))
(let ((ht (make-eq-hashtable)))
(let ((file (format #f "~A/~A" base-path "package-list.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
- (version (let ((v (assq 'version (cdr i))))
- (and v
- (list? (cdr v))
- (= 3 (length (cdr v)))
- (number? (list-ref v 1))
- (number? (list-ref v 2))
- (number? (list-ref v 3))
- (make-version (list-ref v 1)
- (list-ref v 2)
- (list-ref v 3)))))
- (depends (let ((d (assq 'depends (cdr i))))
- (and d (cdr d))))
+ (version (get-version (cdr i)))
+ (depends (cond ((d (assq 'depends (cdr i))) => cdr)
+ (else #f)))
(description (let ((d (assq 'description (cdr i))))
- (and d (apply string-append (cdr d)))))
+ (and d (apply string-append (cdr d)))))
(status #f))
(hashtable-set! ht name
- (make-pkg-info name version depends description status)))
+ (make-pkg-info name version depends description status)))
(loop (read in))))))))
(let ((file (format #f "~A/~A" base-path "install.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
- (status (cond ((cadr i) #t)
- (else #f)))
- (version (let ((v (assq 'version (cddr i))))
- (and v
- (list? (cdr v))
- (= 3 (length (cdr v)))
- (number? (list-ref v 1))
- (number? (list-ref v 2))
- (number? (list-ref v 3))
- (make-version (list-ref v 1)
- (list-ref v 2)
- (list-ref v 3))))))
+ (status (and (cadr i) #t))
+ (version (get-version (cddr i))))
(if (hashtable-contains? ht name)
(let ((p (hashtable-ref ht name)))
(pkg-info-status-set! p
- (make-pkg-stat status version))
+ (make-pkg-stat status version))
(hashtable-set! ht name p))
(hashtable-set! ht name
- (make-pkg-info name #f #f #f
- (make-pkg-stat status version)))))
+ (make-pkg-info name #f #f #f
+ (make-pkg-stat status version)))))
(loop (read in))))))))
ht))
(define (write-install-status pkg-ht)
(let ((file (format #f "~A/~A" base-path "install.sds")))
(call-with-output-file file
(lambda (out)
(let-values (((ks vs) (hashtable-entries pkg-ht)))
(vector-for-each
- (lambda (key val)
- (let ((stat (pkg-info-status val)))
- (when (pkg-stat? stat)
- (if (version? (pkg-stat-version stat))
- (write (list key (pkg-stat-status stat)
- (version->list (pkg-stat-version stat))) out)
- (write (list key (pkg-stat-status stat)) out))
- (newline out))))
- ks vs))))))
+ (lambda (key val)
+ (let ((stat (pkg-info-status val)))
+ (when (pkg-stat? stat)
+ (write (cons*
+ key (pkg-stat-status stat)
+ (if (version? (pkg-stat-version stat))
+ (list (version->list (pkg-stat-version stat)))
+ '()))
+ out)
+ (newline out))))
+ ks vs))))))
(define (version<? v1 v2)
- (and (version? v1) (version? v2)
- (cond ((< (version-major v1) (version-major v2)) #t)
- ((> (version-major v1) (version-major v2)) #f)
- (else (cond ((< (version-minor v1) (version-minor v2)) #t)
- ((> (version-minor v1) (version-minor v2)) #f)
- (else (cond ((< (version-patch v1) (version-patch v2)) #t)
- ((> (version-patch v1) (version-patch v2)) #f)
- (else #f))))))))
+ (cond ((< (version-major v1) (version-major v2)) #t)
+ ((> (version-major v1) (version-major v2)) #f)
+ (else
+ (cond ((< (version-minor v1) (version-minor v2)) #t)
+ ((> (version-minor v1) (version-minor v2)) #f)
+ (else
+ (cond ((< (version-patch v1) (version-patch v2)) #t)
+ (else #f)))))))
(define (version->string version)
(string-append (number->string (version-major version))
- "." (number->string (version-minor version))
- "." (number->string (version-patch version))))
+ "." (number->string (version-minor version))
+ "." (number->string (version-patch version))))
(define (version->list version)
(list 'version
(version-major version)
(version-minor version)
(version-patch version)))
(define (package->symbol p)
(cond
- ((symbol? p) p)
- ((string? p) (string->symbol p))
- ((pkg-info? p) (pkg-info-name p))
- (else #f)))
+ ((symbol? p) p)
+ ((string? p) (string->symbol p))
+ ((pkg-info? p) (pkg-info-name p))
+ (else #f)))
(define (package->string p)
(cond
- ((symbol? p) (symbol->string p))
- ((string? p) p)
- ((pkg-info? p)
- (if (version? (pkg-info-version p))
- (string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
- (symbol->string (pkg-info-name p))))
- (else #f)))
+ ((symbol? p) (symbol->string p))
+ ((string? p) p)
+ ((pkg-info? p)
+ (if (version? (pkg-info-version p))
+ (string-append (symbol->string (pkg-info-name p))
+ "-"
+ (version->string (pkg-info-version p)))
+ (symbol->string (pkg-info-name p))))
+ (else #f)))
(define (package-installed? p ht)
(cond
- ((pkg-info? p)
- (let ((stat (pkg-info-status p)))
- (if (pkg-stat? stat) (pkg-stat-status stat) stat)))
- ((symbol? p) (package-installed? (hashtable-ref ht p #f) ht))
- ((string? p) (package-installed? (string->symbol p) ht))
- (else #f)))
+ ((pkg-info? p)
+ (let ((stat (pkg-info-status p)))
+ (if (pkg-stat? stat) (pkg-stat-status stat) stat)))
+ ((symbol? p) (package-installed? (hashtable-ref ht p #f) ht))
+ ((string? p) (package-installed? (string->symbol p) ht))
+ (else #f)))
(define (cmd-wget uri dir)
(or (apply command
- ((get-config) "wget")
- "-N" "-P" dir uri (if (quiet?) '("-q") '()))
+ ((get-config) "wget")
+ "-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
- (define (show-progress text)
- (unless (quiet?)
- (format #t "----> ~A" text)))
-
- (define (ok)
- (display " ok\n"))
-
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
- (show-progress (format "Downloading package: ~A ..." pkg-uri))
- (cmd-wget pkg-uri src-path)
- (ok)
- (show-progress (format "Downloading signature: ~A ..." sig-uri))
- (cmd-wget sig-uri src-path)
- (ok)))
+ (do-procs
+ ((format "Downloading package: ~A ..." pkg-uri)
+ (cmd-wget pkg-uri src-path)
+ #f
+ "Failed to download the package")
+ ((format "Downloading signature: ~A ..." sig-uri)
+ (cmd-wget sig-uri src-path)
+ #f
+ "Failed to download the signature"))))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
- ((format "Setup package to ~A ..." (string-upcase system-name))
+ ((format "Setup package for ~A ..." (string-upcase system-name))
(parameterize ((current-directory pkg-path))
(command impl install.ss (symbol->string mode)))
#f
(format "error in ~A" install.ss)))))
(define (setup package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(parameterize ((current-directory pkg-path))
(command impl
(if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)
(symbol->string mode)))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(define (install-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (package-installed? pi pkg-ht)
#f
(begin
(when (pkg-info? pi)
(let ((depends (pkg-info-depends pi)))
(when depends
- (let loop ((ls depends))
- (when (pair? ls)
- (install-rec (car ls) pkg-ht)
- (loop (cdr ls)))))))
- (let ((p (if (pkg-info? pi) pi package)))
- (let ((r (and (download p)
- (verify p)
- (decompress p)
- (initialize p 'install)
- (setup p 'install))))
- (unless (quiet?)
- (if r
- (format #t "----> ~A is successfully installed.~%" (package->string p))
- (format #t "----> ~A install failed.~%" (package->string p))))
+ (for-each (lambda (dep)
+ (install-rec dep pkg-ht))
+ depends))))
+ (let* ((p (if (pkg-info? pi) pi package))
+ (package-name (package->string p)))
+ (let ((r (do-procs
+ ((format "Installing ~A" package-name)
+ (and (download p)
+ (verify p)
+ (decompress p)
+ (initialize p 'install)
+ (setup p 'install))
+ (format "~A is successfully installed.~%" package-name)
+ (format "~A install failed.~%" package-name)))))
(when r
(if (pkg-info? pi)
- (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
- (hashtable-set! pkg-ht
- (package->symbol package)
- (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
+ (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
+ (hashtable-set! pkg-ht
+ (package->symbol package)
+ (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))))))
(let ((pkg-ht (read-package-list)))
(if (package-installed? package pkg-ht)
(begin
(format #t "----> ~A is already installed.~%" (package->string package))
#f)
(let ((r (install-rec package pkg-ht)))
(write-install-status pkg-ht)
r))))
(define (update package)
(define (updatable? pi)
(and (pkg-info? pi)
- (let ((stat (pkg-info-status pi)))
- (and (pkg-stat? stat)
- (version<? (pkg-stat-version stat) (pkg-info-version pi))))))
+ (let ((stat (pkg-info-status pi)))
+ (and (pkg-stat? stat)
+ (version<? (pkg-stat-version stat) (pkg-info-version pi))))))
(define (update-rec package pkg-ht)
- (let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
+ (let* ((pi (hashtable-ref pkg-ht (package->symbol package) #f))
+ (package-name (package->string pi)))
(if (updatable? pi)
- (begin
- (let ((depends (pkg-info-depends pi)))
- (when depends
- (let loop ((ls depends))
- (when (pair? ls)
- (update-rec (car ls) pkg-ht)
- (loop (cdr ls))))))
- (let ((r (and (download pi)
- (verify pi)
- (decompress pi)
- (initialize pi 'update)
- (setup pi 'update))))
- (unless (quiet?)
- (if r
- (format #t "----> ~A is successfully update.~%" (package->string pi))
- (format #t "----> ~A update failed.~%" (package->string pi))))
- (when r
- (if (pkg-info? pi)
- (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
- (hashtable-set! pkg-ht
- (package->symbol package)
- (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
- r))
- #f)))
+ (begin
+ (let ((depends (pkg-info-depends pi)))
+ (when depends
+ (for-each (lambda (dep)
+ (update-rec dep pkg-ht))
+ depends)))
+ (let ((r (do-procs
+ ((format "Updating ~A ..." package-name)
+ (and (download pi)
+ (verify pi)
+ (decompress pi)
+ (initialize pi 'update)
+ (setup pi 'update))
+ (format "~A is successfully update.~%" package-name)
+ (format "~A update failed.~%" package-name)))))
+ (when r
+ (if (pkg-info? pi)
+ (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
+ (hashtable-set! pkg-ht
+ (package->symbol package)
+ (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
+ r))
+ #f)))
(let ((pkg-ht (read-package-list)))
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (updatable? pi)
- (let ((r (update-rec package pkg-ht)))
- (write-install-status pkg-ht)
- r)
- (begin
- (format #t "----> ~A can't update." (package->string package))
- #f)))))
+ (let ((r (update-rec package pkg-ht)))
+ (write-install-status pkg-ht)
+ r)
+ (begin
+ (format #t "----> ~A can't update." (package->string package))
+ #f)))))
(define (uninstall package)
#f)
)
|
higepon/spon
|
07af3b91d380641e9c7a519e3dc944045a2df62b
|
parameterize current-directory.
|
diff --git a/compat.mosh.sls b/compat.mosh.sls
index b057f83..3ad87be 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,43 +1,48 @@
(library (spon compat)
(export current-implementation-name
command
file-copy
make-directory
make-symbolic-link
current-directory
- set-current-directory!)
+ )
(import (rnrs)
- (only (mosh) current-directory set-current-directory!)
+ (prefix (only (mosh) current-directory set-current-directory!) mosh:)
(only (mosh process) spawn waitpid pipe)
(spon config))
(define (current-implementation-name) "mosh")
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
(let-values ([(pid cin cout cerr) (spawn command args (list #f out out))])
(close-port out)
(close-port in)
(waitpid pid))))
(define (command cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
(define (file-copy src dst mode)
(command "install" "-m" (number->string mode 8) src dst))
(define (make-directory dir mode)
(command "install" "-m" (number->string mode 8) "-d" dir))
(define (make-symbolic-link target link)
(command "ln" "-sf" target link))
+ (define current-directory
+ (make-parameter (mosh:current-directory)
+ (lambda (val)
+ (mosh:set-current-directory! val)
+ val)))
)
diff --git a/compat.sls b/compat.sls
index 9cf786d..e18b8ef 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,31 +1,31 @@
(library (spon compat)
(export current-implementation-name
command
file-copy
make-directory
make-symbolic-link
current-directory
- set-current-directory!)
+ )
(import (rnrs)
(spon config))
(define (current-implementation-name) "scheme")
;; -- command :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
(define (command cmd . args)
(raise (condition
(make-implementation-restriction-violation)
(make-who-condition 'command)
(make-message-condition
(string-append
"Compatibility layer is not implemented. "
(string-titlecase system-name)
" seems to be not supported by your implementation. "
"Please consult the author of your implementation."))
(make-irritants-condition (cons cmd args)))))
)
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index 538fede..c9efb1d 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,49 +1,46 @@
(library (spon compat)
(export current-implementation-name
command
file-copy
make-directory
make-symbolic-link
current-directory
- set-current-directory!)
+ )
(import (rnrs)
(only (core)
current-directory
destructuring-bind
process
process-wait)
(spon config))
(define (current-implementation-name) "ypsilon")
(define (command cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(zero?
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
(or status (loop (process-wait pid #t)))))) ; nohang = #t
(else
(process-wait pid #f)))))) ; nohang = #f
(define (file-copy src dst mode)
(command "install" "-m" (number->string mode 8) src dst))
(define (make-directory dir mode)
(command "install" "-m" (number->string mode 8) "-d" dir))
(define (make-symbolic-link target link)
(command "ln" "-sf" target link))
- (define (set-current-directory! dir)
- (current-directory dir))
-
) ;[end]
diff --git a/spon.ss b/spon.ss
index 8068257..bbab39c 100644
--- a/spon.ss
+++ b/spon.ss
@@ -1,35 +1,35 @@
(import (rnrs)
(srfi :39)
(srfi :48)
(spon tools)
(spon config))
(define (main args)
(case (string->symbol (cadr args))
((install)
(cond
[(null? (cddr args))
(display (format "ERROR ~a: package name not specified\n" system-name)
(current-error-port))
(exit #f)]
[else
(parameterize ((verbose? #f))
(guard (exception
[(download-error? exception)
(format (current-error-port) "\n failed to download package ~a.\n" (download-error-uri exception))]
[else (raise exception)])
(cond
((install (caddr args))
(exit))
(else
(display (format "ERROR ~A: install failed\n" system-name)
(current-error-port))
(exit #f)))))]))
((use)
(let ((impl (caddr args)))
- (call-with-current-working-directory library-path
- (lambda () (command impl (string-append base-path "/setup." impl ".ss"))))
+ (parameterize ((current-directory library-path))
+ (command impl (string-append base-path "/setup." impl ".ss")))
(make-symbolic-link (string-append base-path "/spon." impl ".sh") command-path)))
(else (exit #f))))
(main (command-line))
diff --git a/tools.sls b/tools.sls
index 7f6177a..bac34cc 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,356 +1,346 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
- call-with-current-working-directory
- current-directory set-current-directory!)
+ current-directory)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
- (define (call-with-current-working-directory dir thunk)
- (let ((cwd (current-directory)))
- (dynamic-wind
- (lambda () (set-current-directory! dir))
- thunk
- (lambda () (set-current-directory! cwd)))))
-
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
(let ((file (format #f "~A/~A" base-path "package-list.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(version (let ((v (assq 'version (cdr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3)))))
(depends (let ((d (assq 'depends (cdr i))))
(and d (cdr d))))
(description (let ((d (assq 'description (cdr i))))
(and d (apply string-append (cdr d)))))
(status #f))
(hashtable-set! ht name
(make-pkg-info name version depends description status)))
(loop (read in))))))))
(let ((file (format #f "~A/~A" base-path "install.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(status (cond ((cadr i) #t)
(else #f)))
(version (let ((v (assq 'version (cddr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3))))))
(if (hashtable-contains? ht name)
(let ((p (hashtable-ref ht name)))
(pkg-info-status-set! p
(make-pkg-stat status version))
(hashtable-set! ht name p))
(hashtable-set! ht name
(make-pkg-info name #f #f #f
(make-pkg-stat status version)))))
(loop (read in))))))))
ht))
(define (write-install-status pkg-ht)
(let ((file (format #f "~A/~A" base-path "install.sds")))
(call-with-output-file file
(lambda (out)
(let-values (((ks vs) (hashtable-entries pkg-ht)))
(vector-for-each
(lambda (key val)
(let ((stat (pkg-info-status val)))
(when (pkg-stat? stat)
(if (version? (pkg-stat-version stat))
(write (list key (pkg-stat-status stat)
(version->list (pkg-stat-version stat))) out)
(write (list key (pkg-stat-status stat)) out))
(newline out))))
ks vs))))))
(define (version<? v1 v2)
(and (version? v1) (version? v2)
(cond ((< (version-major v1) (version-major v2)) #t)
((> (version-major v1) (version-major v2)) #f)
(else (cond ((< (version-minor v1) (version-minor v2)) #t)
((> (version-minor v1) (version-minor v2)) #f)
(else (cond ((< (version-patch v1) (version-patch v2)) #t)
((> (version-patch v1) (version-patch v2)) #f)
(else #f))))))))
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list 'version
(version-major version)
(version-minor version)
(version-patch version)))
(define (package->symbol p)
(cond
((symbol? p) p)
((string? p) (string->symbol p))
((pkg-info? p) (pkg-info-name p))
(else #f)))
(define (package->string p)
(cond
((symbol? p) (symbol->string p))
((string? p) p)
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
(else #f)))
(define (package-installed? p ht)
(cond
((pkg-info? p)
(let ((stat (pkg-info-status p)))
(if (pkg-stat? stat) (pkg-stat-status stat) stat)))
((symbol? p) (package-installed? (hashtable-ref ht p #f) ht))
((string? p) (package-installed? (string->symbol p) ht))
(else #f)))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
- (raise (make-download-error uri))))
+ (raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
- (call-with-current-working-directory pkg-path
- (lambda ()
- (command impl install.ss (symbol->string mode))))
+ (parameterize ((current-directory pkg-path))
+ (command impl install.ss (symbol->string mode)))
#f
(format "error in ~A" install.ss)))))
(define (setup package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
- (call-with-current-working-directory pkg-path
- (lambda ()
- (command impl
- (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)
- (symbol->string mode))))
+ (parameterize ((current-directory pkg-path))
+ (command impl
+ (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)
+ (symbol->string mode)))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(define (install-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (package-installed? pi pkg-ht)
#f
(begin
(when (pkg-info? pi)
(let ((depends (pkg-info-depends pi)))
(when depends
(let loop ((ls depends))
(when (pair? ls)
(install-rec (car ls) pkg-ht)
(loop (cdr ls)))))))
(let ((p (if (pkg-info? pi) pi package)))
(let ((r (and (download p)
(verify p)
(decompress p)
(initialize p 'install)
(setup p 'install))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" (package->string p))
(format #t "----> ~A install failed.~%" (package->string p))))
(when r
(if (pkg-info? pi)
(pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
(hashtable-set! pkg-ht
(package->symbol package)
(make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))))))
(let ((pkg-ht (read-package-list)))
(if (package-installed? package pkg-ht)
(begin
(format #t "----> ~A is already installed.~%" (package->string package))
#f)
(let ((r (install-rec package pkg-ht)))
(write-install-status pkg-ht)
r))))
(define (update package)
(define (updatable? pi)
(and (pkg-info? pi)
(let ((stat (pkg-info-status pi)))
(and (pkg-stat? stat)
(version<? (pkg-stat-version stat) (pkg-info-version pi))))))
(define (update-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (updatable? pi)
(begin
(let ((depends (pkg-info-depends pi)))
(when depends
(let loop ((ls depends))
(when (pair? ls)
(update-rec (car ls) pkg-ht)
(loop (cdr ls))))))
(let ((r (and (download pi)
(verify pi)
(decompress pi)
(initialize pi 'update)
(setup pi 'update))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully update.~%" (package->string pi))
(format #t "----> ~A update failed.~%" (package->string pi))))
(when r
(if (pkg-info? pi)
(pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
(hashtable-set! pkg-ht
(package->symbol package)
(make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))
#f)))
(let ((pkg-ht (read-package-list)))
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (updatable? pi)
(let ((r (update-rec package pkg-ht)))
(write-install-status pkg-ht)
r)
(begin
(format #t "----> ~A can't update." (package->string package))
#f)))))
(define (uninstall package)
#f)
)
|
higepon/spon
|
5177e12ae0215a75b45448daf37eedbb6f33e1b2
|
use dynamic-wind in call-with-current-working-directory.
|
diff --git a/tools.sls b/tools.sls
index 421b23b..7f6177a 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,355 +1,356 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (call-with-current-working-directory dir thunk)
(let ((cwd (current-directory)))
- (set-current-directory! dir)
- (let ((r (thunk)))
- (set-current-directory! cwd) r)))
+ (dynamic-wind
+ (lambda () (set-current-directory! dir))
+ thunk
+ (lambda () (set-current-directory! cwd)))))
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
(let ((file (format #f "~A/~A" base-path "package-list.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(version (let ((v (assq 'version (cdr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3)))))
(depends (let ((d (assq 'depends (cdr i))))
(and d (cdr d))))
(description (let ((d (assq 'description (cdr i))))
(and d (apply string-append (cdr d)))))
(status #f))
(hashtable-set! ht name
(make-pkg-info name version depends description status)))
(loop (read in))))))))
(let ((file (format #f "~A/~A" base-path "install.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(status (cond ((cadr i) #t)
(else #f)))
(version (let ((v (assq 'version (cddr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3))))))
(if (hashtable-contains? ht name)
(let ((p (hashtable-ref ht name)))
(pkg-info-status-set! p
(make-pkg-stat status version))
(hashtable-set! ht name p))
(hashtable-set! ht name
(make-pkg-info name #f #f #f
(make-pkg-stat status version)))))
(loop (read in))))))))
ht))
(define (write-install-status pkg-ht)
(let ((file (format #f "~A/~A" base-path "install.sds")))
(call-with-output-file file
(lambda (out)
(let-values (((ks vs) (hashtable-entries pkg-ht)))
(vector-for-each
(lambda (key val)
(let ((stat (pkg-info-status val)))
(when (pkg-stat? stat)
(if (version? (pkg-stat-version stat))
(write (list key (pkg-stat-status stat)
(version->list (pkg-stat-version stat))) out)
(write (list key (pkg-stat-status stat)) out))
(newline out))))
ks vs))))))
(define (version<? v1 v2)
(and (version? v1) (version? v2)
(cond ((< (version-major v1) (version-major v2)) #t)
((> (version-major v1) (version-major v2)) #f)
(else (cond ((< (version-minor v1) (version-minor v2)) #t)
((> (version-minor v1) (version-minor v2)) #f)
(else (cond ((< (version-patch v1) (version-patch v2)) #t)
((> (version-patch v1) (version-patch v2)) #f)
(else #f))))))))
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list 'version
(version-major version)
(version-minor version)
(version-patch version)))
(define (package->symbol p)
(cond
((symbol? p) p)
((string? p) (string->symbol p))
((pkg-info? p) (pkg-info-name p))
(else #f)))
(define (package->string p)
(cond
((symbol? p) (symbol->string p))
((string? p) p)
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
(else #f)))
(define (package-installed? p ht)
(cond
((pkg-info? p)
(let ((stat (pkg-info-status p)))
(if (pkg-stat? stat) (pkg-stat-status stat) stat)))
((symbol? p) (package-installed? (hashtable-ref ht p #f) ht))
((string? p) (package-installed? (string->symbol p) ht))
(else #f)))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
(lambda ()
(command impl install.ss (symbol->string mode))))
#f
(format "error in ~A" install.ss)))))
(define (setup package mode)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
(lambda ()
(command impl
(if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)
(symbol->string mode))))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(define (install-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (package-installed? pi pkg-ht)
#f
(begin
(when (pkg-info? pi)
(let ((depends (pkg-info-depends pi)))
(when depends
(let loop ((ls depends))
(when (pair? ls)
(install-rec (car ls) pkg-ht)
(loop (cdr ls)))))))
(let ((p (if (pkg-info? pi) pi package)))
(let ((r (and (download p)
(verify p)
(decompress p)
(initialize p 'install)
(setup p 'install))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" (package->string p))
(format #t "----> ~A install failed.~%" (package->string p))))
(when r
(if (pkg-info? pi)
(pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
(hashtable-set! pkg-ht
(package->symbol package)
(make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))))))
(let ((pkg-ht (read-package-list)))
(if (package-installed? package pkg-ht)
(begin
(format #t "----> ~A is already installed.~%" (package->string package))
#f)
(let ((r (install-rec package pkg-ht)))
(write-install-status pkg-ht)
r))))
(define (update package)
(define (updatable? pi)
(and (pkg-info? pi)
(let ((stat (pkg-info-status pi)))
(and (pkg-stat? stat)
(version<? (pkg-stat-version stat) (pkg-info-version pi))))))
(define (update-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (updatable? pi)
(begin
(let ((depends (pkg-info-depends pi)))
(when depends
(let loop ((ls depends))
(when (pair? ls)
(update-rec (car ls) pkg-ht)
(loop (cdr ls))))))
(let ((r (and (download pi)
(verify pi)
(decompress pi)
(initialize pi 'update)
(setup pi 'update))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully update.~%" (package->string pi))
(format #t "----> ~A update failed.~%" (package->string pi))))
(when r
(if (pkg-info? pi)
(pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
(hashtable-set! pkg-ht
(package->symbol package)
(make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))
#f)))
(let ((pkg-ht (read-package-list)))
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(if (updatable? pi)
(let ((r (update-rec package pkg-ht)))
(write-install-status pkg-ht)
r)
(begin
(format #t "----> ~A can't update." (package->string package))
#f)))))
(define (uninstall package)
#f)
)
|
higepon/spon
|
8b2bc092b4357b7003563b7cfc8f6dc5f8b47036
|
added 'update' proc.
|
diff --git a/tools.sls b/tools.sls
index 694f0fc..9821a04 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,294 +1,338 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (call-with-current-working-directory dir thunk)
(let ((cwd (current-directory)))
(set-current-directory! dir)
(let ((r (thunk)))
(set-current-directory! cwd) r)))
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
(let ((file (format #f "~A/~A" base-path "package-list.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(version (let ((v (assq 'version (cdr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3)))))
(depends (let ((d (assq 'depends (cdr i))))
(and d (cdr d))))
(description (let ((d (assq 'description (cdr i))))
(and d (apply string-append (cdr d)))))
(status #f))
(hashtable-set! ht name
(make-pkg-info name version depends description status)))
(loop (read in))))))))
(let ((file (format #f "~A/~A" base-path "install.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(status (cond ((cadr i) #t)
(else #f)))
(version (let ((v (assq 'version (cddr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3))))))
(if (hashtable-contains? ht name)
(let ((p (hashtable-ref ht name)))
(pkg-info-status-set! p
(make-pkg-stat status version))
(hashtable-set! ht name p))
(hashtable-set! ht name
(make-pkg-info name #f #f #f
(make-pkg-stat status version)))))
(loop (read in))))))))
ht))
(define (write-install-status pkg-ht)
(let ((file (format #f "~A/~A" base-path "install.sds")))
(call-with-output-file file
(lambda (out)
(let-values (((ks vs) (hashtable-entries pkg-ht)))
(vector-for-each
(lambda (key val)
(let ((stat (pkg-info-status val)))
- (if (pkg-stat? stat)
+ (when (pkg-stat? stat)
(if (version? (pkg-stat-version stat))
(write (list key (pkg-stat-status stat)
(version->list (pkg-stat-version stat))) out)
(write (list key (pkg-stat-status stat)) out))
- (write (list key stat) out))
- (newline out)))
+ (newline out))))
ks vs))))))
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list 'version
(version-major version)
(version-minor version)
(version-patch version)))
(define (package->symbol p)
(cond
((symbol? p) p)
((string? p) (string->symbol p))
((pkg-info? p) (pkg-info-name p))
(else #f)))
(define (package->string p)
(cond
((symbol? p) (symbol->string p))
((string? p) p)
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
(else #f)))
(define (package-installed? ht p)
(cond
((pkg-info? p)
(let ((stat (pkg-info-status p)))
(if (pkg-stat? stat) (pkg-stat-status stat) stat)))
((symbol? p) (package-installed? ht (hashtable-ref ht p #f)))
((string? p) (package-installed? ht (string->symbol p)))
(else #f)))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
(lambda () (command impl install.ss)))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
(lambda () (command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss))))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(define (install-rec package pkg-ht)
(let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
- (when pi
+ (when (pkg-info? pi)
(let ((depends (pkg-info-depends pi)))
(when depends
(let loop ((ls depends))
(when (pair? ls)
(unless (package-installed? (car ls))
(install-rec (car ls) pkg-ht))
(loop (cdr ls)))))))
(let ((p (if (pkg-info? pi) pi package)))
(let ((r (and (download p)
(verify p)
(decompress p)
(initialize p)
(setup p))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" (package->string p))
(format #t "----> ~A install failed.~%" (package->string p))))
(when r
(if (pkg-info? pi)
(pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
(hashtable-set! pkg-ht
(package->symbol package)
(make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
- r))))
+ r))))
(let ((pkg-ht (read-package-list)))
(if (package-installed? pkg-ht package)
(begin
(format #t "----> ~A is already installed.~%" (package->string package))
#f)
(let ((r (install-rec package pkg-ht)))
(write-install-status pkg-ht)
r))))
+
+ (define (update package)
+ (define (updatable? pi)
+ (and (pkg-info? pi)
+ (let ((stat (pkg-info-status pi)))
+ (and (pkg-stat? stat)
+ (version<? (pkg-stat-version stat) (pkg-info-version pi))))))
+ (define (update-rec package pkg-ht)
+ (let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
+ (if (updatable? pi)
+ (begin
+ (let ((depends (pkg-info-depends pi)))
+ (when depends
+ (let loop ((ls depends))
+ (and (pair? ls)
+ (update-rec (car ls) pkg-ht)))))
+ (let ((r (and (download pi)
+ (verify pi)
+ (decompress pi)
+ (initialize pi)
+ (setup pi 'update))))
+ (unless (quiet?)
+ (if r
+ (format #t "----> ~A is successfully update.~%" (package->string pi))
+ (format #t "----> ~A update failed.~%" (package->string pi))))
+ (when r
+ (if (pkg-info? pi)
+ (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
+ (hashtable-set! pkg-ht
+ (package->symbol package)
+ (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
+ r))
+ #f)))
+ (let ((pkg-ht (read-package-list)))
+ (let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
+ (if (updatable? pi)
+ (let ((r (update-red package pkg-ht)))
+ (write-install-status pkg-ht)
+ r)
+ (begin
+ (format #t "----> ~A can't update." (package->string package))
+ #f)))))
+
+ (define (uninstall package)
+ #f)
)
|
higepon/spon
|
93a2d7218b95a6176e339efc178c4bcea952b2be
|
added 'write-install-status' proc.
|
diff --git a/tools.sls b/tools.sls
index 59c57a3..694f0fc 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,271 +1,294 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (call-with-current-working-directory dir thunk)
(let ((cwd (current-directory)))
(set-current-directory! dir)
(let ((r (thunk)))
(set-current-directory! cwd) r)))
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
(let ((file (format #f "~A/~A" base-path "package-list.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(version (let ((v (assq 'version (cdr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3)))))
(depends (let ((d (assq 'depends (cdr i))))
(and d (cdr d))))
(description (let ((d (assq 'description (cdr i))))
(and d (apply string-append (cdr d)))))
(status #f))
(hashtable-set! ht name
(make-pkg-info name version depends description status)))
(loop (read in))))))))
(let ((file (format #f "~A/~A" base-path "install.sds")))
(when (file-exists? file)
(call-with-input-file file
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(status (cond ((cadr i) #t)
(else #f)))
(version (let ((v (assq 'version (cddr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3))))))
(if (hashtable-contains? ht name)
(let ((p (hashtable-ref ht name)))
(pkg-info-status-set! p
(make-pkg-stat status version))
(hashtable-set! ht name p))
(hashtable-set! ht name
(make-pkg-info name #f #f #f
(make-pkg-stat status version)))))
(loop (read in))))))))
ht))
+ (define (write-install-status pkg-ht)
+ (let ((file (format #f "~A/~A" base-path "install.sds")))
+ (call-with-output-file file
+ (lambda (out)
+ (let-values (((ks vs) (hashtable-entries pkg-ht)))
+ (vector-for-each
+ (lambda (key val)
+ (let ((stat (pkg-info-status val)))
+ (if (pkg-stat? stat)
+ (if (version? (pkg-stat-version stat))
+ (write (list key (pkg-stat-status stat)
+ (version->list (pkg-stat-version stat))) out)
+ (write (list key (pkg-stat-status stat)) out))
+ (write (list key stat) out))
+ (newline out)))
+ ks vs))))))
+
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list 'version
(version-major version)
(version-minor version)
(version-patch version)))
(define (package->symbol p)
(cond
((symbol? p) p)
((string? p) (string->symbol p))
((pkg-info? p) (pkg-info-name p))
(else #f)))
(define (package->string p)
(cond
((symbol? p) (symbol->string p))
((string? p) p)
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
(else #f)))
(define (package-installed? ht p)
(cond
- ((pkg-info? p) (pkg-stat-status (pkg-info-status p)))
+ ((pkg-info? p)
+ (let ((stat (pkg-info-status p)))
+ (if (pkg-stat? stat) (pkg-stat-status stat) stat)))
((symbol? p) (package-installed? ht (hashtable-ref ht p #f)))
((string? p) (package-installed? ht (string->symbol p)))
(else #f)))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
(lambda () (command impl install.ss)))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
(lambda () (command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss))))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
+ (define (install-rec package pkg-ht)
+ (let ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
+ (when pi
+ (let ((depends (pkg-info-depends pi)))
+ (when depends
+ (let loop ((ls depends))
+ (when (pair? ls)
+ (unless (package-installed? (car ls))
+ (install-rec (car ls) pkg-ht))
+ (loop (cdr ls)))))))
+ (let ((p (if (pkg-info? pi) pi package)))
+ (let ((r (and (download p)
+ (verify p)
+ (decompress p)
+ (initialize p)
+ (setup p))))
+ (unless (quiet?)
+ (if r
+ (format #t "----> ~A is successfully installed.~%" (package->string p))
+ (format #t "----> ~A install failed.~%" (package->string p))))
+ (when r
+ (if (pkg-info? pi)
+ (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
+ (hashtable-set! pkg-ht
+ (package->symbol package)
+ (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
+ r))))
(let ((pkg-ht (read-package-list)))
(if (package-installed? pkg-ht package)
(begin
(format #t "----> ~A is already installed.~%" (package->string package))
#f)
- (let install ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
- (when pi
- (let ((depends (pkg-info-depends pi)))
- (when depends
- (let loop ((ls depends))
- (when (pair? ls)
- (let ((pi (hashtable-ref pkg-ht (car ls) #f)))
- (unless (package-installed? pi) (install pi)))
- (loop (cdr ls)))))))
- (let ((p (if (pkg-info? pi) pi package)))
- (let ((r (and (download p)
- (verify p)
- (decompress p)
- (initialize p)
- (setup p))))
- (unless (quiet?)
- (if r
- (format #t "----> ~A is successfully installed.~%" (package->string p))
- (format #t "----> ~A install failed.~%" (package->string p))))
- (when r
- (if (pkg-info? pi)
- (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
- (hashtable-set! pkg-ht
- (package->symbol package)
- (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
- r))))))
+ (let ((r (install-rec package pkg-ht)))
+ (write-install-status pkg-ht)
+ r))))
)
|
higepon/spon
|
55de0c842c6849c4a321a37e10bb7569b4661750
|
fixed install proc.
|
diff --git a/tools.sls b/tools.sls
index 009d91d..59c57a3 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,263 +1,271 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (call-with-current-working-directory dir thunk)
(let ((cwd (current-directory)))
(set-current-directory! dir)
(let ((r (thunk)))
(set-current-directory! cwd) r)))
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
- (call-with-input-file
- (format #f "~A/~A" base-path "package-list.sds")
- (lambda (in)
- (let loop ((i (read in)))
- (unless (eof-object? i)
- (let ((name (car i))
- (version (let ((v (assq 'version (cdr i))))
- (and v
- (list? (cdr v))
- (= 3 (length (cdr v)))
- (number? (list-ref v 1))
- (number? (list-ref v 2))
- (number? (list-ref v 3))
- (make-version (list-ref v 1)
- (list-ref v 2)
- (list-ref v 3)))))
- (depends (let ((d (assq 'depends (cdr i))))
- (and d (cdr d))))
- (description (let ((d (assq 'description (cdr i))))
- (and d (apply string-append (cdr d)))))
- (status #f))
- (hashtable-set! ht name
- (make-pkg-info name version depends description status)))
- (loop (read in))))))
- (call-with-input-file
- (format #f "~A/~A" base-path "install.sds")
- (lambda (in)
- (let loop ((i (read in)))
- (unless (eof-object? i)
- (let ((name (car i))
- (status (cond ((cadr i) #t)
- (else #f)))
- (version (let ((v (assq 'version (cddr i))))
- (and v
- (list? (cdr v))
- (= 3 (length (cdr v)))
- (number? (list-ref v 1))
- (number? (list-ref v 2))
- (number? (list-ref v 3))
- (make-version (list-ref v 1)
- (list-ref v 2)
- (list-ref v 3))))))
- (if (hashtable-contains? ht name)
- (let ((p (hashtable-ref ht name)))
- (pkg-info-status-set! p
- (make-pkg-stat status version))
- (hashtable-set! ht name p))
+ (let ((file (format #f "~A/~A" base-path "package-list.sds")))
+ (when (file-exists? file)
+ (call-with-input-file file
+ (lambda (in)
+ (let loop ((i (read in)))
+ (unless (eof-object? i)
+ (let ((name (car i))
+ (version (let ((v (assq 'version (cdr i))))
+ (and v
+ (list? (cdr v))
+ (= 3 (length (cdr v)))
+ (number? (list-ref v 1))
+ (number? (list-ref v 2))
+ (number? (list-ref v 3))
+ (make-version (list-ref v 1)
+ (list-ref v 2)
+ (list-ref v 3)))))
+ (depends (let ((d (assq 'depends (cdr i))))
+ (and d (cdr d))))
+ (description (let ((d (assq 'description (cdr i))))
+ (and d (apply string-append (cdr d)))))
+ (status #f))
(hashtable-set! ht name
- (make-pkg-info name #f #f #f
- (make-pkg-stat status version)))))
- (loop (read in))))))
+ (make-pkg-info name version depends description status)))
+ (loop (read in))))))))
+ (let ((file (format #f "~A/~A" base-path "install.sds")))
+ (when (file-exists? file)
+ (call-with-input-file file
+ (lambda (in)
+ (let loop ((i (read in)))
+ (unless (eof-object? i)
+ (let ((name (car i))
+ (status (cond ((cadr i) #t)
+ (else #f)))
+ (version (let ((v (assq 'version (cddr i))))
+ (and v
+ (list? (cdr v))
+ (= 3 (length (cdr v)))
+ (number? (list-ref v 1))
+ (number? (list-ref v 2))
+ (number? (list-ref v 3))
+ (make-version (list-ref v 1)
+ (list-ref v 2)
+ (list-ref v 3))))))
+ (if (hashtable-contains? ht name)
+ (let ((p (hashtable-ref ht name)))
+ (pkg-info-status-set! p
+ (make-pkg-stat status version))
+ (hashtable-set! ht name p))
+ (hashtable-set! ht name
+ (make-pkg-info name #f #f #f
+ (make-pkg-stat status version)))))
+ (loop (read in))))))))
ht))
- (define (get-pkg-info)
- (let ((ht #f))
- (lambda (package)
- (unless ht
- (set! ht (read-package-list)))
- (hashtable-ref ht package #f))))
-
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
- (list (version-major version)
+ (list 'version
+ (version-major version)
(version-minor version)
(version-patch version)))
+ (define (package->symbol p)
+ (cond
+ ((symbol? p) p)
+ ((string? p) (string->symbol p))
+ ((pkg-info? p) (pkg-info-name p))
+ (else #f)))
+
(define (package->string p)
(cond
+ ((symbol? p) (symbol->string p))
+ ((string? p) p)
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
- ((symbol? p) (symbol->string p))
- ((string? p) p)
(else #f)))
- (define (package-installed? p)
+ (define (package-installed? ht p)
(cond
- ((pkg-info? p)
- (pkg-stat-status (pkg-info-status p)))
- ((symbol? p)
- (package-installed? ((get-pkg-info) p)))
- ((string? p)
- (package-installed? ((get-pkg-info) (string->symbol p))))
+ ((pkg-info? p) (pkg-stat-status (pkg-info-status p)))
+ ((symbol? p) (package-installed? ht (hashtable-ref ht p #f)))
+ ((string? p) (package-installed? ht (string->symbol p)))
(else #f)))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
(lambda () (command impl install.ss)))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
(lambda () (command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss))))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
- (if (package-installed? package)
- (format #t "----> ~A is already installed.~%" (package->string package))
- (let ((pkg-info (get-pkg-info)))
- (let loop ((pi (pkg-info package)))
+ (let ((pkg-ht (read-package-list)))
+ (if (package-installed? pkg-ht package)
+ (begin
+ (format #t "----> ~A is already installed.~%" (package->string package))
+ #f)
+ (let install ((pi (hashtable-ref pkg-ht (package->symbol package) #f)))
(when pi
(let ((depends (pkg-info-depends pi)))
(when depends
- (for-each
- (lambda (p)
- (let ((pi (pkg-info p)))
- (unless (package-installed? pi) (loop pi))))
- depends))))
+ (let loop ((ls depends))
+ (when (pair? ls)
+ (let ((pi (hashtable-ref pkg-ht (car ls) #f)))
+ (unless (package-installed? pi) (install pi)))
+ (loop (cdr ls)))))))
(let ((p (if (pkg-info? pi) pi package)))
(let ((r (and (download p)
(verify p)
(decompress p)
(initialize p)
(setup p))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" (package->string p))
(format #t "----> ~A install failed.~%" (package->string p))))
+ (when r
+ (if (pkg-info? pi)
+ (pkg-info-status-set! pi (make-pkg-stat #t (pkg-info-version pi)))
+ (hashtable-set! pkg-ht
+ (package->symbol package)
+ (make-pkg-info package #f #f #f (make-pkg-stat #t #f)))))
r))))))
)
|
higepon/spon
|
9119ec63bf116f83ebf324c438eb2667d5a0799f
|
install depends.
|
diff --git a/tools.sls b/tools.sls
index 322224e..009d91d 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,240 +1,263 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
(immutable status pkg-stat-status)
(immutable version pkg-stat-version)))
(define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
(immutable name pkg-info-name)
(immutable version pkg-info-version)
(immutable depends pkg-info-depends)
(immutable description pkg-info-description)
(mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (call-with-current-working-directory dir thunk)
(let ((cwd (current-directory)))
(set-current-directory! dir)
(let ((r (thunk)))
(set-current-directory! cwd) r)))
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
(call-with-input-file
(format #f "~A/~A" base-path "package-list.sds")
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(version (let ((v (assq 'version (cdr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3)))))
(depends (let ((d (assq 'depends (cdr i))))
(and d (cdr d))))
(description (let ((d (assq 'description (cdr i))))
(and d (apply string-append (cdr d)))))
(status #f))
(hashtable-set! ht name
(make-pkg-info name version depends description status)))
(loop (read in))))))
(call-with-input-file
(format #f "~A/~A" base-path "install.sds")
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(status (cond ((cadr i) #t)
(else #f)))
(version (let ((v (assq 'version (cddr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3))))))
(if (hashtable-contains? ht name)
(let ((p (hashtable-ref ht name)))
(pkg-info-status-set! p
(make-pkg-stat status version))
(hashtable-set! ht name p))
(hashtable-set! ht name
(make-pkg-info name #f #f #f
(make-pkg-stat status version)))))
(loop (read in))))))
ht))
(define (get-pkg-info)
(let ((ht #f))
(lambda (package)
(unless ht
(set! ht (read-package-list)))
(hashtable-ref ht package #f))))
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list (version-major version)
(version-minor version)
(version-patch version)))
(define (package->string p)
(cond
((pkg-info? p)
(if (version? (pkg-info-version p))
(string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
(symbol->string (pkg-info-name p))))
((symbol? p) (symbol->string p))
((string? p) p)
(else #f)))
+ (define (package-installed? p)
+ (cond
+ ((pkg-info? p)
+ (pkg-stat-status (pkg-info-status p)))
+ ((symbol? p)
+ (package-installed? ((get-pkg-info) p)))
+ ((string? p)
+ (package-installed? ((get-pkg-info) (string->symbol p))))
+ (else #f)))
+
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
- (pkg-uri (format "~A/~A.tar.gz" download-uri package))
+ (pkg-uri (format "~A/~A.tar.gz" download-uri (package->string package)))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
- (pkg-file (format "~A/~A.tar.gz" src-path package))
+ (pkg-file (format "~A/~A.tar.gz" src-path (package->string package)))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
- (pkg-file (format "~A/~A.tar.gz" src-path package)))
+ (pkg-file (format "~A/~A.tar.gz" src-path (package->string package))))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
- (pkg-path (format "~A/~A" source-path package))
+ (pkg-path (format "~A/~A" source-path (package->string package)))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
(lambda () (command impl install.ss)))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
- (pkg-path (format "~A/~A" source-path package))
+ (pkg-path (format "~A/~A" source-path (package->string package)))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
(lambda () (command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss))))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
- (let ((r (and (download package)
- (verify package)
- (decompress package)
- (initialize package)
- (setup package))))
- (unless (quiet?)
- (if r
- (format #t "----> ~A is successfully installed.~%" package)
- (format #t "----> ~A install failed.~%" package)))
- r))
+ (if (package-installed? package)
+ (format #t "----> ~A is already installed.~%" (package->string package))
+ (let ((pkg-info (get-pkg-info)))
+ (let loop ((pi (pkg-info package)))
+ (when pi
+ (let ((depends (pkg-info-depends pi)))
+ (when depends
+ (for-each
+ (lambda (p)
+ (let ((pi (pkg-info p)))
+ (unless (package-installed? pi) (loop pi))))
+ depends))))
+ (let ((p (if (pkg-info? pi) pi package)))
+ (let ((r (and (download p)
+ (verify p)
+ (decompress p)
+ (initialize p)
+ (setup p))))
+ (unless (quiet?)
+ (if r
+ (format #t "----> ~A is successfully installed.~%" (package->string p))
+ (format #t "----> ~A install failed.~%" (package->string p))))
+ r))))))
)
|
higepon/spon
|
4422bff5e71a6741a71cb444335454ef6fc5d1d3
|
fix 'pkg-info' record. and remove 'insinfo' record.
|
diff --git a/spon.ss b/spon.ss
index 7b66cc9..8068257 100644
--- a/spon.ss
+++ b/spon.ss
@@ -1,35 +1,35 @@
(import (rnrs)
(srfi :39)
(srfi :48)
(spon tools)
(spon config))
(define (main args)
(case (string->symbol (cadr args))
((install)
(cond
[(null? (cddr args))
(display (format "ERROR ~a: package name not specified\n" system-name)
(current-error-port))
(exit #f)]
[else
(parameterize ((verbose? #f))
(guard (exception
[(download-error? exception)
(format (current-error-port) "\n failed to download package ~a.\n" (download-error-uri exception))]
[else (raise exception)])
(cond
((install (caddr args))
(exit))
(else
(display (format "ERROR ~A: install failed\n" system-name)
(current-error-port))
(exit #f)))))]))
((use)
(let ((impl (caddr args)))
(call-with-current-working-directory library-path
- (command impl (string-append base-path "/setup." impl ".ss")))
+ (lambda () (command impl (string-append base-path "/setup." impl ".ss"))))
(make-symbolic-link (string-append base-path "/spon." impl ".sh") command-path)))
(else (exit #f))))
(main (command-line))
diff --git a/tools.sls b/tools.sls
index c77429a..322224e 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,236 +1,240 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
- (define-record-type (pkginfo make-pkginfo pkginfo?)
+ (define-record-type (pkg-stat make-pkg-stat pkg-stat?)
(fields
- (immutable name package-name)
- (immutable version package-version)
- (immutable depends package-depends)
- (immutable description package-description)))
+ (immutable status pkg-stat-status)
+ (immutable version pkg-stat-version)))
- (define-record-type (insinfo make-insinfo insinfo?)
+ (define-record-type (pkg-info make-pkg-info pkg-info?)
(fields
- (immutable name insinfo-name)
- (immutable version insinfo-version)
- (immutable status insinfo-status)))
-
- (define-syntax call-with-current-working-directory
- (syntax-rules ()
- ((_ dir proc)
- (let ((cwd (current-directory)))
- (set-current-directory! dir)
- (let ((r proc))
- (set-current-directory! cwd) r)))))
+ (immutable name pkg-info-name)
+ (immutable version pkg-info-version)
+ (immutable depends pkg-info-depends)
+ (immutable description pkg-info-description)
+ (mutable status pkg-info-status pkg-info-status-set!)))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
+ (define (call-with-current-working-directory dir thunk)
+ (let ((cwd (current-directory)))
+ (set-current-directory! dir)
+ (let ((r (thunk)))
+ (set-current-directory! cwd) r)))
+
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
(call-with-input-file
(format #f "~A/~A" base-path "package-list.sds")
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
(version (let ((v (assq 'version (cdr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3)))))
(depends (let ((d (assq 'depends (cdr i))))
(and d (cdr d))))
(description (let ((d (assq 'description (cdr i))))
- (and d (apply string-append (cdr d))))))
- (hashtable-set! ht name (make-pkginfo name version depends description)))
+ (and d (apply string-append (cdr d)))))
+ (status #f))
+ (hashtable-set! ht name
+ (make-pkg-info name version depends description status)))
(loop (read in))))))
- ht))
-
- (define (get-pkginfo)
- (let ((ht #f))
- (lambda (package)
- (unless ht
- (set! ht (read-package-list)))
- (hashtable-ref ht package #f))))
-
- (define (read-install-information)
- (let ((ht (make-eq-hashtable)))
(call-with-input-file
(format #f "~A/~A" base-path "install.sds")
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
- (state (cond ((eq? 'installed (cadr i)) #t)
- ((eq? 'uninstalled (cadr i)) #f)
- ((cadr i) #t)
- (else #f)))
+ (status (cond ((cadr i) #t)
+ (else #f)))
(version (let ((v (assq 'version (cddr i))))
(and v
(list? (cdr v))
(= 3 (length (cdr v)))
(number? (list-ref v 1))
(number? (list-ref v 2))
(number? (list-ref v 3))
(make-version (list-ref v 1)
(list-ref v 2)
(list-ref v 3))))))
- (hashtable-set! ht name (make-insinfo name version state)))
+ (if (hashtable-contains? ht name)
+ (let ((p (hashtable-ref ht name)))
+ (pkg-info-status-set! p
+ (make-pkg-stat status version))
+ (hashtable-set! ht name p))
+ (hashtable-set! ht name
+ (make-pkg-info name #f #f #f
+ (make-pkg-stat status version)))))
(loop (read in))))))
ht))
- (define (get-insinfo)
+ (define (get-pkg-info)
(let ((ht #f))
(lambda (package)
(unless ht
- (set! ht (read-install-information)))
+ (set! ht (read-package-list)))
(hashtable-ref ht package #f))))
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
(define (version->list version)
(list (version-major version)
(version-minor version)
(version-patch version)))
+ (define (package->string p)
+ (cond
+ ((pkg-info? p)
+ (if (version? (pkg-info-version p))
+ (string-append (symbol->string (pkg-info-name p)) "-" (version->string (pkg-info-version p)))
+ (symbol->string (pkg-info-name p))))
+ ((symbol? p) (symbol->string p))
+ ((string? p) p)
+ (else #f)))
+
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
- (command impl install.ss))
+ (lambda () (command impl install.ss)))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
- (command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)))
+ (lambda () (command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss))))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
(initialize package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
f67398f436a1967bc9a5eb0720545dcc095e6fb0
|
added 'insinfo' record.
|
diff --git a/tools.sls b/tools.sls
index 7935b32..c77429a 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,192 +1,236 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-record-type (version make-version version?)
(fields
(immutable v1 version-major)
(immutable v2 version-minor)
(immutable v3 version-patch)))
(define-record-type (pkginfo make-pkginfo pkginfo?)
(fields
(immutable name package-name)
(immutable version package-version)
(immutable depends package-depends)
(immutable description package-description)))
+ (define-record-type (insinfo make-insinfo insinfo?)
+ (fields
+ (immutable name insinfo-name)
+ (immutable version insinfo-version)
+ (immutable status insinfo-status)))
+
(define-syntax call-with-current-working-directory
(syntax-rules ()
((_ dir proc)
(let ((cwd (current-directory)))
(set-current-directory! dir)
(let ((r proc))
(set-current-directory! cwd) r)))))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (read-package-list)
(let ((ht (make-eq-hashtable)))
(call-with-input-file
(format #f "~A/~A" base-path "package-list.sds")
(lambda (in)
(let loop ((i (read in)))
(unless (eof-object? i)
(let ((name (car i))
- (version (let ((j (assq 'version (cdr i))))
- (and j
- (list? (cdr j))
- (= 3 (length (cdr j)))
- (number? (list-ref j 1))
- (number? (list-ref j 2))
- (number? (list-ref j 3))
- (make-version (list-ref j 1)
- (list-ref j 2)
- (list-ref j 3)))))
- (depends (let ((j (assq 'depends (cdr i))))
- (and j (cdr j))))
- (description (let ((j (assq 'description (cdr i))))
- (and j (apply string-append (cdr j))))))
+ (version (let ((v (assq 'version (cdr i))))
+ (and v
+ (list? (cdr v))
+ (= 3 (length (cdr v)))
+ (number? (list-ref v 1))
+ (number? (list-ref v 2))
+ (number? (list-ref v 3))
+ (make-version (list-ref v 1)
+ (list-ref v 2)
+ (list-ref v 3)))))
+ (depends (let ((d (assq 'depends (cdr i))))
+ (and d (cdr d))))
+ (description (let ((d (assq 'description (cdr i))))
+ (and d (apply string-append (cdr d))))))
(hashtable-set! ht name (make-pkginfo name version depends description)))
(loop (read in))))))
ht))
(define (get-pkginfo)
(let ((ht #f))
(lambda (package)
(unless ht
(set! ht (read-package-list)))
(hashtable-ref ht package #f))))
+ (define (read-install-information)
+ (let ((ht (make-eq-hashtable)))
+ (call-with-input-file
+ (format #f "~A/~A" base-path "install.sds")
+ (lambda (in)
+ (let loop ((i (read in)))
+ (unless (eof-object? i)
+ (let ((name (car i))
+ (state (cond ((eq? 'installed (cadr i)) #t)
+ ((eq? 'uninstalled (cadr i)) #f)
+ ((cadr i) #t)
+ (else #f)))
+ (version (let ((v (assq 'version (cddr i))))
+ (and v
+ (list? (cdr v))
+ (= 3 (length (cdr v)))
+ (number? (list-ref v 1))
+ (number? (list-ref v 2))
+ (number? (list-ref v 3))
+ (make-version (list-ref v 1)
+ (list-ref v 2)
+ (list-ref v 3))))))
+ (hashtable-set! ht name (make-insinfo name version state)))
+ (loop (read in))))))
+ ht))
+
+ (define (get-insinfo)
+ (let ((ht #f))
+ (lambda (package)
+ (unless ht
+ (set! ht (read-install-information)))
+ (hashtable-ref ht package #f))))
+
(define (version->string version)
(string-append (number->string (version-major version))
"." (number->string (version-minor version))
"." (number->string (version-patch version))))
+ (define (version->list version)
+ (list (version-major version)
+ (version-minor version)
+ (version-patch version)))
+
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
(command impl install.ss))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
(command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
(initialize package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
6ddb259aef3aa86532d5d9395820ce7c180dcb3f
|
added package-list
|
diff --git a/install.sh b/install.sh
index 7133fc3..322cb30 100755
--- a/install.sh
+++ b/install.sh
@@ -1,58 +1,58 @@
#!/bin/sh
LN=/bin/ln
SED=/bin/sed
INSTALL=/usr/bin/install
SCHEME_SCRIPT=${1:-mosh}
PREFIX=${2:-/usr/local}
SPON_URI=http://scheme-users.jp/spon
SPON_HOME=$PREFIX/share/spon
SPON_COMMAND=$PREFIX/bin/spon
SPON_LIB=$SPON_HOME/lib
SPON_DOC=$SPON_HOME/doc
SPON_SRC=$SPON_HOME/src
SPON_SHARE=$SPON_HOME/share
SPON_TMP=/tmp
$SED -e "18 c (define download-uri \"$SPON_URI\")" \
-e "19 c (define base-path \"$SPON_HOME\")" \
-e "20 c (define command-path \"$SPON_COMMAND\")" \
-e "21 c (define library-path \"$SPON_LIB\")" \
-e "22 c (define document-path \"$SPON_DOC\")" \
-e "23 c (define source-path \"$SPON_SRC\")" \
-e "24 c (define share-path \"$SPON_SHARE\")" \
-e "25 c (define temporary-path \"$SPON_TMP\")" \
config.tmpl.sls > config.sls
echo -e "#!/bin/sh\nmosh $SPON_HOME/spon.ss \$*" > spon.mosh.sh
echo -e "#!/bin/sh\nypsilon $SPON_HOME/spon.ss \$*" > spon.ypsilon.sh
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_LIB
$INSTALL -v -m 755 -d $SPON_LIB/spon
$INSTALL -v -m 755 -d $SPON_DOC
$INSTALL -v -m 755 -d $SPON_SRC
for f in spon.mosh.sh spon.ypsilon.sh; do
$INSTALL -v -m 755 $f $SPON_HOME
done
-for f in spon.ss setup.mosh.ss setup.ypsilon.ss; do
+for f in spon.ss setup.mosh.ss setup.ypsilon.ss package-list.sds; do
$INSTALL -v -m 644 $f $SPON_HOME
done
for f in sponrc.sample; do
$INSTALL -v -m 644 $f $SPON_DOC
done
for f in compat.sls compat.mosh.sls compat.ypsilon.sls config.sls tools.sls; do
$INSTALL -v -m 644 $f $SPON_LIB/spon
done
CWD=`pwd`
cd $SPON_LIB
$SCHEME_SCRIPT $SPON_HOME/setup.$SCHEME_SCRIPT.ss
cd $CWD
$LN -sf $SPON_HOME/spon.$SCHEME_SCRIPT.sh $SPON_COMMAND
diff --git a/package-list.sds b/package-list.sds
new file mode 100644
index 0000000..83deb88
--- /dev/null
+++ b/package-list.sds
@@ -0,0 +1,3 @@
+(spon (version 0 0 20090506) (depends package-list) (description "Scheme Portable Library Network"))
+(package-list)
+(pkg-list (alias package-list))
diff --git a/tools.sls b/tools.sls
index 303478c..7935b32 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,141 +1,192 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-implementation-name command
file-copy make-directory make-symbolic-link
call-with-current-working-directory
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
+ (define-record-type (version make-version version?)
+ (fields
+ (immutable v1 version-major)
+ (immutable v2 version-minor)
+ (immutable v3 version-patch)))
+
+ (define-record-type (pkginfo make-pkginfo pkginfo?)
+ (fields
+ (immutable name package-name)
+ (immutable version package-version)
+ (immutable depends package-depends)
+ (immutable description package-description)))
+
(define-syntax call-with-current-working-directory
(syntax-rules ()
((_ dir proc)
(let ((cwd (current-directory)))
(set-current-directory! dir)
(let ((r proc))
(set-current-directory! cwd) r)))))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
+ (define (read-package-list)
+ (let ((ht (make-eq-hashtable)))
+ (call-with-input-file
+ (format #f "~A/~A" base-path "package-list.sds")
+ (lambda (in)
+ (let loop ((i (read in)))
+ (unless (eof-object? i)
+ (let ((name (car i))
+ (version (let ((j (assq 'version (cdr i))))
+ (and j
+ (list? (cdr j))
+ (= 3 (length (cdr j)))
+ (number? (list-ref j 1))
+ (number? (list-ref j 2))
+ (number? (list-ref j 3))
+ (make-version (list-ref j 1)
+ (list-ref j 2)
+ (list-ref j 3)))))
+ (depends (let ((j (assq 'depends (cdr i))))
+ (and j (cdr j))))
+ (description (let ((j (assq 'description (cdr i))))
+ (and j (apply string-append (cdr j))))))
+ (hashtable-set! ht name (make-pkginfo name version depends description)))
+ (loop (read in))))))
+ ht))
+
+ (define (get-pkginfo)
+ (let ((ht #f))
+ (lambda (package)
+ (unless ht
+ (set! ht (read-package-list)))
+ (hashtable-ref ht package #f))))
+
+ (define (version->string version)
+ (string-append (number->string (version-major version))
+ "." (number->string (version-minor version))
+ "." (number->string (version-patch version))))
+
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(download-uri (config "download-uri" download-uri))
(pkg-uri (format "~A/~A.tar.gz" download-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
((format "Setup package to ~A ..." (string-upcase system-name))
(call-with-current-working-directory pkg-path
(command impl install.ss))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-implementation-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(setup.ss (format "~A/setup.ss" pkg-path))
(setup.impl.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(call-with-current-working-directory pkg-path
(command impl (if (file-exists? setup.impl.ss) setup.impl.ss setup.ss)))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
(initialize package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
354a10ed51f69d538d9308588e11ca1dd574f1f1
|
fix verbose mode
|
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index f39af63..538fede 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,49 +1,49 @@
(library (spon compat)
(export current-implementation-name
command
file-copy
make-directory
make-symbolic-link
current-directory
set-current-directory!)
(import (rnrs)
(only (core)
current-directory
destructuring-bind
process
process-wait)
(spon config))
(define (current-implementation-name) "ypsilon")
(define (command cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
- (cond ((verbose?)
- (let ((p-message (transcoded-port p-stdout (native-transcoder)))
- (p-error (transcoded-port p-stderr (native-transcoder))))
- (let loop ((status #f))
- (let ((message (get-string-all p-message)))
- (unless (eof-object? message)
- (put-string (current-output-port) message)))
- (let ((error (get-string-all p-error)))
- (unless (eof-object? error)
- (put-string (current-error-port) error)))
- (or status (loop (process-wait pid #t))) ; nohang = #t
- (zero? status))))
- (else
- (zero? (process-wait pid #f)))))) ; nohang = #f
+ (zero?
+ (cond ((verbose?)
+ (let ((p-message (transcoded-port p-stdout (native-transcoder)))
+ (p-error (transcoded-port p-stderr (native-transcoder))))
+ (let loop ((status #f))
+ (let ((message (get-string-all p-message)))
+ (unless (eof-object? message)
+ (put-string (current-output-port) message)))
+ (let ((error (get-string-all p-error)))
+ (unless (eof-object? error)
+ (put-string (current-error-port) error)))
+ (or status (loop (process-wait pid #t)))))) ; nohang = #t
+ (else
+ (process-wait pid #f)))))) ; nohang = #f
(define (file-copy src dst mode)
(command "install" "-m" (number->string mode 8) src dst))
(define (make-directory dir mode)
(command "install" "-m" (number->string mode 8) "-d" dir))
(define (make-symbolic-link target link)
(command "ln" "-sf" target link))
(define (set-current-directory! dir)
(current-directory dir))
) ;[end]
|
higepon/spon
|
5a36d15cf5eeff50c7ebfd6e00365a490496ce11
|
added spon use command
|
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 7b8981c..cda5a32 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,39 +1,43 @@
(library (spon compat)
(export current-system-name
command
file-copy
make-directory
+ make-symbolic-link
current-directory
set-current-directory!)
(import (rnrs)
(only (mosh) current-directory set-current-directory!)
(only (mosh process) spawn waitpid pipe)
(spon config))
(define (current-system-name) "mosh")
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
(let-values ([(pid cin cout cerr) (spawn command args (list #f out out))])
(close-port out)
(close-port in)
(waitpid pid))))
(define (command cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
(define (file-copy src dst mode)
(command "install" "-m" (number->string mode 8) src dst))
(define (make-directory dir mode)
(command "install" "-m" (number->string mode 8) "-d" dir))
+ (define (make-symbolic-link target link)
+ (command "ln" "-sf" target link))
+
)
diff --git a/compat.sls b/compat.sls
index dc39e70..c0fd78f 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,30 +1,31 @@
(library (spon compat)
(export current-system-name
command
file-copy
make-directory
+ make-symbolic-link
current-directory
set-current-directory!)
(import (rnrs)
(spon config))
(define (current-system-name) "scheme")
;; -- command :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
(define (command cmd . args)
(raise (condition
(make-implementation-restriction-violation)
(make-who-condition 'command)
(make-message-condition
(string-append
"Compatibility layer is not implemented. "
(string-titlecase system-name)
" seems to be not supported by your implementation. "
"Please consult the author of your implementation."))
(make-irritants-condition (cons cmd args)))))
)
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index fe82b76..d317fa5 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,50 +1,49 @@
-;; (verbose? #t)ã§ã¡ãã»ã¼ã¸ãåºåããã¾ã
-;; tools.slsã®(srfi :48)ã¯Ypsilonã«ã¯ç¡ãã®ã§ã
-;; (srfi :28)ã«ãã¦è©¦ãã¦ãã ããã
-
(library (spon compat)
(export current-system-name
command
file-copy
make-directory
+ make-symbolic-link
current-directory
set-current-directory!)
(import (rnrs)
- (only (core) destructuring-bind process process-wait)
+ (only (core)
+ current-directory
+ destructuring-bind
+ process
+ process-wait)
(spon config))
(define (current-system-name) "ypsilon")
(define (command cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
(or status (loop (process-wait pid #t))) ; nohang = #t
(zero? status))))
(else
(zero? (process-wait pid #f)))))) ; nohang = #f
(define (file-copy src dst mode)
(command "install" "-m" (number->string mode 8) src dst))
(define (make-directory dir mode)
(command "install" "-m" (number->string mode 8) "-d" dir))
- (define (current-directory)
- ;; TODO
- #f)
+ (define (make-symbolic-link target link)
+ (command "ln" "-sf" target link))
- (define (set-current-directory!)
- ;; TODO
- #f)
+ (define (set-current-directory! dir)
+ (current-directory dir))
) ;[end]
diff --git a/spon.ss b/spon.ss
index b54de39..d97bd45 100644
--- a/spon.ss
+++ b/spon.ss
@@ -1,26 +1,34 @@
(import (rnrs)
(srfi :39)
(srfi :48)
- (spon tools))
+ (spon tools)
+ (spon config))
(define (main args)
- (cond
- [(null? (cdr args))
- (display (format "ERROR ~a: package name not specified\n" system-name)
- (current-error-port))
- (exit #f)]
- [else
- (parameterize ((verbose? #f))
- (guard (exception
- [(download-error? exception)
- (format (current-error-port) "\n failed to download package ~a.\n" (download-error-uri exception))]
- [else (raise exception)])
- (cond
- ((install (cadr args))
- (exit))
- (else
- (display (format "ERROR ~A: install failed\n" system-name)
+ (case (string->symbol (cadr args))
+ ((install)
+ (cond
+ [(null? (cddr args))
+ (display (format "ERROR ~a: package name not specified\n" system-name)
(current-error-port))
- (exit #f))))])))
+ (exit #f)]
+ [else
+ (parameterize ((verbose? #f))
+ (guard (exception
+ [(download-error? exception)
+ (format (current-error-port) "\n failed to download package ~a.\n" (download-error-uri exception))]
+ [else (raise exception)])
+ (cond
+ ((install (caddr args))
+ (exit))
+ (else
+ (display (format "ERROR ~A: install failed\n" system-name)
+ (current-error-port))
+ (exit #f)))))]))
+ ((use)
+ (let ((impl (caddr args)))
+ (command impl (string-append spon-home "/setup." impl ".ss") library-path)
+ (make-symbolic-link (string-append spon-home "/spon." impl ".sh") command-path)))
+ (else (exit #f))))
(main (command-line))
diff --git a/tools.sls b/tools.sls
index 726fca2..1789517 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,135 +1,135 @@
(library (spon tools)
(export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri
current-system-name command
- file-copy make-directory
+ file-copy make-directory make-symbolic-link
current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (cmd-wget uri dir)
(or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(spon-uri (config "spon-uri" spon-uri))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-system-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
("Setup package to SPON ..."
(let ((cwd (current-directory)))
(set-current-directory! pkg-path)
(let ((r (command impl install.ss pkg-path)))
(set-current-directory! cwd) r))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-system-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(setup.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(let ((cwd (current-directory)))
(set-current-directory! pkg-path)
(let ((r (command impl setup.ss pkg-path)))
(set-current-directory! cwd) r))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
(initialize package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
f97df5a3764041295d50086fea5a500b1dd3e3e6
|
rename do-cmd command
|
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 6ae98c1..7b8981c 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,31 +1,39 @@
(library (spon compat)
(export current-system-name
+ command
+ file-copy
+ make-directory
current-directory
- set-current-directory!
- do-cmd)
+ set-current-directory!)
(import (rnrs)
- (spon config)
+ (only (mosh) current-directory set-current-directory!)
(only (mosh process) spawn waitpid pipe)
- (only (mosh) current-directory set-current-directory!))
+ (spon config))
(define (current-system-name) "mosh")
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
(let-values ([(pid cin cout cerr) (spawn command args (list #f out out))])
(close-port out)
(close-port in)
(waitpid pid))))
- (define (do-cmd cmd . args)
+ (define (command cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
+ (define (file-copy src dst mode)
+ (command "install" "-m" (number->string mode 8) src dst))
+
+ (define (make-directory dir mode)
+ (command "install" "-m" (number->string mode 8) "-d" dir))
+
)
diff --git a/compat.sls b/compat.sls
index 89a1f1b..dc39e70 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,25 +1,30 @@
(library (spon compat)
- (export current-system-name do-cmd)
+ (export current-system-name
+ command
+ file-copy
+ make-directory
+ current-directory
+ set-current-directory!)
(import (rnrs)
(spon config))
(define (current-system-name) "scheme")
- ;; -- do-cmd :: (String, [String]) -> Boolean
+ ;; -- command :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
- (define (do-cmd cmd . args)
+ (define (command cmd . args)
(raise (condition
(make-implementation-restriction-violation)
- (make-who-condition 'do-cmd)
+ (make-who-condition 'command)
(make-message-condition
(string-append
"Compatibility layer is not implemented. "
(string-titlecase system-name)
" seems to be not supported by your implementation. "
"Please consult the author of your implementation."))
(make-irritants-condition (cons cmd args)))))
)
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index 5b76213..fe82b76 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,31 +1,50 @@
;; (verbose? #t)ã§ã¡ãã»ã¼ã¸ãåºåããã¾ã
;; tools.slsã®(srfi :48)ã¯Ypsilonã«ã¯ç¡ãã®ã§ã
;; (srfi :28)ã«ãã¦è©¦ãã¦ãã ããã
(library (spon compat)
- (export current-system-name do-cmd)
+ (export current-system-name
+ command
+ file-copy
+ make-directory
+ current-directory
+ set-current-directory!)
(import (rnrs)
- (spon config)
- (only (core) destructuring-bind process process-wait))
+ (only (core) destructuring-bind process process-wait)
+ (spon config))
(define (current-system-name) "ypsilon")
- (define (do-cmd cmd . args)
+ (define (command cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
(or status (loop (process-wait pid #t))) ; nohang = #t
(zero? status))))
(else
(zero? (process-wait pid #f)))))) ; nohang = #f
+ (define (file-copy src dst mode)
+ (command "install" "-m" (number->string mode 8) src dst))
+
+ (define (make-directory dir mode)
+ (command "install" "-m" (number->string mode 8) "-d" dir))
+
+ (define (current-directory)
+ ;; TODO
+ #f)
+
+ (define (set-current-directory!)
+ ;; TODO
+ #f)
+
) ;[end]
diff --git a/setup.mosh.ss b/setup.mosh.ss
index c255936..191525c 100644
--- a/setup.mosh.ss
+++ b/setup.mosh.ss
@@ -1,30 +1,30 @@
(import (rnrs)
(only (mosh config) get-config)
(only (mosh process) spawn waitpid))
(define (cmd-install . args)
(let*-values (((pid . _) (spawn "install" args '(#f #f #f)))
((pid status) (waitpid pid)))
(zero? status)))
-(define (mkdir dir)
- (cmd-install "-v" "-m" "755" "-d" dir))
+(define (file-copy src dst mode)
+ (cmd-install "-v" "-m" (number->string mode 8) src dst))
-(define (file-copy src dst)
- (cmd-install "-v" "-m" "644" src dst))
+(define (make-directory dir mode)
+ (cmd-install "-v" "-m" (number->string mode 8) "-d" dir))
(define (main args)
(let ((spon-lib (cadr args))
(sitelib-path (string-append (get-config "library-path") "/lib")))
- (mkdir (string-append sitelib-path "/spon"))
+ (make-directory (string-append sitelib-path "/spon") #o755)
(file-copy
(string-append spon-lib "/spon/compat.mosh.sls")
- (string-append sitelib-path "/spon/compat.sls"))
+ (string-append sitelib-path "/spon/compat.sls") #o644)
(file-copy
(string-append spon-lib "/spon/config.sls")
- (string-append sitelib-path "/spon/config.sls"))
+ (string-append sitelib-path "/spon/config.sls") #o644)
(file-copy
(string-append spon-lib "/spon/tools.sls")
- (string-append sitelib-path "/spon/tools.sls"))))
+ (string-append sitelib-path "/spon/tools.sls") #o644)))
(main (command-line))
diff --git a/setup.ypsilon.ss b/setup.ypsilon.ss
index da2c92b..5172159 100644
--- a/setup.ypsilon.ss
+++ b/setup.ypsilon.ss
@@ -1,33 +1,33 @@
(import (rnrs)
(only (core)
destructuring-bind
process process-wait
scheme-library-paths))
(define (cmd-install . args)
(destructuring-bind
(pid p-stdin p-stdout p-stderr)
(apply process "install" args)
(zero? (process-wait pid #f))))
-(define (mkdir dir)
- (cmd-install "-v" "-m" "755" "-d" dir))
+(define (file-copy src dst mode)
+ (cmd-install "-v" "-m" (number->string mode 8) src dst))
-(define (file-copy src dst)
- (cmd-install "-v" "-m" "644" src dst))
+(define (make-directory dir mode)
+ (cmd-install "-v" "-m" (number->string mode 8) "-d" dir))
(define (main args)
(let ((spon-lib (cadr args))
(sitelib-path (car (scheme-library-paths))))
- (mkdir (string-append sitelib-path "/spon"))
+ (make-directory (string-append sitelib-path "/spon") #o755)
(file-copy
(string-append spon-lib "/spon/compat.ypsilon.sls")
- (string-append sitelib-path "/spon/compat.sls"))
+ (string-append sitelib-path "/spon/compat.sls") #o644)
(file-copy
(string-append spon-lib "/spon/config.sls")
- (string-append sitelib-path "/spon/config.sls"))
+ (string-append sitelib-path "/spon/config.sls") #o644)
(file-copy
(string-append spon-lib "/spon/tools.sls")
- (string-append sitelib-path "/spon/tools.sls"))))
+ (string-append sitelib-path "/spon/tools.sls") #o644)))
(main (command-line))
diff --git a/tools.sls b/tools.sls
index 2cf5880..726fca2 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,135 +1,135 @@
(library (spon tools)
- (export download verify decompress initialize setup install cmd-install
- system-name verbose? quiet? download-error? download-error-uri)
+ (export download verify decompress initialize setup install
+ system-name verbose? quiet? download-error? download-error-uri
+ current-system-name command
+ file-copy make-directory
+ current-directory set-current-directory!)
(import (rnrs)
(srfi :48)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (cmd-wget uri dir)
- (or (apply do-cmd
+ (or (apply command
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
- (apply do-cmd
+ (apply command
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
- (apply do-cmd
+ (apply command
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
- (define (cmd-install . args)
- (apply do-cmd ((get-config) "install") args))
-
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(spon-uri (config "spon-uri" spon-uri))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
(impl (current-system-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(install.ss (format "~A/install.ss" pkg-path)))
(do-procs
- ("Setup package to SPON's library"
+ ("Setup package to SPON ..."
(let ((cwd (current-directory)))
(set-current-directory! pkg-path)
- (let ((r (do-cmd impl install.ss pkg-path)))
+ (let ((r (command impl install.ss pkg-path)))
(set-current-directory! cwd) r))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
(impl (current-system-name))
(src-path (config "source-path" source-path))
(pkg-path (format "~A/~A" source-path package))
(setup.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(let ((cwd (current-directory)))
(set-current-directory! pkg-path)
- (let ((r (do-cmd impl setup.ss pkg-path)))
+ (let ((r (command impl setup.ss pkg-path)))
(set-current-directory! cwd) r))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
(initialize package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
843ba3de74017037bc65e50f4123085213321683
|
added setup.ypsilon.ss
|
diff --git a/install.sh b/install.sh
index 4829a6e..5425bee 100755
--- a/install.sh
+++ b/install.sh
@@ -1,55 +1,55 @@
#!/bin/sh
LN=/bin/ln
SED=/bin/sed
INSTALL=/usr/bin/install
SCHEME_SCRIPT=${1:-mosh}
PREFIX=${2:-/usr/local}
SPON_URI=http://scheme-users.jp/spon
SPON_HOME=$PREFIX/share/spon
SPON_COMMAND=$PREFIX/bin/spon
SPON_LIB=$SPON_HOME/lib
SPON_DOC=$SPON_HOME/doc
SPON_SRC=$SPON_HOME/src
SPON_SHARE=$SPON_HOME/share
SPON_TMP=/tmp
$SED -e "18 c (define spon-uri \"$SPON_URI\")" \
-e "19 c (define spon-home \"$SPON_HOME\")" \
-e "20 c (define command-path \"$SPON_COMMAND\")" \
-e "21 c (define library-path \"$SPON_LIB\")" \
-e "22 c (define document-path \"$SPON_DOC\")" \
-e "23 c (define source-path \"$SPON_SRC\")" \
-e "24 c (define share-path \"$SPON_SHARE\")" \
-e "25 c (define temporary-path \"$SPON_TMP\")" \
config.tmpl.sls > config.sls
echo -e "#!/bin/sh\nmosh $SPON_HOME/spon.ss \$*" > spon.mosh.sh
echo -e "#!/bin/sh\nypsilon $SPON_HOME/spon.ss \$*" > spon.ypsilon.sh
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_LIB
$INSTALL -v -m 755 -d $SPON_LIB/spon
$INSTALL -v -m 755 -d $SPON_DOC
$INSTALL -v -m 755 -d $SPON_SRC
for f in spon.mosh.sh spon.ypsilon.sh; do
$INSTALL -v -m 755 $f $SPON_HOME
done
-for f in spon.ss setup.mosh.ss; do
+for f in spon.ss setup.mosh.ss setup.ypsilon.ss; do
$INSTALL -v -m 644 $f $SPON_HOME
done
for f in sponrc.sample; do
$INSTALL -v -m 644 $f $SPON_DOC
done
for f in compat.sls compat.mosh.sls compat.ypsilon.sls config.sls tools.sls; do
$INSTALL -v -m 644 $f $SPON_LIB/spon
done
$SCHEME_SCRIPT $SPON_HOME/setup.$SCHEME_SCRIPT.ss $SPON_LIB
$LN -s $SPON_HOME/spon.$SCHEME_SCRIPT.sh $SPON_COMMAND
diff --git a/setup.mosh.ss b/setup.mosh.ss
index be00bec..c255936 100644
--- a/setup.mosh.ss
+++ b/setup.mosh.ss
@@ -1,30 +1,30 @@
(import (rnrs)
- (mosh config)
+ (only (mosh config) get-config)
(only (mosh process) spawn waitpid))
(define (cmd-install . args)
(let*-values (((pid . _) (spawn "install" args '(#f #f #f)))
((pid status) (waitpid pid)))
(zero? status)))
(define (mkdir dir)
(cmd-install "-v" "-m" "755" "-d" dir))
(define (file-copy src dst)
(cmd-install "-v" "-m" "644" src dst))
(define (main args)
(let ((spon-lib (cadr args))
(sitelib-path (string-append (get-config "library-path") "/lib")))
(mkdir (string-append sitelib-path "/spon"))
(file-copy
(string-append spon-lib "/spon/compat.mosh.sls")
(string-append sitelib-path "/spon/compat.sls"))
(file-copy
(string-append spon-lib "/spon/config.sls")
(string-append sitelib-path "/spon/config.sls"))
(file-copy
(string-append spon-lib "/spon/tools.sls")
(string-append sitelib-path "/spon/tools.sls"))))
(main (command-line))
diff --git a/setup.ypsilon.ss b/setup.ypsilon.ss
new file mode 100644
index 0000000..da2c92b
--- /dev/null
+++ b/setup.ypsilon.ss
@@ -0,0 +1,33 @@
+(import (rnrs)
+ (only (core)
+ destructuring-bind
+ process process-wait
+ scheme-library-paths))
+
+(define (cmd-install . args)
+ (destructuring-bind
+ (pid p-stdin p-stdout p-stderr)
+ (apply process "install" args)
+ (zero? (process-wait pid #f))))
+
+(define (mkdir dir)
+ (cmd-install "-v" "-m" "755" "-d" dir))
+
+(define (file-copy src dst)
+ (cmd-install "-v" "-m" "644" src dst))
+
+(define (main args)
+ (let ((spon-lib (cadr args))
+ (sitelib-path (car (scheme-library-paths))))
+ (mkdir (string-append sitelib-path "/spon"))
+ (file-copy
+ (string-append spon-lib "/spon/compat.ypsilon.sls")
+ (string-append sitelib-path "/spon/compat.sls"))
+ (file-copy
+ (string-append spon-lib "/spon/config.sls")
+ (string-append sitelib-path "/spon/config.sls"))
+ (file-copy
+ (string-append spon-lib "/spon/tools.sls")
+ (string-append sitelib-path "/spon/tools.sls"))))
+
+(main (command-line))
|
higepon/spon
|
942f70195e3b0582ee653880b13a720f8530f036
|
remove base.sls spon.sh
|
diff --git a/ChangeLog b/ChangeLog
index 74696bb..9e6dae8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,40 +1,45 @@
+2009-04-05 baal <[email protected]>
+
+ * config.tmpl.sls : marge to base.sls.
+ * spon command : remove. spon command is made in install.sh.
+
2009-03-17 baal <[email protected]>
* config.tmpl.sls : template for generate (spon config). used by install.sh.
2009-03-13 higepon <[email protected]>
* tools.sls (spon): Use down-load-erro condition. Need refactoring.
2009-02-23 leque <[email protected]>
* tools.sls: quiet external commands down when (quiet?) is #t.
* tools.sls: do not verify package by default.
2009-02-22 higepon <[email protected]>
* tools.sls (spon): Added &i/o-download.
* spon.ss (main): (quiet? #t).
2009-02-18 higepon <[email protected]>
* compat.mosh.sls (spon): Added (verbose) => #f support.
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/base.sls b/base.sls
deleted file mode 100644
index 6709d84..0000000
--- a/base.sls
+++ /dev/null
@@ -1,16 +0,0 @@
-(library (spon base)
- (export system-name verbose? quiet?)
- (import (rnrs)
- (srfi :39))
-
- (define system-name "spon")
-
- (define verbose? (make-parameter #f))
-
- ;; (quiet? #t) implies (verbose? #f).
- (define quiet? (make-parameter #f
- (lambda (v)
- (when v
- (verbose? #f))
- v)))
- )
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 83ab4d3..6ae98c1 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,27 +1,31 @@
(library (spon compat)
- (export current-implementation-name do-cmd)
+ (export current-system-name
+ current-directory
+ set-current-directory!
+ do-cmd)
(import (rnrs)
- (spon base)
- (only (mosh process) spawn waitpid pipe))
+ (spon config)
+ (only (mosh process) spawn waitpid pipe)
+ (only (mosh) current-directory set-current-directory!))
- (define (current-implementation-name) "mosh")
+ (define (current-system-name) "mosh")
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
(let-values ([(pid cin cout cerr) (spawn command args (list #f out out))])
(close-port out)
(close-port in)
(waitpid pid))))
(define (do-cmd cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
)
diff --git a/compat.sls b/compat.sls
index 0a777ca..89a1f1b 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,26 +1,25 @@
(library (spon compat)
- (export current-implementation-name do-cmd)
+ (export current-system-name do-cmd)
(import (rnrs)
- (spon base)
- )
+ (spon config))
- (define (current-implementation-name) "scheme")
+ (define (current-system-name) "scheme")
;; -- do-cmd :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
(define (do-cmd cmd . args)
(raise (condition
(make-implementation-restriction-violation)
(make-who-condition 'do-cmd)
(make-message-condition
(string-append
"Compatibility layer is not implemented. "
(string-titlecase system-name)
" seems to be not supported by your implementation. "
"Please consult the author of your implementation."))
(make-irritants-condition (cons cmd args)))))
)
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index 84cfa02..5b76213 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,31 +1,31 @@
;; (verbose? #t)ã§ã¡ãã»ã¼ã¸ãåºåããã¾ã
;; tools.slsã®(srfi :48)ã¯Ypsilonã«ã¯ç¡ãã®ã§ã
;; (srfi :28)ã«ãã¦è©¦ãã¦ãã ããã
(library (spon compat)
- (export current-implementation-name do-cmd)
+ (export current-system-name do-cmd)
(import (rnrs)
- (spon base)
+ (spon config)
(only (core) destructuring-bind process process-wait))
- (define (current-implementation-name) "ypsilon")
+ (define (current-system-name) "ypsilon")
(define (do-cmd cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
(or status (loop (process-wait pid #t))) ; nohang = #t
(zero? status))))
(else
(zero? (process-wait pid #f)))))) ; nohang = #f
) ;[end]
diff --git a/config.tmpl.sls b/config.tmpl.sls
index 9c18d95..445886f 100644
--- a/config.tmpl.sls
+++ b/config.tmpl.sls
@@ -1,58 +1,71 @@
(library (spon config)
- (export *spon-uri* *spon-home*
- *command-path* *library-path*
- *document-path* *source-path*
- *share-path* *temporary-path*
- *config-search-path*
+ (export system-name
+ verbose? quiet?
+ spon-uri spon-home
+ command-path library-path
+ document-path source-path
+ share-path temporary-path
+ config-search-path
load-config get-config)
(import (rnrs)
+ (srfi :39)
(srfi :48)
(srfi :98))
- (define *spon-uri* "http://scheme-users.jp/spon")
- (define *spon-home* "/usr/local/share/spon")
- (define *command-path* "/usr/local/bin/spon")
- (define *library-path* "/usr/local/share/spon/lib")
- (define *document-path* "/usr/local/share/spon/doc")
- (define *source-path* "/usr/local/share/spon/src")
- (define *share-path* "/usr/local/share/spon/share")
- (define *temporary-path* "/tmp")
+ (define system-name "spon")
+ (define spon-uri "http://scheme-users.jp/spon")
+ (define spon-home "/usr/local/share/spon")
+ (define command-path "/usr/local/bin/spon")
+ (define library-path "/usr/local/share/spon/lib")
+ (define document-path "/usr/local/share/spon/doc")
+ (define source-path "/usr/local/share/spon/src")
+ (define share-path "/usr/local/share/spon/share")
+ (define temporary-path "/tmp")
- (define *config-search-path*
+ (define config-search-path
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
- ,(string-append *spon-home* "/sponrc")
+ ,(string-append spon-home "/sponrc")
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
- (config-path (find file-exists? *config-search-path*)))
+ (config-path (find file-exists? config-search-path)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
+
+ (define verbose? (make-parameter #f))
+
+ ;; (quiet? #t) implies (verbose? #f).
+ (define quiet? (make-parameter #f
+ (lambda (v)
+ (when v
+ (verbose? #f))
+ v)))
)
diff --git a/install.sh b/install.sh
index 2dd0ab6..4829a6e 100755
--- a/install.sh
+++ b/install.sh
@@ -1,63 +1,55 @@
#!/bin/sh
+LN=/bin/ln
SED=/bin/sed
INSTALL=/usr/bin/install
SCHEME_SCRIPT=${1:-mosh}
PREFIX=${2:-/usr/local}
SPON_URI=http://scheme-users.jp/spon
SPON_HOME=$PREFIX/share/spon
SPON_COMMAND=$PREFIX/bin/spon
SPON_LIB=$SPON_HOME/lib
SPON_DOC=$SPON_HOME/doc
SPON_SRC=$SPON_HOME/src
SPON_SHARE=$SPON_HOME/share
SPON_TMP=/tmp
-$SED -e "14 c (define *spon-uri* \"$SPON_URI\")" \
- -e "15 c (define *spon-home* \"$SPON_HOME\")" \
- -e "16 c (define *command-path* \"$SPON_COMMAND\")" \
- -e "17 c (define *library-path* \"$SPON_LIB\")" \
- -e "18 c (define *document-path* \"$SPON_DOC\")" \
- -e "19 c (define *source-path* \"$SPON_SRC\")" \
- -e "20 c (define *share-path* \"$SPON_SHARE\")" \
- -e "21 c (define *temporary-path* \"$SPON_TMP\")" \
+$SED -e "18 c (define spon-uri \"$SPON_URI\")" \
+ -e "19 c (define spon-home \"$SPON_HOME\")" \
+ -e "20 c (define command-path \"$SPON_COMMAND\")" \
+ -e "21 c (define library-path \"$SPON_LIB\")" \
+ -e "22 c (define document-path \"$SPON_DOC\")" \
+ -e "23 c (define source-path \"$SPON_SRC\")" \
+ -e "24 c (define share-path \"$SPON_SHARE\")" \
+ -e "25 c (define temporary-path \"$SPON_TMP\")" \
config.tmpl.sls > config.sls
-echo "#!/bin/sh" > spon.sh
-
-case "$SCHEME_SCRIPT" in
- 'mosh')
- echo "mosh $SPON_HOME/spon.ss \$*" >> spon.sh
- ;;
- 'ypsilon')
- echo "ypsilon $SPON_HOME/spon.ss \$*" >> spon.sh
- ;;
- *)
- echo "ERROR!"
- exit 1
- ;;
-esac
+echo -e "#!/bin/sh\nmosh $SPON_HOME/spon.ss \$*" > spon.mosh.sh
+echo -e "#!/bin/sh\nypsilon $SPON_HOME/spon.ss \$*" > spon.ypsilon.sh
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_LIB
$INSTALL -v -m 755 -d $SPON_LIB/spon
$INSTALL -v -m 755 -d $SPON_DOC
$INSTALL -v -m 755 -d $SPON_SRC
-$INSTALL -v -m 755 spon.sh $SPON_COMMAND
+for f in spon.mosh.sh spon.ypsilon.sh; do
+ $INSTALL -v -m 755 $f $SPON_HOME
+done
for f in spon.ss setup.mosh.ss; do
$INSTALL -v -m 644 $f $SPON_HOME
done
for f in sponrc.sample; do
$INSTALL -v -m 644 $f $SPON_DOC
done
-for f in base.sls compat.sls compat.mosh.sls compat.ypsilon.sls config.sls tools.sls; do
+for f in compat.sls compat.mosh.sls compat.ypsilon.sls config.sls tools.sls; do
$INSTALL -v -m 644 $f $SPON_LIB/spon
done
$SCHEME_SCRIPT $SPON_HOME/setup.$SCHEME_SCRIPT.ss $SPON_LIB
+$LN -s $SPON_HOME/spon.$SCHEME_SCRIPT.sh $SPON_COMMAND
diff --git a/setup.mosh.ss b/setup.mosh.ss
index 320282d..be00bec 100644
--- a/setup.mosh.ss
+++ b/setup.mosh.ss
@@ -1,33 +1,30 @@
(import (rnrs)
(mosh config)
(only (mosh process) spawn waitpid))
(define (cmd-install . args)
- (let*-values (((pid . _) (spawn "install" args '(#f #f #f)))
- ((pid status) (waitpid pid)))
- (zero? status)))
+ (let*-values (((pid . _) (spawn "install" args '(#f #f #f)))
+ ((pid status) (waitpid pid)))
+ (zero? status)))
(define (mkdir dir)
- (cmd-install "-v" "-m" "755" "-d" dir))
+ (cmd-install "-v" "-m" "755" "-d" dir))
(define (file-copy src dst)
- (cmd-install "-v" "-m" "644" src dst))
+ (cmd-install "-v" "-m" "644" src dst))
(define (main args)
- (let ((spon-lib (cadr args))
- (sitelib-path (string-append (get-config "library-path") "/lib")))
- (mkdir (string-append sitelib-path "/spon"))
- (file-copy
- (string-append spon-lib "/spon/base.sls")
- (string-append sitelib-path "/spon/base.sls"))
- (file-copy
- (string-append spon-lib "/spon/compat.mosh.sls")
- (string-append sitelib-path "/spon/compat.sls"))
- (file-copy
- (string-append spon-lib "/spon/config.sls")
- (string-append sitelib-path "/spon/config.sls"))
- (file-copy
- (string-append spon-lib "/spon/tools.sls")
- (string-append sitelib-path "/spon/tools.sls"))))
+ (let ((spon-lib (cadr args))
+ (sitelib-path (string-append (get-config "library-path") "/lib")))
+ (mkdir (string-append sitelib-path "/spon"))
+ (file-copy
+ (string-append spon-lib "/spon/compat.mosh.sls")
+ (string-append sitelib-path "/spon/compat.sls"))
+ (file-copy
+ (string-append spon-lib "/spon/config.sls")
+ (string-append sitelib-path "/spon/config.sls"))
+ (file-copy
+ (string-append spon-lib "/spon/tools.sls")
+ (string-append sitelib-path "/spon/tools.sls"))))
(main (command-line))
diff --git a/spon b/spon
deleted file mode 100755
index 83eb9be..0000000
--- a/spon
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/bash
-
-r6rs="`which mosh`"
-if test "" = "$r6rs"; then
- r6rs="`which ypsilon`"
- if test "" = "$r6rs"; then
- echo "R6RS Scheme not found"
- else
- echo "TODO"
- fi
-else
- # TODO path to spon.ss
- # TODO check $1
- $r6rs --loadpath=/usr/local/share/ spon.ss $2
-fi
-
diff --git a/tools.sls b/tools.sls
index f9e4788..2cf5880 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,125 +1,135 @@
(library (spon tools)
- (export download verify decompress initialize setup install
+ (export download verify decompress initialize setup install cmd-install
system-name verbose? quiet? download-error? download-error-uri)
(import (rnrs)
(srfi :48)
- (spon base)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (cmd-wget uri dir)
(or (apply do-cmd
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply do-cmd
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply do-cmd
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
+ (define (cmd-install . args)
+ (apply do-cmd ((get-config) "install") args))
+
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
- (spon-uri (config "spon-uri" *spon-uri*))
+ (spon-uri (config "spon-uri" spon-uri))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
- (src-path (config "source-path" *source-path*)))
+ (src-path (config "source-path" source-path)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
- (src-path (config "source-path" *source-path*))
+ (src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
- (src-path (config "source-path" *source-path*))
+ (src-path (config "source-path" source-path))
(pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (initialize package)
(let* ((config (get-config))
- (src-path (config "source-path" *source-path*))
- (impl (current-implementation-name))
- (install.ss (format "~A/~A/install.ss" src-path package)))
+ (impl (current-system-name))
+ (src-path (config "source-path" source-path))
+ (pkg-path (format "~A/~A" source-path package))
+ (install.ss (format "~A/install.ss" pkg-path)))
(do-procs
- ("Setup package to spon's library"
- (do-cmd impl install.ss)
+ ("Setup package to SPON's library"
+ (let ((cwd (current-directory)))
+ (set-current-directory! pkg-path)
+ (let ((r (do-cmd impl install.ss pkg-path)))
+ (set-current-directory! cwd) r))
#f
(format "error in ~A" install.ss)))))
(define (setup package)
(let* ((config (get-config))
- (src-path (config "source-path" *source-path*))
- (impl (current-implementation-name))
- (setup.ss (format "~A/~A/setup.~A.ss" src-path package impl)))
+ (impl (current-system-name))
+ (src-path (config "source-path" source-path))
+ (pkg-path (format "~A/~A" source-path package))
+ (setup.ss (format "~A/setup.~A.ss" pkg-path impl)))
(do-procs
((format "Setup package to ~A ..." impl)
- (do-cmd impl setup.ss)
+ (let ((cwd (current-directory)))
+ (set-current-directory! pkg-path)
+ (let ((r (do-cmd impl setup.ss pkg-path)))
+ (set-current-directory! cwd) r))
#f
(format "error in ~A" setup.ss)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
(initialize package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
f9a25beacdb4675a9ffaad339b06286bfffd02fd
|
rename install.mosh.ss to setup.mosh.ss
|
diff --git a/install.sh b/install.sh
index 61f661a..2dd0ab6 100755
--- a/install.sh
+++ b/install.sh
@@ -1,63 +1,63 @@
#!/bin/sh
SED=/bin/sed
INSTALL=/usr/bin/install
SCHEME_SCRIPT=${1:-mosh}
PREFIX=${2:-/usr/local}
SPON_URI=http://scheme-users.jp/spon
SPON_HOME=$PREFIX/share/spon
SPON_COMMAND=$PREFIX/bin/spon
SPON_LIB=$SPON_HOME/lib
SPON_DOC=$SPON_HOME/doc
SPON_SRC=$SPON_HOME/src
SPON_SHARE=$SPON_HOME/share
SPON_TMP=/tmp
$SED -e "14 c (define *spon-uri* \"$SPON_URI\")" \
-e "15 c (define *spon-home* \"$SPON_HOME\")" \
-e "16 c (define *command-path* \"$SPON_COMMAND\")" \
-e "17 c (define *library-path* \"$SPON_LIB\")" \
-e "18 c (define *document-path* \"$SPON_DOC\")" \
-e "19 c (define *source-path* \"$SPON_SRC\")" \
-e "20 c (define *share-path* \"$SPON_SHARE\")" \
-e "21 c (define *temporary-path* \"$SPON_TMP\")" \
config.tmpl.sls > config.sls
echo "#!/bin/sh" > spon.sh
case "$SCHEME_SCRIPT" in
'mosh')
echo "mosh $SPON_HOME/spon.ss \$*" >> spon.sh
;;
'ypsilon')
echo "ypsilon $SPON_HOME/spon.ss \$*" >> spon.sh
;;
*)
echo "ERROR!"
exit 1
;;
esac
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_LIB
$INSTALL -v -m 755 -d $SPON_LIB/spon
$INSTALL -v -m 755 -d $SPON_DOC
$INSTALL -v -m 755 -d $SPON_SRC
$INSTALL -v -m 755 spon.sh $SPON_COMMAND
-for f in spon.ss install.mosh.ss; do
+for f in spon.ss setup.mosh.ss; do
$INSTALL -v -m 644 $f $SPON_HOME
done
for f in sponrc.sample; do
$INSTALL -v -m 644 $f $SPON_DOC
done
for f in base.sls compat.sls compat.mosh.sls compat.ypsilon.sls config.sls tools.sls; do
$INSTALL -v -m 644 $f $SPON_LIB/spon
done
-$SCHEME_SCRIPT $SPON_HOME/install.$SCHEME_SCRIPT.ss $SPON_LIB
+$SCHEME_SCRIPT $SPON_HOME/setup.$SCHEME_SCRIPT.ss $SPON_LIB
diff --git a/install.mosh.ss b/setup.mosh.ss
similarity index 100%
rename from install.mosh.ss
rename to setup.mosh.ss
diff --git a/tools.sls b/tools.sls
index e7ff724..f9e4788 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,113 +1,125 @@
(library (spon tools)
- (export download verify decompress install
+ (export download verify decompress initialize setup install
system-name verbose? quiet? download-error? download-error-uri)
(import (rnrs)
(srfi :48)
(spon base)
(spon config)
(spon compat))
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (cmd-wget uri dir)
(or (apply do-cmd
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply do-cmd
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply do-cmd
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(spon-uri (config "spon-uri" *spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-path (config "source-path" *source-path*)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
(src-path (config "source-path" *source-path*))
(pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(src-path (config "source-path" *source-path*))
(pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
+ (define (initialize package)
+ (let* ((config (get-config))
+ (src-path (config "source-path" *source-path*))
+ (impl (current-implementation-name))
+ (install.ss (format "~A/~A/install.ss" src-path package)))
+ (do-procs
+ ("Setup package to spon's library"
+ (do-cmd impl install.ss)
+ #f
+ (format "error in ~A" install.ss)))))
+
(define (setup package)
(let* ((config (get-config))
(src-path (config "source-path" *source-path*))
(impl (current-implementation-name))
- (install.ss (format "~A/~A/install.~A.ss" src-path package impl)))
+ (setup.ss (format "~A/~A/setup.~A.ss" src-path package impl)))
(do-procs
((format "Setup package to ~A ..." impl)
- (do-cmd impl install.ss)
+ (do-cmd impl setup.ss)
#f
- (format "error in ~A/install.~A.ss" package impl)))))
+ (format "error in ~A" setup.ss)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
+ (initialize package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
83b3ffb6bb3d4c276236883b06ab44d3150e7693
|
generate config.sls
|
diff --git a/install.mosh.ss b/install.mosh.ss
index 2da14ac..320282d 100644
--- a/install.mosh.ss
+++ b/install.mosh.ss
@@ -1,32 +1,33 @@
(import (rnrs)
(mosh config)
(only (mosh process) spawn waitpid))
(define (cmd-install . args)
(let*-values (((pid . _) (spawn "install" args '(#f #f #f)))
((pid status) (waitpid pid)))
(zero? status)))
(define (mkdir dir)
- (unless (file-exists? dir)
- (cmd-install "-v" "-m" "755" "-d" dir)))
+ (cmd-install "-v" "-m" "755" "-d" dir))
(define (file-copy src dst)
- (unless (file-exists? dst)
- (cmd-install "-v" "-m" "644" src dst)))
+ (cmd-install "-v" "-m" "644" src dst))
(define (main args)
- (let ((spon-dir (cadr args))
+ (let ((spon-lib (cadr args))
(sitelib-path (string-append (get-config "library-path") "/lib")))
(mkdir (string-append sitelib-path "/spon"))
(file-copy
- (string-append spon-dir "/spon/base.sls")
+ (string-append spon-lib "/spon/base.sls")
(string-append sitelib-path "/spon/base.sls"))
(file-copy
- (string-append spon-dir "/spon/compat.mosh.sls")
+ (string-append spon-lib "/spon/compat.mosh.sls")
(string-append sitelib-path "/spon/compat.sls"))
(file-copy
- (string-append spon-dir "/spon/tools.sls")
+ (string-append spon-lib "/spon/config.sls")
+ (string-append sitelib-path "/spon/config.sls"))
+ (file-copy
+ (string-append spon-lib "/spon/tools.sls")
(string-append sitelib-path "/spon/tools.sls"))))
(main (command-line))
diff --git a/install.sh b/install.sh
index fe633de..61f661a 100755
--- a/install.sh
+++ b/install.sh
@@ -1,44 +1,63 @@
#!/bin/sh
+SED=/bin/sed
INSTALL=/usr/bin/install
SCHEME_SCRIPT=${1:-mosh}
PREFIX=${2:-/usr/local}
-SPON_COMMAND=$PREFIX/bin/spon
+SPON_URI=http://scheme-users.jp/spon
SPON_HOME=$PREFIX/share/spon
-
-$INSTALL -v -m 755 -d $SPON_HOME
-$INSTALL -v -m 755 -d $SPON_HOME/doc
-$INSTALL -v -m 755 -d $SPON_HOME/spon
+SPON_COMMAND=$PREFIX/bin/spon
+SPON_LIB=$SPON_HOME/lib
+SPON_DOC=$SPON_HOME/doc
+SPON_SRC=$SPON_HOME/src
+SPON_SHARE=$SPON_HOME/share
+SPON_TMP=/tmp
+
+$SED -e "14 c (define *spon-uri* \"$SPON_URI\")" \
+ -e "15 c (define *spon-home* \"$SPON_HOME\")" \
+ -e "16 c (define *command-path* \"$SPON_COMMAND\")" \
+ -e "17 c (define *library-path* \"$SPON_LIB\")" \
+ -e "18 c (define *document-path* \"$SPON_DOC\")" \
+ -e "19 c (define *source-path* \"$SPON_SRC\")" \
+ -e "20 c (define *share-path* \"$SPON_SHARE\")" \
+ -e "21 c (define *temporary-path* \"$SPON_TMP\")" \
+ config.tmpl.sls > config.sls
echo "#!/bin/sh" > spon.sh
case "$SCHEME_SCRIPT" in
'mosh')
echo "mosh $SPON_HOME/spon.ss \$*" >> spon.sh
;;
'ypsilon')
echo "ypsilon $SPON_HOME/spon.ss \$*" >> spon.sh
;;
*)
echo "ERROR!"
exit 1
;;
esac
+$INSTALL -v -m 755 -d $SPON_HOME
+$INSTALL -v -m 755 -d $SPON_LIB
+$INSTALL -v -m 755 -d $SPON_LIB/spon
+$INSTALL -v -m 755 -d $SPON_DOC
+$INSTALL -v -m 755 -d $SPON_SRC
+
$INSTALL -v -m 755 spon.sh $SPON_COMMAND
for f in spon.ss install.mosh.ss; do
$INSTALL -v -m 644 $f $SPON_HOME
done
for f in sponrc.sample; do
- $INSTALL -v -m 644 $f $SPON_HOME/doc
+ $INSTALL -v -m 644 $f $SPON_DOC
done
-for f in base.sls compat.sls compat.mosh.sls compat.ypsilon.sls tools.sls; do
- $INSTALL -v -m 644 $f $SPON_HOME/spon
+for f in base.sls compat.sls compat.mosh.sls compat.ypsilon.sls config.sls tools.sls; do
+ $INSTALL -v -m 644 $f $SPON_LIB/spon
done
-$SCHEME_SCRIPT $SPON_HOME/install.$SCHEME_SCRIPT.ss $SPON_HOME
+$SCHEME_SCRIPT $SPON_HOME/install.$SCHEME_SCRIPT.ss $SPON_LIB
|
higepon/spon
|
e9f1308c6b6e0860e83873a5a444365f5f59f897
|
added config.tmpl.sls
|
diff --git a/ChangeLog b/ChangeLog
index 411ae64..74696bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,36 +1,40 @@
+2009-03-17 baal <[email protected]>
+
+ * config.tmpl.sls : template for generate (spon config). used by install.sh.
+
2009-03-13 higepon <[email protected]>
* tools.sls (spon): Use down-load-erro condition. Need refactoring.
2009-02-23 leque <[email protected]>
* tools.sls: quiet external commands down when (quiet?) is #t.
* tools.sls: do not verify package by default.
2009-02-22 higepon <[email protected]>
* tools.sls (spon): Added &i/o-download.
* spon.ss (main): (quiet? #t).
2009-02-18 higepon <[email protected]>
* compat.mosh.sls (spon): Added (verbose) => #f support.
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/config.tmpl.sls b/config.tmpl.sls
new file mode 100644
index 0000000..9c18d95
--- /dev/null
+++ b/config.tmpl.sls
@@ -0,0 +1,58 @@
+(library (spon config)
+
+ (export *spon-uri* *spon-home*
+ *command-path* *library-path*
+ *document-path* *source-path*
+ *share-path* *temporary-path*
+ *config-search-path*
+ load-config get-config)
+
+ (import (rnrs)
+ (srfi :48)
+ (srfi :98))
+
+ (define *spon-uri* "http://scheme-users.jp/spon")
+ (define *spon-home* "/usr/local/share/spon")
+ (define *command-path* "/usr/local/bin/spon")
+ (define *library-path* "/usr/local/share/spon/lib")
+ (define *document-path* "/usr/local/share/spon/doc")
+ (define *source-path* "/usr/local/share/spon/src")
+ (define *share-path* "/usr/local/share/spon/share")
+ (define *temporary-path* "/tmp")
+
+ (define *config-search-path*
+ `(,@(cond
+ ((get-environment-variable "HOME")
+ => (lambda (home)
+ (list (string-append home "/.spon"))))
+ (else '()))
+ ,(string-append *spon-home* "/sponrc")
+ "/usr/share/spon/sponrc"
+ "/etc/sponrc"))
+
+ (define (load-config)
+ (let ((config (make-hashtable string-hash string=?))
+ (config-path (find file-exists? *config-search-path*)))
+ (when config-path
+ (call-with-input-file config-path
+ (lambda (in)
+ (for-each
+ (lambda (x)
+ (if (not (pair? x))
+ (error 'load-config "invalid configuration" x)
+ (hashtable-set! config (format "~A" (car x)) (cdr x))))
+ (read in)))))
+ (letrec (($ (case-lambda
+ ((key)
+ ($ key key))
+ ((key default)
+ (hashtable-ref config key default)))))
+ $)))
+
+ (define (get-config)
+ (let ((config #f))
+ (lambda x
+ (unless config
+ (set! config (load-config)))
+ (apply config x))))
+ )
diff --git a/tools.sls b/tools.sls
index 9cfcfa3..e7ff724 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,153 +1,113 @@
(library (spon tools)
(export download verify decompress install
system-name verbose? quiet? download-error? download-error-uri)
(import (rnrs)
(srfi :48)
- (srfi :98)
(spon base)
+ (spon config)
(spon compat))
- (define *default-spon-uri* "http://scheme-users.jp/spon")
- (define *default-spon-dir* "/usr/local/share/spon")
-
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
- (define *config-search-path*
- `(,@(cond
- ((get-environment-variable "HOME")
- => (lambda (home)
- (list (string-append home "/.spon"))))
- (else '()))
- "/usr/local/share/spon/sponrc"
- "/usr/share/spon/sponrc"
- "/etc/sponrc"))
-
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
- (define (load-config)
- (let ((config (make-hashtable string-hash string=?))
- (config-path (find file-exists? *config-search-path*)))
- (when config-path
- (call-with-input-file config-path
- (lambda (in)
- (for-each
- (lambda (x)
- (if (not (pair? x))
- (error 'load-config "invalid configuration" x)
- (hashtable-set! config (format "~A" (car x)) (cdr x))))
- (read in)))))
- (letrec (($ (case-lambda
- ((key)
- ($ key key))
- ((key default)
- (hashtable-ref config key default)))))
- $)))
-
- (define (get-config)
- (let ((config #f))
- (lambda x
- (unless config
- (set! config (load-config)))
- (apply config x))))
-
(define (cmd-wget uri dir)
(or (apply do-cmd
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply do-cmd
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply do-cmd
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
- (spon-dir (config "spon-dir" *default-spon-dir*))
- (spon-uri (config "spon-uri" *default-spon-uri*))
+ (spon-uri (config "spon-uri" *spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
- (src-dir (format "~A/src" spon-dir)))
+ (src-path (config "source-path" *source-path*)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
- (cmd-wget pkg-uri src-dir)
+ (cmd-wget pkg-uri src-path)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
- (cmd-wget sig-uri src-dir)
+ (cmd-wget sig-uri src-path)
(ok)))
(define (verify package)
(let* ((config (get-config))
- (spon-dir (config "spon-dir" *default-spon-dir*))
- (pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
+ (src-path (config "source-path" *source-path*))
+ (pkg-file (format "~A/~A.tar.gz" src-path package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
- (spon-dir (config "spon-dir" *default-spon-dir*))
- (pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
+ (src-path (config "source-path" *source-path*))
+ (pkg-file (format "~A/~A.tar.gz" src-path package)))
(do-procs
("Decompressing package ..."
- (cmd-tar pkg-file spon-dir)
+ (cmd-tar pkg-file src-path)
#f
"error in decompressing package"))))
(define (setup package)
(let* ((config (get-config))
- (spon-dir (config "spon-dir" *default-spon-dir*))
+ (src-path (config "source-path" *source-path*))
(impl (current-implementation-name))
- (install.ss (format "~A/~A/install.~A.ss" spon-dir package impl)))
+ (install.ss (format "~A/~A/install.~A.ss" src-path package impl)))
(do-procs
((format "Setup package to ~A ..." impl)
(do-cmd impl install.ss)
#f
(format "error in ~A/install.~A.ss" package impl)))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package)
(setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
6f2d33a52aabd4dc3529fa0e7d04df24f297978d
|
added setup procedure.
|
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 2e8a553..83ab4d3 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,25 +1,27 @@
(library (spon compat)
- (export do-cmd)
+ (export current-implementation-name do-cmd)
(import (rnrs)
(spon base)
(only (mosh process) spawn waitpid pipe))
+ (define (current-implementation-name) "mosh")
+
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
(let-values ([(pid cin cout cerr) (spawn command args (list #f out out))])
(close-port out)
(close-port in)
(waitpid pid))))
(define (do-cmd cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
-)
+ )
diff --git a/compat.sls b/compat.sls
index fd58b37..0a777ca 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,24 +1,26 @@
(library (spon compat)
- (export do-cmd)
+ (export current-implementation-name do-cmd)
(import (rnrs)
- (spon base)
- )
+ (spon base)
+ )
+
+ (define (current-implementation-name) "scheme")
;; -- do-cmd :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
(define (do-cmd cmd . args)
(raise (condition
- (make-implementation-restriction-violation)
- (make-who-condition 'do-cmd)
- (make-message-condition
+ (make-implementation-restriction-violation)
+ (make-who-condition 'do-cmd)
+ (make-message-condition
(string-append
"Compatibility layer is not implemented. "
(string-titlecase system-name)
" seems to be not supported by your implementation. "
"Please consult the author of your implementation."))
- (make-irritants-condition (cons cmd args)))))
+ (make-irritants-condition (cons cmd args)))))
)
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index 968dcd3..84cfa02 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,29 +1,31 @@
;; (verbose? #t)ã§ã¡ãã»ã¼ã¸ãåºåããã¾ã
;; tools.slsã®(srfi :48)ã¯Ypsilonã«ã¯ç¡ãã®ã§ã
;; (srfi :28)ã«ãã¦è©¦ãã¦ãã ããã
(library (spon compat)
- (export do-cmd)
+ (export current-implementation-name do-cmd)
(import (rnrs)
(spon base)
(only (core) destructuring-bind process process-wait))
+ (define (current-implementation-name) "ypsilon")
+
(define (do-cmd cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
(or status (loop (process-wait pid #t))) ; nohang = #t
(zero? status))))
(else
(zero? (process-wait pid #f)))))) ; nohang = #f
) ;[end]
diff --git a/tools.sls b/tools.sls
index 66c823d..9cfcfa3 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,142 +1,153 @@
(library (spon tools)
(export download verify decompress install
system-name verbose? quiet? download-error? download-error-uri)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-condition-type &spon &error
make-spon-error spon-error?)
(define-condition-type &download &spon
make-download-error download-error?
(uri download-error-uri))
-
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
(define (cmd-wget uri dir)
(or (apply do-cmd
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '()))
(raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply do-cmd
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply do-cmd
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (show-progress text)
(unless (quiet?)
(format #t "----> ~A" text)))
(define (ok)
(display " ok\n"))
(define (download package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
(show-progress (format "Downloading package: ~A ..." pkg-uri))
(cmd-wget pkg-uri src-dir)
(ok)
(show-progress (format "Downloading signature: ~A ..." sig-uri))
(cmd-wget sig-uri src-dir)
(ok)))
(define (verify package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file spon-dir)
#f
"error in decompressing package"))))
+ (define (setup package)
+ (let* ((config (get-config))
+ (spon-dir (config "spon-dir" *default-spon-dir*))
+ (impl (current-implementation-name))
+ (install.ss (format "~A/~A/install.~A.ss" spon-dir package impl)))
+ (do-procs
+ ((format "Setup package to ~A ..." impl)
+ (do-cmd impl install.ss)
+ #f
+ (format "error in ~A/install.~A.ss" package impl)))))
+
(define (install package)
(let ((r (and (download package)
(verify package)
- (decompress package))))
+ (decompress package)
+ (setup package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
07a5a12e3aef0c7a04780f727c481af643c6eda6
|
fix...
|
diff --git a/install.mosh.ss b/install.mosh.ss
index 76e0dfc..2da14ac 100644
--- a/install.mosh.ss
+++ b/install.mosh.ss
@@ -1,33 +1,32 @@
(import (rnrs)
(mosh config)
(only (mosh process) spawn waitpid))
(define (cmd-install . args)
(let*-values (((pid . _) (spawn "install" args '(#f #f #f)))
((pid status) (waitpid pid)))
(zero? status)))
(define (mkdir dir)
(unless (file-exists? dir)
(cmd-install "-v" "-m" "755" "-d" dir)))
(define (file-copy src dst)
(unless (file-exists? dst)
(cmd-install "-v" "-m" "644" src dst)))
(define (main args)
- (display args) (newline)
- #;(let ((spon-dir (cadr args))
+ (let ((spon-dir (cadr args))
(sitelib-path (string-append (get-config "library-path") "/lib")))
(mkdir (string-append sitelib-path "/spon"))
(file-copy
(string-append spon-dir "/spon/base.sls")
(string-append sitelib-path "/spon/base.sls"))
(file-copy
(string-append spon-dir "/spon/compat.mosh.sls")
(string-append sitelib-path "/spon/compat.sls"))
(file-copy
(string-append spon-dir "/spon/tools.sls")
(string-append sitelib-path "/spon/tools.sls"))))
(main (command-line))
|
higepon/spon
|
59e0e3da4dc88d47fd90eb676403ad5c189f6dd4
|
added install.mosh.ss
|
diff --git a/install.mosh.ss b/install.mosh.ss
new file mode 100644
index 0000000..76e0dfc
--- /dev/null
+++ b/install.mosh.ss
@@ -0,0 +1,33 @@
+(import (rnrs)
+ (mosh config)
+ (only (mosh process) spawn waitpid))
+
+(define (cmd-install . args)
+ (let*-values (((pid . _) (spawn "install" args '(#f #f #f)))
+ ((pid status) (waitpid pid)))
+ (zero? status)))
+
+(define (mkdir dir)
+ (unless (file-exists? dir)
+ (cmd-install "-v" "-m" "755" "-d" dir)))
+
+(define (file-copy src dst)
+ (unless (file-exists? dst)
+ (cmd-install "-v" "-m" "644" src dst)))
+
+(define (main args)
+ (display args) (newline)
+ #;(let ((spon-dir (cadr args))
+ (sitelib-path (string-append (get-config "library-path") "/lib")))
+ (mkdir (string-append sitelib-path "/spon"))
+ (file-copy
+ (string-append spon-dir "/spon/base.sls")
+ (string-append sitelib-path "/spon/base.sls"))
+ (file-copy
+ (string-append spon-dir "/spon/compat.mosh.sls")
+ (string-append sitelib-path "/spon/compat.sls"))
+ (file-copy
+ (string-append spon-dir "/spon/tools.sls")
+ (string-append sitelib-path "/spon/tools.sls"))))
+
+(main (command-line))
diff --git a/install.sh b/install.sh
index 53c0495..fe633de 100755
--- a/install.sh
+++ b/install.sh
@@ -1,41 +1,44 @@
#!/bin/sh
+
INSTALL=/usr/bin/install
SCHEME_SCRIPT=${1:-mosh}
PREFIX=${2:-/usr/local}
SPON_COMMAND=$PREFIX/bin/spon
SPON_HOME=$PREFIX/share/spon
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_HOME/doc
$INSTALL -v -m 755 -d $SPON_HOME/spon
echo "#!/bin/sh" > spon.sh
case "$SCHEME_SCRIPT" in
'mosh')
- echo "mosh --loadpath=$SPON_HOME $SPON_HOME/spon.ss \$*" >> spon.sh
+ echo "mosh $SPON_HOME/spon.ss \$*" >> spon.sh
;;
'ypsilon')
- echo "ypsilon --sitelib=$SPON_HOME $SPON_HOME/spon.ss \$*" >> spon.sh
+ echo "ypsilon $SPON_HOME/spon.ss \$*" >> spon.sh
;;
*)
echo "ERROR!"
exit 1
;;
esac
$INSTALL -v -m 755 spon.sh $SPON_COMMAND
-for f in spon.ss; do
+for f in spon.ss install.mosh.ss; do
$INSTALL -v -m 644 $f $SPON_HOME
done
for f in sponrc.sample; do
$INSTALL -v -m 644 $f $SPON_HOME/doc
done
for f in base.sls compat.sls compat.mosh.sls compat.ypsilon.sls tools.sls; do
$INSTALL -v -m 644 $f $SPON_HOME/spon
done
+
+$SCHEME_SCRIPT $SPON_HOME/install.$SCHEME_SCRIPT.ss $SPON_HOME
|
higepon/spon
|
3cffbde681f2cc152e37348c49693ea684ffe949
|
Use down-load-erro condition. Need refactoring.
|
diff --git a/ChangeLog b/ChangeLog
index ab0bfe8..411ae64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,32 +1,36 @@
+2009-03-13 higepon <[email protected]>
+
+ * tools.sls (spon): Use down-load-erro condition. Need refactoring.
+
2009-02-23 leque <[email protected]>
* tools.sls: quiet external commands down when (quiet?) is #t.
* tools.sls: do not verify package by default.
2009-02-22 higepon <[email protected]>
* tools.sls (spon): Added &i/o-download.
* spon.ss (main): (quiet? #t).
2009-02-18 higepon <[email protected]>
* compat.mosh.sls (spon): Added (verbose) => #f support.
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/spon.ss b/spon.ss
index 365a309..b54de39 100644
--- a/spon.ss
+++ b/spon.ss
@@ -1,22 +1,26 @@
(import (rnrs)
(srfi :39)
(srfi :48)
(spon tools))
(define (main args)
(cond
[(null? (cdr args))
(display (format "ERROR ~a: package name not specified\n" system-name)
(current-error-port))
(exit #f)]
[else
- (parameterize ((verbose? #t))
+ (parameterize ((verbose? #f))
+ (guard (exception
+ [(download-error? exception)
+ (format (current-error-port) "\n failed to download package ~a.\n" (download-error-uri exception))]
+ [else (raise exception)])
(cond
((install (cadr args))
(exit))
(else
(display (format "ERROR ~A: install failed\n" system-name)
(current-error-port))
- (exit #f))))]))
+ (exit #f))))])))
(main (command-line))
diff --git a/tools.sls b/tools.sls
index c1293c0..66c823d 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,132 +1,142 @@
(library (spon tools)
(export download verify decompress install
- system-name verbose? quiet?)
+ system-name verbose? quiet? download-error? download-error-uri)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
- (define-condition-type &i/o-download &i/o-read
- make-i/o-download-error i/o-download-error?)
+ (define-condition-type &spon &error
+ make-spon-error spon-error?)
+
+ (define-condition-type &download &spon
+ make-download-error download-error?
+ (uri download-error-uri))
+
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
(define (cmd-wget uri dir)
- (apply do-cmd
- ((get-config) "wget")
- "-N" "-P" dir uri (if (quiet?) '("-q") '())))
+ (or (apply do-cmd
+ ((get-config) "wget")
+ "-N" "-P" dir uri (if (quiet?) '("-q") '()))
+ (raise (make-download-error uri))))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply do-cmd
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply do-cmd
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
+ (define (show-progress text)
+ (unless (quiet?)
+ (format #t "----> ~A" text)))
+
+ (define (ok)
+ (display " ok\n"))
+
(define (download package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
- (do-procs
- ((format "Downloading package: ~A ..." pkg-uri)
- (cmd-wget pkg-uri src-dir)
- #f
- "failed to download package.")
- ((format "Downloading signature: ~A ..." sig-uri)
- (cmd-wget sig-uri src-dir)
- #f
- "failed to download signature."))))
+ (show-progress (format "Downloading package: ~A ..." pkg-uri))
+ (cmd-wget pkg-uri src-dir)
+ (ok)
+ (show-progress (format "Downloading signature: ~A ..." sig-uri))
+ (cmd-wget sig-uri src-dir)
+ (ok)))
(define (verify package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
(or (not (config "gpg" #f))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file spon-dir)
#f
"error in decompressing package"))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
5a039beb18b2836495e7410eab7fecf03c54c488
|
refactor.
|
diff --git a/install.sh b/install.sh
index a57bf24..53c0495 100755
--- a/install.sh
+++ b/install.sh
@@ -1,36 +1,41 @@
-#!/bin/bash
-
-SPON_COMMAND=/usr/local/bin/spon
-SPON_HOME=/usr/local/share/spon
+#!/bin/sh
+INSTALL=/usr/bin/install
-SCHEME=mosh
-#SCHEME=ypsilon
+SCHEME_SCRIPT=${1:-mosh}
+PREFIX=${2:-/usr/local}
-INSTALL=/usr/bin/install
+SPON_COMMAND=$PREFIX/bin/spon
+SPON_HOME=$PREFIX/share/spon
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_HOME/doc
$INSTALL -v -m 755 -d $SPON_HOME/spon
-$INSTALL -v -m 644 spon.ss $SPON_HOME
-$INSTALL -v -m 644 sponrc.sample $SPON_HOME/doc
-
-$INSTALL -v -m 644 base.sls $SPON_HOME/spon
-$INSTALL -v -m 644 compat.sls $SPON_HOME/spon
-$INSTALL -v -m 644 compat.mosh.sls $SPON_HOME/spon
-$INSTALL -v -m 644 compat.ypsilon.sls $SPON_HOME/spon
-$INSTALL -v -m 644 tools.sls $SPON_HOME/spon
+echo "#!/bin/sh" > spon.sh
-case "$SCHEME" in
+case "$SCHEME_SCRIPT" in
'mosh')
- echo -e "#!/bin/bash\nmosh --loadpath=$SPON_HOME $SPON_HOME/spon.ss \$*" > spon.sh
- $INSTALL -v -D -m 755 spon.sh $SPON_COMMAND
+ echo "mosh --loadpath=$SPON_HOME $SPON_HOME/spon.ss \$*" >> spon.sh
;;
'ypsilon')
- echo -e "#!/bin/bash\nypsilon --sitelib=$SPON_HOME $SPON_HOME/spon.ss \$*" > spon.sh
- $INSTALL -v -D -m 755 spon.sh $SPON_COMMAND
+ echo "ypsilon --sitelib=$SPON_HOME $SPON_HOME/spon.ss \$*" >> spon.sh
;;
*)
echo "ERROR!"
+ exit 1
;;
esac
+
+$INSTALL -v -m 755 spon.sh $SPON_COMMAND
+
+for f in spon.ss; do
+ $INSTALL -v -m 644 $f $SPON_HOME
+done
+
+for f in sponrc.sample; do
+ $INSTALL -v -m 644 $f $SPON_HOME/doc
+done
+
+for f in base.sls compat.sls compat.mosh.sls compat.ypsilon.sls tools.sls; do
+ $INSTALL -v -m 644 $f $SPON_HOME/spon
+done
diff --git a/spon.ss b/spon.ss
index 2134de8..365a309 100644
--- a/spon.ss
+++ b/spon.ss
@@ -1,16 +1,22 @@
(import (rnrs)
- (srfi :48)
(srfi :39)
+ (srfi :48)
(spon tools))
(define (main args)
(cond
[(null? (cdr args))
- (display (format "ERROR ~a: package name not specified\n" system-name) (current-error-port))
- (exit -1)]
+ (display (format "ERROR ~a: package name not specified\n" system-name)
+ (current-error-port))
+ (exit #f)]
[else
- (parameterize ((quiet? #t))
- (install (string->symbol (cadr args)))
- (exit 0))]))
+ (parameterize ((verbose? #t))
+ (cond
+ ((install (cadr args))
+ (exit))
+ (else
+ (display (format "ERROR ~A: install failed\n" system-name)
+ (current-error-port))
+ (exit #f))))]))
(main (command-line))
|
higepon/spon
|
b033468fa8e83d31cb1db875598cf9e0d2435da8
|
fix install script
|
diff --git a/install.sh b/install.sh
index c514e0b..a57bf24 100755
--- a/install.sh
+++ b/install.sh
@@ -1,38 +1,36 @@
#!/bin/bash
SPON_COMMAND=/usr/local/bin/spon
SPON_HOME=/usr/local/share/spon
SCHEME=mosh
#SCHEME=ypsilon
INSTALL=/usr/bin/install
$INSTALL -v -m 755 -d $SPON_HOME
$INSTALL -v -m 755 -d $SPON_HOME/doc
$INSTALL -v -m 755 -d $SPON_HOME/spon
$INSTALL -v -m 644 spon.ss $SPON_HOME
$INSTALL -v -m 644 sponrc.sample $SPON_HOME/doc
$INSTALL -v -m 644 base.sls $SPON_HOME/spon
$INSTALL -v -m 644 compat.sls $SPON_HOME/spon
$INSTALL -v -m 644 compat.mosh.sls $SPON_HOME/spon
$INSTALL -v -m 644 compat.ypsilon.sls $SPON_HOME/spon
$INSTALL -v -m 644 tools.sls $SPON_HOME/spon
case "$SCHEME" in
'mosh')
- echo "#!/bin/bash" > spon.sh
- echo "mosh --loadpath=$SPON_HOME $SPON_HOME/spon.ss" >> spon.sh
+ echo -e "#!/bin/bash\nmosh --loadpath=$SPON_HOME $SPON_HOME/spon.ss \$*" > spon.sh
$INSTALL -v -D -m 755 spon.sh $SPON_COMMAND
;;
'ypsilon')
- echo "#!/bin/bash" > spon.sh
- echo "ypsilon --sitelib=$SPON_HOME $SPON_HOME/spon.ss" >> spon.sh
+ echo -e "#!/bin/bash\nypsilon --sitelib=$SPON_HOME $SPON_HOME/spon.ss \$*" > spon.sh
$INSTALL -v -D -m 755 spon.sh $SPON_COMMAND
;;
*)
echo "ERROR!"
;;
esac
|
higepon/spon
|
cfa1dd742440fccb57989fd6105a3d9ad2a9b0c3
|
add install script
|
diff --git a/install.sh b/install.sh
new file mode 100755
index 0000000..c514e0b
--- /dev/null
+++ b/install.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+SPON_COMMAND=/usr/local/bin/spon
+SPON_HOME=/usr/local/share/spon
+
+SCHEME=mosh
+#SCHEME=ypsilon
+
+INSTALL=/usr/bin/install
+
+$INSTALL -v -m 755 -d $SPON_HOME
+$INSTALL -v -m 755 -d $SPON_HOME/doc
+$INSTALL -v -m 755 -d $SPON_HOME/spon
+
+$INSTALL -v -m 644 spon.ss $SPON_HOME
+$INSTALL -v -m 644 sponrc.sample $SPON_HOME/doc
+
+$INSTALL -v -m 644 base.sls $SPON_HOME/spon
+$INSTALL -v -m 644 compat.sls $SPON_HOME/spon
+$INSTALL -v -m 644 compat.mosh.sls $SPON_HOME/spon
+$INSTALL -v -m 644 compat.ypsilon.sls $SPON_HOME/spon
+$INSTALL -v -m 644 tools.sls $SPON_HOME/spon
+
+case "$SCHEME" in
+ 'mosh')
+ echo "#!/bin/bash" > spon.sh
+ echo "mosh --loadpath=$SPON_HOME $SPON_HOME/spon.ss" >> spon.sh
+ $INSTALL -v -D -m 755 spon.sh $SPON_COMMAND
+ ;;
+ 'ypsilon')
+ echo "#!/bin/bash" > spon.sh
+ echo "ypsilon --sitelib=$SPON_HOME $SPON_HOME/spon.ss" >> spon.sh
+ $INSTALL -v -D -m 755 spon.sh $SPON_COMMAND
+ ;;
+ *)
+ echo "ERROR!"
+ ;;
+esac
|
higepon/spon
|
85744da9a2b4c88cf6f4584f95f46f22c64a4202
|
fix to always return boolean.
|
diff --git a/tools.sls b/tools.sls
index 4f1c0f1..c1293c0 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,132 +1,132 @@
(library (spon tools)
(export download verify decompress install
system-name verbose? quiet?)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-condition-type &i/o-download &i/o-read
make-i/o-download-error i/o-download-error?)
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
(define (cmd-wget uri dir)
(apply do-cmd
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '())))
(define (cmd-gpg signature file)
(let ((gpg ((get-config) "gpg" #f)))
(or (not gpg)
(apply do-cmd
gpg
`(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply do-cmd
((get-config) "tar")
"-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (download package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(cmd-wget pkg-uri src-dir)
#f
"failed to download package.")
((format "Downloading signature: ~A ..." sig-uri)
(cmd-wget sig-uri src-dir)
#f
"failed to download signature."))))
(define (verify package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
- (when (config "gpg" #f)
- (do-procs
- ("Veryfying package ..."
- (cmd-gpg sig-file pkg-file)
- #f
- "cannot verify package.")))))
+ (or (not (config "gpg" #f))
+ (do-procs
+ ("Veryfying package ..."
+ (cmd-gpg sig-file pkg-file)
+ #f
+ "cannot verify package.")))))
(define (decompress package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file spon-dir)
#f
"error in decompressing package"))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
e30593abacd2c7fabe2d92789eb6498c5a75d400
|
documentation.
|
diff --git a/ChangeLog b/ChangeLog
index 4866528..ab0bfe8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,32 +1,32 @@
2009-02-23 leque <[email protected]>
* tools.sls: quiet external commands down when (quiet?) is #t.
- * tools.sls: do not verify package in default.
+ * tools.sls: do not verify package by default.
2009-02-22 higepon <[email protected]>
* tools.sls (spon): Added &i/o-download.
* spon.ss (main): (quiet? #t).
2009-02-18 higepon <[email protected]>
* compat.mosh.sls (spon): Added (verbose) => #f support.
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/sponrc.sample b/sponrc.sample
index 5211959..af2fdf7 100644
--- a/sponrc.sample
+++ b/sponrc.sample
@@ -1,14 +1,18 @@
;; -*- mode: scheme -*-
;; vim:ft=scheme
(
;; the path to wget command
+ ;; default: "wget"
(wget . "/usr/local/bin/wget")
;; the path to gpg command
+ ;; When this value is #f, verification is not executed.
+ ;; default: #f
(gpg . "/opt/local/bin/gpg")
;; the path to tar command
+ ;; default: "tar"
(tar . "/usr/bin/tar")
;; the path where packages are installed
(spon-dir . "/usr/local/share/spon")
;; the URI of the repository
(spon-uri . "http://scheme-users.jp/spon")
)
|
higepon/spon
|
d0c0f128d543edeced5b8b4ecb130e8528804020
|
do not verify package in default.
|
diff --git a/ChangeLog b/ChangeLog
index 8a9cd60..4866528 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,30 +1,32 @@
2009-02-23 leque <[email protected]>
* tools.sls: quiet external commands down when (quiet?) is #t.
+ * tools.sls: do not verify package in default.
+
2009-02-22 higepon <[email protected]>
* tools.sls (spon): Added &i/o-download.
* spon.ss (main): (quiet? #t).
2009-02-18 higepon <[email protected]>
* compat.mosh.sls (spon): Added (verbose) => #f support.
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/tools.sls b/tools.sls
index f9f0c09..af82d2b 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,129 +1,131 @@
(library (spon tools)
(export download verify decompress install
system-name verbose? quiet?)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-condition-type &i/o-download &i/o-read
make-i/o-download-error i/o-download-error?)
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
(define (cmd-wget uri dir)
(apply do-cmd
((get-config) "wget")
"-N" "-P" dir uri (if (quiet?) '("-q") '())))
(define (cmd-gpg signature file)
- (apply do-cmd
- ((get-config) "gpg")
- `(,@(if (quiet?) '("-q") '()) "--verify" signature file)))
+ (let ((gpg ((get-config) "gpg" #f)))
+ (or (not gpg)
+ (apply do-cmd
+ gpg
+ `(,@(if (quiet?) '("-q") '()) "--verify" signature file)))))
(define (cmd-tar file dir)
(apply do-cmd
((get-config) "tar")
- "-xzf" file "-C" dir (if (quiet?) '() ("-v"))))
+ "-xzf" file "-C" dir (if (quiet?) '() '("-v"))))
(define (download package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(cmd-wget pkg-uri src-dir)
#f
"failed to download package.")
((format "Downloading signature: ~A ..." sig-uri)
(cmd-wget sig-uri src-dir)
#f
"failed to download signature."))))
(define (verify package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package."))))
(define (decompress package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file spon-dir)
#f
"error in decompressing package"))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
6360a2335bd65f110689da43b5c445c10e4ae9a7
|
quiet external commands down when (quiet?) is #t.
|
diff --git a/ChangeLog b/ChangeLog
index 3c52d03..8a9cd60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,26 +1,30 @@
+2009-02-23 leque <[email protected]>
+
+ * tools.sls: quiet external commands down when (quiet?) is #t.
+
2009-02-22 higepon <[email protected]>
* tools.sls (spon): Added &i/o-download.
* spon.ss (main): (quiet? #t).
2009-02-18 higepon <[email protected]>
* compat.mosh.sls (spon): Added (verbose) => #f support.
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/tools.sls b/tools.sls
index 027fa81..f9f0c09 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,123 +1,129 @@
(library (spon tools)
(export download verify decompress install
system-name verbose? quiet?)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-condition-type &i/o-download &i/o-read
make-i/o-download-error i/o-download-error?)
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
(define (cmd-wget uri dir)
- (do-cmd ((get-config) "wget") "-N" "-P" dir uri))
+ (apply do-cmd
+ ((get-config) "wget")
+ "-N" "-P" dir uri (if (quiet?) '("-q") '())))
(define (cmd-gpg signature file)
- (do-cmd ((get-config) "gpg") "--verify" signature file))
+ (apply do-cmd
+ ((get-config) "gpg")
+ `(,@(if (quiet?) '("-q") '()) "--verify" signature file)))
(define (cmd-tar file dir)
- (do-cmd ((get-config) "tar") "-xvzf" file "-C" dir))
+ (apply do-cmd
+ ((get-config) "tar")
+ "-xzf" file "-C" dir (if (quiet?) '() ("-v"))))
(define (download package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(cmd-wget pkg-uri src-dir)
#f
"failed to download package.")
((format "Downloading signature: ~A ..." sig-uri)
(cmd-wget sig-uri src-dir)
#f
"failed to download signature."))))
(define (verify package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package."))))
(define (decompress package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file spon-dir)
#f
"error in decompressing package"))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
8dac71892208d981b027dff2f8e67e662eb28a62
|
added donwload-error
|
diff --git a/ChangeLog b/ChangeLog
index ee1d807..3c52d03 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,20 +1,26 @@
+2009-02-22 higepon <[email protected]>
+
+ * tools.sls (spon): Added &i/o-download.
+
+ * spon.ss (main): (quiet? #t).
+
2009-02-18 higepon <[email protected]>
* compat.mosh.sls (spon): Added (verbose) => #f support.
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 68b3c12..2e8a553 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,25 +1,25 @@
(library (spon compat)
(export do-cmd)
(import (rnrs)
(spon base)
(only (mosh process) spawn waitpid pipe))
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
- (let-values ([(pid cin cout cerr) (spawn command args (list #f out #f))])
+ (let-values ([(pid cin cout cerr) (spawn command args (list #f out out))])
(close-port out)
(close-port in)
(waitpid pid))))
(define (do-cmd cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
)
diff --git a/spon.ss b/spon.ss
index bb625ee..2134de8 100644
--- a/spon.ss
+++ b/spon.ss
@@ -1,14 +1,16 @@
(import (rnrs)
(srfi :48)
+ (srfi :39)
(spon tools))
(define (main args)
(cond
[(null? (cdr args))
(display (format "ERROR ~a: package name not specified\n" system-name) (current-error-port))
(exit -1)]
[else
- (install (string->symbol (cadr args)))
- (exit 0)]))
+ (parameterize ((quiet? #t))
+ (install (string->symbol (cadr args)))
+ (exit 0))]))
(main (command-line))
diff --git a/tools.sls b/tools.sls
index 7f67ad6..027fa81 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,120 +1,123 @@
(library (spon tools)
(export download verify decompress install
system-name verbose? quiet?)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
+ (define-condition-type &i/o-download &i/o-read
+ make-i/o-download-error i/o-download-error?)
+
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(unless (quiet?)
(format #t "----> ~A~%" pre))
(let ((res cmd))
(unless (quiet?)
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
(define (cmd-wget uri dir)
(do-cmd ((get-config) "wget") "-N" "-P" dir uri))
(define (cmd-gpg signature file)
(do-cmd ((get-config) "gpg") "--verify" signature file))
(define (cmd-tar file dir)
(do-cmd ((get-config) "tar") "-xvzf" file "-C" dir))
(define (download package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(cmd-wget pkg-uri src-dir)
#f
"failed to download package.")
((format "Downloading signature: ~A ..." sig-uri)
(cmd-wget sig-uri src-dir)
#f
"failed to download signature."))))
(define (verify package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package."))))
(define (decompress package)
(let* ((config (get-config))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file spon-dir)
#f
"error in decompressing package"))))
(define (install package)
(let ((r (and (download package)
(verify package)
(decompress package))))
(unless (quiet?)
(if r
(format #t "----> ~A is successfully installed.~%" package)
(format #t "----> ~A install failed.~%" package)))
r))
)
|
higepon/spon
|
4e85c7b3c4cecaa4f5e4e868c15d9608228561cd
|
parameterize (quiet?).
|
diff --git a/base.sls b/base.sls
index ad5edbe..6709d84 100644
--- a/base.sls
+++ b/base.sls
@@ -1,8 +1,16 @@
(library (spon base)
- (export verbose? system-name)
+ (export system-name verbose? quiet?)
(import (rnrs)
(srfi :39))
(define system-name "spon")
+
(define verbose? (make-parameter #f))
+
+ ;; (quiet? #t) implies (verbose? #f).
+ (define quiet? (make-parameter #f
+ (lambda (v)
+ (when v
+ (verbose? #f))
+ v)))
)
diff --git a/tools.sls b/tools.sls
index d21a3de..7f67ad6 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,168 +1,120 @@
(library (spon tools)
- (export download verify decompress install)
+ (export download verify decompress install
+ system-name verbose? quiet?)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
- (format #t "----> ~A~%" pre)
+ (unless (quiet?)
+ (format #t "----> ~A~%" pre))
(let ((res cmd))
- (if res
- (when ok
- (format #t "----> ~A~%" ok))
- (format #t "----> ERROR: ~A~%" ng))
+ (unless (quiet?)
+ (if res
+ (when ok
+ (format #t "----> ~A~%" ok))
+ (format #t "----> ERROR: ~A~%" ng)))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
- (define (get-options options-list)
- (let ((options (make-hashtable string-hash string=?)))
- (for-each
- (lambda (op)
- (if (pair? op)
- (hashtable-set! options (format "~A" (car op)) (cdr op))
- (hashtable-set! options (format "~A" op) #t)))
- options-list)
- (lambda (key default)
- (hashtable-ref options key default))))
-
- (define (get-message-level options)
- (cond
- ((options "verbose" #f) 'verbose)
- ((options "silent" #f) 'silent)
- ((options "quiet" #f) 'silent)
- (else 'normal)))
-
(define (cmd-wget uri dir)
(do-cmd ((get-config) "wget") "-N" "-P" dir uri))
(define (cmd-gpg signature file)
(do-cmd ((get-config) "gpg") "--verify" signature file))
(define (cmd-tar file dir)
(do-cmd ((get-config) "tar") "-xvzf" file "-C" dir))
- (define (download package . options-list)
+ (define (download package)
(let* ((config (get-config))
- (options (get-options options-list))
- (msg-lvl (get-message-level options))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
- (cond
- ((eq? msg-lvl 'silent) (verbose? #f))
- ((eq? msg-lvl 'normal) (verbose? #f))
- ((eq? msg-lvl 'verbose) (verbose? #t)))
- (cond
- ((eq? msg-lvl 'silent)
- (and
- (cmd-wget pkg-uri src-dir)
- (cmd-wget sig-uri src-dir)))
- (else
- (do-procs
- ((format "Downloading package: ~A ..." pkg-uri)
- (cmd-wget pkg-uri src-dir)
- #f
- "failed to download package.")
- ((format "Downloading signature: ~A ..." sig-uri)
- (cmd-wget sig-uri src-dir)
- #f
- "failed to download signature."))))))
+ (do-procs
+ ((format "Downloading package: ~A ..." pkg-uri)
+ (cmd-wget pkg-uri src-dir)
+ #f
+ "failed to download package.")
+ ((format "Downloading signature: ~A ..." sig-uri)
+ (cmd-wget sig-uri src-dir)
+ #f
+ "failed to download signature."))))
- (define (verify package . options-list)
+ (define (verify package)
(let* ((config (get-config))
- (options (get-options options-list))
- (msg-lvl (get-message-level options))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
- (cond
- ((eq? msg-lvl 'silent) (verbose? #f))
- ((eq? msg-lvl 'normal) (verbose? #f))
- ((eq? msg-lvl 'verbose) (verbose? #t)))
- (cond
- ((eq? msg-lvl 'silent)
- (cmd-gpg sig-file pkg-file))
- (else
- (do-procs
- ("Veryfying package ..."
- (cmd-gpg sig-file pkg-file)
- #f
- "cannot verify package."))))))
+ (do-procs
+ ("Veryfying package ..."
+ (cmd-gpg sig-file pkg-file)
+ #f
+ "cannot verify package."))))
- (define (decompress package . options-list)
+ (define (decompress package)
(let* ((config (get-config))
- (options (get-options options-list))
- (msg-lvl (get-message-level options))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
- (cond
- ((eq? msg-lvl 'silent) (verbose? #f))
- ((eq? msg-lvl 'normal) (verbose? #f))
- ((eq? msg-lvl 'verbose) (verbose? #t)))
- (cond
- ((eq? msg-lvl 'silent)
- (cmd-tar pkg-file spon-dir))
- (else
- (do-procs
- ("Decompressing package ..."
- (cmd-tar pkg-file spon-dir)
- #f
- "error in decompressing package"))))))
+ (do-procs
+ ("Decompressing package ..."
+ (cmd-tar pkg-file spon-dir)
+ #f
+ "error in decompressing package"))))
- (define (install package . options-list)
- (let ((msg-lvl (get-message-level (get-options options-list))))
- (let ((r (and (apply download package options-list)
- (apply verify package options-list)
- (apply decompress package options-list))))
- (when (or (eq? msg-lvl 'normal) (eq? msg-lvl 'verbose))
- (if r
- (format #t "----> ~A is successfully installed.~%" package)
- (format #t "----> ~A install failed.~%" package)))
- r)))
+ (define (install package)
+ (let ((r (and (download package)
+ (verify package)
+ (decompress package))))
+ (unless (quiet?)
+ (if r
+ (format #t "----> ~A is successfully installed.~%" package)
+ (format #t "----> ~A install failed.~%" package)))
+ r))
)
|
higepon/spon
|
31b8c7db26c8a9742da3a0d1e647d97f27b3f818
|
verbose/silent options
|
diff --git a/tools.sls b/tools.sls
index 7798726..d21a3de 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,130 +1,168 @@
(library (spon tools)
(export download verify decompress install)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(format #t "----> ~A~%" pre)
(let ((res cmd))
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
(unless config
(set! config (load-config)))
(apply config x))))
(define (get-options options-list)
(let ((options (make-hashtable string-hash string=?)))
(for-each
(lambda (op)
(if (pair? op)
(hashtable-set! options (format "~A" (car op)) (cdr op))
(hashtable-set! options (format "~A" op) #t)))
options-list)
(lambda (key default)
(hashtable-ref options key default))))
+ (define (get-message-level options)
+ (cond
+ ((options "verbose" #f) 'verbose)
+ ((options "silent" #f) 'silent)
+ ((options "quiet" #f) 'silent)
+ (else 'normal)))
+
(define (cmd-wget uri dir)
(do-cmd ((get-config) "wget") "-N" "-P" dir uri))
(define (cmd-gpg signature file)
(do-cmd ((get-config) "gpg") "--verify" signature file))
(define (cmd-tar file dir)
(do-cmd ((get-config) "tar") "-xvzf" file "-C" dir))
(define (download package . options-list)
(let* ((config (get-config))
(options (get-options options-list))
+ (msg-lvl (get-message-level options))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
(pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
- (do-procs
- ((format "Downloading package: ~A ..." pkg-uri)
- (cmd-wget pkg-uri src-dir)
- #f
- "failed to download package.")
- ((format "Downloading signature: ~A ..." sig-uri)
- (cmd-wget sig-uri src-dir)
- #f
- "failed to download signature."))))
+ (cond
+ ((eq? msg-lvl 'silent) (verbose? #f))
+ ((eq? msg-lvl 'normal) (verbose? #f))
+ ((eq? msg-lvl 'verbose) (verbose? #t)))
+ (cond
+ ((eq? msg-lvl 'silent)
+ (and
+ (cmd-wget pkg-uri src-dir)
+ (cmd-wget sig-uri src-dir)))
+ (else
+ (do-procs
+ ((format "Downloading package: ~A ..." pkg-uri)
+ (cmd-wget pkg-uri src-dir)
+ #f
+ "failed to download package.")
+ ((format "Downloading signature: ~A ..." sig-uri)
+ (cmd-wget sig-uri src-dir)
+ #f
+ "failed to download signature."))))))
(define (verify package . options-list)
(let* ((config (get-config))
(options (get-options options-list))
+ (msg-lvl (get-message-level options))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
- (do-procs
- ("Veryfying package ..."
- (cmd-gpg sig-file pkg-file)
- #f
- "cannot verify package."))))
+ (cond
+ ((eq? msg-lvl 'silent) (verbose? #f))
+ ((eq? msg-lvl 'normal) (verbose? #f))
+ ((eq? msg-lvl 'verbose) (verbose? #t)))
+ (cond
+ ((eq? msg-lvl 'silent)
+ (cmd-gpg sig-file pkg-file))
+ (else
+ (do-procs
+ ("Veryfying package ..."
+ (cmd-gpg sig-file pkg-file)
+ #f
+ "cannot verify package."))))))
(define (decompress package . options-list)
(let* ((config (get-config))
(options (get-options options-list))
+ (msg-lvl (get-message-level options))
(spon-dir (config "spon-dir" *default-spon-dir*))
(pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
- (do-procs
- ("Decompressing package ..."
- (cmd-tar pkg-file spon-dir)
- #f
- "error in decompressing package"))))
+ (cond
+ ((eq? msg-lvl 'silent) (verbose? #f))
+ ((eq? msg-lvl 'normal) (verbose? #f))
+ ((eq? msg-lvl 'verbose) (verbose? #t)))
+ (cond
+ ((eq? msg-lvl 'silent)
+ (cmd-tar pkg-file spon-dir))
+ (else
+ (do-procs
+ ("Decompressing package ..."
+ (cmd-tar pkg-file spon-dir)
+ #f
+ "error in decompressing package"))))))
(define (install package . options-list)
- (let ((r (and (apply download package options-list)
- (apply verify package options-list)
- (apply decompress package options-list))))
- (if r
- (format #t "----> ~A is successfully installed.~%" package)
- (format #t "----> ~A install failed.~%" package))
- r))
+ (let ((msg-lvl (get-message-level (get-options options-list))))
+ (let ((r (and (apply download package options-list)
+ (apply verify package options-list)
+ (apply decompress package options-list))))
+ (when (or (eq? msg-lvl 'normal) (eq? msg-lvl 'verbose))
+ (if r
+ (format #t "----> ~A is successfully installed.~%" package)
+ (format #t "----> ~A install failed.~%" package)))
+ r)))
)
|
higepon/spon
|
6e3c6f077967182454d482fc12c43ceabc81f045
|
refactor.
|
diff --git a/tools.sls b/tools.sls
index 8830038..7798726 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,136 +1,130 @@
(library (spon tools)
(export download verify decompress install)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(format #t "----> ~A~%" pre)
(let ((res cmd))
(if res
(when ok
(format #t "----> ~A~%" ok))
(format #t "----> ERROR: ~A~%" ng))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (get-config)
(let ((config #f))
(lambda x
- (when (not config)
- (set! config (load-config)))
+ (unless config
+ (set! config (load-config)))
(apply config x))))
(define (get-options options-list)
(let ((options (make-hashtable string-hash string=?)))
(for-each
(lambda (op)
(if (pair? op)
(hashtable-set! options (format "~A" (car op)) (cdr op))
(hashtable-set! options (format "~A" op) #t)))
options-list)
(lambda (key default)
(hashtable-ref options key default))))
(define (cmd-wget uri dir)
(do-cmd ((get-config) "wget") "-N" "-P" dir uri))
(define (cmd-gpg signature file)
(do-cmd ((get-config) "gpg") "--verify" signature file))
(define (cmd-tar file dir)
(do-cmd ((get-config) "tar") "-xvzf" file "-C" dir))
(define (download package . options-list)
(let* ((config (get-config))
(options (get-options options-list))
(spon-dir (config "spon-dir" *default-spon-dir*))
(spon-uri (config "spon-uri" *default-spon-uri*))
- (arc-name (format "~A.tar.gz" package))
- (pkg-uri (format "~A/~A" spon-uri arc-name))
+ (pkg-uri (format "~A/~A.tar.gz" spon-uri package))
(sig-uri (format "~A.asc" pkg-uri))
(src-dir (format "~A/src" spon-dir)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(cmd-wget pkg-uri src-dir)
#f
"failed to download package.")
((format "Downloading signature: ~A ..." sig-uri)
(cmd-wget sig-uri src-dir)
#f
"failed to download signature."))))
(define (verify package . options-list)
(let* ((config (get-config))
(options (get-options options-list))
(spon-dir (config "spon-dir" *default-spon-dir*))
- (src-dir (format "~A/src" spon-dir))
- (arc-name (format "~A.tar.gz" package))
- (pkg-file (format "~A/~A" src-dir arc-name))
+ (pkg-file (format "~A/src/~A.tar.gz" spon-dir package))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
("Veryfying package ..."
(cmd-gpg sig-file pkg-file)
#f
"cannot verify package."))))
(define (decompress package . options-list)
(let* ((config (get-config))
(options (get-options options-list))
(spon-dir (config "spon-dir" *default-spon-dir*))
- (src-dir (format "~A/src" spon-dir))
- (arc-name (format "~A.tar.gz" package))
- (pkg-file (format "~A/~A" src-dir arc-name)))
+ (pkg-file (format "~A/src/~A.tar.gz" spon-dir package)))
(do-procs
("Decompressing package ..."
(cmd-tar pkg-file spon-dir)
#f
"error in decompressing package"))))
(define (install package . options-list)
- (let ((r (and
- (apply download (cons package options-list))
- (apply verify (cons package options-list))
- (apply decompress (cons package options-list)))))
+ (let ((r (and (apply download package options-list)
+ (apply verify package options-list)
+ (apply decompress package options-list))))
(if r
- (format #t "----> ~A is successfully installed.~%" package)
- (format #t "----> ~A install failed.~%" package))
+ (format #t "----> ~A is successfully installed.~%" package)
+ (format #t "----> ~A install failed.~%" package))
r))
)
|
higepon/spon
|
3883ed7c0d0fa7565f4dfef6b022d8debacc6292
|
install proc split
|
diff --git a/tools.sls b/tools.sls
index 6d6f55d..b51ef5c 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,94 +1,122 @@
(library (spon tools)
- (export download verify decompress install verbose? system-name)
+ (export download verify decompress install)
(import (rnrs)
(srfi :48)
(srfi :98)
(spon base)
(spon compat))
+ (define *default-spon-uri* "http://scheme-users.jp/spon")
+ (define *default-spon-dir* "/usr/local/share/spon")
+
(define *config-search-path*
`(,@(cond
((get-environment-variable "HOME")
=> (lambda (home)
(list (string-append home "/.spon"))))
(else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
- (define *default-spon-uri* "http://scheme-users.jp/spon")
- (define *default-spon-dir* "/usr/local/share/spon")
+ (define (print . strings)
+ (for-each display strings)
+ (newline))
- (define-syntax do-procs
- (syntax-rules ()
- ((_ (pre cmd ok ng) ...)
- (and (begin
- (format #t "----> ~A~%" pre)
- (let ((res cmd))
- (if res
- (when ok
- (format #t "~A~%" ok))
- (format #t "----> ERROR: ~A~%" ng))
- res))
- ...))))
+ (define (print-if bool t f)
+ (if bool
+ (when t (print t))
+ (when f (print f))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
- (define (download wget uri dir)
- (do-cmd wget "-N" "-P" dir uri))
+ (define (get-config)
+ (let ((config #f))
+ (lambda x
+ (when (not config)
+ (set! config (load-config)))
+ (apply config x))))
+
+ (define (get-options options-list)
+ (let ((options (make-hashtable string-hash string=?)))
+ (for-each
+ (lambda (op)
+ (if (pair? op)
+ (hashtable-set! options (format "~A" (car op)) (cdr op))
+ (hashtable-set! options (format "~A" op) #t)))
+ options-list)
+ (lambda (key default)
+ (hashtable-ref options key default))))
+
+ (define (cmd-wget uri dir)
+ (do-cmd ((get-config) "wget") "-N" "-P" dir uri))
+
+ (define (cmd-gpg signature file)
+ (do-cmd ((get-config) "gpg") "--verify" signature file))
+
+ (define (cmd-tar file dir)
+ (do-cmd ((get-config) "tar") "-xvzf" file "-C" dir))
+
+ (define (download package)
+ (let* ((config (get-config))
+ (spon-dir (config "spon-dir" *default-spon-dir*))
+ (spon-uri (config "spon-uri" *default-spon-uri*))
+ (arc-name (format "~A.tar.gz" package))
+ (pkg-uri (format "~A/~A" spon-uri arc-name))
+ (sig-uri (format "~A.asc" pkg-uri))
+ (src-dir (format "~A/src" spon-dir)))
+ (print (format "----> Downloading package: ~A ..." pkg-uri))
+ (print-if (cmd-wget pkg-uri src-dir)
+ #f
+ "----> failed to download package.")
+ (print (format "Downloading signature: ~A ..." sig-uri))
+ (print-if (cmd-wget sig-uri src-dir)
+ #f
+ "----> failed to download signature.")))
- (define (verify gpg signature file)
- (do-cmd gpg "--verify" signature file))
+ (define (verify package)
+ (let* ((config (get-config))
+ (spon-dir (config "spon-dir" *default-spon-dir*))
+ (src-dir (format "~A/src" spon-dir))
+ (arc-name (format "~A.tar.gz" package))
+ (pkg-file (format "~A/~A" src-dir arc-name))
+ (sig-file (format "~A.asc" pkg-file)))
+ (print "Veryfying package ...")
+ (print-if (cmd-gpg sig-file pkg-file)
+ #f
+ "cannot verify package.")))
- (define (decompress tar file dir)
- (do-cmd tar "-xvzf" file "-C" dir))
+ (define (decompress package)
+ (let* ((config (get-config))
+ (spon-dir (config "spon-dir" *default-spon-dir*))
+ (src-dir (format "~A/src" spon-dir))
+ (arc-name (format "~A.tar.gz" package))
+ (pkg-file (format "~A/~A" src-dir arc-name)))
+ (print "Decompressing package ...")
+ (print-if (cmd-tar pkg-file spon-dir)
+ (format "done.\n~A is successfully installed." package)
+ "error in decompressing package")))
(define (install package)
- (let (($ (load-config)))
- (let ((wget ($ "wget"))
- (gpg ($ "gpg"))
- (tar ($ "tar"))
- (spon-dir ($ "spon-dir" *default-spon-dir*))
- (spon-uri ($ "spon-uri" *default-spon-uri*)))
- (let* ((src-dir (format "~A/src" spon-dir))
- (arc-name (format "~A.tar.gz" package))
- (pkg-uri (format "~A/~A" spon-uri arc-name))
- (sig-uri (format "~A.asc" pkg-uri))
- (pkg-file (format "~A/~A" src-dir arc-name))
- (sig-file (format "~A.asc" pkg-file)))
- (do-procs
- ((format "Downloading package: ~A ..." pkg-uri)
- (download wget pkg-uri src-dir)
- #f
- "failed to download package")
- ((format "Downloading signature: ~A ..." sig-uri)
- (download wget sig-uri src-dir)
- #f
- "failed to download signature")
- ("Veryfying package ..."
- (verify gpg sig-file pkg-file)
- #f
- "cannot verify package")
- ("Decompressing package ..."
- (decompress tar pkg-file spon-dir)
- (format "done.\n~A is successfully installed.\n" package)
- "error in decompressing package")
- )))))
+ (and
+ (download package)
+ (verify package)
+ (decompress package)))
)
|
higepon/spon
|
4dcb30c52f1bc39b90de690679c0675b0eb9a37c
|
(expand-path "~/.spon")
|
diff --git a/tools.sls b/tools.sls
index bb99873..6d6f55d 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,89 +1,94 @@
(library (spon tools)
(export download verify decompress install verbose? system-name)
(import (rnrs)
(srfi :48)
+ (srfi :98)
(spon base)
(spon compat))
(define *config-search-path*
- '("~/.spon" ; SUSS: portable?
+ `(,@(cond
+ ((get-environment-variable "HOME")
+ => (lambda (home)
+ (list (string-append home "/.spon"))))
+ (else '()))
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(format #t "----> ~A~%" pre)
(let ((res cmd))
(if res
(when ok
(format #t "~A~%" ok))
(format #t "----> ERROR: ~A~%" ng))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (download wget uri dir)
(do-cmd wget "-N" "-P" dir uri))
(define (verify gpg signature file)
(do-cmd gpg "--verify" signature file))
(define (decompress tar file dir)
(do-cmd tar "-xvzf" file "-C" dir))
(define (install package)
(let (($ (load-config)))
(let ((wget ($ "wget"))
(gpg ($ "gpg"))
(tar ($ "tar"))
(spon-dir ($ "spon-dir" *default-spon-dir*))
(spon-uri ($ "spon-uri" *default-spon-uri*)))
(let* ((src-dir (format "~A/src" spon-dir))
(arc-name (format "~A.tar.gz" package))
(pkg-uri (format "~A/~A" spon-uri arc-name))
(sig-uri (format "~A.asc" pkg-uri))
(pkg-file (format "~A/~A" src-dir arc-name))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(download wget pkg-uri src-dir)
#f
"failed to download package")
((format "Downloading signature: ~A ..." sig-uri)
(download wget sig-uri src-dir)
#f
"failed to download signature")
("Veryfying package ..."
(verify gpg sig-file pkg-file)
#f
"cannot verify package")
("Decompressing package ..."
(decompress tar pkg-file spon-dir)
(format "done.\n~A is successfully installed.\n" package)
"error in decompressing package")
)))))
)
|
higepon/spon
|
2c38d730410dec24851d8445382ac0ba5dcec38f
|
some documentation.
|
diff --git a/sponrc.sample b/sponrc.sample
index 65fe31d..5211959 100644
--- a/sponrc.sample
+++ b/sponrc.sample
@@ -1,8 +1,14 @@
;; -*- mode: scheme -*-
+;; vim:ft=scheme
(
- ;; (wget . "/usr/local/bin/wget")
+ ;; the path to wget command
+ (wget . "/usr/local/bin/wget")
+ ;; the path to gpg command
(gpg . "/opt/local/bin/gpg")
+ ;; the path to tar command
(tar . "/usr/bin/tar")
+ ;; the path where packages are installed
(spon-dir . "/usr/local/share/spon")
- ;; (spon-uri . "http://scheme-users.jp/spon")
+ ;; the URI of the repository
+ (spon-uri . "http://scheme-users.jp/spon")
)
|
higepon/spon
|
0793289ac3dd4810c56d67f3b4241b79d448b869
|
fix to discard stdout.
|
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 8cc0573..68b3c12 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,25 +1,25 @@
(library (spon compat)
(export do-cmd)
(import (rnrs)
(spon base)
(only (mosh process) spawn waitpid pipe))
;; todo replace with custom port
(define (spawn2->null command args)
(let-values ([(in out) (pipe)])
- (let-values ([(pid cin cout cerr) (spawn command args (list #f #f out))])
+ (let-values ([(pid cin cout cerr) (spawn command args (list #f out #f))])
(close-port out)
(close-port in)
(waitpid pid))))
(define (do-cmd cmd . args)
(cond
[(verbose?)
(let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
[(pid status) (waitpid pid)])
(zero? status))]
[else
(let-values ([(pid status) (spawn2->null cmd args)])
(zero? status))]))
)
|
higepon/spon
|
a89049969e98d06c9e52331a5b41582f8e5d691c
|
pass wget -N option.
|
diff --git a/compat.sls b/compat.sls
index 92b02a9..fd58b37 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,24 +1,24 @@
(library (spon compat)
(export do-cmd)
(import (rnrs)
(spon base)
)
;; -- do-cmd :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
(define (do-cmd cmd . args)
(raise (condition
(make-implementation-restriction-violation)
(make-who-condition 'do-cmd)
(make-message-condition
(string-append
"Compatibility layer is not implemented. "
(string-titlecase system-name)
- " seems to be not supported your implementation. "
+ " seems to be not supported by your implementation. "
"Please consult the author of your implementation."))
(make-irritants-condition (cons cmd args)))))
)
diff --git a/tools.sls b/tools.sls
index f503a95..bb99873 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,89 +1,89 @@
(library (spon tools)
(export download verify decompress install verbose? system-name)
(import (rnrs)
(srfi :48)
(spon base)
(spon compat))
(define *config-search-path*
'("~/.spon" ; SUSS: portable?
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(format #t "----> ~A~%" pre)
(let ((res cmd))
(if res
(when ok
(format #t "~A~%" ok))
(format #t "----> ERROR: ~A~%" ng))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (download wget uri dir)
- (do-cmd wget "-P" dir uri))
+ (do-cmd wget "-N" "-P" dir uri))
(define (verify gpg signature file)
(do-cmd gpg "--verify" signature file))
(define (decompress tar file dir)
(do-cmd tar "-xvzf" file "-C" dir))
(define (install package)
(let (($ (load-config)))
(let ((wget ($ "wget"))
(gpg ($ "gpg"))
(tar ($ "tar"))
(spon-dir ($ "spon-dir" *default-spon-dir*))
(spon-uri ($ "spon-uri" *default-spon-uri*)))
(let* ((src-dir (format "~A/src" spon-dir))
(arc-name (format "~A.tar.gz" package))
(pkg-uri (format "~A/~A" spon-uri arc-name))
(sig-uri (format "~A.asc" pkg-uri))
(pkg-file (format "~A/~A" src-dir arc-name))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(download wget pkg-uri src-dir)
#f
"failed to download package")
((format "Downloading signature: ~A ..." sig-uri)
(download wget sig-uri src-dir)
#f
"failed to download signature")
("Veryfying package ..."
(verify gpg sig-file pkg-file)
#f
"cannot verify package")
("Decompressing package ..."
(decompress tar pkg-file spon-dir)
(format "done.\n~A is successfully installed.\n" package)
"error in decompressing package")
)))))
)
|
higepon/spon
|
f6e0802c734fbfef01e1155bb7b356a0e09b8cda
|
add sponrc.sample.
|
diff --git a/sponrc.sample b/sponrc.sample
new file mode 100644
index 0000000..65fe31d
--- /dev/null
+++ b/sponrc.sample
@@ -0,0 +1,8 @@
+;; -*- mode: scheme -*-
+(
+ ;; (wget . "/usr/local/bin/wget")
+ (gpg . "/opt/local/bin/gpg")
+ (tar . "/usr/bin/tar")
+ (spon-dir . "/usr/local/share/spon")
+ ;; (spon-uri . "http://scheme-users.jp/spon")
+ )
|
higepon/spon
|
ab6f65f74195e9d8ea3bdceb8c8c71b593b5cdc0
|
change messages.
|
diff --git a/compat.sls b/compat.sls
index 0464917..92b02a9 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,21 +1,24 @@
(library (spon compat)
(export do-cmd)
(import (rnrs)
(spon base)
)
;; -- do-cmd :: (String, [String]) -> Boolean
;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
(define (do-cmd cmd . args)
(raise (condition
(make-implementation-restriction-violation)
(make-who-condition 'do-cmd)
(make-message-condition
- "Compatibility layer is not implemented. \
- Please contact the author of your implementation.")
+ (string-append
+ "Compatibility layer is not implemented. "
+ (string-titlecase system-name)
+ " seems to be not supported your implementation. "
+ "Please consult the author of your implementation."))
(make-irritants-condition (cons cmd args)))))
)
|
higepon/spon
|
a74637c7f067ec5d2737eace1a6c6ee1735b903a
|
Added (verbose)=>#f support for Mosh
|
diff --git a/ChangeLog b/ChangeLog
index 6482f5e..ee1d807 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,16 +1,20 @@
+2009-02-18 higepon <[email protected]>
+
+ * compat.mosh.sls (spon): Added (verbose) => #f support.
+
2009-02-17 higepon <[email protected]>
* spon: Added spon command.
Use like following.
% sudo ./spon install base64
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
diff --git a/compat.mosh.sls b/compat.mosh.sls
index 2baeca5..8cc0573 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,18 +1,25 @@
(library (spon compat)
(export do-cmd)
(import (rnrs)
(spon base)
- (only (mosh process) spawn waitpid))
+ (only (mosh process) spawn waitpid pipe))
- (define null-port
- (let ((np #f #;(make-custom-binary-output-port 'null
- (lambda (bv s n) n)
- #f #f #f)))
- (lambda () np)))
+ ;; todo replace with custom port
+ (define (spawn2->null command args)
+ (let-values ([(in out) (pipe)])
+ (let-values ([(pid cin cout cerr) (spawn command args (list #f #f out))])
+ (close-port out)
+ (close-port in)
+ (waitpid pid))))
(define (do-cmd cmd . args)
- (let*-values (((pid . _) (spawn cmd args
- `(#f ,(if (verbose?) #f (null-port)) #f)))
- ((pid status) (waitpid pid)))
- (zero? status)))
- )
+ (cond
+ [(verbose?)
+ (let*-values ([(pid . _) (spawn cmd args '(#f #f #f))]
+ [(pid status) (waitpid pid)])
+ (zero? status))]
+ [else
+ (let-values ([(pid status) (spawn2->null cmd args)])
+ (zero? status))]))
+
+)
diff --git a/spon.ss b/spon.ss
index 319ff7d..bb625ee 100644
--- a/spon.ss
+++ b/spon.ss
@@ -1,14 +1,14 @@
(import (rnrs)
(srfi :48)
(spon tools))
(define (main args)
(cond
[(null? (cdr args))
- (format (current-error-port) "ERROR ~a: package name not specified\n" system-name)
+ (display (format "ERROR ~a: package name not specified\n" system-name) (current-error-port))
(exit -1)]
[else
(install (string->symbol (cadr args)))
(exit 0)]))
(main (command-line))
|
higepon/spon
|
f4b54400f0d835b37bf34d84da7023b38f1bdaf2
|
rename aux.sls to base.sls for Windows platform.
|
diff --git a/aux.sls b/base.sls
similarity index 87%
rename from aux.sls
rename to base.sls
index f778632..ad5edbe 100644
--- a/aux.sls
+++ b/base.sls
@@ -1,8 +1,8 @@
-(library (spon aux)
+(library (spon base)
(export verbose? system-name)
(import (rnrs)
(srfi :39))
(define system-name "spon")
(define verbose? (make-parameter #f))
)
diff --git a/compat.mosh.sls b/compat.mosh.sls
index a2b0dad..2baeca5 100644
--- a/compat.mosh.sls
+++ b/compat.mosh.sls
@@ -1,18 +1,18 @@
(library (spon compat)
(export do-cmd)
(import (rnrs)
- (spon aux)
- (only (mosh process) spawn waitpid))
+ (spon base)
+ (only (mosh process) spawn waitpid))
(define null-port
(let ((np #f #;(make-custom-binary-output-port 'null
(lambda (bv s n) n)
#f #f #f)))
(lambda () np)))
(define (do-cmd cmd . args)
(let*-values (((pid . _) (spawn cmd args
`(#f ,(if (verbose?) #f (null-port)) #f)))
- ((pid status) (waitpid pid)))
+ ((pid status) (waitpid pid)))
(zero? status)))
)
diff --git a/compat.sls b/compat.sls
index 0e01e5a..0464917 100644
--- a/compat.sls
+++ b/compat.sls
@@ -1,21 +1,21 @@
(library (spon compat)
(export do-cmd)
(import (rnrs)
- (spon aux)
+ (spon base)
)
;; -- do-cmd :: (String, [String]) -> Boolean
- ;; Execute a command `cmd' with arguments `args'.
+ ;; Execute an external command `cmd' with arguments `args'.
;; If the command is successfully exited, returns #t,
;; otherwise returns #f.
- ;; On `verbose?' produre (see the library (spon aux)) returns #f,
+ ;; When `verbose?' procedure (in the library (spon base)) returns #f,
;; standard output of the command is discarded.
(define (do-cmd cmd . args)
(raise (condition
(make-implementation-restriction-violation)
(make-who-condition 'do-cmd)
(make-message-condition
"Compatibility layer is not implemented. \
Please contact the author of your implementation.")
(make-irritants-condition (cons cmd args)))))
)
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index 417eac9..968dcd3 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,29 +1,29 @@
;; (verbose? #t)ã§ã¡ãã»ã¼ã¸ãåºåããã¾ã
;; tools.slsã®(srfi :48)ã¯Ypsilonã«ã¯ç¡ãã®ã§ã
;; (srfi :28)ã«ãã¦è©¦ãã¦ãã ããã
(library (spon compat)
(export do-cmd)
(import (rnrs)
- (spon aux)
+ (spon base)
(only (core) destructuring-bind process process-wait))
(define (do-cmd cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
(or status (loop (process-wait pid #t))) ; nohang = #t
(zero? status))))
(else
(zero? (process-wait pid #f)))))) ; nohang = #f
) ;[end]
diff --git a/tools.sls b/tools.sls
index 93e2963..f503a95 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,89 +1,89 @@
(library (spon tools)
(export download verify decompress install verbose? system-name)
(import (rnrs)
(srfi :48)
- (spon aux)
+ (spon base)
(spon compat))
(define *config-search-path*
'("~/.spon" ; SUSS: portable?
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(format #t "----> ~A~%" pre)
(let ((res cmd))
(if res
(when ok
(format #t "~A~%" ok))
(format #t "----> ERROR: ~A~%" ng))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
(for-each
(lambda (x)
(if (not (pair? x))
(error 'load-config "invalid configuration" x)
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in)))))
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (download wget uri dir)
(do-cmd wget "-P" dir uri))
(define (verify gpg signature file)
(do-cmd gpg "--verify" signature file))
(define (decompress tar file dir)
(do-cmd tar "-xvzf" file "-C" dir))
(define (install package)
(let (($ (load-config)))
(let ((wget ($ "wget"))
(gpg ($ "gpg"))
(tar ($ "tar"))
(spon-dir ($ "spon-dir" *default-spon-dir*))
(spon-uri ($ "spon-uri" *default-spon-uri*)))
(let* ((src-dir (format "~A/src" spon-dir))
(arc-name (format "~A.tar.gz" package))
(pkg-uri (format "~A/~A" spon-uri arc-name))
(sig-uri (format "~A.asc" pkg-uri))
(pkg-file (format "~A/~A" src-dir arc-name))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(download wget pkg-uri src-dir)
#f
"failed to download package")
((format "Downloading signature: ~A ..." sig-uri)
(download wget sig-uri src-dir)
#f
"failed to download signature")
("Veryfying package ..."
(verify gpg sig-file pkg-file)
#f
"cannot verify package")
("Decompressing package ..."
(decompress tar pkg-file spon-dir)
(format "done.\n~A is successfully installed.\n" package)
"error in decompressing package")
)))))
)
|
higepon/spon
|
6d9ab1f84e510ee6bb998bb44dcabde89465ffe7
|
stub compat.sls.
|
diff --git a/aux.sls b/aux.sls
index c7b9098..f778632 100644
--- a/aux.sls
+++ b/aux.sls
@@ -1,8 +1,8 @@
(library (spon aux)
(export verbose? system-name)
(import (rnrs)
- (srfi :39))
+ (srfi :39))
(define system-name "spon")
(define verbose? (make-parameter #f))
)
diff --git a/compat.sls b/compat.sls
new file mode 100644
index 0000000..0e01e5a
--- /dev/null
+++ b/compat.sls
@@ -0,0 +1,21 @@
+(library (spon compat)
+ (export do-cmd)
+ (import (rnrs)
+ (spon aux)
+ )
+
+ ;; -- do-cmd :: (String, [String]) -> Boolean
+ ;; Execute a command `cmd' with arguments `args'.
+ ;; If the command is successfully exited, returns #t,
+ ;; otherwise returns #f.
+ ;; On `verbose?' produre (see the library (spon aux)) returns #f,
+ ;; standard output of the command is discarded.
+ (define (do-cmd cmd . args)
+ (raise (condition
+ (make-implementation-restriction-violation)
+ (make-who-condition 'do-cmd)
+ (make-message-condition
+ "Compatibility layer is not implemented. \
+ Please contact the author of your implementation.")
+ (make-irritants-condition (cons cmd args)))))
+ )
diff --git a/tools.sls b/tools.sls
index e699a14..93e2963 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,96 +1,89 @@
(library (spon tools)
(export download verify decompress install verbose? system-name)
(import (rnrs)
- (srfi :48)
- (spon aux)
- (spon compat))
+ (srfi :48)
+ (spon aux)
+ (spon compat))
(define *config-search-path*
'("~/.spon" ; SUSS: portable?
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
- (format #t "----> ~A~%" pre)
- (let ((res cmd))
- (if res
- (when ok
- (format #t "~A~%" ok))
- (format #t "----> ERROR: ~A~%" ng))
- res))
- ...))))
+ (format #t "----> ~A~%" pre)
+ (let ((res cmd))
+ (if res
+ (when ok
+ (format #t "~A~%" ok))
+ (format #t "----> ERROR: ~A~%" ng))
+ res))
+ ...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
- (config-path (find file-exists? *config-search-path*)))
+ (config-path (find file-exists? *config-search-path*)))
(when config-path
- (call-with-input-file config-path
- (lambda (in)
- #|
- (for-each
- (lambda (x)
- (when (and (pair? x) (pair? (car x)))
- (hashtable-set! config (format "~A" (car x)) (cdr x))))
- (read in))
- |#
- (let loop ((ls (read in)))
- (when (and (pair? ls)
- (pair? (car ls))
- (string? (caar ls)))
- (hashtable-set! config (caar ls) (cdar ls))
- (loop (cdr ls))))))) ; SUSS: correct?
+ (call-with-input-file config-path
+ (lambda (in)
+ (for-each
+ (lambda (x)
+ (if (not (pair? x))
+ (error 'load-config "invalid configuration" x)
+ (hashtable-set! config (format "~A" (car x)) (cdr x))))
+ (read in)))))
(letrec (($ (case-lambda
- ((key)
- ($ key key))
- ((key default)
- (hashtable-ref config key default)))))
- $)))
+ ((key)
+ ($ key key))
+ ((key default)
+ (hashtable-ref config key default)))))
+ $)))
(define (download wget uri dir)
(do-cmd wget "-P" dir uri))
(define (verify gpg signature file)
(do-cmd gpg "--verify" signature file))
(define (decompress tar file dir)
(do-cmd tar "-xvzf" file "-C" dir))
(define (install package)
(let (($ (load-config)))
(let ((wget ($ "wget"))
- (gpg ($ "gpg"))
- (tar ($ "tar"))
- (spon-dir ($ "spon-dir" *default-spon-dir*))
- (spon-uri ($ "spon-uri" *default-spon-uri*)))
- (let* ((src-dir (format "~A/src" spon-dir))
- (arc-name (format "~A.tar.gz" package))
- (pkg-uri (format "~A/~A" spon-uri arc-name))
- (sig-uri (format "~A.asc" pkg-uri))
- (pkg-file (format "~A/~A" src-dir arc-name))
- (sig-file (format "~A.asc" pkg-file)))
- (do-procs
- ((format "Downloading package: ~A ..." pkg-uri)
- (download wget pkg-uri src-dir)
- #f
- "failed to download package")
- ((format "Downloading signature: ~A ..." sig-uri)
- (download wget sig-uri src-dir)
- #f
- "failed to download signature")
- ("Veryfying package ..."
- (verify gpg sig-file pkg-file)
- #f
- "cannot verify package")
- ("Decompressing package ..."
- (decompress tar pkg-file spon-dir)
- (format "done.\n~A is successfully installed.\n" package)
- "error in decompressing package")
- )))))
+ (gpg ($ "gpg"))
+ (tar ($ "tar"))
+ (spon-dir ($ "spon-dir" *default-spon-dir*))
+ (spon-uri ($ "spon-uri" *default-spon-uri*)))
+ (let* ((src-dir (format "~A/src" spon-dir))
+ (arc-name (format "~A.tar.gz" package))
+ (pkg-uri (format "~A/~A" spon-uri arc-name))
+ (sig-uri (format "~A.asc" pkg-uri))
+ (pkg-file (format "~A/~A" src-dir arc-name))
+ (sig-file (format "~A.asc" pkg-file)))
+ (do-procs
+ ((format "Downloading package: ~A ..." pkg-uri)
+ (download wget pkg-uri src-dir)
+ #f
+ "failed to download package")
+ ((format "Downloading signature: ~A ..." sig-uri)
+ (download wget sig-uri src-dir)
+ #f
+ "failed to download signature")
+ ("Veryfying package ..."
+ (verify gpg sig-file pkg-file)
+ #f
+ "cannot verify package")
+ ("Decompressing package ..."
+ (decompress tar pkg-file spon-dir)
+ (format "done.\n~A is successfully installed.\n" package)
+ "error in decompressing package")
+ )))))
)
|
higepon/spon
|
b7100e3eea8bd9b85bb5e5b6957573825d25e566
|
compat.ypsilon.sls
|
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index f29a197..417eac9 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,28 +1,29 @@
;; (verbose? #t)ã§ã¡ãã»ã¼ã¸ãåºåããã¾ã
;; tools.slsã®(srfi :48)ã¯Ypsilonã«ã¯ç¡ãã®ã§ã
;; (srfi :28)ã«ãã¦è©¦ãã¦ãã ããã
(library (spon compat)
(export do-cmd)
(import (rnrs)
(spon aux)
(only (core) destructuring-bind process process-wait))
(define (do-cmd cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
(or status (loop (process-wait pid #t))) ; nohang = #t
(zero? status))))
(else
(zero? (process-wait pid #f)))))) ; nohang = #f
+
) ;[end]
|
higepon/spon
|
fc4b7b6f7a5651fcf161035e1a2ce2653cbdb716
|
compat.ypsilon.sls
|
diff --git a/compat.ypsilon.sls b/compat.ypsilon.sls
index 3616ca6..f29a197 100644
--- a/compat.ypsilon.sls
+++ b/compat.ypsilon.sls
@@ -1,27 +1,28 @@
;; (verbose? #t)ã§ã¡ãã»ã¼ã¸ãåºåããã¾ã
;; tools.slsã®(srfi :48)ã¯Ypsilonã«ã¯ç¡ãã®ã§ã
;; (srfi :28)ã«ãã¦è©¦ãã¦ãã ããã
(library (spon compat)
(export do-cmd)
(import (rnrs)
(spon aux)
(only (core) destructuring-bind process process-wait))
(define (do-cmd cmd . args)
(destructuring-bind (pid p-stdin p-stdout p-stderr)
(apply process cmd args)
(cond ((verbose?)
(let ((p-message (transcoded-port p-stdout (native-transcoder)))
(p-error (transcoded-port p-stderr (native-transcoder))))
(let loop ((status #f))
(let ((message (get-string-all p-message)))
(unless (eof-object? message)
(put-string (current-output-port) message)))
(let ((error (get-string-all p-error)))
(unless (eof-object? error)
(put-string (current-error-port) error)))
- (or status (loop (process-wait pid #t)))))) ; nohang = #t
+ (or status (loop (process-wait pid #t))) ; nohang = #t
+ (zero? status))))
(else
(zero? (process-wait pid #f)))))) ; nohang = #f
) ;[end]
|
higepon/spon
|
36ff06d42ad7f893de327703d3b0c3ea572c0842
|
Added spon
|
diff --git a/spon b/spon
index 46e93e7..83eb9be 100755
--- a/spon
+++ b/spon
@@ -1,14 +1,16 @@
#!/bin/bash
r6rs="`which mosh`"
if test "" = "$r6rs"; then
r6rs="`which ypsilon`"
if test "" = "$r6rs"; then
echo "R6RS Scheme not found"
+ else
+ echo "TODO"
fi
else
# TODO path to spon.ss
# TODO check $1
$r6rs --loadpath=/usr/local/share/ spon.ss $2
fi
|
higepon/spon
|
fdaff398251390e999997c4a513a3b1afd35d464
|
Added spon
|
diff --git a/ChangeLog b/ChangeLog
index eab0c79..6482f5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,16 @@
2009-02-17 higepon <[email protected]>
+ * spon: Added spon command.
+ Use like following.
+
+ % sudo ./spon install base64
+
* tools.sls (spon): Merged leque's code.
* tools.ypsilon.sls: Added by fujita-y.
2009-02-14 higepon <[email protected]>
* tools.mosh.sls (spon): Use (mosh process) instead of (system).
* First import originally from baal's implementation.
-
diff --git a/aux.sls b/aux.sls
index b76888f..c7b9098 100644
--- a/aux.sls
+++ b/aux.sls
@@ -1,7 +1,8 @@
(library (spon aux)
- (export verbose?)
+ (export verbose? system-name)
(import (rnrs)
(srfi :39))
+ (define system-name "spon")
(define verbose? (make-parameter #f))
)
diff --git a/spon b/spon
new file mode 100755
index 0000000..46e93e7
--- /dev/null
+++ b/spon
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+r6rs="`which mosh`"
+if test "" = "$r6rs"; then
+ r6rs="`which ypsilon`"
+ if test "" = "$r6rs"; then
+ echo "R6RS Scheme not found"
+ fi
+else
+ # TODO path to spon.ss
+ # TODO check $1
+ $r6rs --loadpath=/usr/local/share/ spon.ss $2
+fi
+
diff --git a/spon.ss b/spon.ss
new file mode 100644
index 0000000..319ff7d
--- /dev/null
+++ b/spon.ss
@@ -0,0 +1,14 @@
+(import (rnrs)
+ (srfi :48)
+ (spon tools))
+
+(define (main args)
+ (cond
+ [(null? (cdr args))
+ (format (current-error-port) "ERROR ~a: package name not specified\n" system-name)
+ (exit -1)]
+ [else
+ (install (string->symbol (cadr args)))
+ (exit 0)]))
+
+(main (command-line))
diff --git a/tools.sls b/tools.sls
index b53aaa4..e699a14 100644
--- a/tools.sls
+++ b/tools.sls
@@ -1,96 +1,96 @@
(library (spon tools)
- (export download verify decompress install verbose?)
+ (export download verify decompress install verbose? system-name)
(import (rnrs)
(srfi :48)
(spon aux)
(spon compat))
(define *config-search-path*
'("~/.spon" ; SUSS: portable?
"/usr/local/share/spon/sponrc"
"/usr/share/spon/sponrc"
"/etc/sponrc"))
(define *default-spon-uri* "http://scheme-users.jp/spon")
(define *default-spon-dir* "/usr/local/share/spon")
(define-syntax do-procs
(syntax-rules ()
((_ (pre cmd ok ng) ...)
(and (begin
(format #t "----> ~A~%" pre)
(let ((res cmd))
(if res
(when ok
(format #t "~A~%" ok))
(format #t "----> ERROR: ~A~%" ng))
res))
...))))
(define (load-config)
(let ((config (make-hashtable string-hash string=?))
(config-path (find file-exists? *config-search-path*)))
(when config-path
(call-with-input-file config-path
(lambda (in)
#|
(for-each
(lambda (x)
(when (and (pair? x) (pair? (car x)))
(hashtable-set! config (format "~A" (car x)) (cdr x))))
(read in))
|#
(let loop ((ls (read in)))
(when (and (pair? ls)
(pair? (car ls))
(string? (caar ls)))
(hashtable-set! config (caar ls) (cdar ls))
(loop (cdr ls))))))) ; SUSS: correct?
(letrec (($ (case-lambda
((key)
($ key key))
((key default)
(hashtable-ref config key default)))))
$)))
(define (download wget uri dir)
(do-cmd wget "-P" dir uri))
(define (verify gpg signature file)
(do-cmd gpg "--verify" signature file))
(define (decompress tar file dir)
(do-cmd tar "-xvzf" file "-C" dir))
(define (install package)
(let (($ (load-config)))
(let ((wget ($ "wget"))
(gpg ($ "gpg"))
(tar ($ "tar"))
(spon-dir ($ "spon-dir" *default-spon-dir*))
(spon-uri ($ "spon-uri" *default-spon-uri*)))
(let* ((src-dir (format "~A/src" spon-dir))
(arc-name (format "~A.tar.gz" package))
(pkg-uri (format "~A/~A" spon-uri arc-name))
(sig-uri (format "~A.asc" pkg-uri))
(pkg-file (format "~A/~A" src-dir arc-name))
(sig-file (format "~A.asc" pkg-file)))
(do-procs
((format "Downloading package: ~A ..." pkg-uri)
(download wget pkg-uri src-dir)
#f
"failed to download package")
((format "Downloading signature: ~A ..." sig-uri)
(download wget sig-uri src-dir)
#f
"failed to download signature")
("Veryfying package ..."
(verify gpg sig-file pkg-file)
#f
"cannot verify package")
("Decompressing package ..."
(decompress tar pkg-file spon-dir)
(format "done.\n~A is successfully installed.\n" package)
"error in decompressing package")
)))))
)
|
higepon/spon
|
3e1aa60c778897185aed146733081a5c4fb3857e
|
Use (mosh process) instead of (system).
|
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..9324b82
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,6 @@
+2009-02-14 higepon <[email protected]>
+
+ * tools.mosh.sls (spon): Use (mosh process) instead of (system).
+
+ * First import originally from baal's implementation.
+
diff --git a/tools.mosh.sls b/tools.mosh.sls
new file mode 100644
index 0000000..87a161c
--- /dev/null
+++ b/tools.mosh.sls
@@ -0,0 +1,70 @@
+(library (spon tools)
+
+ (export download verify decompress install)
+ (import (rnrs)
+ (only (mosh process) spawn waitpid))
+
+ (define *config-search-path*
+ '("~/.spon"
+ "/usr/local/share/spon/sponrc"
+ "/usr/share/spon/sponrc"
+ "/etc/sponrc"))
+
+ (define *default-spon-uri* "http://scheme-users.jp/spon/")
+ (define *default-spon-dir* "/usr/local/share/spon")
+
+ (define-syntax do-procs
+ (syntax-rules ()
+ ((_ (res ok err)) (let ((r res)) (display (if r ok err)) (newline) r))
+ ((_ x y ...) (and (do-procs x) (do-procs y ...)))))
+
+ (define (get-config-path)
+ (let loop ((ls *config-search-path*))
+ (if (pair? ls)
+ (if (file-exists? (car ls))
+ (car ls)
+ (loop (cdr ls)))
+ #f)))
+
+ (define (get-config)
+ (let ((config (make-hashtable string-hash string=?))
+ (config-path (get-config-path)))
+ (when config-path
+ (call-with-input-file config-path
+ (lambda (in)
+ (let loop ((ls (read in)))
+ (when (and (pair? ls) (pair? (car ls)) (string? (car (car ls))))
+ (hashtable-set! config (car (car ls)) (cdr (car ls)))
+ (loop (cdr ls)))))))
+ config))
+
+ (define (download wget uri dir)
+ (let-values (((pid cin cout cerr) (spawn wget (list "-P" dir uri) '(#f #f #f))))
+ (let-values (((pid status) (waitpid pid))) (zero? status))))
+
+ (define (verify gpg signature file)
+ (let-values (((pid cin cout cerr) (spawn gpg (list "--verify" signature file) '(#f #f #f))))
+ (let-values (((pid status) (waitpid pid))) (zero? status))))
+
+ (define (decompress tar file dir)
+ (let-values (((pid cin cout cerr) (spawn tar (list "-xvzf" file "-C" dir) '(#f #f #f))))
+ (let-values (((pid status) (waitpid pid))) (zero? status))))
+
+ (define (install package)
+ (let ((config (get-config)))
+ (let ((wget (hashtable-ref config "wget" "wget"))
+ (gpg (hashtable-ref config "gpg" "gpg"))
+ (tar (hashtable-ref config "tar" "tar"))
+ (spon-dir (hashtable-ref config "spon-dir" *default-spon-dir*))
+ (spon-uri (hashtable-ref config "spon-uri" *default-spon-uri*)))
+ (let ((src-dir (string-append spon-dir "/src"))
+ (pkg-uri (string-append spon-uri package ".tar.gz"))
+ (sig-uri (string-append spon-uri package ".tar.gz.asc"))
+ (pkg-file (string-append spon-dir "/src/" package ".tar.gz"))
+ (sig-file (string-append spon-dir "/src/" package ".tar.gz.asc")))
+ (do-procs
+ ((download wget pkg-uri src-dir) "OK: package download." "ERROR: package download.")
+ ((download wget sig-uri src-dir) "OK: signature download." "ERROR: signature download.")
+ ((verify gpg sig-file pkg-file) "OK: verify." "ERROR: verify.")
+ ((decompress tar pkg-file spon-dir) "OK: decompress." "ERROR : decompress."))))))
+ )
|
KeithHanson/rmuddy
|
3700a525f204bf2a43391bf40a596bfc1a098355
|
Moved Timer methods into BasePlugin.
|
diff --git a/base_plugin.rb b/base_plugin.rb
index 7ae1d18..e4b5189 100644
--- a/base_plugin.rb
+++ b/base_plugin.rb
@@ -1,74 +1,108 @@
class BasePlugin
attr_accessor :triggers, :receiver
def initialize(rec)
@receiver = rec
self.setup
end
def plugins
@receiver.plugins
end
def disabled_plugins
@receiver.disabled_plugins
end
def disable
unless @receiver.disabled_plugins.include?(self)
@receiver.enabled_plugins.delete(self)
@receiver.disabled_plugins << self
end
warn("#{self.class.to_s} Plugin has been disabled.")
end
def enable
unless @receiver.enabled_plugins.include?(self)
@receiver.disabled_plugins.delete(self)
@receiver.enabled_plugins << self
end
warn("#{self.class.to_s} Plugin has been enabled.")
end
def help
warn("That plugin's author has not created a help for you!")
end
def trigger(regex, method)
@triggers ||= {}
@triggers[regex] = method
end
def set_kmuddy_variable(variable_name, variable_value)
@receiver.queue << ["set_var", variable_name, variable_value]
end
def get_kmuddy_variable(variable_name)
@receiver.varsock.get(variable_name)
end
def send_kmuddy_command(command_text)
@receiver.queue << ["send_command", command_text]
end
def before(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(1, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
module_name.module_eval(new_method.join("\n"))
end
def after(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(-2, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
module_name.module_eval(new_method.join("\n"))
end
+
+ #Use this in your timer blocks... this should be interesting.
+ def simple_timer (time_to_wait, method)
+ Thread.new do
+ sleep time_to_wait #this will be in seconds, though fractions will do
+ self.send(method.to_sym)
+ end
+ end
+
+ #Method to allow sending a command to another plugin.
+ def plugin_timer(time_to_wait, plugin, method)
+ Thread.new do
+ sleep time_to_wait
+ if plugin.class?(Class)
+ plugins[plugin].send(method.to_sym)
+ else
+ plugin.send(method.to_sym)
+ end
+ end
+ end
+
+ #this one repeats every time_to_wait seconds
+ def time_block
+ start_time = Time.now
+ Thread.new { yield }
+ Time.now - start_time
+ end
+
+ def heartbeat(time_to_wait)
+ while true do
+ time_spent = time_block { yield }
+ sleep(time_to_wait - time_spent) if time_spent < time_to_wait
+ end
+ end
end
\ No newline at end of file
diff --git a/connection_handler.rb b/connection_handler.rb
index 9796e1e..aec8c0b 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,46 +1,46 @@
-require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
-require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
-require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
+require File.join(File.dirname(__FILE__), "lib", 'kmuddy.rb')
+require File.join(File.dirname(__FILE__), "lib", 'eventserver.rb')
+require File.join(File.dirname(__FILE__), "lib", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
$server_port = 4567
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
debug("Received a line!")
@receiver.receive(line)
end
}
@threads << Thread.new {
while (event = @evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
@receiver.command(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
diff --git a/disabled-plugins/timer.rb b/disabled-plugins/timer.rb
deleted file mode 100644
index 57a4bd2..0000000
--- a/disabled-plugins/timer.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-#Timer module for RMuddy... may very well be pulled back into core/init/baseplugin at some point... currently sitting outside for testing.
-
-
-class Timer < BasePlugin
-
- def setup
-
- end
-
- #Use this in your timer blocks... this should be interesting.
- def timer (time_to_wait, method)
- Thread.new do
- sleep time_to_wait #this will be in seconds, though fractions will do
- self.send(method.to_sym)
- end
- end
-
- #this one repeats every time_to_wait seconds
- def time_block
- start_time = Time.now
- Thread.new { yield }
- Time.now - start_time
- end
-
- def heartbeat(time_to_wait)
- while true do
- time_spent = time_block { yield }
- sleep(time_to_wait - time_spent) if time_spent < time_to_wait
- end
- end
-
- def help
- warn("Dude, you don't really need help with this... it's not going to be callable via kmuddy, I don't think")
- warn("And even if it -is-... it's pretty straightforward... heartbeat(time in seconds) { stuff to do }")
- warn("The time can be in decimal, so you can do heartbeat(0.030) {cure} and it will call your 'cure' method every 30 milliseconds")
- warn("similarly, you can do")
- warn("timer 0.3 has_balance")
- warn("And it will execute the has_balance method 300 milliseconds after it executes")
- warn("So, I suppose, you could manually inject this kind of stuff by doing")
- warn("/notify 4567 Timer timer 1 plugins[Sipper].should_i_sip?")
- warn("To have it check in 1 second if you should sip... ")
- end
-
-end
diff --git a/init.rb b/init.rb
index c35d9f5..dc17df9 100755
--- a/init.rb
+++ b/init.rb
@@ -1,22 +1,21 @@
#!/usr/bin/env ruby
DEBUG = false
Dir[File.join(File.dirname(__FILE__), "gems", "gems", "*")].each do |gem_folder|
$: << gem_folder + "/lib/"
end
require File.join(File.dirname(__FILE__), "connection_handler.rb")
require File.join(File.dirname(__FILE__), "base_plugin.rb")
require File.join(File.dirname(__FILE__), "receiver.rb")
require 'yaml'
require "ruby2ruby"
debug("Starting Receiver...")
receiver = Receiver.new()
debug("Starting Connection Handler")
connection_handler = ConnectionHandler.new(receiver)
-
connection_handler.start
debug("Connection Handler Started")
\ No newline at end of file
diff --git a/kmuddy/eventserver.rb b/lib/eventserver.rb
similarity index 100%
rename from kmuddy/eventserver.rb
rename to lib/eventserver.rb
diff --git a/kmuddy/kmuddy.rb b/lib/kmuddy.rb
similarity index 100%
rename from kmuddy/kmuddy.rb
rename to lib/kmuddy.rb
diff --git a/kmuddy/variablesock.rb b/lib/variablesock.rb
similarity index 100%
rename from kmuddy/variablesock.rb
rename to lib/variablesock.rb
|
KeithHanson/rmuddy
|
aeb4e992e140614edd030c3d0a1ca1ff34c7e261
|
Timer and heartbeat functionality... should be in disabled-plugins/timer... may want to merge it in with BasePlugin so it can be used in all modules. Also, it is currently completely untested
|
diff --git a/disabled-plugins/timer.rb b/disabled-plugins/timer.rb
index 0cf4d4c..57a4bd2 100644
--- a/disabled-plugins/timer.rb
+++ b/disabled-plugins/timer.rb
@@ -1,20 +1,44 @@
#Timer module for RMuddy... may very well be pulled back into core/init/baseplugin at some point... currently sitting outside for testing.
class Timer < BasePlugin
+
def setup
end
#Use this in your timer blocks... this should be interesting.
def timer (time_to_wait, method)
- Thread.new {
- @start_time = time.now
- }
+ Thread.new do
+ sleep time_to_wait #this will be in seconds, though fractions will do
+ self.send(method.to_sym)
+ end
+ end
+
+ #this one repeats every time_to_wait seconds
+ def time_block
+ start_time = Time.now
+ Thread.new { yield }
+ Time.now - start_time
+ end
+
+ def heartbeat(time_to_wait)
+ while true do
+ time_spent = time_block { yield }
+ sleep(time_to_wait - time_spent) if time_spent < time_to_wait
+ end
end
def help
warn("Dude, you don't really need help with this... it's not going to be callable via kmuddy, I don't think")
+ warn("And even if it -is-... it's pretty straightforward... heartbeat(time in seconds) { stuff to do }")
+ warn("The time can be in decimal, so you can do heartbeat(0.030) {cure} and it will call your 'cure' method every 30 milliseconds")
+ warn("similarly, you can do")
+ warn("timer 0.3 has_balance")
+ warn("And it will execute the has_balance method 300 milliseconds after it executes")
+ warn("So, I suppose, you could manually inject this kind of stuff by doing")
+ warn("/notify 4567 Timer timer 1 plugins[Sipper].should_i_sip?")
+ warn("To have it check in 1 second if you should sip... ")
end
end
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index dafb624..56a3252 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,178 +1,185 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
class Ratter < BasePlugin
attr_accessor :ratter_enabled, :balance_user, :attack_command, :available_rats
attr_accessor :inventory_rats, :rat_prices, :total_rat_money
def setup
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
@balance_user = false
#What do we do when we want them dead?
@attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#Identify when there WAS a rat, but there no longer is cuz someone else using RMuddy ninja'd it
trigger /I do not recognise anything called that here./, :no_rats!
trigger /Ahh, I am truly sorry, but I do not see anyone by that name here./, :no_rats!
trigger /Nothing can be seen here by that name./, :no_rats!
trigger /You detect nothing here by that name./, :no_rats!
trigger /You cannot see that being here./, :no_rats!
+
+ #So, you walked away and your character fell asleep.. that's cool, he'll wake up eventually... but not standup
+ trigger /You must be standing first/, :standup
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
trigger /Liirup the Placid stands here/, :sell_rats_hashan
trigger /The Ratman stands here quietly/, :sell_rats_ashtan
#Reset the money after selling to the ratter in hashan. .. Or Ashtan, now
trigger /Liirup squeals with delight/, :reset_money
trigger /The ratman thanks you as you hand over/, :reset_money
trigger /Although you exert extraordinary effort, you find you lack the mental reserves to perform that ability./, :out_of_mana!
trigger /You cannot summon up the willpower to perform such a mentally exhausting task./, :out_of_willpower!
trigger /You see exits/, :reset_available_rats
trigger /You see a single exit/, :reset_available_rats
#After we gain balance, we need to decide if we should attack again or not.
after Character, :set_simple_stats, :should_i_attack_rat?
after Character, :set_extended_stats, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
def out_of_mana!
if !@balance_user
disable_ratter
end
end
def out_of_willpower!
if !@balance_user
disable_ratter
end
end
def sell_rats_ashtan
if @ratter_enabled
send_kmuddy_command("Sell rats to Ratman")
end
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
+ def standup
+ send_kmuddy_command("stand")
+ end
+
def no_rats!
@available_rats = 0
end
def enable_ratter
warn("Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
def reset_available_rats
@available_rats = 0
end
def sell_rats_hashan
if @ratter_enabled
send_kmuddy_command("Sell rats to Liirup")
end
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && plugins[Character].balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && plugins[Character].has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/tarot.rb b/enabled-plugins/tarot.rb
index c7e7ed9..2230771 100644
--- a/enabled-plugins/tarot.rb
+++ b/enabled-plugins/tarot.rb
@@ -1,297 +1,298 @@
#Ok, combining the hermit tracker with auto-charger/flinger and the mass inscriber... take one
#THIS IS NOT FOOLPROOF... DON'T BE A FOOL!
#That having been said, I plan to make it foolproof at some point...
class Tarot < BasePlugin
#set up our variables, etc.
def setup
#setup triggers here
trigger /^The card begins to glow with a mystic energy./, :charged
trigger /^Rubbing your fingers briskly on the card, you charge it with necessary energy./, :charging
trigger /^The mystic glow on the Tarot card fades./, :uncharged
trigger /^You have recovered equilibrium.$/, :put_away_hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /You have successfully inscribed/, :decrement_counter #we did it!
trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
trigger /^None of your decks contain a card with the image of (.+)/, :aint_got_it
after Character, :is_balanced, :fling_card
after Character, :gained_equilibrium, :fling_card
#setup variables here... comment specific bits if necessary for sanity
#because I like some things to be stored as variables for easy changing later... formatting sheit mostly
@whichhermit = ''
@key = ''
@formatlength = 80
@formatpad = (@formatlength / 3)
@resethash = {"Location" => "card number"}
#by default, we are not, in fact, inscribing, activating, or charging any cards
@tarotcards = %w(sun emperor magician priestess fool chariot hermit empress lovers hierophant hangedman tower wheel creator justice star aeon lust universe devil moon death)
@groundonly = %w(chariot hermit universe)
@charginghermit = false
@paused = false
@batch_total = 0
@inscribing = false
@number_to_inscribe = 0
@type_to_inscribe = ""
@card_to_fling = ''
@target = ''
- @tarotcards.each{ |key| warn("Full Tarot list: #{key}") }
- @groundonly.each {|key| warn("Ground Only: #{key}")}
+ @charging = false
+ @charged = false
+
#do any other actual setup work here
warn("Loading hermit locations database")
unless File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
warn("Failed to find and load the hermit database. You need to have hermithash.yaml in the configs directory")
else
warn("Hermit database loaded")
end
send_kmuddy_command("ind 50 hermit")
end
#this is the receptacle into which your commands for non-hermit flinging should go
def tarot_card (card = '', target = 'ground')
#determine what card to outd, outd it, then charge it
warn("Ok, we're gonna use #{card} on #{target}")
@card_to_fling = card.downcase
@target = target.downcase
if @tarotcards.include?(@card_to_fling)
warn("It's a real tarot card!")
if @groundonly.include?(@card_to_fling)
@target = "ground"
send_kmuddy_command("outd #{@card_to_fling}")
send_kmuddy_command("charge #{@card_to_fling}")
else
send_kmuddy_command("outd #{@card_to_fling}")
send_kmuddy_command("charge #{@card_to_fling}")
end
else
warn("Ok... I need a real tarot card, and who/what to fling it at... if it's the ground, you may omit the target")
end
end
#cuz we might want some help for the tarot module
def help (topic = '')
if topic == ''
warn("Specificy a topic: inscribe, hermit, or use")
elsif topic.downcase == "inscribe"
warn("To inscribe, /notify 4567 Tarot mass_inscribe <number to inscribe> <type of tarot to inscribe>")
warn("Then /notify 4567 Tarot begin_inscribing to actually begin the inscription process")
warn("/notify 4567 (un)pause_inscription will (un)pause the batch inscription process")
warn("I doubt it has to be said, but just in case, that's pause_inscript or unpause_inscription, with no ()")
blank_line
elsif topic.downcase == "hermit"
warn("For hermit tracking, you can use /notify 4567 Tarot activate_hermit <what you want to call this place>")
warn("this will outd a hermit, check its card number, then activate it and put it away, storing it in our database")
warn("/notify 4567 Tarot fling_hermit <whereyawannago> will then grab the appropriate hermit (based on the same name you gave it when you did activate_hermit)")
warn("charge the hermit, and then fling it. It will at this point delete it from the database of hermit locations")
warn("/notify 4567 Tarot del_hash <which room to delete> will remove the room you tell it to remove from the hermit locations database")
warn("/notify 4567 Tarot reset_hash will wipe the entire database, if all of your hermits have decayed")
blank_line
elsif topic.downcase == "use"
warn("this is very basic tarot card usage here... but essentially you would")
warn("/notify 4567 Tarot tarot_card <which card to throw> <who/what to throw it at>")
warn("it should then outd the card, charge the card, and after the card is charged fling it the next time you regain equilibrium/balance")
blank_line
else
warn("Please specify a valid topic: inscribe, hermit, or use")
end
end
#So we know it's charged, and can fling that biatch
def charged
@charging = false
@charged = true
fling_card
end
def fling_card
#fling the card as commanded... and do the correct one, at whom, and do it
if @card_to_fling != '' && @target != '' && plugins[Character].balanced && plugins[Character].has_equilibrium && @charged
send_kmuddy_command("fling #{@card_to_fling} at #{@target}")
@card_to_fling = ''
@target = ''
uncharged
if @card_to_fling.downcase == 'hermit'
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
#in case we need it later
def charging
@charging = true
end
def uncharged
@charged = false
end
#so... you tried to outd a card you don't have...
def aint_got_it(match_object = '')
- warn("You tried to get a #{match_object} but you don't have one, man.")
+ warn("You tried to get a #{match_object[1]} but you don't have one, man.")
@card_to_fling = ''
@target = ''
end
#imported from the mass inscriber
def mass_inscribe(number_to_inscribe, type_to_inscribe)
@number_to_inscribe = number_to_inscribe.to_i
@type_to_inscribe = type_to_inscribe.to_s
@batch_total = number_to_inscribe.to_i
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
warn("Inscriber Plugin: Ready to inscribe #{@number_to_inscribe} #{@type_to_inscribe}")
warn("Use begin_inscribing to start.")
end
#begin the inscription process
def begin_inscribing
inscribe_tarot
end
#here's how we actually inscribe the bloody cards
def inscribe_tarot
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
plugins[Sipper].should_i_sip? #check to see if we need mana before we inscribe
plugins[Sipper].disable #then disable the sipper so as not to kill our inscribe
send_kmuddy_command("inscribe blank with #{@type_to_inscribe}") #and actually inscribe
end
#lower the counter, so we inscribe the correct # of cards
def decrement_counter
@number_to_inscribe -= 1 #decrement counter
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
should_we_inscribe? #check if we should do another!
end
#pretty obvious
def out_of_mana!
@inscribing = false #if we're out of mana, we're not inscribing
plugins[Sipper].enable
send_kmuddy_command("sip mana") #so we need to sip some mana
end
#so we can stop in the middle of stuff
def pause_inscription
@paused = true
end
#so we can continue when we're done flapping our gums
def unpause_inscription
@paused = false
inscribe_tarot
end
#test if we should inscribe
def should_we_inscribe?
if @number_to_inscribe > 0 && !@paused #if we still have inscription to do and we're not paused
inscribe_tarot #then inscribe
elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
send_kmuddy_command("ind #{@batch_total} #{@type_to_inscribe}") #put the cards away
plugins[Sipper].should_i_sip? #check if we need to sip
end
end
#imported from the hermit tracker... might as well keep it all in one, right?
#
#the code which associates a specific hermit card with the room you're in. ONE WORD KEYS ONLY
def activate_hermit(key = '')
if key == ''
warn("You must supply a word to associate this room with!!")
else
@key = key
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
#this grabs the hermit's unique ID from "ii hermit" so it can be stored in the hash
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
#the code which actually creates the association
def associate_hermit
warn("Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
@activatinghermit = true
end
#saves your hash of hermitty type locations
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
warn("Saved hermit tracker hash")
end
#accepts the command to grab hermit for room <key> and begin the charging/flinging process
def fling_hermit(key = '')
@key = key
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
#put the sucker away once it is activated
def put_away_hermit
if @activatinghermit
send_kmuddy_command("Put hermit in pack")
@activatinghermit = false
end
end
#to manually remove a key from the hash
def del_hash (key = '')
if key == ''
warn("You must specify the room tag you wish to remove from the database")
else
warn("deleting #{key} from the hermit locations database")
@hermithash.delete(key.to_s)
save_hash
end
end
#nicely formatted list of all the hermits the tracker is tracking
def hermit_list
warn("Hermits currently in database")
@output = "Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
warn(@output)
@hermithash.each_key { |key|
unless key == "Location"
@output = "#{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
warn(@output)
end
}
end
#been gone awhile, hermits turned to dust? Well... reset the hash
def reset_hash
warn("Resetting hermit database... all hermit location is now kaput")
@hermithash = @resethash
save_hash
end
#actually does the work of dropping/flinging the hermit to begint the teleportation
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
|
KeithHanson/rmuddy
|
0319db3f7101a859ebf199543867d4da6ccbeb6a
|
Fixed a typo in the tarot module which was breaking it... it now does in fact work
|
diff --git a/enabled-plugins/tarot.rb b/enabled-plugins/tarot.rb
index 5938df1..c7e7ed9 100644
--- a/enabled-plugins/tarot.rb
+++ b/enabled-plugins/tarot.rb
@@ -1,269 +1,297 @@
#Ok, combining the hermit tracker with auto-charger/flinger and the mass inscriber... take one
#THIS IS NOT FOOLPROOF... DON'T BE A FOOL!
#That having been said, I plan to make it foolproof at some point...
class Tarot < BasePlugin
#set up our variables, etc.
def setup
#setup triggers here
trigger /^The card begins to glow with a mystic energy./, :charged
trigger /^Rubbing your fingers briskly on the card, you charge it with necessary energy./, :charging
trigger /^The mystic glow on the Tarot card fades./, :uncharged
trigger /^You have recovered equilibrium.$/, :put_away_hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /You have successfully inscribed/, :decrement_counter #we did it!
trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
trigger /^None of your decks contain a card with the image of (.+)/, :aint_got_it
after Character, :is_balanced, :fling_card
after Character, :gained_equilibrium, :fling_card
#setup variables here... comment specific bits if necessary for sanity
#because I like some things to be stored as variables for easy changing later... formatting sheit mostly
@whichhermit = ''
@key = ''
@formatlength = 80
@formatpad = (@formatlength / 3)
@resethash = {"Location" => "card number"}
#by default, we are not, in fact, inscribing, activating, or charging any cards
- @tarotcards = %w(Sun Emperor Magician Priestess Fool Chariot Hermit Empress Lovers Hierophant Hangedman Tower Wheel Creator Justice Star Aeon Lust Universe Devil Moon Death)
- @groundonly = %w(Chariot Hermit Universe)
+ @tarotcards = %w(sun emperor magician priestess fool chariot hermit empress lovers hierophant hangedman tower wheel creator justice star aeon lust universe devil moon death)
+ @groundonly = %w(chariot hermit universe)
@charginghermit = false
@paused = false
@batch_total = 0
@inscribing = false
@number_to_inscribe = 0
@type_to_inscribe = ""
@card_to_fling = ''
@target = ''
-
+ @tarotcards.each{ |key| warn("Full Tarot list: #{key}") }
+ @groundonly.each {|key| warn("Ground Only: #{key}")}
#do any other actual setup work here
warn("Loading hermit locations database")
unless File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
warn("Failed to find and load the hermit database. You need to have hermithash.yaml in the configs directory")
else
warn("Hermit database loaded")
end
send_kmuddy_command("ind 50 hermit")
end
#this is the receptacle into which your commands for non-hermit flinging should go
def tarot_card (card = '', target = 'ground')
#determine what card to outd, outd it, then charge it
- if ! @tarotcards.downcase.include? (card.downcase)
- warn("Cereally Dude, tell me what to fling assmunch.. Make it an actual tarot card, even... then gimme a target, eh?")
- elsif @groundonly.downcase.include? (card.downcase)
- @card_to_fling = card
- @target = "ground"
- send_kmuddy_command("outd #{@card_to_fling}")
- send_kmuddy_command("charge #{@card_to_fling}")
- else
- @card_to_fling = card
- @target = target
- send_kmuddy_command("outd #{@card_to_fling}")
- send_kmuddy_command("charge #{@card_to_fling}")
+ warn("Ok, we're gonna use #{card} on #{target}")
+ @card_to_fling = card.downcase
+ @target = target.downcase
+ if @tarotcards.include?(@card_to_fling)
+ warn("It's a real tarot card!")
+ if @groundonly.include?(@card_to_fling)
+ @target = "ground"
+ send_kmuddy_command("outd #{@card_to_fling}")
+ send_kmuddy_command("charge #{@card_to_fling}")
+ else
+ send_kmuddy_command("outd #{@card_to_fling}")
+ send_kmuddy_command("charge #{@card_to_fling}")
+ end
+ else
+ warn("Ok... I need a real tarot card, and who/what to fling it at... if it's the ground, you may omit the target")
end
end
#cuz we might want some help for the tarot module
- def help
- #I'd put some help stuff here, if I were me
+ def help (topic = '')
+ if topic == ''
+ warn("Specificy a topic: inscribe, hermit, or use")
+ elsif topic.downcase == "inscribe"
+ warn("To inscribe, /notify 4567 Tarot mass_inscribe <number to inscribe> <type of tarot to inscribe>")
+ warn("Then /notify 4567 Tarot begin_inscribing to actually begin the inscription process")
+ warn("/notify 4567 (un)pause_inscription will (un)pause the batch inscription process")
+ warn("I doubt it has to be said, but just in case, that's pause_inscript or unpause_inscription, with no ()")
+ blank_line
+ elsif topic.downcase == "hermit"
+ warn("For hermit tracking, you can use /notify 4567 Tarot activate_hermit <what you want to call this place>")
+ warn("this will outd a hermit, check its card number, then activate it and put it away, storing it in our database")
+ warn("/notify 4567 Tarot fling_hermit <whereyawannago> will then grab the appropriate hermit (based on the same name you gave it when you did activate_hermit)")
+ warn("charge the hermit, and then fling it. It will at this point delete it from the database of hermit locations")
+ warn("/notify 4567 Tarot del_hash <which room to delete> will remove the room you tell it to remove from the hermit locations database")
+ warn("/notify 4567 Tarot reset_hash will wipe the entire database, if all of your hermits have decayed")
+ blank_line
+ elsif topic.downcase == "use"
+ warn("this is very basic tarot card usage here... but essentially you would")
+ warn("/notify 4567 Tarot tarot_card <which card to throw> <who/what to throw it at>")
+ warn("it should then outd the card, charge the card, and after the card is charged fling it the next time you regain equilibrium/balance")
+ blank_line
+ else
+ warn("Please specify a valid topic: inscribe, hermit, or use")
+ end
+
end
#So we know it's charged, and can fling that biatch
def charged
@charging = false
@charged = true
fling_card
end
def fling_card
#fling the card as commanded... and do the correct one, at whom, and do it
if @card_to_fling != '' && @target != '' && plugins[Character].balanced && plugins[Character].has_equilibrium && @charged
send_kmuddy_command("fling #{@card_to_fling} at #{@target}")
@card_to_fling = ''
@target = ''
uncharged
if @card_to_fling.downcase == 'hermit'
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
#in case we need it later
def charging
@charging = true
end
def uncharged
@charged = false
end
#so... you tried to outd a card you don't have...
def aint_got_it(match_object = '')
warn("You tried to get a #{match_object} but you don't have one, man.")
@card_to_fling = ''
@target = ''
end
#imported from the mass inscriber
def mass_inscribe(number_to_inscribe, type_to_inscribe)
@number_to_inscribe = number_to_inscribe.to_i
@type_to_inscribe = type_to_inscribe.to_s
@batch_total = number_to_inscribe.to_i
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
warn("Inscriber Plugin: Ready to inscribe #{@number_to_inscribe} #{@type_to_inscribe}")
warn("Use begin_inscribing to start.")
end
#begin the inscription process
def begin_inscribing
inscribe_tarot
end
#here's how we actually inscribe the bloody cards
def inscribe_tarot
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
plugins[Sipper].should_i_sip? #check to see if we need mana before we inscribe
plugins[Sipper].disable #then disable the sipper so as not to kill our inscribe
send_kmuddy_command("inscribe blank with #{@type_to_inscribe}") #and actually inscribe
end
#lower the counter, so we inscribe the correct # of cards
def decrement_counter
@number_to_inscribe -= 1 #decrement counter
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
should_we_inscribe? #check if we should do another!
end
#pretty obvious
def out_of_mana!
@inscribing = false #if we're out of mana, we're not inscribing
plugins[Sipper].enable
send_kmuddy_command("sip mana") #so we need to sip some mana
end
#so we can stop in the middle of stuff
def pause_inscription
@paused = true
end
#so we can continue when we're done flapping our gums
def unpause_inscription
@paused = false
inscribe_tarot
end
#test if we should inscribe
def should_we_inscribe?
if @number_to_inscribe > 0 && !@paused #if we still have inscription to do and we're not paused
inscribe_tarot #then inscribe
elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
send_kmuddy_command("ind #{@batch_total} #{@type_to_inscribe}") #put the cards away
plugins[Sipper].should_i_sip? #check if we need to sip
end
end
#imported from the hermit tracker... might as well keep it all in one, right?
#
#the code which associates a specific hermit card with the room you're in. ONE WORD KEYS ONLY
def activate_hermit(key = '')
if key == ''
warn("You must supply a word to associate this room with!!")
else
@key = key
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
#this grabs the hermit's unique ID from "ii hermit" so it can be stored in the hash
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
#the code which actually creates the association
def associate_hermit
warn("Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
@activatinghermit = true
end
#saves your hash of hermitty type locations
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
warn("Saved hermit tracker hash")
end
#accepts the command to grab hermit for room <key> and begin the charging/flinging process
def fling_hermit(key = '')
@key = key
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
#put the sucker away once it is activated
def put_away_hermit
if @activatinghermit
send_kmuddy_command("Put hermit in pack")
@activatinghermit = false
end
end
#to manually remove a key from the hash
def del_hash (key = '')
if key == ''
warn("You must specify the room tag you wish to remove from the database")
else
warn("deleting #{key} from the hermit locations database")
@hermithash.delete(key.to_s)
save_hash
end
end
#nicely formatted list of all the hermits the tracker is tracking
def hermit_list
warn("Hermits currently in database")
@output = "Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
warn(@output)
@hermithash.each_key { |key|
unless key == "Location"
@output = "#{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
warn(@output)
end
}
end
#been gone awhile, hermits turned to dust? Well... reset the hash
def reset_hash
warn("Resetting hermit database... all hermit location is now kaput")
@hermithash = @resethash
save_hash
end
#actually does the work of dropping/flinging the hermit to begint the teleportation
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
|
KeithHanson/rmuddy
|
579e9e908e888fe743f19c8f3446a36ff77c5371
|
All-in-one tarot plugin is now tested and operational for your enjoyment
|
diff --git a/configs/antitheft.yaml b/configs/antitheft.yaml
index 2fab944..a331c91 100644
--- a/configs/antitheft.yaml
+++ b/configs/antitheft.yaml
@@ -1,12 +1,13 @@
---
journal: ""
trousers: "leggings286549"
armor: "scalemail88722"
weapon1: ""
weapon2: ""
+shield: "shield70653"
robe: "robes290768"
shirt: "shirt286549"
ring1: ""
ring2: ""
pack: "pack296008"
shoes: "sandals167956"
\ No newline at end of file
diff --git a/enabled-plugins/hermit.rb b/disabled-plugins/hermit.rb
similarity index 100%
rename from enabled-plugins/hermit.rb
rename to disabled-plugins/hermit.rb
diff --git a/enabled-plugins/inscriber.rb b/disabled-plugins/inscriber.rb
similarity index 100%
rename from enabled-plugins/inscriber.rb
rename to disabled-plugins/inscriber.rb
diff --git a/disabled-plugins/timer.rb b/disabled-plugins/timer.rb
new file mode 100644
index 0000000..0cf4d4c
--- /dev/null
+++ b/disabled-plugins/timer.rb
@@ -0,0 +1,20 @@
+#Timer module for RMuddy... may very well be pulled back into core/init/baseplugin at some point... currently sitting outside for testing.
+
+
+class Timer < BasePlugin
+ def setup
+
+ end
+
+ #Use this in your timer blocks... this should be interesting.
+ def timer (time_to_wait, method)
+ Thread.new {
+ @start_time = time.now
+ }
+ end
+
+ def help
+ warn("Dude, you don't really need help with this... it's not going to be callable via kmuddy, I don't think")
+ end
+
+end
diff --git a/enabled-plugins/antitheft.rb b/enabled-plugins/antitheft.rb
index 6267898..1a2052e 100644
--- a/enabled-plugins/antitheft.rb
+++ b/enabled-plugins/antitheft.rb
@@ -1,187 +1,251 @@
# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
class Antitheft < BasePlugin
#setup method for the plugin.. triggers, var. init and stuff goes here
def setup
#by default, we do in fact want anti_theft
@anti_theft = true
#Setup your anti-theft triggers here... they might be different for you than me
+
+ #souldmasters and hypnosis triggers
trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
+
+ #protect your cash!
trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
+
+ #and rewear/wield things
trigger /^You remove a canvas backpack/, :rewear_pack
trigger /^You remove a suit of scale mail/, :rewear_armor
trigger /^You remove flowing violet robes./, :rewear_robe
trigger /^You remove a flowing blue shirt./, :rewear_shirt
trigger /^You remove tan coloured leggings./, :rewear_trousers
- trigger /^You remove a simple pair of wooden sandals../, :rewear_shoes
+ trigger /^You remove a simple pair of wooden sandals/, :rewear_shoes
+ trigger /You cease wielding a cavalry shield in your \w+ hand/, :rewear_shield
+ trigger /You drop a cavalry shield./, :pickup_shield
+
+ #triggers so you know you put the stuff on
+ trigger /You begin to wield a cavalry shield in your left hand/, :reset_shield
+ trigger /You are now wearing tan coloured leggings./, :reset_trousers
+ trigger /You are now wearing a flowing blue shirt./, :reset_shirt
+ trigger /You are now wearing a suit of scale mail./, :reset_armor
+ trigger /You are now wearing flowing violet robes./, :reset_robe
+ trigger /You are now wearing a canvas backpack./, :reset_pack
+ trigger /You are now wearing a simple pair of wooden sandals./, :reset_shoe
#After we gain balance, check if we need to rewear something!
after Character, :is_balanced, :rewear?
#load the theft database
unless (File.open("configs/antitheft.yaml") {|fi| @thefthash = YAML.load(fi)})
warn("No configuration file found... you must have the configuration file")
warn("antitheft.yaml in the configs directory")
end
#here, we'll push a bunch of variables out to kmuddy
@thefthash.each_key {|key| set_kmuddy_variable("theft_#{key}", @thefthash[key])}
end
def hypnosis (match_object )
if @anti_theft
send_kmuddy_command("lose #{match_object[1]}")
send_kmuddy_command("/echo OK! YOU MAY BE GETTING STOLEN FROM!")
end
end
def help
warn("OK, you asked for it. You must setup the YAML file. It has a format.")
warn("Each thing should be on a seperate line")
warn("The format is... on separate lines, mind you, with nothing in front of it")
warn("item: \"<fully described item, with number here>\"")
blank_line
warn("example:")
warn("pack: \"pack296008\"")
blank_line
warn("Items which can be set in the yaml file. There is a set_hash method ... ")
warn("\"/notify 4567 Antitheft set_hash pack pack1234\" ...\"/notify 4567 ")
warn("Antitheft set_hash armor scalemail1234\" etc.")
@thefthash.each_key { |key| warn("#{key}") }
blank_line
warn("If you've got alternate gear... say, a sailor's kitbag, or what have")
warn("you, you'll need to modify the triggers in the antitheft.rb file to ")
warn("match the appropriate message")
blank_line
warn("Finally, you can save your hash to the config file using /notify 4567 ")
warn("Antitheft save_hash")
end
def rewear_pack
if @anti_theft
@packbalance = true
send_kmuddy_command("wear #{@thefthash["pack"]}")
end
end
def rewear_shoes
if @anti_theft
@shoebalance = true
send_kmuddy_command("wear #{@thefthash["shoes"]}")
end
end
+ def rewear_shield
+ if @anti_theft
+ @shieldbalance = true
+ send_kmuddy_command("wear #{@thefthash["shield"]}")
+ end
+ end
+
+ def reset_shield
+ @shieldbalance = false
+ end
+
+ def reset_trousers
+ @trouserbalance = false
+ end
+
+ def reset_shirt
+ @shirtbalance = false
+ end
+
+ def reset_armor
+ @armorbalance = false
+ end
+
+ def reset_robe
+ @robebalance = false
+ end
+
+ def reset_pack
+ @packbalance = false
+ end
+
+ def reset_shoe
+ @shoebalance = false
+ end
+
+ def pickup_shield
+ if @anti_theft
+ send_kmuddy_command("Get #{@thefthash["shield"]}")
+ send_kmuddy_command("wield #{@thefthash["shield"]}")
+ @shieldbalance = true
+ end
+ end
+
def rewear_shirt
if @anti_theft
@shirtbalance = true
send_kmuddy_command("wear #{@thefthash["shirt"]}")
end
end
def rewear_trousers
if @anti_theft
@trouserbalance = true
send_kmuddy_command("wear #{@thefthash["trousers"]}")
end
end
def rewear_armor
if @anti_theft
@armorbalance = true
send_kmuddy_command("wear #{@thefthash["armor"]}")
end
end
def rewear_robe
if @anti_theft
@robebalance = true
send_kmuddy_command("wear #{@thefthash["robe"]}")
end
end
def rewear?
if @soulmaster
send_kmuddy_command("lose soulmaster")
@soulmaster = false
elsif @packbalance
send_kmuddy_command("wear #{@thefthash["pack"]}")
@packbalance = false
elsif @armorbalance
send_kmuddy_command("wear #{@thefthash["armor"]}")
@armorbalance = false
+
+ elsif @shieldbalance
+ send_kmuddy_command("wear #{@thefthash["shield"]}")
+ @shieldbalance = false
elsif @shoebalance
send_kmuddy_command("wear #{@thefthash["shoes"]}")
elsif @shirtbalance
send_kmuddy_command("wear #{@thefthash["shirt"]}")
@shirtbalance = false
elsif @trouserbalance
send_kmuddy_command("wear #{@thefthash["trousers"]}")
@trouserbalance = false
elsif @robebalance
send_kmuddy_command("wear #{@thefthash["robe"]}")
@robebalance = 0
end
end
def print_hash
warn("Printing anti-theft database, this may be spammy")
@thefthash.each_key { |key| warn("#{key}: #{@thefthash[key]}" ) }
end
def put_gold_away
if @anti_theft
send_kmuddy_command("put sovereigns in #{@thefthash["pack"]}")
end
end
def test (key = "pack")
send_kmuddy_command("/echo #{@thefthash[key]}")
end
def lose_soulmaster
send_kmuddy_command("lose soulmaster")
@soulmaster = true
end
def set_hash (key = '', value = '')
if (key == '' && value == '')
warn("You must tell me what article you are trying to protect, and which")
warn("one it is supposed to be specifically!")
elsif (key != '' && value =='')
warn("You have to tell me what #{key} is your's, specifically!")
elsif (key == '' && value != '')
warn("You have to tell me what kind of item #{value} is, so we can properly protect it!")
else
@thefthash[key] = value
warn("Setting item #{key} to your specific item, #{value}")
save_hash
end
end
def theft_on
@anti_theft = true
end
def theft_off
@anti_theft = false
end
def save_hash
warn("Saving antitheft configuration")
unless (File.open("configs/antitheft.yaml", "w") {|fi| @thefthash = YAML.dump(fi)})
warn("Could not write configuration file for antitheft")
end
end
end
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 0239353..4045bf1 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,146 +1,150 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
class Character < BasePlugin
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :current_health, :current_mana
attr_accessor :total_health, :total_mana
attr_accessor :current_endurance, :total_endurance
attr_accessor :current_willpower, :total_willpower
attr_accessor :balanced
attr_accessor :status
attr_accessor :has_equilibrium
def setup
#By default, we are assumed to be balanced and to have equilibrium.
@balanced = true
@has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :set_total_endurance
#set the balance when it returns.(useful for antitheft)
trigger /^You have recovered balance on all limbs.$/, :is_balanced
- #demonnic: set the equilibrium when it returns(useful for some things)
+ #demonnic: set the equilibrium when it returns(useful for some things *tarot*)
trigger /^You have recovered equilibrium.$/, :gained_equilibrium
#We use the prompt to tell us when we are unbalanced.
#trigger /^\d+h, \d+m\se-/, :is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
#trigger /You reach out and bop/, :is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def set_simple_stats(match_object)
unless @using_extended_stats == true
@current_health = match_object[1].to_i
@current_mana = match_object[2].to_i
@balanced = match_object[3].include?("x")
@has_equilibrium = match_object[3].include?("e")
#Because it will be helpful to keep using is_balanced and gained_equilibrium
if match_object[3].include?("x")
is_balanced
elsif match_object[3].include?("e")
gained_equilibrium
end
debug("Character: Loaded Current Stats")
debug("Character: Sending Current Stats")
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_balanced", @balanced)
set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
debug("Character: Sent Current Stats")
unless @total_health
send_kmuddy_command("qsc")
end
end
end
def set_extended_stats(match_object)
@current_health = match_object[1].to_i
@current_mana = match_object[2].to_i
@current_endurance = match_object[3].to_i
@current_willpower = match_object[4].to_i
@balanced = match_object[5].include?("x")
@has_equilibrium = match_object[5].include?("e")
-
+ if match_object[3].include?("x")
+ is_balanced
+ elsif match_object[3].include?("e")
+ gained_equilibrium
+ end
debug("Character: Loaded Current Stats")
debug("Character: Sending Current Stats")
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_current_endurance", @current_endurance)
set_kmuddy_variable("character_current_willpower", @current_willpower)
set_kmuddy_variable("character_balanced", @balanced)
set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
debug("Character: Sent Current Stats")
@using_extended_stats = true
unless @total_health
send_kmuddy_command("qsc")
end
end
def set_total_health(match_object )
@total_health = match_object[2].to_i
@current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_total_health", @total_health)
end
def set_total_mana(match_object )
@total_mana = match_object[2].to_i
@current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_total_mana", @total_mana)
end
def set_total_endurance(match_object )
@total_endurance = match_object[2].to_i
@current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @current_endurance)
set_kmuddy_variable("character_total_endurance", @total_endurance)
end
def set_total_willpower(match_object )
@total_willpower = match_object[2].to_i
@current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @current_willpower)
set_kmuddy_variable("character_total_willpower", @total_willpower)
end
def is_balanced
@balanced = true
end
def is_unbalanced
@balanced = false
end
def gained_equilibrium
@has_equilibrium = true
end
def lost_equilibrium
@has_equilibrium = false
end
end
\ No newline at end of file
diff --git a/disabled-plugins/tarot.rb b/enabled-plugins/tarot.rb
similarity index 94%
rename from disabled-plugins/tarot.rb
rename to enabled-plugins/tarot.rb
index bd4f67f..5938df1 100644
--- a/disabled-plugins/tarot.rb
+++ b/enabled-plugins/tarot.rb
@@ -1,258 +1,269 @@
#Ok, combining the hermit tracker with auto-charger/flinger and the mass inscriber... take one
#THIS IS NOT FOOLPROOF... DON'T BE A FOOL!
#That having been said, I plan to make it foolproof at some point...
class Tarot < BasePlugin
#set up our variables, etc.
def setup
#setup triggers here
trigger /^The card begins to glow with a mystic energy./, :charged
trigger /^Rubbing your fingers briskly on the card, you charge it with necessary energy./, :charging
trigger /^The mystic glow on the Tarot card fades./, :uncharged
trigger /^You have recovered equilibrium.$/, :put_away_hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /You have successfully inscribed/, :decrement_counter #we did it!
trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
trigger /^None of your decks contain a card with the image of (.+)/, :aint_got_it
-
+ after Character, :is_balanced, :fling_card
+ after Character, :gained_equilibrium, :fling_card
#setup variables here... comment specific bits if necessary for sanity
#because I like some things to be stored as variables for easy changing later... formatting sheit mostly
@whichhermit = ''
@key = ''
@formatlength = 80
@formatpad = (@formatlength / 3)
@resethash = {"Location" => "card number"}
#by default, we are not, in fact, inscribing, activating, or charging any cards
@tarotcards = %w(Sun Emperor Magician Priestess Fool Chariot Hermit Empress Lovers Hierophant Hangedman Tower Wheel Creator Justice Star Aeon Lust Universe Devil Moon Death)
+ @groundonly = %w(Chariot Hermit Universe)
@charginghermit = false
@paused = false
@batch_total = 0
@inscribing = false
@number_to_inscribe = 0
@type_to_inscribe = ""
@card_to_fling = ''
@target = ''
#do any other actual setup work here
warn("Loading hermit locations database")
unless File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
warn("Failed to find and load the hermit database. You need to have hermithash.yaml in the configs directory")
else
warn("Hermit database loaded")
end
send_kmuddy_command("ind 50 hermit")
end
#this is the receptacle into which your commands for non-hermit flinging should go
def tarot_card (card = '', target = 'ground')
#determine what card to outd, outd it, then charge it
- if ! @tarotcards.include? (card)
+ if ! @tarotcards.downcase.include? (card.downcase)
warn("Cereally Dude, tell me what to fling assmunch.. Make it an actual tarot card, even... then gimme a target, eh?")
- elsif @groundonly.include? (card)
+ elsif @groundonly.downcase.include? (card.downcase)
@card_to_fling = card
@target = "ground"
send_kmuddy_command("outd #{@card_to_fling}")
send_kmuddy_command("charge #{@card_to_fling}")
else
@card_to_fling = card
@target = target
send_kmuddy_command("outd #{@card_to_fling}")
send_kmuddy_command("charge #{@card_to_fling}")
end
end
#cuz we might want some help for the tarot module
def help
#I'd put some help stuff here, if I were me
end
#So we know it's charged, and can fling that biatch
def charged
@charging = false
+ @charged = true
+ fling_card
+ end
+ def fling_card
#fling the card as commanded... and do the correct one, at whom, and do it
- if @card_to_fling != '' && @target != ''
+ if @card_to_fling != '' && @target != '' && plugins[Character].balanced && plugins[Character].has_equilibrium && @charged
send_kmuddy_command("fling #{@card_to_fling} at #{@target}")
+ @card_to_fling = ''
+ @target = ''
+ uncharged
if @card_to_fling.downcase == 'hermit'
@charginghermit = false
@hermithash.delete(@key.to_s)
end
- @card_to_fling = ''
- @target = ''
end
end
#in case we need it later
def charging
@charging = true
end
+ def uncharged
+ @charged = false
+ end
+
#so... you tried to outd a card you don't have...
def aint_got_it(match_object = '')
warn("You tried to get a #{match_object} but you don't have one, man.")
@card_to_fling = ''
@target = ''
end
#imported from the mass inscriber
def mass_inscribe(number_to_inscribe, type_to_inscribe)
@number_to_inscribe = number_to_inscribe.to_i
@type_to_inscribe = type_to_inscribe.to_s
@batch_total = number_to_inscribe.to_i
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
warn("Inscriber Plugin: Ready to inscribe #{@number_to_inscribe} #{@type_to_inscribe}")
warn("Use begin_inscribing to start.")
end
#begin the inscription process
def begin_inscribing
inscribe_tarot
end
#here's how we actually inscribe the bloody cards
def inscribe_tarot
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
plugins[Sipper].should_i_sip? #check to see if we need mana before we inscribe
plugins[Sipper].disable #then disable the sipper so as not to kill our inscribe
send_kmuddy_command("inscribe blank with #{@type_to_inscribe}") #and actually inscribe
end
#lower the counter, so we inscribe the correct # of cards
def decrement_counter
@number_to_inscribe -= 1 #decrement counter
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
should_we_inscribe? #check if we should do another!
end
#pretty obvious
def out_of_mana!
@inscribing = false #if we're out of mana, we're not inscribing
plugins[Sipper].enable
send_kmuddy_command("sip mana") #so we need to sip some mana
end
#so we can stop in the middle of stuff
def pause_inscription
@paused = true
end
#so we can continue when we're done flapping our gums
def unpause_inscription
@paused = false
inscribe_tarot
end
#test if we should inscribe
def should_we_inscribe?
if @number_to_inscribe > 0 && !@paused #if we still have inscription to do and we're not paused
inscribe_tarot #then inscribe
elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
send_kmuddy_command("ind #{@batch_total} #{@type_to_inscribe}") #put the cards away
plugins[Sipper].should_i_sip? #check if we need to sip
end
end
#imported from the hermit tracker... might as well keep it all in one, right?
#
#the code which associates a specific hermit card with the room you're in. ONE WORD KEYS ONLY
def activate_hermit(key = '')
if key == ''
warn("You must supply a word to associate this room with!!")
else
@key = key
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
#this grabs the hermit's unique ID from "ii hermit" so it can be stored in the hash
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
#the code which actually creates the association
def associate_hermit
warn("Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
@activatinghermit = true
end
#saves your hash of hermitty type locations
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
warn("Saved hermit tracker hash")
end
#accepts the command to grab hermit for room <key> and begin the charging/flinging process
def fling_hermit(key = '')
@key = key
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
#put the sucker away once it is activated
def put_away_hermit
if @activatinghermit
send_kmuddy_command("Put hermit in pack")
@activatinghermit = false
end
end
#to manually remove a key from the hash
def del_hash (key = '')
if key == ''
warn("You must specify the room tag you wish to remove from the database")
else
warn("deleting #{key} from the hermit locations database")
@hermithash.delete(key.to_s)
save_hash
end
end
#nicely formatted list of all the hermits the tracker is tracking
def hermit_list
warn("Hermits currently in database")
@output = "Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
warn(@output)
@hermithash.each_key { |key|
unless key == "Location"
@output = "#{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
warn(@output)
end
}
end
#been gone awhile, hermits turned to dust? Well... reset the hash
def reset_hash
warn("Resetting hermit database... all hermit location is now kaput")
@hermithash = @resethash
save_hash
end
#actually does the work of dropping/flinging the hermit to begint the teleportation
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
|
KeithHanson/rmuddy
|
34c1a440830cbdfd0b6694e97fe028a56be91599
|
I am a sadist, and combined all the tarot like stuff into one module... it's still disable as it has been completely untested to this point. I also added shoes to the anti-theft stacks and suchlike.
|
diff --git a/configs/antitheft.yaml b/configs/antitheft.yaml
index 945c0d0..2fab944 100644
--- a/configs/antitheft.yaml
+++ b/configs/antitheft.yaml
@@ -1,11 +1,12 @@
---
journal: ""
trousers: "leggings286549"
armor: "scalemail88722"
weapon1: ""
weapon2: ""
robe: "robes290768"
shirt: "shirt286549"
ring1: ""
ring2: ""
-pack: "pack296008"
\ No newline at end of file
+pack: "pack296008"
+shoes: "sandals167956"
\ No newline at end of file
diff --git a/disabled-plugins/tarot.rb b/disabled-plugins/tarot.rb
new file mode 100644
index 0000000..bd4f67f
--- /dev/null
+++ b/disabled-plugins/tarot.rb
@@ -0,0 +1,258 @@
+#Ok, combining the hermit tracker with auto-charger/flinger and the mass inscriber... take one
+#THIS IS NOT FOOLPROOF... DON'T BE A FOOL!
+#That having been said, I plan to make it foolproof at some point...
+
+
+class Tarot < BasePlugin
+ #set up our variables, etc.
+ def setup
+ #setup triggers here
+ trigger /^The card begins to glow with a mystic energy./, :charged
+ trigger /^Rubbing your fingers briskly on the card, you charge it with necessary energy./, :charging
+ trigger /^The mystic glow on the Tarot card fades./, :uncharged
+ trigger /^You have recovered equilibrium.$/, :put_away_hermit
+ trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
+ trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
+ trigger /You have successfully inscribed/, :decrement_counter #we did it!
+ trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
+ trigger /^None of your decks contain a card with the image of (.+)/, :aint_got_it
+
+ #setup variables here... comment specific bits if necessary for sanity
+
+ #because I like some things to be stored as variables for easy changing later... formatting sheit mostly
+ @whichhermit = ''
+ @key = ''
+ @formatlength = 80
+ @formatpad = (@formatlength / 3)
+ @resethash = {"Location" => "card number"}
+
+ #by default, we are not, in fact, inscribing, activating, or charging any cards
+ @tarotcards = %w(Sun Emperor Magician Priestess Fool Chariot Hermit Empress Lovers Hierophant Hangedman Tower Wheel Creator Justice Star Aeon Lust Universe Devil Moon Death)
+ @charginghermit = false
+ @paused = false
+ @batch_total = 0
+ @inscribing = false
+ @number_to_inscribe = 0
+ @type_to_inscribe = ""
+ @card_to_fling = ''
+ @target = ''
+
+ #do any other actual setup work here
+ warn("Loading hermit locations database")
+ unless File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
+ warn("Failed to find and load the hermit database. You need to have hermithash.yaml in the configs directory")
+ else
+ warn("Hermit database loaded")
+ end
+ send_kmuddy_command("ind 50 hermit")
+ end
+
+ #this is the receptacle into which your commands for non-hermit flinging should go
+ def tarot_card (card = '', target = 'ground')
+ #determine what card to outd, outd it, then charge it
+ if ! @tarotcards.include? (card)
+ warn("Cereally Dude, tell me what to fling assmunch.. Make it an actual tarot card, even... then gimme a target, eh?")
+ elsif @groundonly.include? (card)
+ @card_to_fling = card
+ @target = "ground"
+ send_kmuddy_command("outd #{@card_to_fling}")
+ send_kmuddy_command("charge #{@card_to_fling}")
+ else
+ @card_to_fling = card
+ @target = target
+ send_kmuddy_command("outd #{@card_to_fling}")
+ send_kmuddy_command("charge #{@card_to_fling}")
+ end
+ end
+
+ #cuz we might want some help for the tarot module
+ def help
+ #I'd put some help stuff here, if I were me
+ end
+
+ #So we know it's charged, and can fling that biatch
+ def charged
+ @charging = false
+ #fling the card as commanded... and do the correct one, at whom, and do it
+ if @card_to_fling != '' && @target != ''
+ send_kmuddy_command("fling #{@card_to_fling} at #{@target}")
+ if @card_to_fling.downcase == 'hermit'
+ @charginghermit = false
+ @hermithash.delete(@key.to_s)
+ end
+ @card_to_fling = ''
+ @target = ''
+ end
+ end
+
+ #in case we need it later
+ def charging
+ @charging = true
+ end
+
+ #so... you tried to outd a card you don't have...
+ def aint_got_it(match_object = '')
+ warn("You tried to get a #{match_object} but you don't have one, man.")
+ @card_to_fling = ''
+ @target = ''
+ end
+
+ #imported from the mass inscriber
+ def mass_inscribe(number_to_inscribe, type_to_inscribe)
+ @number_to_inscribe = number_to_inscribe.to_i
+ @type_to_inscribe = type_to_inscribe.to_s
+ @batch_total = number_to_inscribe.to_i
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
+ set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
+ warn("Inscriber Plugin: Ready to inscribe #{@number_to_inscribe} #{@type_to_inscribe}")
+ warn("Use begin_inscribing to start.")
+ end
+
+ #begin the inscription process
+ def begin_inscribing
+ inscribe_tarot
+ end
+
+ #here's how we actually inscribe the bloody cards
+ def inscribe_tarot
+ disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
+ plugins[Sipper].should_i_sip? #check to see if we need mana before we inscribe
+ plugins[Sipper].disable #then disable the sipper so as not to kill our inscribe
+ send_kmuddy_command("inscribe blank with #{@type_to_inscribe}") #and actually inscribe
+ end
+
+ #lower the counter, so we inscribe the correct # of cards
+ def decrement_counter
+ @number_to_inscribe -= 1 #decrement counter
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
+ should_we_inscribe? #check if we should do another!
+ end
+
+ #pretty obvious
+ def out_of_mana!
+ @inscribing = false #if we're out of mana, we're not inscribing
+ plugins[Sipper].enable
+ send_kmuddy_command("sip mana") #so we need to sip some mana
+ end
+
+ #so we can stop in the middle of stuff
+ def pause_inscription
+ @paused = true
+ end
+
+ #so we can continue when we're done flapping our gums
+ def unpause_inscription
+ @paused = false
+ inscribe_tarot
+ end
+
+ #test if we should inscribe
+ def should_we_inscribe?
+ if @number_to_inscribe > 0 && !@paused #if we still have inscription to do and we're not paused
+ inscribe_tarot #then inscribe
+ elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
+ disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
+ send_kmuddy_command("ind #{@batch_total} #{@type_to_inscribe}") #put the cards away
+ plugins[Sipper].should_i_sip? #check if we need to sip
+ end
+ end
+
+ #imported from the hermit tracker... might as well keep it all in one, right?
+ #
+ #the code which associates a specific hermit card with the room you're in. ONE WORD KEYS ONLY
+ def activate_hermit(key = '')
+ if key == ''
+ warn("You must supply a word to associate this room with!!")
+ else
+ @key = key
+ warn("Ok, activating a hermit for this room")
+ send_kmuddy_command("outd hermit")
+ send_kmuddy_command("ii hermit")
+ end
+
+ end
+
+ #this grabs the hermit's unique ID from "ii hermit" so it can be stored in the hash
+ def set_value(match_object )
+ @whichhermit = match_object[1]
+ associate_hermit
+ end
+
+ #the code which actually creates the association
+ def associate_hermit
+ warn("Associating card #{@whichhermit} with the place name #{@key}")
+ @hermithash[@key] = @whichhermit
+ send_kmuddy_command("activate hermit")
+ @activatinghermit = true
+ end
+
+ #saves your hash of hermitty type locations
+ def save_hash
+ File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
+ warn("Saved hermit tracker hash")
+ end
+
+ #accepts the command to grab hermit for room <key> and begin the charging/flinging process
+ def fling_hermit(key = '')
+ @key = key
+ if key == ''
+ warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
+ else
+ send_kmuddy_command("get #{@hermithash[key]} from pack")
+ send_kmuddy_command("charge hermit")
+ @charginghermit = true
+ end
+ end
+
+ #put the sucker away once it is activated
+ def put_away_hermit
+ if @activatinghermit
+ send_kmuddy_command("Put hermit in pack")
+ @activatinghermit = false
+ end
+ end
+
+ #to manually remove a key from the hash
+ def del_hash (key = '')
+ if key == ''
+ warn("You must specify the room tag you wish to remove from the database")
+ else
+ warn("deleting #{key} from the hermit locations database")
+ @hermithash.delete(key.to_s)
+ save_hash
+ end
+ end
+
+ #nicely formatted list of all the hermits the tracker is tracking
+ def hermit_list
+ warn("Hermits currently in database")
+ @output = "Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
+ warn(@output)
+ @hermithash.each_key { |key|
+ unless key == "Location"
+ @output = "#{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
+ warn(@output)
+ end
+ }
+ end
+
+ #been gone awhile, hermits turned to dust? Well... reset the hash
+ def reset_hash
+ warn("Resetting hermit database... all hermit location is now kaput")
+ @hermithash = @resethash
+ save_hash
+ end
+
+ #actually does the work of dropping/flinging the hermit to begint the teleportation
+ def hermit_drop
+ if @charginghermit
+ send_kmuddy_command("fling hermit at ground")
+ @charginghermit = false
+ @hermithash.delete(@key.to_s)
+ end
+ end
+
+end
+
+
+
diff --git a/enabled-plugins/antitheft.rb b/enabled-plugins/antitheft.rb
index d5fa716..6267898 100644
--- a/enabled-plugins/antitheft.rb
+++ b/enabled-plugins/antitheft.rb
@@ -1,156 +1,187 @@
# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
class Antitheft < BasePlugin
#setup method for the plugin.. triggers, var. init and stuff goes here
def setup
#by default, we do in fact want anti_theft
@anti_theft = true
#Setup your anti-theft triggers here... they might be different for you than me
trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
trigger /^You remove a canvas backpack/, :rewear_pack
trigger /^You remove a suit of scale mail/, :rewear_armor
trigger /^You remove flowing violet robes./, :rewear_robe
+ trigger /^You remove a flowing blue shirt./, :rewear_shirt
+ trigger /^You remove tan coloured leggings./, :rewear_trousers
+ trigger /^You remove a simple pair of wooden sandals../, :rewear_shoes
#After we gain balance, check if we need to rewear something!
after Character, :is_balanced, :rewear?
#load the theft database
unless (File.open("configs/antitheft.yaml") {|fi| @thefthash = YAML.load(fi)})
warn("No configuration file found... you must have the configuration file")
warn("antitheft.yaml in the configs directory")
end
#here, we'll push a bunch of variables out to kmuddy
@thefthash.each_key {|key| set_kmuddy_variable("theft_#{key}", @thefthash[key])}
end
def hypnosis (match_object )
if @anti_theft
send_kmuddy_command("lose #{match_object[1]}")
send_kmuddy_command("/echo OK! YOU MAY BE GETTING STOLEN FROM!")
end
end
def help
warn("OK, you asked for it. You must setup the YAML file. It has a format.")
warn("Each thing should be on a seperate line")
warn("The format is... on separate lines, mind you, with nothing in front of it")
warn("item: \"<fully described item, with number here>\"")
blank_line
warn("example:")
warn("pack: \"pack296008\"")
blank_line
warn("Items which can be set in the yaml file. There is a set_hash method ... ")
warn("\"/notify 4567 Antitheft set_hash pack pack1234\" ...\"/notify 4567 ")
warn("Antitheft set_hash armor scalemail1234\" etc.")
@thefthash.each_key { |key| warn("#{key}") }
blank_line
warn("If you've got alternate gear... say, a sailor's kitbag, or what have")
warn("you, you'll need to modify the triggers in the antitheft.rb file to ")
warn("match the appropriate message")
blank_line
warn("Finally, you can save your hash to the config file using /notify 4567 ")
warn("Antitheft save_hash")
end
def rewear_pack
if @anti_theft
@packbalance = true
send_kmuddy_command("wear #{@thefthash["pack"]}")
end
end
+ def rewear_shoes
+ if @anti_theft
+ @shoebalance = true
+ send_kmuddy_command("wear #{@thefthash["shoes"]}")
+ end
+ end
+
+ def rewear_shirt
+ if @anti_theft
+ @shirtbalance = true
+ send_kmuddy_command("wear #{@thefthash["shirt"]}")
+ end
+ end
+
+ def rewear_trousers
+ if @anti_theft
+ @trouserbalance = true
+ send_kmuddy_command("wear #{@thefthash["trousers"]}")
+ end
+ end
def rewear_armor
if @anti_theft
@armorbalance = true
send_kmuddy_command("wear #{@thefthash["armor"]}")
end
end
def rewear_robe
if @anti_theft
@robebalance = true
send_kmuddy_command("wear #{@thefthash["robe"]}")
end
end
def rewear?
- if @souldmaster
+ if @soulmaster
send_kmuddy_command("lose soulmaster")
@soulmaster = false
- end
-
- if @packbalance
+
+ elsif @packbalance
send_kmuddy_command("wear #{@thefthash["pack"]}")
@packbalance = false
- end
-
- if @armorbalance
+
+ elsif @armorbalance
send_kmuddy_command("wear #{@thefthash["armor"]}")
@armorbalance = false
- end
-
- if @robebalance
+
+ elsif @shoebalance
+ send_kmuddy_command("wear #{@thefthash["shoes"]}")
+
+ elsif @shirtbalance
+ send_kmuddy_command("wear #{@thefthash["shirt"]}")
+ @shirtbalance = false
+
+ elsif @trouserbalance
+ send_kmuddy_command("wear #{@thefthash["trousers"]}")
+ @trouserbalance = false
+
+ elsif @robebalance
send_kmuddy_command("wear #{@thefthash["robe"]}")
@robebalance = 0
end
end
def print_hash
warn("Printing anti-theft database, this may be spammy")
@thefthash.each_key { |key| warn("#{key}: #{@thefthash[key]}" ) }
end
def put_gold_away
if @anti_theft
send_kmuddy_command("put sovereigns in #{@thefthash["pack"]}")
end
end
def test (key = "pack")
send_kmuddy_command("/echo #{@thefthash[key]}")
end
def lose_soulmaster
send_kmuddy_command("lose soulmaster")
@soulmaster = true
end
def set_hash (key = '', value = '')
if (key == '' && value == '')
warn("You must tell me what article you are trying to protect, and which")
warn("one it is supposed to be specifically!")
elsif (key != '' && value =='')
warn("You have to tell me what #{key} is your's, specifically!")
elsif (key == '' && value != '')
warn("You have to tell me what kind of item #{value} is, so we can properly protect it!")
else
@thefthash[key] = value
warn("Setting item #{key} to your specific item, #{value}")
save_hash
end
end
def theft_on
@anti_theft = true
end
def theft_off
@anti_theft = false
end
def save_hash
warn("Saving antitheft configuration")
unless (File.open("configs/antitheft.yaml", "w") {|fi| @thefthash = YAML.dump(fi)})
warn("Could not write configuration file for antitheft")
end
end
end
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 9559420..0239353 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,146 +1,146 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
class Character < BasePlugin
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :current_health, :current_mana
attr_accessor :total_health, :total_mana
attr_accessor :current_endurance, :total_endurance
attr_accessor :current_willpower, :total_willpower
attr_accessor :balanced
attr_accessor :status
attr_accessor :has_equilibrium
def setup
#By default, we are assumed to be balanced and to have equilibrium.
@balanced = true
@has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :set_total_endurance
- #set the balance when it returns.
- #trigger /^You have recovered balance on all limbs.$/, :is_balanced
+ #set the balance when it returns.(useful for antitheft)
+ trigger /^You have recovered balance on all limbs.$/, :is_balanced
- #demonnic: set the equilibrium when it returns
- #trigger /^You have recovered equilibrium.$/, :gained_equilibrium
+ #demonnic: set the equilibrium when it returns(useful for some things)
+ trigger /^You have recovered equilibrium.$/, :gained_equilibrium
#We use the prompt to tell us when we are unbalanced.
#trigger /^\d+h, \d+m\se-/, :is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
#trigger /You reach out and bop/, :is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def set_simple_stats(match_object)
unless @using_extended_stats == true
@current_health = match_object[1].to_i
@current_mana = match_object[2].to_i
@balanced = match_object[3].include?("x")
@has_equilibrium = match_object[3].include?("e")
#Because it will be helpful to keep using is_balanced and gained_equilibrium
if match_object[3].include?("x")
is_balanced
elsif match_object[3].include?("e")
gained_equilibrium
end
debug("Character: Loaded Current Stats")
debug("Character: Sending Current Stats")
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_balanced", @balanced)
set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
debug("Character: Sent Current Stats")
unless @total_health
send_kmuddy_command("qsc")
end
end
end
def set_extended_stats(match_object)
@current_health = match_object[1].to_i
@current_mana = match_object[2].to_i
@current_endurance = match_object[3].to_i
@current_willpower = match_object[4].to_i
@balanced = match_object[5].include?("x")
@has_equilibrium = match_object[5].include?("e")
debug("Character: Loaded Current Stats")
debug("Character: Sending Current Stats")
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_current_endurance", @current_endurance)
set_kmuddy_variable("character_current_willpower", @current_willpower)
set_kmuddy_variable("character_balanced", @balanced)
set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
debug("Character: Sent Current Stats")
@using_extended_stats = true
unless @total_health
send_kmuddy_command("qsc")
end
end
def set_total_health(match_object )
@total_health = match_object[2].to_i
@current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_total_health", @total_health)
end
def set_total_mana(match_object )
@total_mana = match_object[2].to_i
@current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_total_mana", @total_mana)
end
def set_total_endurance(match_object )
@total_endurance = match_object[2].to_i
@current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @current_endurance)
set_kmuddy_variable("character_total_endurance", @total_endurance)
end
def set_total_willpower(match_object )
@total_willpower = match_object[2].to_i
@current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @current_willpower)
set_kmuddy_variable("character_total_willpower", @total_willpower)
end
def is_balanced
@balanced = true
end
def is_unbalanced
@balanced = false
end
def gained_equilibrium
@has_equilibrium = true
end
def lost_equilibrium
@has_equilibrium = false
end
end
\ No newline at end of file
diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb
index 8a98398..1767993 100644
--- a/enabled-plugins/sipper.rb
+++ b/enabled-plugins/sipper.rb
@@ -1,73 +1,73 @@
#The AutoSipper. It checks to see if a certain threshold percentage is hit for
#Health and Mana, and keeps your health/mana above that percentage.
#
#You will undoubtedly need to add exception triggers in to disable sipping,
#but right now it is customized for Tarot inscribing.
class Sipper < BasePlugin
attr_accessor :sipper_enabled
def sipper_enabled?
@sipper_enabled
end
#Check to make sure we are not below our health threshold
#We make sure to use floats! Since integers round ;)
def health_below_threshold?
(plugins[Character].current_health.to_f / plugins[Character].total_health.to_f) * 100 < @health_threshold_percentage
end
#Same as above
def mana_below_threshold?
(plugins[Character].current_mana.to_f / plugins[Character].total_mana.to_f) * 100 < @mana_threshold_percentage
end
def setup
#By default, we want to be healed ;)
@sipper_enabled = true
#Our health and mana thresholds
- @health_threshold_percentage = 50
+ @health_threshold_percentage = 65
@mana_threshold_percentage = 40
#After every time the character's current stats are updated, we check to see if we should sip.
after Character, :set_simple_stats, :should_i_sip?
after Character, :set_extended_stats, :should_i_sip?
#This group of triggers disables the sipping for various reasons.
trigger /^Your mind feels stronger and more alert\.$/, :disable_sip
trigger /^The elixer heals and soothes you\.$/, :disable_sip
trigger /^What is it that you wish to drink\?$/, :disable_sip
trigger /^You are asleep and can do nothing\./, :disable_sip
trigger /^The elixer flows down your throat without effect/, :disable_sip
trigger /Wisely preparing yourself beforehand/, :disable_sip
#This group of triggers, substantially smaller, enables the sipping when we can :)
trigger /^You may drink another .*$/, :enable_sip
trigger /^You have successfully inscribed/, :enable_sip
end
#The heart of the plugin...
def should_i_sip?
#If we don't have our total scores, wait until character fills them in.
if plugins[Character].total_mana && plugins[Character].total_health
#Otherwise, begin checking health and mana to see if we need to do some drinking...
if health_below_threshold? && sipper_enabled?
send_kmuddy_command("drink health")
@sipper_enabled = false
end
if mana_below_threshold? && sipper_enabled?
send_kmuddy_command("drink mana")
@sipper_enabled = false
end
end
end
def disable_sip
@sipper_enabled = false
end
def enable_sip
@sipper_enabled = true
end
end
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index abccbaf..581e2e6 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,222 +1,222 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
class Walker < BasePlugin
attr_accessor :opposite_directions, :last_timer, :lost_or_not, :seconds_to_wait
attr_accessor :rail_position, :current_rail, :current_thread, :ratter_rail, :auto_walk_enabled
attr_accessor :back_tracking
def setup
warn("***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#lost or not? Well, let's see
@lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
- trigger /is here, shrouded\./, :skip_room
+ trigger /is here, (shrouded|hidden)\./, :skip_room
trigger /There is no exit in that direction/, :lost!
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
sleep 0.03
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
sleep 1
end
#If we can walk, walk!
if plugins[Character].balanced && plugins[Character].has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def ashtan_rail
@ratter_rail = [
%w(e e e ne e se se s sw se se e e e e se se s s s sw sw w nw nw sw sw nw n nw w w n nw nw n n n w w),
%w(w s s se s se se e s s s w s s s se se ne e e se se s se se sw sw nw n nw nw nw ne e e n n ne ne se se e ne se e e ne n n nw nw sw w nw nw sw sw nw n nw w w sw s s s w nw w n ne n ne nw n nw n n e)
]
end
def hashan_rail
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
end
def disable_walker
warn("Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
- def skip_room
+ def skip_room (match_object = [])
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
#def misguided
# @lost_or_not += 1
# if @lost_or_not == 1
# @rail_position -= 2
# elsif @lost_or_not <3
# @rail_position -= 1
# else
# lost!
# end
# end
def lost!
if @auto_walk_enabled == true
warn("Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
@lost_or_not = 0
if plugins[Ratter].ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
sleep 0.5
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
7bbf9df08952a269ab8ff9f6ed57343ffdece67c
|
Shortened the sleep time.
|
diff --git a/receiver.rb b/receiver.rb
index 7935b4d..3420a49 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,140 +1,140 @@
class Receiver
attr_accessor :varsock, :enabled_plugins, :disabled_plugins, :queue
def plugins
@enabled_plugins
end
debug("Receiver: Loading Files...")
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
attr_accessor File.basename(file, ".rb").to_sym
end
def initialize
warn("RMuddy: System Loading...")
@queue = []
@enabled_plugins = []
class << @enabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
@disabled_plugins = []
class << @disabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
basename = File.basename(file, ".rb")
class_string = basename.split("_").each{|part| part.capitalize!}.join("")
instantiated_class = Object.module_eval(class_string).new(self)
instantiated_class.enable
end
Thread.new do
while true do
- sleep 0.1
+ sleep 0.01
if @queue.length > 0
element = @queue.shift
case element[0]
when "set_var"
@varsock.set(element[1], element[2])
when "send_command"
@varsock.command(element[1])
end
end
end
end
warn("=" * 80)
warn("You may send commands to RMuddy's plugins like so:")
warn("/notify 4567 PluginName action_name arg1 arg2 arg3")
warn("=" * 80)
warn("You may ask a plugin for help by doing:")
warn("/notify 4567 PluginName help")
warn("=" * 80)
warn("RMuddy: System Ready!")
end
def receive(text)
@enabled_plugins.each do |klass|
klass.triggers.each_pair do |regex, method|
debug("Testing Plugin: #{klass.to_s}| Regex: #{regex} against line: #{text}")
match = regex.match(text)
unless match.nil?
debug("Match!")
unless match[1].nil?
klass.send(method.to_sym, match)
else
klass.send(method.to_sym)
end
else
debug("No match!")
end
end
end
end
def command(text)
debug("RMuddy received notify command: #{text} ")
method_and_args = text.split(" ")
klass = Object.module_eval("#{method_and_args[0]}")
method_sym = method_and_args[1].to_sym
args = method_and_args[2..-1]
unless method_sym == :enable
@enabled_plugins.each do |plugin|
if plugin.is_a?(klass)
unless args.empty?
plugin.send(method_sym, *args)
else
plugin.send(method_sym)
end #args check
end #check the class of the plugin
end #loop through enabled plugins
else # Check to see if it's an enable command
@disabled_plugins.each do |plugin|
if plugin.is_a?(klass)
plugin.send(:enable)
end #check for class of the plugin
end #looping through the disabled plugins
end # end of check for :enable
end #end of Command method.
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
9e5db0abd938f6e667221c69bf05f23a97193061
|
Added more antitheft
|
diff --git a/configs/antitheft.yaml b/configs/antitheft.yaml
index 772b571..945c0d0 100644
--- a/configs/antitheft.yaml
+++ b/configs/antitheft.yaml
@@ -1,11 +1,11 @@
---
-pack: "pack296008"
+journal: ""
+trousers: "leggings286549"
armor: "scalemail88722"
-shirt: ""
-trousers: ""
-robe: "robes290768"
weapon1: ""
weapon2: ""
+robe: "robes290768"
+shirt: "shirt286549"
ring1: ""
ring2: ""
-journal: ""
\ No newline at end of file
+pack: "pack296008"
\ No newline at end of file
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index 1d204d1..dafb624 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,164 +1,178 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
class Ratter < BasePlugin
attr_accessor :ratter_enabled, :balance_user, :attack_command, :available_rats
attr_accessor :inventory_rats, :rat_prices, :total_rat_money
def setup
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
@balance_user = false
#What do we do when we want them dead?
@attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#Identify when there WAS a rat, but there no longer is cuz someone else using RMuddy ninja'd it
trigger /I do not recognise anything called that here./, :no_rats!
trigger /Ahh, I am truly sorry, but I do not see anyone by that name here./, :no_rats!
trigger /Nothing can be seen here by that name./, :no_rats!
trigger /You detect nothing here by that name./, :no_rats!
trigger /You cannot see that being here./, :no_rats!
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
trigger /Liirup the Placid stands here/, :sell_rats_hashan
trigger /The Ratman stands here quietly/, :sell_rats_ashtan
#Reset the money after selling to the ratter in hashan. .. Or Ashtan, now
trigger /Liirup squeals with delight/, :reset_money
trigger /The ratman thanks you as you hand over/, :reset_money
+ trigger /Although you exert extraordinary effort, you find you lack the mental reserves to perform that ability./, :out_of_mana!
+ trigger /You cannot summon up the willpower to perform such a mentally exhausting task./, :out_of_willpower!
trigger /You see exits/, :reset_available_rats
trigger /You see a single exit/, :reset_available_rats
#After we gain balance, we need to decide if we should attack again or not.
after Character, :set_simple_stats, :should_i_attack_rat?
after Character, :set_extended_stats, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
- def self_rats_ashtan
+ def out_of_mana!
+ if !@balance_user
+ disable_ratter
+ end
+ end
+
+ def out_of_willpower!
+ if !@balance_user
+ disable_ratter
+ end
+ end
+
+ def sell_rats_ashtan
if @ratter_enabled
send_kmuddy_command("Sell rats to Ratman")
end
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def no_rats!
@available_rats = 0
end
def enable_ratter
warn("Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
def reset_available_rats
@available_rats = 0
end
def sell_rats_hashan
if @ratter_enabled
send_kmuddy_command("Sell rats to Liirup")
end
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && plugins[Character].balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && plugins[Character].has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index fc845e7..abccbaf 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,221 +1,222 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
class Walker < BasePlugin
attr_accessor :opposite_directions, :last_timer, :lost_or_not, :seconds_to_wait
attr_accessor :rail_position, :current_rail, :current_thread, :ratter_rail, :auto_walk_enabled
attr_accessor :back_tracking
def setup
warn("***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#lost or not? Well, let's see
@lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
+ trigger /is here, shrouded\./, :skip_room
trigger /There is no exit in that direction/, :lost!
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
sleep 0.03
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
sleep 1
end
#If we can walk, walk!
if plugins[Character].balanced && plugins[Character].has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def ashtan_rail
@ratter_rail = [
%w(e e e ne e se se s sw se se e e e e se se s s s sw sw w nw nw sw sw nw n nw w w n nw nw n n n w w),
%w(w s s se s se se e s s s w s s s se se ne e e se se s se se sw sw nw n nw nw nw ne e e n n ne ne se se e ne se e e ne n n nw nw sw w nw nw sw sw nw n nw w w sw s s s w nw w n ne n ne nw n nw n n e)
]
end
def hashan_rail
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
end
def disable_walker
warn("Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
#def misguided
# @lost_or_not += 1
# if @lost_or_not == 1
# @rail_position -= 2
# elsif @lost_or_not <3
# @rail_position -= 1
# else
# lost!
# end
# end
def lost!
if @auto_walk_enabled == true
warn("Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
@lost_or_not = 0
if plugins[Ratter].ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
sleep 0.5
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
40fca144632b31046676915e2d54e113f74cc302
|
Added rails for autowalker/ratter in Ashtan. Added ashtan_rail and hashan_rail methods to Walker plugin so that you can tell it which city you're ratting in.
|
diff --git a/configs/hermithash.yaml b/configs/hermithash.yaml
index 93c1bd5..51778e4 100644
--- a/configs/hermithash.yaml
+++ b/configs/hermithash.yaml
@@ -1,7 +1,2 @@
---
-manara: "284348"
Location: card number
-lounge: "265385"
-delos: "250918"
-thera: "87842"
-lessons: "176010"
diff --git a/enabled-plugins/hermit.rb b/enabled-plugins/hermit.rb
index a393ae9..2848575 100644
--- a/enabled-plugins/hermit.rb
+++ b/enabled-plugins/hermit.rb
@@ -1,106 +1,107 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermit activate_hermit <tag to associate room with>
# /notify 4567 Hermit fling_hermit <room-tag>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
class Hermit < BasePlugin
def setup
@whichhermit = ''
@key = ''
@formatlength = 80
@formatpad = (@formatlength / 3)
@charginghermit = false
@resethash = {"Location" => "card number"}
warn("Loading hermit locations database")
File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
trigger /^You have recovered equilibrium.$/, :put_away_hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
warn("Hermit Tracker loaded")
end
def activate_hermit(key = '')
if key == ''
warn("You must supply a word to associate this room with!!")
else
@key = key
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
def associate_hermit
warn("Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
@activatinghermit = true
end
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
warn("Saved hermit tracker hash")
end
def fling_hermit(key = '')
@key = key
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
def put_away_hermit
if @activatinghermit
send_kmuddy_command("Put hermit in pack")
@activatinghermit = false
end
end
def del_hash (key = '')
if key == ''
warn("You must specify the room tag you wish to remove from the database")
else
warn("deleting #{key} from the hermit locations database")
@hermithash.delete(key.to_s)
+ save_hash
end
end
def hermit_list
warn("Hermits currently in database")
@output = "Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
warn(@output)
@hermithash.each_key { |key|
unless key == "Location"
@output = "#{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
warn(@output)
end
}
end
def reset_hash
warn("Resetting hermit database... all hermit location is now kaput")
@hermithash = @resethash
save_hash
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index a80ff11..1d204d1 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,145 +1,164 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
class Ratter < BasePlugin
attr_accessor :ratter_enabled, :balance_user, :attack_command, :available_rats
attr_accessor :inventory_rats, :rat_prices, :total_rat_money
def setup
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
@balance_user = false
#What do we do when we want them dead?
@attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
+
+ #Identify when there WAS a rat, but there no longer is cuz someone else using RMuddy ninja'd it
+ trigger /I do not recognise anything called that here./, :no_rats!
+ trigger /Ahh, I am truly sorry, but I do not see anyone by that name here./, :no_rats!
+ trigger /Nothing can be seen here by that name./, :no_rats!
+ trigger /You detect nothing here by that name./, :no_rats!
+ trigger /You cannot see that being here./, :no_rats!
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
- trigger /Liirup the Placid stands here/, :sell_rats
- #Reset the money after selling to the ratter in hashan.
+ trigger /Liirup the Placid stands here/, :sell_rats_hashan
+ trigger /The Ratman stands here quietly/, :sell_rats_ashtan
+ #Reset the money after selling to the ratter in hashan. .. Or Ashtan, now
trigger /Liirup squeals with delight/, :reset_money
+ trigger /The ratman thanks you as you hand over/, :reset_money
trigger /You see exits/, :reset_available_rats
trigger /You see a single exit/, :reset_available_rats
#After we gain balance, we need to decide if we should attack again or not.
after Character, :set_simple_stats, :should_i_attack_rat?
after Character, :set_extended_stats, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
+
+ def self_rats_ashtan
+ if @ratter_enabled
+ send_kmuddy_command("Sell rats to Ratman")
+ end
+ end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
+
+ def no_rats!
+ @available_rats = 0
+ end
def enable_ratter
warn("Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
def reset_available_rats
@available_rats = 0
end
-
- def sell_rats
+
+ def sell_rats_hashan
if @ratter_enabled
send_kmuddy_command("Sell rats to Liirup")
end
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && plugins[Character].balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && plugins[Character].has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb
index 049ccfc..8a98398 100644
--- a/enabled-plugins/sipper.rb
+++ b/enabled-plugins/sipper.rb
@@ -1,73 +1,73 @@
#The AutoSipper. It checks to see if a certain threshold percentage is hit for
#Health and Mana, and keeps your health/mana above that percentage.
#
#You will undoubtedly need to add exception triggers in to disable sipping,
#but right now it is customized for Tarot inscribing.
class Sipper < BasePlugin
attr_accessor :sipper_enabled
def sipper_enabled?
@sipper_enabled
end
#Check to make sure we are not below our health threshold
#We make sure to use floats! Since integers round ;)
def health_below_threshold?
(plugins[Character].current_health.to_f / plugins[Character].total_health.to_f) * 100 < @health_threshold_percentage
end
#Same as above
def mana_below_threshold?
(plugins[Character].current_mana.to_f / plugins[Character].total_mana.to_f) * 100 < @mana_threshold_percentage
end
def setup
#By default, we want to be healed ;)
@sipper_enabled = true
#Our health and mana thresholds
- @health_threshold_percentage = 70
- @mana_threshold_percentage = 70
+ @health_threshold_percentage = 50
+ @mana_threshold_percentage = 40
#After every time the character's current stats are updated, we check to see if we should sip.
after Character, :set_simple_stats, :should_i_sip?
after Character, :set_extended_stats, :should_i_sip?
#This group of triggers disables the sipping for various reasons.
trigger /^Your mind feels stronger and more alert\.$/, :disable_sip
trigger /^The elixer heals and soothes you\.$/, :disable_sip
trigger /^What is it that you wish to drink\?$/, :disable_sip
trigger /^You are asleep and can do nothing\./, :disable_sip
trigger /^The elixer flows down your throat without effect/, :disable_sip
trigger /Wisely preparing yourself beforehand/, :disable_sip
#This group of triggers, substantially smaller, enables the sipping when we can :)
trigger /^You may drink another .*$/, :enable_sip
trigger /^You have successfully inscribed/, :enable_sip
end
#The heart of the plugin...
def should_i_sip?
#If we don't have our total scores, wait until character fills them in.
if plugins[Character].total_mana && plugins[Character].total_health
#Otherwise, begin checking health and mana to see if we need to do some drinking...
if health_below_threshold? && sipper_enabled?
send_kmuddy_command("drink health")
@sipper_enabled = false
end
if mana_below_threshold? && sipper_enabled?
send_kmuddy_command("drink mana")
@sipper_enabled = false
end
end
end
def disable_sip
@sipper_enabled = false
end
def enable_sip
@sipper_enabled = true
end
end
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index 53ee2aa..fc845e7 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,207 +1,221 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
class Walker < BasePlugin
attr_accessor :opposite_directions, :last_timer, :lost_or_not, :seconds_to_wait
attr_accessor :rail_position, :current_rail, :current_thread, :ratter_rail, :auto_walk_enabled
attr_accessor :back_tracking
def setup
warn("***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#lost or not? Well, let's see
@lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
trigger /There is no exit in that direction/, :lost!
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
sleep 0.03
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
sleep 1
end
#If we can walk, walk!
if plugins[Character].balanced && plugins[Character].has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
+
+ def ashtan_rail
+ @ratter_rail = [
+ %w(e e e ne e se se s sw se se e e e e se se s s s sw sw w nw nw sw sw nw n nw w w n nw nw n n n w w),
+ %w(w s s se s se se e s s s w s s s se se ne e e se se s se se sw sw nw n nw nw nw ne e e n n ne ne se se e ne se e e ne n n nw nw sw w nw nw sw sw nw n nw w w sw s s s w nw w n ne n ne nw n nw n n e)
+ ]
+ end
+
+ def hashan_rail
+ @ratter_rail = [
+ %w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
+ %w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
+ ]
+ end
def disable_walker
warn("Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
#def misguided
# @lost_or_not += 1
# if @lost_or_not == 1
# @rail_position -= 2
# elsif @lost_or_not <3
# @rail_position -= 1
# else
# lost!
# end
# end
def lost!
if @auto_walk_enabled == true
warn("Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
@lost_or_not = 0
if plugins[Ratter].ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
sleep 0.5
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
0a4385fee166202efbfbc6bdb3b61e7e66bdce23
|
Added sleep to keep the auto walker from eating my entire cpu, 30ms. changed the receiver to use sleep 0.03 also...
|
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index 4c0de73..53ee2aa 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,206 +1,207 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
class Walker < BasePlugin
attr_accessor :opposite_directions, :last_timer, :lost_or_not, :seconds_to_wait
attr_accessor :rail_position, :current_rail, :current_thread, :ratter_rail, :auto_walk_enabled
attr_accessor :back_tracking
def setup
warn("***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#lost or not? Well, let's see
@lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
trigger /There is no exit in that direction/, :lost!
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
+ sleep 0.03
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
sleep 1
end
#If we can walk, walk!
if plugins[Character].balanced && plugins[Character].has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def disable_walker
warn("Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
#def misguided
# @lost_or_not += 1
# if @lost_or_not == 1
# @rail_position -= 2
# elsif @lost_or_not <3
# @rail_position -= 1
# else
# lost!
# end
# end
def lost!
if @auto_walk_enabled == true
warn("Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
@lost_or_not = 0
if plugins[Ratter].ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
- sleep 0.3
+ sleep 0.5
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
diff --git a/receiver.rb b/receiver.rb
index 80a92c5..b13f1e1 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,144 +1,144 @@
class Receiver
attr_accessor :varsock, :enabled_plugins, :disabled_plugins, :queue
def plugins
@enabled_plugins
end
debug("Receiver: Loading Files...")
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
attr_accessor File.basename(file, ".rb").to_sym
end
def initialize
warn("System Loading...")
@queue = []
@enabled_plugins = []
class << @enabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
@disabled_plugins = []
class << @disabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
basename = File.basename(file, ".rb")
class_string = basename.split("_").each{|part| part.capitalize!}.join("")
instantiated_class = Object.module_eval(class_string).new(self)
instantiated_class.enable
end
Thread.new do
while true do
- sleep 0.1
+ sleep 0.03
if @queue.length > 0
element = @queue.shift
case element[0]
when "set_var"
@varsock.set(element[1], element[2])
when "send_command"
@varsock.command(element[1])
end
end
end
end
bar_line
warn("You may send commands to RMuddy's plugins like so:")
warn("/notify 4567 PluginName action_name arg1 arg2 arg3")
bar_line
warn("You may ask a plugin for help by doing:")
warn("/notify 4567 PluginName help")
bar_line
warn("System Ready!")
end
def bar_line
warn("=" * 80)
end
def receive(text)
@enabled_plugins.each do |klass|
klass.triggers.each_pair do |regex, method|
debug("Testing Plugin: #{klass.to_s}| Regex: #{regex} against line: #{text}")
match = regex.match(text)
unless match.nil?
debug("Match!")
unless match[1].nil?
klass.send(method.to_sym, match)
else
klass.send(method.to_sym)
end
else
debug("No match!")
end
end
end
end
def command(text)
debug("RMuddy received notify command: #{text} ")
method_and_args = text.split(" ")
klass = Object.module_eval("#{method_and_args[0]}")
method_sym = method_and_args[1].to_sym
args = method_and_args[2..-1]
unless method_sym == :enable
@enabled_plugins.each do |plugin|
if plugin.is_a?(klass)
unless args.empty?
plugin.send(method_sym, *args)
else
plugin.send(method_sym)
end #args check
end #check the class of the plugin
end #loop through enabled plugins
else # Check to see if it's an enable command
@disabled_plugins.each do |plugin|
if plugin.is_a?(klass)
plugin.send(:enable)
end #check for class of the plugin
end #looping through the disabled plugins
end # end of check for :enable
end #end of Command method.
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
6c81b81dad1ee1dbffccbf4db403381c97877a33
|
Fixed liirup selling trigger
|
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index 8618dda..a80ff11 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,143 +1,145 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
class Ratter < BasePlugin
attr_accessor :ratter_enabled, :balance_user, :attack_command, :available_rats
attr_accessor :inventory_rats, :rat_prices, :total_rat_money
def setup
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
@balance_user = false
#What do we do when we want them dead?
@attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
trigger /Liirup the Placid stands here/, :sell_rats
#Reset the money after selling to the ratter in hashan.
trigger /Liirup squeals with delight/, :reset_money
trigger /You see exits/, :reset_available_rats
trigger /You see a single exit/, :reset_available_rats
#After we gain balance, we need to decide if we should attack again or not.
after Character, :set_simple_stats, :should_i_attack_rat?
after Character, :set_extended_stats, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def enable_ratter
warn("Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
def reset_available_rats
@available_rats = 0
end
def sell_rats
- send_kmuddy_command("Sell rats to Liirup")
+ if @ratter_enabled
+ send_kmuddy_command("Sell rats to Liirup")
+ end
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && plugins[Character].balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && plugins[Character].has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
13580b014002a6ffe7b76737f2dbb1d2f2c21fe9
|
Beta version of the Antitheft module. Will put sovereigns away, and can rewear robes, pack, and armor... the rest will be forthcoming once I arrange triggers.
|
diff --git a/configs/antitheft.yaml b/configs/antitheft.yaml
index ed6677d..772b571 100644
--- a/configs/antitheft.yaml
+++ b/configs/antitheft.yaml
@@ -1,10 +1,11 @@
---
-pack: ""
-armor: ""
+pack: "pack296008"
+armor: "scalemail88722"
shirt: ""
trousers: ""
-robe: ""
+robe: "robes290768"
weapon1: ""
weapon2: ""
ring1: ""
ring2: ""
+journal: ""
\ No newline at end of file
diff --git a/configs/hermithash.yaml b/configs/hermithash.yaml
index 66a21a1..93c1bd5 100644
--- a/configs/hermithash.yaml
+++ b/configs/hermithash.yaml
@@ -1,5 +1,7 @@
---
+manara: "284348"
Location: card number
-lounge: "335421"
-xroads: "335646"
-lessons: "335337"
+lounge: "265385"
+delos: "250918"
+thera: "87842"
+lessons: "176010"
diff --git a/disabled-plugins/antitheft.rb b/enabled-plugins/antitheft.rb
similarity index 59%
rename from disabled-plugins/antitheft.rb
rename to enabled-plugins/antitheft.rb
index 104d864..d5fa716 100644
--- a/disabled-plugins/antitheft.rb
+++ b/enabled-plugins/antitheft.rb
@@ -1,99 +1,156 @@
# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
class Antitheft < BasePlugin
#setup method for the plugin.. triggers, var. init and stuff goes here
def setup
+ #by default, we do in fact want anti_theft
+
+ @anti_theft = true
+
#Setup your anti-theft triggers here... they might be different for you than me
trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
trigger /^You remove a canvas backpack/, :rewear_pack
trigger /^You remove a suit of scale mail/, :rewear_armor
trigger /^You remove flowing violet robes./, :rewear_robe
#After we gain balance, check if we need to rewear something!
after Character, :is_balanced, :rewear?
+ #load the theft database
unless (File.open("configs/antitheft.yaml") {|fi| @thefthash = YAML.load(fi)})
- warn("No configuration file found... you must have the configuration file antitheft.yaml in the configs directory")
+ warn("No configuration file found... you must have the configuration file")
+ warn("antitheft.yaml in the configs directory")
+ end
+ #here, we'll push a bunch of variables out to kmuddy
+ @thefthash.each_key {|key| set_kmuddy_variable("theft_#{key}", @thefthash[key])}
+ end
+
+ def hypnosis (match_object )
+ if @anti_theft
+ send_kmuddy_command("lose #{match_object[1]}")
+ send_kmuddy_command("/echo OK! YOU MAY BE GETTING STOLEN FROM!")
end
end
def help
- warn("OK, you asked for it. You must setup the YAML file. It has a format. Each thing should be on a seperate line")
+ warn("OK, you asked for it. You must setup the YAML file. It has a format.")
+ warn("Each thing should be on a seperate line")
warn("The format is... on separate lines, mind you, with nothing in front of it")
warn("item: \"<fully described item, with number here>\"")
blank_line
warn("example:")
warn("pack: \"pack296008\"")
blank_line
- warn("You can use \"/notify 4567 Antitheft set_hash pack pack296008\" to accomplish the same result as the line above")
- warn("and this module should have been packaged with a template antitheft.yaml file with it")
- blank_line
warn("Items which can be set in the yaml file. There is a set_hash method ... ")
- warn("\"/notify 4567 Antitheft set_hash pack pack1234\" ...\"/notify 4567 Antitheft set_hash armor scalemail1234\" etc.")
+ warn("\"/notify 4567 Antitheft set_hash pack pack1234\" ...\"/notify 4567 ")
+ warn("Antitheft set_hash armor scalemail1234\" etc.")
@thefthash.each_key { |key| warn("#{key}") }
blank_line
warn("If you've got alternate gear... say, a sailor's kitbag, or what have")
- warn("you, you'll need to modify the triggers in the antitheft.rb file to match the appropriate message")
+ warn("you, you'll need to modify the triggers in the antitheft.rb file to ")
+ warn("match the appropriate message")
blank_line
- warn("Finally, you can save your hash to the config file using /notify 4567 Antitheft save_hash")
+ warn("Finally, you can save your hash to the config file using /notify 4567 ")
+ warn("Antitheft save_hash")
end
def rewear_pack
- @packbalance = true
+ if @anti_theft
+ @packbalance = true
+ send_kmuddy_command("wear #{@thefthash["pack"]}")
+ end
end
def rewear_armor
- @armorbalance = true
+ if @anti_theft
+ @armorbalance = true
+ send_kmuddy_command("wear #{@thefthash["armor"]}")
+ end
end
def rewear_robe
- @robebalance = true
+ if @anti_theft
+ @robebalance = true
+ send_kmuddy_command("wear #{@thefthash["robe"]}")
+ end
end
def rewear?
- if @armorbalance
- send_kmuddy_command("wear #{@thefthash[armor]}")
- @armorbalance = false
+
+ if @souldmaster
+ send_kmuddy_command("lose soulmaster")
+ @soulmaster = false
end
if @packbalance
- send_kmuddy_command("wear #{@thefthash[pack]}")
+ send_kmuddy_command("wear #{@thefthash["pack"]}")
@packbalance = false
end
- if @robebalance
- send_kmuddy_command("wear #{@thefthash[robe]}")
+ if @armorbalance
+ send_kmuddy_command("wear #{@thefthash["armor"]}")
+ @armorbalance = false
+ end
+
+ if @robebalance
+ send_kmuddy_command("wear #{@thefthash["robe"]}")
@robebalance = 0
end
+
+ end
+
+ def print_hash
+ warn("Printing anti-theft database, this may be spammy")
+ @thefthash.each_key { |key| warn("#{key}: #{@thefthash[key]}" ) }
end
def put_gold_away
- send_kmuddy_command("put sovereigns in #{@thefthash[pack]}")
+ if @anti_theft
+ send_kmuddy_command("put sovereigns in #{@thefthash["pack"]}")
+ end
+ end
+
+ def test (key = "pack")
+ send_kmuddy_command("/echo #{@thefthash[key]}")
+ end
+
+ def lose_soulmaster
+ send_kmuddy_command("lose soulmaster")
+ @soulmaster = true
end
def set_hash (key = '', value = '')
if (key == '' && value == '')
- warn("You must tell me what article you are trying to protect, and which one it is supposed to be specifically!")
+ warn("You must tell me what article you are trying to protect, and which")
+ warn("one it is supposed to be specifically!")
elsif (key != '' && value =='')
warn("You have to tell me what #{key} is your's, specifically!")
elsif (key == '' && value != '')
warn("You have to tell me what kind of item #{value} is, so we can properly protect it!")
else
@thefthash[key] = value
warn("Setting item #{key} to your specific item, #{value}")
save_hash
end
end
+ def theft_on
+ @anti_theft = true
+ end
+
+ def theft_off
+ @anti_theft = false
+ end
+
def save_hash
warn("Saving antitheft configuration")
unless (File.open("configs/antitheft.yaml", "w") {|fi| @thefthash = YAML.dump(fi)})
warn("Could not write configuration file for antitheft")
end
end
end
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index 4899e41..4c0de73 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,205 +1,206 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
class Walker < BasePlugin
attr_accessor :opposite_directions, :last_timer, :lost_or_not, :seconds_to_wait
attr_accessor :rail_position, :current_rail, :current_thread, :ratter_rail, :auto_walk_enabled
attr_accessor :back_tracking
def setup
warn("***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#lost or not? Well, let's see
@lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
- trigger /There is no exit in that direction/, :misguided
+ trigger /There is no exit in that direction/, :lost!
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
sleep 1
end
#If we can walk, walk!
if plugins[Character].balanced && plugins[Character].has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def disable_walker
warn("Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
- def misguided
- @lost_or_not += 1
- if @lost_or_not = 1
- @rail_position -= 2
- elsif @lost_or_not <3
- @rail_position -= 1
- else
- lost!
- end
- end
+
+ #def misguided
+ # @lost_or_not += 1
+ # if @lost_or_not == 1
+ # @rail_position -= 2
+ # elsif @lost_or_not <3
+ # @rail_position -= 1
+ # else
+ # lost!
+ # end
+ # end
def lost!
if @auto_walk_enabled == true
warn("Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
@lost_or_not = 0
if plugins[Ratter].ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
sleep 0.3
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
16a9ee46966d40f8127040133f230f70e1454ea3
|
Added pause_inscription and unpause_inscription methods for use pausing and unpausing batch jobs. It will cause it to pause the next time it checks if you should inscribe using simple boolean logic.
|
diff --git a/enabled-plugins/inscriber.rb b/enabled-plugins/inscriber.rb
index 04bc794..b90fedd 100644
--- a/enabled-plugins/inscriber.rb
+++ b/enabled-plugins/inscriber.rb
@@ -1,64 +1,77 @@
#Inscriber module for RMuddy triggering/aliasing system.
#Module to handle inscribing batches of tarot cards in Achaea
#Will make sure you only ever sip in between cards... still very rough
#draft.
class Inscriber < BasePlugin
#we'll setup some accessor methods, weee
attr_accessor :number_to_inscribe
attr_accessor :type_to_inscribe
attr_accessor :inscribing
def setup
#setup our triggers for commands... will be deprecated when /notify works
trigger /You have successfully inscribed/, :decrement_counter #we did it!
trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
#by default, we are not, in fact, inscribing
+ @paused = false
+ @batch_total = 0
@inscribing = false
@number_to_inscribe = 0
@type_to_inscribe = ""
end
def mass_inscribe(number_to_inscribe, type_to_inscribe)
@number_to_inscribe = number_to_inscribe.to_i
@type_to_inscribe = type_to_inscribe.to_s
+ @batch_total = number_to_inscribe.to_i
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
warn("Inscriber Plugin: Ready to inscribe #{@number_to_inscribe} #{@type_to_inscribe}")
warn("Use begin_inscribing to start.")
end
def begin_inscribing
inscribe_tarot
end
def inscribe_tarot #here's how we actually inscribe the bloody cards
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
plugins[Sipper].should_i_sip? #check to see if we need mana before we inscribe
plugins[Sipper].disable #then disable the sipper so as not to kill our inscribe
send_kmuddy_command("inscribe blank with #{@type_to_inscribe}") #and actually inscribe
end
def decrement_counter #lower the counter, so we inscribe the correct # of cards
@number_to_inscribe -= 1 #decrement counter
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
should_we_inscribe? #check if we should do another!
end
def out_of_mana! #pretty obvious
@inscribing = false #if we're out of mana, we're not inscribing
+ plugins[Sipper].enable
send_kmuddy_command("sip mana") #so we need to sip some mana
end
+ def pause_inscription
+ @paused = true
+ end
+
+ def unpause_inscription
+ @paused = false
+ inscribe_tarot
+ end
+
def should_we_inscribe? #test if we should inscribe
- if @number_to_inscribe > 0 #if we still have inscription to do
+ if @number_to_inscribe > 0 && !@paused #if we still have inscription to do and we're not paused
inscribe_tarot #then inscribe
elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
- send_kmuddy_command("ind 50 #{@type_to_inscribe}") #put the cards away
+ send_kmuddy_command("ind #{@batch_total} #{@type_to_inscribe}") #put the cards away
plugins[Sipper].should_i_sip? #check if we need to sip
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
05b6cb14c731a32adc9488a4b492d2b30dabd2e6
|
More work on antitheft, modified kmuddy.rb again... moved a couple things around, cleaned up a bit... everything still works that is in enabled-plugins
|
diff --git a/base_plugin.rb b/base_plugin.rb
index 54d9eff..7ae1d18 100644
--- a/base_plugin.rb
+++ b/base_plugin.rb
@@ -1,80 +1,74 @@
class BasePlugin
attr_accessor :triggers, :receiver
def initialize(rec)
@receiver = rec
self.setup
end
-
- def bar_line
- warn("=" * 80)
- end
-
+
def plugins
@receiver.plugins
end
def disabled_plugins
@receiver.disabled_plugins
end
def disable
unless @receiver.disabled_plugins.include?(self)
@receiver.enabled_plugins.delete(self)
@receiver.disabled_plugins << self
end
- warn("RMuddy: #{self.class.to_s} Plugin has been disabled.")
+ warn("#{self.class.to_s} Plugin has been disabled.")
end
def enable
unless @receiver.enabled_plugins.include?(self)
@receiver.disabled_plugins.delete(self)
@receiver.enabled_plugins << self
end
warn("#{self.class.to_s} Plugin has been enabled.")
end
def help
warn("That plugin's author has not created a help for you!")
end
def trigger(regex, method)
@triggers ||= {}
@triggers[regex] = method
end
def set_kmuddy_variable(variable_name, variable_value)
@receiver.queue << ["set_var", variable_name, variable_value]
end
- def blank_line
- warn("")
- end
+
def get_kmuddy_variable(variable_name)
@receiver.varsock.get(variable_name)
end
def send_kmuddy_command(command_text)
@receiver.queue << ["send_command", command_text]
end
def before(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(1, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
module_name.module_eval(new_method.join("\n"))
end
def after(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(-2, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
module_name.module_eval(new_method.join("\n"))
end
end
\ No newline at end of file
diff --git a/configs/hermithash.yaml b/configs/hermithash.yaml
index da191f5..66a21a1 100644
--- a/configs/hermithash.yaml
+++ b/configs/hermithash.yaml
@@ -1,4 +1,5 @@
---
-lounge2: "241350"
Location: card number
-lounge: "319420"
+lounge: "335421"
+xroads: "335646"
+lessons: "335337"
diff --git a/disabled-plugins/antitheft.rb b/disabled-plugins/antitheft.rb
index 4224a38..104d864 100644
--- a/disabled-plugins/antitheft.rb
+++ b/disabled-plugins/antitheft.rb
@@ -1,36 +1,99 @@
# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
class Antitheft < BasePlugin
#setup method for the plugin.. triggers, var. init and stuff goes here
def setup
+
+ #Setup your anti-theft triggers here... they might be different for you than me
trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
trigger /^You remove a canvas backpack/, :rewear_pack
trigger /^You remove a suit of scale mail/, :rewear_armor
+ trigger /^You remove flowing violet robes./, :rewear_robe
+
+ #After we gain balance, check if we need to rewear something!
+ after Character, :is_balanced, :rewear?
- unless (File.open("configs/anti_theft.yaml") {|fi| @thefthash = YAML.load(fi)})
- warn("No configuration file found... you must have the configuration file anti_theft.yaml in the configs directory")
+ unless (File.open("configs/antitheft.yaml") {|fi| @thefthash = YAML.load(fi)})
+ warn("No configuration file found... you must have the configuration file antitheft.yaml in the configs directory")
end
end
def help
warn("OK, you asked for it. You must setup the YAML file. It has a format. Each thing should be on a seperate line")
warn("The format is... on separate lines, mind you, with nothing in front of it")
warn("item: \"<fully described item, with number here>\"")
blank_line
warn("example:")
warn("pack: \"pack296008\"")
blank_line
- warn("You can use \"/notify 4567 Antitheft set_pack pack296008\" to accomplish the same result as the line above")
+ warn("You can use \"/notify 4567 Antitheft set_hash pack pack296008\" to accomplish the same result as the line above")
warn("and this module should have been packaged with a template antitheft.yaml file with it")
blank_line
- warn("Items which can be set in the yaml file. There is a set_item method for each of these. IE set_pack, set_armor ad nauseum")
+ warn("Items which can be set in the yaml file. There is a set_hash method ... ")
+ warn("\"/notify 4567 Antitheft set_hash pack pack1234\" ...\"/notify 4567 Antitheft set_hash armor scalemail1234\" etc.")
@thefthash.each_key { |key| warn("#{key}") }
blank_line
warn("If you've got alternate gear... say, a sailor's kitbag, or what have")
warn("you, you'll need to modify the triggers in the antitheft.rb file to match the appropriate message")
+ blank_line
+ warn("Finally, you can save your hash to the config file using /notify 4567 Antitheft save_hash")
+ end
+
+ def rewear_pack
+ @packbalance = true
+ end
+
+ def rewear_armor
+ @armorbalance = true
+ end
+
+ def rewear_robe
+ @robebalance = true
+ end
+
+ def rewear?
+ if @armorbalance
+ send_kmuddy_command("wear #{@thefthash[armor]}")
+ @armorbalance = false
+ end
+
+ if @packbalance
+ send_kmuddy_command("wear #{@thefthash[pack]}")
+ @packbalance = false
+ end
+
+ if @robebalance
+ send_kmuddy_command("wear #{@thefthash[robe]}")
+ @robebalance = 0
+ end
+ end
+
+ def put_gold_away
+ send_kmuddy_command("put sovereigns in #{@thefthash[pack]}")
+ end
+
+ def set_hash (key = '', value = '')
+ if (key == '' && value == '')
+ warn("You must tell me what article you are trying to protect, and which one it is supposed to be specifically!")
+ elsif (key != '' && value =='')
+ warn("You have to tell me what #{key} is your's, specifically!")
+ elsif (key == '' && value != '')
+ warn("You have to tell me what kind of item #{value} is, so we can properly protect it!")
+ else
+ @thefthash[key] = value
+ warn("Setting item #{key} to your specific item, #{value}")
+ save_hash
+ end
+ end
+
+ def save_hash
+ warn("Saving antitheft configuration")
+ unless (File.open("configs/antitheft.yaml", "w") {|fi| @thefthash = YAML.dump(fi)})
+ warn("Could not write configuration file for antitheft")
+ end
end
end
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index eee4d8a..9559420 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,140 +1,146 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
class Character < BasePlugin
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :current_health, :current_mana
attr_accessor :total_health, :total_mana
attr_accessor :current_endurance, :total_endurance
attr_accessor :current_willpower, :total_willpower
attr_accessor :balanced
attr_accessor :status
attr_accessor :has_equilibrium
def setup
#By default, we are assumed to be balanced and to have equilibrium.
@balanced = true
@has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :set_total_endurance
#set the balance when it returns.
#trigger /^You have recovered balance on all limbs.$/, :is_balanced
#demonnic: set the equilibrium when it returns
#trigger /^You have recovered equilibrium.$/, :gained_equilibrium
#We use the prompt to tell us when we are unbalanced.
#trigger /^\d+h, \d+m\se-/, :is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
#trigger /You reach out and bop/, :is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def set_simple_stats(match_object)
unless @using_extended_stats == true
@current_health = match_object[1].to_i
@current_mana = match_object[2].to_i
- @balanced = match_object[3].include("x")
+ @balanced = match_object[3].include?("x")
@has_equilibrium = match_object[3].include?("e")
+ #Because it will be helpful to keep using is_balanced and gained_equilibrium
+ if match_object[3].include?("x")
+ is_balanced
+ elsif match_object[3].include?("e")
+ gained_equilibrium
+ end
debug("Character: Loaded Current Stats")
debug("Character: Sending Current Stats")
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_balanced", @balanced)
set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
debug("Character: Sent Current Stats")
unless @total_health
send_kmuddy_command("qsc")
end
end
end
def set_extended_stats(match_object)
@current_health = match_object[1].to_i
@current_mana = match_object[2].to_i
@current_endurance = match_object[3].to_i
@current_willpower = match_object[4].to_i
@balanced = match_object[5].include?("x")
@has_equilibrium = match_object[5].include?("e")
debug("Character: Loaded Current Stats")
debug("Character: Sending Current Stats")
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_current_endurance", @current_endurance)
set_kmuddy_variable("character_current_willpower", @current_willpower)
set_kmuddy_variable("character_balanced", @balanced)
set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
debug("Character: Sent Current Stats")
@using_extended_stats = true
unless @total_health
send_kmuddy_command("qsc")
end
end
def set_total_health(match_object )
@total_health = match_object[2].to_i
@current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @current_health)
set_kmuddy_variable("character_total_health", @total_health)
end
def set_total_mana(match_object )
@total_mana = match_object[2].to_i
@current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @current_mana)
set_kmuddy_variable("character_total_mana", @total_mana)
end
def set_total_endurance(match_object )
@total_endurance = match_object[2].to_i
@current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @current_endurance)
set_kmuddy_variable("character_total_endurance", @total_endurance)
end
def set_total_willpower(match_object )
@total_willpower = match_object[2].to_i
@current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @current_willpower)
set_kmuddy_variable("character_total_willpower", @total_willpower)
end
def is_balanced
@balanced = true
end
def is_unbalanced
@balanced = false
end
def gained_equilibrium
@has_equilibrium = true
end
def lost_equilibrium
@has_equilibrium = false
end
end
\ No newline at end of file
diff --git a/enabled-plugins/hermit.rb b/enabled-plugins/hermit.rb
index 18380fe..a393ae9 100644
--- a/enabled-plugins/hermit.rb
+++ b/enabled-plugins/hermit.rb
@@ -1,106 +1,106 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermit activate_hermit <tag to associate room with>
# /notify 4567 Hermit fling_hermit <room-tag>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
class Hermit < BasePlugin
def setup
@whichhermit = ''
@key = ''
@formatlength = 80
@formatpad = (@formatlength / 3)
@charginghermit = false
@resethash = {"Location" => "card number"}
warn("Loading hermit locations database")
File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
trigger /^You have recovered equilibrium.$/, :put_away_hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
warn("Hermit Tracker loaded")
end
def activate_hermit(key = '')
if key == ''
warn("You must supply a word to associate this room with!!")
else
@key = key
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
def associate_hermit
warn("Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
@activatinghermit = true
end
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
- warn(" Saved hermit tracker hash")
+ warn("Saved hermit tracker hash")
end
def fling_hermit(key = '')
@key = key
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
def put_away_hermit
if @activatinghermit
send_kmuddy_command("Put hermit in pack")
@activatinghermit = false
end
end
def del_hash (key = '')
if key == ''
warn("You must specify the room tag you wish to remove from the database")
else
warn("deleting #{key} from the hermit locations database")
@hermithash.delete(key.to_s)
end
end
def hermit_list
warn("Hermits currently in database")
- @output = " Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
+ @output = "Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
warn(@output)
@hermithash.each_key { |key|
unless key == "Location"
- @output = " #{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
+ @output = "#{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
warn(@output)
end
}
end
def reset_hash
warn("Resetting hermit database... all hermit location is now kaput")
@hermithash = @resethash
save_hash
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
diff --git a/kmuddy/kmuddy.rb b/kmuddy/kmuddy.rb
index a898c8d..3b482a5 100755
--- a/kmuddy/kmuddy.rb
+++ b/kmuddy/kmuddy.rb
@@ -1,43 +1,50 @@
#!/bin/env ruby
#Modified for use with RMuddy specifically by Demonnic.
require 'socket'
module KMuddy
ANSI = { "reset" => "\e[0m", "bold" => "\e[1m",
"underline" => "\e[4m", "blink" => "\e[5m",
"reverse" => "\e[7m", "invisible" => "\e[8m",
"black" => "\e[0;30m", "darkgrey" => "\e[1;30m",
"red" => "\e[0;31m", "lightred" => "\e[1;31m",
"green" => "\e[0;32m", "lightgreen" => "\e[1;32m",
"brown" => "\e[0;33m", "yellow" => "\e[1;33m",
"blue" => "\e[0;34m", "lightblue" => "\e[1;34m",
"purple" => "\e[0;35m", "magenta" => "\e[1;35m",
"cyan" => "\e[1;36m", "lightcyan" => "\e[1;36m",
"grey" => "\e[0;37m", "white" => "\e[1;37m",
"bgblack" => "\e[40m", "bgred" => "\e[41m",
"bggreen" => "\e[42m", "bgyellow" => "\e[43m",
"bgblue" => "\e[44m", "bgmagenta" => "\e[45m",
"bgcyan" => "\e[46m", "bgwhite" => "\e[47m"
}
def ansi(text)
ANSI[text]
end
def ansi_strip(line)
return line.gsub!(/\e\[[0-9;]+m/, "")
end
def debug(text)
#$stderr.puts("#{ansi("red")}--> #{text}#{ansi("reset")}") if DEBUG
$stderr.puts("DEBUG--> #{text}") if DEBUG
end
+ def blank_line
+ warn("")
+ end
+
+ def bar_line
+ warn("=" * 80)
+ end
def warn(text)
$stderr.puts("\n-!RMuddy: #{text}")
end
def output(text)
$stderr.puts(text)
end
end
|
KeithHanson/rmuddy
|
68cc8b90ea9feca08e89dc8beeea2a1e272e228a
|
Changed antitheft for sanity. modified current plugins due to changes in kmuddy.rb and base_plugin.rb
|
diff --git a/configs/anti_theft.yaml b/configs/antitheft.yaml
similarity index 100%
rename from configs/anti_theft.yaml
rename to configs/antitheft.yaml
diff --git a/disabled-plugins/anti_theft.rb b/disabled-plugins/anti_theft.rb
deleted file mode 100644
index 3513a98..0000000
--- a/disabled-plugins/anti_theft.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
-
-class Anti_theft < BasePlugin
- #setup method for the plugin.. triggers, var. init and stuff goes here
- def setup
- trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
- trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
- trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
- trigger /^You remove a canvas backpack/, :rewear_pack
- trigger /^You remove a suit of scale mail/, :rewear_armor
-
- unless (File.open("configs/anti_theft.yaml") {|fi| @thefthash = YAML.load(fi)})
- warn("RMuddy: No configuration file found... you must have the configuration file anti_theft.yaml in the configs directory")
- end
- end
-
- def help
- warn("RMuddy: OK, you asked for it. You must setup the YAML file. It has a format. Each thing should be on a seperate line")
- warn("RMuddy: The format is... on separate lines, mind you, with nothing in front of it")
- warn("item: \"<fully described item, with number here>\"")
- blank_line
- warn("RMuddy: example:")
- warn("RMuddy: pack: \"pack296008\"")
- blank_line
- warn("RMuddy: You can use \"/notify 4567 Antitheft set_pack pack296008\" to accomplish the same result as the line above")
- warn("RMuddy: and this module should have been packaged with a template anti_theft.yaml file with it")
- blank_line
- warn("RMuddy:")
- end
-end
-
diff --git a/disabled-plugins/antitheft.rb b/disabled-plugins/antitheft.rb
new file mode 100644
index 0000000..4224a38
--- /dev/null
+++ b/disabled-plugins/antitheft.rb
@@ -0,0 +1,36 @@
+# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
+
+class Antitheft < BasePlugin
+ #setup method for the plugin.. triggers, var. init and stuff goes here
+ def setup
+ trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
+ trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
+ trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
+ trigger /^You remove a canvas backpack/, :rewear_pack
+ trigger /^You remove a suit of scale mail/, :rewear_armor
+
+ unless (File.open("configs/anti_theft.yaml") {|fi| @thefthash = YAML.load(fi)})
+ warn("No configuration file found... you must have the configuration file anti_theft.yaml in the configs directory")
+ end
+ end
+
+ def help
+ warn("OK, you asked for it. You must setup the YAML file. It has a format. Each thing should be on a seperate line")
+ warn("The format is... on separate lines, mind you, with nothing in front of it")
+ warn("item: \"<fully described item, with number here>\"")
+ blank_line
+ warn("example:")
+ warn("pack: \"pack296008\"")
+ blank_line
+ warn("You can use \"/notify 4567 Antitheft set_pack pack296008\" to accomplish the same result as the line above")
+ warn("and this module should have been packaged with a template antitheft.yaml file with it")
+ blank_line
+ warn("Items which can be set in the yaml file. There is a set_item method for each of these. IE set_pack, set_armor ad nauseum")
+ @thefthash.each_key { |key| warn("#{key}") }
+ blank_line
+ warn("If you've got alternate gear... say, a sailor's kitbag, or what have")
+ warn("you, you'll need to modify the triggers in the antitheft.rb file to match the appropriate message")
+ end
+
+end
+
diff --git a/enabled-plugins/hermit.rb b/enabled-plugins/hermit.rb
index 51d7977..18380fe 100644
--- a/enabled-plugins/hermit.rb
+++ b/enabled-plugins/hermit.rb
@@ -1,106 +1,106 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermit activate_hermit <tag to associate room with>
# /notify 4567 Hermit fling_hermit <room-tag>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
class Hermit < BasePlugin
def setup
@whichhermit = ''
@key = ''
@formatlength = 80
@formatpad = (@formatlength / 3)
@charginghermit = false
@resethash = {"Location" => "card number"}
- warn("RMuddy: Loading hermit locations database")
+ warn("Loading hermit locations database")
File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
trigger /^You have recovered equilibrium.$/, :put_away_hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
- warn("RMuddy: Hermit Tracker loaded")
+ warn("Hermit Tracker loaded")
end
def activate_hermit(key = '')
if key == ''
- warn("RMuddy: You must supply a word to associate this room with!!")
+ warn("You must supply a word to associate this room with!!")
else
@key = key
- warn("RMuddy: Ok, activating a hermit for this room")
+ warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
def associate_hermit
- warn("RMuddy: Associating card #{@whichhermit} with the place name #{@key}")
+ warn("Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
@activatinghermit = true
end
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
- warn("RMuddy: Saved hermit tracker hash")
+ warn(" Saved hermit tracker hash")
end
def fling_hermit(key = '')
@key = key
if key == ''
- warn("RMuddy: Come now, you have to tell me where to go! Specify a hermit to fling!")
+ warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
def put_away_hermit
if @activatinghermit
send_kmuddy_command("Put hermit in pack")
@activatinghermit = false
end
end
def del_hash (key = '')
if key == ''
- warn("RMuddy: You must specify the room tag you wish to remove from the database")
+ warn("You must specify the room tag you wish to remove from the database")
else
- warn("RMuddy deleting #{key} from the hermit locations database")
+ warn("deleting #{key} from the hermit locations database")
@hermithash.delete(key.to_s)
end
end
def hermit_list
- warn("RMuddy: Hermits currently in database")
- @output = "Rmuddy: Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
+ warn("Hermits currently in database")
+ @output = " Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
warn(@output)
@hermithash.each_key { |key|
unless key == "Location"
- @output = "Rmuddy: #{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
+ @output = " #{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
warn(@output)
end
}
end
def reset_hash
- warn("RMuddy: Resetting hermit database... all hermit location is now kaput")
+ warn("Resetting hermit database... all hermit location is now kaput")
@hermithash = @resethash
save_hash
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index 473fde7..8618dda 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,143 +1,143 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
class Ratter < BasePlugin
attr_accessor :ratter_enabled, :balance_user, :attack_command, :available_rats
attr_accessor :inventory_rats, :rat_prices, :total_rat_money
def setup
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
@balance_user = false
#What do we do when we want them dead?
@attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
trigger /Liirup the Placid stands here/, :sell_rats
#Reset the money after selling to the ratter in hashan.
trigger /Liirup squeals with delight/, :reset_money
trigger /You see exits/, :reset_available_rats
trigger /You see a single exit/, :reset_available_rats
#After we gain balance, we need to decide if we should attack again or not.
after Character, :set_simple_stats, :should_i_attack_rat?
after Character, :set_extended_stats, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def enable_ratter
- warn("RMuddy: Room Ratter Turned On.")
+ warn("Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
- warn("RMuddy: Room Ratter Turned Off.")
+ warn("Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
def reset_available_rats
@available_rats = 0
end
def sell_rats
send_kmuddy_command("Sell rats to Liirup")
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && plugins[Character].balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && plugins[Character].has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index 3753095..4899e41 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,203 +1,205 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
class Walker < BasePlugin
attr_accessor :opposite_directions, :last_timer, :lost_or_not, :seconds_to_wait
attr_accessor :rail_position, :current_rail, :current_thread, :ratter_rail, :auto_walk_enabled
attr_accessor :back_tracking
def setup
- warn("RMuddy: ***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
- warn("RMuddy: ***Use at your own risk!***")
+ warn("***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
+ warn("***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#lost or not? Well, let's see
@lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
trigger /There is no exit in that direction/, :misguided
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
sleep 1
end
#If we can walk, walk!
if plugins[Character].balanced && plugins[Character].has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
- warn("RMuddy: Auto Walker turned on. (Used with the Room Ratter.)")
+ warn("Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def disable_walker
- warn("RMuddy: Auto Walker turned off. (Used with the Room Ratter.)")
+ warn("Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
def misguided
@lost_or_not += 1
- if @lost_or_not < 3
+ if @lost_or_not = 1
@rail_position -= 2
+ elsif @lost_or_not <3
+ @rail_position -= 1
else
lost!
end
end
def lost!
if @auto_walk_enabled == true
- warn("RMuddy: Auto Walker is LOST! Disabling.")
+ warn("Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
-
+ @lost_or_not = 0
if plugins[Ratter].ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
sleep 0.3
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
52fa77b78c157cd9a99cb4b8e92b1a52cf1a82f3
|
Added blank_line and bar_line methods to BasePlugin class. These are to prevent repeating yourself. blank_line prints out a single warn bar_line prints out 80 ==
|
diff --git a/base_plugin.rb b/base_plugin.rb
index ba84633..54d9eff 100644
--- a/base_plugin.rb
+++ b/base_plugin.rb
@@ -1,74 +1,80 @@
class BasePlugin
attr_accessor :triggers, :receiver
def initialize(rec)
@receiver = rec
self.setup
end
+
+ def bar_line
+ warn("=" * 80)
+ end
def plugins
@receiver.plugins
end
def disabled_plugins
@receiver.disabled_plugins
end
def disable
unless @receiver.disabled_plugins.include?(self)
@receiver.enabled_plugins.delete(self)
@receiver.disabled_plugins << self
end
warn("RMuddy: #{self.class.to_s} Plugin has been disabled.")
end
def enable
unless @receiver.enabled_plugins.include?(self)
@receiver.disabled_plugins.delete(self)
@receiver.enabled_plugins << self
end
- warn("RMuddy: #{self.class.to_s} Plugin has been enabled.")
+ warn("#{self.class.to_s} Plugin has been enabled.")
end
def help
- warn("RMuddy: That plugin's author has not created a help for you!")
+ warn("That plugin's author has not created a help for you!")
end
def trigger(regex, method)
@triggers ||= {}
@triggers[regex] = method
end
def set_kmuddy_variable(variable_name, variable_value)
@receiver.queue << ["set_var", variable_name, variable_value]
end
-
+ def blank_line
+ warn("")
+ end
def get_kmuddy_variable(variable_name)
@receiver.varsock.get(variable_name)
end
def send_kmuddy_command(command_text)
@receiver.queue << ["send_command", command_text]
end
def before(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(1, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
module_name.module_eval(new_method.join("\n"))
end
def after(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(-2, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
module_name.module_eval(new_method.join("\n"))
end
end
\ No newline at end of file
diff --git a/configs/anti_theft.yaml b/configs/anti_theft.yaml
new file mode 100644
index 0000000..ed6677d
--- /dev/null
+++ b/configs/anti_theft.yaml
@@ -0,0 +1,10 @@
+---
+pack: ""
+armor: ""
+shirt: ""
+trousers: ""
+robe: ""
+weapon1: ""
+weapon2: ""
+ring1: ""
+ring2: ""
diff --git a/disabled-plugins/anti_theft.rb b/disabled-plugins/anti_theft.rb
index 4f0d168..3513a98 100644
--- a/disabled-plugins/anti_theft.rb
+++ b/disabled-plugins/anti_theft.rb
@@ -1,14 +1,31 @@
# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
class Anti_theft < BasePlugin
#setup method for the plugin.. triggers, var. init and stuff goes here
def setup
trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
trigger /^You remove a canvas backpack/, :rewear_pack
trigger /^You remove a suit of scale mail/, :rewear_armor
- File.open("configs/anti_theft.yaml") {|fi| @thefthash = YAML.load(fi)}
+
+ unless (File.open("configs/anti_theft.yaml") {|fi| @thefthash = YAML.load(fi)})
+ warn("RMuddy: No configuration file found... you must have the configuration file anti_theft.yaml in the configs directory")
+ end
+ end
+
+ def help
+ warn("RMuddy: OK, you asked for it. You must setup the YAML file. It has a format. Each thing should be on a seperate line")
+ warn("RMuddy: The format is... on separate lines, mind you, with nothing in front of it")
+ warn("item: \"<fully described item, with number here>\"")
+ blank_line
+ warn("RMuddy: example:")
+ warn("RMuddy: pack: \"pack296008\"")
+ blank_line
+ warn("RMuddy: You can use \"/notify 4567 Antitheft set_pack pack296008\" to accomplish the same result as the line above")
+ warn("RMuddy: and this module should have been packaged with a template anti_theft.yaml file with it")
+ blank_line
+ warn("RMuddy:")
end
end
diff --git a/disabled-plugins/hermit_tracker.rb b/disabled-plugins/hermit_tracker.rb
deleted file mode 100644
index 17ef8a3..0000000
--- a/disabled-plugins/hermit_tracker.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-#Module for tracking where you have charged Hermit tarot cards in achaea
-#USAGE: /notify 4567 Hermittracker activate_hermit <tag to associate room with>
-# /notify 4567 Hermittracker fling_hermit <room-tag>
-#The tracker -should- automagically keep track of which card you charged, and
-#where, and get it from your pack.
-class Hermit_tracker < BasePlugin
- def setup
- @whichhermit = ''
- @key = ''
- @charginghermit = false
- warn("Loading hermit locations database")
- File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
- trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
- trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
- trigger /^The card begins to glow with a mystic energy/, :hermit_drop
- send_kmuddy_command("ind 50 hermit")
- warn("Hermit Tracker loaded")
- end
-
- def activate_hermit(key)
- if key == ''
- warn("Rmuddy: You must supply a word to associate this room with!!")
- else
- @key = key
- warn("Rmuddy: Ok, activating a hermit for this room")
- send_kmuddy_command("outd hermit")
- send_kmuddy_command("ii hermit")
- end
-
- end
-
- def set_value(match_object )
- @whichhermit = match_object[1]
- associate_hermit
- end
-
- def associate_hermit
- warn("Rmuddy: Associating card #{@whichhermit} with the place name #{@key}")
- @hermithash[@key] = @whichhermit
- send_kmuddy_command("activate hermit")
- end
-
- def save_hash
- File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
- warn("Saved hermit tracker hash")
- end
-
- def fling_hermit(key)
- if key == ''
- warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
- else
- send_kmuddy_command("get #{@hermithash[key]} from pack")
- send_kmuddy_command("charge hermit")
- @charginghermit = true
- end
- end
-
- def hermit_list
- wanr("Rmuddy: Hermits currently in database")
- @hermithash.each_key { |key| warn("Rmuddy: #{key}") }
- end
-
- def hermit_drop
- if @charginghermit
- send_kmuddy_command("fling hermit at ground")
- @charginghermit = false
- @hermithash.delete(@key.to_s)
- end
- end
-end
\ No newline at end of file
diff --git a/kmuddy/kmuddy.rb b/kmuddy/kmuddy.rb
index 76fe5bb..a898c8d 100755
--- a/kmuddy/kmuddy.rb
+++ b/kmuddy/kmuddy.rb
@@ -1,43 +1,43 @@
#!/bin/env ruby
-
+#Modified for use with RMuddy specifically by Demonnic.
require 'socket'
module KMuddy
ANSI = { "reset" => "\e[0m", "bold" => "\e[1m",
"underline" => "\e[4m", "blink" => "\e[5m",
"reverse" => "\e[7m", "invisible" => "\e[8m",
"black" => "\e[0;30m", "darkgrey" => "\e[1;30m",
"red" => "\e[0;31m", "lightred" => "\e[1;31m",
"green" => "\e[0;32m", "lightgreen" => "\e[1;32m",
"brown" => "\e[0;33m", "yellow" => "\e[1;33m",
"blue" => "\e[0;34m", "lightblue" => "\e[1;34m",
"purple" => "\e[0;35m", "magenta" => "\e[1;35m",
"cyan" => "\e[1;36m", "lightcyan" => "\e[1;36m",
"grey" => "\e[0;37m", "white" => "\e[1;37m",
"bgblack" => "\e[40m", "bgred" => "\e[41m",
"bggreen" => "\e[42m", "bgyellow" => "\e[43m",
"bgblue" => "\e[44m", "bgmagenta" => "\e[45m",
"bgcyan" => "\e[46m", "bgwhite" => "\e[47m"
}
def ansi(text)
ANSI[text]
end
def ansi_strip(line)
return line.gsub!(/\e\[[0-9;]+m/, "")
end
def debug(text)
#$stderr.puts("#{ansi("red")}--> #{text}#{ansi("reset")}") if DEBUG
$stderr.puts("DEBUG--> #{text}") if DEBUG
end
def warn(text)
- $stderr.puts("\n-! #{text}")
+ $stderr.puts("\n-!RMuddy: #{text}")
end
def output(text)
$stderr.puts(text)
end
end
diff --git a/receiver.rb b/receiver.rb
index 7935b4d..80a92c5 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,140 +1,144 @@
class Receiver
attr_accessor :varsock, :enabled_plugins, :disabled_plugins, :queue
def plugins
@enabled_plugins
end
debug("Receiver: Loading Files...")
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
attr_accessor File.basename(file, ".rb").to_sym
end
def initialize
- warn("RMuddy: System Loading...")
+ warn("System Loading...")
@queue = []
@enabled_plugins = []
class << @enabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
@disabled_plugins = []
class << @disabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
basename = File.basename(file, ".rb")
class_string = basename.split("_").each{|part| part.capitalize!}.join("")
instantiated_class = Object.module_eval(class_string).new(self)
instantiated_class.enable
end
Thread.new do
while true do
sleep 0.1
if @queue.length > 0
element = @queue.shift
case element[0]
when "set_var"
@varsock.set(element[1], element[2])
when "send_command"
@varsock.command(element[1])
end
end
end
end
- warn("=" * 80)
+ bar_line
warn("You may send commands to RMuddy's plugins like so:")
warn("/notify 4567 PluginName action_name arg1 arg2 arg3")
- warn("=" * 80)
+ bar_line
warn("You may ask a plugin for help by doing:")
warn("/notify 4567 PluginName help")
+ bar_line
+ warn("System Ready!")
+ end
+
+ def bar_line
warn("=" * 80)
- warn("RMuddy: System Ready!")
end
def receive(text)
@enabled_plugins.each do |klass|
klass.triggers.each_pair do |regex, method|
debug("Testing Plugin: #{klass.to_s}| Regex: #{regex} against line: #{text}")
match = regex.match(text)
unless match.nil?
debug("Match!")
unless match[1].nil?
klass.send(method.to_sym, match)
else
klass.send(method.to_sym)
end
else
debug("No match!")
end
end
end
end
def command(text)
debug("RMuddy received notify command: #{text} ")
method_and_args = text.split(" ")
klass = Object.module_eval("#{method_and_args[0]}")
method_sym = method_and_args[1].to_sym
args = method_and_args[2..-1]
unless method_sym == :enable
@enabled_plugins.each do |plugin|
if plugin.is_a?(klass)
unless args.empty?
plugin.send(method_sym, *args)
else
plugin.send(method_sym)
end #args check
end #check the class of the plugin
end #loop through enabled plugins
else # Check to see if it's an enable command
@disabled_plugins.each do |plugin|
if plugin.is_a?(klass)
plugin.send(:enable)
end #check for class of the plugin
end #looping through the disabled plugins
end # end of check for :enable
end #end of Command method.
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
0f7d427f4ca0bcef20a532c2c1ee04479f02efc3
|
Added formatting to hermit_list in Hermit plugin. Added del_hash and reset_hash methods to Hermit plugin.
|
diff --git a/configs/hermithash.yaml b/configs/hermithash.yaml
index 0b61456..da191f5 100644
--- a/configs/hermithash.yaml
+++ b/configs/hermithash.yaml
@@ -1,4 +1,4 @@
---
-:Location: placeholder
-kitchen: "307184"
-droom: "333643"
+lounge2: "241350"
+Location: card number
+lounge: "319420"
diff --git a/enabled-plugins/hermit.rb b/enabled-plugins/hermit.rb
index fa22c1f..51d7977 100644
--- a/enabled-plugins/hermit.rb
+++ b/enabled-plugins/hermit.rb
@@ -1,79 +1,106 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermit activate_hermit <tag to associate room with>
# /notify 4567 Hermit fling_hermit <room-tag>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
class Hermit < BasePlugin
def setup
@whichhermit = ''
@key = ''
+ @formatlength = 80
+ @formatpad = (@formatlength / 3)
@charginghermit = false
- @resethash = {"Location" => "placeholder"}
- warn("Loading hermit locations database")
+ @resethash = {"Location" => "card number"}
+ warn("RMuddy: Loading hermit locations database")
File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
+ trigger /^You have recovered equilibrium.$/, :put_away_hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
- warn("Hermit Tracker loaded")
+ warn("RMuddy: Hermit Tracker loaded")
end
def activate_hermit(key = '')
if key == ''
- warn("Rmuddy: You must supply a word to associate this room with!!")
+ warn("RMuddy: You must supply a word to associate this room with!!")
else
@key = key
- warn("Rmuddy: Ok, activating a hermit for this room")
+ warn("RMuddy: Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
def associate_hermit
- warn("Rmuddy: Associating card #{@whichhermit} with the place name #{@key}")
+ warn("RMuddy: Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
+ @activatinghermit = true
end
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
- warn("Saved hermit tracker hash")
+ warn("RMuddy: Saved hermit tracker hash")
end
def fling_hermit(key = '')
@key = key
if key == ''
- warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
+ warn("RMuddy: Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
+ def put_away_hermit
+ if @activatinghermit
+ send_kmuddy_command("Put hermit in pack")
+ @activatinghermit = false
+ end
+ end
+
+ def del_hash (key = '')
+ if key == ''
+ warn("RMuddy: You must specify the room tag you wish to remove from the database")
+ else
+ warn("RMuddy deleting #{key} from the hermit locations database")
+ @hermithash.delete(key.to_s)
+ end
+ end
+
def hermit_list
- warn("Rmuddy: Hermits currently in database")
- @hermithash.each_key { |key| warn("Rmuddy: #{key}") }
+ warn("RMuddy: Hermits currently in database")
+ @output = "Rmuddy: Location".ljust(@formatpad) + @hermithash["Location"].rjust(@formatpad)
+ warn(@output)
+ @hermithash.each_key { |key|
+ unless key == "Location"
+ @output = "Rmuddy: #{key.to_s}".ljust(@formatpad) + @hermithash[key].to_s.rjust(@formatpad)
+ warn(@output)
+ end
+ }
end
def reset_hash
- warn("Rmuddy: Resetting hermit database... all hermit location is now kaput")
+ warn("RMuddy: Resetting hermit database... all hermit location is now kaput")
@hermithash = @resethash
save_hash
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
|
KeithHanson/rmuddy
|
52a35a34fca166055d19cd62e3effe01429df948
|
We have hermit tracker! Plugin Hermit now works. woot woot. Working on beginnings of anti-theft plugin
|
diff --git a/configs/hermithash.yaml b/configs/hermithash.yaml
index e69de29..0b61456 100644
--- a/configs/hermithash.yaml
+++ b/configs/hermithash.yaml
@@ -0,0 +1,4 @@
+---
+:Location: placeholder
+kitchen: "307184"
+droom: "333643"
diff --git a/disabled-plugins/anti_theft.rb b/disabled-plugins/anti_theft.rb
new file mode 100644
index 0000000..4f0d168
--- /dev/null
+++ b/disabled-plugins/anti_theft.rb
@@ -0,0 +1,14 @@
+# Plugin for RMuddy. Should handle basic anti-theft, configuration will be in anti_theft.yaml
+
+class Anti_theft < BasePlugin
+ #setup method for the plugin.. triggers, var. init and stuff goes here
+ def setup
+ trigger /^(\w+) snaps his fingers in front of you/, :hypnosis
+ trigger /^A soulmaster entity lets loose a horrible scream as a dark stream of primal chaos flows from it and into your very being/, :lose_soulmaster
+ trigger /You get \d+ gold sovereigns from \w+/, :put_gold_away
+ trigger /^You remove a canvas backpack/, :rewear_pack
+ trigger /^You remove a suit of scale mail/, :rewear_armor
+ File.open("configs/anti_theft.yaml") {|fi| @thefthash = YAML.load(fi)}
+ end
+end
+
diff --git a/enabled-plugins/hermit.rb b/enabled-plugins/hermit.rb
index a14fb13..fa22c1f 100644
--- a/enabled-plugins/hermit.rb
+++ b/enabled-plugins/hermit.rb
@@ -1,75 +1,79 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
-#USAGE: /notify 4567 Hermittracker activate_hermit <tag to associate room with>
-# /notify 4567 Hermittracker fling_hermit <room-tag>
+#USAGE: /notify 4567 Hermit activate_hermit <tag to associate room with>
+# /notify 4567 Hermit fling_hermit <room-tag>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
class Hermit < BasePlugin
def setup
@whichhermit = ''
@key = ''
@charginghermit = false
+ @resethash = {"Location" => "placeholder"}
warn("Loading hermit locations database")
File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
warn("Hermit Tracker loaded")
end
- def activate_hermit(key)
+ def activate_hermit(key = '')
if key == ''
warn("Rmuddy: You must supply a word to associate this room with!!")
else
@key = key
warn("Rmuddy: Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
end
end
def set_value(match_object )
@whichhermit = match_object[1]
associate_hermit
end
def associate_hermit
warn("Rmuddy: Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[@key] = @whichhermit
send_kmuddy_command("activate hermit")
end
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
warn("Saved hermit tracker hash")
end
- def fling_hermit(key)
+ def fling_hermit(key = '')
+ @key = key
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
def hermit_list
warn("Rmuddy: Hermits currently in database")
@hermithash.each_key { |key| warn("Rmuddy: #{key}") }
end
- def test_this
- warn("Rmuddy: TESTING!!!!!")
+ def reset_hash
+ warn("Rmuddy: Resetting hermit database... all hermit location is now kaput")
+ @hermithash = @resethash
+ save_hash
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
|
KeithHanson/rmuddy
|
31d0ee3f98331be2a594aca4465487efd748710b
|
Changed hermit_tracker.rb to hermit.rb... class Hermit. method test_this works in class Hermit. method hermit_list does not... minimal testing due to dinnertime, more work later
|
diff --git a/enabled-plugins/hermit.rb b/enabled-plugins/hermit.rb
new file mode 100644
index 0000000..a14fb13
--- /dev/null
+++ b/enabled-plugins/hermit.rb
@@ -0,0 +1,75 @@
+#Module for tracking where you have charged Hermit tarot cards in achaea
+#USAGE: /notify 4567 Hermittracker activate_hermit <tag to associate room with>
+# /notify 4567 Hermittracker fling_hermit <room-tag>
+#The tracker -should- automagically keep track of which card you charged, and
+#where, and get it from your pack.
+class Hermit < BasePlugin
+
+ def setup
+ @whichhermit = ''
+ @key = ''
+ @charginghermit = false
+ warn("Loading hermit locations database")
+ File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
+ trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
+ trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
+ trigger /^The card begins to glow with a mystic energy/, :hermit_drop
+ send_kmuddy_command("ind 50 hermit")
+ warn("Hermit Tracker loaded")
+ end
+
+ def activate_hermit(key)
+ if key == ''
+ warn("Rmuddy: You must supply a word to associate this room with!!")
+ else
+ @key = key
+ warn("Rmuddy: Ok, activating a hermit for this room")
+ send_kmuddy_command("outd hermit")
+ send_kmuddy_command("ii hermit")
+ end
+
+ end
+
+ def set_value(match_object )
+ @whichhermit = match_object[1]
+ associate_hermit
+ end
+
+ def associate_hermit
+ warn("Rmuddy: Associating card #{@whichhermit} with the place name #{@key}")
+ @hermithash[@key] = @whichhermit
+ send_kmuddy_command("activate hermit")
+ end
+
+ def save_hash
+ File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
+ warn("Saved hermit tracker hash")
+ end
+
+ def fling_hermit(key)
+ if key == ''
+ warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
+ else
+ send_kmuddy_command("get #{@hermithash[key]} from pack")
+ send_kmuddy_command("charge hermit")
+ @charginghermit = true
+ end
+ end
+
+ def hermit_list
+ warn("Rmuddy: Hermits currently in database")
+ @hermithash.each_key { |key| warn("Rmuddy: #{key}") }
+ end
+
+ def test_this
+ warn("Rmuddy: TESTING!!!!!")
+ end
+
+ def hermit_drop
+ if @charginghermit
+ send_kmuddy_command("fling hermit at ground")
+ @charginghermit = false
+ @hermithash.delete(@key.to_s)
+ end
+ end
+end
|
KeithHanson/rmuddy
|
bf14aeedcaa27b472960ca1089b4b6073f461312
|
Edited hermittracker so that it no longer assumes the triggers fire before the code in the method... may fix issue with breaking rmuddy
|
diff --git a/disabled-plugins/hermit_tracker.rb b/disabled-plugins/hermit_tracker.rb
index aba59a9..17ef8a3 100644
--- a/disabled-plugins/hermit_tracker.rb
+++ b/disabled-plugins/hermit_tracker.rb
@@ -1,64 +1,70 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermittracker activate_hermit <tag to associate room with>
# /notify 4567 Hermittracker fling_hermit <room-tag>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
class Hermit_tracker < BasePlugin
def setup
@whichhermit = ''
@key = ''
@charginghermit = false
warn("Loading hermit locations database")
File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
warn("Hermit Tracker loaded")
end
def activate_hermit(key)
if key == ''
- warn("You must supply a word to associate this room with!!")
+ warn("Rmuddy: You must supply a word to associate this room with!!")
else
- warn("Ok, activating a hermit for this room")
+ @key = key
+ warn("Rmuddy: Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
- @key = key
- warn("Associating card #{@whichhermit} with the place name #{@key}")
- @hermithash[key] = @whichhermit
- send_kmuddy_command("activate hermit")
end
+
end
def set_value(match_object )
@whichhermit = match_object[1]
+ associate_hermit
+ end
+
+ def associate_hermit
+ warn("Rmuddy: Associating card #{@whichhermit} with the place name #{@key}")
+ @hermithash[@key] = @whichhermit
+ send_kmuddy_command("activate hermit")
end
def save_hash
File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
warn("Saved hermit tracker hash")
end
def fling_hermit(key)
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
def hermit_list
- @hermithash.each_key { |key| puts key }
+ wanr("Rmuddy: Hermits currently in database")
+ @hermithash.each_key { |key| warn("Rmuddy: #{key}") }
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete(@key.to_s)
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
f3d9f99acb1629e881c83fe4a56bead57ad2bd0f
|
modified to work with new system, yay notify!
|
diff --git a/disabled-plugins/hermit_tracker.rb b/disabled-plugins/hermit_tracker.rb
index 2f2b9ac..aba59a9 100644
--- a/disabled-plugins/hermit_tracker.rb
+++ b/disabled-plugins/hermit_tracker.rb
@@ -1,64 +1,64 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
-#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
-# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
+#USAGE: /notify 4567 Hermittracker activate_hermit <tag to associate room with>
+# /notify 4567 Hermittracker fling_hermit <room-tag>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
-module Hermittracker
- def hermittracker_setup
+class Hermit_tracker < BasePlugin
+ def setup
@whichhermit = ''
@key = ''
@charginghermit = false
warn("Loading hermit locations database")
- @hermithash = YAML.load(File.open("configs/hermithash.yaml"))
+ File.open("configs/hermithash.yaml") {|fi| @hermithash = YAML.load(fi)}
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
warn("Hermit Tracker loaded")
end
def activate_hermit(key)
if key == ''
warn("You must supply a word to associate this room with!!")
else
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
@key = key
- warn("Associating card @whichhermit with the place name @key")
+ warn("Associating card #{@whichhermit} with the place name #{@key}")
@hermithash[key] = @whichhermit
send_kmuddy_command("activate hermit")
end
end
def set_value(match_object )
@whichhermit = match_object[1]
end
def save_hash
- File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
+ File.open("configs/hermithash.yaml", "w") {|fi| YAML.dump(@hermithash, fi)}
warn("Saved hermit tracker hash")
end
def fling_hermit(key)
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
- send_kmuddy_command("get @hermithash[key] from pack")
+ send_kmuddy_command("get #{@hermithash[key]} from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
def hermit_list
@hermithash.each_key { |key| puts key }
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
- @hermithash.delete("@key")
+ @hermithash.delete(@key.to_s)
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/inscriber.rb b/enabled-plugins/inscriber.rb
index ac0a51f..04bc794 100644
--- a/enabled-plugins/inscriber.rb
+++ b/enabled-plugins/inscriber.rb
@@ -1,73 +1,64 @@
#Inscriber module for RMuddy triggering/aliasing system.
#Module to handle inscribing batches of tarot cards in Achaea
#Will make sure you only ever sip in between cards... still very rough
#draft.
class Inscriber < BasePlugin
#we'll setup some accessor methods, weee
attr_accessor :number_to_inscribe
attr_accessor :type_to_inscribe
attr_accessor :inscribing
def setup
#setup our triggers for commands... will be deprecated when /notify works
- trigger /ins (\d+) (\w+)/, :set_number_to_inscribe #command to set params
- trigger /startins/, :should_we_inscribe? #command to go!
trigger /You have successfully inscribed/, :decrement_counter #we did it!
trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
#by default, we are not, in fact, inscribing
@inscribing = false
@number_to_inscribe = 0
- @type_to_inscribe = 0
+ @type_to_inscribe = ""
end
def mass_inscribe(number_to_inscribe, type_to_inscribe)
@number_to_inscribe = number_to_inscribe.to_i
- @type_to_inscribe = type_to_inscribe
+ @type_to_inscribe = type_to_inscribe.to_s
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
warn("Inscriber Plugin: Ready to inscribe #{@number_to_inscribe} #{@type_to_inscribe}")
warn("Use begin_inscribing to start.")
end
def begin_inscribing
inscribe_tarot
end
- #def set_number_to_inscribe (match_object ) #so we need to actually set the params
- # @number_to_inscribe = match_object[1].to_i #so we match to the trigger
- # @type_to_inscribe = match_object[2].to_s #and do it
- # set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #and push back to kmuddy
- # set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
- #end
-
def inscribe_tarot #here's how we actually inscribe the bloody cards
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
plugins[Sipper].should_i_sip? #check to see if we need mana before we inscribe
plugins[Sipper].disable #then disable the sipper so as not to kill our inscribe
- send_kmuddy_command("inscribe blank with $type_to_inscribe") #and actually inscribe
+ send_kmuddy_command("inscribe blank with #{@type_to_inscribe}") #and actually inscribe
end
def decrement_counter #lower the counter, so we inscribe the correct # of cards
@number_to_inscribe -= 1 #decrement counter
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
should_we_inscribe? #check if we should do another!
end
def out_of_mana! #pretty obvious
@inscribing = false #if we're out of mana, we're not inscribing
send_kmuddy_command("sip mana") #so we need to sip some mana
end
def should_we_inscribe? #test if we should inscribe
if @number_to_inscribe > 0 #if we still have inscription to do
inscribe_tarot #then inscribe
elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
- send_kmuddy_command("ind 50 $type_to_inscribe") #put the cards away
+ send_kmuddy_command("ind 50 #{@type_to_inscribe}") #put the cards away
plugins[Sipper].should_i_sip? #check if we need to sip
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index 15e0a45..473fde7 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,143 +1,143 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
class Ratter < BasePlugin
attr_accessor :ratter_enabled, :balance_user, :attack_command, :available_rats
attr_accessor :inventory_rats, :rat_prices, :total_rat_money
def setup
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
- @balance_user = true
+ @balance_user = false
#What do we do when we want them dead?
- @attack_command = "bop rat"
+ @attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
trigger /Liirup the Placid stands here/, :sell_rats
#Reset the money after selling to the ratter in hashan.
trigger /Liirup squeals with delight/, :reset_money
trigger /You see exits/, :reset_available_rats
trigger /You see a single exit/, :reset_available_rats
#After we gain balance, we need to decide if we should attack again or not.
after Character, :set_simple_stats, :should_i_attack_rat?
after Character, :set_extended_stats, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def enable_ratter
warn("RMuddy: Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("RMuddy: Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
def reset_available_rats
@available_rats = 0
end
def sell_rats
send_kmuddy_command("Sell rats to Liirup")
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && plugins[Character].balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && plugins[Character].has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
23d4b44381113710701535bb796672b9fbfa8e8e
|
Trying to fix send_command in setups...
|
diff --git a/receiver.rb b/receiver.rb
index 6e16cc2..7935b4d 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,139 +1,140 @@
class Receiver
attr_accessor :varsock, :enabled_plugins, :disabled_plugins, :queue
def plugins
@enabled_plugins
end
debug("Receiver: Loading Files...")
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
attr_accessor File.basename(file, ".rb").to_sym
end
def initialize
warn("RMuddy: System Loading...")
@queue = []
@enabled_plugins = []
class << @enabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
@disabled_plugins = []
class << @disabled_plugins
alias_method :original_indexer, :[]
def [](arg)
if arg.is_a?(Class)
each do |plugin|
if plugin.is_a?(arg)
return plugin
end
end
return nil
else
original_indexer(arg)
end
end
end
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
basename = File.basename(file, ".rb")
class_string = basename.split("_").each{|part| part.capitalize!}.join("")
instantiated_class = Object.module_eval(class_string).new(self)
instantiated_class.enable
end
Thread.new do
while true do
+ sleep 0.1
if @queue.length > 0
element = @queue.shift
case element[0]
when "set_var"
@varsock.set(element[1], element[2])
when "send_command"
@varsock.command(element[1])
end
end
end
end
warn("=" * 80)
warn("You may send commands to RMuddy's plugins like so:")
warn("/notify 4567 PluginName action_name arg1 arg2 arg3")
warn("=" * 80)
warn("You may ask a plugin for help by doing:")
warn("/notify 4567 PluginName help")
warn("=" * 80)
warn("RMuddy: System Ready!")
end
def receive(text)
@enabled_plugins.each do |klass|
klass.triggers.each_pair do |regex, method|
debug("Testing Plugin: #{klass.to_s}| Regex: #{regex} against line: #{text}")
match = regex.match(text)
unless match.nil?
debug("Match!")
unless match[1].nil?
klass.send(method.to_sym, match)
else
klass.send(method.to_sym)
end
else
debug("No match!")
end
end
end
end
def command(text)
debug("RMuddy received notify command: #{text} ")
method_and_args = text.split(" ")
klass = Object.module_eval("#{method_and_args[0]}")
method_sym = method_and_args[1].to_sym
args = method_and_args[2..-1]
unless method_sym == :enable
@enabled_plugins.each do |plugin|
if plugin.is_a?(klass)
unless args.empty?
plugin.send(method_sym, *args)
else
plugin.send(method_sym)
end #args check
end #check the class of the plugin
end #loop through enabled plugins
else # Check to see if it's an enable command
@disabled_plugins.each do |plugin|
if plugin.is_a?(klass)
plugin.send(:enable)
end #check for class of the plugin
end #looping through the disabled plugins
end # end of check for :enable
end #end of Command method.
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
08d1bc9ddca2e36dea6e595269d89612381ae48d
|
Massive Commit! Better Faster Stronger!
|
diff --git a/base_plugin.rb b/base_plugin.rb
new file mode 100644
index 0000000..ba84633
--- /dev/null
+++ b/base_plugin.rb
@@ -0,0 +1,74 @@
+class BasePlugin
+ attr_accessor :triggers, :receiver
+
+ def initialize(rec)
+ @receiver = rec
+
+ self.setup
+ end
+
+ def plugins
+ @receiver.plugins
+ end
+
+ def disabled_plugins
+ @receiver.disabled_plugins
+ end
+
+ def disable
+ unless @receiver.disabled_plugins.include?(self)
+ @receiver.enabled_plugins.delete(self)
+ @receiver.disabled_plugins << self
+ end
+ warn("RMuddy: #{self.class.to_s} Plugin has been disabled.")
+ end
+
+ def enable
+ unless @receiver.enabled_plugins.include?(self)
+ @receiver.disabled_plugins.delete(self)
+ @receiver.enabled_plugins << self
+ end
+ warn("RMuddy: #{self.class.to_s} Plugin has been enabled.")
+ end
+
+ def help
+ warn("RMuddy: That plugin's author has not created a help for you!")
+ end
+
+ def trigger(regex, method)
+ @triggers ||= {}
+ @triggers[regex] = method
+ end
+
+ def set_kmuddy_variable(variable_name, variable_value)
+ @receiver.queue << ["set_var", variable_name, variable_value]
+ end
+
+ def get_kmuddy_variable(variable_name)
+ @receiver.varsock.get(variable_name)
+ end
+
+ def send_kmuddy_command(command_text)
+ @receiver.queue << ["send_command", command_text]
+ end
+
+ def before(module_name, method_symbol, hook_symbol)
+ method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
+
+ new_method = method.split("\n")
+ new_method.insert(1, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
+
+ module_name.module_eval(new_method.join("\n"))
+ end
+
+ def after(module_name, method_symbol, hook_symbol)
+ method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
+
+ new_method = method.split("\n")
+
+ new_method.insert(-2, "plugins[#{self.class}].send(:#{hook_symbol.to_s}) if plugins[#{self.class}] ")
+
+ module_name.module_eval(new_method.join("\n"))
+ end
+
+end
\ No newline at end of file
diff --git a/connection_handler.rb b/connection_handler.rb
index 96bd984..9796e1e 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,45 +1,46 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
$server_port = 4567
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
+ debug("Received a line!")
@receiver.receive(line)
end
}
@threads << Thread.new {
while (event = @evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
@receiver.command(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
diff --git a/enabled-plugins/hermittracker.rb b/disabled-plugins/hermit_tracker.rb
similarity index 100%
rename from enabled-plugins/hermittracker.rb
rename to disabled-plugins/hermit_tracker.rb
diff --git a/disabled-plugins/hermittracker.rb b/disabled-plugins/hermittracker.rb
deleted file mode 100644
index 946f06e..0000000
--- a/disabled-plugins/hermittracker.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-#Module for tracking where you have charged Hermit tarot cards in achaea
-#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
-# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
-#The tracker -should- automagically keep track of which card you charged, and
-#where, and get it from your pack.
-module Hermittracker
-
- def hermittracker_setup
-
- #Setup our hermit tracker module... by default, there is no hermit, no key,
- #we are not charging the tarot
- @whichhermit = ''
- @key = ''
- @charginghermit = false
-
- #Let the user know we're loading the hash
- warn("Rmuddy: Loading hermit locations database")
- file = File.open("configs/hermithash.yaml")
- @hermithash = YAML.load(file)
- file.close
- hermit_list
- warn("Rmuddy: Hash loaded, database open, hermit away")
-
- #trigger set, in RMuddy DSL, for when you check the hermit you are
- #activating, when you've activated it, and to check when you charge a card
- #if you've told RMuddy you're wanting to use a hermit
- trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_hermit_value
- trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hermit_hash
- trigger /^The card begins to glow with a mystic energy/, :hermit_drop
-
- #Put all the hermits you happen to have in your inventory in a deck... this
- #keeps the trigger for checking which hermit is being activated working
- #cleanly
- send_kmuddy_command("ind 50 hermit")
-
- #all done! let the user know it's loaded up
- warn("Rmuddy: Hermit Tracker loaded")
- end
-
- def test_this
- #added to help test /notify capability of RMuddy
- warn("Test passed!")
- end
-
- def activate_hermit(key)
- if key == '' #If you don't provide us with what you want to call this room
- warn("You must supply a word to associate this room with!!") #we tell you
- else #about it
- warn("Ok, activating a hermit for this room") #otherwise, we let you know
- send_kmuddy_command("outd hermit") #take a card out
- send_kmuddy_command("ii hermit") #inspect it
- @key = key #set @key to equal the key
- warn("Associating card @whichhermit with the place name @key") #notify
- @hermithash[key] = @whichhermit #store the key=>card#### pair
- send_kmuddy_command("activate hermit") #activate the hermit card
- end
- end
-
- def set_hermit_value (match_object ) #this is to set @whichhermit when it is
- @whichhermit = match_object[1] #inspected via ii, above
- end
-
- def save_hermit_hash #save our hash to the yaml file
- File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
- warn("Saved hermit tracker hash") #and let user know about it
- end
-
- def fling_hermit(key) #ok, we need to skedaddle
- if key == '' #again, if you don't tell us where to go...
- warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
- else #otherwise
- send_kmuddy_command("get @hermithash[key] from pac") #get the proper card
- send_kmuddy_command("charge hermit") #and charge it
- @charginghermit = true #let the script know we're trying to use a hermit card
- end
- end
-
- def hermit_list #print out a list of keys from our hash... fairly simple
- @hermithash.each_key { |key| warn("key") }
- end
-
- def hermit_drop #ACTUALLY fling the hermit card
- if @charginghermit #but ONLY if we're actually charging a HERMIT
- send_kmuddy_command("fling hermit at ground") #ok.. so do it
- @charginghermit = false #and now we're not charging a hermit
- @hermithash.delete("@key") #and we no longer have that card
- end
- end
-
-end
\ No newline at end of file
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 250215a..eee4d8a 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,129 +1,140 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
-module Character
+class Character < BasePlugin
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
- attr_accessor :character_current_health, :character_current_mana
- attr_accessor :character_total_health, :character_total_mana
- attr_accessor :character_current_endurance, :character_total_endurance
- attr_accessor :character_current_willpower, :character_total_willpower
- attr_accessor :character_balanced
- attr_accessor :character_status
- attr_accessor :character_has_equilibrium
+ attr_accessor :current_health, :current_mana
+ attr_accessor :total_health, :total_mana
+ attr_accessor :current_endurance, :total_endurance
+ attr_accessor :current_willpower, :total_willpower
+ attr_accessor :balanced
+ attr_accessor :status
+ attr_accessor :has_equilibrium
- def character_setup
- warn("RMuddy: Character Plugin Loaded!")
+ def setup
#By default, we are assumed to be balanced and to have equilibrium.
- @character_balanced = true
- @character_has_equilibrium = true
+ @balanced = true
+ @has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
- trigger /^(\d+)h, (\d+)m (\w+)-/, :character_set_simple_stats
- trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_extended_stats
+ trigger /^(\d+)h, (\d+)m (\w+)-/, :set_simple_stats
+ trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :set_extended_stats
#Trigger off of when we use the SCORE command.
- trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
- trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
- trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
- trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
+ trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :set_total_health
+ trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :set_total_mana
+ trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :set_total_willpower
+ trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :set_total_endurance
#set the balance when it returns.
- trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
+ #trigger /^You have recovered balance on all limbs.$/, :is_balanced
#demonnic: set the equilibrium when it returns
- trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
+ #trigger /^You have recovered equilibrium.$/, :gained_equilibrium
#We use the prompt to tell us when we are unbalanced.
- trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
+ #trigger /^\d+h, \d+m\se-/, :is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
- trigger /You reach out and bop/, :character_is_unbalanced
+ #trigger /You reach out and bop/, :is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
- def character_set_simple_stats(match_object)
+ def set_simple_stats(match_object)
unless @using_extended_stats == true
- @character_current_health = match_object[1].to_i
- @character_current_mana = match_object[2].to_i
- @character_balanced = match_object[3].include("x")
- @character_has_equilibrium = match_object[3].include?("e")
+ @current_health = match_object[1].to_i
+ @current_mana = match_object[2].to_i
+ @balanced = match_object[3].include("x")
+ @has_equilibrium = match_object[3].include?("e")
debug("Character: Loaded Current Stats")
-
- set_kmuddy_variable("character_current_health", @character_current_health)
- set_kmuddy_variable("character_current_mana", @character_current_mana)
- set_kmuddy_variable("character_balanced", @character_balanced)
- set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
+ debug("Character: Sending Current Stats")
+ set_kmuddy_variable("character_current_health", @current_health)
+ set_kmuddy_variable("character_current_mana", @current_mana)
+ set_kmuddy_variable("character_balanced", @balanced)
+ set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
+
+ debug("Character: Sent Current Stats")
+
+ unless @total_health
+ send_kmuddy_command("qsc")
+ end
end
end
- def character_set_extended_stats(match_object)
- @character_current_health = match_object[1].to_i
- @character_current_mana = match_object[2].to_i
- @character_current_endurance = match_object[3].to_i
- @character_current_willpower = match_object[4].to_i
- @character_balanced = match_object[5].include?("x")
- @character_has_equilibrium = match_object[5].include?("e")
+ def set_extended_stats(match_object)
+ @current_health = match_object[1].to_i
+ @current_mana = match_object[2].to_i
+ @current_endurance = match_object[3].to_i
+ @current_willpower = match_object[4].to_i
+ @balanced = match_object[5].include?("x")
+ @has_equilibrium = match_object[5].include?("e")
+
debug("Character: Loaded Current Stats")
-
- set_kmuddy_variable("character_current_health", @character_current_health)
- set_kmuddy_variable("character_current_mana", @character_current_mana)
- set_kmuddy_variable("character_current_endurance", @character_current_endurance)
- set_kmuddy_variable("character_current_willpower", @character_current_willpower)
- set_kmuddy_variable("character_balanced", @character_balanced)
- set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
+ debug("Character: Sending Current Stats")
+
+ set_kmuddy_variable("character_current_health", @current_health)
+ set_kmuddy_variable("character_current_mana", @current_mana)
+ set_kmuddy_variable("character_current_endurance", @current_endurance)
+ set_kmuddy_variable("character_current_willpower", @current_willpower)
+ set_kmuddy_variable("character_balanced", @balanced)
+ set_kmuddy_variable("character_has_equilibrium", @has_equilibrium)
+
+ debug("Character: Sent Current Stats")
@using_extended_stats = true
+
+ unless @total_health
+ send_kmuddy_command("qsc")
+ end
end
- def character_set_total_health(match_object )
- @character_total_health = match_object[2].to_i
- @character_current_health = match_object[1].to_i
- set_kmuddy_variable("character_current_health", @character_current_health)
- set_kmuddy_variable("character_total_health", @character_total_health)
+ def set_total_health(match_object )
+ @total_health = match_object[2].to_i
+ @current_health = match_object[1].to_i
+ set_kmuddy_variable("character_current_health", @current_health)
+ set_kmuddy_variable("character_total_health", @total_health)
end
- def character_set_total_mana(match_object )
- @character_total_mana = match_object[2].to_i
- @character_current_mana = match_object[1].to_i
- set_kmuddy_variable("character_current_mana", @character_current_mana)
- set_kmuddy_variable("character_total_mana", @character_total_mana)
+ def set_total_mana(match_object )
+ @total_mana = match_object[2].to_i
+ @current_mana = match_object[1].to_i
+ set_kmuddy_variable("character_current_mana", @current_mana)
+ set_kmuddy_variable("character_total_mana", @total_mana)
end
- def character_set_total_endurance(match_object )
- @character_total_endurance = match_object[2].to_i
- @character_current_endurance = match_object[1].to_i
- set_kmuddy_variable("character_current_endurance", @character_current_endurance)
- set_kmuddy_variable("character_total_endurance", @character_total_endurance)
+ def set_total_endurance(match_object )
+ @total_endurance = match_object[2].to_i
+ @current_endurance = match_object[1].to_i
+ set_kmuddy_variable("character_current_endurance", @current_endurance)
+ set_kmuddy_variable("character_total_endurance", @total_endurance)
end
- def character_set_total_willpower(match_object )
- @character_total_willpower = match_object[2].to_i
- @character_current_willpower = match_object[1].to_i
- set_kmuddy_variable("character_current_willpower", @character_current_willpower)
- set_kmuddy_variable("character_total_willpower", @character_total_willpower)
+ def set_total_willpower(match_object )
+ @total_willpower = match_object[2].to_i
+ @current_willpower = match_object[1].to_i
+ set_kmuddy_variable("character_current_willpower", @current_willpower)
+ set_kmuddy_variable("character_total_willpower", @total_willpower)
end
- def character_is_balanced
- @character_balanced = true
+ def is_balanced
+ @balanced = true
end
- def character_is_unbalanced
- @character_balanced = false
+ def is_unbalanced
+ @balanced = false
end
- def character_has_equilibrium
- @character_has_equilibrium = true
+ def gained_equilibrium
+ @has_equilibrium = true
end
- def character_lost_equilibrium
- @character_has_equilibrium = false
+ def lost_equilibrium
+ @has_equilibrium = false
end
-end
-
-debug("Character: Character file required.")
\ No newline at end of file
+end
\ No newline at end of file
diff --git a/enabled-plugins/inscriber.rb b/enabled-plugins/inscriber.rb
index e06f4ea..ac0a51f 100644
--- a/enabled-plugins/inscriber.rb
+++ b/enabled-plugins/inscriber.rb
@@ -1,68 +1,73 @@
#Inscriber module for RMuddy triggering/aliasing system.
#Module to handle inscribing batches of tarot cards in Achaea
#Will make sure you only ever sip in between cards... still very rough
#draft.
-module Inscriber
+class Inscriber < BasePlugin
#we'll setup some accessor methods, weee
attr_accessor :number_to_inscribe
attr_accessor :type_to_inscribe
attr_accessor :inscribing
- def inscriber_setup
- #Let the user know it's loading...
- warn("RMuddy: Tarot Batch Inscription Module loading")
-
+ def setup
#setup our triggers for commands... will be deprecated when /notify works
trigger /ins (\d+) (\w+)/, :set_number_to_inscribe #command to set params
trigger /startins/, :should_we_inscribe? #command to go!
trigger /You have successfully inscribed/, :decrement_counter #we did it!
trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
#by default, we are not, in fact, inscribing
@inscribing = false
@number_to_inscribe = 0
@type_to_inscribe = 0
end
- def test_this
- #added to test /notify with a working module (stupid hermittracker)
- warn("testing...")
- end
-
- def set_number_to_inscribe (match_object ) #so we need to actually set the params
- @number_to_inscribe = match_object[1].to_i #so we match to the trigger
- @type_to_inscribe = match_object[2].to_s #and do it
- set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #and push back to kmuddy
+ def mass_inscribe(number_to_inscribe, type_to_inscribe)
+ @number_to_inscribe = number_to_inscribe.to_i
+ @type_to_inscribe = type_to_inscribe
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
+ warn("Inscriber Plugin: Ready to inscribe #{@number_to_inscribe} #{@type_to_inscribe}")
+ warn("Use begin_inscribing to start.")
end
+
+ def begin_inscribing
+ inscribe_tarot
+ end
+
+ #def set_number_to_inscribe (match_object ) #so we need to actually set the params
+ # @number_to_inscribe = match_object[1].to_i #so we match to the trigger
+ # @type_to_inscribe = match_object[2].to_s #and do it
+ # set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #and push back to kmuddy
+ # set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
+ #end
def inscribe_tarot #here's how we actually inscribe the bloody cards
- @inscribing = true #let everything know we are currently inscribing
- self::Sipper.should_i_sip? #check to see if we need mana before we inscribe
- self::Sipper.disable_sip #then disable the sipper so as not to kill our inscribe
+ disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
+ plugins[Sipper].should_i_sip? #check to see if we need mana before we inscribe
+ plugins[Sipper].disable #then disable the sipper so as not to kill our inscribe
send_kmuddy_command("inscribe blank with $type_to_inscribe") #and actually inscribe
end
def decrement_counter #lower the counter, so we inscribe the correct # of cards
- @inscribing = false #if it triggered into this, we've just finished one
@number_to_inscribe -= 1 #decrement counter
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
should_we_inscribe? #check if we should do another!
end
def out_of_mana! #pretty obvious
@inscribing = false #if we're out of mana, we're not inscribing
send_kmuddy_command("sip mana") #so we need to sip some mana
end
def should_we_inscribe? #test if we should inscribe
if @number_to_inscribe > 0 #if we still have inscription to do
inscribe_tarot #then inscribe
elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
+ disabled_plugins[Sipper].enable unless disabled_plugins[Sipper].nil?
send_kmuddy_command("ind 50 $type_to_inscribe") #put the cards away
- self::Sipper.should_i_sip? #check if we need to sip
+ plugins[Sipper].should_i_sip? #check if we need to sip
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index 03a76e9..15e0a45 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,148 +1,143 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
-module Ratter
- def ratter_setup
- warn("RMuddy: Room Ratter Plugin Loaded!")
+class Ratter < BasePlugin
+
+ attr_accessor :ratter_enabled, :balance_user, :attack_command, :available_rats
+ attr_accessor :inventory_rats, :rat_prices, :total_rat_money
+
+ def setup
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
- @balance_user = false
+ @balance_user = true
#What do we do when we want them dead?
- @attack_command = "warp rat"
+ @attack_command = "bop rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
trigger /Liirup the Placid stands here/, :sell_rats
#Reset the money after selling to the ratter in hashan.
trigger /Liirup squeals with delight/, :reset_money
+ trigger /You see exits/, :reset_available_rats
+ trigger /You see a single exit/, :reset_available_rats
+
#After we gain balance, we need to decide if we should attack again or not.
- if @balance_user
- after Character, :character_is_balanced, :should_i_attack_rat?
- else
- after Character, :character_has_equilibrium, :should_i_attack_rat?
- end
+ after Character, :set_simple_stats, :should_i_attack_rat?
+ after Character, :set_extended_stats, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
-
- #first make sure that we are balanced and there are rats available
- if @balance_user
- if rat_available? && @character_balanced
- send_kmuddy_command(@attack_command)
- end
- else
- if rat_available? && @character_has_equilibrium
- send_kmuddy_command(@attack_command)
- end
- end
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def enable_ratter
warn("RMuddy: Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("RMuddy: Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
+
+ def reset_available_rats
+ @available_rats = 0
+ end
+
def sell_rats
- if @ratter_enabled
- send_kmuddy_command("Sell rats to Liirup")
- end
+ send_kmuddy_command("Sell rats to Liirup")
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
- if rat_available? && @character_balanced
+ if rat_available? && plugins[Character].balanced
send_kmuddy_command(@attack_command)
end
else
- if rat_available? && @character_has_equilibrium
+ if rat_available? && plugins[Character].has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb
index 1850a4c..049ccfc 100644
--- a/enabled-plugins/sipper.rb
+++ b/enabled-plugins/sipper.rb
@@ -1,77 +1,73 @@
#The AutoSipper. It checks to see if a certain threshold percentage is hit for
#Health and Mana, and keeps your health/mana above that percentage.
#
#You will undoubtedly need to add exception triggers in to disable sipping,
#but right now it is customized for Tarot inscribing.
-module Sipper
+class Sipper < BasePlugin
+
+ attr_accessor :sipper_enabled
def sipper_enabled?
@sipper_enabled
end
#Check to make sure we are not below our health threshold
#We make sure to use floats! Since integers round ;)
def health_below_threshold?
- (@character_current_health.to_f / @character_total_health.to_f) * 100 < @health_threshold_percentage
+ (plugins[Character].current_health.to_f / plugins[Character].total_health.to_f) * 100 < @health_threshold_percentage
end
#Same as above
def mana_below_threshold?
- (@character_current_mana.to_f / @character_total_mana.to_f) * 100 < @mana_threshold_percentage
+ (plugins[Character].current_mana.to_f / plugins[Character].total_mana.to_f) * 100 < @mana_threshold_percentage
end
- def sipper_setup
- warn("RMuddy: Sipper Plugin Loaded!")
+ def setup
#By default, we want to be healed ;)
@sipper_enabled = true
#Our health and mana thresholds
@health_threshold_percentage = 70
- @mana_threshold_percentage = 40
+ @mana_threshold_percentage = 70
#After every time the character's current stats are updated, we check to see if we should sip.
- after Character, :character_set_simple_stats, :should_i_sip?
- after Character, :character_set_extended_stats, :should_i_sip?
+ after Character, :set_simple_stats, :should_i_sip?
+ after Character, :set_extended_stats, :should_i_sip?
#This group of triggers disables the sipping for various reasons.
trigger /^Your mind feels stronger and more alert\.$/, :disable_sip
trigger /^The elixer heals and soothes you\.$/, :disable_sip
trigger /^What is it that you wish to drink\?$/, :disable_sip
trigger /^You are asleep and can do nothing\./, :disable_sip
trigger /^The elixer flows down your throat without effect/, :disable_sip
- trigger /Wisely preparing yourself beforehand/, :sip_inscribe
+ trigger /Wisely preparing yourself beforehand/, :disable_sip
#This group of triggers, substantially smaller, enables the sipping when we can :)
- trigger /^You may drink another .*$/, :enable_sip
+ trigger /^You may drink another .*$/, :enable_sip
+ trigger /^You have successfully inscribed/, :enable_sip
end
#The heart of the plugin...
def should_i_sip?
- #If we don't have our total scores, issue a score and allow the Character plugin to update them.
- if @character_total_mana.nil? || @character_total_health.nil?
- send_kmuddy_command("score")
- else
+ #If we don't have our total scores, wait until character fills them in.
+ if plugins[Character].total_mana && plugins[Character].total_health
#Otherwise, begin checking health and mana to see if we need to do some drinking...
if health_below_threshold? && sipper_enabled?
send_kmuddy_command("drink health")
@sipper_enabled = false
end
if mana_below_threshold? && sipper_enabled?
send_kmuddy_command("drink mana")
@sipper_enabled = false
end
end
end
- def sip_inscribe
- @inscribing = true
- end
-
def disable_sip
@sipper_enabled = false
end
def enable_sip
@sipper_enabled = true
end
end
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index db6aa79..3753095 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,202 +1,203 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
-module Walker
- def walker_setup
- warn("RMuddy: Auto Walker Plugin Loaded!")
+class Walker < BasePlugin
+ attr_accessor :opposite_directions, :last_timer, :lost_or_not, :seconds_to_wait
+ attr_accessor :rail_position, :current_rail, :current_thread, :ratter_rail, :auto_walk_enabled
+ attr_accessor :back_tracking
+
+ def setup
warn("RMuddy: ***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("RMuddy: ***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#lost or not? Well, let's see
@lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
trigger /There is no exit in that direction/, :misguided
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
- #Wait until we pass our seconds to wait.
+ sleep 1
end
#If we can walk, walk!
- if @character_balanced && @character_has_equilibrium && @auto_walk_enabled
+ if plugins[Character].balanced && plugins[Character].has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("RMuddy: Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def disable_walker
warn("RMuddy: Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
def misguided
@lost_or_not += 1
if @lost_or_not < 3
@rail_position -= 2
else
lost!
end
end
def lost!
if @auto_walk_enabled == true
warn("RMuddy: Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
- if @ratter_enabled && @auto_walk_enabled
+ if plugins[Ratter].ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
- @available_rats = 0
-
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
sleep 0.3
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
diff --git a/init.rb b/init.rb
index c3de4b6..c35d9f5 100755
--- a/init.rb
+++ b/init.rb
@@ -1,21 +1,22 @@
#!/usr/bin/env ruby
DEBUG = false
Dir[File.join(File.dirname(__FILE__), "gems", "gems", "*")].each do |gem_folder|
$: << gem_folder + "/lib/"
end
require File.join(File.dirname(__FILE__), "connection_handler.rb")
+require File.join(File.dirname(__FILE__), "base_plugin.rb")
require File.join(File.dirname(__FILE__), "receiver.rb")
require 'yaml'
require "ruby2ruby"
debug("Starting Receiver...")
receiver = Receiver.new()
debug("Starting Connection Handler")
connection_handler = ConnectionHandler.new(receiver)
connection_handler.start
debug("Connection Handler Started")
\ No newline at end of file
diff --git a/receiver.rb b/receiver.rb
index f370625..6e16cc2 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,109 +1,139 @@
class Receiver
- attr_accessor :varsock, :matches, :setups, :queue
+ attr_accessor :varsock, :enabled_plugins, :disabled_plugins, :queue
+ def plugins
+ @enabled_plugins
+ end
+
debug("Receiver: Loading Files...")
-
+
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
- include module_eval(File.basename(file, ".rb").capitalize)
+ attr_accessor File.basename(file, ".rb").to_sym
end
def initialize
warn("RMuddy: System Loading...")
- @triggers = {}
- @setups = []
@queue = []
+ @enabled_plugins = []
+
+ class << @enabled_plugins
+ alias_method :original_indexer, :[]
+
+ def [](arg)
+ if arg.is_a?(Class)
+ each do |plugin|
+ if plugin.is_a?(arg)
+ return plugin
+ end
+ end
+
+ return nil
+ else
+ original_indexer(arg)
+ end
+ end
+ end
+
+ @disabled_plugins = []
+
+ class << @disabled_plugins
+ alias_method :original_indexer, :[]
+
+ def [](arg)
+ if arg.is_a?(Class)
+ each do |plugin|
+ if plugin.is_a?(arg)
+ return plugin
+ end
+ end
+
+ return nil
+ else
+ original_indexer(arg)
+ end
+ end
+ end
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
- @setups << File.basename(file, ".rb") + "_setup"
+ basename = File.basename(file, ".rb")
+ class_string = basename.split("_").each{|part| part.capitalize!}.join("")
+
+ instantiated_class = Object.module_eval(class_string).new(self)
+ instantiated_class.enable
end
- @setups.each {|setup_string| send(setup_string.to_sym)}
-
Thread.new do
while true do
if @queue.length > 0
element = @queue.shift
case element[0]
when "set_var"
@varsock.set(element[1], element[2])
when "send_command"
@varsock.command(element[1])
end
end
end
end
+ warn("=" * 80)
+ warn("You may send commands to RMuddy's plugins like so:")
+ warn("/notify 4567 PluginName action_name arg1 arg2 arg3")
+ warn("=" * 80)
+ warn("You may ask a plugin for help by doing:")
+ warn("/notify 4567 PluginName help")
+ warn("=" * 80)
warn("RMuddy: System Ready!")
end
def receive(text)
- @triggers.each_pair do |regex, method|
- debug("Testing #{regex} against line: #{text}")
- match = regex.match(text)
- unless match.nil?
- unless match[1].nil?
- send(method.to_sym, match)
+ @enabled_plugins.each do |klass|
+ klass.triggers.each_pair do |regex, method|
+ debug("Testing Plugin: #{klass.to_s}| Regex: #{regex} against line: #{text}")
+ match = regex.match(text)
+ unless match.nil?
+ debug("Match!")
+ unless match[1].nil?
+ klass.send(method.to_sym, match)
+ else
+ klass.send(method.to_sym)
+ end
else
- send(method.to_sym)
+ debug("No match!")
end
- else
- debug("No match!")
end
end
end
def command(text)
+ debug("RMuddy received notify command: #{text} ")
method_and_args = text.split(" ")
- klass = module_eval(method_and_args[0])
+
+ klass = Object.module_eval("#{method_and_args[0]}")
+
method_sym = method_and_args[1].to_sym
args = method_and_args[2..-1]
-
- debug("RMuddy: Sending to Plugin #{klass.name.to_s}::#{method_sym.to_s} with arguments #{args.join(", ")}")
- self::klass.send(method_sym, *args)
- end
-
- def trigger(regex, method)
- @triggers[regex] = method
- end
-
- def set_kmuddy_variable(variable_name, variable_value)
- @queue << ["set_var", variable_name, variable_value]
- end
-
- def get_kmuddy_variable(variable_name)
- @varsock.get(variable_name)
- end
-
- def send_kmuddy_command(command_text)
- @queue << ["send_command", command_text]
- end
-
- def before(module_name, method_symbol, hook_symbol)
- method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
-
- new_method = method.split("\n")
- new_method.insert(1, "send(:#{hook_symbol.to_s})")
-
- module_name.module_eval(new_method.join("\n"))
- end
-
- def after(module_name, method_symbol, hook_symbol)
- method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
-
- new_method = method.split("\n")
-
- new_method.insert(-2, "send(:#{hook_symbol.to_s})")
-
- module_name.module_eval(new_method.join("\n"))
- end
-
- def to_s
- "Receiver Loaded"
- end
-end
+ unless method_sym == :enable
+ @enabled_plugins.each do |plugin|
+ if plugin.is_a?(klass)
+ unless args.empty?
+ plugin.send(method_sym, *args)
+ else
+ plugin.send(method_sym)
+ end #args check
+ end #check the class of the plugin
+ end #loop through enabled plugins
+ else # Check to see if it's an enable command
+ @disabled_plugins.each do |plugin|
+ if plugin.is_a?(klass)
+ plugin.send(:enable)
+ end #check for class of the plugin
+ end #looping through the disabled plugins
+ end # end of check for :enable
+ end #end of Command method.
-
\ No newline at end of file
+end
\ No newline at end of file
|
KeithHanson/rmuddy
|
fbdc7f4f1da7bb62d83c7ee00553fa8138802ffb
|
Hermittracker still broken, cleaned up inscriber and sipper using direct method calls (self::Sipper:should_i_sip? and self::Sipper:disable_sip) instead of cludgy variable method... have not tested, will test tomorrow
|
diff --git a/connection_handler.rb b/connection_handler.rb
index 7b40c39..96bd984 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,45 +1,45 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
- $server_port = 5678
+ $server_port = 4567
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
@receiver.receive(line)
end
}
@threads << Thread.new {
while (event = @evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
@receiver.command(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
diff --git a/connection_handler.rb~ b/connection_handler.rb~
index f87e468..668408a 100755
--- a/connection_handler.rb~
+++ b/connection_handler.rb~
@@ -1,45 +1,45 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
- $server_port = 4567
+ $server_port = 5678
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
@receiver.receive(line)
end
}
@threads << Thread.new {
while (event = evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
@receiver.command(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
diff --git a/disabled-plugins/hermittracker.rb b/disabled-plugins/hermittracker.rb
index c725ead..946f06e 100644
--- a/disabled-plugins/hermittracker.rb
+++ b/disabled-plugins/hermittracker.rb
@@ -1,87 +1,90 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
module Hermittracker
def hermittracker_setup
#Setup our hermit tracker module... by default, there is no hermit, no key,
#we are not charging the tarot
@whichhermit = ''
@key = ''
@charginghermit = false
#Let the user know we're loading the hash
warn("Rmuddy: Loading hermit locations database")
- @hermithash = YAML.load(File.open("configs/hermithash.yaml"))
+ file = File.open("configs/hermithash.yaml")
+ @hermithash = YAML.load(file)
+ file.close
+ hermit_list
warn("Rmuddy: Hash loaded, database open, hermit away")
#trigger set, in RMuddy DSL, for when you check the hermit you are
#activating, when you've activated it, and to check when you charge a card
#if you've told RMuddy you're wanting to use a hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_hermit_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hermit_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
#Put all the hermits you happen to have in your inventory in a deck... this
#keeps the trigger for checking which hermit is being activated working
#cleanly
send_kmuddy_command("ind 50 hermit")
#all done! let the user know it's loaded up
warn("Rmuddy: Hermit Tracker loaded")
end
def test_this
#added to help test /notify capability of RMuddy
warn("Test passed!")
end
def activate_hermit(key)
if key == '' #If you don't provide us with what you want to call this room
warn("You must supply a word to associate this room with!!") #we tell you
else #about it
warn("Ok, activating a hermit for this room") #otherwise, we let you know
send_kmuddy_command("outd hermit") #take a card out
send_kmuddy_command("ii hermit") #inspect it
@key = key #set @key to equal the key
warn("Associating card @whichhermit with the place name @key") #notify
@hermithash[key] = @whichhermit #store the key=>card#### pair
send_kmuddy_command("activate hermit") #activate the hermit card
end
end
def set_hermit_value (match_object ) #this is to set @whichhermit when it is
@whichhermit = match_object[1] #inspected via ii, above
end
def save_hermit_hash #save our hash to the yaml file
File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
warn("Saved hermit tracker hash") #and let user know about it
end
def fling_hermit(key) #ok, we need to skedaddle
if key == '' #again, if you don't tell us where to go...
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else #otherwise
send_kmuddy_command("get @hermithash[key] from pac") #get the proper card
send_kmuddy_command("charge hermit") #and charge it
@charginghermit = true #let the script know we're trying to use a hermit card
end
end
def hermit_list #print out a list of keys from our hash... fairly simple
@hermithash.each_key { |key| warn("key") }
end
def hermit_drop #ACTUALLY fling the hermit card
if @charginghermit #but ONLY if we're actually charging a HERMIT
send_kmuddy_command("fling hermit at ground") #ok.. so do it
@charginghermit = false #and now we're not charging a hermit
@hermithash.delete("@key") #and we no longer have that card
end
end
end
\ No newline at end of file
diff --git a/disabled-plugins/hermittracker.rb~ b/disabled-plugins/hermittracker.rb~
index 7f1edbe..eb4cb01 100644
--- a/disabled-plugins/hermittracker.rb~
+++ b/disabled-plugins/hermittracker.rb~
@@ -1,67 +1,69 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
module Hermittracker
+
def hermittracker_setup
@whichhermit = ''
@key = ''
@charginghermit = false
warn("Rmuddy: Loading hermit locations database")
@hermithash = YAML.load(File.open("configs/hermithash.yaml"))
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_hermit_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hermit_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
warn("Rmuddy: Hermit Tracker loaded")
end
+
def test_this
warn("Test passed!")
end
def activate_hermit(key)
if key == ''
warn("You must supply a word to associate this room with!!")
else
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
@key = key
warn("Associating card @whichhermit with the place name @key")
@hermithash[key] = @whichhermit
send_kmuddy_command("activate hermit")
end
end
def set_hermit_value (match_object )
@whichhermit = match_object[1]
end
def save_hermit_hash
File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
warn("Saved hermit tracker hash")
end
def fling_hermit(key)
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get @hermithash[key] from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
def hermit_list
@hermithash.each_key { |key| warn("key") }
end
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete("@key")
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/inscriber.rb b/enabled-plugins/inscriber.rb
index 1d1e2bb..e06f4ea 100644
--- a/enabled-plugins/inscriber.rb
+++ b/enabled-plugins/inscriber.rb
@@ -1,64 +1,68 @@
#Inscriber module for RMuddy triggering/aliasing system.
#Module to handle inscribing batches of tarot cards in Achaea
#Will make sure you only ever sip in between cards... still very rough
#draft.
module Inscriber
+#we'll setup some accessor methods, weee
attr_accessor :number_to_inscribe
attr_accessor :type_to_inscribe
attr_accessor :inscribing
def inscriber_setup
- warn("RMuddy Tarot Batch Inscription Module loaded (module inscriber)")
- trigger /ins (\d+) (\w+)/, :set_number_to_inscribe
- trigger /startins/, :should_we_inscribe?
- trigger /You have successfully inscribed/, :decrement_counter
- trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana!
+ #Let the user know it's loading...
+ warn("RMuddy: Tarot Batch Inscription Module loading")
+
+ #setup our triggers for commands... will be deprecated when /notify works
+ trigger /ins (\d+) (\w+)/, :set_number_to_inscribe #command to set params
+ trigger /startins/, :should_we_inscribe? #command to go!
+ trigger /You have successfully inscribed/, :decrement_counter #we did it!
+ trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana! #oops, ran out of mana
#by default, we are not, in fact, inscribing
@inscribing = false
@number_to_inscribe = 0
@type_to_inscribe = 0
end
def test_this
+ #added to test /notify with a working module (stupid hermittracker)
warn("testing...")
end
- def set_number_to_inscribe (match_object )
- @number_to_inscribe = match_object[1].to_i
- @type_to_inscribe = match_object[2].to_s
- set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
+ def set_number_to_inscribe (match_object ) #so we need to actually set the params
+ @number_to_inscribe = match_object[1].to_i #so we match to the trigger
+ @type_to_inscribe = match_object[2].to_s #and do it
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #and push back to kmuddy
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
end
- def inscribe_tarot
- @inscribing = true
- if @character_current_mana < 350
- send_kmuddy_command("sip mana")
- end
- send_kmuddy_command("inscribe blank with $type_to_inscribe")
+ def inscribe_tarot #here's how we actually inscribe the bloody cards
+ @inscribing = true #let everything know we are currently inscribing
+ self::Sipper.should_i_sip? #check to see if we need mana before we inscribe
+ self::Sipper.disable_sip #then disable the sipper so as not to kill our inscribe
+ send_kmuddy_command("inscribe blank with $type_to_inscribe") #and actually inscribe
end
- def decrement_counter
- @inscribing = false
- @number_to_inscribe -= 1
- set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
- should_we_inscribe?
+ def decrement_counter #lower the counter, so we inscribe the correct # of cards
+ @inscribing = false #if it triggered into this, we've just finished one
+ @number_to_inscribe -= 1 #decrement counter
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe) #let kmuddy know
+ should_we_inscribe? #check if we should do another!
end
- def out_of_mana!
- @inscrbing = false
- send_kmuddy_command("sip mana")
+ def out_of_mana! #pretty obvious
+ @inscribing = false #if we're out of mana, we're not inscribing
+ send_kmuddy_command("sip mana") #so we need to sip some mana
end
- def should_we_inscribe?
- if @number_to_inscribe > 0
- inscribe_tarot
- elsif @number_to_inscribe == 0
- send_kmuddy_command("ind all $type_to_inscribe")
- send_kmuddy_command("sip mana")
+ def should_we_inscribe? #test if we should inscribe
+ if @number_to_inscribe > 0 #if we still have inscription to do
+ inscribe_tarot #then inscribe
+ elsif @number_to_inscribe == 0 #otherwise, if there are 0 left to do
+ send_kmuddy_command("ind 50 $type_to_inscribe") #put the cards away
+ self::Sipper.should_i_sip? #check if we need to sip
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb
index e11e992..1850a4c 100644
--- a/enabled-plugins/sipper.rb
+++ b/enabled-plugins/sipper.rb
@@ -1,77 +1,77 @@
#The AutoSipper. It checks to see if a certain threshold percentage is hit for
#Health and Mana, and keeps your health/mana above that percentage.
#
#You will undoubtedly need to add exception triggers in to disable sipping,
#but right now it is customized for Tarot inscribing.
module Sipper
def sipper_enabled?
@sipper_enabled
end
#Check to make sure we are not below our health threshold
#We make sure to use floats! Since integers round ;)
def health_below_threshold?
(@character_current_health.to_f / @character_total_health.to_f) * 100 < @health_threshold_percentage
end
#Same as above
def mana_below_threshold?
(@character_current_mana.to_f / @character_total_mana.to_f) * 100 < @mana_threshold_percentage
end
def sipper_setup
warn("RMuddy: Sipper Plugin Loaded!")
#By default, we want to be healed ;)
@sipper_enabled = true
#Our health and mana thresholds
@health_threshold_percentage = 70
@mana_threshold_percentage = 40
#After every time the character's current stats are updated, we check to see if we should sip.
after Character, :character_set_simple_stats, :should_i_sip?
after Character, :character_set_extended_stats, :should_i_sip?
#This group of triggers disables the sipping for various reasons.
trigger /^Your mind feels stronger and more alert\.$/, :disable_sip
trigger /^The elixer heals and soothes you\.$/, :disable_sip
trigger /^What is it that you wish to drink\?$/, :disable_sip
trigger /^You are asleep and can do nothing\./, :disable_sip
trigger /^The elixer flows down your throat without effect/, :disable_sip
trigger /Wisely preparing yourself beforehand/, :sip_inscribe
#This group of triggers, substantially smaller, enables the sipping when we can :)
trigger /^You may drink another .*$/, :enable_sip
end
#The heart of the plugin...
def should_i_sip?
#If we don't have our total scores, issue a score and allow the Character plugin to update them.
if @character_total_mana.nil? || @character_total_health.nil?
send_kmuddy_command("score")
- elsif !@inscribing
+ else
#Otherwise, begin checking health and mana to see if we need to do some drinking...
if health_below_threshold? && sipper_enabled?
send_kmuddy_command("drink health")
@sipper_enabled = false
end
if mana_below_threshold? && sipper_enabled?
send_kmuddy_command("drink mana")
@sipper_enabled = false
end
end
end
def sip_inscribe
@inscribing = true
end
def disable_sip
@sipper_enabled = false
end
def enable_sip
@sipper_enabled = true
end
end
diff --git a/init.rb~ b/init.rb~
index c3de4b6..c99ca40 100755
--- a/init.rb~
+++ b/init.rb~
@@ -1,21 +1,21 @@
#!/usr/bin/env ruby
-DEBUG = false
+DEBUG = true
Dir[File.join(File.dirname(__FILE__), "gems", "gems", "*")].each do |gem_folder|
$: << gem_folder + "/lib/"
end
require File.join(File.dirname(__FILE__), "connection_handler.rb")
require File.join(File.dirname(__FILE__), "receiver.rb")
require 'yaml'
require "ruby2ruby"
debug("Starting Receiver...")
receiver = Receiver.new()
debug("Starting Connection Handler")
connection_handler = ConnectionHandler.new(receiver)
connection_handler.start
debug("Connection Handler Started")
\ No newline at end of file
|
KeithHanson/rmuddy
|
d95bf2669b392b953a3be7c608eb17287e9a4f5f
|
Added comments to hermittracker plugin, in disabled-plugins directory In the hopes I can maybe find why it kills RMuddy altogether
|
diff --git a/disabled-plugins/hermittracker.rb b/disabled-plugins/hermittracker.rb
index eb4cb01..c725ead 100644
--- a/disabled-plugins/hermittracker.rb
+++ b/disabled-plugins/hermittracker.rb
@@ -1,69 +1,87 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
-#The tracker -should- automagically keep track of which card you charged, and
+#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
module Hermittracker
-
+
def hermittracker_setup
+
+ #Setup our hermit tracker module... by default, there is no hermit, no key,
+ #we are not charging the tarot
@whichhermit = ''
@key = ''
@charginghermit = false
+
+ #Let the user know we're loading the hash
warn("Rmuddy: Loading hermit locations database")
@hermithash = YAML.load(File.open("configs/hermithash.yaml"))
+ warn("Rmuddy: Hash loaded, database open, hermit away")
+
+ #trigger set, in RMuddy DSL, for when you check the hermit you are
+ #activating, when you've activated it, and to check when you charge a card
+ #if you've told RMuddy you're wanting to use a hermit
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_hermit_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hermit_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
+
+ #Put all the hermits you happen to have in your inventory in a deck... this
+ #keeps the trigger for checking which hermit is being activated working
+ #cleanly
send_kmuddy_command("ind 50 hermit")
+
+ #all done! let the user know it's loaded up
warn("Rmuddy: Hermit Tracker loaded")
end
-
+
def test_this
+ #added to help test /notify capability of RMuddy
warn("Test passed!")
end
-
+
def activate_hermit(key)
- if key == ''
- warn("You must supply a word to associate this room with!!")
- else
- warn("Ok, activating a hermit for this room")
- send_kmuddy_command("outd hermit")
- send_kmuddy_command("ii hermit")
- @key = key
- warn("Associating card @whichhermit with the place name @key")
- @hermithash[key] = @whichhermit
- send_kmuddy_command("activate hermit")
+ if key == '' #If you don't provide us with what you want to call this room
+ warn("You must supply a word to associate this room with!!") #we tell you
+ else #about it
+ warn("Ok, activating a hermit for this room") #otherwise, we let you know
+ send_kmuddy_command("outd hermit") #take a card out
+ send_kmuddy_command("ii hermit") #inspect it
+ @key = key #set @key to equal the key
+ warn("Associating card @whichhermit with the place name @key") #notify
+ @hermithash[key] = @whichhermit #store the key=>card#### pair
+ send_kmuddy_command("activate hermit") #activate the hermit card
end
end
-
- def set_hermit_value (match_object )
- @whichhermit = match_object[1]
+
+ def set_hermit_value (match_object ) #this is to set @whichhermit when it is
+ @whichhermit = match_object[1] #inspected via ii, above
end
-
- def save_hermit_hash
+
+ def save_hermit_hash #save our hash to the yaml file
File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
- warn("Saved hermit tracker hash")
+ warn("Saved hermit tracker hash") #and let user know about it
end
-
- def fling_hermit(key)
- if key == ''
+
+ def fling_hermit(key) #ok, we need to skedaddle
+ if key == '' #again, if you don't tell us where to go...
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
- else
- send_kmuddy_command("get @hermithash[key] from pack")
- send_kmuddy_command("charge hermit")
- @charginghermit = true
+ else #otherwise
+ send_kmuddy_command("get @hermithash[key] from pac") #get the proper card
+ send_kmuddy_command("charge hermit") #and charge it
+ @charginghermit = true #let the script know we're trying to use a hermit card
end
end
-
- def hermit_list
+
+ def hermit_list #print out a list of keys from our hash... fairly simple
@hermithash.each_key { |key| warn("key") }
end
-
- def hermit_drop
- if @charginghermit
- send_kmuddy_command("fling hermit at ground")
- @charginghermit = false
- @hermithash.delete("@key")
+
+ def hermit_drop #ACTUALLY fling the hermit card
+ if @charginghermit #but ONLY if we're actually charging a HERMIT
+ send_kmuddy_command("fling hermit at ground") #ok.. so do it
+ @charginghermit = false #and now we're not charging a hermit
+ @hermithash.delete("@key") #and we no longer have that card
end
end
+
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
f1769b3d7c54bba0dd2d2e7d46a1c5fff6e9800b
|
Keith tracked down the rabbit hole breaking /notify
|
diff --git a/connection_handler.rb b/connection_handler.rb
index 668408a..7b40c39 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,45 +1,45 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
$server_port = 5678
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
@receiver.receive(line)
end
}
@threads << Thread.new {
- while (event = evserver.accept)
+ while (event = @evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
@receiver.command(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
3f9a37ea622416320f0cefa97929dcb252e6ae84
|
Hermittracker broken, not sure why
|
diff --git a/configs/hermithash.yaml b/configs/hermithash.yaml
new file mode 100644
index 0000000..e69de29
diff --git a/configs/hermithash.yaml~ b/configs/hermithash.yaml~
new file mode 100644
index 0000000..4470507
--- /dev/null
+++ b/configs/hermithash.yaml~
@@ -0,0 +1 @@
+:placeholder: holdingplace
\ No newline at end of file
diff --git a/connection_handler.rb b/connection_handler.rb
index f87e468..668408a 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,45 +1,45 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
- $server_port = 4567
+ $server_port = 5678
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
@receiver.receive(line)
end
}
@threads << Thread.new {
while (event = evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
@receiver.command(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
diff --git a/connection_handler.rb~ b/connection_handler.rb~
new file mode 100755
index 0000000..f87e468
--- /dev/null
+++ b/connection_handler.rb~
@@ -0,0 +1,45 @@
+require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
+require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
+require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
+
+include KMuddy
+
+class ConnectionHandler
+ def initialize(receiver)
+ $server_port = 4567
+ debug("ConnectionHandler--Server Port: #{$server_port}")
+
+ @evserver = EventServer.new($server_port)
+ @varsock = VariableSock.new()
+ @threads = [ ]
+
+ @receiver = receiver
+ @receiver.varsock = @varsock
+ debug("ConnectionHandler--Receiver: #{@receiver}")
+ end
+
+ def start
+ @threads << Thread.new {
+ while line = STDIN.gets.chomp
+ # Normally one would parse the line of text from the server here.
+ # Instead, I demonstrate the 'set' method of the VariableSock.
+ # Check your variables in KMuddy after you receive text from the
+ # mud.
+ @receiver.receive(line)
+ end
+ }
+
+ @threads << Thread.new {
+ while (event = evserver.accept)
+ line = event.gets.chomp
+ debug("Received Line: #{line}") unless line.empty?
+ exit(0) if line == "quit"
+ #varsock.command(line)
+ @receiver.command(line)
+ event.close
+ end
+}
+
+ @threads.each { |task| task.join }
+ end
+end
\ No newline at end of file
diff --git a/disabled-plugins/hermittracker.rb b/disabled-plugins/hermittracker.rb
new file mode 100644
index 0000000..eb4cb01
--- /dev/null
+++ b/disabled-plugins/hermittracker.rb
@@ -0,0 +1,69 @@
+#Module for tracking where you have charged Hermit tarot cards in achaea
+#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
+# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
+#The tracker -should- automagically keep track of which card you charged, and
+#where, and get it from your pack.
+module Hermittracker
+
+ def hermittracker_setup
+ @whichhermit = ''
+ @key = ''
+ @charginghermit = false
+ warn("Rmuddy: Loading hermit locations database")
+ @hermithash = YAML.load(File.open("configs/hermithash.yaml"))
+ trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_hermit_value
+ trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hermit_hash
+ trigger /^The card begins to glow with a mystic energy/, :hermit_drop
+ send_kmuddy_command("ind 50 hermit")
+ warn("Rmuddy: Hermit Tracker loaded")
+ end
+
+ def test_this
+ warn("Test passed!")
+ end
+
+ def activate_hermit(key)
+ if key == ''
+ warn("You must supply a word to associate this room with!!")
+ else
+ warn("Ok, activating a hermit for this room")
+ send_kmuddy_command("outd hermit")
+ send_kmuddy_command("ii hermit")
+ @key = key
+ warn("Associating card @whichhermit with the place name @key")
+ @hermithash[key] = @whichhermit
+ send_kmuddy_command("activate hermit")
+ end
+ end
+
+ def set_hermit_value (match_object )
+ @whichhermit = match_object[1]
+ end
+
+ def save_hermit_hash
+ File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
+ warn("Saved hermit tracker hash")
+ end
+
+ def fling_hermit(key)
+ if key == ''
+ warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
+ else
+ send_kmuddy_command("get @hermithash[key] from pack")
+ send_kmuddy_command("charge hermit")
+ @charginghermit = true
+ end
+ end
+
+ def hermit_list
+ @hermithash.each_key { |key| warn("key") }
+ end
+
+ def hermit_drop
+ if @charginghermit
+ send_kmuddy_command("fling hermit at ground")
+ @charginghermit = false
+ @hermithash.delete("@key")
+ end
+ end
+end
\ No newline at end of file
diff --git a/disabled-plugins/hermittracker.rb~ b/disabled-plugins/hermittracker.rb~
new file mode 100644
index 0000000..7f1edbe
--- /dev/null
+++ b/disabled-plugins/hermittracker.rb~
@@ -0,0 +1,67 @@
+#Module for tracking where you have charged Hermit tarot cards in achaea
+#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
+# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
+#The tracker -should- automagically keep track of which card you charged, and
+#where, and get it from your pack.
+module Hermittracker
+ def hermittracker_setup
+ @whichhermit = ''
+ @key = ''
+ @charginghermit = false
+ warn("Rmuddy: Loading hermit locations database")
+ @hermithash = YAML.load(File.open("configs/hermithash.yaml"))
+ trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_hermit_value
+ trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hermit_hash
+ trigger /^The card begins to glow with a mystic energy/, :hermit_drop
+ send_kmuddy_command("ind 50 hermit")
+ warn("Rmuddy: Hermit Tracker loaded")
+ end
+ def test_this
+ warn("Test passed!")
+ end
+
+ def activate_hermit(key)
+ if key == ''
+ warn("You must supply a word to associate this room with!!")
+ else
+ warn("Ok, activating a hermit for this room")
+ send_kmuddy_command("outd hermit")
+ send_kmuddy_command("ii hermit")
+ @key = key
+ warn("Associating card @whichhermit with the place name @key")
+ @hermithash[key] = @whichhermit
+ send_kmuddy_command("activate hermit")
+ end
+ end
+
+ def set_hermit_value (match_object )
+ @whichhermit = match_object[1]
+ end
+
+ def save_hermit_hash
+ File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
+ warn("Saved hermit tracker hash")
+ end
+
+ def fling_hermit(key)
+ if key == ''
+ warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
+ else
+ send_kmuddy_command("get @hermithash[key] from pack")
+ send_kmuddy_command("charge hermit")
+ @charginghermit = true
+ end
+ end
+
+ def hermit_list
+ @hermithash.each_key { |key| warn("key") }
+ end
+
+ def hermit_drop
+ if @charginghermit
+ send_kmuddy_command("fling hermit at ground")
+ @charginghermit = false
+ @hermithash.delete("@key")
+ end
+ end
+end
\ No newline at end of file
diff --git a/enabled-plugins/inscriber.rb b/enabled-plugins/inscriber.rb
index 5437c49..1d1e2bb 100644
--- a/enabled-plugins/inscriber.rb
+++ b/enabled-plugins/inscriber.rb
@@ -1,60 +1,64 @@
#Inscriber module for RMuddy triggering/aliasing system.
#Module to handle inscribing batches of tarot cards in Achaea
#Will make sure you only ever sip in between cards... still very rough
#draft.
module Inscriber
attr_accessor :number_to_inscribe
attr_accessor :type_to_inscribe
attr_accessor :inscribing
def inscriber_setup
warn("RMuddy Tarot Batch Inscription Module loaded (module inscriber)")
trigger /ins (\d+) (\w+)/, :set_number_to_inscribe
trigger /startins/, :should_we_inscribe?
trigger /You have successfully inscribed/, :decrement_counter
trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana!
#by default, we are not, in fact, inscribing
@inscribing = false
@number_to_inscribe = 0
@type_to_inscribe = 0
end
+ def test_this
+ warn("testing...")
+ end
+
def set_number_to_inscribe (match_object )
@number_to_inscribe = match_object[1].to_i
@type_to_inscribe = match_object[2].to_s
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
end
def inscribe_tarot
@inscribing = true
if @character_current_mana < 350
send_kmuddy_command("sip mana")
end
send_kmuddy_command("inscribe blank with $type_to_inscribe")
end
def decrement_counter
@inscribing = false
@number_to_inscribe -= 1
set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
should_we_inscribe?
end
def out_of_mana!
@inscrbing = false
send_kmuddy_command("sip mana")
end
def should_we_inscribe?
if @number_to_inscribe > 0
inscribe_tarot
elsif @number_to_inscribe == 0
send_kmuddy_command("ind all $type_to_inscribe")
send_kmuddy_command("sip mana")
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/inscriber.rb~ b/enabled-plugins/inscriber.rb~
new file mode 100644
index 0000000..5437c49
--- /dev/null
+++ b/enabled-plugins/inscriber.rb~
@@ -0,0 +1,60 @@
+#Inscriber module for RMuddy triggering/aliasing system.
+#Module to handle inscribing batches of tarot cards in Achaea
+#Will make sure you only ever sip in between cards... still very rough
+#draft.
+
+module Inscriber
+attr_accessor :number_to_inscribe
+attr_accessor :type_to_inscribe
+attr_accessor :inscribing
+
+
+ def inscriber_setup
+ warn("RMuddy Tarot Batch Inscription Module loaded (module inscriber)")
+ trigger /ins (\d+) (\w+)/, :set_number_to_inscribe
+ trigger /startins/, :should_we_inscribe?
+ trigger /You have successfully inscribed/, :decrement_counter
+ trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana!
+
+ #by default, we are not, in fact, inscribing
+ @inscribing = false
+ @number_to_inscribe = 0
+ @type_to_inscribe = 0
+ end
+
+ def set_number_to_inscribe (match_object )
+ @number_to_inscribe = match_object[1].to_i
+ @type_to_inscribe = match_object[2].to_s
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
+ set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
+ end
+
+ def inscribe_tarot
+ @inscribing = true
+ if @character_current_mana < 350
+ send_kmuddy_command("sip mana")
+ end
+ send_kmuddy_command("inscribe blank with $type_to_inscribe")
+ end
+
+ def decrement_counter
+ @inscribing = false
+ @number_to_inscribe -= 1
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
+ should_we_inscribe?
+ end
+
+ def out_of_mana!
+ @inscrbing = false
+ send_kmuddy_command("sip mana")
+ end
+
+ def should_we_inscribe?
+ if @number_to_inscribe > 0
+ inscribe_tarot
+ elsif @number_to_inscribe == 0
+ send_kmuddy_command("ind all $type_to_inscribe")
+ send_kmuddy_command("sip mana")
+ end
+ end
+end
\ No newline at end of file
diff --git a/init.rb b/init.rb
index c3de4b6..c99ca40 100755
--- a/init.rb
+++ b/init.rb
@@ -1,21 +1,21 @@
#!/usr/bin/env ruby
-DEBUG = false
+DEBUG = true
Dir[File.join(File.dirname(__FILE__), "gems", "gems", "*")].each do |gem_folder|
$: << gem_folder + "/lib/"
end
require File.join(File.dirname(__FILE__), "connection_handler.rb")
require File.join(File.dirname(__FILE__), "receiver.rb")
require 'yaml'
require "ruby2ruby"
debug("Starting Receiver...")
receiver = Receiver.new()
debug("Starting Connection Handler")
connection_handler = ConnectionHandler.new(receiver)
connection_handler.start
debug("Connection Handler Started")
\ No newline at end of file
diff --git a/init.rb~ b/init.rb~
new file mode 100755
index 0000000..c3de4b6
--- /dev/null
+++ b/init.rb~
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+DEBUG = false
+
+Dir[File.join(File.dirname(__FILE__), "gems", "gems", "*")].each do |gem_folder|
+ $: << gem_folder + "/lib/"
+end
+
+require File.join(File.dirname(__FILE__), "connection_handler.rb")
+require File.join(File.dirname(__FILE__), "receiver.rb")
+require 'yaml'
+require "ruby2ruby"
+
+debug("Starting Receiver...")
+receiver = Receiver.new()
+
+debug("Starting Connection Handler")
+connection_handler = ConnectionHandler.new(receiver)
+
+connection_handler.start
+debug("Connection Handler Started")
\ No newline at end of file
|
KeithHanson/rmuddy
|
9c004ac6c82275fcd0515810d5b9f7b551efada1
|
More hermity stuff... namely, a command to print a list of all places you have in your hash of hermits. mmmm, hermit hash and eggs.
|
diff --git a/enabled-plugins/hermittracker.rb b/enabled-plugins/hermittracker.rb
index b634222..2f2b9ac 100644
--- a/enabled-plugins/hermittracker.rb
+++ b/enabled-plugins/hermittracker.rb
@@ -1,60 +1,64 @@
#Module for tracking where you have charged Hermit tarot cards in achaea
#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
#The tracker -should- automagically keep track of which card you charged, and
#where, and get it from your pack.
module Hermittracker
def hermittracker_setup
@whichhermit = ''
@key = ''
@charginghermit = false
warn("Loading hermit locations database")
@hermithash = YAML.load(File.open("configs/hermithash.yaml"))
trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
trigger /^The card begins to glow with a mystic energy/, :hermit_drop
send_kmuddy_command("ind 50 hermit")
warn("Hermit Tracker loaded")
end
def activate_hermit(key)
if key == ''
warn("You must supply a word to associate this room with!!")
else
warn("Ok, activating a hermit for this room")
send_kmuddy_command("outd hermit")
send_kmuddy_command("ii hermit")
@key = key
warn("Associating card @whichhermit with the place name @key")
@hermithash[key] = @whichhermit
send_kmuddy_command("activate hermit")
end
end
def set_value(match_object )
@whichhermit = match_object[1]
end
def save_hash
File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
warn("Saved hermit tracker hash")
end
def fling_hermit(key)
if key == ''
warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
else
send_kmuddy_command("get @hermithash[key] from pack")
send_kmuddy_command("charge hermit")
@charginghermit = true
end
end
+ def hermit_list
+ @hermithash.each_key { |key| puts key }
+ end
+
def hermit_drop
if @charginghermit
send_kmuddy_command("fling hermit at ground")
@charginghermit = false
@hermithash.delete("@key")
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
da7c56b224c84411e470ba6cad77104c12c7ecb8
|
First version of Hermittracker This should, if the notify support is functioning, help you to keep track of which hermit cards go where. It uses a hash database, and save the information to a yaml document for use between sessions.
|
diff --git a/enabled-plugins/hermittracker.rb b/enabled-plugins/hermittracker.rb
new file mode 100644
index 0000000..b634222
--- /dev/null
+++ b/enabled-plugins/hermittracker.rb
@@ -0,0 +1,60 @@
+#Module for tracking where you have charged Hermit tarot cards in achaea
+#USAGE: /notify 4567 Hermittracker activate_hermit <word to associate room with>
+# /notify 4567 Hermittracker fling_hermit <word you tagged the room you want to go to with>
+#The tracker -should- automagically keep track of which card you charged, and
+#where, and get it from your pack.
+module Hermittracker
+ def hermittracker_setup
+ @whichhermit = ''
+ @key = ''
+ @charginghermit = false
+ warn("Loading hermit locations database")
+ @hermithash = YAML.load(File.open("configs/hermithash.yaml"))
+ trigger /card(\d+)\s+a tarot card inscribed with the Hermit/, :set_value
+ trigger /You take the Hermit tarot and rub it vigorously on the ground/, :save_hash
+ trigger /^The card begins to glow with a mystic energy/, :hermit_drop
+ send_kmuddy_command("ind 50 hermit")
+ warn("Hermit Tracker loaded")
+ end
+
+ def activate_hermit(key)
+ if key == ''
+ warn("You must supply a word to associate this room with!!")
+ else
+ warn("Ok, activating a hermit for this room")
+ send_kmuddy_command("outd hermit")
+ send_kmuddy_command("ii hermit")
+ @key = key
+ warn("Associating card @whichhermit with the place name @key")
+ @hermithash[key] = @whichhermit
+ send_kmuddy_command("activate hermit")
+ end
+ end
+
+ def set_value(match_object )
+ @whichhermit = match_object[1]
+ end
+
+ def save_hash
+ File.open("configs/hermithash.yaml", "w") {|f| YAML.dump(@hermithash, f)}
+ warn("Saved hermit tracker hash")
+ end
+
+ def fling_hermit(key)
+ if key == ''
+ warn("Come now, you have to tell me where to go! Specify a hermit to fling!")
+ else
+ send_kmuddy_command("get @hermithash[key] from pack")
+ send_kmuddy_command("charge hermit")
+ @charginghermit = true
+ end
+ end
+
+ def hermit_drop
+ if @charginghermit
+ send_kmuddy_command("fling hermit at ground")
+ @charginghermit = false
+ @hermithash.delete("@key")
+ end
+ end
+end
\ No newline at end of file
|
KeithHanson/rmuddy
|
f4bd2af236ff6cfbf266276e05854b3201c77157
|
Fixed small issue with the new /notify handler... namely, a forgotten @
|
diff --git a/connection_handler.rb b/connection_handler.rb
index 03cff1f..71cdb9c 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,45 +1,45 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
$server_port = 4567
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
@receiver.receive(line)
end
}
- threads << Thread.new {
+ @threads << Thread.new {
while (event = evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
@receiver.receive(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
1c13275340491bdb097e17b933173b35840ca708
|
Tweaked. Sorry for the gnashing of teeth that caused.
|
diff --git a/connection_handler.rb b/connection_handler.rb
index 03cff1f..c0fd9a0 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,45 +1,45 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
$server_port = 4567
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
while line = STDIN.gets.chomp
# Normally one would parse the line of text from the server here.
# Instead, I demonstrate the 'set' method of the VariableSock.
# Check your variables in KMuddy after you receive text from the
# mud.
@receiver.receive(line)
end
}
threads << Thread.new {
while (event = evserver.accept)
line = event.gets.chomp
debug("Received Line: #{line}") unless line.empty?
exit(0) if line == "quit"
#varsock.command(line)
- @receiver.receive(line)
+ @receiver.command(line)
event.close
end
}
@threads.each { |task| task.join }
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
6ab5ba5d72c1d1b8b3071e2d891be20fcf0a5ea8
|
Modified the /notify to receive Plugin method_name arg1 arg2
|
diff --git a/receiver.rb b/receiver.rb
index fc46a5b..f370625 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,99 +1,109 @@
class Receiver
attr_accessor :varsock, :matches, :setups, :queue
debug("Receiver: Loading Files...")
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
include module_eval(File.basename(file, ".rb").capitalize)
end
def initialize
warn("RMuddy: System Loading...")
@triggers = {}
@setups = []
@queue = []
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
@setups << File.basename(file, ".rb") + "_setup"
end
@setups.each {|setup_string| send(setup_string.to_sym)}
Thread.new do
while true do
if @queue.length > 0
element = @queue.shift
case element[0]
when "set_var"
@varsock.set(element[1], element[2])
when "send_command"
@varsock.command(element[1])
end
end
end
end
warn("RMuddy: System Ready!")
end
def receive(text)
@triggers.each_pair do |regex, method|
debug("Testing #{regex} against line: #{text}")
match = regex.match(text)
unless match.nil?
unless match[1].nil?
send(method.to_sym, match)
else
send(method.to_sym)
end
else
debug("No match!")
end
end
end
+
+ def command(text)
+ method_and_args = text.split(" ")
+ klass = module_eval(method_and_args[0])
+ method_sym = method_and_args[1].to_sym
+ args = method_and_args[2..-1]
+
+ debug("RMuddy: Sending to Plugin #{klass.name.to_s}::#{method_sym.to_s} with arguments #{args.join(", ")}")
+ self::klass.send(method_sym, *args)
+ end
def trigger(regex, method)
@triggers[regex] = method
end
def set_kmuddy_variable(variable_name, variable_value)
@queue << ["set_var", variable_name, variable_value]
end
def get_kmuddy_variable(variable_name)
@varsock.get(variable_name)
end
def send_kmuddy_command(command_text)
@queue << ["send_command", command_text]
end
def before(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(1, "send(:#{hook_symbol.to_s})")
module_name.module_eval(new_method.join("\n"))
end
def after(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(-2, "send(:#{hook_symbol.to_s})")
module_name.module_eval(new_method.join("\n"))
end
def to_s
"Receiver Loaded"
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
fd915714c0c24fcd8dc78e64249951cb62abba5a
|
Added batch inscription module, inscriber.rb Works with autosipper sipper.rb Much gnashing of teeth, but has successfully completed batches of up to 10 cards
|
diff --git a/enabled-plugins/inscriber.rb b/enabled-plugins/inscriber.rb
new file mode 100644
index 0000000..5437c49
--- /dev/null
+++ b/enabled-plugins/inscriber.rb
@@ -0,0 +1,60 @@
+#Inscriber module for RMuddy triggering/aliasing system.
+#Module to handle inscribing batches of tarot cards in Achaea
+#Will make sure you only ever sip in between cards... still very rough
+#draft.
+
+module Inscriber
+attr_accessor :number_to_inscribe
+attr_accessor :type_to_inscribe
+attr_accessor :inscribing
+
+
+ def inscriber_setup
+ warn("RMuddy Tarot Batch Inscription Module loaded (module inscriber)")
+ trigger /ins (\d+) (\w+)/, :set_number_to_inscribe
+ trigger /startins/, :should_we_inscribe?
+ trigger /You have successfully inscribed/, :decrement_counter
+ trigger /^You lack the mental resources to etch a Tarot card./, :out_of_mana!
+
+ #by default, we are not, in fact, inscribing
+ @inscribing = false
+ @number_to_inscribe = 0
+ @type_to_inscribe = 0
+ end
+
+ def set_number_to_inscribe (match_object )
+ @number_to_inscribe = match_object[1].to_i
+ @type_to_inscribe = match_object[2].to_s
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
+ set_kmuddy_variable("type_to_inscribe", @type_to_inscribe)
+ end
+
+ def inscribe_tarot
+ @inscribing = true
+ if @character_current_mana < 350
+ send_kmuddy_command("sip mana")
+ end
+ send_kmuddy_command("inscribe blank with $type_to_inscribe")
+ end
+
+ def decrement_counter
+ @inscribing = false
+ @number_to_inscribe -= 1
+ set_kmuddy_variable("number_to_inscribe", @number_to_inscribe)
+ should_we_inscribe?
+ end
+
+ def out_of_mana!
+ @inscrbing = false
+ send_kmuddy_command("sip mana")
+ end
+
+ def should_we_inscribe?
+ if @number_to_inscribe > 0
+ inscribe_tarot
+ elsif @number_to_inscribe == 0
+ send_kmuddy_command("ind all $type_to_inscribe")
+ send_kmuddy_command("sip mana")
+ end
+ end
+end
\ No newline at end of file
diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb
index bfa93b4..e11e992 100644
--- a/enabled-plugins/sipper.rb
+++ b/enabled-plugins/sipper.rb
@@ -1,76 +1,77 @@
#The AutoSipper. It checks to see if a certain threshold percentage is hit for
#Health and Mana, and keeps your health/mana above that percentage.
#
#You will undoubtedly need to add exception triggers in to disable sipping,
#but right now it is customized for Tarot inscribing.
module Sipper
def sipper_enabled?
@sipper_enabled
end
#Check to make sure we are not below our health threshold
#We make sure to use floats! Since integers round ;)
def health_below_threshold?
(@character_current_health.to_f / @character_total_health.to_f) * 100 < @health_threshold_percentage
end
#Same as above
def mana_below_threshold?
(@character_current_mana.to_f / @character_total_mana.to_f) * 100 < @mana_threshold_percentage
end
def sipper_setup
warn("RMuddy: Sipper Plugin Loaded!")
#By default, we want to be healed ;)
@sipper_enabled = true
#Our health and mana thresholds
@health_threshold_percentage = 70
- @mana_threshold_percentage = 70
+ @mana_threshold_percentage = 40
#After every time the character's current stats are updated, we check to see if we should sip.
after Character, :character_set_simple_stats, :should_i_sip?
after Character, :character_set_extended_stats, :should_i_sip?
#This group of triggers disables the sipping for various reasons.
trigger /^Your mind feels stronger and more alert\.$/, :disable_sip
trigger /^The elixer heals and soothes you\.$/, :disable_sip
trigger /^What is it that you wish to drink\?$/, :disable_sip
trigger /^You are asleep and can do nothing\./, :disable_sip
trigger /^The elixer flows down your throat without effect/, :disable_sip
- trigger /Wisely preparing yourself beforehand/, :disable_sip
+ trigger /Wisely preparing yourself beforehand/, :sip_inscribe
#This group of triggers, substantially smaller, enables the sipping when we can :)
trigger /^You may drink another .*$/, :enable_sip
- trigger /You have successfully inscribed the image/, :enable_sip
end
#The heart of the plugin...
def should_i_sip?
#If we don't have our total scores, issue a score and allow the Character plugin to update them.
if @character_total_mana.nil? || @character_total_health.nil?
send_kmuddy_command("score")
- else
-
+ elsif !@inscribing
#Otherwise, begin checking health and mana to see if we need to do some drinking...
if health_below_threshold? && sipper_enabled?
send_kmuddy_command("drink health")
@sipper_enabled = false
end
-
if mana_below_threshold? && sipper_enabled?
send_kmuddy_command("drink mana")
@sipper_enabled = false
end
end
end
+ def sip_inscribe
+ @inscribing = true
+ end
+
def disable_sip
@sipper_enabled = false
end
def enable_sip
@sipper_enabled = true
end
end
|
KeithHanson/rmuddy
|
143cec86500e067413ac7939145bbe83ffeb5093
|
Added support for /notify
|
diff --git a/connection_handler.rb b/connection_handler.rb
index efd078c..03cff1f 100755
--- a/connection_handler.rb
+++ b/connection_handler.rb
@@ -1,34 +1,45 @@
require File.join(File.dirname(__FILE__), "kmuddy", 'kmuddy.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'eventserver.rb')
require File.join(File.dirname(__FILE__), "kmuddy", 'variablesock.rb')
include KMuddy
class ConnectionHandler
def initialize(receiver)
$server_port = 4567
debug("ConnectionHandler--Server Port: #{$server_port}")
@evserver = EventServer.new($server_port)
@varsock = VariableSock.new()
@threads = [ ]
@receiver = receiver
@receiver.varsock = @varsock
debug("ConnectionHandler--Receiver: #{@receiver}")
end
def start
@threads << Thread.new {
- while line = STDIN.gets.chomp
- # Normally one would parse the line of text from the server here.
- # Instead, I demonstrate the 'set' method of the VariableSock.
- # Check your variables in KMuddy after you receive text from the
- # mud.
- @receiver.receive(line)
- end
+ while line = STDIN.gets.chomp
+ # Normally one would parse the line of text from the server here.
+ # Instead, I demonstrate the 'set' method of the VariableSock.
+ # Check your variables in KMuddy after you receive text from the
+ # mud.
+ @receiver.receive(line)
+ end
}
+ threads << Thread.new {
+ while (event = evserver.accept)
+ line = event.gets.chomp
+ debug("Received Line: #{line}") unless line.empty?
+ exit(0) if line == "quit"
+ #varsock.command(line)
+ @receiver.receive(line)
+ event.close
+ end
+}
+
@threads.each { |task| task.join }
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
de05bc14ade258495409ca9a0b015a235d2822eb
|
Added the misguided step to walker.rb... to try and find yourself if you're lost.
|
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index 20956ff..03a76e9 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,146 +1,148 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
module Ratter
def ratter_setup
warn("RMuddy: Room Ratter Plugin Loaded!")
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
@balance_user = false
#What do we do when we want them dead?
@attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
#sell your rats when you come into the room Liirup is in!
trigger /Liirup the Placid stands here/, :sell_rats
#Reset the money after selling to the ratter in hashan.
trigger /Liirup squeals with delight/, :reset_money
#After we gain balance, we need to decide if we should attack again or not.
if @balance_user
after Character, :character_is_balanced, :should_i_attack_rat?
else
after Character, :character_has_equilibrium, :should_i_attack_rat?
end
end
def ratter_enabled?
@ratter_enabled
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
#first make sure that we are balanced and there are rats available
if @balance_user
if rat_available? && @character_balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && @character_has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def enable_ratter
warn("RMuddy: Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("RMuddy: Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
send_kmuddy_command("put sovereigns in pack")
end
def sell_rats
- send_kmuddy_command("Sell rats to Liirup")
+ if @ratter_enabled
+ send_kmuddy_command("Sell rats to Liirup")
+ end
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && @character_balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && @character_has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index d2c3ef5..db6aa79 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,191 +1,202 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
module Walker
def walker_setup
warn("RMuddy: Auto Walker Plugin Loaded!")
warn("RMuddy: ***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("RMuddy: ***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
-
+
+ #lost or not? Well, let's see
+ @lost_or_not = 0
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
- trigger /There is no exit in that direction/, :lost!
+ trigger /There is no exit in that direction/, :misguided
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
#Wait until we pass our seconds to wait.
end
#If we can walk, walk!
if @character_balanced && @character_has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("RMuddy: Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def disable_walker
warn("RMuddy: Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
+ def misguided
+ @lost_or_not += 1
+ if @lost_or_not < 3
+ @rail_position -= 2
+ else
+ lost!
+ end
+ end
+
def lost!
if @auto_walk_enabled == true
warn("RMuddy: Auto Walker is LOST! Disabling.")
@auto_walk_enabled = false
end
end
def increment_rail_position
if @ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
@available_rats = 0
backtrack
end
def backtrack
if @backtracking
warn("We're backtracking")
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
disable_walker
end
if @rail_position > 0
@rail_position -= 1
sleep 0.3
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
3ea85c218b3dd1b7479845ec99d2a24fdf43d238
|
Small mods to ratter.rb to make it even more automated. Set the auto-ratter to sell rats to Liirup when you walk into the room she is in. Also set it to automagically put sovereigns in your pack when you are paid as part of the reset_money method.
|
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index 3404e6e..20956ff 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,140 +1,146 @@
#The Ratter plugin is, essentially, a one room auto-ratter.
#It keeps track of the rats in your inventory, as well as how much you have earned so far.
#It will send these variables on to kmuddy as the following variables,
#so you can make status variables or guages or what have you
# current_rat_count (Total rats collected so far)
# total_rat_money (Total money you will earn after selling the rats)
#This has currently been customized for the Jester class and for ratting in Hashani.
#Further configurability to come.
module Ratter
def ratter_setup
warn("RMuddy: Room Ratter Plugin Loaded!")
#By default, we will disable the ratter.
@ratter_enabled = false
#This determines if we're a balance user or an equilibrium user...
- @balance_user = true
+ @balance_user = false
#What do we do when we want them dead?
- @attack_command = "bop rat"
+ @attack_command = "warp rat"
#Set the current room's rats to 0
@available_rats = 0
#Set the inventory's rats to 0
@inventory_rats = 0
#Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
#Total money collected so far.
@total_rat_money = 0
#This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
#Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
#Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
#disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
+ #sell your rats when you come into the room Liirup is in!
+ trigger /Liirup the Placid stands here/, :sell_rats
#Reset the money after selling to the ratter in hashan.
trigger /Liirup squeals with delight/, :reset_money
#After we gain balance, we need to decide if we should attack again or not.
if @balance_user
after Character, :character_is_balanced, :should_i_attack_rat?
else
after Character, :character_has_equilibrium, :should_i_attack_rat?
end
end
def ratter_enabled?
@ratter_enabled
end
def rat_available?
@available_rats > 0
end
def rat_is_available
#increment the available rats in the room by one.
@available_rats += 1
#first make sure that we are balanced and there are rats available
if @balance_user
if rat_available? && @character_balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && @character_has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
def rat_is_unavailable
#decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
#decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
#add the rat to our inventory rats
@inventory_rats += 1
#take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
#send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def enable_ratter
warn("RMuddy: Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
warn("RMuddy: Room Ratter Turned Off.")
@ratter_enabled = false
end
#reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
+ send_kmuddy_command("put sovereigns in pack")
+ end
+ def sell_rats
+ send_kmuddy_command("Sell rats to Liirup")
end
#Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if @balance_user
if rat_available? && @character_balanced
send_kmuddy_command(@attack_command)
end
else
if rat_available? && @character_has_equilibrium
send_kmuddy_command(@attack_command)
end
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
eceebf43ef9d6974a826f808be6483e2e33bbc14
|
Fixed the walker to include equilibrium, lazy
|
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index 0bb393a..1e42b95 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,187 +1,187 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
module Walker
def walker_setup
warn("RMuddy: Auto Walker Plugin Loaded!")
warn("RMuddy: ***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("RMuddy: ***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
#It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
trigger /is here\./, :skip_room
trigger /There is no exit in that direction/, :lost!
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
#Wait until we pass our seconds to wait.
end
#If we can walk, walk!
- if @character_balanced && @auto_walk_enabled
+ if @character_balanced && @character_has_equilibrium && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("RMuddy: Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def disable_walker
warn("RMuddy: Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
def lost!
@auto_walk_enabled = false
warn("RMuddy: Auto Walker is LOST! Disabling.")
end
def increment_rail_position
if @ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
@available_rats = 0
backtrack
end
def backtrack
if @backtracking && @auto_walker_enabled
if @rail_position > 0
warn "Auto Walker: Backtracking #{@rail_position} steps."
else
warn "Auto Walker: Finished Backtracking."
end
if @rail_position > 0
@rail_position -= 1
sleep 0.3
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
8fb44a74b662a35f7204e4a4a808878ddfacfe94
|
Cleaned up 2 lines from character.rb
|
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 2aec865..250215a 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,131 +1,129 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
module Character
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :character_current_health, :character_current_mana
attr_accessor :character_total_health, :character_total_mana
attr_accessor :character_current_endurance, :character_total_endurance
attr_accessor :character_current_willpower, :character_total_willpower
attr_accessor :character_balanced
attr_accessor :character_status
attr_accessor :character_has_equilibrium
def character_setup
warn("RMuddy: Character Plugin Loaded!")
#By default, we are assumed to be balanced and to have equilibrium.
@character_balanced = true
@character_has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :character_set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
#set the balance when it returns.
trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
#demonnic: set the equilibrium when it returns
trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
#We use the prompt to tell us when we are unbalanced.
trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
trigger /You reach out and bop/, :character_is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def character_set_simple_stats(match_object)
unless @using_extended_stats == true
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
- #@character_status = match_object[3].to_s
@character_balanced = match_object[3].include("x")
@character_has_equilibrium = match_object[3].include?("e")
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
end
end
def character_set_extended_stats(match_object)
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_current_endurance = match_object[3].to_i
@character_current_willpower = match_object[4].to_i
- #@character_status = match_object[5].to_s
@character_balanced = match_object[5].include?("x")
@character_has_equilibrium = match_object[5].include?("e")
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
@using_extended_stats = true
end
def character_set_total_health(match_object )
@character_total_health = match_object[2].to_i
@character_current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_total_health", @character_total_health)
end
def character_set_total_mana(match_object )
@character_total_mana = match_object[2].to_i
@character_current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_set_total_endurance(match_object )
@character_total_endurance = match_object[2].to_i
@character_current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_total_endurance", @character_total_endurance)
end
def character_set_total_willpower(match_object )
@character_total_willpower = match_object[2].to_i
@character_current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_total_willpower", @character_total_willpower)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
def character_has_equilibrium
@character_has_equilibrium = true
end
def character_lost_equilibrium
@character_has_equilibrium = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
9ccb33dabd7ce5e2beb400f7ca202f40575fe6c1
|
really, really fixed it this time.
|
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 1bfc5a6..2aec865 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,131 +1,131 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
module Character
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :character_current_health, :character_current_mana
attr_accessor :character_total_health, :character_total_mana
attr_accessor :character_current_endurance, :character_total_endurance
attr_accessor :character_current_willpower, :character_total_willpower
attr_accessor :character_balanced
attr_accessor :character_status
attr_accessor :character_has_equilibrium
def character_setup
warn("RMuddy: Character Plugin Loaded!")
#By default, we are assumed to be balanced and to have equilibrium.
@character_balanced = true
@character_has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :character_set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
#set the balance when it returns.
trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
#demonnic: set the equilibrium when it returns
trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
#We use the prompt to tell us when we are unbalanced.
trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
trigger /You reach out and bop/, :character_is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def character_set_simple_stats(match_object)
unless @using_extended_stats == true
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
- @character_status = match_object[3].to_s
- @character_balanced = @character_status.include? "x"
- @character_has_equilibrium = @character_status.include? "e"
+ #@character_status = match_object[3].to_s
+ @character_balanced = match_object[3].include("x")
+ @character_has_equilibrium = match_object[3].include?("e")
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
end
end
def character_set_extended_stats(match_object)
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_current_endurance = match_object[3].to_i
@character_current_willpower = match_object[4].to_i
- @character_status = match_object[5].to_s
- @character_balanced = @character_status.include? "x"
- @character_has_equilibrium = @character_status.include? "e"
+ #@character_status = match_object[5].to_s
+ @character_balanced = match_object[5].include?("x")
+ @character_has_equilibrium = match_object[5].include?("e")
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
@using_extended_stats = true
end
def character_set_total_health(match_object )
@character_total_health = match_object[2].to_i
@character_current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_total_health", @character_total_health)
end
def character_set_total_mana(match_object )
@character_total_mana = match_object[2].to_i
@character_current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_set_total_endurance(match_object )
@character_total_endurance = match_object[2].to_i
@character_current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_total_endurance", @character_total_endurance)
end
def character_set_total_willpower(match_object )
@character_total_willpower = match_object[2].to_i
@character_current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_total_willpower", @character_total_willpower)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
def character_has_equilibrium
@character_has_equilibrium = true
end
def character_lost_equilibrium
@character_has_equilibrium = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
fea8ce126cd41e7db1fcd93b82cfba6ddc825d27
|
bah, fixed the stupid method again...
|
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 016b1f3..1bfc5a6 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,131 +1,131 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
module Character
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :character_current_health, :character_current_mana
attr_accessor :character_total_health, :character_total_mana
attr_accessor :character_current_endurance, :character_total_endurance
attr_accessor :character_current_willpower, :character_total_willpower
attr_accessor :character_balanced
attr_accessor :character_status
attr_accessor :character_has_equilibrium
def character_setup
warn("RMuddy: Character Plugin Loaded!")
#By default, we are assumed to be balanced and to have equilibrium.
@character_balanced = true
@character_has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :character_set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
#set the balance when it returns.
trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
#demonnic: set the equilibrium when it returns
trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
#We use the prompt to tell us when we are unbalanced.
trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
trigger /You reach out and bop/, :character_is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def character_set_simple_stats(match_object)
unless @using_extended_stats == true
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
- @character_status = match_object[3].to_i
+ @character_status = match_object[3].to_s
@character_balanced = @character_status.include? "x"
@character_has_equilibrium = @character_status.include? "e"
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
end
end
def character_set_extended_stats(match_object)
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_current_endurance = match_object[3].to_i
@character_current_willpower = match_object[4].to_i
- @character_status = match_object[5].to_i
+ @character_status = match_object[5].to_s
@character_balanced = @character_status.include? "x"
@character_has_equilibrium = @character_status.include? "e"
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
@using_extended_stats = true
end
def character_set_total_health(match_object )
@character_total_health = match_object[2].to_i
@character_current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_total_health", @character_total_health)
end
def character_set_total_mana(match_object )
@character_total_mana = match_object[2].to_i
@character_current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_set_total_endurance(match_object )
@character_total_endurance = match_object[2].to_i
@character_current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_total_endurance", @character_total_endurance)
end
def character_set_total_willpower(match_object )
@character_total_willpower = match_object[2].to_i
@character_current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_total_willpower", @character_total_willpower)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
def character_has_equilibrium
@character_has_equilibrium = true
end
def character_lost_equilibrium
@character_has_equilibrium = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
ce5bd65339d46eca78aba4bf29315d8d75bd8794
|
Backed out changes which broke character.rb, but retained the balance and equil. tracking for simple stat checking
|
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index ce80b5d..016b1f3 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,129 +1,131 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
module Character
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :character_current_health, :character_current_mana
attr_accessor :character_total_health, :character_total_mana
attr_accessor :character_current_endurance, :character_total_endurance
attr_accessor :character_current_willpower, :character_total_willpower
attr_accessor :character_balanced
attr_accessor :character_status
attr_accessor :character_has_equilibrium
def character_setup
warn("RMuddy: Character Plugin Loaded!")
#By default, we are assumed to be balanced and to have equilibrium.
@character_balanced = true
@character_has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :character_set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
#set the balance when it returns.
trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
#demonnic: set the equilibrium when it returns
trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
#We use the prompt to tell us when we are unbalanced.
trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
trigger /You reach out and bop/, :character_is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def character_set_simple_stats(match_object)
unless @using_extended_stats == true
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
- @character_balanced = match_object.include?("x")
- @character_has_equilibrium = match_object.include?("e")
+ @character_status = match_object[3].to_i
+ @character_balanced = @character_status.include? "x"
+ @character_has_equilibrium = @character_status.include? "e"
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
end
end
def character_set_extended_stats(match_object)
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_current_endurance = match_object[3].to_i
@character_current_willpower = match_object[4].to_i
- @character_balanced = match_object.include?("x")
- @character_has_equilibrium = match_object.include?("e")
+ @character_status = match_object[5].to_i
+ @character_balanced = @character_status.include? "x"
+ @character_has_equilibrium = @character_status.include? "e"
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
@using_extended_stats = true
end
def character_set_total_health(match_object )
@character_total_health = match_object[2].to_i
@character_current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_total_health", @character_total_health)
end
def character_set_total_mana(match_object )
@character_total_mana = match_object[2].to_i
@character_current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_set_total_endurance(match_object )
@character_total_endurance = match_object[2].to_i
@character_current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_total_endurance", @character_total_endurance)
end
def character_set_total_willpower(match_object )
@character_total_willpower = match_object[2].to_i
@character_current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_total_willpower", @character_total_willpower)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
def character_has_equilibrium
@character_has_equilibrium = true
end
def character_lost_equilibrium
@character_has_equilibrium = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
a3afea1445873594a541b6e4256ea0b9d31f2e1c
|
Cleaned up the character stat plugin, streamlined it slightly, less code. Added equilibrium and balance tracking to the prompt for the character_set_simple_stat s method.
|
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 1bfc5a6..ce80b5d 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,131 +1,129 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
module Character
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :character_current_health, :character_current_mana
attr_accessor :character_total_health, :character_total_mana
attr_accessor :character_current_endurance, :character_total_endurance
attr_accessor :character_current_willpower, :character_total_willpower
attr_accessor :character_balanced
attr_accessor :character_status
attr_accessor :character_has_equilibrium
def character_setup
warn("RMuddy: Character Plugin Loaded!")
#By default, we are assumed to be balanced and to have equilibrium.
@character_balanced = true
@character_has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :character_set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
#set the balance when it returns.
trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
#demonnic: set the equilibrium when it returns
trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
#We use the prompt to tell us when we are unbalanced.
trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
trigger /You reach out and bop/, :character_is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def character_set_simple_stats(match_object)
unless @using_extended_stats == true
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
- @character_status = match_object[3].to_s
- @character_balanced = @character_status.include? "x"
- @character_has_equilibrium = @character_status.include? "e"
+ @character_balanced = match_object.include?("x")
+ @character_has_equilibrium = match_object.include?("e")
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
end
end
def character_set_extended_stats(match_object)
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_current_endurance = match_object[3].to_i
@character_current_willpower = match_object[4].to_i
- @character_status = match_object[5].to_s
- @character_balanced = @character_status.include? "x"
- @character_has_equilibrium = @character_status.include? "e"
+ @character_balanced = match_object.include?("x")
+ @character_has_equilibrium = match_object.include?("e")
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
@using_extended_stats = true
end
def character_set_total_health(match_object )
@character_total_health = match_object[2].to_i
@character_current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_total_health", @character_total_health)
end
def character_set_total_mana(match_object )
@character_total_mana = match_object[2].to_i
@character_current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_set_total_endurance(match_object )
@character_total_endurance = match_object[2].to_i
@character_current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_total_endurance", @character_total_endurance)
end
def character_set_total_willpower(match_object )
@character_total_willpower = match_object[2].to_i
@character_current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_total_willpower", @character_total_willpower)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
def character_has_equilibrium
@character_has_equilibrium = true
end
def character_lost_equilibrium
@character_has_equilibrium = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
dc858645d1ceaedb8e7e52385b3271b1be0b87f3
|
Cleaned up the character stat plugin, streamlined it slightly, less code. Added equilibrium and balance tracking to the prompt for the character_set_simple_stats method.
|
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index d71bc52..1bfc5a6 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,129 +1,131 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
module Character
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
attr_accessor :character_current_health, :character_current_mana
attr_accessor :character_total_health, :character_total_mana
attr_accessor :character_current_endurance, :character_total_endurance
attr_accessor :character_current_willpower, :character_total_willpower
attr_accessor :character_balanced
attr_accessor :character_status
attr_accessor :character_has_equilibrium
def character_setup
warn("RMuddy: Character Plugin Loaded!")
#By default, we are assumed to be balanced and to have equilibrium.
@character_balanced = true
@character_has_equilibrium = true
@using_extended_status = false
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m (\w+)-/, :character_set_simple_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_extended_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
#set the balance when it returns.
trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
#demonnic: set the equilibrium when it returns
trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
#We use the prompt to tell us when we are unbalanced.
trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
trigger /You reach out and bop/, :character_is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def character_set_simple_stats(match_object)
unless @using_extended_stats == true
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_status = match_object[3].to_s
@character_balanced = @character_status.include? "x"
@character_has_equilibrium = @character_status.include? "e"
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
+ set_kmuddy_variable("character_balanced", @character_balanced)
+ set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
end
end
def character_set_extended_stats(match_object)
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_current_endurance = match_object[3].to_i
@character_current_willpower = match_object[4].to_i
@character_status = match_object[5].to_s
@character_balanced = @character_status.include? "x"
@character_has_equilibrium = @character_status.include? "e"
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
@using_extended_stats = true
end
def character_set_total_health(match_object )
@character_total_health = match_object[2].to_i
@character_current_health = match_object[1].to_i
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_total_health", @character_total_health)
end
def character_set_total_mana(match_object )
@character_total_mana = match_object[2].to_i
@character_current_mana = match_object[1].to_i
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_set_total_endurance(match_object )
@character_total_endurance = match_object[2].to_i
@character_current_endurance = match_object[1].to_i
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_total_endurance", @character_total_endurance)
end
def character_set_total_willpower(match_object )
@character_total_willpower = match_object[2].to_i
@character_current_willpower = match_object[1].to_i
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_total_willpower", @character_total_willpower)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
def character_has_equilibrium
@character_has_equilibrium = true
end
def character_lost_equilibrium
@character_has_equilibrium = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
b28082ec6065a544f1ad7e58c2b1ce8ec352c6fb
|
Fixed where extendedcharacter module was not pushing variable back to kmuddy
|
diff --git a/enabled-plugins/extendedcharacter.rb b/enabled-plugins/extendedcharacter.rb
index b1498c6..39ed761 100644
--- a/enabled-plugins/extendedcharacter.rb
+++ b/enabled-plugins/extendedcharacter.rb
@@ -1,133 +1,141 @@
#The Character plugin tracks the stats of a character.
#It will also track afflictions, defenses, and other states soon.
#DEMONNIC: This is an intermediary version which has been modified to track
#endurance,willpower, and equilibrium on top of the health, mana, and balance
#already being tracked by the original character plugin by Keith. I am not
#certain, but you may wish to only have either character.rb or
#extendedcharacter.rb active at any given time
module Extendedcharacter
#setup the common variables for stats and state
#attr_accessor provides us with methods and instance variables of the same name
#demonnic: I changed the declarations to be structured by stat, as opposed to
#demonnic: currents and totals on one line. will make changes later easier,
#demonnic: I think.
attr_accessor :character_current_health, :character_total_health
attr_accessor :character_current_mana, :character_total_mana
attr_accessor :character_current_endurance, :character_total_endurance
attr_accessor :character_current_willpower, :character_total_willpower
attr_accessor :character_status
attr_accessor :character_balanced
attr_accessor :character_has_equilibrium
def extendedcharacter_setup
warn("RMuddy: Character Plugin Loaded!")
#By default, we are assumed to be balanced and to have equilibrium
@character_balanced = true
@character_has_equilibrium = true
#trigger off of seeing the current prompt.
#You might need to customize this for yourself!
#demonnic: now triggering off of CONFIG PROMPT FULL for achaea
#trigger /^(\d+)h, (\d+)m\s.*/, :character_set_current_stats
trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_current_stats
#Trigger off of when we use the SCORE command.
trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
#set the balance when it returns. demonnic:tagged it to beginning and end
#demonnic: line so that it can't be broken by even sloppy illusions
trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
#demonnic: set the equilibrium when it returns
trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
#We use the prompt to tell us when we are unbalanced.
#demonnic: so we put all that with the -other- prompt trigger... DRY
#trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
#If for some reason we don't catch being unbalanced from the prompt...
#We KNOW we are unbalanced from an attack.
#demonnic: I'm not sure this is necessary... and it seems like it could end
#demonnic: up leading to a LOT of code. commenting out for now; however,
#demonnic: I am leaving the character_is_balanced et. al. for use in other
#demonnic: scripts.
#trigger /You reach out and bop/, :character_is_unbalanced
end
#using the matches that come in, we set our stats and communicate them.
def character_set_current_stats(match_object )
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
@character_current_endurance = match_object[3].to_i
@character_current_willpower = match_object[4].to_i
@character_status = match_object[5].to_s
@character_balanced = @character_status.include? "x"
@character_has_equilibrium = @character_status.include? "e"
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
set_kmuddy_variable("character_current_endurance", @character_current_endurance)
set_kmuddy_variable("character_current_willpower", @character_current_willpower)
set_kmuddy_variable("character_balanced", @character_balanced)
set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
end
#This happens when a SCORE is issued.
#demonnic:or it did, anyways. I now have this being handled seperately for each stat,
#demonnic:this way, it can track each one on its own and it isn't tied to just SCORE
#demonnic:but could be seen using qsc also
#def character_set_total_stats(match_object)
# @character_total_health = match_object[1].to_i
# @character_total_mana = match_object[2].to_i
# debug("Character: Loaded Total Stats")
# set_kmuddy_variable("character_total_health", @character_total_health)
# set_kmuddy_variable("character_total_mana", @character_total_mana)
#end
def character_set_total_health(match_object )
@character_total_health = match_object[2].to_i
@character_current_health = match_object[1].to_i
+ set_kmuddy_variable("character_current_health", @character_current_health)
+ set_kmuddy_variable("character_total_health", @character_total_health)
end
def character_set_total_mana(match_object )
@character_total_mana = match_object[2].to_i
@character_current_mana = match_object[1].to_i
+ set_kmuddy_variable("character_current_mana", @character_current_mana)
+ set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_set_total_endurance(match_object )
@character_total_endurance = match_object[2].to_i
@character_current_endurance = match_object[1].to_i
+ set_kmuddy_variable("character_current_endurance", @character_current_endurance)
+ set_kmuddy_variable("character_total_endurance", @character_total_endurance)
end
def character_set_total_willpower(match_object )
@character_total_willpower = match_object[2].to_i
@character_current_willpower = match_object[1].to_i
+ set_kmuddy_variable("character_current_willpower", @character_current_willpower)
+ set_kmuddy_variable("character_total_willpower", @character_total_willpower)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
def character_has_equilibrium
@character_has_equilibrium = true
end
def character_lost_equilibrium
@character_has_equilibrium = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
bdebe53b8d7756aca445867f005e63779ec8981d
|
Added error message when options are not set correctly.
|
diff --git a/kmuddy/variablesock.rb b/kmuddy/variablesock.rb
index 1dfec19..4b5d776 100755
--- a/kmuddy/variablesock.rb
+++ b/kmuddy/variablesock.rb
@@ -1,157 +1,159 @@
class VariableSock
include KMuddy
def initialize
if ENV.has_key?('KMUDDY_SOCKET')
@socket_name = ENV['KMUDDY_SOCKET']
else
- warn("Variable KMUDDY_SOCKET is not set - variable support won't work!")
+ warn("*" * 80)
+ warn("RMuddy: Please Check COMMUNICATE VARIABLES In The Script Configuration.")
+ warn("*" * 80)
end
begin
@socketfile = UNIXSocket.new(@socket_name)
rescue StandardError => errormsg
warn("VariableSock.initialize: #{errormsg}")
end
end
def close
unless(@socketfile.closed?)
@socketfile.close
else
warn("VariableSock.close: The pipe is not open.")
end
end
def get(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("get #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.get: #{errormsg}")
end
else
warn("VariableSock.get: The pipe is not open.")
end
end
def set(name,value)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("set #{name} #{value}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.set: #{errormsg}")
end
else
warn("VariableSock.set: The pipe is not open.")
end
end
def unset(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("unset #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.unset: #{errormsg}")
end
else
warn("VariableSock.unset: The pipe is not open.")
end
end
def inc(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("inc #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.inc: #{errormsg}")
end
else
warn("VariableSock.inc: The pipe is not open.")
end
end
def dec(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("dec #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.dec: #{errormsg}")
end
else
warn("VariableSock.dec: The pipe is not open.")
end
end
def request(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("request #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.request: #{errormsg}")
end
else
warn("VariableSock.request: The pipe is not open.")
end
end
def provide(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("provide #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.provide: #{errormsg}")
end
else
warn("VariableSock.provide: The pipe is not open.")
end
end
def lock(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("lock #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.lock: #{errormsg}")
end
else
warn("VariableSock.lock: The pipe is not open.")
end
end
def unlock(name)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("unlock #{name}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.unlock: #{errormsg}")
end
else
warn("VariableSock.unlock: The pipe is not open.")
end
end
def command(command)
unless(@socket_name.nil? || @socket_name.empty?)
begin
@socketfile.puts("send #{command}")
@socketfile.gets.chomp
@socketfile.puts("set lastcommand #{command}")
return @socketfile.gets.chomp
rescue StandardError => errormsg
warn("VariableSock.command: #{errormsg}")
end
else
warn("VariableSock.command: The pipe is not open.")
end
end
end
|
KeithHanson/rmuddy
|
f0fd0861344450a60eaf68e4e2696dc5c6d77839
|
Added extended character stat tracking (extendedcharacter.rb)
|
diff --git a/enabled-plugins/extendedcharacter.rb b/enabled-plugins/extendedcharacter.rb
new file mode 100644
index 0000000..b1498c6
--- /dev/null
+++ b/enabled-plugins/extendedcharacter.rb
@@ -0,0 +1,133 @@
+#The Character plugin tracks the stats of a character.
+#It will also track afflictions, defenses, and other states soon.
+#DEMONNIC: This is an intermediary version which has been modified to track
+#endurance,willpower, and equilibrium on top of the health, mana, and balance
+#already being tracked by the original character plugin by Keith. I am not
+#certain, but you may wish to only have either character.rb or
+#extendedcharacter.rb active at any given time
+module Extendedcharacter
+ #setup the common variables for stats and state
+ #attr_accessor provides us with methods and instance variables of the same name
+ #demonnic: I changed the declarations to be structured by stat, as opposed to
+ #demonnic: currents and totals on one line. will make changes later easier,
+ #demonnic: I think.
+
+ attr_accessor :character_current_health, :character_total_health
+ attr_accessor :character_current_mana, :character_total_mana
+ attr_accessor :character_current_endurance, :character_total_endurance
+ attr_accessor :character_current_willpower, :character_total_willpower
+ attr_accessor :character_status
+ attr_accessor :character_balanced
+ attr_accessor :character_has_equilibrium
+
+ def extendedcharacter_setup
+ warn("RMuddy: Character Plugin Loaded!")
+ #By default, we are assumed to be balanced and to have equilibrium
+ @character_balanced = true
+ @character_has_equilibrium = true
+
+ #trigger off of seeing the current prompt.
+ #You might need to customize this for yourself!
+ #demonnic: now triggering off of CONFIG PROMPT FULL for achaea
+ #trigger /^(\d+)h, (\d+)m\s.*/, :character_set_current_stats
+
+ trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/, :character_set_current_stats
+
+ #Trigger off of when we use the SCORE command.
+
+ trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
+ trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
+ trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
+ trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
+
+ #set the balance when it returns. demonnic:tagged it to beginning and end
+ #demonnic: line so that it can't be broken by even sloppy illusions
+ trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
+
+ #demonnic: set the equilibrium when it returns
+ trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
+
+ #We use the prompt to tell us when we are unbalanced.
+ #demonnic: so we put all that with the -other- prompt trigger... DRY
+ #trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
+
+ #If for some reason we don't catch being unbalanced from the prompt...
+ #We KNOW we are unbalanced from an attack.
+ #demonnic: I'm not sure this is necessary... and it seems like it could end
+ #demonnic: up leading to a LOT of code. commenting out for now; however,
+ #demonnic: I am leaving the character_is_balanced et. al. for use in other
+ #demonnic: scripts.
+ #trigger /You reach out and bop/, :character_is_unbalanced
+ end
+
+ #using the matches that come in, we set our stats and communicate them.
+ def character_set_current_stats(match_object )
+ @character_current_health = match_object[1].to_i
+ @character_current_mana = match_object[2].to_i
+ @character_current_endurance = match_object[3].to_i
+ @character_current_willpower = match_object[4].to_i
+ @character_status = match_object[5].to_s
+ @character_balanced = @character_status.include? "x"
+ @character_has_equilibrium = @character_status.include? "e"
+ debug("Character: Loaded Current Stats")
+
+ set_kmuddy_variable("character_current_health", @character_current_health)
+ set_kmuddy_variable("character_current_mana", @character_current_mana)
+ set_kmuddy_variable("character_current_endurance", @character_current_endurance)
+ set_kmuddy_variable("character_current_willpower", @character_current_willpower)
+ set_kmuddy_variable("character_balanced", @character_balanced)
+ set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
+ end
+
+ #This happens when a SCORE is issued.
+ #demonnic:or it did, anyways. I now have this being handled seperately for each stat,
+ #demonnic:this way, it can track each one on its own and it isn't tied to just SCORE
+ #demonnic:but could be seen using qsc also
+ #def character_set_total_stats(match_object)
+ # @character_total_health = match_object[1].to_i
+ # @character_total_mana = match_object[2].to_i
+ # debug("Character: Loaded Total Stats")
+
+ # set_kmuddy_variable("character_total_health", @character_total_health)
+ # set_kmuddy_variable("character_total_mana", @character_total_mana)
+ #end
+
+ def character_set_total_health(match_object )
+ @character_total_health = match_object[2].to_i
+ @character_current_health = match_object[1].to_i
+ end
+
+ def character_set_total_mana(match_object )
+ @character_total_mana = match_object[2].to_i
+ @character_current_mana = match_object[1].to_i
+ end
+
+ def character_set_total_endurance(match_object )
+ @character_total_endurance = match_object[2].to_i
+ @character_current_endurance = match_object[1].to_i
+ end
+
+ def character_set_total_willpower(match_object )
+ @character_total_willpower = match_object[2].to_i
+ @character_current_willpower = match_object[1].to_i
+ end
+
+ def character_is_balanced
+ @character_balanced = true
+ end
+
+ def character_is_unbalanced
+ @character_balanced = false
+ end
+
+ def character_has_equilibrium
+ @character_has_equilibrium = true
+ end
+
+ def character_lost_equilibrium
+ @character_has_equilibrium = false
+ end
+
+end
+
+debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
bdb77a3c2b060bbd5c8d84fe3b7560ccd4f80301
|
Added an extendedcharacter.rb plugin to track balance -and- equilibrium will now also track all four of achaea's major stats (health, mana, willpower, and endurance) from either a score or qsc command and the prompt. Modified some of the balance triggering to fire off the prompt, no need to bog RMuddy down with extra code and repetition (I think... I'm still new to this, so if it doesn't work, woops)
|
diff --git a/enabled-plugins/extendedcharacter.rb b/enabled-plugins/extendedcharacter.rb
new file mode 100644
index 0000000..badbd5c
--- /dev/null
+++ b/enabled-plugins/extendedcharacter.rb
@@ -0,0 +1,130 @@
+#The Character plugin tracks the stats of a character.
+#It will also track afflictions, defenses, and other states soon.
+#DEMONNIC: This is an intermediary version which has been modified to track
+#endurance,willpower, and equilibrium on top of the health, mana, and balance
+#already being tracked by the original character plugin by Keith. I am not
+#certain, but you may wish to only have either character.rb or
+#extendedcharacter.rb active at any given time
+module Extendedcharacter
+ #setup the common variables for stats and state
+ #attr_accessor provides us with methods and instance variables of the same name
+ #demonnic: I changed the declarations to be structured by stat, as opposed to
+ #demonnic: currents and totals on one line. will make changes later easier,
+ #demonnic: I think.
+
+ attr_accessor :character_current_health, :character_total_health
+ attr_accessor :character_current_mana, :character_total_mana
+ attr_accessor :character_current_endurance, :character_total_endurance
+ attr_accessor :character_current_willpower, :character_total_willpower
+ attr_accessor :character_status
+ attr_accessor :character_balanced
+ attr_accessor :character_has_equilibrium
+
+ def character_setup
+ warn("RMuddy: Character Plugin Loaded!")
+ #By default, we are assumed to be balanced and to have equilibrium
+ @character_balanced = true
+ @character_has_equilibrium = true
+
+ #trigger off of seeing the current prompt.
+ #You might need to customize this for yourself!
+ #demonnic: now triggering off of CONFIG PROMPT FULL for achaea
+ #trigger /^(\d+)h, (\d+)m\s.*/, :character_set_current_stats
+ trigger /^(\d+)h, (\d+)m, (\d+)e, (\d+)w (\w+)-/ :character_set_current_stats
+ #Trigger off of when we use the SCORE command.
+ trigger /Health:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_health
+ trigger /Mana:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_mana
+ trigger /Willpower:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_willpower
+ trigger /Endurance:\s*(\d+)\s*\/\s*(\d+)/, :character_set_total_endurance
+
+ #set the balance when it returns. demonnic:tagged it to beginning and end
+ #demonnic: line so that it can't be broken by even sloppy illusions
+ trigger /^You have recovered balance on all limbs.$/, :character_is_balanced
+
+ #demonnic: set the equilibrium when it returns
+ trigger /^You have recovered equilibrium.$/, :character_has_equilibrium
+
+ #We use the prompt to tell us when we are unbalanced.
+ #demonnic: so we put all that with the -other- prompt trigger... DRY
+ #trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
+
+ #If for some reason we don't catch being unbalanced from the prompt...
+ #We KNOW we are unbalanced from an attack.
+ #demonnic: I'm not sure this is necessary... and it seems like it could end
+ #demonnic: up leading to a LOT of code. commenting out for now; however,
+ #demonnic: I am leaving the character_is_balanced et. al. for use in other
+ #demonnic: scripts.
+ #trigger /You reach out and bop/, :character_is_unbalanced
+ end
+
+ #using the matches that come in, we set our stats and communicate them.
+ def character_set_current_stats(match_object )
+ @character_current_health = match_object[1].to_i
+ @character_current_mana = match_object[2].to_i
+ @character_current_endurance = match_object[3].to_i
+ @character_current_willpower = match_object[4].to_i
+ @character_status = match_object[5].to_s
+ @character_balanced = @character_status.include? "x"
+ @character_has_equilibrium = @character_status.include? "e"
+ debug("Character: Loaded Current Stats")
+
+ set_kmuddy_variable("character_current_health", @character_current_health)
+ set_kmuddy_variable("character_current_mana", @character_current_mana)
+ set_kmuddy_variable("character_current_endurance", @character_current_endurance)
+ set_kmuddy_variable("character_current_willpower", @character_current_willpower)
+ set_kmuddy_variable("character_balanced", @character_balanced)
+ set_kmuddy_variable("character_has_equilibrium", @character_has_equilibrium)
+ end
+
+ #This happens when a SCORE is issued.
+ #demonnic:or it did, anyways. I now have this being handled seperately for each stat,
+ #demonnic:this way, it can track each one on its own and it isn't tied to just SCORE
+ #demonnic:but could be seen using qsc also
+ #def character_set_total_stats(match_object)
+ # @character_total_health = match_object[1].to_i
+ # @character_total_mana = match_object[2].to_i
+ # debug("Character: Loaded Total Stats")
+
+ # set_kmuddy_variable("character_total_health", @character_total_health)
+ # set_kmuddy_variable("character_total_mana", @character_total_mana)
+ #end
+
+ def character_set_total_health(match_object )
+ @character_total_health = match_object[2].to_i
+ @character_current_health = match_obect[1].to_i
+ end
+
+ def character_set_total_mana(match_object )
+ @character_total_mana = match_object[2].to_i
+ @character_current_mana = match_obect[1].to_i
+ end
+
+ def character_set_total_endurance(match_object )
+ @character_total_endurance = match_object[2].to_i
+ @character_current_endurance = match_obect[1].to_i
+ end
+
+ def character_set_total_willpower(match_object )
+ @character_total_willpower = match_object[2].to_i
+ @character_current_willpower = match_obect[1].to_i
+ end
+
+ def character_is_balanced
+ @character_balanced = true
+ end
+
+ def character_is_unbalanced
+ @character_balanced = false
+ end
+
+ def character_has_equilibrium
+ @character_has_equilibrium = true
+ end
+
+ def character_lost_equilibrium
+ @character_has_equilibrium = false
+ end
+
+end
+
+debug("Character: Character file required.")
\ No newline at end of file
|
KeithHanson/rmuddy
|
2fcbad036b77dd0b238c259581149e2a400863a3
|
Modified sipper to be less buggy. Modified Walker to skip rooms.
|
diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb
index 989b232..bc955e1 100644
--- a/enabled-plugins/sipper.rb
+++ b/enabled-plugins/sipper.rb
@@ -1,73 +1,75 @@
#The AutoSipper. It checks to see if a certain threshold percentage is hit for
#Health and Mana, and keeps your health/mana above that percentage.
#
#You will undoubtedly need to add exception triggers in to disable sipping,
#but right now it is customized for Tarot inscribing.
module Sipper
def sipper_enabled?
@sipper_enabled
end
#Check to make sure we are not below our health threshold
#We make sure to use floats! Since integers round ;)
def health_below_threshold?
(@character_current_health.to_f / @character_total_health.to_f) * 100 < @health_threshold_percentage
end
#Same as above
def mana_below_threshold?
(@character_current_mana.to_f / @character_total_mana.to_f) * 100 < @mana_threshold_percentage
end
def sipper_setup
warn("RMuddy: Sipper Plugin Loaded!")
#By default, we want to be healed ;)
@sipper_enabled = true
#Our health and mana thresholds
@health_threshold_percentage = 70
@mana_threshold_percentage = 70
#After every time the character's current stats are updated, we check to see if we should sip.
after Character, :character_set_current_stats, :should_i_sip?
#This group of triggers disables the sipping for various reasons.
trigger /^Your mind feels stronger and more alert\.$/, :disable_sip
trigger /^The elixer heals and soothes you\.$/, :disable_sip
trigger /^What is it that you wish to drink\?$/, :disable_sip
trigger /^You are asleep and can do nothing\./, :disable_sip
trigger /^The elixer flows down your throat without effect/, :disable_sip
trigger /Wisely preparing yourself beforehand/, :disable_sip
#This group of triggers, substantially smaller, enables the sipping when we can :)
trigger /^You may drink another .*$/, :enable_sip
trigger /You have successfully inscribed the image/, :enable_sip
end
#The heart of the plugin...
def should_i_sip?
#If we don't have our total scores, issue a score and allow the Character plugin to update them.
if @character_total_mana.nil? || @character_total_health.nil?
send_kmuddy_command("score")
else
#Otherwise, begin checking health and mana to see if we need to do some drinking...
if health_below_threshold? && sipper_enabled?
send_kmuddy_command("drink health")
+ @sipper_enabled = false
end
if mana_below_threshold? && sipper_enabled?
send_kmuddy_command("drink mana")
+ @sipper_enabled = false
end
end
end
def disable_sip
@sipper_enabled = false
end
def enable_sip
@sipper_enabled = true
end
end
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
index 7b8e8e4..f9eab01 100644
--- a/enabled-plugins/walker.rb
+++ b/enabled-plugins/walker.rb
@@ -1,169 +1,187 @@
#The Walker is a taaaaad bit more complex than the other plugins.
#The main reason being that we need to use multi-threading to make timers work.
#Essentially, we set our character down on a mono-rail of directions they should go through,
#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
#we want to reset the timers again. Once the timer is up, move forward.
module Walker
def walker_setup
warn("RMuddy: Auto Walker Plugin Loaded!")
- warn("RMuddy: ***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***"
+ warn("RMuddy: ***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***")
warn("RMuddy: ***Use at your own risk!***")
#When we backtrack along the rail, we'll need these.
@opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
#last_timer is essentially the last time the timer was started.
@last_timer = Time.now
#This is to seed the random number generator
#So we don't get duplicate sequences
srand = Time.now.to_i
#This is where we define, how many seconds to wait, randomly 0-10
@seconds_to_wait = rand(10)
#default values. This is the position on our mono-rail, so to speak.
@rail_position = 0
@current_rail = 0
#The current thread that is doing the moving around. We'll have a reference to it here
#So we can kill it if need be.
@current_thread = nil
#The path to walk, the rail of our mono... or something of that nature ;)
#It is an array of arrays. First array holds all paths, inner array holds movements.
@ratter_rail = [
%w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
%w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
]
#defaults
@auto_walk_enabled = false
@backtracking = false
#Since we moved and see a new room, we increment the rail position.
trigger /You see exits leading/, :increment_rail_position
trigger /You see a single exit/, :increment_rail_position
#The only time we ever care about moving too fast is when we're back-tracking.
#So when we see this message, we didn't hit our next room and need to try again.
trigger /Now now, don't be so hasty!/, :backtrack
#The skip room method is used to skip places where it's considered rude to rat.
+ #It also tries to skip places with people in them...
trigger /The Crossroads\./, :skip_room
+ trigger /.* is here\./, :skip_room
+
+ trigger /There is no exit in that direction/, :lost!
#After doing any thing that would cause us to do something to a rat, reset the timers.
after Ratter, :should_i_attack_rat?, :reset_rail_timer
#Enable and disable the auto walker with these two after filters.
after Ratter, :enable_ratter, :enable_walker
after Ratter, :disable_ratter, :disable_walker
#This mother thread keeps track of the sub thread that does the timing.
Thread.new do
while true do
if @auto_walk_enabled
@last_timer = Time.now
@seconds_to_wait = rand(10) + 10
@current_thread = Thread.new do
while @last_timer + @seconds_to_wait >= Time.now do
#Wait until we pass our seconds to wait.
end
#If we can walk, walk!
if @character_balanced && @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
end
end
#Pauses mother thread until sub thread is finished.
@current_thread.join
end
end
end
end
def enable_walker
warn("RMuddy: Auto Walker turned on. (Used with the Room Ratter.)")
@auto_walk_enabled = true
reset_rail_timer
end
def disable_walker
warn("RMuddy: Auto Walker turned off. (Used with the Room Ratter.)")
@auto_walk_enabled = false
kill_thread
@backtracking = true
unless @rail_position <= 0
@rail_position -= 1
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
end
end
def skip_room
if @auto_walk_enabled
send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
end
end
+ def lost!
+ @auto_walk_enabled = false
+ warn("RMuddy: Auto Walker is LOST! Disabling.")
+ end
+
def increment_rail_position
+
if @ratter_enabled && @auto_walk_enabled
if @rail_position + 1 < @ratter_rail[@current_rail].length
@rail_position += 1
else
@rail_position = 0
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
+ warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
+ warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
@available_rats = 0
backtrack
end
def backtrack
- if @backtracking
- warn "Auto Walker: Backtracking #{@rail_position} steps."
+ if @backtracking && @auto_walker_enabled
+ if @rail_position > 0
+ warn "Auto Walker: Backtracking #{@rail_position} steps."
+ else
+ warn "Auto Walker: Finished Backtracking."
+ end
if @rail_position > 0
@rail_position -= 1
sleep 0.3
send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
else
@backtracking = false
if @current_rail + 1 < @ratter_rail.length
@current_rail += 1
+ warn "Auto Walker: Finished moving along current Rail. Loading Next Rail."
else
@current_rail = 0
+ warn "Auto Walker: Finished moving along last rail. Loading First Rail."
end
end
end
end
def reset_rail_timer
@last_timer = Time.now
@seconds_to_wait = rand(10) + 5
#warn("Timers Reset")
#warn("Last Timer: #{@last_timer}")
#warn("Seconds to wait: #{@seconds_to_wait}")
end
def kill_thread
unless @current_thread.nil?
@current_thread.kill
@current_thread = nil
end
end
end
\ No newline at end of file
diff --git a/receiver.rb b/receiver.rb
index 7b347ad..fc46a5b 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,99 +1,99 @@
class Receiver
attr_accessor :varsock, :matches, :setups, :queue
debug("Receiver: Loading Files...")
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
include module_eval(File.basename(file, ".rb").capitalize)
end
def initialize
warn("RMuddy: System Loading...")
@triggers = {}
@setups = []
@queue = []
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
@setups << File.basename(file, ".rb") + "_setup"
end
@setups.each {|setup_string| send(setup_string.to_sym)}
Thread.new do
while true do
if @queue.length > 0
element = @queue.shift
case element[0]
when "set_var"
@varsock.set(element[1], element[2])
when "send_command"
@varsock.command(element[1])
end
end
end
end
- warn("RMuddy System Ready!")
+ warn("RMuddy: System Ready!")
end
def receive(text)
@triggers.each_pair do |regex, method|
debug("Testing #{regex} against line: #{text}")
match = regex.match(text)
unless match.nil?
unless match[1].nil?
send(method.to_sym, match)
else
send(method.to_sym)
end
else
debug("No match!")
end
end
end
def trigger(regex, method)
@triggers[regex] = method
end
def set_kmuddy_variable(variable_name, variable_value)
@queue << ["set_var", variable_name, variable_value]
end
def get_kmuddy_variable(variable_name)
@varsock.get(variable_name)
end
def send_kmuddy_command(command_text)
@queue << ["send_command", command_text]
end
def before(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(1, "send(:#{hook_symbol.to_s})")
module_name.module_eval(new_method.join("\n"))
end
def after(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(-2, "send(:#{hook_symbol.to_s})")
module_name.module_eval(new_method.join("\n"))
end
def to_s
"Receiver Loaded"
end
end
\ No newline at end of file
|
KeithHanson/rmuddy
|
4fa099a51929fd6bf71c98f449560a4215a764b7
|
MAJOR update.
|
diff --git a/enabled-plugins/character.rb b/enabled-plugins/character.rb
index 451085b..c2f82c5 100644
--- a/enabled-plugins/character.rb
+++ b/enabled-plugins/character.rb
@@ -1,49 +1,63 @@
+#The Character plugin tracks the stats of a character.
+#It will also track afflictions, defenses, and other states soon.
module Character
+ #setup the common variables for stats and state
+ #attr_accessor provides us with methods and instance variables of the same name
attr_accessor :character_current_health, :character_current_mana
attr_accessor :character_total_health, :character_total_mana
attr_accessor :character_balanced
def character_setup
-
+ warn("RMuddy: Character Plugin Loaded!")
+ #By default, we are assumed to be balanced.
@character_balanced = true
+ #trigger off of seeing the current prompt.
+ #You might need to customize this for yourself!
trigger /^(\d+)h, (\d+)m\s.*/, :character_set_current_stats
-
+
+ #Trigger off of when we use the SCORE command.
trigger /^Health: \d*\/(\d*)\s\sMana: \d*\/(\d*)$/, :character_set_total_stats
+ #set the balance when it returns.
trigger /You have recovered balance on all limbs./, :character_is_balanced
+ #We use the prompt to tell us when we are unbalanced.
trigger /^\d+h, \d+m\se-/, :character_is_unbalanced
+ #If for some reason we don't catch being unbalanced from the prompt...
+ #We KNOW we are unbalanced from an attack.
trigger /You reach out and bop/, :character_is_unbalanced
end
+ #using the matches that come in, we set our stats and communicate them.
def character_set_current_stats(match_object )
@character_current_health = match_object[1].to_i
@character_current_mana = match_object[2].to_i
debug("Character: Loaded Current Stats")
set_kmuddy_variable("character_current_health", @character_current_health)
set_kmuddy_variable("character_current_mana", @character_current_mana)
end
+ #This happens when a SCORE is issued.
def character_set_total_stats(match_object)
@character_total_health = match_object[1].to_i
@character_total_mana = match_object[2].to_i
debug("Character: Loaded Total Stats")
set_kmuddy_variable("character_total_health", @character_total_health)
set_kmuddy_variable("character_total_mana", @character_total_mana)
end
def character_is_balanced
@character_balanced = true
end
def character_is_unbalanced
@character_balanced = false
end
end
debug("Character: Character file required.")
\ No newline at end of file
diff --git a/enabled-plugins/ratter.rb b/enabled-plugins/ratter.rb
index c173681..4c39516 100644
--- a/enabled-plugins/ratter.rb
+++ b/enabled-plugins/ratter.rb
@@ -1,84 +1,119 @@
+#The Ratter plugin is, essentially, a one room auto-ratter.
+#It keeps track of the rats in your inventory, as well as how much you have earned so far.
+#It will send these variables on to kmuddy as the following variables,
+#so you can make status variables or guages or what have you
+# current_rat_count (Total rats collected so far)
+# total_rat_money (Total money you will earn after selling the rats)
+
+#This has currently been customized for the Jester class and for ratting in Hashani.
+#Further configurability to come.
module Ratter
def ratter_setup
+ warn("RMuddy: Room Ratter Plugin Loaded!")
+ #By default, we will disable the ratter.
@ratter_enabled = false
+
+ #Set the current room's rats to 0
@available_rats = 0
+
+ #Set the inventory's rats to 0
@inventory_rats = 0
+ #Ratting prices taken from HELP RATTING
@rat_prices = {"baby rat" => 7, "young rat" => 14, "rat" => 21, "old rat" => 28, "black rat" => 35}
+ #Total money collected so far.
@total_rat_money = 0
+ #This group of triggers alerts the ratter that a rat is available in the room.
trigger /With a squeak, an*\s*\w* rat darts into the room, looking about wildly./, :rat_is_available
trigger /Your eyes are drawn to an*\s*\w* rat that darts suddenly into view./, :rat_is_available
trigger /An*\s*\w* rat noses its way cautiously out of the shadows./, :rat_is_available
trigger /An*\s*\w* rat wanders into view, nosing about for food./, :rat_is_available
+ #Identifies when a rat has been killed, incrementing counters and such.
trigger /You have slain an*\s(.*\s*rat), retrieving the corpse./, :killed_rat
+ #Identifies when a rat has left the room.
trigger /An*\s*\w* rat wanders back into its warren where you may not follow./, :rat_is_unavailable
trigger /With a flick of its small whiskers, an*\s*\w* rat dashes out of view./, :rat_is_unavailable
trigger /An*\s*\w* rat darts into the shadows and disappears./, :rat_is_unavailable
+ #disable and enable the scripts with "rats" in the mud.
trigger /You will now notice the movement of rats\. Happy hunting\!/, :enable_ratter
trigger /You will no longer take notice of the movement of rats\./, :disable_ratter
+ #Reset the money after selling to the ratter in hashan.
trigger /Liirup squeals with delight/, :reset_money
-
+
+ #After we gain balance, we need to decide if we should attack again or not.
after Character, :character_is_balanced, :should_i_attack_rat?
end
def ratter_enabled?
@ratter_enabled
end
def rat_available?
@available_rats > 0
end
def rat_is_available
+ #increment the available rats in the room by one.
@available_rats += 1
+ #first make sure that we are balanced and there are rats available
if rat_available? && @character_balanced
+ #attack
send_kmuddy_command("bop rat")
end
end
def rat_is_unavailable
+ #decrement by one unless we're already at 0 for some reason.
@available_rats -= 1 unless @available_rats <= 0
end
def killed_rat(match_object)
+ #decrement by one unless we're already at 0 for some reason
@available_rats -= 1 unless @available_rats <= 0
+ #add the rat to our inventory rats
@inventory_rats += 1
+ #take the match for the type of rat that we killed, look up it's price, and add it to the money
@total_rat_money += @rat_prices[match_object[1]]
+ #send updated stats
set_kmuddy_variable("current_rat_count", @inventory_rats)
set_kmuddy_variable("total_rat_money", @total_rat_money)
end
def enable_ratter
+ warn("RMuddy: Room Ratter Turned On.")
@ratter_enabled = true
end
def disable_ratter
+ warn("RMuddy: Room Ratter Turned Off.")
@ratter_enabled = false
end
+ #reset the stats and send them
def reset_money
@total_rat_money = 0
set_kmuddy_variable("total_rat_money", 0)
@inventory_rats = 0
set_kmuddy_variable("current_rat_count", 0)
end
-
+
+ #Decide whether or not we should attack a rat and do so if we can.
def should_i_attack_rat?
if rat_available? && @character_balanced
send_kmuddy_command("bop rat")
end
end
end
\ No newline at end of file
diff --git a/enabled-plugins/sipper.rb b/enabled-plugins/sipper.rb
index 9e31ac8..989b232 100644
--- a/enabled-plugins/sipper.rb
+++ b/enabled-plugins/sipper.rb
@@ -1,56 +1,73 @@
+#The AutoSipper. It checks to see if a certain threshold percentage is hit for
+#Health and Mana, and keeps your health/mana above that percentage.
+#
+#You will undoubtedly need to add exception triggers in to disable sipping,
+#but right now it is customized for Tarot inscribing.
module Sipper
-
-
+
def sipper_enabled?
@sipper_enabled
end
+ #Check to make sure we are not below our health threshold
+ #We make sure to use floats! Since integers round ;)
def health_below_threshold?
(@character_current_health.to_f / @character_total_health.to_f) * 100 < @health_threshold_percentage
end
+ #Same as above
def mana_below_threshold?
(@character_current_mana.to_f / @character_total_mana.to_f) * 100 < @mana_threshold_percentage
end
-
+
def sipper_setup
+ warn("RMuddy: Sipper Plugin Loaded!")
+ #By default, we want to be healed ;)
@sipper_enabled = true
+ #Our health and mana thresholds
@health_threshold_percentage = 70
@mana_threshold_percentage = 70
+ #After every time the character's current stats are updated, we check to see if we should sip.
after Character, :character_set_current_stats, :should_i_sip?
+ #This group of triggers disables the sipping for various reasons.
trigger /^Your mind feels stronger and more alert\.$/, :disable_sip
trigger /^The elixer heals and soothes you\.$/, :disable_sip
trigger /^What is it that you wish to drink\?$/, :disable_sip
trigger /^You are asleep and can do nothing\./, :disable_sip
trigger /^The elixer flows down your throat without effect/, :disable_sip
trigger /Wisely preparing yourself beforehand/, :disable_sip
+ #This group of triggers, substantially smaller, enables the sipping when we can :)
trigger /^You may drink another .*$/, :enable_sip
trigger /You have successfully inscribed the image/, :enable_sip
end
+ #The heart of the plugin...
def should_i_sip?
+ #If we don't have our total scores, issue a score and allow the Character plugin to update them.
if @character_total_mana.nil? || @character_total_health.nil?
send_kmuddy_command("score")
else
+
+ #Otherwise, begin checking health and mana to see if we need to do some drinking...
if health_below_threshold? && sipper_enabled?
send_kmuddy_command("drink health")
end
if mana_below_threshold? && sipper_enabled?
send_kmuddy_command("drink mana")
end
end
end
def disable_sip
@sipper_enabled = false
end
def enable_sip
@sipper_enabled = true
end
end
diff --git a/enabled-plugins/walker.rb b/enabled-plugins/walker.rb
new file mode 100644
index 0000000..7b8e8e4
--- /dev/null
+++ b/enabled-plugins/walker.rb
@@ -0,0 +1,169 @@
+#The Walker is a taaaaad bit more complex than the other plugins.
+#The main reason being that we need to use multi-threading to make timers work.
+#Essentially, we set our character down on a mono-rail of directions they should go through,
+#and from there let the room ratter do it's work. Every time we hit, see, or do anything to a rat,
+#we want to reset the timers again. Once the timer is up, move forward.
+module Walker
+ def walker_setup
+ warn("RMuddy: Auto Walker Plugin Loaded!")
+ warn("RMuddy: ***The Auto Walker will fully automate your ratting and is considered ILLEGAL by Achaea.***"
+ warn("RMuddy: ***Use at your own risk!***")
+
+ #When we backtrack along the rail, we'll need these.
+ @opposite_directions = { "n" => "s", "s" => "n", "e" => "w", "w" => "e", "ne" => "sw", "sw" => "ne", "nw" => "se", "se" => "nw", "in" => "out", "out" => "in", "u" => "d", "d" => "u"}
+
+ #last_timer is essentially the last time the timer was started.
+ @last_timer = Time.now
+
+ #This is to seed the random number generator
+ #So we don't get duplicate sequences
+ srand = Time.now.to_i
+
+ #This is where we define, how many seconds to wait, randomly 0-10
+ @seconds_to_wait = rand(10)
+
+ #default values. This is the position on our mono-rail, so to speak.
+ @rail_position = 0
+ @current_rail = 0
+
+ #The current thread that is doing the moving around. We'll have a reference to it here
+ #So we can kill it if need be.
+ @current_thread = nil
+
+ #The path to walk, the rail of our mono... or something of that nature ;)
+ #It is an array of arrays. First array holds all paths, inner array holds movements.
+ @ratter_rail = [
+ %w(n n ne e n e ne e n ne e se e ne se ne n n e ne e n ne e se se e s s sw s s w sw nw w w sw w w nw w s s sw s s s sw w w w s w w nw sw nw nw n n),
+ %w(n n ne e n e ne e n nw w nw sw nw n n ne se e ne e se ne n e e s se s s s se s s s s sw s s s sw w w w s w w nw sw nw nw n n)
+ ]
+
+
+ #defaults
+ @auto_walk_enabled = false
+ @backtracking = false
+
+ #Since we moved and see a new room, we increment the rail position.
+ trigger /You see exits leading/, :increment_rail_position
+ trigger /You see a single exit/, :increment_rail_position
+
+ #The only time we ever care about moving too fast is when we're back-tracking.
+ #So when we see this message, we didn't hit our next room and need to try again.
+ trigger /Now now, don't be so hasty!/, :backtrack
+
+ #The skip room method is used to skip places where it's considered rude to rat.
+ trigger /The Crossroads\./, :skip_room
+
+ #After doing any thing that would cause us to do something to a rat, reset the timers.
+ after Ratter, :should_i_attack_rat?, :reset_rail_timer
+
+ #Enable and disable the auto walker with these two after filters.
+ after Ratter, :enable_ratter, :enable_walker
+ after Ratter, :disable_ratter, :disable_walker
+
+ #This mother thread keeps track of the sub thread that does the timing.
+ Thread.new do
+ while true do
+
+ if @auto_walk_enabled
+
+ @last_timer = Time.now
+ @seconds_to_wait = rand(10) + 10
+
+ @current_thread = Thread.new do
+ while @last_timer + @seconds_to_wait >= Time.now do
+ #Wait until we pass our seconds to wait.
+ end
+
+ #If we can walk, walk!
+ if @character_balanced && @auto_walk_enabled
+ send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position]}")
+ end
+ end
+
+ #Pauses mother thread until sub thread is finished.
+ @current_thread.join
+
+ end
+ end
+ end
+ end
+
+ def enable_walker
+ warn("RMuddy: Auto Walker turned on. (Used with the Room Ratter.)")
+ @auto_walk_enabled = true
+
+ reset_rail_timer
+ end
+
+ def disable_walker
+ warn("RMuddy: Auto Walker turned off. (Used with the Room Ratter.)")
+ @auto_walk_enabled = false
+ kill_thread
+ @backtracking = true
+ unless @rail_position <= 0
+ @rail_position -= 1
+ send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
+ end
+ end
+
+ def skip_room
+ if @auto_walk_enabled
+ send_kmuddy_command("#{@ratter_rail[@current_rail][@rail_position + 1]}")
+ end
+ end
+
+ def increment_rail_position
+ if @ratter_enabled && @auto_walk_enabled
+ if @rail_position + 1 < @ratter_rail[@current_rail].length
+ @rail_position += 1
+ else
+ @rail_position = 0
+
+ if @current_rail + 1 < @ratter_rail.length
+ @current_rail += 1
+ else
+ @current_rail = 0
+ end
+ end
+ end
+
+ @available_rats = 0
+
+ backtrack
+ end
+
+ def backtrack
+ if @backtracking
+ warn "Auto Walker: Backtracking #{@rail_position} steps."
+ if @rail_position > 0
+ @rail_position -= 1
+ sleep 0.3
+ send_kmuddy_command("#{@opposite_directions[@ratter_rail[@current_rail][@rail_position]]}")
+ else
+ @backtracking = false
+
+ if @current_rail + 1 < @ratter_rail.length
+ @current_rail += 1
+ else
+ @current_rail = 0
+ end
+ end
+ end
+ end
+
+ def reset_rail_timer
+ @last_timer = Time.now
+ @seconds_to_wait = rand(10) + 5
+ #warn("Timers Reset")
+ #warn("Last Timer: #{@last_timer}")
+ #warn("Seconds to wait: #{@seconds_to_wait}")
+ end
+
+ def kill_thread
+ unless @current_thread.nil?
+ @current_thread.kill
+ @current_thread = nil
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/init.rb b/init.rb
index 1e1bf78..c3de4b6 100755
--- a/init.rb
+++ b/init.rb
@@ -1,21 +1,21 @@
#!/usr/bin/env ruby
+
+DEBUG = false
+
Dir[File.join(File.dirname(__FILE__), "gems", "gems", "*")].each do |gem_folder|
$: << gem_folder + "/lib/"
end
require File.join(File.dirname(__FILE__), "connection_handler.rb")
require File.join(File.dirname(__FILE__), "receiver.rb")
require 'yaml'
require "ruby2ruby"
-
-DEBUG = false
-
debug("Starting Receiver...")
receiver = Receiver.new()
debug("Starting Connection Handler")
connection_handler = ConnectionHandler.new(receiver)
connection_handler.start
debug("Connection Handler Started")
\ No newline at end of file
diff --git a/kmuddy/kmuddy.rb b/kmuddy/kmuddy.rb
index 157182f..76fe5bb 100755
--- a/kmuddy/kmuddy.rb
+++ b/kmuddy/kmuddy.rb
@@ -1,45 +1,43 @@
#!/bin/env ruby
-DEBUG = false
-
require 'socket'
module KMuddy
ANSI = { "reset" => "\e[0m", "bold" => "\e[1m",
"underline" => "\e[4m", "blink" => "\e[5m",
"reverse" => "\e[7m", "invisible" => "\e[8m",
"black" => "\e[0;30m", "darkgrey" => "\e[1;30m",
"red" => "\e[0;31m", "lightred" => "\e[1;31m",
"green" => "\e[0;32m", "lightgreen" => "\e[1;32m",
"brown" => "\e[0;33m", "yellow" => "\e[1;33m",
"blue" => "\e[0;34m", "lightblue" => "\e[1;34m",
"purple" => "\e[0;35m", "magenta" => "\e[1;35m",
"cyan" => "\e[1;36m", "lightcyan" => "\e[1;36m",
"grey" => "\e[0;37m", "white" => "\e[1;37m",
"bgblack" => "\e[40m", "bgred" => "\e[41m",
"bggreen" => "\e[42m", "bgyellow" => "\e[43m",
"bgblue" => "\e[44m", "bgmagenta" => "\e[45m",
"bgcyan" => "\e[46m", "bgwhite" => "\e[47m"
}
def ansi(text)
ANSI[text]
end
def ansi_strip(line)
return line.gsub!(/\e\[[0-9;]+m/, "")
end
def debug(text)
#$stderr.puts("#{ansi("red")}--> #{text}#{ansi("reset")}") if DEBUG
$stderr.puts("DEBUG--> #{text}") if DEBUG
end
def warn(text)
- $stderr.puts("-! #{text}")
+ $stderr.puts("\n-! #{text}")
end
def output(text)
$stderr.puts(text)
end
end
diff --git a/receiver.rb b/receiver.rb
index a845373..7b347ad 100644
--- a/receiver.rb
+++ b/receiver.rb
@@ -1,81 +1,99 @@
class Receiver
- attr_accessor :varsock, :matches, :setups
+ attr_accessor :varsock, :matches, :setups, :queue
debug("Receiver: Loading Files...")
#Load All Plugins
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
debug("Receiver: Found #{file}")
require file
include module_eval(File.basename(file, ".rb").capitalize)
end
def initialize
+ warn("RMuddy: System Loading...")
@triggers = {}
@setups = []
+ @queue = []
Dir[File.join(File.dirname(__FILE__), "enabled-plugins", "*.rb")].each do |file|
@setups << File.basename(file, ".rb") + "_setup"
end
@setups.each {|setup_string| send(setup_string.to_sym)}
+
+ Thread.new do
+ while true do
+ if @queue.length > 0
+ element = @queue.shift
+ case element[0]
+ when "set_var"
+ @varsock.set(element[1], element[2])
+ when "send_command"
+ @varsock.command(element[1])
+ end
+ end
+ end
+ end
+
+ warn("RMuddy System Ready!")
end
def receive(text)
@triggers.each_pair do |regex, method|
debug("Testing #{regex} against line: #{text}")
match = regex.match(text)
unless match.nil?
unless match[1].nil?
send(method.to_sym, match)
else
send(method.to_sym)
end
else
debug("No match!")
end
end
end
def trigger(regex, method)
@triggers[regex] = method
end
def set_kmuddy_variable(variable_name, variable_value)
- @varsock.set(variable_name, variable_value)
+ @queue << ["set_var", variable_name, variable_value]
end
def get_kmuddy_variable(variable_name)
@varsock.get(variable_name)
end
def send_kmuddy_command(command_text)
- @varsock.command(command_text)
+ @queue << ["send_command", command_text]
end
def before(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(1, "send(:#{hook_symbol.to_s})")
module_name.module_eval(new_method.join("\n"))
end
def after(module_name, method_symbol, hook_symbol)
method = Ruby2Ruby.translate(module_name, method_symbol.to_sym)
new_method = method.split("\n")
new_method.insert(-2, "send(:#{hook_symbol.to_s})")
module_name.module_eval(new_method.join("\n"))
end
def to_s
"Receiver Loaded"
end
end
\ No newline at end of file
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.