Radios

The goal of this challenge is to produce a set of radio (or walkie-talkie) objects that are multichannel, multicast devices -- each radio may be tuned to a single frequency at a time, and will receive any broadcast made on the same frequency.

A radio object is different from a chat channel because it is an *object* that can be given, dropped, etc. The radio should have three volume levels: off (nothing received is broadcast), normal (anything received is emitted to the location of the radio, which may be a player), and loud (anything received is emitted to the location of the radio and to the container of the location of the radio).

*Extra challenge*: Make a scanner that can receive multiple frequencies.

*Extra challenge*: Add an encryption system to the radios so that if an encryption key is set, other radios receive garbled text unless they have same encryption key set. The garbled text, ideally, should not be random but text that would actually be susceptible to (human) cryptanalysis.

This coding challenge by: Javelin

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Example of Radio Challenge

This is TinyMUSH 3 code.

Create the User Flag _RADIO (in this case I set it to Marker Flag '4'). This is so you can easily track down all the Radio devices on the game for setting the attribute '&RADIOS' on the Tower object. Given more time, I could figure out a way to get around the permission issues with the children() function instead, without setting every damn thing Inherit... but this works just fine. Don't document the +radio/search command... rename if it you like, use an error check to make sure only wizards use it, use a cronjob, whatever you want to do to make it inaccessable to the average player and such.

