# in room object
@script << "@mobs << world.create_mob_index['shire.mob.bilbo']"
# so when the timer for the rooms repop goes off do
room.script.call # or something to that effect
# or using eval?
eval(room.script)
class Operator
attr_reader :glyph, :method, :priority
def initialize(g,m,p)
@glyph, @method, @priority = g,m,p
end
def plus(l,r)
e = l + r
e.to_s
end
def minus(l,r)
e = l - r
e.to_s
end
def times(l,r)
e = l * r
e.to_s
end
def divide(l,r)
e = l / r
e.to_s
end
def assign(l,r)
l = r
l.to_s
end
end
# Test
require 'operator'
operators = [
Operator.new("+", :plus, 1),
Operator.new('-', :minus, 1),
Operator.new('/', :divide, 1),
Operator.new('*', :times, 1),
Operator.new('=', :assign, 2)
]
l = 100
r = 200
operators.each {|e| p l.to_s << " " << e.glyph << " " << r.to_s << " = " << e.send(e.method, l, r)}
OUTPUT:
"100 + 200 = 300"
"100 - 200 = -100"
"100 / 200 = 0"
"100 * 200 = 20000"
"100 = 200 = 200"
require 'pp'
module Kernel
def sandbox
Thread.new {
$SAFE = 4
yield
}.join
end
end
class Monster
attr_accessor :state, :level
def initialize s, l
@state, @level = s, l
end
end
# The test script code
script = <<EOD
obj.state = :attack
obj.level = 20
EOD
obj = Monster.new :alert, 16
pp obj
pp obj.tainted?
# Allow object to be used
obj.taint
sandbox do
eval script
end
# Insert code to check object
pp obj
pp obj.tainted?
# Set object to untainted
obj.untaint
# Script should crash with security error here
sandbox do
eval script
end
obj.taint
sandbox do
@@ eval script
end
I was thinking about using Procs as a sort of script for resets. I dont necessarily mean sandboxing, but it would be an easy way to load game objects. When it comes time to repop,
you could just say "room.reset" which runs that rooms individual script.
I guess the smart thing to do is create a sandbox, but is that really needed when me and my
friends are the only builders?