deck/gold stuff
This commit is contained in:
parent
4ca446621c
commit
07d7480ff0
@ -8,6 +8,7 @@ import com.alterdekim.hearthhack.util.BattleNetPacket;
|
||||
import com.alterdekim.hearthhack.util.Util;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
@ -36,6 +37,10 @@ public class TcpConnection extends Thread {
|
||||
@Getter
|
||||
private final UserService userService;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Long userId;
|
||||
|
||||
public void stopListeningAndDisconnect() {
|
||||
log.warn("Tried to stopListening");
|
||||
try {
|
||||
|
@ -72,10 +72,9 @@ public class AuthProcessor extends Processor {
|
||||
= Protocol.VerifyWebCredentialsRequest.parseFrom(packet.getBody());
|
||||
|
||||
String token = new String( verifyWebCredentialsRequest.getWebCredentials().toByteArray() );
|
||||
log.info(token);
|
||||
|
||||
if( !conn.getUserService().authMe(token) ) conn.stopListeningAndDisconnect();
|
||||
|
||||
if( !conn.getUserService().authMe(token) ) { conn.stopListeningAndDisconnect(); return; }
|
||||
conn.setUserId(conn.getUserService().extractId(token));
|
||||
Protocol.Header h = Processor.generateResponse(0, packet.getHeader().getToken(), 0, 0);
|
||||
|
||||
conn.send(new BattleNetPacket(h, new byte[0]));
|
||||
@ -113,7 +112,7 @@ public class AuthProcessor extends Processor {
|
||||
.addAvailableRegion(6)
|
||||
.addAvailableRegion(98)
|
||||
.setConnectedRegion(2)
|
||||
.setBattleTag("Asmodeus#66666")
|
||||
.setBattleTag(conn.getUserService().findById(conn.getUserId()).getDisplayName()+"#66666")
|
||||
.setGeoipCountry("SK")
|
||||
.build();
|
||||
|
||||
|
@ -28,7 +28,8 @@ public class PresenceProcessor extends Processor {
|
||||
conn.send(new BattleNetPacket(header, new byte[0]));
|
||||
|
||||
if( subscribeRequest.getObjectId() == 1 ) {
|
||||
byte[] nickname = "Asmodeus#66666".getBytes(StandardCharsets.US_ASCII);
|
||||
String ni = conn.getUserService().findById(conn.getUserId()).getDisplayName()+"#66666";
|
||||
byte[] nickname = ni.getBytes(StandardCharsets.US_ASCII);
|
||||
// byte[] bb = Util.hexStringToByteArray("1A"+Util.intToHex(98+nickname.length)+"AA06"+Util.intToHex(95+nickname.length)+"0A120900000000000000011193710E1A0000000012190A170A0A08CE84011001180620001209189AB1D8B499BCCC02121A0A180A0A08CE8401100118012000120A2A086A6F686E20626F6E12210A1F0A0A08CE840110011804200012102A"+Util.intToHex(nickname.length)+Util.bytesToHex(nickname));
|
||||
byte[] bb = Util.hexStringToByteArray("1A71AA066E0A120900000000000000011193710E1A0000000012190A170A0A08CE84011001180620001209189AB1D8B499BCCC02121A0A180A0A08CE8401100118012000120A2A086A6F686E20626F6E12210A1F0A0A08CE840110011804200012"+Util.intToHex(nickname.length+2)+"2A"+Util.intToHex(nickname.length)+Util.bytesToHex(nickname));
|
||||
bb[1] = (byte) (98 + nickname.length);
|
||||
@ -52,7 +53,8 @@ public class PresenceProcessor extends Processor {
|
||||
|
||||
|
||||
} else if( subscribeRequest.getObjectId() == 2 ) {
|
||||
byte[] nickname = "Asmodeus#66666".getBytes(StandardCharsets.US_ASCII);
|
||||
String ni = conn.getUserService().findById(conn.getUserId()).getDisplayName()+"#66666";
|
||||
byte[] nickname = ni.getBytes(StandardCharsets.US_ASCII);
|
||||
byte[] bb = Util.hexStringToByteArray("1ADB01AA06D7010A12094743545702000002116739AB040000000012210A1F0A0A08CE840110021805200012"+Util.intToHex(nickname.length+2)+"2A"+Util.intToHex(nickname.length)+Util.bytesToHex(nickname)+"12240A220A0A08CE8401100218072000121452120900000000000000011193710E1A0000000012190A170A0A08CE84011002180420001209189AB1D8B499BCCC0212120A100A0A08CE84011002180C20001202100012120A100A0A08CE84011002180120001202100012160A140A0A08CE84011002180320001206420457544347121D0A1B0A0A08CE8401100218062000120D2A0B3433373135343139352331");
|
||||
bb[1] = (byte) (204 + nickname.length);
|
||||
bb[5] = (byte) (200 + nickname.length);
|
||||
@ -122,7 +124,7 @@ public class PresenceProcessor extends Processor {
|
||||
|
||||
conn.send(new BattleNetPacket(header1, b));
|
||||
|
||||
b = Util.hexStringToByteArray("0A120900000000000000021100000000000000001212094743545702000002116739AB04000000001A1C575443472E5574696C4E6F74696669636174696F6E4D65737361676522130A0C6D6573736167655F74797065120318CA0222140A0C667261676D656E745F30303012043202080122120A0C6D6573736167655F73697A65120218022A1209000000000000000111000000000000000032120900000000000000011193710E1A000000003A004A0A0889FF5C1092E5A1B90552150A050D93710E1A120C0D6739AB0415474354571802");
|
||||
/* b = Util.hexStringToByteArray("0A120900000000000000021100000000000000001212094743545702000002116739AB04000000001A1C575443472E5574696C4E6F74696669636174696F6E4D65737361676522130A0C6D6573736167655F74797065120318CA0222140A0C667261676D656E745F30303012043202080122120A0C6D6573736167655F73697A65120218022A1209000000000000000111000000000000000032120900000000000000011193710E1A000000003A004A0A0889FF5C1092E5A1B90552150A050D93710E1A120C0D6739AB0415474354571802");
|
||||
|
||||
header = Protocol.Header.newBuilder()
|
||||
.setServiceId(4)
|
||||
@ -133,7 +135,7 @@ public class PresenceProcessor extends Processor {
|
||||
.setStatus(0)
|
||||
.build();
|
||||
|
||||
conn.send(new BattleNetPacket(header, b));
|
||||
conn.send(new BattleNetPacket(header, b));*/
|
||||
|
||||
} else if( packet.getHeader().getToken() == 26 ) {
|
||||
/* Protocol.Header header1 = Processor.generateResponse(0, packet.getHeader().getToken(), 0, 0);
|
||||
@ -179,7 +181,7 @@ public class PresenceProcessor extends Processor {
|
||||
Protocol.Header header1 = Processor.generateResponse(b.length, packet.getHeader().getToken(), 0, 0);
|
||||
// conn.send(new BattleNetPacket(header1, b));
|
||||
|
||||
b = Util.hexStringToByteArray("0A120900000000000000021100000000000000001212094743545702000002116739AB04000000001A1C575443472E5574696C4E6F74696669636174696F6E4D65737361676522130A0C6D6573736167655F74797065120318E00122120A0C6D6573736167655F73697A65120218002A1209000000000000000111000000000000000032120900000000000000011193710E1A000000003A004A0A0889FF5C1092E5A1B90552150A050D93710E1A120C0D6739AB0415474354571802");
|
||||
/* b = Util.hexStringToByteArray("0A120900000000000000021100000000000000001212094743545702000002116739AB04000000001A1C575443472E5574696C4E6F74696669636174696F6E4D65737361676522130A0C6D6573736167655F74797065120318E00122120A0C6D6573736167655F73697A65120218002A1209000000000000000111000000000000000032120900000000000000011193710E1A000000003A004A0A0889FF5C1092E5A1B90552150A050D93710E1A120C0D6739AB0415474354571802");
|
||||
|
||||
header = Protocol.Header.newBuilder()
|
||||
.setServiceId(4)
|
||||
@ -189,7 +191,7 @@ public class PresenceProcessor extends Processor {
|
||||
.setSize(b.length)
|
||||
.setStatus(0)
|
||||
.build();
|
||||
conn.send(new BattleNetPacket(header, b));
|
||||
conn.send(new BattleNetPacket(header, b));*/
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.alterdekim.hearthhack.component.processor.client.request;
|
||||
|
||||
import com.alterdekim.hearthhack.component.TcpConnection;
|
||||
import com.alterdekim.hearthhack.util.BattleNetPacket;
|
||||
import com.alterdekim.hearthhack.util.ClientRequestBody;
|
||||
|
||||
public class DeckUpdate extends ClientRequestParser {
|
||||
@Override
|
||||
public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
|
||||
// 222 DeckSetData
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 222;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
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;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
|
||||
|
||||
@Slf4j
|
||||
public class OpenBooster extends ClientRequestParser {
|
||||
@Override
|
||||
public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
|
||||
// 226 BoosterContent
|
||||
log.info("BoosterContent: got");
|
||||
Protocol.Date d = Protocol.Date.newBuilder()
|
||||
.setYear(2023)
|
||||
.setMonth(1)
|
||||
.setDay(3)
|
||||
.setHours(0)
|
||||
.setMin(0)
|
||||
.setSec(0)
|
||||
.build();
|
||||
|
||||
Protocol.BoosterContent response = Protocol.BoosterContent.newBuilder()
|
||||
.addList(Protocol.BoosterCard.newBuilder()
|
||||
.setCardDef(Protocol.CardDef.newBuilder()
|
||||
.setAsset(459)
|
||||
.setPremium(1))
|
||||
.setInsertDate(d))
|
||||
.addList(Protocol.BoosterCard.newBuilder()
|
||||
.setCardDef(Protocol.CardDef.newBuilder()
|
||||
.setAsset(457)
|
||||
.setPremium(1))
|
||||
.setInsertDate(d))
|
||||
.addList(Protocol.BoosterCard.newBuilder()
|
||||
.setCardDef(Protocol.CardDef.newBuilder()
|
||||
.setAsset(777)
|
||||
.setPremium(1))
|
||||
.setInsertDate(d))
|
||||
.addList(Protocol.BoosterCard.newBuilder()
|
||||
.setCardDef(Protocol.CardDef.newBuilder()
|
||||
.setAsset(459)
|
||||
.setPremium(1))
|
||||
.setInsertDate(d))
|
||||
.addList(Protocol.BoosterCard.newBuilder()
|
||||
.setCardDef(Protocol.CardDef.newBuilder()
|
||||
.setAsset(459)
|
||||
.setPremium(0))
|
||||
.setInsertDate(d))
|
||||
.build();
|
||||
|
||||
Protocol.Notification n = generateNotification(226, response.toByteString(), response.getSerializedSize());
|
||||
|
||||
Protocol.Header header = Protocol.Header.newBuilder()
|
||||
.setServiceId(4)
|
||||
.setMethodId(1)
|
||||
.setToken(conn.nextToken())
|
||||
.setStatus(0)
|
||||
.setObjectId(0)
|
||||
.setSize(n.getSerializedSize())
|
||||
.build();
|
||||
|
||||
conn.send(new BattleNetPacket(header, n.toByteArray()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 225;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
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;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class PurchaseWithGold extends ClientRequestParser {
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 279;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
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;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
|
||||
|
||||
@Slf4j
|
||||
public class SetCardBack extends ClientRequestParser {
|
||||
@Override
|
||||
public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
|
||||
Protocol.SetCardBack request = Protocol.SetCardBack.parseFrom(body.getBody());
|
||||
Integer cardBack = request.getCardBack();
|
||||
boolean success = false;
|
||||
if( !request.hasDeckId() && conn.getUserService().isUserHasCardBack(conn.getUserId(), cardBack) ) {
|
||||
conn.getUserService().setDefaultUserCardBack(conn.getUserId(), cardBack);
|
||||
success = true;
|
||||
}
|
||||
|
||||
Protocol.SetCardBackResponse response = Protocol.SetCardBackResponse.newBuilder()
|
||||
.setSuccess(success)
|
||||
.setCardBack(cardBack)
|
||||
.build();
|
||||
|
||||
Protocol.Notification n = generateNotification(292, 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
|
||||
public int getId() {
|
||||
return 291;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SetCardSeen extends ClientRequestParser {
|
||||
@Override
|
||||
public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
|
||||
Protocol.AckCardSeen request = Protocol.AckCardSeen.parseFrom(body.getBody());
|
||||
List<Protocol.CardDef> l = request.getCardDefsList();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return 223;
|
||||
}
|
||||
}
|
@ -6,11 +6,15 @@ import com.alterdekim.hearthhack.config.DBFConfig;
|
||||
import com.alterdekim.hearthhack.config.ServerConfig;
|
||||
import com.alterdekim.hearthhack.service.IService;
|
||||
import com.alterdekim.hearthhack.util.BattleNetPacket;
|
||||
import com.alterdekim.hearthhack.util.Util;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
|
||||
import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.FEATURES;
|
||||
|
||||
@ -38,6 +42,41 @@ public class AvailableFeatures extends GenericParser {
|
||||
.build();
|
||||
|
||||
conn.send(new BattleNetPacket(header, n.toByteArray()));
|
||||
|
||||
/* byte[] b = Util.hexStringToByteArray("0A120900000000000000021100000000000000001212094743545702000002116739AB04000000001A1C575443472E5574696C4E6F74696669636174696F6E4D65737361676522130A0C6D6573736167655F74797065120318E00122120A0C6D6573736167655F73697A65120218002A1209000000000000000111000000000000000032120900000000000000011193710E1A000000003A004A0A0889FF5C1092E5A1B90552150A050D93710E1A120C0D6739AB0415474354571802");
|
||||
|
||||
header = Protocol.Header.newBuilder()
|
||||
.setServiceId(4)
|
||||
.setMethodId(1)
|
||||
.setToken(conn.nextToken())
|
||||
.setObjectId(0)
|
||||
.setSize(b.length)
|
||||
.setStatus(0)
|
||||
.build();
|
||||
conn.send(new BattleNetPacket(header, b));*/
|
||||
|
||||
List<Protocol.BoosterInfo> binfo = conn.getUserService().getBoostersByUserId(conn.getUserId()).stream().map(b -> Protocol.BoosterInfo.newBuilder()
|
||||
.setCount(b.getCount())
|
||||
.setType(b.getType())
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
|
||||
Protocol.BoosterList boosterList = Protocol.BoosterList.newBuilder()
|
||||
.addAllList(binfo)
|
||||
.build();
|
||||
|
||||
n = generateNotification(224, boosterList.toByteString(), boosterList.getSerializedSize());
|
||||
|
||||
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
|
||||
|
@ -3,13 +3,13 @@ package com.alterdekim.hearthhack.component.processor.client.request.generic;
|
||||
import com.alterdekim.Protocol;
|
||||
import com.alterdekim.hearthhack.component.TcpConnection;
|
||||
import com.alterdekim.hearthhack.config.DBFConfig;
|
||||
import com.alterdekim.hearthhack.config.ServerConfig;
|
||||
import com.alterdekim.hearthhack.service.IService;
|
||||
import com.alterdekim.hearthhack.service.UserService;
|
||||
import com.alterdekim.hearthhack.util.BattleNetPacket;
|
||||
import com.alterdekim.hearthhack.util.GetAccountInfoRequest;
|
||||
|
||||
import static com.alterdekim.hearthhack.util.GameUtilities.generateEmptyNotification;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
|
||||
import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.BOOSTERS;
|
||||
|
||||
@ -26,7 +26,14 @@ public class Boosters extends GenericParser {
|
||||
|
||||
@Override
|
||||
public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
|
||||
List<Protocol.BoosterInfo> binfo = userService.getBoostersByUserId(conn.getUserId()).stream().map(b -> Protocol.BoosterInfo.newBuilder()
|
||||
.setCount(b.getCount())
|
||||
.setType(b.getType())
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
|
||||
Protocol.BoosterList boosterList = Protocol.BoosterList.newBuilder()
|
||||
.addAllList(binfo)
|
||||
.build();
|
||||
|
||||
Protocol.Notification n = generateNotification(224, boosterList.toByteString(), boosterList.getSerializedSize());
|
||||
|
@ -4,26 +4,34 @@ import com.alterdekim.Protocol;
|
||||
import com.alterdekim.hearthhack.component.TcpConnection;
|
||||
import com.alterdekim.hearthhack.config.DBFConfig;
|
||||
import com.alterdekim.hearthhack.config.ServerConfig;
|
||||
import com.alterdekim.hearthhack.entity.CardBack;
|
||||
import com.alterdekim.hearthhack.service.IService;
|
||||
import com.alterdekim.hearthhack.service.UserService;
|
||||
import com.alterdekim.hearthhack.util.BattleNetPacket;
|
||||
import com.alterdekim.hearthhack.util.GetAccountInfoRequest;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
|
||||
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(0)
|
||||
.setDefaultCardBack(userService.getDefaultCardBackForUserId(conn.getUserId()))
|
||||
.addAllCardBacks(userService.getCardBacksForUserId(conn.getUserId()).stream()
|
||||
.map(CardBack::getBackId).collect(Collectors.toList()))
|
||||
.build();
|
||||
|
||||
Protocol.Notification n = generateNotification(236, cardBacks.toByteString(), cardBacks.getSerializedSize());
|
||||
|
@ -26,7 +26,7 @@ public class DustBalance extends GenericParser {
|
||||
@Override
|
||||
public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
|
||||
Protocol.ArcaneDustBalance dustBalance = Protocol.ArcaneDustBalance.newBuilder()
|
||||
.setBalance(665)
|
||||
.setBalance(userService.getDustForUserId(conn.getUserId()))
|
||||
.build();
|
||||
|
||||
Protocol.Notification n = generateNotification(262, dustBalance.toByteString(), dustBalance.getSerializedSize());
|
||||
|
@ -27,8 +27,8 @@ public class GoldBalance extends GenericParser {
|
||||
public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
|
||||
Protocol.GoldBalance gb = Protocol.GoldBalance.newBuilder()
|
||||
.setCap(999999)
|
||||
.setBonusBalance(165)
|
||||
.setCappedBalance(160)
|
||||
.setBonusBalance(0)
|
||||
.setCappedBalance(userService.getGoldForUserId(conn.getUserId()))
|
||||
.setCapWarning(2000)
|
||||
.build();
|
||||
|
||||
|
15
src/main/java/com/alterdekim/hearthhack/dto/BoosterDTO.java
Normal file
15
src/main/java/com/alterdekim/hearthhack/dto/BoosterDTO.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.alterdekim.hearthhack.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class BoosterDTO {
|
||||
private Integer type;
|
||||
private Integer count;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.alterdekim.hearthhack.entity;
|
||||
|
||||
import com.alterdekim.hearthhack.dto.BoosterDTO;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@ -12,6 +13,23 @@ import lombok.Setter;
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "boosters")
|
||||
@SqlResultSetMapping(
|
||||
name = "boosterEntityMapping",
|
||||
classes = {
|
||||
@ConstructorResult(
|
||||
targetClass = BoosterDTO.class,
|
||||
columns = {
|
||||
@ColumnResult(name = "type", type = Integer.class),
|
||||
@ColumnResult(name = "count", type = Integer.class)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
@NamedNativeQuery(
|
||||
name = "Booster.findBoostersByUserId",
|
||||
query = "SELECT b.type as type, COUNT(b.id) as count FROM boosters b WHERE b.user_id = :userId GROUP BY b.type",
|
||||
resultSetMapping = "boosterEntityMapping"
|
||||
)
|
||||
public class Booster {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
@ -44,5 +44,5 @@ public class User {
|
||||
private Integer goldBalance = 0;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer defaultCardBack = 0;
|
||||
private Long defaultCardBack = 0L;
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
package com.alterdekim.hearthhack.repository;
|
||||
|
||||
import com.alterdekim.hearthhack.dto.BoosterDTO;
|
||||
import com.alterdekim.hearthhack.entity.Booster;
|
||||
import com.alterdekim.hearthhack.entity.HeroXP;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface BoosterRepository extends JpaRepository<Booster, Long> {
|
||||
@Query(nativeQuery = true)
|
||||
List<BoosterDTO> findBoostersByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
|
@ -2,9 +2,23 @@ package com.alterdekim.hearthhack.repository;
|
||||
|
||||
import com.alterdekim.hearthhack.entity.CardBack;
|
||||
import com.alterdekim.hearthhack.entity.HeroXP;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface CardBackRepository extends JpaRepository<CardBack, Long> {
|
||||
List<CardBack> findByUserId(Long userId);
|
||||
|
||||
@Query(value = "SELECT TRUE FROM CardBack c WHERE c.userId = :userId AND c.backId = :cardBack")
|
||||
Boolean isUserHasCardBack(@Param("userId") Long userId, @Param("cardBack") Integer cardBack);
|
||||
|
||||
@Query(value = "SELECT c FROM CardBack c WHERE c.userId = :userId AND c.backId = :cardBack")
|
||||
Optional<CardBack> findByUserIdAndBackId(@Param("userId") Long userId, @Param("cardBack") Integer cardBack);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.alterdekim.hearthhack.service;
|
||||
|
||||
import com.alterdekim.hearthhack.dto.BoosterDTO;
|
||||
import com.alterdekim.hearthhack.dto.UserDTO;
|
||||
import com.alterdekim.hearthhack.entity.CardBack;
|
||||
import com.alterdekim.hearthhack.entity.Role;
|
||||
@ -49,6 +50,37 @@ public class UserService implements IService {
|
||||
return userRepository.findByUsername(username);
|
||||
}
|
||||
|
||||
public List<CardBack> getCardBacksForUserId(Long userId) {
|
||||
return cardBackRepository.findByUserId(userId);
|
||||
}
|
||||
|
||||
public void setDefaultUserCardBack(Long userId, Integer cardBack) {
|
||||
CardBack cb = cardBackRepository.findByUserIdAndBackId(userId, cardBack).get();
|
||||
userRepository.updateCardBackOfUser(userId, cb.getId());
|
||||
}
|
||||
|
||||
public boolean isUserHasCardBack(Long userId, Integer cardBack) {
|
||||
return cardBackRepository.isUserHasCardBack(userId, cardBack);
|
||||
}
|
||||
|
||||
|
||||
public Integer getGoldForUserId(Long userId) {
|
||||
return userRepository.findById(userId).get().getGoldBalance();
|
||||
}
|
||||
|
||||
public Integer getDustForUserId(Long userId) {
|
||||
return userRepository.findById(userId).get().getDustBalance();
|
||||
}
|
||||
|
||||
public Integer getDefaultCardBackForUserId(Long userId) {
|
||||
return cardBackRepository.findById(
|
||||
userRepository.findById(userId).get().getDefaultCardBack()
|
||||
).get().getBackId();
|
||||
}
|
||||
|
||||
public List<BoosterDTO> getBoostersByUserId(Long userId) {
|
||||
return boosterRepository.findBoostersByUserId(userId);
|
||||
}
|
||||
|
||||
public List<UserDTO> findAllUsers() {
|
||||
List<User> users = userRepository.findAll();
|
||||
@ -72,6 +104,12 @@ public class UserService implements IService {
|
||||
return passwordEncoder.matches(raw, hash);
|
||||
}
|
||||
|
||||
public Long extractId(String token) {
|
||||
String[] arr = token.split("\\-");
|
||||
if(arr.length != 3) return 0L;
|
||||
return Long.parseLong(arr[2]);
|
||||
}
|
||||
|
||||
public String genHash(Long id) throws Exception {
|
||||
Optional<User> user = this.userRepository.findById(id);
|
||||
if( user.isEmpty() ) throw new Exception();
|
||||
|
@ -3248,4 +3248,98 @@ message DeckContents {
|
||||
required bool success = 1;
|
||||
required int64 deck_id = 2;
|
||||
repeated DeckCardData cards = 3;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.SetCardBack
|
||||
message SetCardBack {
|
||||
// ref: PegasusUtil.SetCardBack/PacketID
|
||||
enum PacketID {
|
||||
system = 0;
|
||||
ID = 291;
|
||||
}
|
||||
|
||||
required int32 card_back = 1;
|
||||
optional int64 deck_id = 2;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.SetCardBackResponse
|
||||
message SetCardBackResponse {
|
||||
// ref: PegasusUtil.SetCardBackResponse/PacketID
|
||||
enum PacketID {
|
||||
ID = 292;
|
||||
}
|
||||
|
||||
required bool success = 1;
|
||||
required int32 card_back = 2;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.OpenBooster
|
||||
message OpenBooster {
|
||||
// ref: PegasusUtil.OpenBooster/PacketID
|
||||
enum PacketID {
|
||||
system = 0;
|
||||
ID = 225;
|
||||
}
|
||||
|
||||
required int32 booster_type = 2;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.BoosterCard
|
||||
message BoosterCard {
|
||||
required CardDef card_def = 1;
|
||||
required Date insert_date = 2;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.BoosterContent
|
||||
message BoosterContent {
|
||||
// ref: PegasusUtil.BoosterContent/PacketID
|
||||
enum PacketID {
|
||||
ID = 226;
|
||||
}
|
||||
|
||||
repeated BoosterCard list = 1;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.AckCardSeen
|
||||
message AckCardSeen {
|
||||
// ref: PegasusUtil.AckCardSeen/PacketID
|
||||
enum PacketID {
|
||||
system = 0;
|
||||
ID = 223;
|
||||
}
|
||||
|
||||
repeated CardDef card_defs = 1;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.PurchaseWithGold
|
||||
message PurchaseWithGold {
|
||||
// ref: PegasusUtil.PurchaseWithGold/PacketID
|
||||
enum PacketID {
|
||||
system = 0;
|
||||
ID = 279;
|
||||
}
|
||||
|
||||
required int32 quantity = 1;
|
||||
required ProductType product = 2;
|
||||
optional int32 data = 3;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.PurchaseWithGoldResponse
|
||||
message PurchaseWithGoldResponse {
|
||||
// ref: PegasusUtil.PurchaseWithGoldResponse/PacketID
|
||||
enum PacketID {
|
||||
ID = 280;
|
||||
}
|
||||
|
||||
// ref: PegasusUtil.PurchaseWithGoldResponse/PurchaseResult
|
||||
enum PurchaseResult {
|
||||
PR_SUCCESS = 1;
|
||||
PR_INSUFFICIENT_FUNDS = 2;
|
||||
PR_PRODUCT_NA = 3;
|
||||
PR_FEATURE_NA = 4;
|
||||
PR_INVALID_QUANTITY = 5;
|
||||
}
|
||||
|
||||
required PurchaseResult result = 1;
|
||||
optional int64 gold_used = 2;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user