示例#1
0
class AoProtocol(Protocol):
    """Interfaz con Twisted para el socket del cliente."""
    def __init__(self):
        # Buffers de datos
        self._ao_inbuff = ByteQueue()
        self.outbuf = ByteQueue()

        self._peer = None

        # En medio de una desconexion.
        self._ao_closing = False
        self._ao_connLost = False
        self.lastHandledPacket = int(time.time())

        # la instancia de Player se crea cuando el login es exitoso.
        self.player = None

        # Wrapper para serializar comandos en outbuf.
        self.cmdout = ServerCommandsEncoder(self)

    def __hash__(self):
        return id(self)

    def __eq__(self, other):
        return id(self) == id(other)

    def dataReceived(self, data):
        if not self._ao_closing:
            self._ao_inbuff.addData(data)
            self._handleData()

    def connectionMade(self):
        debug_print("connectionMade")

        if not gameServer.connectionsLimitReached():
            gameServer.connectionMade(self)
        else:
            self.loseConnection()

    def connectionLost(self, reason):
        debug_print("connectionLost")
        self._ao_connLost = True

        # Todo el codigo de limpieza de la conexion debe ir en loseConnection.

        if not self._ao_closing:
            self.loseConnection()

    def getPeer(self):
        # host, port, type
        if self._peer is None:
            self._peer = self.transport.getPeer()
        return self._peer

    def _handleData(self):
        try:
            cmdDecoder.handleData(self)
        except CriticalDecoderException, e:
            debug_print("CriticalDecoderException")
            self.loseConnection()
示例#2
0
    def __init__(self):
        # Buffers de datos
        self._ao_inbuff = ByteQueue()
        self.outbuf = ByteQueue()

        self._peer = None

        # En medio de una desconexion.
        self._ao_closing = False
        self._ao_connLost = False
        self.lastHandledPacket = int(time.time())

        # la instancia de Player se crea cuando el login es exitoso.
        self.player = None

        # Wrapper para serializar comandos en outbuf.
        self.cmdout = ServerCommandsEncoder(self)
示例#3
0
def loadMapFile(mapNum, fileNameBasePath):
    """Carga un mapa"""


    fileNameMap = os.path.join(fileNameBasePath, 'Mapa%d.map' % mapNum)
    fileNameInf = os.path.join(fileNameBasePath, 'Mapa%d.inf' % mapNum)
    fileNameDat = os.path.join(fileNameBasePath, 'Mapa%d.dat' % mapNum)

    # .map
    with open(fileNameMap, 'rb') as f:
        mapData = ByteQueue(f.read())

    # .inf
    with open(fileNameInf, 'rb') as f:
        infData = ByteQueue(f.read())

    # .dat
    datData = util.MyConfigParser()
    datData.read([fileNameDat])

    # Map object.
    mf = MapFile(mapNum)

    # Map header
    mf.mapVers = mapData.readInt16()
    mf.mapDesc = mapData.readStringFixed(255)
    mf.mapCrc = mapData.readInt32()
    mf.mapMagicWord = mapData.readInt32()

    # Dat data
    datSection = "Mapa%d" % mapNum

    mapOptions = ['Name', 'MusicNum', 'StartPos', 'MagiaSinEfecto', 
        'InviSinEfecto', 'ResuSinEfecto', 'OcultarSinEfecto', 
        'InvocarSinEfecto', 'NoEncriptarMP', 'RoboNpcsPermitido', 'Pk', 
        'Terreno', 'Zona', 'Restringir', 'BACKUP']

    # Carga las opciones del mapa que están dentro del .dat.
    # Si una opcion no está la guarda como None.

    for opt in mapOptions:
        try:
            mf.opts[opt] = datData.get(datSection, opt)
        except NoOptionError, e:
            mf.opts[opt] = None
示例#4
0
class Decryptor_v2():

    blocks_passed = 0
    iv = None
    key = None
    data_buffer = ByteQueue()
    checksum = hashlib.sha256()

    def __init__(self, out_file, file_size, password):

        self.out_file = out_file
        self.password = password
        self.file_size = file_size

    def get_checksum(self):

        return self.checksum.hexdigest()

    def unpad(self, data_str):

        return data_str[0:-ord(data_str[-1])]

    def create_key(self, salt):

        self.key = hashlib.pbkdf2_hmac('sha1', self.password, salt, 65536, 16)

    def decrypt(self, data, iv):

        dec_obj = AES.new(self.key, AES.MODE_CBC, iv)
        return dec_obj.decrypt(data)

    def stream_to_file(self, block):

        self.data_buffer.enqueue(block)
        self.blocks_passed += len(block)

        if not self.key:
            if len(self.data_buffer) >= 16:
                salt = self.data_buffer.dequeue(16)
                self.create_key(salt)
        elif not self.iv:
            if len(self.data_buffer) >= 16:
                self.iv = self.data_buffer.dequeue(16)
        else:
            while len(self.data_buffer) >= 16:
                b = self.data_buffer.dequeue(16)
                data = self.decrypt(b, self.iv)
                if self.blocks_passed == self.file_size:
                    data = self.unpad(data)
                self.out_file.write(data)
                self.checksum.update(data)
                self.iv = b
