Master Comlink Parent
From HSpace
The author of this code is believed to be Sholevi. If anyone knows for sure, please edit this article and give the proper credit to the author. -- Fixer.
@@ Administrative Notes:
@@ * To make a comlink, @create an object and @parent it to this one.
@@ * All comlinks must have see_all power, or ROYAL.
@@ * You can optionally create a @channel called 'HSpace Comm' - all comlink
@@ messages will also appear on this channel for the purposes of admin
@@ monitoring.
@@ * Set these attributes on the parent only:
@@ - &MAX_SLOTS - attribute sets the number of frequencies each device is
@@ allowed - to listen on. The ascii desc supports up to 6.
@@ - &MAX_FRQ - attribute indicates the maximum numerical frequency.
@@ - &RANGE - the range of the message of each device in hspace units.
@@ - &MAX_FILES - The maximum number of comdata files that can be stored.
@@
@@ As a tip for setting these attributes, you can use them to provide
@@ different grades of comlinks in the IC world that are more or less
@@ expensive to buy depending on their capabilities.
@@
@@ * The &OBSTRUCTION_LEVEL attribute is a very special one. Obstruction Level
@@ corrupts messages based on a level of 0 through 10. 0 is a completely
@@ clear message, while 10 is a completely mangled message.
@@
@@ The way it works is like this: if a person sends a message and his device
@@ or the room has an obstruction level set, then anyone outside that room will
@@ hear a mangled message. Alternatively, if the device or the room has an
@@ obstruction level set and he receives a message, that message will be mangled
@@ to him.
@@
@@ The purpose of obstruction levels is to simulate message interference.
@@ An obstruction level that is set on a room can simulate interference when
@@ people walk into a cave or something similar. Obstruction levels set on a
@@ device can simulate a damaged device.
@@
@@ If two people are standing in the same room, messages that they send and
@@ receive to eachother will never be mangled no matter what - because obviously
@@ they should be able to hear eachother clearly.
@@
@@ &OBSTRUCTION_LEVEL can be set on either a device, or a room. If both are set
@@ then the room's obstruction level is favored. If two people in different
@@ rooms have an obstruction level set on their devices, then the higher
@@ obstruction level will be favored.
@@
@@
@create Master Comlink Parent <MCP>
@lock/Use Master Comlink Parent <MCP>=%#
@lset Master Comlink Parent <MCP>/Use=no_inherit
@set Master Comlink Parent <MCP> = ROYALTY
@set Master Comlink Parent <MCP> = HSPACE_COMM
&ACTIVE Master Comlink Parent <MCP>=1
@ADROP Master Comlink Parent <MCP>=@ulock me=me;&user me=
@set Master Comlink Parent <MCP>/ADROP=no_command prefixmatch
@ASUCCESS Master Comlink Parent <MCP>=@ulock me=%#;&user me=%#
@set Master Comlink Parent <MCP>/ASUCCESS=no_command prefixmatch
&CMD_COM Master Comlink Parent <MCP>=$com *:@pemit %#=[setq(e,encrypt(setr(0,%0),v(enckey)))][switch([v(active)][t(u(fn_hs_loc))][cand(isnum(v(comm_broadcast)),gt(v(comm_broadcast),0),lt(v(comm_broadcast),v(max_frq)))][isnum(v(range))],0*,[ansi(hr,-%b)][name(me)] is not active.,10*,[ansi(hr,-%b)]You do not have a valid HSpace location.,110*,[ansi(hr,-%b)][name(me)] does not have a valid BROADCAST channel set.,1110*,[ansi(hr,-%b)][name(me)] does not have a valid RANGE set.,1111,if(strmatch([hs_comm_msg(u(fn_uid),u(fn_uid),u(fn_x),u(fn_y),u(fn_z),v(range),v(comm_broadcast),if(v(encryption),%qe,%q0))],Failed.),[remit(%L,%N speaks into %p Comlink saying, [ansi(c,"%q0")], but is greeted only by static.)],[remit(%L,%N speaks into %p Comlink saying, [ansi(c,"%q0")].)][cemit(HSpace Comm,[ansi(hc,HSComm:)] [ansi(b,\[)][ansi(hg,[v(comm_broadcast)])]: [ansi(c,<%N\,%b[if(t(setr(c,squish(xget(v(user),callsign)))),%qc,Anonymous Ccoward)]\,%b[name(u(fn_hs_loc))]>)]%b[ansi(hg,\([timefmt($H:$M:$S,secs())]\))][ansi(b,\])]%b"%q0")]),[ansi(hr,-%b)]Critical error occured.)]
&CMD_COMDATA Master Comlink Parent <MCP>=$comdata *:@pemit %#=[switch([v(active)][first(%0)],0*,[ansi(hr,-%b)][name(me)] is not active.,1set,u(fn_fileset,rest(%0)),1clear,u(fn_fileclear,rest(%0)),1list,u(fn_filelist),1uplink,u(fn_fileuplink,rest(%0)),if(v(data_%0),u(fn_fileshow,%0),[ansi(hr,-%b)][name(me)] does not know that file.))]
&CMD_COMSET Master Comlink Parent <MCP>=$comset *:@pemit %#=[switch([v(active)][first(lcstr(%0))],?on,ulocal(fn_poweron),?off,ulocal(fn_poweroff),0*,[ansi(hr,-%b)][name(me)] is not active.,?reset,ulocal(fn_reset),?broadcast,ulocal(fn_setbroadcast,%0),?timestamp,ulocal(fn_settimestamp),?encryption,u(fn_setencryption,rest(%0)),?key,u(fn_setkey,rest(%0)),if(and(isnum(first(%0)),eq(2,words(%0))),ulocal(fn_setreceive,%0),[ansi(hr,-%b)][name(me)] does not understand the parameters you wish to set.))]
&CMD_HELP Master Comlink Parent <MCP>=$comhelp:@pemit %#=.[ansi(hg,repeat(-,77))].%r[ansi(hg,|)][center(Comlink Help (v[v(mcpver)]),77)][ansi(hg,|)]%r[ansi(hg,=[repeat(-,77)]=)]%r[align(1. 75 1.,ansi(hg,|),u(fn_help),ansi(hg,|))]%r[ansi(hg,=[repeat(-,77)]=)]
&COMM_BROADCAST Master Comlink Parent <MCP>=-
&COMM_FRQS Master Comlink Parent <MCP>=- - - - - -
&COMM_HANDLER Master Comlink Parent <MCP>=if(v(active),[setq(m,u(fn_mangle,%0,if(strmatch(room(%!),room(%2)),0,max(firstof(get(room(%2)/obstruction_level),get(%2/obstruction_level),0),firstof(get(room(%!)/obstruction_level),get(%!/obstruction_level),0)))))] [pemit(v(user),[ansi(b,\[)][ansi(hg,%1)]: [ansi(c,<[firstof(squish(xget(get(%2/user),callsign)),Anonymous Coward)]>)][if(v(timestamp),[ansi(hg,%b\([timefmt($H:$M:$S,secs())]\))])][ansi(b,\])]%b"[if(v(encryption),decrypt(%qm,v(enckey)),%qm)]")])
&DATA_FILE Master Comlink Parent <MCP>=foo\, bar\, baz this is a test of the american broadcasting system\, this is a test of the american broadcasting system.
@DESCRIBE Master Comlink Parent <MCP>=[ansi(w,%b%b_nn____________________%r |_|__________________ |_|%r | \,-------------------. |%r | |[ansi(r,Broadcast:)]%b[ansi(c,[ljust(v(comm_broadcast),8)])]| |%r | `-------------------' |\]%r | \,-------------------. |\]%r | |[center([ansi(r,- Incoming -)],19)]| |\]%r | |[ansi(g,1.)]%b[ansi(c,[ljust(extract(v(comm_frqs),1,1),7)])][ansi(g,2.)]%b[ansi(c,[ljust(extract(v(comm_frqs),2,1),6)])]| |\]%b%b[ansi(g,\(See '[ansi(hc,comhelp)]' for help\))]%r | |[ansi(g,3.)]%b[ansi(c,[ljust(extract(v(comm_frqs),3,1),7)])][ansi(g,4.)]%b[ansi(c,[ljust(extract(v(comm_frqs),4,1),6)])]| |%r | |[ansi(g,5.)]%b[ansi(c,[ljust(extract(v(comm_frqs),5,1),7)])][ansi(g,6.)]%b[ansi(c,[ljust(extract(v(comm_frqs),6,1),6)])]| |%r | `-------------------' |%r | \,-------------------. |%r | |[center([ansi(r,- Files -)],19)]| |%r | |[ansi(c,[left(ljust(capstr(lcstr(after(extract(lattr(me/data_*),1,1),_))),19),19)])]| |%r | |[ansi(c,[left(ljust(capstr(lcstr(after(extract(lattr(me/data_*),2,1),_))),19),19)])]| |%b%b [ansi(g,\(Use '[ansi(hc,comdata list)]' for more\))]%r | |[ansi(c,[left(ljust(capstr(lcstr(after(extract(lattr(me/data_*),3,1),_))),19),19)])]| |%r | `-------------------' |\]%r |%b%b ___%b%b%b%b%b%b%b%b \{~~~\}%b%b |\]%r |%b%b= O =%b%b___%b%b \{~~~\}%b%b |%r |%b%b ---%b%b= I =%b%b\{~~~\}%b%b |%r |%b%b%b%b%b%b%b%b ---%b%b%b%b[if(v(active),[ansi(hc,ON%b)],[ansi(r,OFF)])]%b%b%b \,%r |_________...________ \,"%r)]
@set Master Comlink Parent <MCP>/DESCRIBE=no_command visual prefixmatch public nearby
&ENCKEY Master Comlink Parent <MCP>=
&ENCRYPTION Master Comlink Parent <MCP>=0
&FN_FILECLEAR Master Comlink Parent <MCP>=switch([t(v(DATA_%0))],0,[ansi(hr,-%b)][name(me)] does not know that file.,[wipe(me/DATA_%0)][ansi(hg,-%b)][name(me)] cleared the contents of file [ansi(hg,[capstr(%0)])].)
&FN_FILELIST Master Comlink Parent <MCP>=[ansi(w,%b%b_nn____________________%r |_|__________________ |_|%r | \,-------------------\, |%r | |[center([ansi(r,- Files -)],19)]| |%r[iter(lcstr(lattr(me/data*)),%b|%b|[ansi(c,[left(ljust(capstr(after(itext(0),_)),19),19)])]|%b|%r,,)] | `-------------------' |%r |__________..._______ \,"%r)]
&FN_FILESET Master Comlink Parent <MCP>=[setq(0,capstr(first(%0)))][switch([not(match(v(reserved),%q0))][cor(lt(words(lattr(me/data*)),v(max_files)),v(data_%q0))][lte(strlen(%q0),30)][gt(words(%0),1)],0*,[ansi(hr,-%b)]Please choose a different filename.,10*,[ansi(hr,-%b)]The maximum number of files for [name(me)] have been reached.,110*,[ansi(hr,-%b)]Filenames may only be up to 30 characters in length.,1110,[ansi(hr,-%b)]What content do you wish to set in that file?,1111,[set(me,DATA_[%q0]:[after(escape(rest(%0)),\\)])][ansi(hg,-%b)][name(me)] set file [ansi(hg,%q0)] with new data.)]
&FN_FILESHOW Master Comlink Parent <MCP>=[switch(t(v(data_%0)),0,[ansi(hr,-%b)][name(me)] does not know that file.,1,.[ansi(hg,repeat(-,77))].%r[ansi(hg,|)][center([name(me)] ComData File: [ansi(hg,setr(0,capstr(%0)))],77)][ansi(hg,|)]%r[ansi(hg,=[repeat(-,77)]=)]%r[align(1. 77 1.,ansi(hg,|),u(data_%q0),ansi(hg,|),%b,)]%r[ansi(hg,=[repeat(-,77)]=)])]
&FN_FILEUPLINK Master Comlink Parent <MCP>=switch([isdbref(setr(0,locate(%#,*[edit(first(%0),*,)],Pp)))][t(v(data_[setr(1,capstr(last(%0)))]))],0*,[ansi(hr,-%b)][name(me)] could not find that player to establish a link.,10,[ansi(hr,-%b)][name(me)] found the player to uplink\, but not a valid file.,11,[iter(lcon(%q0),if(and(hasattrpval(itext(0),mcpver),not(%q2)),setq(2,itext(0))),,)][switch([t(%q2)][xget(%q2,active)],0*,[ansi(hr,-%b)][name(me)] could not find [name(%q0)]'s Comlink.,10,[ansi(hr,-%b)][name(%q0)]'s Comlink is not active.[pemit(%q0,[ansi(hr,-%b)]%N fails to send a file because your Comlink is not on.)],11,[ansi(hg,-%b)]Link established with [name(%q0)].[remit(%L,%N fingers the keys on %p Comlink, directed at [name(%q0)].)]%r[set(%q2,data_[%q1]:[v(data_%q1)])][ansi(hg,-%b)]Sending file: [ansi(hg,%q1)]...[pemit(%q0,[ansi(hg,-%b)]%N sends file %q1 to your Comlink.)]%r[ansi(hg,-%b)]Link with [name(%q0)] closed.,[ansi(hr,-%b)]Critical error.)])
&FN_HELP Master Comlink Parent <MCP>=[ansi(hr,com)] [ansi(hb,<message>)] - Sends your message to whatever your Comlink's broadcast paramter is set to. Your callsign will be prefixed to each message (the &callsign attribute attached to yourself.)%r[ansi(hr,comset)] [ansi(hb,<on/off>)] - Toggles the Comlink's power.%r[ansi(hr,comset broadcast)] [ansi(hb,<channel>)] - Sets your Comlink's broadcast frequency. You must be receiving on that channel first.%r[ansi(hr,comset)] [ansi(hb,<slot> <channel>)] - Sets one of your Comlink's receiving slots to a channel you specify. There are a max of [v(max_slots)] slots.%r[ansi(hr,comset timestamp)] - Toggles the timestamp on incoming messages.%r[ansi(hr,comset reset)] - Will erase all of the unit's channel and user settings.%r[ansi(hr,comset key)] [ansi(hb,<key>)] - Sets the key used to encrypt your outgoing messages, and decrypt all incoming messages from others. If you have set a key that does not match the key used to encrypt an incoming message (or if the incoming message wasn't encrypted in the first place), you will see garbage. You can also set a blank key for no encryption.%r[ansi(hr,comset encryption)] - Toggles the device's ability to encrypt messages. Use this to turn it off if you don't want to set a blank encryption key.%r[ansi(hr,comdata set)] [ansi(hb,<filename> <contents>)] - Saves a file <filename> with <contents> into this unit.%r[ansi(hr,comdata clear)] [ansi(hb,<filename>)] - Erases <filename> from this unit.%r[ansi(hr,comdata list)] - Will show all files stored in this unit.%r[ansi(hr,comdata uplink)] [ansi(hb,<player> <filename>)] - Will send the contents of the specified file to <player>, who must be in the same room as you and have his own Comlink. The data sent will have the same filename as on this unit.
&FN_HS_LOC Master Comlink Parent <MCP>=switch(match(xget(v(user),hspace_location),switch([hasflag(zone(loc(v(user))),hspace_object)][hasflag(xget(loc(v(user)),hspace_location),hspace_object)],1*,zone(loc(v(user))),01,xget(loc(v(user)),hspace_location))),1,xget(v(user),hspace_location),0)
&FN_LIST Master Comlink Parent <MCP>=[ansi(w,%b%b_nn____________________%r |_|__________________ |_|%r | \,-------------------\, |%r | |[center([ansi(r,- Files -)],19)]| |%r[iter(lcstr(lattr(me/data*)),%b|%b|[ansi(c,[left(ljust(capstr(after(itext(0),_)),19),19)])]|%b|%r,,)] | `-------------------' |%r |__________..._______ \,"%r)]
&FN_MANGLE Master Comlink Parent <MCP>=if(setr(j,val(%1)),iter(%0,if(lt(rand(10),max(0,%qj)),repeat(.,add(rand(5),2)),itext(0))),%0)
&FN_POWEROFF Master Comlink Parent <MCP>=if(not(v(active)),[ansi(hr,-%b)][name(me)] is already inactive.,[set(me,active:0)][set(me,user:%#)][ansi(hg,-%b)]You turn [name(me)] off.)
&FN_POWERON Master Comlink Parent <MCP>=if(v(active),[ansi(hr,-%b)][name(me)] is already active.,[set(me,active:1)][set(me,user:%#)][ansi(hg,-%b)]You turn [name(me)] on.)
&FN_RESET Master Comlink Parent <MCP>=[set(me,active:[v(active)])][set(me,user:[loc(me)])][set(me,obstruction_level:[v(obstruction_level)])][set(me,enckey:)][set(me,encryption:0)][set(me,comm_broadcast:-)][set(me,comm_frqs:[repeat(-%b,v(max_slots))])][set(me,comm_handler:[xget(last(lparent(me)),comm_handler)])][set(me,uid:[v(uid)])][set(me,x:[v(x)])][set(me,y:[v(y)])][set(me,z:[v(z)])][set(me,timestamp:0)][if(gt(words(lparent(me)),1),lock(me/use,loc(me)))][ansi(hg,-%b)]Parameters for [name(me)] have been reset.
&FN_SET Master Comlink Parent <MCP>=[setq(0,capstr(first(%0)))][switch([not(match(v(reserved),%q0))][cor(lt(words(lattr(me/data*)),v(max_files)),v(data_%q0))][lte(strlen(%q0),30)][gt(words(%0),1)],0*,[ansi(hr,-%b)]Please choose a different filename.,10*,[ansi(hr,-%b)]The maximum number of files for [name(me)] have been reached.,110*,[ansi(hr,-%b)]Filenames may only be up to 30 characters in length.,1110,[ansi(hr,-%b)]What content do you wish to set in that file?,1111,[set(me,DATA_[%q0]:[after(escape(rest(%0)),\\)])][ansi(hg,-%b)][name(me)] set file [ansi(hg,%q0)] with new data.)]
&FN_SETBROADCAST Master Comlink Parent <MCP>=[setq(0,[rjust(trim(before(rest(%0),.),0,l),3,0)].[rjust(after(rest(%0),.),2,0)])][if(match(v(comm_frqs),%q0),[set(me,comm_broadcast:%q0)][ansi(hg,-%b)]Messages will now broadcast to channel: [ansi(hg,%q0)],[ansi(hr,-%b)]You must be receiving on a channel before you can broadcast to it.)]
&FN_SETENCRYPTION Master Comlink Parent <MCP>=[set(me,encryption:[if(v(encryption),0,1)])][ansi(hg,-%b)]Encryption is now [if(v(encryption),en,dis)]abled.
&FN_SETKEY Master Comlink Parent <MCP>=[set(me,enckey:%0)][ansi(hg,-%b)][name(me)] encryption key set... [ansi(hg,%0)]
&FN_SETRECEIVE Master Comlink Parent <MCP>=[setq(0,first(%0))][setq(1,trim(rest(%0),0,l))][switch([mul(gte(%q0,1),lte(%q0,v(max_slots)))][mul([isnum(%q1)],[gt(%q1,0)],[lt(%q1,v(max_frq))],[lte(strlen(setr(2,after(%q1,.))),2)])],0*,[ansi(hr,-%b)]Please choose a receiving slot between 1 and [v(max_slots)],10,[ansi(hr,-%b)]Please choose a frequency between 0.0 and [v(max_frq)] with two digits of precision.,11,if(eq(words(v(comm_frqs)),v(max_slots)),[set(me,comm_frqs:[replace(v(comm_frqs),%q0,[rjust(before(%q1,.),3,0)].[rjust(%q2,2,0)])])][ansi(hg,-%b)]Comlink incoming slot [ansi(hg,%q0)] is set to: [ansi(hg,[rjust(before(%q1,.),3,0)].[rjust(%q2,2,0)])],[ansi(hr,-%b)]Please use [ansi(hg,comset reset)] to reconfigure [name(me)].),[ansi(hr,-%b)][name(me)] does not understand the parameters you wish to set.)]
&FN_SETTIMESTAMP Master Comlink Parent <MCP>=[if(v(timestamp),[set(me,timestamp:0)][ansi(hg,-%b)]Timestamps are now disbaled.,[set(me,timestamp:1)][ansi(hg,-%b)]Timestamps are now enabled.)]
&FN_SHOW Master Comlink Parent <MCP>=[switch(t(v(data_%0)),0,[ansi(hr,-%b)][name(me)] does not know that file.,1,.[ansi(hg,repeat(-,77))].%r[ansi(hg,|)][center([name(me)] ComData File: [ansi(hg,setr(0,capstr(%0)))],77)][ansi(hg,|)]%r[ansi(hg,=[repeat(-,77)]=)]%r[iter(setr(1,wrap(edit(u(data_%q0),%t,repeat(%b,8)),77)),[ansi(hg,|)][ljust(itext(0),sub(78,add(not(strlen(extract(%q1,inc(inum(0)),1,%r))),not(strlen(itext(0))))))][ansi(hg,|)],%r,%r)]%r[ansi(hg,=[repeat(-,77)]=)])]
&FN_UID Master Comlink Parent <MCP>=if(u(fn_hs_loc),hs_get_attr(u(fn_hs_loc),uid),0)
&FN_UPLINK Master Comlink Parent <MCP>=switch([isdbref(setr(0,locate(%#,*[edit(first(%0),*,)],Pp)))][t(v(data_[setr(1,capstr(last(%0)))]))],0*,[ansi(hr,-%b)][name(me)] could not find that player to establish a link.,10,[ansi(hr,-%b)][name(me)] found the player to uplink\, but not a valid file.,11,[iter(lcon(%q0),if(and(hasattrpval(itext(0),mcpver),not(%q2)),setq(2,itext(0))),,)][switch([t(%q2)][xget(%q2,active)],0*,[ansi(hr,-%b)][name(me)] could not find [name(%q0)]'s Comlink.,10,[ansi(hr,-%b)][name(%q0)]'s Comlink is not active.[pemit(%q0,[ansi(hr,-%b)]%N fails to send a file because your Comlink is not on.)],11,[ansi(hg,-%b)]Link established with [name(%q0)].[remit(%L,%N fingers the keys on %p Comlink, directed at [name(%q0)].)]%r[set(%q2,data_[%q1]:[v(data_%q1)])][ansi(hg,-%b)]Sending file: [ansi(hg,%q1)]...[pemit(%q0,[ansi(hg,-%b)]%N sends file %q1 to your Comlink.)]%r[ansi(hg,-%b)]Link with [name(%q0)] closed.,[ansi(hr,-%b)]Critical error.)])
&FN_X Master Comlink Parent <MCP>=if(u(fn_hs_loc),hs_get_attr(u(fn_hs_loc),x),0)
&FN_Y Master Comlink Parent <MCP>=if(u(fn_hs_loc),hs_get_attr(u(fn_hs_loc),y),0)
&FN_Z Master Comlink Parent <MCP>=if(u(fn_hs_loc),hs_get_attr(u(fn_hs_loc),z),0)
&MAX_FILES Master Comlink Parent <MCP>=100
&MAX_FRQ Master Comlink Parent <MCP>=10000.00
&MAX_SLOTS Master Comlink Parent <MCP>=6
&MCPVER Master Comlink Parent <MCP>=2.0
&OBSTRUCTION_LEVEL Master Comlink Parent <MCP>=0
&RANGE Master Comlink Parent <MCP>=5
&RESERVED Master Comlink Parent <MCP>=Set Clear Uplink List
&TIMESTAMP Master Comlink Parent <MCP>=0
&UID Master Comlink Parent <MCP>=u(fn_uid)
&USER Master Comlink Parent <MCP>=
&X Master Comlink Parent <MCP>=u(fn_x)
&Y Master Comlink Parent <MCP>=u(fn_y)
&Z Master Comlink Parent <MCP>=u(fn_z)
