db x2
This commit is contained in:
parent
9006c0c3cd
commit
cd63319aef
5
pom.xml
5
pom.xml
@ -90,6 +90,11 @@
|
||||
<artifactId>luaj-jse</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.11.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -72,6 +72,8 @@ public class AuthProcessor extends Processor {
|
||||
= Protocol.VerifyWebCredentialsRequest.parseFrom(packet.getBody());
|
||||
log.info( new String( verifyWebCredentialsRequest.getWebCredentials().toByteArray() ) );
|
||||
|
||||
String token = new String( verifyWebCredentialsRequest.getWebCredentials().toByteArray() );
|
||||
|
||||
Protocol.Header h = Processor.generateResponse(0, packet.getHeader().getToken(), 0, 0);
|
||||
|
||||
conn.send(new BattleNetPacket(h, new byte[0]));
|
||||
|
@ -4,6 +4,7 @@ import com.alterdekim.Protocol;
|
||||
import com.alterdekim.hearthhack.component.TcpConnection;
|
||||
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;
|
||||
|
||||
@ -14,10 +15,12 @@ import static com.alterdekim.hearthhack.util.GetAccountInfoRequest.BOOSTERS;
|
||||
public class Boosters extends GenericParser {
|
||||
|
||||
private ServerConfig config;
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public void setResources(IService service, ServerConfig config) {
|
||||
this.config = config;
|
||||
this.userService = (UserService) service;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,6 @@ public class CardValues extends GenericParser {
|
||||
public void parseGenericRequest(int token, TcpConnection conn) throws Exception {
|
||||
|
||||
CardsDBF cards = DBFParser.parseCards(config.getDbfPath());
|
||||
log.info("CardsDBF: {}", cards);
|
||||
Protocol.CardValues.Builder cardVals = Protocol.CardValues.newBuilder();
|
||||
|
||||
cards.getRecords().forEach(c -> {
|
||||
@ -56,6 +55,24 @@ public class CardValues extends GenericParser {
|
||||
.setBuy(400)
|
||||
.setSell(100)
|
||||
.setNerfed(false));
|
||||
cardVals.addCards(Protocol.CardValue.newBuilder()
|
||||
.setCard(
|
||||
Protocol.CardDef.newBuilder()
|
||||
.setAsset(
|
||||
Integer.parseInt(
|
||||
fields.stream()
|
||||
.filter(p -> p.getColumn().equals("ID"))
|
||||
.findFirst()
|
||||
.get()
|
||||
.getVal()
|
||||
)
|
||||
)
|
||||
.setPremium(0)
|
||||
.build()
|
||||
)
|
||||
.setBuy(400)
|
||||
.setSell(100)
|
||||
.setNerfed(false));
|
||||
});
|
||||
|
||||
Protocol.CardValues vals = cardVals.setCardNerfIndex(5).build();
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.alterdekim.hearthhack.dbf;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -10,8 +13,17 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CardsDBF {
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
private String name;
|
||||
|
||||
@JsonProperty("SourceFingerprint")
|
||||
private String sourceFingerprint;
|
||||
|
||||
@JsonProperty("Column")
|
||||
@JacksonXmlElementWrapper(useWrapping = false)
|
||||
private List<DBFColumn> columns;
|
||||
|
||||
@JsonProperty("Record")
|
||||
@JacksonXmlElementWrapper(useWrapping = false)
|
||||
private List<DBFCard> records;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.alterdekim.hearthhack.dbf;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -9,6 +11,9 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
|
||||
public class DBFCard {
|
||||
@JsonProperty("Field")
|
||||
@JacksonXmlElementWrapper(useWrapping = false)
|
||||
private List<DBFField> fields;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.alterdekim.hearthhack.dbf;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@ -7,7 +9,10 @@ import lombok.*;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
|
||||
public class DBFColumn {
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
private String name;
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
private String type;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.alterdekim.hearthhack.dbf;
|
||||
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@ -8,6 +10,8 @@ import lombok.*;
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class DBFField {
|
||||
@JacksonXmlProperty(isAttribute = true)
|
||||
private String column;
|
||||
@JacksonXmlText
|
||||
private String val;
|
||||
}
|
||||
|
25
src/main/java/com/alterdekim/hearthhack/entity/Booster.java
Normal file
25
src/main/java/com/alterdekim/hearthhack/entity/Booster.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.alterdekim.hearthhack.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "boosters")
|
||||
public class Booster {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer type;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Long userId;
|
||||
}
|
@ -19,4 +19,7 @@ public class CardBack {
|
||||
|
||||
@Column(nullable=false)
|
||||
private Integer backId;
|
||||
|
||||
@Column(nullable=false)
|
||||
private Long userId;
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.alterdekim.hearthhack.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "card_stack")
|
||||
public class CardStack {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable=false)
|
||||
private Integer asset;
|
||||
|
||||
@Column(nullable=false)
|
||||
private Integer premium;
|
||||
}
|
37
src/main/java/com/alterdekim/hearthhack/entity/HeroXP.java
Normal file
37
src/main/java/com/alterdekim/hearthhack/entity/HeroXP.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.alterdekim.hearthhack.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "hero_xp")
|
||||
public class HeroXP {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer classId;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer level;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer currXp;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer maxXp;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Long nextRewardId;
|
||||
}
|
@ -38,10 +38,10 @@ public class User {
|
||||
private List<Role> roles = new ArrayList<>();
|
||||
|
||||
@Column(nullable = false)
|
||||
private Long dustBalance;
|
||||
private Integer dustBalance = 0;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Long goldBalance;
|
||||
private Integer goldBalance = 0;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer defaultCardBack = 0;
|
||||
|
@ -22,8 +22,5 @@ public class UserCard {
|
||||
private Long userId;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer asset;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Integer premium;
|
||||
private Long cardStackId;
|
||||
}
|
||||
|
@ -1,101 +1,20 @@
|
||||
package com.alterdekim.hearthhack.parser;
|
||||
|
||||
import com.alterdekim.hearthhack.dbf.CardsDBF;
|
||||
import com.alterdekim.hearthhack.dbf.DBFCard;
|
||||
import com.alterdekim.hearthhack.dbf.DBFColumn;
|
||||
import com.alterdekim.hearthhack.dbf.DBFField;
|
||||
import lombok.Getter;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
|
||||
@Slf4j
|
||||
public class DBFParser extends DefaultHandler {
|
||||
public static CardsDBF parseCards(String path) {
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
try (InputStream is = new FileInputStream(path + "/CARD.xml")) {
|
||||
SAXParser saxParser = factory.newSAXParser();
|
||||
DBFParser handler = new DBFParser();
|
||||
saxParser.parse(is, handler);
|
||||
return handler.getResult();
|
||||
} catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
try {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
return xmlMapper.readValue(new File(path + "/CARD.xml"), CardsDBF.class);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return new CardsDBF();
|
||||
}
|
||||
|
||||
private final StringBuilder currentValue = new StringBuilder();
|
||||
|
||||
@Getter
|
||||
private CardsDBF result;
|
||||
|
||||
@Override
|
||||
public void startDocument() {
|
||||
result = new CardsDBF();
|
||||
result.setColumns(new ArrayList<>());
|
||||
result.setRecords(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(
|
||||
String uri,
|
||||
String localName,
|
||||
String qName,
|
||||
Attributes attributes) {
|
||||
|
||||
currentValue.setLength(0);
|
||||
|
||||
switch (qName) {
|
||||
case "SourceFingerprint":
|
||||
result.setSourceFingerprint(attributes.getValue(qName));
|
||||
break;
|
||||
case "Column":
|
||||
DBFColumn column = new DBFColumn();
|
||||
column.setName(attributes.getValue("name"));
|
||||
column.setType(attributes.getValue("type"));
|
||||
result.getColumns().add(column);
|
||||
break;
|
||||
case "Record":
|
||||
result.getRecords().add(new DBFCard(new ArrayList<>()));
|
||||
break;
|
||||
case "Field":
|
||||
DBFField field = new DBFField();
|
||||
field.setColumn(attributes.getValue("column"));
|
||||
result.getRecords()
|
||||
.get(result.getRecords().size()-1)
|
||||
.getFields()
|
||||
.add(field);
|
||||
break;
|
||||
case "Dbf":
|
||||
result.setName(attributes.getValue("name"));
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri,
|
||||
String localName,
|
||||
String qName) {
|
||||
if( qName.equals("Field") ) {
|
||||
List<DBFField> fields = result.getRecords()
|
||||
.get(result.getRecords().size()-1)
|
||||
.getFields();
|
||||
fields.get(fields.size()-1).setVal(currentValue.toString());
|
||||
result.getRecords()
|
||||
.get(result.getRecords().size()-1)
|
||||
.setFields(fields);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
currentValue.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.alterdekim.hearthhack.repository;
|
||||
|
||||
import com.alterdekim.hearthhack.entity.Booster;
|
||||
import com.alterdekim.hearthhack.entity.HeroXP;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface BoosterRepository extends JpaRepository<Booster, Long> {
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.alterdekim.hearthhack.repository;
|
||||
|
||||
import com.alterdekim.hearthhack.entity.CardBack;
|
||||
import com.alterdekim.hearthhack.entity.HeroXP;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CardBackRepository extends JpaRepository<CardBack, Long> {
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.alterdekim.hearthhack.repository;
|
||||
|
||||
import com.alterdekim.hearthhack.entity.Deck;
|
||||
import com.alterdekim.hearthhack.entity.HeroXP;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DeckRepository extends JpaRepository<Deck, Long> {
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.alterdekim.hearthhack.repository;
|
||||
|
||||
import com.alterdekim.hearthhack.entity.HeroXP;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface HeroXPRepository extends JpaRepository<HeroXP, Long> {
|
||||
}
|
@ -2,9 +2,11 @@ package com.alterdekim.hearthhack.repository;
|
||||
|
||||
import com.alterdekim.hearthhack.entity.Role;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface RoleRepository extends JpaRepository<Role, Long> {
|
||||
Role findByName(String name);
|
||||
|
||||
|
@ -3,14 +3,14 @@ package com.alterdekim.hearthhack.service;
|
||||
import com.alterdekim.hearthhack.dto.UserDTO;
|
||||
import com.alterdekim.hearthhack.entity.Role;
|
||||
import com.alterdekim.hearthhack.entity.User;
|
||||
import com.alterdekim.hearthhack.repository.RoleRepository;
|
||||
import com.alterdekim.hearthhack.repository.UserRepository;
|
||||
import com.alterdekim.hearthhack.repository.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@ -20,6 +20,10 @@ public class UserService implements IService {
|
||||
private final UserRepository userRepository;
|
||||
private final RoleRepository roleRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final HeroXPRepository heroXPRepository;
|
||||
private final DeckRepository deckRepository;
|
||||
private final CardBackRepository cardBackRepository;
|
||||
private final BoosterRepository boosterRepository;
|
||||
|
||||
|
||||
public void saveUser(UserDTO userDto) {
|
||||
@ -47,6 +51,24 @@ public class UserService implements IService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public boolean authMe(String token) {
|
||||
String[] arr = token.split("\\-");
|
||||
if( arr.length != 3 ) return false;
|
||||
String hash = arr[1];
|
||||
Long id = Long.parseLong(arr[2]);
|
||||
Optional<User> user = this.userRepository.findById(id);
|
||||
if( user.isEmpty() ) return false;
|
||||
String raw = user.get().getId() + user.get().getPassword() + user.get().getUsername();
|
||||
return passwordEncoder.matches(raw, hash);
|
||||
}
|
||||
|
||||
public String genHash(Long id) throws Exception {
|
||||
Optional<User> user = this.userRepository.findById(id);
|
||||
if( user.isEmpty() ) throw new Exception();
|
||||
String hash = passwordEncoder.encode(user.get().getId() + user.get().getPassword() + user.get().getUsername());
|
||||
return "HH-"+hash+"-"+id;
|
||||
}
|
||||
|
||||
|
||||
public User findById(Long id) {
|
||||
return userRepository.findById(id).orElse(null);
|
||||
|
@ -1,16 +0,0 @@
|
||||
package com.alterdekim.hearthhack.xml;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static com.alterdekim.hearthhack.xml.XmlType.Attribute;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface XmlElement {
|
||||
String name() default "";
|
||||
XmlType type() default Attribute;
|
||||
boolean inheritName() default true;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.alterdekim.hearthhack.xml;
|
||||
|
||||
public enum XmlType {
|
||||
Attribute,
|
||||
ChildElement,
|
||||
PlainValue,
|
||||
NestedList,
|
||||
List
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user