module Cmd

file

cmd_chat.rb

author

Jon A. Lambert

version

2.3.0

date

08/31/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_color.rb

author

Jon A. Lambert

version

2.5.3

date

09/21/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_drop.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_dumpcache.rb

author

Jon A. Lambert

version

2.7.0

date

01/13/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_edit.rb

author

Jon A. Lambert

version

2.10.0

date

06/25/2006

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_emote.rb

author

Jon A. Lambert

version

2.4.0

date

09/12/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_gc.rb

author

Jon A. Lambert

version

2.9.0

date

03/15/2006

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_get.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_go.rb

author

Jon A. Lambert

version

2.10.0

date

06/27/2006

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_hello.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_help.rb

author

Jon A. Lambert

version

2.4.0

date

09/12/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_inv.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_kill.rb

author

Jon A. Lambert

version

2.3.0

date

08/31/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_look.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_memstats.rb

author

Jon A. Lambert

version

2.7.0

date

01/13/2006

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_object.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_quit.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_reload.rb

author

Jon A. Lambert

version

2.4.0

date

09/12/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_room.rb

author

Jon A. Lambert

version

2.10.0

date

06/25/2006

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_say.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_script.rb

author

Jon A. Lambert

version

2.8.0

date

02/21/2005

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_set.rb

author

Jon A. Lambert

version

2.8.0

date

02/21/2005

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_show.rb

author

Jon A. Lambert

version

2.9.0

date

03/10/2006

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_shutdown.rb

author

Jon A. Lambert

version

2.8.0

date

01/19/2006

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_stats.rb

author

Jon A. Lambert

version

2.7.0

date

01/13/2006

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_status.rb

author

Jon A. Lambert

version

2.5.3

date

09/21/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_trigger.rb

author

Jon A. Lambert

version

2.8.0

date

02/21/2005

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_who.rb

author

Jon A. Lambert

version

2.3.0

date

08/31/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_get.rb

author

Jon A. Lambert

version

2.2.0

date

08/29/2005

This source code copyright (C) 2005 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

file

cmd_shutdown.rb

author

Jon A. Lambert

version

2.9.0

date

01/19/2006

This source code copyright (C) 2005, 2006 by Jon A. Lambert All rights reserved.

Released under the terms of the TeensyMUD Public License See LICENSE file for additional information.

Public Instance Methods

cmd_chat(args) click to toggle source

sends <message> to all characters in the game

# File cmd/teensy/cmd_chat.rb, line 16
def cmd_chat(args)
  case args
  when nil, ""
    sendto("What are you trying to tell everyone?")
  else
    sendto("[COLOR Magenta]You chat, \"#{args}\".[/COLOR]")
    world.connected_characters.each do |pid|
      if id != pid
        add_event(id,pid,:show,
          "[COLOR Magenta]#{name} chats, \"#{args}\".[/COLOR]")
      end
    end
  end
end
cmd_color(args) click to toggle source

toggles colors on or off

# File cmd/teensy/cmd_color.rb, line 16
def cmd_color(args)
  sendto @account.toggle_color
end
cmd_drop(args) click to toggle source

drops all objects in your inventory into the room

# File cmd/teensy/cmd_drop.rb, line 16
def cmd_drop(args)
  objects.each do |q|
    add_event(id,q.id,:drop)
  end
end
cmd_dumpcache(args) click to toggle source

Look command displays the contents of a room

# File cmd/teensy/cmd_dumpcache.rb, line 16
def cmd_dumpcache(args)
  sendto(Engine.instance.db.inspect)
end
cmd_edit(args) click to toggle source

@edits a string field on an object Syntax:

@edit #<id> <field>
@edit sysmsg <field>

