Ejemplo n.º 1
0
	def handler(self, packet, state):
		ans = presence_pb2.PAnsProtocol()
		ans.ParseFromString(packet)

		if ans.IsInitialized():
			if ans.command in self.handlerMap.keys():
				v = self.handlerMap[ans.command]
				print ans.command
				return v(self, ans, state)
		return False
Ejemplo n.º 2
0
	def process(self, request):
		req = presence_pb2.PReqProtocol()
		req.ParseFromString(request)
		command = req.command

		# check ppID & gameID

		self.gameID = req.gameID

		seqID = req.seqID
		gameID = req.gameID
		svcID = req.svcID
		category = req.category

		res = False

		if command == presence_pb2.LOGIN:
			res = self.login(gameID, seqID, svcID)
		elif command == presence_pb2.LOGOUT:
			res = self.logout(gameID, seqID, svcID)
		elif command == presence_pb2.GAMEENTER:
			res = self.gameEnter(gameID, seqID, svcID, category)
		elif command == presence_pb2.GAMELEAVE:
			res = self.gameLeave(gameID, seqID, svcID)
		elif command == presence_pb2.DETACH:
			res = self.detach(gameID, seqID, svcID)
		elif command == presence_pb2.PLUG:
			res = self.plug(gameID, seqID, svcID)
		else:
			command = presence_pb2.NONE
			
			
		state = res[1]
		ans = presence_pb2.PAnsProtocol()
		ans.command = command
		ans.seqID = seqID
		ans.gameID = gameID
		ans.svcID = svcID
		ans.category = category

		ans.result = res[0]
		ans.status = state[0]
		ans.detached = state[1]
		if state[0] == 'G':
			ans.ip = state[2][0]
			ans.port = state[2][1]
			ans.roomID = state[2][2]

		packet = ans.SerializeToString()
		header = pack("I", len(packet))
		header += packet
		self.transport.write(header)
Ejemplo n.º 3
0
 def rcvAns(self):
     self.buffer += self.sock.recv(1024)
     if len(self.buffer) > 4:
         (size, ) = unpack('I', self.buffer[0:4])
         size += 4
         if len(self.buffer) >= size:
             ans = self.buffer[4:size]
             self.buffer = self.buffer[size:]
             if size > 4:
                 ret = presence_pb2.PAnsProtocol()
                 ret.ParseFromString(ans)
                 return ret
     return False
Ejemplo n.º 4
0
			elif command == presence_pb2.GAMELEAVE:
				res = self.gameLeave(gameID, seqID, svcID)
			elif command == presence_pb2.DETACH:
				res = self.detach(gameID, seqID, svcID)
			elif command == presence_pb2.PLUG:
				res = self.plug(gameID, seqID, svcID)
			elif command == presence_pb2.CATEGORY:
				res = self.category(gameID, seqID, svcID)
			else:
				command = presence_pb2.NONE
		else:
			command = presence_pb2.NONE
			
			
			
		ans = presence_pb2.PAnsProtocol()
		ans.command = command
		ans.seqID = seqID
		ans.gameID = gameID
		ans.svcID = svcID
		ans.category = category

		if command == presence_pb2.CATEGORY:
			print 'ans:', command, gameID, seqID, svcID, res
			ans.result = True
			ans.status = ''
			ans.detached = False
			ans.info = res
		elif command == presence_pb2.NONE:
			ans.result = False
			ans.status = ''