The World class is the mother of all worlds.
It contains world state information, the world timer, utility functions, and delegates to the Engine.
cmds
is a handle to the character commands table.
ocmds
is a handle to the object commands table.
timer_list
is a list of all installed timer objects (persistent)
all_characters
is a list of all characters (persistent)
timer_list
is a list of all connected characters
Create the World. This loads or creates the database depending on whether it finds it.
return
A handle to the World object.
# File lib/core/world.rb, line 41 def initialize self.timer_list = [] self.all_characters = [] self.all_accounts = [] self.admins = [] self.builders = [] self.msgs = {} @connected_characters = [] end
Make the character an admin
oid
character object id
return
undefined
# File lib/core/world.rb, line 122 def add_admin oid self.admins << oid if Character && !admin?(oid) end
Make the character a builder
oid
character object id
return
undefined
# File lib/core/world.rb, line 136 def add_builder oid self.builders << oid if Character && !builder?(oid) end
Is character an admin?
oid
character object id
return
true or false
# File lib/core/world.rb, line 115 def is_admin? oid admins.include? oid end
Is character a builder?
oid
character object id
return
true or false
# File lib/core/world.rb, line 108 def is_builder? oid builders.include? oid end
Does character own the object?
pid
character object id
oid
object id
return
true or false
# File lib/core/world.rb, line 151 def is_owner?(pid, oid) oid.owner == get_object(pid).owner end
memstats scans all objects in memory and produces a report
return
a string
# File lib/core/world.rb, line 157 def memstats # initialize all counters rooms = objs = chars = accounts = scripts = strcount = strsize = ocount = 0 # scan the ObjectSpace counting things ObjectSpace.each_object do |x| case x when String strcount += 1 strsize += x.size when Character chars += 1 when Account accounts += 1 when Room rooms += 1 when GameObject objs += 1 when Script scripts += 1 else ocount += 1 end end # our report : # :NOTE: sprintf would be better memstats="[COLOR Cyan] ----* Memory Statistics *---- Rooms - #{rooms} Objects - #{objs} Scripts - #{scripts} Accounts - #{accounts} Characters - #{chars} ----------------------------- Strings - #{strcount} size - #{strsize} bytes Other - #{ocount} ----------------------------- Total Objects - #{rooms+objs+chars+accounts+scripts+strcount+ocount} ----* *---- [/COLOR] " end
Remove admin priviledges from character
oid
character object id
return
undefined
# File lib/core/world.rb, line 129 def rem_admin oid self.admins.delete oid end
Remove admin priviledges from character
oid
character object id
return
undefined
# File lib/core/world.rb, line 143 def rem_builder oid self.builders.delete oid end
Set/add a timer for an object
id
The id of the object that wants to get a timer event
name
The symbolic name of the timer event
time
The interval time in seconds of the timer event
# File lib/core/world.rb, line 86 def set_timer(id, name, time) @timer_list_mutex.synchronize do timer_list << Timer.new(id, name, time) end end
# File lib/core/world.rb, line 77 def shutdown connected_characters.each{|pid| get_object(pid).account.disconnect("Shutdown.")} Thread.kill(@timer) end
# File lib/core/world.rb, line 51 def startup @connected_characters = [] @cmds, @ocmds = Command.load log.info "Starting Timer..." @timer_list_mutex = Mutex.new @timer = Thread.new do begin while true sleep 1.0 @timer_list_mutex.synchronize do timer_list.each do |ti| if ti.fire? add_event(0, ti.id, :timer, ti.name) ti.reset end end end end rescue Exception log.fatal "Timer thread blew up" log.fatal $! end end log.info "World initialized." end
Unset/remove a timer for an object
id
The id of the object to remove a timer event
name
The symbolic name of the timer event to remove (or nil for all events)
# File lib/core/world.rb, line 95 def unset_timer(id, name=nil) @timer_list_mutex.synchronize do if name.nil? timer_list.delete_if {|ti| ti.id == id } else timer_list.delete_if {|ti| ti.id == id && ti.name == name } end end end