示例#5
0
    def __init__(self):
        # Buffers de datos
        self._ao_inbuff = ByteQueue()
        self.outbuf = ByteQueue()

        self._peer = None

        # En medio de una desconexion.
        self._ao_closing = False
        self._ao_connLost = False
        self.lastHandledPacket = int(time.time())

        # la instancia de Player se crea cuando el login es exitoso.
        self.player = None

        # Wrapper para serializar comandos en outbuf.
        self.cmdout = ServerCommandsEncoder(self)
示例#6
0
def loadMapFile(mapNum, fileNameBasePath):
    """Carga un mapa"""

    fileNameMap = os.path.join(fileNameBasePath, 'Mapa%d.map' % mapNum)
    fileNameInf = os.path.join(fileNameBasePath, 'Mapa%d.inf' % mapNum)
    fileNameDat = os.path.join(fileNameBasePath, 'Mapa%d.dat' % mapNum)

    # .map
    with open(fileNameMap, 'rb') as f:
        mapData = ByteQueue(f.read())

    # .inf
    with open(fileNameInf, 'rb') as f:
        infData = ByteQueue(f.read())

    # .dat
    datData = util.MyConfigParser()
    datData.read([fileNameDat])

    # Map object.
    mf = MapFile(mapNum)

    # Map header
    mf.mapVers = mapData.readInt16()
    mf.mapDesc = mapData.readStringFixed(255)
    mf.mapCrc = mapData.readInt32()
    mf.mapMagicWord = mapData.readInt32()

    # Dat data
    datSection = "Mapa%d" % mapNum

    mapOptions = [
        'Name', 'MusicNum', 'StartPos', 'MagiaSinEfecto', 'InviSinEfecto',
        'ResuSinEfecto', 'OcultarSinEfecto', 'InvocarSinEfecto',
        'NoEncriptarMP', 'RoboNpcsPermitido', 'Pk', 'Terreno', 'Zona',
        'Restringir', 'BACKUP'
    ]

    # Carga las opciones del mapa que están dentro del .dat.
    # Si una opcion no está la guarda como None.

    for opt in mapOptions:
        try:
            mf.opts[opt] = datData.get(datSection, opt)
        except NoOptionError, e:
            mf.opts[opt] = None
示例#7
0
class AoProtocol(Protocol):
    """Interfaz con Twisted para el socket del cliente."""

    def __init__(self):
        # Buffers de datos
        self._ao_inbuff = ByteQueue()
        self.outbuf = ByteQueue()

        self._peer = None

        # En medio de una desconexion.
        self._ao_closing = False
        self._ao_connLost = False
        self.lastHandledPacket = int(time.time())

        # la instancia de Player se crea cuando el login es exitoso.
        self.player = None

        # Wrapper para serializar comandos en outbuf.
        self.cmdout = ServerCommandsEncoder(self)

    def __hash__(self):
        return id(self)

    def __eq__(self, other):
        return id(self) == id(other)

    def dataReceived(self, data):
        if not self._ao_closing:
            self._ao_inbuff.addData(data)
            self._handleData()

    def connectionMade(self):
        debug_print("connectionMade")

        if not gameServer.connectionsLimitReached():
            gameServer.connectionMade(self)
        else:
            self.loseConnection()

    def connectionLost(self, reason):
        debug_print("connectionLost")
        self._ao_connLost = True

        # Todo el codigo de limpieza de la conexion debe ir en loseConnection.

        if not self._ao_closing:
            self.loseConnection()

    def getPeer(self):
        # host, port, type
        if self._peer is None:
            self._peer = self.transport.getPeer()
        return self._peer

    def _handleData(self):
        try:
            cmdDecoder.handleData(self)
        except CriticalDecoderException, e:
            debug_print("CriticalDecoderException")
            self.loseConnection()