public static void BattleSignIn(Client client, string jsonPacketData) { client.packetMap.Remove("BattleSignIn"); BattleSignIn battleSignIn = JsonConvert.DeserializeObject<BattleSignIn>(jsonPacketData); if (InternalSignIn(client, battleSignIn.email, battleSignIn.password)) { Battle battle = BattleAPI.GetBattle(client.account.username); if (!PlayerAPI.IsOnline(battle.opponent)) { while (!PlayerAPI.IsOnline(battle.opponent)) { Thread.Sleep(1); } BattleSignInFinish(client); } else { BattleSignInFinish(client); } } }
public static void RemoveCard(Client client, int cardId) { client.account.cardMap.Remove(cardId); int lastId; DB.Database.Execute(client.connection, out lastId, true, true, "DELETE FROM account_cards WHERE id = ?", cardId); }
public static void DeckCards(Client client, string jsonPacketData) { client.packetMap.Remove("DeckCards"); DeckCards deckCardsClient = JsonConvert.DeserializeObject<DeckCards>(jsonPacketData); DeckCards deckCardsServer = new DeckCards(); if (client.account.deckMap.ContainsKey(deckCardsClient.deck)) { Deck deck = client.account.deckMap[deckCardsClient.deck]; deckCardsServer.deck = deckCardsClient.deck; deckCardsServer.valid = deck.valid; deckCardsServer.metadata = deck.metadata; foreach (string resource in deck.resources) { deckCardsServer.resources.Add(resource); } foreach (Card card in deck.cards) { deckCardsServer.cards.Add(card); } client.Send(deckCardsServer); } else { Console.WriteLine("{0} requested the deck {1} which they don't own!", client.account.username, deckCardsClient.deck); PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!"); } }
public static void RemoveShards(Client client, int amount) { client.account.shards -= amount; int lastId; DB.Database.Execute(client.connection, out lastId, true, true, "UPDATE account_data SET shards = ? WHERE guid = ?", client.account.shards, client.account.id); }
public static void IncreaseGold(Client client, int amount) { client.account.gold += amount; int lastId; DB.Database.Execute(client.connection, out lastId, true, true, "UPDATE account_data SET gold = ? WHERE guid = ?", client.account.gold, client.account.id); }
public static void AvatarSave(Client client, string jsonPacketData) { client.packetMap.Remove("AvatarSave"); AvatarSave avatarSave = JsonConvert.DeserializeObject<AvatarSave>(jsonPacketData); client.account.avatar.head = avatarSave.head; client.account.avatar.body = avatarSave.body; client.account.avatar.leg = avatarSave.leg; client.account.avatar.armBack = avatarSave.armBack; client.account.avatar.armFront = avatarSave.armFront; if (Variables.avatarTypeMap.ContainsKey(avatarSave.head) && Variables.avatarTypeMap.ContainsKey(avatarSave.body) && Variables.avatarTypeMap.ContainsKey(avatarSave.leg) && Variables.avatarTypeMap.ContainsKey(avatarSave.armBack) && Variables.avatarTypeMap.ContainsKey(avatarSave.armFront)) { int lastId; DB.Database.Execute(client.connection, out lastId, true, true, "UPDATE account_avatar SET head = ?, body = ?, leg = ?, armBack = ?, armFront = ? WHERE guid = ?", avatarSave.head, avatarSave.body, avatarSave.leg, avatarSave.armBack, avatarSave.armFront, client.account.id); } else { Console.WriteLine("{0} tried to save an avatar with invalid avatar type(s)!", client.account.username); PlayerAPI.KickPlayer(client, "AntiCheat: You have been disconnected from the server!"); } }
public static void RoomEnterFree(Client client, string jsonPacketData) { client.packetMap.Remove("RoomEnterFree"); RoomEnterFree roomEnterFree = JsonConvert.DeserializeObject<RoomEnterFree>(jsonPacketData); RoomAPI.JoinRoom(client, roomEnterFree.roomName); }
public static void RoomExit(Client client, string jsonPacketData) { client.packetMap.Remove("RoomExit"); RoomExit roomExit = JsonConvert.DeserializeObject<RoomExit>(jsonPacketData); client.account.chatroomList.Remove(roomExit.roomName); RoomAPI.RemovePlayer(roomExit.roomName, client.account.username); }
public static Card GetCard(Client client, int cardId) { if (client.account.cardMap.ContainsKey(cardId)) { return client.account.cardMap[cardId]; } return null; }
public static void PurchaseItem(Client client, string itemType) { BuyStoreItemResponse buyStoreItemResponse = new BuyStoreItemResponse(); Random random = new Random(); switch (itemType) { case "CARD_DECAY": { Card card = CardAPI.AddCard(client, Variables.cardTypeDecayMap[Variables.cardTypeDecayMap.Keys.ToList()[random.Next(Variables.cardTypeDecayMap.Count)]]); buyStoreItemResponse.cards.Add(card); break; } case "CARD_ENERGY": { Card card = CardAPI.AddCard(client, Variables.cardTypeEnergyMap[Variables.cardTypeEnergyMap.Keys.ToList()[random.Next(Variables.cardTypeEnergyMap.Count)]]); buyStoreItemResponse.cards.Add(card); break; } case "CARD_FACE_DOWN": { Card card = CardAPI.AddCard(client, Variables.cardTypeMap[Variables.cardTypeMap.Keys.ToList()[random.Next(Variables.cardTypeMap.Count)]]); buyStoreItemResponse.cards.Add(card); break; } case "CARD_GROWTH": { Card card = CardAPI.AddCard(client, Variables.cardTypeGrowthMap[Variables.cardTypeGrowthMap.Keys.ToList()[random.Next(Variables.cardTypeGrowthMap.Count)]]); buyStoreItemResponse.cards.Add(card); break; } case "CARD_ORDER": { Card card = CardAPI.AddCard(client, Variables.cardTypeOrderMap[Variables.cardTypeOrderMap.Keys.ToList()[random.Next(Variables.cardTypeOrderMap.Count)]]); buyStoreItemResponse.cards.Add(card); break; } case "CARD_PACK": { for (int i = 0; i < 10; i++) { Card card = CardAPI.AddCard(client, Variables.cardTypeMap[Variables.cardTypeMap.Keys.ToList()[random.Next(Variables.cardTypeMap.Count)]]); buyStoreItemResponse.cards.Add(card); } break; } } client.Send(buyStoreItemResponse); }
public static void LobbyLookup(Client client) { client.packetMap.Remove("LobbyLookup"); LobbyLookup lobbyLookup = new LobbyLookup(); lobbyLookup.ip = ConfigReader.serverHost; lobbyLookup.port = ConfigReader.lobbyPort; client.Send(lobbyLookup); }
public static void ProfilePageInfo(Client client, string jsonPacketData) { client.packetMap.Remove("ProfilePageInfo"); ProfilePageInfo profilePageInfoClient = JsonConvert.DeserializeObject<ProfilePageInfo>(jsonPacketData); ProfilePageInfo profilePageInfoServer = new ProfilePageInfo(); if (profilePageInfoClient.id != null) { Client remoteSession = PlayerAPI.GetSession(profilePageInfoClient.id, true); if (remoteSession != null) { profilePageInfoServer.name = remoteSession.account.username; profilePageInfoServer.gold = remoteSession.account.gold; profilePageInfoServer.rating = 0; profilePageInfoServer.gamesPlayed = remoteSession.account.gamesPlayed; profilePageInfoServer.gamesWon = remoteSession.account.gamesWon; profilePageInfoServer.gamesSurrendered = remoteSession.account.gamesSurrendered; profilePageInfoServer.ranking = 0; profilePageInfoServer.scrollsCommon = remoteSession.account.cardTypeCount.common; profilePageInfoServer.scrollsUncommon = remoteSession.account.cardTypeCount.uncommon; profilePageInfoServer.scrollsRare = remoteSession.account.cardTypeCount.rare; profilePageInfoServer.lastGamePlayed = "Never"; profilePageInfoServer.avatar.profileId = remoteSession.account.id; profilePageInfoServer.avatar.head = remoteSession.account.avatar.head; profilePageInfoServer.avatar.body = remoteSession.account.avatar.body; profilePageInfoServer.avatar.leg = remoteSession.account.avatar.leg; profilePageInfoServer.avatar.armBack = remoteSession.account.avatar.armBack; profilePageInfoServer.avatar.armFront = remoteSession.account.avatar.armFront; } } else { profilePageInfoServer.name = client.account.username; profilePageInfoServer.gold = client.account.gold; profilePageInfoServer.rating = 0; profilePageInfoServer.gamesPlayed = client.account.gamesPlayed; profilePageInfoServer.gamesWon = client.account.gamesWon; profilePageInfoServer.gamesSurrendered = client.account.gamesSurrendered; profilePageInfoServer.ranking = 0; profilePageInfoServer.scrollsCommon = client.account.cardTypeCount.common; profilePageInfoServer.scrollsUncommon = client.account.cardTypeCount.uncommon; profilePageInfoServer.scrollsRare = client.account.cardTypeCount.rare; profilePageInfoServer.lastGamePlayed = "Never"; profilePageInfoServer.avatar.profileId = client.account.id; profilePageInfoServer.avatar.head = client.account.avatar.head; profilePageInfoServer.avatar.body = client.account.avatar.body; profilePageInfoServer.avatar.leg = client.account.avatar.leg; profilePageInfoServer.avatar.armBack = client.account.avatar.armBack; profilePageInfoServer.avatar.armFront = client.account.avatar.armFront; } client.Send(profilePageInfoServer); }
public static void TradeAcceptBargain(Client client) { client.packetMap.Remove("TradeAcceptBargain"); if (client.account.tradeStatus.trading) { Client opponentSession = PlayerAPI.GetSession(client.account.tradeStatus.partner, false); if (opponentSession != null && !client.account.tradeStatus.accepted) { client.account.tradeStatus.accepted = !client.account.tradeStatus.accepted; TradeViewUpdate(client, opponentSession); if (opponentSession.account.tradeStatus.accepted) { if (client.account.tradeStatus.gold > 0) { PlayerAPI.RemoveGold(client, client.account.tradeStatus.gold); PlayerAPI.IncreaseGold(opponentSession, client.account.tradeStatus.gold); } if (opponentSession.account.tradeStatus.gold > 0) { PlayerAPI.RemoveGold(opponentSession, opponentSession.account.tradeStatus.gold); PlayerAPI.IncreaseGold(client, opponentSession.account.tradeStatus.gold); } if (client.account.tradeStatus.cardIds.Count > 0) { foreach (int cardId in client.account.tradeStatus.cardIds) { CardAPI.RemoveCardFromDecks(client, cardId); CardAPI.TransferCard(client, opponentSession, cardId); PlayerAPI.UpdateScrollTypeCount(client); PlayerAPI.UpdateScrollTypeCount(opponentSession); } } if (opponentSession.account.tradeStatus.cardIds.Count > 0) { foreach (int cardId in opponentSession.account.tradeStatus.cardIds) { CardAPI.RemoveCardFromDecks(opponentSession, cardId); CardAPI.TransferCard(opponentSession, client, cardId); PlayerAPI.UpdateScrollTypeCount(client); PlayerAPI.UpdateScrollTypeCount(opponentSession); } } RoomAPI.Message("trade-" + client.account.tradeStatus.tradeId, "Scrolls", "Trade complete."); } } } }
public static void JoinRoom(Client client, string roomName) { client.account.chatroomList.Add(roomName); RoomAPI.AddPlayer(roomName, client.account.username); List<string> playerList = RoomAPI.GetPlayerList(roomName); RoomEnter roomEnterServer = new RoomEnter(); roomEnterServer.roomName = roomName; client.Send(roomEnterServer); RoomInfo roomInfo = new RoomInfo(); roomInfo.updated = new List<RoomInfo.PlayerInfo>(); roomInfo.roomName = roomName; roomInfo.reset = false; foreach (string playerName in playerList) { Client roomClient = PlayerAPI.GetSession(playerName, false); RoomInfo.PlayerInfo playerInfo = new RoomInfo.PlayerInfo(); playerInfo.id = roomClient.account.id; playerInfo.name = roomClient.account.username; playerInfo.acceptChallenges = roomClient.account.acceptChallenges; playerInfo.acceptTrades = roomClient.account.acceptTrades; playerInfo.adminRole = roomClient.account.adminRole; roomInfo.updated.Add(playerInfo); } client.Send(roomInfo); RoomAPI.Message(roomName, "Scrolls", "You have joined \"" + roomName + "\"", client); RoomInfo newPlayerAlert = new RoomInfo(); newPlayerAlert.updated = new List<RoomInfo.PlayerInfo>(); newPlayerAlert.roomName = roomName; RoomInfo.PlayerInfo newPlayerInfo = new RoomInfo.PlayerInfo(); newPlayerInfo.id = client.account.id; newPlayerInfo.name = client.account.username; newPlayerInfo.acceptChallenges = client.account.acceptChallenges; newPlayerInfo.acceptTrades = client.account.acceptTrades; newPlayerInfo.adminRole = client.account.adminRole; newPlayerAlert.updated.Add(newPlayerInfo); foreach (string playerName in playerList) { PlayerAPI.GetSession(playerName, false).Send(newPlayerAlert); } }
public static void AvatarTypes(Client client) { client.packetMap.Remove("AvatarTypes"); AvatarTypes avatarTypes = new AvatarTypes(); foreach (KeyValuePair<int, AvatarType> avatarType in Variables.avatarTypeMap) { avatarTypes.types.Add(avatarType.Value); } client.Send(avatarTypes); }
public static void ProfileInfo(Client client) { client.packetMap.Remove("ProfileInfo"); ProfileInfo profileInfo = new ProfileInfo(); profileInfo.profile.id = client.account.id; profileInfo.profile.userUuid = ""; //Note: Unsure what exactly the userUuid does or how it is generated profileInfo.profile.name = client.account.username; profileInfo.profile.acceptChallenges = client.account.acceptChallenges; profileInfo.profile.acceptTrades = client.account.acceptTrades; profileInfo.profile.adminRole = client.account.adminRole; profileInfo.profile.userType = "Beta"; client.Send(profileInfo); }
public static void RoomChatMessage(Client client, string jsonPacketData) { client.packetMap.Remove("RoomChatMessage"); RoomChatMessage roomChatMessage = JsonConvert.DeserializeObject<RoomChatMessage>(jsonPacketData); if (roomChatMessage.text.StartsWith("/")) { RoomChatHandler.HandleCommand(client, roomChatMessage.roomName, roomChatMessage.text.Remove(0, 1)); } else { RoomAPI.Message(roomChatMessage.roomName, client.account.username, roomChatMessage.text); } }
public static void UpdateScrollTypeCount(Client client) { client.account.cardTypeCount.common = 0; client.account.cardTypeCount.uncommon = 0; client.account.cardTypeCount.rare = 0; foreach (KeyValuePair<int, Card> card in client.account.cardMap) { switch (CardAPI.GetCardType(card.Value.typeId).rarity) { case 0: { client.account.cardTypeCount.common++; break; } case 1: { client.account.cardTypeCount.uncommon++; break; } case 2: { client.account.cardTypeCount.rare++; break; } } } }
public static void KickPlayer(Client client, string reason) { FailMessage failMessage = new FailMessage(); failMessage.op = "Reconnect"; failMessage.info = reason; client.Send(failMessage); FailMessage infoFailMessage = new FailMessage(); infoFailMessage.info = reason; client.Send(infoFailMessage); Variables.sessionMap.Remove(client.account.username); client.account = new Account(); }
public static Card AddCard(Client client, CardType cardType) { int lastId; DB.Database.Execute(client.connection, out lastId, true, true, "INSERT INTO account_cards VALUES (0, ?, ?, 1, 0, 0);", client.account.id, cardType.id); Card card = new Card(); card.id = lastId; card.typeId = cardType.id; card.tradable = true; card.isToken = false; card.level = 0; client.account.cardMap.Add(card.id, card); return card; }
private static void BattleSignInFinish(Client client) { Battle battle = BattleAPI.GetBattle(client.account.username); if (battle.phase == null) { battle.phase = "Init"; BattleHandler.GameInfo(client); } else { BattleAPI.Message(battle, "Scrolls", client.account.username + " has reconnected!"); BattleHandler.GameInfo(client); } }
public static void ProfileDataInfo(Client client) { client.packetMap.Remove("ProfileDataInfo"); ProfileDataInfo profileDataInfo = new ProfileDataInfo(); profileDataInfo.profileData.gold = client.account.gold; profileDataInfo.profileData.shards = client.account.shards; profileDataInfo.profileData.rating = 0; if (client.account.selectedPreconstructed != 0) { profileDataInfo.profileData.selectedPreconstructed = client.account.selectedPreconstructed; } client.Send(profileDataInfo); }
public static void RoomEnterMulti(Client client, string jsonPacketData) { client.packetMap.Remove("RoomEnterMulti"); RoomEnterMulti roomEnterMulti = JsonConvert.DeserializeObject<RoomEnterMulti>(jsonPacketData); foreach (string roomName in roomEnterMulti.roomNames) { if (!RoomAPI.Exists(roomName)) { RoomAPI.Add(roomName); } RoomAPI.JoinRoom(client, roomName); } }
public static void BuyStoreItem(Client client, string jsonPacketData) { client.packetMap.Remove("BuyStoreItem"); BuyStoreItem buyStoreItem = JsonConvert.DeserializeObject<BuyStoreItem>(jsonPacketData); string purchaseMessage = ""; StoreItem storeItem = null; if (Variables.storeItemMap.ContainsKey(buyStoreItem.itemId)) { storeItem = Variables.storeItemMap[buyStoreItem.itemId]; if (buyStoreItem.payWithShards) { if (client.account.shards >= storeItem.costShards) { PlayerAPI.RemoveShards(client, storeItem.costShards); } else { purchaseMessage = "Not enough shards to purchase this item."; } } else { if (client.account.gold >= storeItem.costGold) { PlayerAPI.RemoveGold(client, storeItem.costGold); } else { purchaseMessage = "Not enough gold to purchase this item."; } } } if (String.IsNullOrEmpty(purchaseMessage)) { StoreItemHandler.PurchaseItem(client, storeItem.itemType); ProfileHandler.ProfileDataInfo(client); PlayerAPI.UpdateScrollTypeCount(client); } else { FailMessage failMessage = new FailMessage(); failMessage.op = "BuyStoreItem"; failMessage.info = purchaseMessage; client.Send(failMessage); } }
public static void OverallStats(Client client) { client.packetMap.Remove("OverallStats"); SQLResult serverStatsResult = DB.Database.Select(client.connection, true, false, "SELECT * FROM server_stats"); SQLResult cardCountResult = DB.Database.Select(client.connection, false, true, "SELECT COUNT(*) FROM account_cards"); OverallStats overallStats = new OverallStats(); overallStats.serverName = ConfigReader.serverName; overallStats.loginsLast24h = serverStatsResult.Read<int>(0, "loginsLast24h"); overallStats.totalCards = cardCountResult.Read <int>(0, "COUNT(*)"); //Note: Maybe some sort of cache instead? overallStats.totalGoldRewarded = serverStatsResult.Read<int>(0, "totalGoldRewarded"); overallStats.totalSoldCards = serverStatsResult.Read<int>(0, "totalSoldCards"); ; overallStats.nrOfProfiles = Variables.sessionMap.Count; client.Send(overallStats); }
public static void Reconnect(Client client, string jsonPacketData) { client.packetMap.Remove("Reconnect"); Reconnect reconnect = JsonConvert.DeserializeObject<Reconnect>(jsonPacketData); if (InternalSignIn(client, reconnect.email, reconnect.password)) { OkMessage okMessage = new OkMessage(); okMessage.op = "Reconnect"; client.Send(okMessage); ProfileHandler.ProfileInfo(client); ProfileHandler.ProfileDataInfo(client); } }
public static void SignIn(Client client, string jsonPacketData) { client.packetMap.Remove("SignIn"); SignIn signIn = JsonConvert.DeserializeObject<SignIn>(jsonPacketData); if (InternalSignIn(client, signIn.email, signIn.password)) { OkMessage okMessage = new OkMessage(); okMessage.op = "SignIn"; client.Send(okMessage); ProfileHandler.ProfileInfo(client); ProfileHandler.ProfileDataInfo(client); } }
public static void CreatureAttack(Client client, Battle battle) { for (int i = 0; i < 5; i++) { for (int ii = 0; ii < 3; ii++) { Creature creature = battle.board[ii, i]; if (creature != null) { if (creature.canTick && creature.currentAc == 0) { RuleHandler.HandleCreatureStructureAttack(client, ref creature, battle); } } } } }
async void AcceptConnection() { while (listenSocket) { Thread.Sleep(1); if (listener.Pending()) { Client client = new Client() { clientSocket = await listener.AcceptSocketAsync(), clientType = listenerType }; client.OnConnect(); } } }
public static void DeckList(Client client) { client.packetMap.Remove("DeckList"); DeckList deckList = new DeckList(); foreach (KeyValuePair<string, Deck> deckServer in client.account.deckMap) { DeckList.Deck deckClient = new DeckList.Deck(); deckClient.name = deckServer.Value.name; string resources = ""; foreach (string resource in deckServer.Value.resources) { resources += resource + ","; } resources.Remove(resources.Length - 1); deckClient.resources = resources; deckClient.valid = deckServer.Value.valid; deckClient.timestamp = deckServer.Value.timestamp; DateTime dateTimeTimestamp = new DateTime(deckServer.Value.timestamp); DateTime dateTimeNow = DateTime.Now; TimeBlock timeBlock = new TimeBlock(dateTimeTimestamp, dateTimeNow); if (timeBlock.DurationDescription == String.Empty) { deckClient.updated = "A few moments ago"; } else { deckClient.updated = timeBlock.DurationDescription; } deckList.decks.Add(deckClient); } client.Send(deckList); }