public CoCServer() { Clients = new List<CoCRemoteClient>(); AvatarManager = new AvatarManager(this); DefaultVillage = new Village(); DefaultVillage.FromJson(File.ReadAllText("default_village.json")); }
public CoCRemoteClient(CoCServer server, Socket connection) { Connection = connection; Server = server; NetworkManager = new NetworkManagerAsync(connection, HandlePacketReceived, HandleReceicedPacketFailed); PacketHandlers = new Dictionary<ushort, PacketHandler>(); Avatar = new Avatar(); Home = new Village(); }
public CoCClient() { Fingerprint = new Fingerprint(); Home = new Village(); Avatar = new Avatar(); Connection = new Socket(SocketType.Stream, ProtocolType.Tcp); PacketHandlers = new Dictionary<ushort, PacketHandler>(); KeepAliveManager = new KeepAliveManager(this); PacketLogger = new PacketLogger() { LogConsole = false }; LoginPacketHandlers.RegisterLoginPacketHandlers(this); InGamePacketHandlers.RegisterInGamePacketHandler(this); }
public CoCClient() { Fingerprint = new Fingerprint(); Home = new Village(); Avatar = new Avatar(); Connection = new Socket(SocketType.Stream, ProtocolType.Tcp); DefaultPacketHandlers = new Dictionary<ushort, PacketHandler>(); PacketHandlers = new Dictionary<ushort, PacketHandler>(); KeepAliveManager = new KeepAliveManager(this); PacketLog = new PacketLog("packets.log") { AutoSave = true }; PluginManager = new PluginManager(this); LoginPacketHandlers.RegisterLoginPacketHandlers(this); InGamePacketHandlers.RegisterInGamePacketHandler(this); PluginManager.LoadPlugins(); PluginManager.EnablePlugins(); }
/// <summary> /// Initializes a new instance of the <see cref="Obstacle"/> class with /// the specified class. /// </summary> /// <param name="id">Sets the ID of this <see cref="Obstacle"/> class.</param> public Obstacle(int id, Village village) : base(id, village) { // Space }
/// <summary> /// Initializes a new instance of the <see cref="Building"/> class with the specified /// <see cref="Village"/> instance and <see cref="BuildingData"/>. /// </summary> /// /// <param name="village"> /// <see cref="Village"/> instance which owns this <see cref="Building"/>. /// </param> /// /// <param name="data"><see cref="BuildingData"/> representing the data of the <see cref="Building"/>.</param> /// /// <exception cref="ArgumentNullException"><paramref name="village"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</exception> public Building(Village village, BuildingData data) : base(village, data) { SetComponents(); }
/// <summary> /// Initailizes a new instance of the <see cref="Building"/> class with the specified /// ID and level. /// </summary> /// <param name="id">Sets the ID of this <see cref="Building"/> class.</param> /// <param name="level">Sets the Level of this <see cref="Building"/> class</param> public Building(int id, int level, Village village) : base(id, village) { Level = level; }
public void ReadPacket(PacketReader reader) { LastVisit = TimeSpan.FromSeconds(reader.ReadInt32()); //Unknown1 = reader.ReadInt(); reader.Seek(4, SeekOrigin.Current); TimeStamp = reader.ReadInt64(); UserID = reader.ReadInt64(); ShieldDuration = TimeSpan.FromSeconds(reader.ReadInt32()); //Unknown2 = reader.ReadLong(); reader.Seek(8, SeekOrigin.Current); Compressed = reader.ReadBoolean(); Home = new Village(); Home.ReadFromPacketReader(reader); //Unknown4 = reader.ReadInt(); reader.Seek(4, SeekOrigin.Current); //UserID2 = reader.ReadLong(); //UserID3 = reader.ReadLong(); reader.Seek(16, SeekOrigin.Current); if ((HasClan = reader.ReadBoolean())) { Clan = new Clan() { ID = reader.ReadInt64(), Name = reader.ReadString(), Badge = reader.ReadInt32(), }; Level = reader.ReadInt32(); // member status? Level = reader.ReadInt32(); } if (reader.ReadBoolean()) reader.Seek(8, SeekOrigin.Current); if (reader.ReadBoolean()) reader.Seek(8, SeekOrigin.Current); //Unknown5 = (byte)reader.ReadByte(); //Unknown6 = reader.ReadInt(); //Unknown7 = reader.ReadLong(); //Unknown8 = reader.ReadLong(); reader.Seek(4, SeekOrigin.Current); AllianceCastleLevel = reader.ReadInt32(); AllianceCastleCapacity = reader.ReadInt32(); AllianceCastleUsed = reader.ReadInt32(); TownHallLevel = reader.ReadInt32(); Username = reader.ReadString(); FacebookID = reader.ReadInt32(); Level = reader.ReadInt32(); Experience = reader.ReadInt32(); Gems = reader.ReadInt32(); //Gems1 = reader.ReadInt(); //Unknown9 = reader.ReadLong(); reader.Seek(12, SeekOrigin.Current); TrophiesCount = reader.ReadInt32(); AttackWon = reader.ReadInt32(); AttackLost = reader.ReadInt32(); DefenceWon = reader.ReadInt32(); DefenceLost = reader.ReadInt32(); reader.Seek(21, SeekOrigin.Current); HasName = reader.ReadBoolean(); reader.Seek(16, SeekOrigin.Current); }
/// <summary> /// /// </summary> public VillageObject(Village village) { ID = -1; Village = village; }
/// <summary> /// Initializes a new instance of the <see cref="Decoration"/> class with /// the specified ID. /// </summary> /// <param name="id">Sets the ID of this <see cref="Decoration"/> class.</param> public Decoration(int id, Village village) : base(id, village) { // Space }
/// <summary> /// Initializes a new instance of the <see cref="Obstacle"/> class with /// the specified class. /// </summary> /// <param name="id">Sets the ID of this <see cref="Obstacle"/> class.</param> public Obstacle(int id, Village village) : base(id, village) { // Space }
public void ReadPacket(PacketReader reader) { var offset = 0x2A; LastVisit = TimeSpan.FromSeconds(reader.ReadInt32()); Unknown1 = reader.ReadInt32(); Timestamp = DateTimeConverter.FromUnixTimestamp(reader.ReadInt32()); Unknown2 = reader.ReadInt32(); UserID = reader.ReadInt64(); ShieldDuration = TimeSpan.FromSeconds(reader.ReadInt32()); Unknown3 = reader.ReadInt32(); Unknown4 = reader.ReadInt32(); Compressed = reader.ReadBoolean(); Home = new Village(); Home.Read(reader); Avatar = new Avatar(); // Seems like a whole object Unknown6 = reader.ReadInt32(); UserID1 = reader.ReadInt64(); UserID2 = reader.ReadInt64(); Avatar.ID = UserID1; switch (reader.ReadByte()) { case 0: break; case 1: Avatar.Clan = new Clan(); Avatar.Clan.ID = reader.ReadInt64(); Avatar.Clan.Name = reader.ReadString(); Avatar.Clan.Badge = reader.ReadInt32(); reader.ReadInt32(); Avatar.Clan.Level = reader.ReadInt32(); offset += 1; break; case 2: // clanless but clan castle built? var lel = reader.ReadInt64(); break; } if (Unknown7 = reader.ReadBoolean()) Unknown8 = reader.ReadInt64(); if (Unknown9 = reader.ReadBoolean()) Unknown10 = reader.ReadInt64(); reader.Seek(offset, SeekOrigin.Current); Unknown11 = reader.ReadInt32(); AllianceCastleLevel = reader.ReadInt32(); // -1 if not constructed AllianceCastleUnitCapacity = reader.ReadInt32(); AllianceCastleUnitCount = reader.ReadInt32(); Avatar.TownHallLevel = reader.ReadInt32(); Avatar.Username = reader.ReadString(); FacebookID = reader.ReadString(); Avatar.Level = reader.ReadInt32(); Avatar.Experience = reader.ReadInt32(); Avatar.Gems = reader.ReadInt32(); Gems1 = reader.ReadInt32(); Unknown14 = reader.ReadInt32(); Unknown15 = reader.ReadInt32(); Avatar.Trophies = reader.ReadInt32(); Avatar.AttacksWon = reader.ReadInt32(); Avatar.AttacksLost = reader.ReadInt32(); Avatar.DefencesWon = reader.ReadInt32(); Avatar.DefencesLost = reader.ReadInt32(); Unknown16 = reader.ReadInt32(); Unknown17 = reader.ReadInt32(); Unknown18 = reader.ReadInt32(); if (Unknown19 = reader.ReadBoolean()) Unknown20 = reader.ReadInt64(); Unknown21 = reader.ReadByte(); Unknown22 = reader.ReadInt32(); Unknown23 = reader.ReadInt32(); Unknown24 = reader.ReadInt32(); Unknown25 = reader.ReadInt32(); var count1 = reader.ReadInt32(); for (int i = 0; i < count1; i++) { var id = reader.ReadInt32(); // resource id from resources.csv var capacity = reader.ReadInt32(); } var count2 = reader.ReadInt32(); for (int i = 0; i < count2; i++) { var id = reader.ReadInt32(); // resource id from resources.csv var amount = reader.ReadInt32(); } var count3 = reader.ReadInt32(); for (int i = 0; i < count3; i++) { var id = reader.ReadInt32(); // unit id from characters.csv var amount = reader.ReadInt32(); } var count4 = reader.ReadInt32(); for (int i = 0; i < count4; i++) { var id = reader.ReadInt32(); // spell id from spells.csv var amount = reader.ReadInt32(); } var count5 = reader.ReadInt32(); for (int i = 0; i < count5; i++) { var id = reader.ReadInt32(); // unit id from characters.csv var level = reader.ReadInt32(); } var count6 = reader.ReadInt32(); for (int i = 0; i < count6; i++) { var id = reader.ReadInt32(); // spell id from spells.csv var level = reader.ReadInt32(); } var count7 = reader.ReadInt32(); for (int i = 0; i < count7; i++) { var id = reader.ReadInt32(); // hero id from heros.csv var level = reader.ReadInt32(); } var count8 = reader.ReadInt32(); for (int i = 0; i < count8; i++) { var id = reader.ReadInt32(); // hero id from heros.csv var health = reader.ReadInt32(); } var count9 = reader.ReadInt32(); for (int i = 0; i < count9; i++) { var id = reader.ReadInt32(); // hero id from heros.csv var state = reader.ReadInt32(); } var count10 = reader.ReadInt32(); for (int i = 0; i < count10; i++) { var id = reader.ReadInt32(); // unit id from characters.csv var amount = reader.ReadInt32(); var level = reader.ReadInt32(); } var count11 = reader.ReadInt32(); for (int i = 0; i < count11; i++) { var id = reader.ReadInt32(); // mission id from missions.csv } var count12 = reader.ReadInt32(); for (int i = 0; i < count12; i++) { var id = reader.ReadInt32(); // achievement id from achievements.csv } var count13 = reader.ReadInt32(); for (int i = 0; i < count13; i++) { var id = reader.ReadInt32(); // achievement id from achievements.csv var progress = reader.ReadInt32(); } var count14 = reader.ReadInt32(); for (int i = 0; i < count14; i++) { var id = reader.ReadInt32(); // npc id from npcs.csv var stars = reader.ReadInt32(); } var count15 = reader.ReadInt32(); for (int i = 0; i < count15; i++) { var id = reader.ReadInt32(); // npc id from npcs.csv var gold = reader.ReadInt32(); } var count16 = reader.ReadInt32(); for (int i = 0; i < count16; i++) { var id = reader.ReadInt32(); // npc id from npcs.csv var elixir = reader.ReadInt32(); } Unknown26 = reader.ReadInt32(); Unknown27 = reader.ReadInt32(); Unknown28 = reader.ReadInt32(); }
/// <summary> /// /// </summary> /// <param name="id"></param> public VillageObject(int id, Village village) { ID = id; Village = village; }
/// <summary> /// /// </summary> public VillageObject(Village village) { ID = -1; Village = village; }
/// <summary> /// Initializes a new instance of the <see cref="Obstacle"/> class with the specified /// <see cref="Village"/> instance and <see cref="ObstacleData"/>. /// </summary> /// /// <param name="village"> /// <see cref="Village"/> instance which owns this <see cref="Obstacle"/>. /// </param> /// /// <param name="data"><see cref="ObstacleData"/> representing the data of the <see cref="Obstacle"/>.</param> /// /// <exception cref="ArgumentNullException"><paramref name="village"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</exception> public Trap(Village village, TrapData data) : base(village, data) { // Space }
public void ReadPacket(PacketReader reader) { Unknown1 = reader.ReadInt32(); Unknown2 = reader.ReadInt32(); UserID = reader.ReadInt64(); Shield = TimeSpan.FromSeconds(reader.ReadInt32()); Unknown3 = reader.ReadInt32(); Unknown4 = reader.ReadInt32(); Compressed = reader.ReadBoolean(); Home = new Village(); Home.Read(reader); Unknown5 = reader.ReadInt32(); UserID1 = reader.ReadInt64(); UserID2 = reader.ReadInt64(); var offset = 0x2A; bool isClan = reader.ReadBoolean(); if (isClan) { Clan = new Clan(); Clan.ID = reader.ReadInt64(); Clan.Name = reader.ReadString(); Clan.Badge = reader.ReadInt32(); Unknown6 = reader.ReadInt32(); Clan.Level = reader.ReadInt32(); offset += 1; } bool Unknown7 = reader.ReadBoolean(); if (Unknown7) Unknown8 = reader.ReadInt64(); bool Unknown9 = reader.ReadBoolean(); if (Unknown9) Unknown10 = reader.ReadInt64(); reader.Seek(offset, SeekOrigin.Current); Unknown11 = reader.ReadInt32(); Unknown12 = reader.ReadInt32(); Unknown13 = reader.ReadInt32(); ClanUnits = reader.ReadInt32(); TownHall = reader.ReadInt32(); Username = reader.ReadString(); FacebookID = reader.ReadString(); Stars = reader.ReadInt32(); Points = reader.ReadInt32(); Unknown14 = reader.ReadInt32(); Unknown15 = reader.ReadInt32(); Unknown16 = reader.ReadInt32(); Unknown17 = reader.ReadInt32(); Trophies = reader.ReadInt32(); AttacksWon = reader.ReadInt32(); Unknown18 = reader.ReadInt32(); DefenseWon = reader.ReadInt32(); Unknown19 = reader.ReadInt32(); Unknown20 = reader.ReadInt32(); Unknown21 = reader.ReadInt32(); Unknown22 = reader.ReadInt32(); bool Unknown23 = reader.ReadBoolean(); if (Unknown23) Unknown24 = reader.ReadInt64(); Unknown25 = reader.ReadByte(); Unknown26 = reader.ReadInt32(); Unknown27 = reader.ReadInt32(); Unknown28 = reader.ReadInt32(); Unknown29 = reader.ReadInt32(); var count = reader.ReadInt32(); //storage for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //resources for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //units for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //spells for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //unit_upgrades for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //spell_upgrades for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //hero_upgrades for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //hero_health for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //hero_state for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); } count = reader.ReadInt32(); //alliance_units for (int i = 0; i < count; i++) { var id = reader.ReadInt32(); var capacity = reader.ReadInt32(); var level = reader.ReadInt32(); } // more (needed?) values... }
/// <summary> /// Initializes a new instance of the <see cref="Decoration"/> class with /// the specified ID. /// </summary> /// <param name="id">Sets the ID of this <see cref="Decoration"/> class.</param> public Decoration(int id, Village village) : base(id, village) { // Space }
/// <summary> /// /// </summary> /// <param name="id"></param> public VillageObject(int id, Village village) { ID = id; Village = village; }
/// <summary> /// Initializes a new instance of the <see cref="Buildable{TCsvData}"/> class with the specified /// <see cref="Village"/> instance and <typeparamref name="TCsvData"/>. /// </summary> /// /// <param name="village"> /// <see cref="Village"/> instance which owns this <see cref="Buildable{TCsvData}"/>. /// </param> /// /// <param name="data"><typeparamref name="TCsvData"/> representing the data of the <see cref="Buildable{TCsvData}"/>.</param> /// /// <exception cref="ArgumentNullException"><paramref name="village"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</exception> protected Buildable(Village village, TCsvData data) : base(village, data) { _upgradeLevel = -1; _timer = new TickTimer(); }
/// <summary> /// Initializes a new instance of the <see cref="Decoration"/> class with the specified /// <see cref="Village"/> instance and <see cref="DecorationData"/>. /// </summary> /// /// <param name="village"> /// <see cref="Village"/> instance which owns this <see cref="Decoration"/>. /// </param> /// /// <param name="data"><see cref="DecorationData"/> representing the data of the <see cref="Decoration"/>.</param> /// /// <exception cref="ArgumentNullException"><paramref name="village"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</exception> public Decoration(Village village, DecorationData data) : base(village, data) { // Space }
/// <summary> /// Initializes a new instance of the <see cref="Obstacle"/> class with the specified /// <see cref="Village"/> instance and <see cref="ObstacleData"/>. /// </summary> /// /// <param name="village"> /// <see cref="Village"/> instance which owns this <see cref="Obstacle"/>. /// </param> /// /// <param name="data"><see cref="ObstacleData"/> representing the data of the <see cref="Obstacle"/>.</param> /// /// <exception cref="ArgumentNullException"><paramref name="village"/> is null.</exception> /// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</exception> public Obstacle(Village village, ObstacleData data) : base(village, data) { _timer = new TickTimer(); }
/// <summary> /// Initailizes a new instance of the <see cref="Trap"/> class with the specified /// ID and level. /// </summary> /// <param name="id">Sets the ID of this <see cref="Trap"/> class.</param> /// <param name="level">Sets the ID of this <see cref="Trap"/> class.</param> public Trap(int id, int level, Village village) : base(id, village) { Level = level; }
/// <summary> /// Initailizes a new instance of the <see cref="Building"/> class with the specified /// ID and level. /// </summary> /// <param name="id">Sets the ID of this <see cref="Building"/> class.</param> /// <param name="level">Sets the Level of this <see cref="Building"/> class</param> public Building(int id, int level, Village village) : base(id, village) { Level = level; }
/// <summary> /// Initailizes a new instance of the <see cref="Trap"/> class with the specified /// ID and level. /// </summary> /// <param name="id">Sets the ID of this <see cref="Trap"/> class.</param> /// <param name="level">Sets the ID of this <see cref="Trap"/> class.</param> public Trap(int id, int level, Village village) : base(id, village) { Level = level; }
public int Unknown4; // 0 /// <summary> /// Reads the <see cref="VillageData"/> from the specified <see cref="MessageReader"/>. /// </summary> /// <param name="reader"> /// <see cref="MessageReader"/> that will be used to read the <see cref="VillageData"/>. /// </param> /// <exception cref="NotImplementedException">Compressed set to false.</exception> /// <exception cref="InvalidMessageException">Home data array is null.</exception> public void Read(MessageReader reader) { if (!Compressed) throw new NotImplementedException("Uncompressed Village definition is not implemented."); Unknown1 = reader.ReadInt32(); // 0 UserID = reader.ReadInt64(); ShieldDuration = TimeSpan.FromSeconds(reader.ReadInt32()); Unknown2 = reader.ReadInt32(); // 1200 Unknown3 = reader.ReadInt32(); // 60 Compressed = reader.ReadBoolean(); var homeData = reader.ReadBytes(); if (homeData == null) throw new InvalidMessageException("No data was provided about Village."); using (var br = new BinaryReader(new MemoryStream(homeData))) // little endian { var decompressedLength = br.ReadInt32(); var compressedHome = br.ReadBytes(homeData.Length - 4); // -4 to remove the decompressedLength bytes read var homeJson = ZlibStream.UncompressString(compressedHome); Home = Village.FromJson(homeJson); } Unknown4 = reader.ReadInt32(); }