heimdall/proto.rb

84 lines
1.4 KiB
Ruby

UIDS = {}
module Heimdall
class UID
def initialize
@UID_prefix = "abstract" if not @UID_prefix
id = (1..32).map { |x| (rand()*10).floor }.join
while UIDS.has_key? id do
id = (1..32).map { |x| (rand()*10).floor }.join
end
UIDS[@UID_prefix+id] = self
@UID = id
end
attr_reader :UID
end
class UserCache
def initialize
@users = {}
end
def add(user)
@users[user.protoid] = user
end
def get(protoid)
return @users[user.protoid]
end
end
class User < UID
def initialize(username, protoid)
@username = username
@protoid = protoid
@UID_prefix = "user"
super()
end
attr_reader :username
attr_reader :protoid
end
class Server < UID
def initialize
@UID_prefix = "server"
super()
end
end
class Channel < UID
def initialize
@UID_prefix = "channel"
super()
end
end
class DirectChannel < Channel
def initialize
@UID_prefix = "dchannel"
super()
end
end
class ServerChannel < Channel
def initialize
@UID_prefix = "schannel"
super()
end
end
class Message < UID
def initialize
@UID_prefix = "message"
super()
end
end
class MsgStack < UID
def initialize
@UID_prefix = "msgstack"
super()
end
end
end