diff --git a/src/main/java/com/alterdekim/hearthhack/component/StartupListener.java b/src/main/java/com/alterdekim/hearthhack/component/StartupListener.java index 94f8f04..237718e 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/StartupListener.java +++ b/src/main/java/com/alterdekim/hearthhack/component/StartupListener.java @@ -2,6 +2,7 @@ package com.alterdekim.hearthhack.component; import com.alterdekim.hearthhack.config.DBFConfig; import com.alterdekim.hearthhack.config.ServerConfig; +import com.alterdekim.hearthhack.parser.CardsXmlParser; import com.alterdekim.hearthhack.parser.DBFParser; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +36,7 @@ public class StartupListener { ) ) ); + log.info("CardsXmlMap: {}", CardsXmlParser.parse(serverConfig.getCardsXmlPath())); } catch (Exception e) { log.error(e.getMessage()); } diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/BuySellCard.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/BuySellCard.java new file mode 100644 index 0000000..3d8383a --- /dev/null +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/BuySellCard.java @@ -0,0 +1,19 @@ +package com.alterdekim.hearthhack.component.processor.client.request; + +import com.alterdekim.Protocol; +import com.alterdekim.hearthhack.component.TcpConnection; +import com.alterdekim.hearthhack.util.BattleNetPacket; +import com.alterdekim.hearthhack.util.ClientRequestBody; + +public class BuySellCard extends ClientRequestParser { + @Override + public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception { + Protocol.BuySellCard request = Protocol.BuySellCard.parseFrom(body.getBody()); + + } + + @Override + public int getId() { + return 257; + } +} diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/PurchaseWithGold.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/PurchaseWithGold.java index fbcea2b..820ac0b 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/PurchaseWithGold.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/PurchaseWithGold.java @@ -6,13 +6,50 @@ import com.alterdekim.hearthhack.util.BattleNetPacket; import com.alterdekim.hearthhack.util.ClientRequestBody; import lombok.extern.slf4j.Slf4j; +import java.util.stream.IntStream; + +import static com.alterdekim.Protocol.ProductType.PRODUCT_TYPE_BOOSTER; +import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification; + @Slf4j public class PurchaseWithGold extends ClientRequestParser { + + private final int PACK_COST = 100; + @Override public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception { // PurchaseWithGoldResponse 280 Protocol.PurchaseWithGold request = Protocol.PurchaseWithGold.parseFrom(body.getBody()); - log.info("PurchaseWithGold: {}", request); + Protocol.PurchaseWithGoldResponse response; + if( request.getProduct() != PRODUCT_TYPE_BOOSTER ) { + response = Protocol.PurchaseWithGoldResponse.newBuilder() + .setResult(Protocol.PurchaseWithGoldResponse.PurchaseResult.PR_FEATURE_NA) + .build(); + } else if( conn.getUserService().getGoldForUserId(conn.getUserId()) < (PACK_COST * request.getQuantity()) ) { + response = Protocol.PurchaseWithGoldResponse.newBuilder() + .setResult(Protocol.PurchaseWithGoldResponse.PurchaseResult.PR_INSUFFICIENT_FUNDS) + .build(); + } else { + IntStream.range(0, request.getQuantity()) + .forEach(i -> conn.getUserService().addBooster(conn.getUserId(), request.getData())); + conn.getUserService().setGoldForUserId(conn.getUserId(), conn.getUserService().getGoldForUserId(conn.getUserId()) - (PACK_COST * request.getQuantity())); + response = Protocol.PurchaseWithGoldResponse.newBuilder() + .setResult(Protocol.PurchaseWithGoldResponse.PurchaseResult.PR_SUCCESS) + .build(); + } + + Protocol.Notification n = generateNotification(280, response.toByteString(), response.getSerializedSize()); + + Protocol.Header header = Protocol.Header.newBuilder() + .setServiceId(4) + .setMethodId(1) + .setToken(conn.nextToken()) + .setObjectId(0) + .setSize(n.getSerializedSize()) + .setStatus(0) + .build(); + + conn.send(new BattleNetPacket(header, n.toByteArray())); } @Override diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AccountLicensesInfo.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AccountLicensesInfo.java index 016d193..96aa28a 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AccountLicensesInfo.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AccountLicensesInfo.java @@ -13,9 +13,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.ACCOUNT_LICEN public class AccountLicensesInfo extends GenericParser { - @Override - public void setResources(IService service, DBFConfig config) {} - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { // Protocol.AccountLicensesInfoResponse diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AvailableFeatures.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AvailableFeatures.java index 009358a..c3e3d62 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AvailableFeatures.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/AvailableFeatures.java @@ -20,8 +20,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.FEATURES; @Slf4j public class AvailableFeatures extends GenericParser { - - private DBFConfig config; private Executor executor; private void executeFeatures(TcpConnection conn) throws Exception { @@ -79,11 +77,6 @@ public class AvailableFeatures extends GenericParser { conn.send(new BattleNetPacket(header, n.toByteArray())); } - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { if( this.executor != null ) this.executor.setRunning(false); diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Boosters.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Boosters.java index d64d07f..1ca2c36 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Boosters.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Boosters.java @@ -15,18 +15,9 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.BOOSTERS; public class Boosters extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { - List binfo = userService.getBoostersByUserId(conn.getUserId()).stream().map(b -> Protocol.BoosterInfo.newBuilder() + List binfo = conn.getUserService().getBoostersByUserId(conn.getUserId()).stream().map(b -> Protocol.BoosterInfo.newBuilder() .setCount(b.getCount()) .setType(b.getType()) .build() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardBacks.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardBacks.java index fb29730..bd255fd 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardBacks.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardBacks.java @@ -17,20 +17,11 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.CARD_BACKS; public class CardBacks extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.CardBacks cardBacks = Protocol.CardBacks.newBuilder() - .setDefaultCardBack(userService.getDefaultCardBackForUserId(conn.getUserId())) - .addAllCardBacks(userService.getCardBacksForUserId(conn.getUserId()).stream() + .setDefaultCardBack(conn.getUserService().getDefaultCardBackForUserId(conn.getUserId())) + .addAllCardBacks(conn.getUserService().getCardBacksForUserId(conn.getUserId()).stream() .map(CardBack::getBackId).collect(Collectors.toList())) .build(); diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardValues.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardValues.java index 01fabd0..71767f7 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardValues.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/CardValues.java @@ -22,16 +22,9 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.CARD_VALUES; @Slf4j public class CardValues extends GenericParser { - private DBFConfig config; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { - CardsDBF cards = config.getCards(); + CardsDBF cards = conn.getDbfConfig().getCards(); Protocol.CardValues.Builder cardVals = Protocol.CardValues.newBuilder(); cards.getRecords().forEach(c -> { diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ClientOptions.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ClientOptions.java index 6cfa264..e0df06b 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ClientOptions.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ClientOptions.java @@ -13,13 +13,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.CLIENT_OPTION public class ClientOptions extends GenericParser { - private DBFConfig config; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.ClientOptions clientOptions = Protocol.ClientOptions.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Collection.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Collection.java index 350663e..1c828a0 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Collection.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/Collection.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.COLLECTION; public class Collection extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { // my collection diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DeckList.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DeckList.java index 44e739d..2bd6374 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DeckList.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DeckList.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.DECK_LIST; public class DeckList extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.userService = (UserService) service; - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.DeckList deckList = Protocol.DeckList.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DustBalance.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DustBalance.java index c543938..323dc2b 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DustBalance.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/DustBalance.java @@ -14,19 +14,10 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.ARCANE_DUST_B public class DustBalance extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.userService = (UserService) service; - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.ArcaneDustBalance dustBalance = Protocol.ArcaneDustBalance.newBuilder() - .setBalance(userService.getDustForUserId(conn.getUserId())) + .setBalance(conn.getUserService().getDustForUserId(conn.getUserId())) .build(); Protocol.Notification n = generateNotification(262, dustBalance.toByteString(), dustBalance.getSerializedSize()); diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/FavoriteHeroes.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/FavoriteHeroes.java index 79c93ab..fb31f1f 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/FavoriteHeroes.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/FavoriteHeroes.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.FAVORITE_HERO public class FavoriteHeroes extends GenericParser { - private UserService userService; - private DBFConfig config; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.FavoriteHeroesResponse favoriteHeroesResponse = Protocol.FavoriteHeroesResponse.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GeneralGenericParser.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GeneralGenericParser.java index 063fab7..a838487 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GeneralGenericParser.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GeneralGenericParser.java @@ -20,7 +20,6 @@ public class GeneralGenericParser extends ReflectionLoader { } try { GenericParser parser = this.getParsers().get(req.getValue()); - parser.setResources(conn.getUserService(), conn.getDbfConfig()); parser.parseGenericRequest(token, conn); } catch (Exception e) { log.error(e.getMessage()); diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GenericParser.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GenericParser.java index b261fdd..31a105d 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GenericParser.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GenericParser.java @@ -17,8 +17,6 @@ import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification; @NoArgsConstructor public abstract class GenericParser implements AbstractParser { - public abstract void setResources(IService service, DBFConfig config); - public abstract void parseGenericRequest(int token, TcpConnection conn) throws Exception; @Override diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GoldBalance.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GoldBalance.java index c7d94b7..ae93806 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GoldBalance.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/GoldBalance.java @@ -14,21 +14,12 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.GOLD_BALANCE; public class GoldBalance extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.GoldBalance gb = Protocol.GoldBalance.newBuilder() .setCap(999999) .setBonusBalance(0) - .setCappedBalance(userService.getGoldForUserId(conn.getUserId())) + .setCappedBalance(conn.getUserService().getGoldForUserId(conn.getUserId())) .setCapWarning(2000) .build(); diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/HeroXP.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/HeroXP.java index ff49856..17ace6f 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/HeroXP.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/HeroXP.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.HERO_XP; public class HeroXP extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/MedalInfo.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/MedalInfo.java index 2f4cee4..06d2cc6 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/MedalInfo.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/MedalInfo.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.MEDAL_INFO; public class MedalInfo extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.userService = (UserService) service; - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.MedalInfo medalInfo = Protocol.MedalInfo.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/NotSoMassiveLoginReply.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/NotSoMassiveLoginReply.java index c1d4912..9885741 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/NotSoMassiveLoginReply.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/NotSoMassiveLoginReply.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.NOT_SO_MASSIV public class NotSoMassiveLoginReply extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.userService = (UserService) service; - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.NotSoMassiveLoginReply reply = Protocol.NotSoMassiveLoginReply.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayQueue.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayQueue.java index b7e2229..3ca8332 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayQueue.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayQueue.java @@ -16,15 +16,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.PVP_QUEUE; @Slf4j public class PlayQueue extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.PlayQueue playQueue = Protocol.PlayQueue.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayerRecords.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayerRecords.java index e0e1786..b07d57b 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayerRecords.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/PlayerRecords.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.PLAYER_RECORD public class PlayerRecords extends GenericParser { - private DBFConfig config; - private UserService userService; - - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.PlayerRecords playerRecords = Protocol.PlayerRecords.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileNotices.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileNotices.java index c2cfa29..4b04e42 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileNotices.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileNotices.java @@ -22,8 +22,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.NOTICES; public class ProfileNotices extends GenericParser { private Executor executor; - private UserService userService; - private DBFConfig config; private void sendNotices(TcpConnection conn) throws Exception { Protocol.ProfileNotices notices = Protocol.ProfileNotices.newBuilder() @@ -43,12 +41,6 @@ public class ProfileNotices extends GenericParser { conn.send(new BattleNetPacket(header, n.toByteArray())); } - @Override - public void setResources(IService service, DBFConfig config) { - this.config = config; - this.userService = (UserService) service; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { if( this.executor != null ) this.executor.setRunning(false); diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileProgress.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileProgress.java index e465024..b201596 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileProgress.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/ProfileProgress.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.CAMPAIGN_INFO public class ProfileProgress extends GenericParser { - private UserService userService; - private DBFConfig config; - - @Override - public void setResources(IService service, DBFConfig config) { - this.userService = (UserService) service; - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.ProfileProgress profileProgress = Protocol.ProfileProgress.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/RewardProgress.java b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/RewardProgress.java index 7004dc1..f4506dc 100644 --- a/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/RewardProgress.java +++ b/src/main/java/com/alterdekim/hearthhack/component/processor/client/request/generic/RewardProgress.java @@ -14,15 +14,6 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.REWARD_PROGRE public class RewardProgress extends GenericParser { - private UserService userService; - private DBFConfig config; - - @Override - public void setResources(IService service, DBFConfig config) { - this.userService = (UserService) service; - this.config = config; - } - @Override public void parseGenericRequest(int token, TcpConnection conn) throws Exception { Protocol.RewardProgress rewardProgress = Protocol.RewardProgress.newBuilder() diff --git a/src/main/java/com/alterdekim/hearthhack/config/ServerConfig.java b/src/main/java/com/alterdekim/hearthhack/config/ServerConfig.java index 94c770c..2c5f346 100644 --- a/src/main/java/com/alterdekim/hearthhack/config/ServerConfig.java +++ b/src/main/java/com/alterdekim/hearthhack/config/ServerConfig.java @@ -12,4 +12,5 @@ public class ServerConfig { @Value("${hearthhack.bnet_port}") private Integer bnetPort; @Value("${hearthhack.game_port}") private Integer gamePort; @Value("${hearthhack.host}") private String host; + @Value("${hearthhack.cards_xml_path}") private String cardsXmlPath; } diff --git a/src/main/java/com/alterdekim/hearthhack/entity/Booster.java b/src/main/java/com/alterdekim/hearthhack/entity/Booster.java index c8327e3..b53d3c5 100644 --- a/src/main/java/com/alterdekim/hearthhack/entity/Booster.java +++ b/src/main/java/com/alterdekim/hearthhack/entity/Booster.java @@ -40,4 +40,9 @@ public class Booster { @Column(nullable = false) private Long userId; + + public Booster(Long userId, Integer type) { + this.type = type; + this.userId = userId; + } } diff --git a/src/main/java/com/alterdekim/hearthhack/parser/CardsXmlParser.java b/src/main/java/com/alterdekim/hearthhack/parser/CardsXmlParser.java new file mode 100644 index 0000000..1b4f22c --- /dev/null +++ b/src/main/java/com/alterdekim/hearthhack/parser/CardsXmlParser.java @@ -0,0 +1,47 @@ +package com.alterdekim.hearthhack.parser; + +import com.alterdekim.hearthhack.util.Util; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class CardsXmlParser { + + private static final byte[] cardDef = Util.hexStringToByteArray("3C43617264446566733E"); + + private static final byte[] cardDefEnd = Util.hexStringToByteArray("3C2F43617264446566733E"); + + public static Map parse(String path) throws IOException { + Map m = new HashMap<>(); + byte[] b = Files.readAllBytes(Path.of(path)); + byte[] a; + for( int i = 0; i < b.length; i++ ) { + if( isEq(b, i, cardDef) ) { // -8 + a = Arrays.copyOfRange(b, i-8, i-4); + int f = findFirst(b, i); + m.put(new String(a), new String(Arrays.copyOfRange(b, i, f))); + i += f; + } + } + return m; + } + + private static int findFirst(byte[] b, int s) { + for( int i = s; i < b.length; i++ ) { + if( !isEq(b, i, cardDefEnd) ) continue; + return i+cardDefEnd.length; + } + return 0; + } + + private static boolean isEq(byte[] src, int start, byte[] m) { + for( int i = 0; i < m.length; i++ ) { + if( m[i] != src[start + i] ) return false; + } + return true; + } +} diff --git a/src/main/java/com/alterdekim/hearthhack/repository/UserRepository.java b/src/main/java/com/alterdekim/hearthhack/repository/UserRepository.java index b469c66..751654e 100644 --- a/src/main/java/com/alterdekim/hearthhack/repository/UserRepository.java +++ b/src/main/java/com/alterdekim/hearthhack/repository/UserRepository.java @@ -16,4 +16,10 @@ public interface UserRepository extends JpaRepository { @Modifying @Query(value = "UPDATE User u SET u.defaultCardBack = :cardBackId WHERE u.id = :userId") void updateCardBackOfUser(@Param("userId") Long userId, @Param("cardBackId") Long cardBackId); + + + @Transactional + @Modifying + @Query(value = "UPDATE User u SET u.goldBalance = :goldCount WHERE u.id = :userId") + void updateGoldOfUser(@Param("userId") Long userId, @Param("goldCount") Integer goldCount); } \ No newline at end of file diff --git a/src/main/java/com/alterdekim/hearthhack/service/UserService.java b/src/main/java/com/alterdekim/hearthhack/service/UserService.java index b9cf9aa..fdd05f1 100644 --- a/src/main/java/com/alterdekim/hearthhack/service/UserService.java +++ b/src/main/java/com/alterdekim/hearthhack/service/UserService.java @@ -2,6 +2,7 @@ package com.alterdekim.hearthhack.service; import com.alterdekim.hearthhack.dto.BoosterDTO; import com.alterdekim.hearthhack.dto.UserDTO; +import com.alterdekim.hearthhack.entity.Booster; import com.alterdekim.hearthhack.entity.CardBack; import com.alterdekim.hearthhack.entity.Role; import com.alterdekim.hearthhack.entity.User; @@ -63,11 +64,19 @@ public class UserService implements IService { return cardBackRepository.isUserHasCardBack(userId, cardBack); } + public void addBooster(Long userId, Integer boosterType) { + boosterRepository.save(new Booster(userId, boosterType)); + } + public Integer getGoldForUserId(Long userId) { return userRepository.findById(userId).get().getGoldBalance(); } + public void setGoldForUserId(Long userId, Integer gold) { + userRepository.updateGoldOfUser(userId, gold); + } + public Integer getDustForUserId(Long userId) { return userRepository.findById(userId).get().getDustBalance(); } diff --git a/src/main/proto/bnet/protocol/protocol.proto b/src/main/proto/bnet/protocol/protocol.proto index 2a6d538..f19a5b2 100644 --- a/src/main/proto/bnet/protocol/protocol.proto +++ b/src/main/proto/bnet/protocol/protocol.proto @@ -3342,4 +3342,19 @@ message PurchaseWithGoldResponse { required PurchaseResult result = 1; optional int64 gold_used = 2; +} + +// ref: PegasusUtil.BuySellCard +message BuySellCard { + // ref: PegasusUtil.BuySellCard/PacketID + enum PacketID { + system = 0; + ID = 257; + } + + required CardDef def = 1; + optional int32 count = 2; + required bool buying = 3; + optional int32 unit_sell_price = 4; + optional int32 unit_buy_price = 5; } \ No newline at end of file