Exemplo n.º 1
0
    def getGRFInfo(self, grfs, addr=None):
        p = DataPacket(0, const.PACKET_UDP_CLIENT_GET_NEWGRFS)
        p.send_uint8(len(grfs))
        for grf in grfs:
            p.send_something('4s16s', grf)
        self.sendMsg_UDP(p.command, p.data, addr=addr)
        p = self.receiveMsg_UDP(True, useaddr=not addr is None)
        if p is None:
            LOG.debug("unable to receive UDP packet")
            return None
        newgrfs = []
        if p.command == const.PACKET_UDP_SERVER_NEWGRFS:
            reply_count = p.recv_uint8()
            for i in range(0, reply_count):
                [grfid, md5sum] = p.recv_something('4s16s')
                grfname = p.recv_str()
                newgrfs.append([grfid, md5sum, grfname])

            LOG.debug("Got reply to grf request with %d grfs:" % reply_count)
            for grf in newgrfs:
                LOG.debug(" %s - %s - %s" % (grf[0].encode("hex"), grf[1].encode("hex"), grf[2]))
            
            if not addr is None:
                return p.addr, newgrfs
            else:
                return newgrfs
        else:
            raise _error.UnexpectedResponse("PACKET_UDP_CLIENT_GET_NEWGRFS", str(p.command))
Exemplo n.º 2
0
    def getGRFInfo(self, grfs, addr=None):
        p = DataPacket(0, const.PACKET_UDP_CLIENT_GET_NEWGRFS)
        p.send_uint8(len(grfs))
        for grf in grfs:
            p.send_something('4s16s', grf)
        self.sendMsg_UDP(p.command, p.data, addr=addr)
        p = self.receiveMsg_UDP(True, useaddr=not addr is None)
        if p is None:
            LOG.debug("unable to receive UDP packet")
            return None
        newgrfs = []
        if p.command == const.PACKET_UDP_SERVER_NEWGRFS:
            reply_count = p.recv_uint8()
            for i in range(0, reply_count):
                [grfid, md5sum] = p.recv_something('4s16s')
                grfname = p.recv_str()
                newgrfs.append([grfid, md5sum, grfname])

            LOG.debug("Got reply to grf request with %d grfs:" % reply_count)
            for grf in newgrfs:
                LOG.debug(" %s - %s - %s" %
                          (grf[0].encode("hex"), grf[1].encode("hex"), grf[2]))

            if not addr is None:
                return p.addr, newgrfs
            else:
                return newgrfs
        else:
            raise _error.UnexpectedResponse("PACKET_UDP_CLIENT_GET_NEWGRFS",
                                            str(p.command))
