Working on major restructuring
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
module GameServer
|
||||
module Server
|
||||
class MessageRouter
|
||||
def initialize(world)
|
||||
@world = world
|
||||
end
|
||||
|
||||
def handle(data)
|
||||
case data["type"]
|
||||
when "hello"
|
||||
hello
|
||||
when "query"
|
||||
query(data)
|
||||
when "command"
|
||||
command(data)
|
||||
else
|
||||
error("UNKNOWN_TYPE")
|
||||
end
|
||||
end
|
||||
|
||||
def hello
|
||||
{
|
||||
type: "update",
|
||||
domain: "world",
|
||||
payload: {
|
||||
time: @world.time,
|
||||
game_speed: Settings::GAME_SPEED
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def query(data)
|
||||
if data["domain"] == "player"
|
||||
{
|
||||
type: "update",
|
||||
domain: "player",
|
||||
payload: { money: 1000 }
|
||||
}
|
||||
else
|
||||
error("UNKNOWN_DOMAIN")
|
||||
end
|
||||
end
|
||||
|
||||
def command(data)
|
||||
{
|
||||
type: "update",
|
||||
domain: "command",
|
||||
payload: { status: "accepted" }
|
||||
}
|
||||
end
|
||||
|
||||
def error(code)
|
||||
{
|
||||
type: "error",
|
||||
domain: "system",
|
||||
payload: { code: code }
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user