@program iwc-client.muf 1 10000 d i ( iwc-client.muf, by Hinoserm, DO NOT DISTRIBUTE. ) (-------------------------------------------------) ( The program should give the instructions when ) ( you compile it. Contact hinoserm@protomuck.org ) ( to obtain your login info. ) (-------------------------------------------------) ( Much thanks to The_Blob for helping to optimize ) ( some of my functions. ) (!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!) ( This will not run on Proto2b5.12 or older. ) ( This program could be considered UNSAFE. ) (!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!) $author Hinoserm $note IWCv2 Client Program, unfinished. $version 0.9 $lib-version 0.4 $def | 127 itoc $pubdef | 127 itoc $def MUCKNAME prog "@config/muckname" getpropstr $def PASSWORD prog "@config/password" getpropstr $def HOSTNAME "iwc1.ginkosoft.com" $def PORT 4443 $def array_keys2list array_keys array_make $def list_modules ( -- a ) #0 "_reg/iwc" array_get_propvals array_keys2list : log ( s i -- ) pop "IWC: " swap strcat logstatus ; ( // START PUBLIC FUNCTIONS // ) : iwc-send ( str:data str:pid str:to -- int:status ) prog "@pid" getpropval dup ispid? not if pop 0 exit then "IWC.SEND" { 6 rotate dup array? if | array_join then | 7 rotate | 8 rotate | "SEND" }cat event_send 1 ; PUBLIC iwc-send $libdef iwc-send : iwc-bcast ( str:data str:pid -- int:status ) prog "@pid" getpropval dup ispid? not if pop 0 then "IWC.SEND" { 5 rotate dup array? if | array_join then | 6 rotate | "CAST" }cat event_send 1 ; MAGECALL iwc-bcast $libdef iwc-bcast : iwc-mlist ( int:timeout -- arr:list OR int:0 ) "i" checkargs prog "@pid" getpropval dup ispid? not if pop pop 0 exit then "IWC.SEND" { pid | "LIST" }cat event_send "IWC.TIMEOUT" timer_start 0 array_make begin { "TIMER.IWC.TIMEOUT" "USER.IWC.LIST" }list event_waitfor "TIMER.IWC.TIMEOUT" stringpfx if pop pop 0 break else "data" [] "data" [] dup "-" strcmp not if pop "IWC.TIMEOUT" timer_stop break then swap array_appenditem then repeat ; MAGECALL iwc-mlist $libdef iwc-mlist : iwc-getdata ( int:timeout -- arr:data OR int:0 ) "i" checkargs prog "@pid" getpropval ispid? not if pop 0 exit then "IWC.TIMEOUT" timer_start { "TIMER.IWC.TIMEOUT" "USER.IWC.SEND" "USER.IWC.CAST" }list event_waitfor "TIMER.IWC.TIMEOUT" stringpfx if pop 0 exit else "data" [] then "IWC.TIMEOUT" timer_stop ; PUBLIC iwc-getdata $libdef iwc-getdata : iwc-get ( arr:types int:timeout -- arr:data OR int:0 ) prog "@pid" getpropval ispid? not if pop pop 0 exit then "IWC.TIMEOUT" timer_start dup string? if "USER.IWC." swap strcat 1 array_make then { "TIMER.IWC.TIMEOUT" }list array_union event_waitfor "TIMER.IWC.TIMEOUT" stringpfx if pop 0 exit else "data" [] then "IWC.TIMEOUT" timer_stop ; PUBLIC iwc-get $libdef iwc-get : iwc-mods ( str:muck int:timeout -- arr:mods OR int:0 ) "si" checkargs over not 3 pick MUCKNAME stringcmp not or if pop list_modules exit else prog "@pid" getpropval dup ispid? not if pop pop 0 exit then "IWC.SEND" { 5 rotate | pid | "MLST" }cat event_send "IWC.TO.MDS" timer_start 0 array_make begin { "TIMER.IWC.TO.MDS" "USER.IWC.SEND" }list event_waitfor "TIMER.IWC.TO.MDS" stringpfx if pop pop 0 break else "data" [] "data" [] dup not if pop break then swap array_appenditem then repeat then ; PUBLIC iwc-mods $libdef iwc-mods : iwc-hasmod? ( str:muck str:mod int:timeout -- int:bool ) "ssi" checkargs rot swap iwc-mods swap array_findval not not ; PUBLIC iwc-hasmod? $libdef iwc-hasmod? : iwc-crypt ( str:in str:key -- str:out ) "" 1 4 pick strlen 1 for 4 pick swap 1 midstr ctoi dup 1 5 pick strlen 1 for 5 pick swap 1 midstr ctoi bitxor repeat dup if swap then pop itoc strcat repeat -3 rotate pop pop ; PUBLIC iwc-crypt $libdef iwc-crypt : iwc-modlist ( -- arr:data OR int:0 ) 5 iwc-mlist dup not if pop 0 exit then prog "@pid" getpropval dup ispid? not if pop pop 0 exit then "IWC.SEND" { pid | "BMLST" }cat event_send 0 array_make_dict 5 "IWC.TO.ML" timer_start begin { "TIMER.IWC.TO.ML" "USER.IWC.SEND" }list event_waitfor "TIMER.IWC.TO.ML" stringpfx if pop swap pop break else ( mlist a darr a data ) "data" [] dup "data" [] dup if -3 rotate "from" [] 2 dupn array_getitem dup not if pop 0 array_make then 4 rotate swap array_appenditem -3 rotate array_setitem else pop rot dup rot "from" [] array_excludeval array_extract dup not if pop break else swap then then then repeat "IWC.TO.ML" timer_stop ; PUBLIC iwc-modlist $libdef iwc-modlist : iwc-mod-mlist ( str:mod -- arr:data OR int:0) "s" checkargs iwc-modlist dup not if pop pop 0 exit then 0 array_make swap foreach 4 pick array_findval if swap array_appenditem else pop then repeat swap pop ; PUBLIC iwc-mod-mlist $libdef iwc-mod-mlist ( // START COMMON FUNCTIONS // ) : is_comment? ( s -- i ) dup strlen dup 3 >= if 2 - 3 midstr " //" stringcmp not else pop pop 0 then ; : ok-muckname? ( s -- i ) dup | instr not over strlen 32 < and over "-" stringcmp and over ":" instr not and swap is_comment? not and ; $define get_registered ( s -- d ) #0 "_reg/iwc/" rot strcat getprop dup dbref? not if pop #-1 then $enddef $define prog_registered? ( d -- ? ) #0 "_reg/iwc" array_get_propvals swap array_findval $enddef $define register_prog ( d s -- ) #0 "_reg/iwc/" rot strcat rot setprop $enddef : pid_registered? ( i -- i ) dup ispid? if getpidinfo "CALLED_PROG" [] prog_registered? else pop 0 then ; : do_error ( i s -- ) prog "@lastiwcerr" getpropstr over strcmp 3 pick -1 = or if "ERROR: " over strcat 0 log prog "@lastiwcerr" rot setprop dup -1 = not if prog "Startup" queue else pop then else "ERROR: " swap strcat 1 log dup -1 = not if 2 * prog "Startup" queue else pop then then ; : do_connect ( -- sock OR i s ) HOSTNAME PORT nbsockopen dup "Operation now in progress" stringcmp if swap pop 20 swap exit else pop then 10 "CONN.TIMEOUT" timer_start $ifdef __proto= - Load a program module. " }cat notify (me @ { " " command @ tolower " #config - Start the menu config system. " }cat notify) me @ { " " command @ tolower " #stop - Shut down the IWC client service." }cat notify me @ { " " command @ tolower " #start - Start up the IWC client service. " }cat notify me @ { " " command @ tolower " #restart - Restart the IWC client service. " }cat notify ; : do_start ( -- ) prog "@pid" getpropval ispid? if me @ "\[[1;33mThe service is already started." ansi_notify else me @ "\[[1;32mStarting..." ansi_notify background main_daemon exit then ; : do_stop ( -- ) prog "@pid" getpropval dup ispid? not if pop me @ "\[[1;33mThe service is not started." ansi_notify else kill if me @ "\[[1;32mStopped." ansi_notify else me @ "\[[1;31mCould not stop the process." ansi_notify then prog "@pid" remove_prop then ; : do_reg ( s -- ) " " split swap pop "=" split swap dup not 3 pick not or if pop pop me @ "\[[1;33mMissing argument." notify exit then match dup program? not if pop pop me @ "\[[1;33mObject not found or not of type program." notify exit then swap dup name-ok? not over ok-muckname? not or if pop pop me @ "\[[1;31mInvalid module name." notify exit then register_prog me @ "\[[1;32mRegistered." ansi_notify ; ( // START USER-DEIDIOTIZER DIRECTIVES // ) $ansi ^YELLOW^IWC ^WHITE^>> ^RED^ Remember to: $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @set iwc-client.muf=A $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @set iwc-client.muf=W3 $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @set iwc-client.muf=L $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @set iwc-client.muf=@config/muckname: $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @set iwc-client.muf=@config/password: $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @propset #0=dbref:_reg/iwc/sys:iwc-client.muf $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @action iwc=#0=iwcact $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ @link $iwcact=iwc-client.muf $ansi ^YELLOW^IWC ^WHITE^>> ^GREEN^ iwc #start $ansi ^YELLOW^IWC ^WHITE^>> ^RED^ If you need assistance, contact hinoserm@protomuck.org. ( // MAIN FUNCTION // ) : main ( s -- ) dup "Startup" stringcmp not trigger @ #-1 dbcmp caller program? or and if pop 0 try main_daemon catch 10 "MUF ERROR: " rot strcat do_error endcatch exit else me @ "w" flag? not if me @ "\[[1;31mPermission denied." ansi_notify exit then dup "#restart" stringcmp not if pop do_stop do_start exit then dup "#start" stringcmp not if pop do_start exit then dup "#stop" stringcmp not if pop do_stop exit then dup "#reg" stringpfx if do_reg exit then pop do_help exit then ; . c q