public static void HandleLoginRequestPacket(CoCRemoteClient client, CoCServer server, IPacket packet) { client.Seed = ((LoginRequestPacket)packet).Seed; client.QueuePacket(new UpdateKeyPacket() { Key = new byte[] { 23, 32, 45, 13, 54, 43 } }); client.QueuePacket(new LoginSuccessPacket() { UserID = 12312332, UserToken = "SOMETOKEN", ServerEnvironment = "prod", DateJoined = "123123", DateLastPlayed = "123123", FacebookAppID = "asdasd", FacebookID = "asdasd", GameCenterID = "asdasd", GooglePlusID = "asdasdsdad", LoginCount = 69, MajorVersion = 7, MinorVersion = 156, PlayTime = new TimeSpan(0, 0, 0), RevisionVersion = 0, CountryCode = "MU" }); }
private static void HandleChatMessageClientMessageMessage(CoCServer server, CoCRemoteClient client, Message message) { var cmcMessage = message as ChatMessageClientMessage; var cmsMessage = new ChatMessageServerMessage(); //TODO: Set alliance and all that jazz. cmsMessage.Name = client.Avatar.Name; cmsMessage.Message = cmcMessage.Message; for (int i = 0; i < server.Clients.Count; i++) server.Clients[i].NetworkManager.SendMessage(cmsMessage); }
private static void HandleCommandMessage(CoCServer server, CoCRemoteClient client, Message message) { var cmdMessage = message as CommandMessage; if (cmdMessage.Commands.Length > 0) { for (int i = 0; i < cmdMessage.Commands.Length; i++) { var cmd = cmdMessage.Commands[i]; if (cmd == null) continue; var handler = (CommandHandler)null; if (server.CommandHandlers.TryGetValue(cmd.ID, out handler)) handler(server, client, cmd); } server.AvatarManager.SaveAvatar(client.Avatar); } }
private static void HandleBuyBuildingCommand(CoCServer server, CoCRemoteClient client, Command command) { s_client = client; //TODO: Find a more consitent way of doing stuff. s_server = server; var bbCmd = command as BuyBuildingCommand; var dataIndex = bbCmd.BuildingDataIndex; var dataID = Building.IndexToDataID(dataIndex); //Console.WriteLine("Buying new building {0} at {1}, {2}", dataID, bbCmd.X, bbCmd.Y); var building = new Building(dataID); building.Data = server.DataManager.FindBuilding(dataIndex, 0); building.X = bbCmd.X; building.Y = bbCmd.Y; building.BeginConstruct(); building.ConstructionFinished += OnConstructed; client.Avatar.Home.Buildings.Add(building); }
private static void HandleKeepAliveRequestMessage(CoCServer server, CoCRemoteClient client, Message message) { client.NetworkManager.SendMessage(new KeepAliveResponseMessage()); }
private static void HandleLoginRequestMessage(CoCServer server, CoCRemoteClient client, Message message) { var encryptionMessage = new EncryptionMessage() { ServerRandom = Crypto7.GenerateNonce(), ScramblerVersion = 1 }; var lrMessage = message as LoginRequestMessage; var lsMessage = new LoginSuccessMessage() { FacebookID = null, GameCenterID = null, MajorVersion = 7, MinorVersion = 200, RevisionVersion = 19, ServerEnvironment = "prod", LoginCount = 0, PlayTime = new TimeSpan(0, 0, 0), //TODO: Implement saving of playtime. Unknown1 = 0, FacebookAppID = "297484437009394", //TODO: Implement this into CoCSharp itself. DateLastPlayed = DateTime.Now, //TODO: Implement saving of date last played. DateJoined = DateTime.Now, //TODO: Implement saving of date joined. Unknown2 = 0, GooglePlusID = null, CountryCode = "EU" }; var avatar = (Avatar)null; if (lrMessage.UserID == 0 && lrMessage.UserToken == null) // new account { avatar = server.AvatarManager.CreateNewAvatar(); Console.WriteLine("Created new avatar with Token {0}, ID {1}", avatar.Token, avatar.ID); lsMessage.UserID = avatar.ID; lsMessage.UserID1 = avatar.ID; lsMessage.UserToken = avatar.Token; } else { if (!server.AvatarManager.LoadedAvatar.TryGetValue(lrMessage.UserToken, out avatar)) // unknown token and id { avatar = server.AvatarManager.CreateNewAvatar(lrMessage.UserToken, lrMessage.UserID); Console.WriteLine("Unknown avatar, Created new avatar with Token {0}, ID {1}", avatar.Token, avatar.ID); } else Console.WriteLine("Avatar with Token {0}, ID {1} logged in.", avatar.Token, avatar.ID); lsMessage.UserID = avatar.ID; lsMessage.UserID1 = avatar.ID; lsMessage.UserToken = avatar.Token; } server.AvatarManager.SaveAvatar(avatar); client.Avatar = avatar; var avatarData = new AvatarData(avatar) { TownHallLevel = 5, AllianceCastleLevel = 1, AllianceCastleTotalCapacity = 10, AllianceCastleUsedCapacity = 0, ResourcesCapacity = new ResourceCapacitySlot[] { new ResourceCapacitySlot(3000001, 1000), new ResourceCapacitySlot(3000002, 1000) }, ResourcesAmount = new ResourceAmountSlot[] { new ResourceAmountSlot(3000001, 100), new ResourceAmountSlot(3000002, 200) } }; var ohdMessage = new OwnHomeDataMessage() { LastVisit = TimeSpan.FromSeconds(100), Unknown1 = -1, Timestamp = DateTime.UtcNow, OwnAvatarData = avatarData }; client.NetworkManager.SendMessage(encryptionMessage); client.NetworkManager.SendMessage(lsMessage); // LoginSuccessMessage client.NetworkManager.SendMessage(ohdMessage); // OwnHomeDataMessage }
private static void HandleUpgradeBuildingCommand(CoCServer server, CoCRemoteClient client, Command command) { // Space }
public static void RegisterLoginPacketHandlers(CoCRemoteClient client) { client.RegisterPacketHandler(new LoginRequestPacket(), HandleLoginRequestPacket); }
public static void HandleKeepAliveRequestPacket(CoCRemoteClient client, CoCServer server, IPacket packet) { client.QueuePacket(new KeepAliveResponsePacket()); }
public static void RegisterInGamePacketHandlers(CoCRemoteClient client) { client.RegisterPacketHandler(new KeepAliveRequestPacket(), HandleKeepAliveRequestPacket); }
public static void HandleLoginRequestPacket(CoCRemoteClient client, CoCServer server, IPacket packet) { var lrPacket = packet as LoginRequestPacket; client.NetworkManager.Seed = lrPacket.Seed; client.QueuePacket(new UpdateKeyPacket() { Key = CoCCrypto.CreateRandomByteArray(), ScramblerVersion = 1 }); if (lrPacket.UserID == 0 && lrPacket.UserToken == null) { client.Avatar = server.AvatarManager.NewAvatar; client.Home = server.DefaultVillage; } client.QueuePacket(new LoginSuccessPacket() { UserID = client.Avatar.ID, UserID1 = client.Avatar.ID, UserToken = client.Avatar.Token, FacebookID = null, GameCenterID = null, MajorVersion = 7, MinorVersion = 156, RevisionVersion = 5, ServerEnvironment = "prod", LoginCount = 0, PlayTime = new TimeSpan(0, 0, 0), Unknown1 = 0, FacebookAppID = "297484437009394", DateLastPlayed = DateTime.Now, DateJoined = DateTime.Now, Unknown2 = 0, GooglePlusID = null, CountryCode = "MU" }); client.QueuePacket(new OwnHomeDataPacket() { LastVisit = TimeSpan.FromSeconds(0), Unknown1 = -1, Timestamp = DateTime.UtcNow, Unknown2 = 0, UserID = client.Avatar.ID, ShieldDuration = TimeSpan.FromSeconds(10), Unknown3 = 1200, Unknown4 = 60, Compressed = true, Home = client.Home, Avatar = client.Avatar, Unknown6 = 0, UserID1 = client.Avatar.ID, UserID2 = client.Avatar.ID, AllianceCastleLevel = -1, Unknown14 = 1200, Unknown15 = 60, Unknown19 = true, Unknown20 = 946720861000, Unknown21 = 1, Unknown25 = 1, }); }