Object 1: Radio Tower - Place it in a Room that is not the Master Room, but is only accessible by Wizards. I use a room called 'Treasure Chest' myself. In this case it was object number #1137. That said, you can search and replace this, replacing #1137 with whatever dbref # the Radio Tower is created as.
---
@create Radio Tower=10
&RADIO_SEARCH Radio Tower=$+radio/search:&RADIOS #1137=[search(flags=4)]
@Desc Radio Tower=This Military Grade handheld radio scanner/transmitter looks like it has been through a war or two. Dinged up, scratched, dented, and burned... yet still fully functional. A testament to the ingenuity and endurance of the Soldier's spirit. It has three notches on the volume dial: off, quiet, and loud. As well, there is a ten digit pad for both encryption and frequency input use. Including an additional three buttons for hotswaping frequencies.
&VOLUME_CONTROL Radio Tower=$^\+radio/volume (off|quiet|loud)?.*$:@switch [t([match(off quiet loud,%1)])]=1,{@switch [streq(%1,[get(%!/volume)])]=1,{@pemit %#=%xhRadio:%xn [name(%!)] is already set to [capstr(%1)].},{@pemit %#=%xhRadio:%xn You set [name(%!)]'s volume to [setr(1,[switch(%1,off,Off,quiet,Quiet,loud,Loud)])].;&volume %!=%q1}},{@pemit %#=%xhRadio:%xn The Radio may only be set to 'Off', 'Quiet', 'Loud'}
@set Radio Tower/VOLUME_CONTROL = regexp
&FREQ_CONTROL Radio Tower=$+radio/freq *:@switch [regmatch(%0,\^\(\[0-9\]\)\{1\,2\}\$)]=1,{@pemit %#=%xhRadio:%xn [name(%!)]'s frequency set to %0.;&FREQ %!=%0},{@pemit %#=%xhRadio:%xn %0 is not a valid frequency. Please use a 1 or 2 digit number between 0-99.}
&VOLUME_CHECK Radio Tower=$^\+radio/volume$:@pemit %#=%xhRadio:%xn [name(%!)]'s volume is currently set to [get(%!/volume)].
@set Radio Tower/VOLUME_CHECK = regexp
&FREQ_CHECK Radio Tower=$+radio/freq:@pemit %#=%xhRadio:%xn [name(%!)]'s Current Frequency is [ifelse({[streq([get(%!/scanning)],On)]},{[get(%!/freq)] - You Are Currently Scanning},{[get(%!/freq)]})].
&TALK Radio Tower=$+radio *:@pemit/list/contents [iter([istrue([edit([v(radios)],%!,[null()])],[streq([get(##/freq)],[get(%!/freq)])])],[switch([get(##/volume)],quiet,[loc(##)],loud,[room(##)],off,[null()])])]=%xhRadio:%xn %N speaks over frequency '[get(%!/freq)]': %0;@pemit %#=%xhRadio:%xy You speak over the radio:%xn %0
&RADIOS Radio Tower=#1 #2 #3 #4 #etc...
&CODE_CONTROL Radio Tower=$+radio/code *:@switch [regmatch(%0,\^\(\[A-Za-z0-9\]\)\{5\,10\}\(Off\)\?\$)]=1,{@switch %0=Off,{%xhRadio:%xn %!'s Cryptography turned off.},{@pemit %#=%xhRadio:%xn [name(%!)]'s Cryptographic Code set to %0.;&CODE %!=%0}},{@pemit %#=%xhRadio:%xn %0 is not a valid Cryptography code. Please use a 5 to 10 character alphanumeric code. Enter 'off' to turn off the Encryption/Decryption.}
&CODE_CHECK Radio Tower=$+radio/code:@pemit %#=%xhRadio:%xn [name(%!)]'s [switch([get(%!/code)],Off,{Cryptography is Currently Off.},{Current Cryptographic Code is [get(%!/code)].})]
&TALK_CRYPTO Radio Tower=$+radio/e *:@iter [istrue([edit([v(radios)],%!,[null()])],[streq([get(##/freq)],[get(%!/freq)])])]={@pemit/list/contents [switch([get(##/volume)],quiet,[loc(##)],loud,[room(##)],off,[null()])]=%xhRadio:%xn [decrypt([encrypt(%N,[get(##/code)])],[get(%!/code)])] speaks over frequency '[get(%!/freq)]': [decrypt([encrypt(%0,[get(##/code)])],[get(%!/code)])]};@pemit %#=%xhRadio:%xy You speak over the radio using Encryption Code '[get(%!/code)]':%xn %0
&SCAN_CONTROL Radio Tower=$+radio/scan *:@switch [regmatch(%0,\^\(On\|Off\|on\|off\)\?\$)]=1,{@pemit %#=%xhRadio:%xn [name(%!)] Scanning Mode set to '[capstr(%0)]';&scanning %!=[capstr(%0)];@switch %0=on,{@cron %!/radio_cron=0-59 * * * *},off,{@crondel %!/radio_cron}},{@pemit %#=%xhRadio:%xn You can only set Scanning to 'on' or 'off'.}
&SCAN_CHECK Radio Tower=$+radio/scan:@pemit %#=%xhRadio:%xn [name(%!)] is Currently [ifelse({[streq([get(%!/scanning)],On)]},{Scanning},{Not Scanning})].
&RADIO_CRON Radio Tower=&freq %!=[ifelse([lt([get(%!/freq)],99)],[add([get(%!/freq)],1)],0)]
@asucc #1137=@lock/uselock %!=%#
@adrop #1137=@lock/uselock %!=%!
@set Radio Tower=INHERIT
@set Radio Tower=PARENT_OK
@set Radio Tower=SAFE
---

Object 2: Radios - I have created 3 myself, but you can create as many as your MU* base will support sending to at once. These are the objects that are carried around.
They can talk (+radio [text]).

They have all the volume options. Quiet, Loud, Off (+radio/volume quiet|loud|off).

It can be set to a specific frequency (+radio/freq [1 or 2 digit number])

It can scan through frequencies at one per minute (+radio/scan on|off).

It can utilize encryption (+radio/code [5-9 character alphanumeric code]) (+radio/e [text])

If the Radio is on at all, and is located directly in a room (rather than in a character's inventory), anyone in the room can hear messages coming through it. Encryption of course still applies.

Replace the '1' here with whatever number radio you're creating.
When you've created all the radios you want, run the +radio/search command (or however you've set up that particular function of the tower).
---
@create Radio 1=300
&VOLUME Radio 1=Off
&FREQ Radio 1=1
&CODE Radio 1=00000
&SCANNING Radio 1=On
@lock/uselock Radio 1=Radio 1
@set Radio 1=SAFE
@set Radio 1=COMMANDS
@set Radio 1=_RADIO
@parent Radio 1=#1137
---

Well, that seems to be it. The challenge with both 'extras'. I had fun working this out as my first challenge. I think there maybe some securing issues that could be resolved through use of certain @locks and such. That is probably one failing I tend to have in my code, making it 100% secure against abuse.

Milamber@Gateway(OGR) and Heart of the Wyld(My MUSH :) )
elraver@yahoo.com

Nice work!

Great example of addressing a challenge! For the curious, the code ought to work pretty much fine in PennMUSH, too, other than the ansi via %x, the slightly different approach to creating new flags (although you could create a _RADIO flag with '4' as its alias, I think) and the need for a Penn wiz object to be set WIZARD, rather than owned by a wizard and set INHERIT.

Thanks. I know about as much

Thanks. I know about as much about PennMUSH and what is different about it from TinyMUSH3 as I do about Nuclear Physics... maybe less.

That said, there are some issues in my own code there I'd probably address, now that it isn't 6:00am in the morning. :)

Such as removing the RegExp command matching (not the RegMatch functions, but the commands themselves. The ones I used could easily have been a normal wildcard (*) match. Originally the intention was to have the control of 0-99 for frequency and such right in the command. But as I remembered too late, it seems to be impossible to do proper error matching when you use a RegExp command attribute. Anyone know how to do this? The [^abc] option doesn't seem to work as [^(abc)], so I don't know how to do a second RegExp command that works exclusively for catching errors. Is this possible?

Mil

Lookahead assertions

Look through the regex or pcre help files for the bits about zero-width positive and negative lookahead assertions, which I believe can do what you want.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.