Permalink
Browse files

Merge branch 'master' of github.com:psubocz/garden-dWARves

  • Loading branch information...
lqc committed Apr 14, 2012
2 parents a772d06 + 9f401d5 commit 0178bc3e849d58392007e7163b13e84ce189bdd8
Showing with 64 additions and 0 deletions.
  1. +39 −0 server/actor.py
  2. +4 −0 server/config.py
  3. +21 −0 server/server.py
View
@@ -0,0 +1,39 @@
+from socketio.namespace import BaseNamespace
+
+UNCONNECTED = 0
+CONNECTED = 1
+SEARCHING = 2
+INLOBBY = 3
+INGAME = 4
+
+class ActorProxy(BaseNamespace):
+
+ def initialize(self):
+ self._state = UNCONNECTED
+
+ def on_connect(self, udata):
+ self._udata = udata
+ self._change_state(CONNECTED)
+ self.emit('connected')
+
+ def on_search_for_opponent(self, filters):
+ self._change_state(SEARCHING)
+ self.emit('waiting_for_oppponent')
+ gevent.sleep(3)
+ self._change_state(INLOBBY)
+ self.emit('opponent_found', self._udata)
+
+ def on_start_game(self):
+ self._change_state(INGAME)
+ self.emit('game_started')
+
+ def on_chat(self, txt):
+ self.emit('chat', self._udata, txt)
+
+ def on_end_game(self):
+ self._change_state(INLOBBY)
+ self.emit('game_terminated', 'Opponent left')
+
+ def _change_state(self, newstate):
+ self._state = newstate
+
View
@@ -0,0 +1,4 @@
+
+SOCKETIO_PORT = 8000
+SOCKETIO_IFACE = '0.0.0.0'
+
View
@@ -0,0 +1,21 @@
+from gevent import monkey
+monkey.patch_all()
+from socketio.server import SocketIOServer
+from socketio import socketio_manage
+from actor import ActorProxy
+import bottle
+from bottle import route, request, static_file
+
+import config
+
+@route('/socket.io/<rest:path>')
+def handle_socketio(rest):
+ socketio_manage(request.environ, {'': ActorProxy})
+
+@route('/static/<path>')
+def handle_static(path):
+ return static_file(path, root='clitest')
+
+print "Starting socket.io server at %s:%d" % (config.SOCKETIO_IFACE, config.SOCKETIO_PORT)
+SocketIOServer((config.SOCKETIO_IFACE, config.SOCKETIO_PORT), bottle.default_app(), namespace="socket.io").serve_forever()
+

0 comments on commit 0178bc3

Please sign in to comment.