Skip to content

Commit

Permalink
Merge branch 'tjkirch/origin'
Browse files Browse the repository at this point in the history
  • Loading branch information
presidentbeef committed Apr 25, 2011
2 parents 9483a92 + 997e360 commit 6fd750e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion components/commandparser.rb
Expand Up @@ -241,7 +241,7 @@ def parse(player, input)
elsif @news.include? command
parse_news input
elsif @mobile.include? command and player.is_a? Mobile
parse_mobile command
parse_mobile command ### implement me
elsif input =~ /^alarm\s+([0-9]+)$/i
after $1.to_i do
player.output "***ALARM***"
Expand Down
4 changes: 1 addition & 3 deletions components/manager.rb
Expand Up @@ -20,8 +20,8 @@ class Manager
#a Manager object in an external script.
def initialize(objects = nil)
@soft_restart = false

@storage = StorageMachine.new
@uptime = Time.new.to_i

unless objects
@cancelled_events = Set.new
Expand All @@ -38,8 +38,6 @@ def initialize(objects = nil)
else
@game_objects = objects
end

@uptime = Time.new.to_i
end

#Checks if a game object ID exists already, to avoid conflicts.
Expand Down
27 changes: 22 additions & 5 deletions components/storage.rb
Expand Up @@ -8,15 +8,32 @@
load 'util/all-behaviors.rb'
load 'util/all-objects.rb'

#Storage class for object persistance. Uses GDBM.
# Storage class for object persistance. Uses GDBM.
#
#GDBM is a file-system hash table which is fast and available on many platforms. However, it only stores strings. So objects are stored as Strings representing the marshaled object.
# GDBM is a file-system hash table which is fast and available on many
# platforms. However, it only stores strings. So objects are stored as Strings
# representing the marshaled object.
#
#The default storage system works this way: each GameObject is stored in a file which is named after the GameObject's class. For example, a Door would be in storage/Door. In each file, objects are indexed by their GOID. There is a special file in storage/goids which lists GOIDs and the class of the GameObject. This is used to find Objects according to their GOID.
# The default storage system works this way: each GameObject is stored in a
# file which is named after the GameObject's class. For example, a Door would
# be in storage/Door. In each file, objects are indexed by their GOID. There
# is a special file in storage/goids which lists GOIDs and the class of the
# GameObject. This is used to find Objects according to their GOID.
#
#Here is an example: you want to load an object with a GOID of 476dfe3e-96bc-1952-fadd-26c22043a5a3. The StorageMachine will first open up storage/goids and retrieve the class pointed to by 476dfe3e-96bc-1952-fadd-26c22043a5a3, which happens to be Dog. The StorageMachine then opens up storage/Dog and again retrieves the Object pointed to by 476dfe3e-96bc-1952-fadd-26c22043a5a3, but this time it will be the (marshaled string of the) Dog object.
# Here is an example: you want to load an object with a GOID of
# 476dfe3e-96bc-1952-fadd-26c22043a5a3. The StorageMachine will first open up
# storage/goids and retrieve the class pointed to by
# 476dfe3e-96bc-1952-fadd-26c22043a5a3, which happens to be Dog. The
# StorageMachine then opens up storage/Dog and again retrieves the Object
# pointed to by 476dfe3e-96bc-1952-fadd-26c22043a5a3, but this time it will be
# the (marshaled string of the) Dog object.
#
#Of course, there is an exception. Players are handled differently, because they are typically looked up by name and not by their GOID. Instead of being listed in storage/goids, they are listed in storage/players. This file maps player names to GOIDs. Then they can be looked up by GOID in the storage/Player file. Additionally, passwords are stored as MD5 hashes in storage/passwords, indexed by GOID (a tiny bit of security there).
# Of course, there are exceptions. Players are handled differently, because
# they are typically looked up by name and not by their GOID. Instead of being
# listed in storage/goids, they are listed in storage/players. This file maps
# player names to GOIDs. Then they can be looked up by GOID in the
# storage/Player file. Additionally, passwords are stored as MD5 hashes in
# storage/passwords, indexed by GOID (a tiny bit of security there).
class StorageMachine
def initialize(path = 'storage/')
@path = path
Expand Down
3 changes: 1 addition & 2 deletions events/admin.rb
Expand Up @@ -571,7 +571,7 @@ def aset(event, player, room)
when "false"
value = false
when /^:/
value = value.to_sym
value = value[1..-1].to_sym
when "nil"
value = nil
when /^[0-9]+$/
Expand Down Expand Up @@ -899,7 +899,6 @@ def areaction(event, player, room)
elsif not object.is_a? Reacts and (event[:command] == "load" or event[:command] == "reload")
player.output "Object cannot react, adding react ability."
object.extend(Reacts)
object.init_reactor
end

case event[:command]
Expand Down
2 changes: 1 addition & 1 deletion lib/gary.rb
Expand Up @@ -134,7 +134,7 @@ def find_all(attrib, match)
when /^\d+$/
match = match.to_i
when /^:/
match = match.to_sym
match = match[1..-1].to_sym
end
if attrib == "class" and (match.is_a? Class or match.is_a? Module)
@ghash.dup.each do |goid, obj|
Expand Down
7 changes: 5 additions & 2 deletions traits/reacts.rb
Expand Up @@ -11,8 +11,11 @@ def uses_reaction? file
@reactions_files.include? file
end

#This is called when the object is created, but if the
#module is mixed in dynamically this needs to be called before being used
# Automatically set up the reactor when we extend an object
def self.extended(obj)
obj.init_reactor
end

def init_reactor
@reactor ||= Reactor.new(self)
@reaction_files ||= Set.new
Expand Down

0 comments on commit 6fd750e

Please sign in to comment.