(ex. @edit #1 desc

# File cmd/teensy/cmd_edit.rb, line 20
def cmd_edit(args)
  case args
  when nil, ""
    sendto("What??")
  when %rsysmsg\s+(\w+)/
    @mode = :edit
    @editobj = world.msgs
    @editfield = $1.intern
    @editstr = world.msgs[$1.intern] || ''
    sendto(edit_display(@editstr))
  when %r#(\d+)\s+(\w+)/
    o = get_object($1.to_i)
    case o
    when GameObject, Room, Character, Script, Exit
      if o.respond_to?($2) &&
         o.respond_to?("#$2=") &&
         o.send($2).class == String

        @mode = :edit
        @editobj = o
        @editfield = $2
        @editstr = o.send $2

        sendto(edit_display(@editstr))
      else
        sendto("Field #$2 not found on object.")
      end
    else
      sendto("No object.")
    end
  else
    sendto("What??")
  end
end
cmd_emote(args) click to toggle source

sends <message> to all characters in the room

# File cmd/teensy/cmd_emote.rb, line 16
def cmd_emote(args)
  case args
  when nil, ""
    sendto("What are you trying to emote?")
  else
    sendto("You #{args}.")
    get_object(location).characters(id).each do |p|
      add_event(id,p.id,:show,"#{name} #{args}.")
    end
  end
end
cmd_gc(args) click to toggle source

This command runs garbage collection

# File cmd/teensy/cmd_gc.rb, line 16
def cmd_gc(args)
  GC.start
  sendto("Garbage collector run")
end
cmd_get(args) click to toggle source

gets all objects in the room into your inventory

# File cmd/teensy/cmd_get.rb, line 16
def cmd_get(args)
  get_object(location).objects.each do |q|
    add_event(id,q.id,:get)
  end
end
cmd_go(args) click to toggle source

sends <message> to all characters in the room

# File cmd/teensy/cmd_go.rb, line 16
def cmd_go(args)
  case args
  when nil, ""
    sendto("Where do you want to go?")
  else
    ex = []
    ext = nil
    get_object(location).exits.each do |exid|
      ext = get_object(exid)
      ex = ext.name.split(%r;/).grep(%r^#{args}/)
      break if !ex.empty?
    end
    if ex.empty?
      sendto("Can't find that place")
    elsif ex.size > 1
      ln = "Which did you mean, "
      ex.each {|x| ln << "\'" << x << "\' "}
      ln << "?"
      sendto(ln)
    else
      add_event(id,ext.id,:leave, args)
    end
  end
end
cmd_hello(args) click to toggle source

The hello social command

# File cmd/teensy/cmd_hello.rb, line 16
def cmd_hello(args)
  parse("say hello")
end
cmd_help(args) click to toggle source

The help command

# File cmd/teensy/cmd_help.rb, line 16
def cmd_help(args)
  case args
  when nil, ""
    sendto("====================HELP=======================")
    world.cmds.to_hash.values.each do |h|
      sendto(sprintf("%-10s - %s", h.name, h.help))
    end
  else
    q = world.cmds.find(args)
    if q
      sendto("====================HELP=======================")
      q.each do |h|
        sendto(sprintf("%-10s - %s", h.name, h.help))
      end
    else
      sendto "No help on that."
    end
  end
end
cmd_inv(args) click to toggle source

The inventory command

# File cmd/teensy/cmd_inv.rb, line 16
def cmd_inv(args)
  sendto("=== Inventory ===")
  objects.each do |x|
    add_event(id,x.id,:describe)
  end
end
cmd_kill(args) click to toggle source

This kills a character anywhere - it’s link death (30% chance)

# File cmd/teensy/cmd_kill.rb, line 16
def cmd_kill(args)
  case args
  when nil, ""
    sendto("Who do you want to kill?")
  else
    d = world.all_characters.find {|pid| args == get_object(pid).name }
    if !d
      sendto("Can't find them.")
      return
    end
    d = get_object(d)  # get object
    if rand < 0.3
      sendto("You kill #{d.name}.")
      world.connected_characters.each {|pid|
        if pid != id
          add_event(id,pid,:show,"#{name} kills #{d.name}.")
        end
      }
      d.account.disconnect("You have been pwn3d!")
      # delete_object(d)  Dont delete character, it's annoying
    else
      sendto("You attacks and misses #{d.name}.")
      world.connected_characters.each {|pid|
        if pid != id
          add_event(id,pid,:show,"#{name} attacks and misses #{d.name}.")
        end
      }
    end
  end
end
cmd_look(args) click to toggle source

Look command displays the contents of a room

# File cmd/teensy/cmd_look.rb, line 16
def cmd_look(args)
  place = get_object(location)
  add_event(id,location,:describe)
  place.objects.each do |x|
    add_event(id,x.id,:describe)
  end
  place.characters(id).each do |x|
    add_event(id,x.id,:describe)
  end
  add_event(id,location,:describe_exits)
end
cmd_memstats(args) click to toggle source

The memory stats command

# File cmd/teensy/cmd_memstats.rb, line 16
def cmd_memstats(args)
  sendto(world.memstats)
end
cmd_object(args) click to toggle source

sets the description for an object (ex. @set #1 A beautiful rose.)

# File cmd/teensy/cmd_object.rb, line 16
def cmd_object(args)
  case args
  when %r(.*)/
    newobj = GameObject.new($1, id, location)
    if newobj.nil?
      log.error "Unable to create object."
      sendto "System error: unable to create object."
      return
    end
    put_object(newobj)
    get_object(location).add_contents(newobj.id)
    sendto "Ok."
  else
    sendto("What!!?")
  end
end
cmd_quit(args) click to toggle source

The quit command

# File cmd/teensy/cmd_quit.rb, line 16
def cmd_quit(args)
  @account.disconnect
end
cmd_reload(args) click to toggle source

This reloads the commands

# File cmd/teensy/cmd_reload.rb, line 16
def cmd_reload(args)
  world.cmds, world.ocmds = Command.load
  sendto("Command table reloaded.")
end
cmd_room(args) click to toggle source

creates a new room and autolinks the exits using the exit names provided. (ex. @room My Room north south)

# File cmd/teensy/cmd_room.rb, line 17
def cmd_room(args)
  case args
  when %r(.*) (.*) (.*)/
    d=Room.new($1, id)
    if d.nil?
      log.error "Unable to create room."
      sendto "System error: unable to create room."
      return
    end
    put_object(d)
    curr = get_object(location)
    e1 = Exit.new($2, id, curr.id, d.id)
    curr.exits << e1.id
    put_object(e1)
    e2 = Exit.new($3, id, d.id, curr.id)
    d.exits << e2.id
    put_object(e2)
    sendto("Ok.")
  else
    sendto("say what??")
  end
end
cmd_say(args) click to toggle source

sends <message> to all characters in the room

# File cmd/teensy/cmd_say.rb, line 16
def cmd_say(args)
  case args
  when nil, ""
    sendto("What are you trying to say?")
  else
    sendto("You say, \"#{args}\".")
    get_object(location).characters(id).each do |p|
      add_event(id,p.id,:show,"#{name} says, \"#{args}\".")
    end
  end
end
cmd_script(args) click to toggle source

adds, deletes, lists, or a script Syntax:

@script add <lang> <progname>|<code>
@script del #<scriptid>
@script show #<scriptid>

(ex. @script add fart myprog) (ex. @script add boolexp #234|#42&#34 )

# File cmd/teensy/cmd_script.rb, line 22
def cmd_script(args)
  case args
  when %rdel\s+#(\d+)/
    s = get_object($1.to_i)
    case s
    when Script
      delete_object(s.id)
      sendto("Script #$1 deleted.")
    else
      sendto("No script.")
    end
  when %radd\s+(\w+)\s+(.*)/
    case $1.intern
    when :fart
      s = Script.new($2.strip, id, $1.intern)
      put_object(s)
      sendto("Script #{s.id} added.")
    when :boolexp
      s = Script.new(nil, id, $1.intern)
      s.load($2.strip)
      put_object(s)
      sendto("Script #{s.id} added.")
    else
      sendto("No language.")
    end
  when %rshow\s+#(\d+)/
    s = get_object($1.to_i)
    case s
    when Script
      s.load if !s.src
      sendto(s.src)
    else
      sendto("No script.")
    end
  else
    sendto("What??")
  end
end
cmd_set(args) click to toggle source

sets the description or timer for an object Syntax:

@set desc #<id> <description>
@set key #<id> <description>
@set timer #<id> <on|off>

(ex. @set desc #1 A beautiful rose.)

# File cmd/teensy/cmd_set.rb, line 21
def cmd_set(args)
  case args
  when nil, ""
    sendto("What??")
  when %rdesc\s+#(\d+)\s+(.*)/
    o = get_object($1.to_i)
    case o
    when nil, 0
      sendto("No object.")
    else
      o.desc = $2
      sendto("Object #" + $1 + " description set.")
    end
  when %rkey\s+#(\d+)\s+(.*)/
    o = get_object($1.to_i)
    case o
    when nil, 0
      sendto("No object.")
    else
      o.key = $2
      sendto("Object #" + $1 + " key set.")
    end
  when %rtimer\s+#(\d+)\s+(on|off)\s+(.*)/
    o = get_object($1.to_i)
    case o
    when nil
      sendto("No object.")
    else
      if $2 == 'on'
        if $3 =~ %r(\w+)\s+(\d+)/
          world.set_timer(o.id, $1.to_sym, $2.to_i)
          sendto("Object ##{o.id} registered with timer.")
        else
          sendto("Bad symbol or missing time")
        end
      else
        if $3 =~ %r(\w+)/
          world.unset_timer(o.id, $1.to_sym)
          sendto("Object ##{o.id} unregistered with timer.")
        else
          sendto("Bad symbol")
        end
      end
    end
  else
    sendto("What??")
  end
end
cmd_show(args) click to toggle source

displays object Syntax:

@show #<oid>|me

(ex. @show me)

# File cmd/teensy/cmd_show.rb, line 19
def cmd_show(args)
  case args
  when %r#(\d+)/
    sendto(get_object($1.to_i).inspect)
  when %rme/
    sendto(get_object(id).inspect)
  else
    sendto("What??")
  end
end
cmd_shutdown(args) click to toggle source

The shutdown command

# File cmd/teensy/cmd_shutdown.rb, line 16
def cmd_shutdown(args)
  Engine.instance.shutdown = true
end
cmd_stats(args) click to toggle source

The database stats command

# File cmd/teensy/cmd_stats.rb, line 16
def cmd_stats(args)
  sendto(Engine.instance.db.stats)
end
cmd_status(args) click to toggle source

displays session information

# File cmd/teensy/cmd_status.rb, line 16
def cmd_status(args)
  sendto @account.status_rept
end
cmd_trigger(args) click to toggle source

adds, deletes, or shows triggers on an object Syntax:

@trigger add #<id> #<scriptid> <eventtype>
@trigger del #<id> <eventtype>
@trigger show #<id>

(ex. @trigger add #1 myprog arrive)

# File cmd/teensy/cmd_trigger.rb, line 21
def cmd_trigger(args)
  case args
  when nil, ""
    sendto("What??")
  when %rdel\s+#(\d+)\s+(\w+)/
    o = get_object($1.to_i)
    case o
    when GameObject, Room, Character
      if o.get_trigger($2)
        o.delete_trigger($2)
        sendto("Object ##$1 trigger deleted.")
      else
        sendto("Trigger ##$2 not found on object.")
      end
    else
      sendto("No object.")
    end
  when %radd\s+#(\d+)\s+#(\d+)\s+(\w+)/
    o = get_object($1.to_i)
    case o
    when GameObject, Room, Character
      s = get_object($2.to_i)
      case s
      when Script
        o.add_trigger($3, s.id)
        sendto("Object ##$1 trigger added.")
      else
        sendto("No script.")
      end
    else
      sendto("No object.")
    end
  when %rshow\s+#(\d+)/
    o = get_object($1.to_i)
    case o
    when GameObject, Room, Character
      sendto("===========TRIGGERS============")
      sendto(sprintf("%-15s %-15s", "Event", "Program"))
      o.triggers.each do |e, t|
        sendto(sprintf("%-15s #%d", e.id2name, t))
      end
    else
      sendto("No object.")
    end
  else
    sendto("What??")
  end
end
cmd_who(args) click to toggle source

shows a list of all connected characters

# File cmd/teensy/cmd_who.rb, line 16
def cmd_who(args)
  sendto("=== Who List ===")
  world.connected_characters.each {|pid| sendto(get_object(pid).name)}
end
edit_display(str) click to toggle source
# File cmd/teensy/cmd_edit.rb, line 55
  def edit_display(str)
    header ="======== Teensy String Editor ========
   Type .h on a new line for help
 Terminate with a @ on a blank line.
======================================
"
    i = 0
    header + str.gsub(%r^/){"#{i+=1}: "}
  end
edit_parser(args) click to toggle source
# File cmd/teensy/cmd_edit.rb, line 73
  def edit_parser(args)
    case args
    when nil
      sendto("What??")
    when %r^\.h/
      sendto "@edit help (commands on blank line):
.r /old/new/     - replace a substring
.h               - get help (this info)
.s               - show string so far
.ww [width]      - word wrap string (width optional)
                   defaults to 76
.c               - clear string so far
.ld <num>        - delete line <num>
.li <num> <txt>  - insert <txt> before line <num>
.lr <num> <txt>  - replace line <num> with <txt>
@                - end string
"
    when %r^\.c/
      @editstr = ""
    when %r^\.s/
      sendto(edit_display(@editstr))
    when %r^\.r\s+\/(.+)?\/(.+)?\//
      @editstr.gsub!($1, '\2')
    when %r^\.ww\s+(\d+)/, %r^\.ww/
      @editstr = word_wrap(@editstr, $1 && $1.to_i > 2 ? $1.to_i : 76 )
    when %r^\.ld\s+(\d+)/
      idx = $1.to_i
      return if idx < 1
      idx -= 1
      lines = @editstr.split("\n")
      lines.delete_at(idx)
      @editstr = lines.join("\n")
    when %r^\.li\s+(\d+)\s+(.*)?$/
      idx = $1.to_i
      return if idx < 1
      idx -= 1
      nl = $2
      lines = @editstr.split("\n")
      lines.insert(idx, nl + "\n")
      @editstr = lines.join("\n")
    when %r^\.lr\s+(\d+)\s+(.*)?$/
      idx = $1.to_i
      return if idx < 1
      idx -= 1
      nl = $2
      lines = @editstr.split("\n")
      lines[idx] = nl + "\n"
      @editstr = lines.compact.join("\n")
    when %r^@/
      @mode = nil
      if @editobj.object_id == world.msgs.object_id  # detect sysmsgs
        @editobj.send("[]=", @editfield, @editstr)
      else
        @editobj.send(@editfield+"=", @editstr)
      end
    when %r^\./
      sendto "Invalid command."
    else
      @editstr << args << "\n"
    end
  end
word_wrap(s, len) click to toggle source
# File cmd/teensy/cmd_edit.rb, line 66
def word_wrap(s, len)
  str = s
  str.gsub!(%r\n/,' ');str.squeeze!(' ')
  str.gsub!(%r(\S{#{len}})(?=\S)/,'\1 ')
  str.scan(%r(.{1,#{len}})(?:\s+|$)/).flatten.join("\n")
end