Created
May 27, 2014 13:41
-
-
Save photofroggy/9ffeb1dde5de1a902671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Server | |
AppManager app | |
AppManager | |
add(name, cls) | |
apps[name] = cls | |
get(name) | |
return apps[name] || null; | |
remove(name) | |
del apps[name] | |
Application | |
lobby(name, host, private) | |
return new Lobby(this, name, host, private); | |
create(name, host, private) | |
if name in this.lobbies: | |
return null; | |
lobby = this.lobby(name, host, private); | |
this.lobbies[name] = lobby; | |
return lobby; | |
get(name) | |
return this.lobbies[name] || null; | |
close(name, conn) | |
this.lobbies[name].close(conn) | |
list() | |
return this.lobbies.keys; | |
bool access(conn) | |
does user have access to the application? | |
handle(conn, event) | |
Lobby | |
info() | |
bool access(conn, event) | |
handle(conn, event) | |
send(event) | |
for conn in conns | |
conn.send(event) | |
ChatApplication | |
lobby(...) | |
return new ChatLobby(...) | |
serv = Server | |
serv.app.add('chat', ChatApplication) | |
cserv = serv.app.get('chat') | |
botlab = cserv.create('botlab', conn, false) | |
events | |
handshake | |
{ | |
cmd: 'handshake', | |
type: 'client' || 'server', | |
version: ver, | |
[id: { | |
client: uuid, | |
server: uuid | |
}] | |
} | |
client sends type: 'client' | |
server responds with type: 'server' | |
server sends type: 'server' | |
server responds with type: 'server' | |
when connecting to a server, server returns a handshake containing | |
the `id` object. id.client is the uuid for the client connecting to | |
the server, id.server is the uuid for the server. Servers connecting | |
to another server are identified with the id.client uuid returned by | |
the server they are connecting to, unless they provide their own | |
id.client uuid. | |
Servers should set their own uuid internally, but when connecting to a | |
network of servers, should also store the uuid set by another server, | |
maybe. Prevent collisions! Communications from other servers will | |
reference uuids set by other servers. | |
eg: | |
Server A sets own uuid 'a' | |
Server B sets own uuid 'b' | |
Server B connects to A | |
Server A sets uuid 'ab' for Server B | |
Server C sets own uuid 'c' | |
Server C connects to B | |
Server B sets uuid 'bc' for Server C | |
Server B informs 'a' of 'bc' | |
Client A sends {cmd: lobby.list, application: chat} -> Server A | |
Server A needs list of lobbies for chat app | |
cmd = { | |
cmd: 'lobby.list', | |
application: 'chat', | |
id: cmd_uuid, | |
trace: [A.uuid], | |
respond: true? | |
} | |
A.event[cmd.id].waiting = ['ab']; | |
A.event[cmd.id].for = clientA.uuid | |
cmd -> B | |
Server B | |
cmd.trace.append('ab'); | |
B.event[cmd.id].waiting = []; | |
for server in conns: | |
if server.uuid not in cmd.trace | |
cmd -> server // cmd -> C | |
B.event[cmd.id].waiting.append(server.uuid); | |
Server C | |
cmd.trace.append('bc'); | |
no one else to send to | |
btrace = cmd.trace | |
btrace.pop() | |
response = { | |
cmd: 'lobby.list.response', | |
id: cmd.id, | |
trace: btrace, | |
list: ['botlab'] | |
} | |
response -> response.trace.pop() | |
Server B | |
B.event[response.id].waiting.remove(response.sender.id) | |
B.event[response.id].response[response.sender.id] = response | |
if B.event[response.id].waiting.length == 0 | |
response.list.append('botdom') | |
response -> response.trace.pop() // response -> A | |
del B.event[response.id] | |
Server A | |
mostly same as above | |
response.list.append('devart') | |
{ | |
cmd: 'lobby.list', | |
application: response.application, | |
list: response.list | |
} -> A.event[response.id].for | |
Will need to incorporate routing algorithms in the forwarding stuff | |
Using multicast could be fine for our needs, though | |
Need to think about this more | |
Maybe have normal commands wrapped in another command that accounts | |
for routing and what have you | |
{ | |
cmd: 'handshake.error', | |
error: int, | |
description: eg 'incompatible versions' | |
} | |
lobby commands | |
{ | |
cmd: 'lobby.*', | |
lobby: { | |
application: name, | |
id: id | |
}, | |
... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment