| Class | World |
| In: |
lib/core/world.rb
|
| Parent: | Root |
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 | [RW] | |
| connected_characters | [RW] | |
| ocmds | [RW] |
Create the World. This loads or creates the database depending on whether it finds it.
# 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
# File lib/core/world.rb, line 122 def add_admin oid self.admins << oid if Character && !admin?(oid) end
Make the character a builder
# File lib/core/world.rb, line 136 def add_builder oid self.builders << oid if Character && !builder?(oid) end
Is character an admin?
# File lib/core/world.rb, line 115 def is_admin? oid admins.include? oid end
Is character a builder?
# File lib/core/world.rb, line 108 def is_builder? oid builders.include? oid end
Does character own the object?
# 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
# 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]\n----* Memory Statistics *----\n Rooms - \#{rooms}\n Objects - \#{objs}\n Scripts - \#{scripts}\n Accounts - \#{accounts}\n Characters - \#{chars}\n-----------------------------\n Strings - \#{strcount}\n size - \#{strsize} bytes\n Other - \#{ocount}\n-----------------------------\n Total Objects - \#{rooms+objs+chars+accounts+scripts+strcount+ocount}\n----* *----\n[/COLOR]\n" end
Remove admin priviledges from character
# File lib/core/world.rb, line 129 def rem_admin oid self.admins.delete oid end
Remove admin priviledges from character
# File lib/core/world.rb, line 143 def rem_builder oid self.builders.delete oid end
Set/add a timer for an object
# 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
# 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