Exemplo n.º 3
0
 def GameInfo_Process(self, data="", p=None, encode_grfs=False, short=False):
     """
     Processes a gameinfo response
     @param           p: DataPacket to read from
     @type            p: DataPacket
     @param        data: data to use when p is not given
     @type         data: string
     @param encode_grfs: return the grfs in hex if True
     @type  encode_grfs: bool
     @param       short: only return the things that could change?
     @type        short: bool
     @returns:           processed data
     @rtype:             DataStorageClass
     """
     if p is None:
         p = DataPacket(len(data), const.PACKET_UDP_SERVER_RESPONSE, data)
     info = DataStorageClass()
     info.game_info_version = p.recv_uint8()
     
     if info.game_info_version >= 4:
         grfcount = p.recv_uint8()
         grfs = []
         
         for i in range(0, grfcount):
             [grfid, md5sum] = p.recv_something('4s16s')
             if encode_grfs:
                 grfs.append((grfid.encode('hex'), md5sum.encode('hex')))
             else:
                 grfs.append((grfid, md5sum))
         if not short:
             info.grfs = grfs
     if info.game_info_version >=3:
         info.game_date  = p.recv_uint32()
         if not short:
             info.start_date = p.recv_uint32()
         else:
             p.recv_uint32()
     if info.game_info_version >=2:
         info.companies_max  = p.recv_uint8()
         info.companies_on   = p.recv_uint8()
         info.spectators_max = p.recv_uint8()
     if info.game_info_version >=1:
         info.server_name     = p.recv_str()
         if not short:
             info.server_revision = p.recv_str()
         else:
             p.recv_str()
         info.server_lang     = p.recv_uint8()
         info.use_password    = p.recv_bool()
         info.clients_max     = p.recv_uint8()
         info.clients_on      = p.recv_uint8()
         info.spectators_on   = p.recv_uint8()
         if info.game_info_version < 3: # 16-bit dates were removed from version 3
             info.game_date  = p.recv_uint16() + const.DAYS_TILL_ORIGINAL_BASE_YEAR
             if not short:
                 info.start_date = p.recv_uint16() + const.DAYS_TILL_ORIGINAL_BASE_YEAR
             else:
                 p.recv_uint16()
         if not short:
             info.map_name       = p.recv_str()
             info.map_width      = p.recv_uint16()
             info.map_height     = p.recv_uint16()
             info.map_set        = p.recv_uint8()
             info.dedicated      = p.recv_bool()
         else:
             p.recv_something("zHBB")
     return info
Exemplo n.º 4
0
 def CompanyInfo_Process(self, data="", p=None):
     """
     Processes a companyinfo response
     @param           p: DataPacket to read from
     @type            p: DataPacket
     @param        data: data to use when p is not given
     @type         data: string
     @returns:           processed data
     @rtype:             DataStorageClass
     """
     if p is None:
         p = DataPacket(len(data), const.PACKET_UDP_SERVER_DETAIL_INFO, data)
     info_version = p.recv_uint8()
     player_count = p.recv_uint8()
     
     if info_version == const.NETWORK_COMPANY_INFO_VERSION or info_version == 5 or info_version == 4:
         companies = []
         
         for i in range(0, player_count):
             company = DataStorageClass()
             
             company.number = p.recv_uint8() + 1
             company.company_name     = p.recv_str()
             company.inaugurated_year = p.recv_uint32()
             company.company_value    = p.recv_uint64()
             company.money            = p.recv_uint64()
             company.income           = p.recv_uint64()
             company.performance      = p.recv_uint16()
             company.password_protected = p.recv_bool()
             company.vehicles = p.recv_something('H'*5)
             company.stations = p.recv_something('H'*5)
             
             if info_version == 4:
                 # get the client information from version 4
                 players = []
                 while p.recv_bool():
                     player = DataStorageClass()
                     player.client_name = p.recv_str()
                     player.unique_id   = p.recv_str()
                     player.join_date   = p.recv_uint32()
                     players.append(player)
                 company.clients = players
             
             companies.append(company)
         
         if info_version == 4:
             # get the list of spectators from version 4
             players = []
             while p.recv_bool():
                 player = DataStorageClass()
                 player.client_name = p.recv_str()
                 player.unique_id   = p.recv_str()
                 player.join_date   = p.recv_uint32()
                 players.append(player)
                 
         ret = DataStorageClass()
         ret.info_version = info_version
         ret.player_count = player_count
         ret.companies    = companies
         if info_version == 4:
             ret.spectators = players
         return ret
