Valhalla Legends Forums Archive | Battle.net Bot Development | [Python] BNLS Verbyte Retriever

AuthorMessageTime
Topaz
verbyte.py:

[code]#topaz

#docs:

#http://bnetdocs.valhallalegends.com/content.php?Section=m&Code=180
#http://www.valhallalegends.com/yoni/BNLSProtocolSpec.txt

import struct
import socket

BNLS_REQUESTVERBYTE = 0x10
productID = {'STAR':0x01, 'SEXP':0x02, 'W2BN':0x03, 'D2DV':0x04,
            'D2XP':0x05, 'JSTR':0x06, 'WAR3':0x07, 'W3XP':0x08}

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

class packetbuffer:
   
    def __init__(self):
        self.buffer = []
       
    def insertData(self, data):
        self.buffer.append(data)

    def insertDWORD(self, data):
        data = self.makeDWORD(data)
        self.buffer.append(data)

    def makeDWORD(self, data):
        return struct.pack('I', data)

    def makeWORD(self, data):
        return struct.pack('H', data)

    def getDWORD(self, data):
        return struct.unpack('I', data)
       
    def sendPacket(self, packetID):

        tmp = ''
        for i in self.buffer: tmp += i

        packetlen = self.makeWORD(len(tmp) + 3)

        sock.send(packetlen + chr(packetID) + tmp)
       
        self.clear()
       
    def clear(self):
        self.buffer = list()

def getVerbyte(data):
    verbyte = pbuffer.getDWORD(data[7:11])
    verbyte = hex(verbyte[0])
       
    print 'verbyte: %s' %(verbyte)


sock.connect(('bnls.valhallalegends.com', 9367))

pbuffer = packetbuffer()

pbuffer.insertDWORD(productID[productID])
pbuffer.sendPacket(0x10)


getVerbyte(sock.recv(1024))
[/code]

Tested and known to work.
June 4, 2006, 7:36 AM
Yegg
You seem to be doing well with Python, nice job on the dictionary usage. Just a reminder incase you don't already know, the following line
[code]print 'verbyte: %s' %(verbyte)[/code]
can also be written as
[code]print 'verbyte: %s' % verbyte[/code]
When you are only inputting a single variable when formatting text, you don't need to enclose that variable with parenthesis, you only need to enclose it when there are 2 or more. IMO, no parenthesis when one variable is used looks nicer, you may think otherwise.
June 4, 2006, 5:51 PM

Search