Beispiel #1
0
	def send_session_reply(self, station, session_info):
		logger.debug("Sending session reply")
		
		stream = StreamOut(self.settings)
		stream.add(session_info)
		data = stream.get()
		
		rand_value = random.randint(0, 0xFFFFFFFF)
		
		fragments = (len(data) - 1) // 800 + 1
		for i in range(fragments):
			stream = StreamOut(self.settings)
			stream.u8(self.MESSAGE_SESSION_REPLY)
			stream.pad(11)
			stream.u32(rand_value)
			stream.u16(self.session_reply_id)
			stream.u8(i)
			stream.u8(fragments)
			
			body = data[i * 800 : (i + 1) * 800]
			stream.u32(len(body))
			stream.write(body)
			
			message = PIAMessage()
			message.protocol_id = self.get_protocol_type()
			message.payload = stream.get()
			self.transport.send(station, message)
			
		self.session_reply_id += 1
Beispiel #2
0
 def encode(self, stream):
     if stream.settings.get("pia.version") < 51000:
         stream.add(self.connection_info)
     else:
         substream = StreamOut(stream.settings)
         substream.add(self.connection_info.local)
         substream.pad(0x3E - substream.size())
         stream.write(substream.get())
     stream.u8(self.index)
     stream.align(4)
Beispiel #3
0
    def send_ack(self, station, ack_id):
        logger.debug("Acknowledging packet %i", ack_id)

        stream = StreamOut(self.settings)
        stream.u8(self.MESSAGE_ACK)
        stream.pad(3)
        stream.u32(ack_id)

        message = PIAMessage()
        message.protocol_id = self.get_protocol_type()
        message.payload = stream.get()

        self.transport.send(station, message)
Beispiel #4
0
	def send_session_request(self, session_id):
		logger.debug("Sending host request")
		
		stream = StreamOut(self.settings)
		stream.u8(self.MESSAGE_SESSION_REQUEST)
		stream.pad(11)
		stream.u32(session_id)
		
		message = PIAMessage()
		message.protocol_id = self.get_protocol_type()
		message.payload = stream.get()
		
		for port in range(0xC000, 0xC004):
			self.transport.broadcast(port, message)
Beispiel #5
0
    def send_connection_response(self, station):
        logger.debug("Sending connection response")

        stream = StreamOut(self.settings)
        stream.u8(self.MESSAGE_CONNECTION_RESPONSE)
        stream.u8(0)
        stream.u8(self.version)
        stream.u8(self.platform)

        identification = self.session.local_station().identification_info

        if self.version < 7:
            stream.chars(identification.token.ljust(32, "\0"))

            player = identification.players[0]
            stream.wchars(player.name.ljust(16, "\0"))
            stream.u8(len(player.name))
            stream.u8(player.language)
        else:
            stream.u8(0)
            stream.u64(station.connection_info.local.pid)
            stream.u32(station.connection_info.local.cid)
            stream.chars(identification.token.ljust(32, "\0"))
            stream.u32(self.session.get_session_id())
            stream.u8(len(identification.players))
            stream.u8(identification.participants)
            stream.u8(len(identification.players))

            for player in identification.players:
                stream.write(player.name.encode("utf8").ljust(80, b"\0"))
                stream.u8(1)
                stream.write(player.nickname.encode("utf8").ljust(40, b"\0"))
                stream.u8(1)
                stream.u8(player.language)
                stream.write(player.play_history_key)
                stream.u64(player.info)

            stream.pad(0xC3 * (4 - len(identification.players)))

        message = PIAMessage()
        message.protocol_id = self.get_protocol_type()
        message.payload = stream.get()

        self.resender.send(station, message)
Beispiel #6
0
    def send_join_request(self, station):
        logger.debug("Sending join request")

        local_station = self.session.local_station()
        local_address = local_station.connection_info.local.local

        stream = StreamOut(self.settings)
        stream.u8(self.MESSAGE_JOIN_REQUEST)
        stream.u8(local_station.index)

        if self.settings.get("pia.version") >= 51100:
            stream.pad(2)
            stream.add(local_address)

        message = PIAMessage()
        message.protocol_id = self.get_protocol_type()
        message.protocol_port = self.PORT_UNRELIABLE
        message.payload = stream.get()

        self.resender.send(station, message)
Beispiel #7
0
	def send_host_reply(self, station, session_info):
		logger.debug("Sending host reply")
		
		stream = StreamOut(self.settings)
		stream.u8(self.MESSAGE_HOST_REPLY)
		stream.pad(11)
		stream.u32(session_info.session_id)
		
		host = self.session.host_station()
		if self.settings.get("pia.version") < 51000:
			stream.add(host.connection_info)
		else:
			stream.add(host.connection_info.local)
		
		message = PIAMessage()
		message.protocol_id = self.get_protocol_type()
		message.payload = stream.get()
		
		for i in range(3):
			self.transport.send(station, message)