Exemplo n.º 5
0
    def GameInfo_Process(self,
                         data="",
                         p=None,
                         encode_grfs=False,
                         short=False):
        """
        Processes a gameinfo response
        @param           p: DataPacket to read from
        @type            p: DataPacket
        @param        data: data to use when p is not given
        @type         data: string
        @param encode_grfs: return the grfs in hex if True
        @type  encode_grfs: bool
        @param       short: only return the things that could change?
        @type        short: bool
        @returns:           processed data
        @rtype:             DataStorageClass
        """
        if p is None:
            p = DataPacket(len(data), const.PACKET_UDP_SERVER_RESPONSE, data)
        info = DataStorageClass()
        info.game_info_version = p.recv_uint8()

        if info.game_info_version >= 4:
            grfcount = p.recv_uint8()
            grfs = []

            for i in range(0, grfcount):
                [grfid, md5sum] = p.recv_something('4s16s')
                if encode_grfs:
                    grfs.append((grfid.encode('hex'), md5sum.encode('hex')))
                else:
                    grfs.append((grfid, md5sum))
            if not short:
                info.grfs = grfs
        if info.game_info_version >= 3:
            info.game_date = p.recv_uint32()
            if not short:
                info.start_date = p.recv_uint32()
            else:
                p.recv_uint32()
        if info.game_info_version >= 2:
            info.companies_max = p.recv_uint8()
            info.companies_on = p.recv_uint8()
            info.spectators_max = p.recv_uint8()
        if info.game_info_version >= 1:
            info.server_name = p.recv_str()
            if not short:
                info.server_revision = p.recv_str()
            else:
                p.recv_str()
            info.server_lang = p.recv_uint8()
            info.use_password = p.recv_bool()
            info.clients_max = p.recv_uint8()
            info.clients_on = p.recv_uint8()
            info.spectators_on = p.recv_uint8()
            if info.game_info_version < 3:  # 16-bit dates were removed from version 3
                info.game_date = p.recv_uint16(
                ) + const.DAYS_TILL_ORIGINAL_BASE_YEAR
                if not short:
                    info.start_date = p.recv_uint16(
                    ) + const.DAYS_TILL_ORIGINAL_BASE_YEAR
                else:
                    p.recv_uint16()
            if not short:
                info.map_name = p.recv_str()
                info.map_width = p.recv_uint16()
                info.map_height = p.recv_uint16()
                info.map_set = p.recv_uint8()
                info.dedicated = p.recv_bool()
            else:
                p.recv_something("zHBB")
        return info
Exemplo n.º 6
0
    def CompanyInfo_Process(self, data="", p=None):
        """
        Processes a companyinfo response
        @param           p: DataPacket to read from
        @type            p: DataPacket
        @param        data: data to use when p is not given
        @type         data: string
        @returns:           processed data
        @rtype:             DataStorageClass
        """
        if p is None:
            p = DataPacket(len(data), const.PACKET_UDP_SERVER_DETAIL_INFO,
                           data)
        info_version = p.recv_uint8()
        player_count = p.recv_uint8()

        if info_version == const.NETWORK_COMPANY_INFO_VERSION or info_version == 5 or info_version == 4:
            companies = []

            for i in range(0, player_count):
                company = DataStorageClass()

                company.number = p.recv_uint8() + 1
                company.company_name = p.recv_str()
                company.inaugurated_year = p.recv_uint32()
                company.company_value = p.recv_uint64()
                company.money = p.recv_uint64()
                company.income = p.recv_uint64()
                company.performance = p.recv_uint16()
                company.password_protected = p.recv_bool()
                company.vehicles = p.recv_something('H' * 5)
                company.stations = p.recv_something('H' * 5)

                if info_version == 4:
                    # get the client information from version 4
                    players = []
                    while p.recv_bool():
                        player = DataStorageClass()
                        player.client_name = p.recv_str()
                        player.unique_id = p.recv_str()
                        player.join_date = p.recv_uint32()
                        players.append(player)
                    company.clients = players

                companies.append(company)

            if info_version == 4:
                # get the list of spectators from version 4
                players = []
                while p.recv_bool():
                    player = DataStorageClass()
                    player.client_name = p.recv_str()
                    player.unique_id = p.recv_str()
                    player.join_date = p.recv_uint32()
                    players.append(player)

            ret = DataStorageClass()
            ret.info_version = info_version
            ret.player_count = player_count
            ret.companies = companies
            if info_version == 4:
                ret.spectators = players
            return ret