예제 #1
0
파일: dispatcher.py 프로젝트: esh/invaders
def dispatch(env, start_response):
	path = env['PATH_INFO']

	if path == "/comet/meta":
		start_response('200 OK', [('Content-Type', 'text/plain')])
		body = env['wsgi.input'].read()
		msg = json.loads(body)
		if msg["type"] == "login":
			return [client.login(msg)]
		elif msg["type"] == "chat":
			chat.broadcast(msg)
		elif msg["type"] == "universe":
			msg["user"] = client.resolve(msg["uid"])
			del msg["uid"]
			chan.basic_publish(mq.msg(msg), exchange="ex", routing_key="universe")
		else:
			# push it into the right queue
			raise Exception("not yet implemented")

		return [""]	
	elif path.startswith("/comet/client/"):
		start_response('200 OK', [('Content-Type', 'text/plain')])
		return [client.handle(env)]
	else:
		return ["401"]
예제 #2
0
	def handle_request(self, req):
		if req.path() == "/comet/meta":
			msg = json.loads(req.read_body())
			if msg["type"] == "login":
				client.login(req, msg)
			elif msg["type"] == "chat":
				chat.broadcast(req, msg)	
			else:
				# push it into the right queue
				raise Exception("not yet implemented")

		elif req.path().startswith("/comet/client/"):
			client.handle(req)
		else:
			req.response(401)
			req.write("")