async def on_client_accepted(self, socket): client = SocketClient(socket=socket) maple_client = await getattr(self, 'client_connect')(client) debug.logs(f"{self.name} Connection Accepted at {maple_client.ip}") self._clients.append(maple_client) await maple_client.initialize()
async def _listen(self): debug.logs( f"{self._parent.name} Listening on port {self._connection[1]}") while self.is_alive: client_sock, _ = await self._loop.sock_accept(self._serv_sock) client_sock.setblocking(False) client_sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) create_task(self._parent.on_client_accepted(client_sock))
def push(self, client, packet): if packet.name.upper() not in recv_ops.recv_spam_ops: debug.logs(f"InPacket Opcode: {packet.name}: | {packet.to_string()} |") try: coro = None for packet_handler in self.parent.packet_handlers: if packet_handler.opcode == packet.opcode: coro = packet_handler.callback break if not coro: raise AttributeError except AttributeError: if packet.name.upper() not in recv_ops.recv_spam_ops: debug.warn( f"{self.parent.name} Unhandled InPacket in : {packet.name}") else: self.parent._loop.create_task( self._run_event(coro, client, packet))
async def create_account(account: Account): """This creates a new row "Account" object into the database""" try: con = mysql.connector.connect( database=SCHEMA_NAME, host=DATABASE_HOST, user=DATABASE_USER, password=DATABASE_PASSWORD, port=DATABASE_PORT, ) cursor = con.cursor(dictionary=True) cursor.execute(f"INSERT INTO accounts (worldid, userid) VALUES " + f"({account.world_id}, {account.user_id})") con.commit() con.disconnect() debug.logs( f"Successfully created account object in DB userid: {account.user_id}" ) return True except Exception as e: print("[ERROR] Error trying to create new account", e) return False
async def send_packet_raw(self, packet): debug.logs("OutPacket Opcode: " + str(packet.name) + " | " + str(packet.to_string()) + " |") await self.socket.send_packet_raw(packet)
def get_body_part_arr_from_item(item_id, gender_arg): gender = get_gender_from_id(item_id) eqp_prefix = equip_prefix.get_equip_prefix_by_val( int(get_item_prefix(item_id))) body_part_list = [] if eqp_prefix != EquipPrefix.Emblem and \ eqp_prefix != EquipPrefix.Bit and \ gender != 2 and \ gender_arg != 2 and gender != gender_arg: return body_part_list if eqp_prefix is not None: if eqp_prefix == EquipPrefix.Hat: body_part_list.append(BodyPart.Hat.value) body_part_list.append(BodyPart.EvanHat.value) body_part_list.append(BodyPart.APHat.value) body_part_list.append(BodyPart.DUHat.value) body_part_list.append(BodyPart.ZeroHat.value) elif eqp_prefix == EquipPrefix.FaceAccessory: body_part_list.append(BodyPart.FaceAccessory.value) body_part_list.append(BodyPart.APFaceAccessory.value) body_part_list.append(BodyPart.DUFaceAccessory.value) body_part_list.append(BodyPart.ZeroFaceAccessory.value) elif eqp_prefix == EquipPrefix.EyeAccessory: body_part_list.append(BodyPart.FaceAccessory.value) body_part_list.append(BodyPart.ZeroEyeAccessory.value) elif eqp_prefix == EquipPrefix.Earrings: body_part_list.append(BodyPart.Earrings.value) body_part_list.append(BodyPart.ZeroEarrings.value) elif eqp_prefix == EquipPrefix.Top or eqp_prefix == EquipPrefix.Overall: body_part_list.append(BodyPart.Top.value) body_part_list.append(BodyPart.APTop.value) body_part_list.append(BodyPart.DUTop.value) body_part_list.append(BodyPart.ZeroTop.value) elif eqp_prefix == EquipPrefix.Bottom: body_part_list.append(BodyPart.Bottom.value) body_part_list.append(BodyPart.APBottom.value) body_part_list.append(BodyPart.ZeroBottom.value) elif eqp_prefix == EquipPrefix.Shoes: body_part_list.append(BodyPart.Shoes.value) body_part_list.append(BodyPart.APShoes.value) body_part_list.append(BodyPart.ZeroShoes.value) elif eqp_prefix == EquipPrefix.Gloves: body_part_list.append(BodyPart.Gloves.value) body_part_list.append(BodyPart.APGloves.value) body_part_list.append(BodyPart.DUGloves.value) body_part_list.append(BodyPart.ZeroGloves.value) elif eqp_prefix == EquipPrefix.Shield or \ eqp_prefix == EquipPrefix.Katara or \ eqp_prefix == EquipPrefix.SecondaryWeapon or \ eqp_prefix == EquipPrefix.Lapis: body_part_list.append(BodyPart.Shield.value) elif eqp_prefix == EquipPrefix.Lazuli: body_part_list.append(BodyPart.Weapon.value) elif eqp_prefix == EquipPrefix.Cape: body_part_list.append(BodyPart.Cape.value) body_part_list.append(BodyPart.APCape.value) body_part_list.append(BodyPart.DUCape.value) body_part_list.append(BodyPart.ZeroCape.value) elif eqp_prefix == EquipPrefix.Ring: body_part_list.append(BodyPart.Ring1.value) body_part_list.append(BodyPart.Ring2.value) body_part_list.append(BodyPart.Ring3.value) body_part_list.append(BodyPart.Ring4.value) body_part_list.append(BodyPart.ZeroRing1.value) body_part_list.append(BodyPart.ZeroRing2.value) elif eqp_prefix == EquipPrefix.Pendant: body_part_list.append(BodyPart.Pendant.value) body_part_list.append(BodyPart.ExtendedPendant.value) elif eqp_prefix == EquipPrefix.Belt: body_part_list.append(BodyPart.Belt.value) elif eqp_prefix == EquipPrefix.Medal: body_part_list.append(BodyPart.Medal.value) elif eqp_prefix == EquipPrefix.Shoulder: body_part_list.append(BodyPart.Shoulder.value) elif eqp_prefix == EquipPrefix.PocketItem: body_part_list.append(BodyPart.PocketItem.value) elif eqp_prefix == EquipPrefix.MonsterBook: body_part_list.append(BodyPart.MonsterBook.value) elif eqp_prefix == EquipPrefix.Badge: body_part_list.append(BodyPart.Badge.value) elif eqp_prefix == EquipPrefix.Emblem: body_part_list.append(BodyPart.Emblem.value) elif eqp_prefix == EquipPrefix.Totem: body_part_list.append(BodyPart.Totem1.value) body_part_list.append(BodyPart.Totem2.value) body_part_list.append(BodyPart.Totem3.value) elif eqp_prefix == EquipPrefix.MachineEngine: body_part_list.append(BodyPart.MachineEngine.value) elif eqp_prefix == EquipPrefix.MachineArm: body_part_list.append(BodyPart.MachineArm.value) elif eqp_prefix == EquipPrefix.MachineLeg: body_part_list.append(BodyPart.MachineLeg.value) elif eqp_prefix == EquipPrefix.MachineFrame: body_part_list.append(BodyPart.MachineFrame.value) elif eqp_prefix == EquipPrefix.MachineTransistor: body_part_list.append(BodyPart.MachineTransistor.value) elif eqp_prefix == EquipPrefix.Android: body_part_list.append(BodyPart.Android.value) elif eqp_prefix == EquipPrefix.MechanicalHeart: body_part_list.append(BodyPart.MechanicalHeart.value) elif eqp_prefix == EquipPrefix.Bit: bit_id = BodyPart.BitsBase.value while bit_id <= BodyPart.BitsEnd.value: body_part_list.append(bit_id) bit_id += 1 elif eqp_prefix == EquipPrefix.PetWear: body_part_list.append(BodyPart.PetWear1.value) body_part_list.append(BodyPart.PetWear2.value) body_part_list.append(BodyPart.PetWear3.value) elif eqp_prefix == EquipPrefix.TamingMob: body_part_list.append(BodyPart.TamingMob.value) elif eqp_prefix == EquipPrefix.Saddle: body_part_list.append(BodyPart.Saddle.value) elif eqp_prefix == EquipPrefix.EvanHat: body_part_list.append(BodyPart.EvanHat.value) elif eqp_prefix == EquipPrefix.EvanPendant: body_part_list.append(BodyPart.EvanPendant.value) elif eqp_prefix == EquipPrefix.EvanWing: body_part_list.append(BodyPart.EvanWing.value) elif eqp_prefix == EquipPrefix.EvanShoes: body_part_list.append(BodyPart.EvanShoes.value) else: if is_long_or_big_sword(item_id) or is_weapon(item_id): body_part_list.append(BodyPart.Weapon.value) if is_fan(item_id): body_part_list.append(BodyPart.HakuFan.value) else: body_part_list.append(BodyPart.ZeroWeapon.value) else: debug.logs(f"Unknown type item id: {item_id}") else: debug.logs(f"Unknown type item id: {item_id}") return body_part_list
def on_client_disconnect(self, client): self._clients.remove(client) debug.logs(f"Client Disconnected {client.ip}")