Module Cmd
In: cmd/teensy/cmd_chat.rb
cmd/teensy/cmd_color.rb
cmd/teensy/cmd_drop.rb
cmd/teensy/cmd_dumpcache.rb
cmd/teensy/cmd_edit.rb
cmd/teensy/cmd_emote.rb
cmd/teensy/cmd_gc.rb
cmd/teensy/cmd_get.rb
cmd/teensy/cmd_go.rb
cmd/teensy/cmd_hello.rb
cmd/teensy/cmd_help.rb
cmd/teensy/cmd_inv.rb
cmd/teensy/cmd_kill.rb
cmd/teensy/cmd_look.rb
cmd/teensy/cmd_memstats.rb
cmd/teensy/cmd_object.rb
cmd/teensy/cmd_quit.rb
cmd/teensy/cmd_reload.rb
cmd/teensy/cmd_room.rb
cmd/teensy/cmd_say.rb
cmd/teensy/cmd_script.rb
cmd/teensy/cmd_set.rb
cmd/teensy/cmd_show.rb
cmd/teensy/cmd_shutdown.rb
cmd/teensy/cmd_stats.rb
cmd/teensy/cmd_status.rb
cmd/teensy/cmd_trigger.rb
cmd/teensy/cmd_who.rb
cmd/tiny/cmd_get.rb
cmd/tiny/cmd_shutdown.rb
Cmd
dot/f_62.png
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.

Methods

Public Instance methods

sends <message> to all characters in the game

[Source]

# 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

toggles colors on or off

[Source]

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

drops all objects in your inventory into the room

[Source]

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

Look command displays the contents of a room

[Source]

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

@edits a string field on an object Syntax:

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

(ex. @edit 1 desc

[Source]

# File cmd/teensy/cmd_edit.rb, line 20
  def cmd_edit(args)
    case args
    when nil, ""
      sendto("What??")
    when /sysmsg\s+(\w+)/
      @mode = :edit
      @editobj = world.msgs
      @editfield = $1.intern
      @editstr = world.msgs[$1.intern] || ''
      sendto(edit_display(@editstr))
    when /#(\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

sends <message> to all characters in the room

[Source]

# 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

This command runs garbage collection

[Source]

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

gets all objects in the room into your inventory

[Source]

# File cmd/tiny/cmd_get.rb, line 16
  def cmd_get(args)
    get_object(location).objects.each do |q|
      add_event(id,q.id,:get)
    end
  end

gets all objects in the room into your inventory

[Source]

# 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

sends <message> to all characters in the room

[Source]

# 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(/;/).grep(/^#{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

The hello social command

[Source]

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

The help command

[Source]

# 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

The inventory command

[Source]

# 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

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

[Source]

# 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

Look command displays the contents of a room

[Source]

# 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

The memory stats command

[Source]

# File cmd/teensy/cmd_memstats.rb, line 16
  def cmd_memstats(args)
    sendto(world.memstats)
  end

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

[Source]

# File cmd/teensy/cmd_object.rb, line 16
  def cmd_object(args)
    case args
    when /(.*)/
      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

The quit command

[Source]

# File cmd/teensy/cmd_quit.rb, line 16
  def cmd_quit(args)
    @account.disconnect
  end

This reloads the commands

[Source]

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

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

[Source]

# File cmd/teensy/cmd_room.rb, line 17
  def cmd_room(args)
    case args
    when /(.*) (.*) (.*)/
      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

sends <message> to all characters in the room

[Source]

# 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

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 )

[Source]

# File cmd/teensy/cmd_script.rb, line 22
  def cmd_script(args)
    case args
    when /del\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 /add\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 /show\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

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.)

[Source]

# File cmd/teensy/cmd_set.rb, line 21
  def cmd_set(args)
    case args
    when nil, ""
      sendto("What??")
    when /desc\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 /key\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 /timer\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 =~ /(\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 =~ /(\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

displays object Syntax:

  @show #<oid>|me

(ex. @show me)

[Source]

# File cmd/teensy/cmd_show.rb, line 19
  def cmd_show(args)
    case args
    when /#(\d+)/
      sendto(get_object($1.to_i).inspect)
    when /me/
      sendto(get_object(id).inspect)
    else
      sendto("What??")
    end
  end

The shutdown command

[Source]

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

The shutdown command

[Source]

# File cmd/tiny/cmd_shutdown.rb, line 16
  def cmd_shutdown(args)
    if world.is_admin? id
      log.info "Shutdown by '#{name}'"
      Engine.instance.shutdown = true
    else
      sendto "You do not have the authority to shutdown the server."
    end
  end

The database stats command

[Source]

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

displays session information

[Source]

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

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)

[Source]

# File cmd/teensy/cmd_trigger.rb, line 21
  def cmd_trigger(args)
    case args
    when nil, ""
      sendto("What??")
    when /del\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 /add\s+#(\d+)\s+#(\d+)\s+(\w+)/i
      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 /show\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

shows a list of all connected characters

[Source]

# 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

[Source]

# File cmd/teensy/cmd_edit.rb, line 55
  def edit_display(str)
    header ="======== Teensy String Editor ========\n   Type .h on a new line for help\n Terminate with a @ on a blank line.\n======================================\n"
    i = 0
    header + str.gsub(/^/){"#{i+=1}: "}
  end

[Source]

# File cmd/teensy/cmd_edit.rb, line 74
  def edit_parser(args)
    case args
    when nil
      sendto("What??")
    when /^\.h/
      sendto "@edit help (commands on blank line):\n.r /old/new/     - replace a substring\n.h               - get help (this info)\n.s               - show string so far\n.ww [width]      - word wrap string (width optional)\n                   defaults to 76\n.c               - clear string so far\n.ld <num>        - delete line <num>\n.li <num> <txt>  - insert <txt> before line <num>\n.lr <num> <txt>  - replace line <num> with <txt>\n@                - end string\n"
    when /^\.c/
      @editstr = ""
    when /^\.s/
      sendto(edit_display(@editstr))
    when /^\.r\s+\/(.+)?\/(.+)?\//
      @editstr.gsub!($1, '\2')
    when /^\.ww\s+(\d+)/, /^\.ww/
      @editstr = word_wrap(@editstr, $1 && $1.to_i > 2 ? $1.to_i : 76 )
    when /^\.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 /^\.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 /^\.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 /^@/
      @mode = nil
      if @editobj.object_id == world.msgs.object_id  # detect sysmsgs
        @editobj.send("[]=", @editfield, @editstr)
      else
        @editobj.send(@editfield+"=", @editstr)
      end
    when /^\./
      sendto "Invalid command."
    else
      @editstr << args << "\n"
    end
  end

[Source]

# File cmd/teensy/cmd_edit.rb, line 67
  def word_wrap(s, len)
    str = s
    str.gsub!(/\n/,' ');str.squeeze!(' ')
    str.gsub!(/(\S{#{len}})(?=\S)/,'\1 ')
    str.scan(/(.{1,#{len}})(?:\s+|$)/).flatten.join("\n")
  end

[Validate]