def SendCreationResponse(Server: GameServer, address: Address, Response: MinifigureCreationResponse): packet = WriteStream() writeHeader(packet, PacketHeader.MinifigureCreationResponse) packet.write(c_uint8( Response.value)) #Just going to leave it at success for now Server.send(packet, address)
def Ressurect(Object, stream: ReadStream, address: Address, Server: GameServer): packet = WriteStream() Server.InitializeGameMessage(packet, Object.ObjectConfig["ObjectID"], 0x00a0) Object.ObjectConfig["Health"] = Object.ObjectConfig["MaxHealth"] Object.ObjectConfig["Armor"] = Object.ObjectConfig["MaxArmor"] Server.brodcastPacket(packet, Object.Zone) Object.ObjectConfig["Alive"] = True
def RunCommand(Object, stream: ReadStream, address: Address, Server: GameServer): if (Object.Parent.IsAdmin == True): clientState = stream.read(c_int) command = stream.read(str, length_type=c_ulong) args = command.split(" ") try: if (args[0] == "/loadWorld"): Server.LoadWorld(Object, int(args[1]), address, SpawnAtDefault=True) elif (args[0] == "/getJetpack"): packet = WriteStream() Server.InitializeGameMessage(packet, Object.ObjectConfig["ObjectID"], 0x0231) packet.write(c_bit(True)) packet.write(c_bit(False)) packet.write(c_bit(True)) packet.write(c_int(-1)) #EffectID packet.write(c_float(10)) #Air Speed packet.write(c_float(15)) #Max Air Speed packet.write(c_float(1.5)) #Vertical Velocity packet.write(c_int(0)) Server.brodcastPacket(packet, Object.Zone) elif (args[0] == "/setConfig"): if (Object.ObjectConfig[args[1]] is not None): configType = type(Object.ObjectConfig[str(args[1])]) if (configType == str): Object.ObjectConfig[str(args[1])] = str(args[2]) print("Changed {} to {}".format(args[1], args[2])) elif (configType == int): Object.ObjectConfig[str(args[1])] = int(args[2]) print("Changed {} to {}".format(args[1], args[2])) elif (configType == Vector3): Object.ObjectConfig[str(args[1])] = Vector3( float(args[2]), float(args[3]), float(args[4])) print("Changed {} to ({}, {}, {})".format( args[1], args[2], args[3], args[4])) elif (configType == Vector4): Object.ObjectConfig[str(args[1])] = Vector4( float(args[2]), float(args[3]), float(args[4]), float(args[5])) print("Changed {} to ({}, {}, {}, {})".format( args[1], args[2], args[3], args[4], args[5])) except Exception as e: print("Error While Executing Command : {}".format(e)) else: print("{} Is Not An Admin!".format(Object.ObjectConfig("Name")))
def HandleSessionKey(Server: GameServer, data: bytes, address: Address): stream = ReadStream(data) username = stream.read(str, allocated_length=33) userKey = stream.read(str, allocated_length=33) session = Server.Game.getSessionByAddress(address) if (session is not None and session.userKey == userKey and session.accountUsername == username): print(address, "sent the following valid key:", userKey) session.State = SessionState.CharacterScreen else: Server.send( getDisconnect(DisconnectionReasons.InvalidSessionKey.value), address)
def HandleMinifigListRequest(Server: GameServer, data: bytes, address: Address): session = Server.Game.getSessionByAddress(address) if (session.State == SessionState.CharacterScreen): characters = Server.Game.getAccountByUsername( session.accountUsername).Characters packet = WriteStream() writeHeader(packet, PacketHeader.MinifigureList) packet.write(c_uint8(len(characters))) packet.write(c_uint8(0)) for character in characters: packet.write(c_longlong( character.ObjectConfig["ObjectID"])) #Object ID packet.write(c_ulong(0)) packet.write(character.ObjectConfig["Name"], allocated_length=33) #Character Name packet.write("", allocated_length=33) #Name to show up in paranthesis packet.write(c_bool(False)) #Name rejected packet.write(c_bool(False)) #Free to play packet.write(CString("", allocated_length=10)) #Unknown packet.write(c_ulong(character.ObjectConfig["ShirtColor"])) packet.write(c_ulong(character.ObjectConfig["ShirtStyle"])) packet.write(c_ulong(character.ObjectConfig["PantsColor"])) packet.write(c_ulong(character.ObjectConfig["HairStyle"])) packet.write(c_ulong(character.ObjectConfig["HairColor"])) packet.write(c_ulong(character.ObjectConfig["lh"])) packet.write(c_ulong(character.ObjectConfig["rh"])) packet.write(c_ulong(character.ObjectConfig["Eyebrows"])) packet.write(c_ulong(character.ObjectConfig["Eyes"])) packet.write(c_ulong(character.ObjectConfig["Mouth"])) packet.write(c_ulong(0)) packet.write(c_uint16(character.Zone)) packet.write(c_uint16(0)) #MapInstance packet.write(c_ulong(0)) #MapClone packet.write(c_ulonglong(0)) equippedItems = character.ObjectConfig[ "Inventory"].getEquippedItems() packet.write(c_ushort(len(equippedItems))) for item in equippedItems: packet.write(c_ulong(item["LOT"])) Server.send(packet, address)
def HandleJoinWorld(Server: GameServer, data: bytes, address: Address): stream = ReadStream(data) ObjectID = stream.read(c_longlong) player: Character = Server.Game.getCharacterByObjectID(ObjectID) if (player.Zone == ZoneID.NoZone.value): player.Zone = ZoneID.VentureExplorer.value SpawnAtDefault = False if (player.ObjectConfig["Position"] == Vector3(0, 0, 0)): SpawnAtDefault = True Server.LoadWorld(player, player.Zone, address, SpawnAtDefault=SpawnAtDefault)
def HandleDetailedLoad(Server: GameServer, data: bytes, address: Address): session: Session = Server.Game.getSessionByAddress(address) player: Character = Server.Game.getCharacterByObjectID(session.ObjectID) zone: Zone = Server.Game.getZoneByID(player.Zone) zone.createObject(player) ldf = LDF() ldf.registerKey("levelid", player.Zone, 1) ldf.registerKey("objid", player.ObjectConfig["ObjectID"], 9) ldf.registerKey("template", player.ObjectConfig["LOT"], 1) ldf.registerKey("name", player.ObjectConfig["Name"], 0) root = ElementTree.Element("obj") root.set("v", "1") buff = ElementTree.SubElement(root, "buff") skill = ElementTree.SubElement(root, "skill") inv = ElementTree.SubElement(root, "inv") bag = ElementTree.SubElement(inv, "bag") bagInfo = ElementTree.SubElement(bag, "b") bagInfo.set("t", "0") bagInfo.set("m", str(player.ObjectConfig["Inventory"].Space)) items = ElementTree.SubElement(inv, "items") itemIn = ElementTree.SubElement(items, "in") for item in player.ObjectConfig["Inventory"].InventoryList: i = ElementTree.SubElement(itemIn, "i") i.set("l", str(item["LOT"])) i.set("id", str(item["ObjectID"])) i.set("s", str(item["Slot"])) i.set("c", str(item["Quantity"])) i.set("b", str(int(item["Linked"]))) i.set("eq", str(int(item["Equipped"]))) mf = ElementTree.SubElement(root, "mf") char = ElementTree.SubElement(root, "char") char.set("cc", str(player.ObjectConfig["Currency"])) char.set("ls", str(player.ObjectConfig["UniverseScore"])) lvl = ElementTree.SubElement(root, "lvl") lvl.set("l", str(player.ObjectConfig["Level"])) pets = ElementTree.SubElement(root, "pet") mis = ElementTree.SubElement(root, "mis") done = ElementTree.SubElement(mis, "done") for mission in player.ObjectConfig["CompletedMissions"]: m = ElementTree.SubElement(done, "m") m.set("id", str(mission)) m.set("cct", "1") m.set("cts", "0") cur = ElementTree.SubElement(mis, "cur") for mission in player.ObjectConfig["CurrentMissions"]: m = ElementTree.SubElement(cur, "m") m.set("id", str(mission.MissionID)) sv = ElementTree.SubElement(m, "sv") sv.set("v", str(mission.Progress)) ldf.registerKey("xmlData", root, 13) LegoData = WriteStream() ldf.writeLDF(LegoData) ldfBytes = bytes(LegoData) compressed = zlib.compress(ldfBytes) packet = WriteStream() writeHeader(packet, PacketHeader.DetailedUserInfo) packet.write(c_ulong(len(compressed) + 9)) packet.write(c_bool(True)) packet.write(c_ulong(len(ldfBytes))) packet.write(c_ulong(len(compressed))) packet.write(compressed) Server.send(packet, address) print("Sent Detailed User Info to Player {}".format( player.ObjectConfig["ObjectID"])) ConstructObjectsInZone(Server, address, zone.ZoneID, ExcludeIDs=[player.ObjectConfig["ObjectID"]]) if (player.Components == []): player.Components = player.findComponentsFromCDClient(Server.CDClient) Server.ReplicaManagers[zone.ZoneID].construct(player) doneLoadingObjects = WriteStream() Server.InitializeGameMessage(doneLoadingObjects, player.ObjectConfig["ObjectID"], 0x066a) Server.send(doneLoadingObjects, address) playerReady = WriteStream() Server.InitializeGameMessage(playerReady, player.ObjectConfig["ObjectID"], 0x01fd) Server.send(playerReady, address)
def HandleHandshake(Server: GameServer, data: bytes, address: Address): stream = ReadStream(data) clientVersion = stream.read(c_ulong) Server.send(getHandshake(clientVersion, 4), address)