TeensyMud - 'A ruby mud server.'

TeensyMud1K

TM1k (teensy mud 1K v4) - 1063 bytes

Package is at t1k4.tgz which is everything on this page.

require 'socket';require 'yaml';def q x;$m.find{|o|o.t==2&&x==o.n};end
def a r,t;$m.find_all{|o|t==o.t&&(!r||r==o.l)};end;def g z;a(nil,2).each{|p|
p.p z};end;class O;attr_accessor :i,:n,:l,:e,:s,:t;def initialize n,l=nil,t=0
@n,@l,@i,@t=n,l,$d+=1,t;@e={};end;def p s;@s.puts(s)if @s;end;def y m
v=$m.find{|o|@l==o.i};t=v.e.keys;case m;when/^q/;@s.close;@s=nil;
File.open('d','w'){|f|YAML::dump $m,f};when/^h/;p "i,l,d,g,c,h,q,<exit>,O,R"
when/^i/;a(@i,1).each{|o|p o.n};when/^c.* (.*)/;g "#{@n}:#{$1}"
when/^g/;a(@l,1).each{|q|q.l=@i};when/^d/;a(@i,1).each{|q|q.l=@l}
when/^O (.*)/;$m<<O.new($1,@l,1);when/^R (.*) (.*) (.*)/;$m<<d=O.new($1)
v.e[$2]=d.i;d.e[$3]=v.i;when/^l/;p v.n;(a(@l,2)+a(@l,1)).each{|x|
p x.n if x.s||x.t==1};p t.join '|';when/(^#{t.empty? ? "\1" : t.join('|^')})/
@l=v.e[$1];else;p "?";end;end;end;if !test ?e,'d';$d=0;$m=[O.new("Home")];else
$m=YAML::load_file 'd';end;$d=$m.size;z=TCPServer.new 0,4000;while k=z.accept
Thread.new(k){|s|s.puts "Name";s.gets;l=$_.chomp;d=q l;$m<<d=O.new(l,1,2)if !d
d.s=s;while s.gets;d.y $_.chomp;end;};end

TM1k (teensy mud 1K v4) - 1063 bytes

This has the features of t1k3 minus the zlib compression, the autolook features, and the combat system. It's over the 1k limit by 39 bytes, but much better at 15 than 27 LOC. Using zlib felt a bit too much like cheating. The reduction in LOC was mostly achieved by collapsing the inheritance scheme into a single object with it's type represented by integers (0 for rooms, 1 for objects and 2 for players - an idea inspired from the original tinymud I should add), unrolling a function or two, and the elimination of many parenthesis, enough so that ruby will issue warnings about them. This also contains a bug fix supplied by Dan Burt, which I've dubbed the medusa bug as it involved turning players into lifeless objects upon looking at them. Strictly speaking one could pare down about 6 bytes (login message/help port number?) and force the user to specify the requires on the command line (i.e. "ruby -rsocket -ryaml t") and be at exactly 1k. Anyway enjoy. :-)

Features are:

To install and run type:

$ tar xzvf t1k4.tgz ; ruby t  

It will boot on port 4000

Help (for the single character impaired)
i = displays player inventory
l = displays the contents of a room
d = drops all objects in your inventory into the room
g = gets all objects in the room into your inventory
c < message > = chat with other players h = displays help
q = quits the game (saves player)
O < object name > = creates a new object (ex. O rose)
R < room name > < exit name to > < exit name back > = creates a new room and autolinks the exits using the exit names provided.
< exit name > = moves player through exit named (ex. south)