Beispiel #1
0
Datei: s.py Projekt: gv/stuff
		def handleStartGame(self, req):
				""" When player has enough invitations, he can send a 'startGame'
				"""
				starter = self.getPlayer(req)
				# check everything
				ids = getArg(req, 'with').split(' ')
				partners = [starter]
				errMsgs = []
				for id in ids:
						player = Client.get(id)
						if not player:
								errMsgs += ["No player %s" % id]
								continue
						partners += [player]
						# remove invitation
						starter.postMessage(what = 'uninvited',
																gameType = getArg(req, 'gameType'),
																who = player.id)
				# Now let's start
				# FIXME Account for other kinds of games here
				thousand.Game(partners)
				rv  = {}
				if errMsgs != []:
						# it's partial success so we don't raise exception
						rv['err'] = {'msg': "\n".join(errMsgs)}
				return rv
Beispiel #2
0
Datei: s.py Projekt: gv/stuff
		def handleChat(self, req):
				# It must support auth
				player = self.getPlayer(req)
				Client.get('players').postMessage(
						what = 'chat',
						phrase = getArg(req, 'phrase'),
						author = player.id
						)
				return {}
Beispiel #3
0
Datei: s.py Projekt: gv/stuff
		def handleNeedClient(self, request):
				# player must have a name, so we can show him in a list
				name = getArg(request, 'name')
				if Player.getByName(name):
						raise ValueError('There already is a player named ' + name)
				player = Player(name)
				return dict(id = player.id, 
										priv = player.priv, 
										name = player.name)
Beispiel #4
0
Datei: s.py Projekt: gv/stuff
		def handleInvite(self, req):
				""" Any player can send 'invite' with list of target ids
				Then each of the targets gets and keeps an invitation
				"""
				inviter = self.getPlayer(req)
				ids = getArg(req, 'target').split(' ')
				errMsgs = []
				for id in ids:
						if id == inviter.id:
								errMsgs += ["You can't invite yourself"]
								continue
						who = Client.get(id)
						if not who:
								errMsgs += ["No client %s" % id]
						# TODO Don't send if he already got equivalent invitation.
						who.postMessage(what = 'invited',
														who = inviter.id,
														gameType = getArg(req, 'gameType'))
				rv  = {}
				if errMsgs != []:
						# it's partial success so we don't raise exception
						rv['err'] = {'msg': "\n".join(errMsgs)}
				return rv
Beispiel #5
0
		def render(self, req):
				m = ''
				if 'POST' == req.method:
						m = unicode(getArg(req, 'm'), 'utf-8')
						print 'Got ' + m
						print [ord(c) for c in m]
				hs = http_headers.Headers()
				hs.addRawHeader('Content-Type', 'text/html;charset=utf-8')
				return http.Response(200, headers=hs, stream="""
<html>
<body>
<div>%(str)s</div>
<div>%(js)s</div>
<form method="post">
<input type=text name="m" />
<input type="submit" />
</form>
</body>
</html>
""" % { 'str': m.encode('utf-8'), 'js': cjson.encode({'x': m})})