Esempio n. 1
0
 def charParser(socket):
     data = socket.recv(1024)
     print len(data)
     if len(data) < 4:
         log.error("Char login bad error")
         return
     if data.startswith(conn.accountID):
         data = data[4:]
         if len(data) == 0:
             return
     
     (header,) = struct.unpack('H', data[0:2])
     if header == 0x6c:
         log.error("Char login denied")
         return
     elif header == 0x81:
         log.error("Already logged in")
         return
     elif header == 0x71:
         mapname = data[6:22].split('\x00\x00')[0]
         conn.mapname = mapname
         socket.close()
         event.removeSocket(socket)
         event.addEvent(lambda: self.mapConnect(conn), 0)
     elif header == 0x6b:
         (length,) = struct.unpack('H', data[2:4])
         if (length - 24) % 108 == 0:
             charlen = 108
         elif (length - 24) % 106 == 0:
             charlen = 106
             
         numChars = (length - 24) / charlen
         
         log.info("Number of characters: %d",numChars)
         
         for i in range(0, numChars):
             offset = 24 + i * charlen
             res = struct.unpack('IIIIIIIIIIHHHHHHHHHHHHHHHHH24sBBBBBBH', data[offset:offset+106])
             if conn.slot == res[34]:
                 conn.charID = res[0]
                 log.info('CharId: %s', util.toHex(struct.pack('I', conn.charID)))
                 conn.baseExp = res[1]
                 conn.zeny = res[2]
                 conn.jobExp = res[3]
                 conn.jobLevel = res[4]
                 conn.hp = res[11]
                 conn.maxhp = res[12]
                 conn.sp = res[13]
                 conn.maxsp = res[14]
                 conn.charname = res[27].split('\x00')[0]
                 socket.send('\x87\x01' + conn.accountID);
                 socket.send(struct.pack('bxb', 0x66, conn.slot));
Esempio n. 2
0
 def loginParser(socket):
     data = socket.recv(1024)
     (header,) = struct.unpack('H', data[0:2])
     if header == 0x6a:
         log.info("Rejected from server")
         return
     elif header == 0x69:
         (length,) = struct.unpack('H', data[2:4])
         numServers = (length-47)/32
         connection.accountID =data[8:12];
         connection.sessionID1=data[4:8];
         connection.sessionID2=data[12:16];
         log.info("AccountId: %s SessionId1: %s SessionId2 %s", connection.accountID, connection.sessionID1, connection.sessionID2)
         connection.sex = data[46]
         socket.close()
         event.removeSocket(socket)
         event.addEvent(lambda: self.charLogin(connection), 0)
Esempio n. 3
0
    def addEvent(self, e, delay):
        eventToken = random.randint(0, sys.maxint)

        #this wrapper is necessary to perform 'cleanup' when an event ends
        def eventWrapper():
            e()
            del self.scriptTokens[eventToken]

        token = event.addEvent(eventWrapper, delay)
        self.scriptTokens[eventToken] = token
        return eventToken
Esempio n. 4
0
    def addEvent(self, e, delay):
        eventToken = random.randint(0, sys.maxint)
        
	#this wrapper is necessary to perform 'cleanup' when an event ends
        def eventWrapper():
            e()
	    del self.scriptTokens[eventToken]
        
        token = event.addEvent(eventWrapper, delay)
        self.scriptTokens[eventToken] = token
	return eventToken