mirror of
https://github.com/Leahnaya/UBFunkeysServer.git
synced 2026-03-22 01:34:26 -05:00
Finish Jammers from Funkey Trunk
This commit is contained in:
parent
b22c0bcefd
commit
69e02d1d04
|
|
@ -147,6 +147,9 @@ public class ArkOneController implements TcpHandler {
|
|||
case "gfl":
|
||||
responses.add(trunkPlugin.GetFamiliarsList());
|
||||
break;
|
||||
case "gjl":
|
||||
responses.add(trunkPlugin.GetJammerList());
|
||||
break;
|
||||
case "gutc":
|
||||
responses.add(trunkPlugin.GetUserTransactionsCount(connection));
|
||||
break;
|
||||
|
|
@ -154,11 +157,14 @@ public class ArkOneController implements TcpHandler {
|
|||
responses.add(trunkPlugin.GetUserTransactions(connection));
|
||||
break;
|
||||
case "asp":
|
||||
responses.add(trunkPlugin.AssetParam());
|
||||
responses.add(trunkPlugin.AssetParam(commandInfo, connection));
|
||||
break;
|
||||
case "bf":
|
||||
responses.add(trunkPlugin.BuyFamiliar(commandInfo, connection));
|
||||
break;
|
||||
case "bj":
|
||||
responses.add(trunkPlugin.BuyJammer(commandInfo, connection));
|
||||
break;
|
||||
|
||||
// Catch Unhandled Commands
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package com.icedberries.UBFunkeysServer.ArkOne.Plugins;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.ArkOne.ArkOneParser;
|
||||
import com.icedberries.UBFunkeysServer.DatabaseSetup.TrunkData;
|
||||
import com.icedberries.UBFunkeysServer.domain.Familiar;
|
||||
import com.icedberries.UBFunkeysServer.domain.Jammer;
|
||||
import com.icedberries.UBFunkeysServer.domain.User;
|
||||
import com.icedberries.UBFunkeysServer.service.FamiliarService;
|
||||
import com.icedberries.UBFunkeysServer.service.FileService;
|
||||
import com.icedberries.UBFunkeysServer.service.JammerService;
|
||||
import com.icedberries.UBFunkeysServer.service.UserService;
|
||||
import javagrinko.spring.tcp.Connection;
|
||||
import javagrinko.spring.tcp.Server;
|
||||
|
|
@ -34,7 +37,8 @@ public class TrunkPlugin {
|
|||
private final Integer LOOT_BALANCE = 2500;
|
||||
|
||||
private enum PurchaseType {
|
||||
FAMILIAR
|
||||
FAMILIAR,
|
||||
JAMMER
|
||||
}
|
||||
|
||||
@Autowired
|
||||
|
|
@ -46,11 +50,14 @@ public class TrunkPlugin {
|
|||
@Autowired
|
||||
FamiliarService familiarService;
|
||||
|
||||
@Autowired
|
||||
JammerService jammerService;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
public String GetUserAssets(Connection connection) throws ParserConfigurationException, IOException, SAXException {
|
||||
//TODO: IMPLEMENT ITEMS | MOODS | JAMMERS
|
||||
//TODO: IMPLEMENT ITEMS | MOODS
|
||||
// Moods - Tag looks like this: <m id="80041a" />
|
||||
|
||||
// Append the starting tags
|
||||
|
|
@ -88,6 +95,17 @@ public class TrunkPlugin {
|
|||
// id -> item id
|
||||
response.append("<f id=\"" + id + "\" p=\"" + p + "\" c=\"" + (c / 60) + "\" />");
|
||||
}
|
||||
|
||||
/* Append the jammers
|
||||
* NOTE: We have to store this on the profile since the user doesn't properly save jammer
|
||||
* counts to the profile data
|
||||
*/
|
||||
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
|
||||
Integer p = user.getJammersUsed() != null ? user.getJammersUsed() : 0;
|
||||
Integer c = user.getJammersTotal() != null ? user.getJammersTotal() : 0;
|
||||
if (c > 0) {
|
||||
response.append("<j id=\"" + TrunkData.JAMMER_RID + "\" p=\"" + p + "\" c=\"" + c + "\" />");
|
||||
}
|
||||
}
|
||||
|
||||
// Append the ending tags
|
||||
|
|
@ -112,7 +130,7 @@ public class TrunkPlugin {
|
|||
|
||||
// Iterate over the items in the familiars list to add them to the response
|
||||
for (Familiar familiar : familiars) {
|
||||
stringBuilder.append("<f rid=\"" + familiar.getId() + "\" id=\"" + familiar.getId() + "\" c=\""
|
||||
stringBuilder.append("<f rid=\"" + familiar.getRid() + "\" id=\"" + familiar.getId() + "\" c=\""
|
||||
+ familiar.getCost() + "\" dc=\"" + familiar.getDiscountedCost() + "\" h=\""
|
||||
+ familiar.getDuration() + "\" d=\"\" />");
|
||||
}
|
||||
|
|
@ -124,6 +142,28 @@ public class TrunkPlugin {
|
|||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String GetJammerList() {
|
||||
|
||||
// Get all the jammers
|
||||
List<Jammer> jammers = jammerService.findAll();
|
||||
|
||||
// Start to build the response
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<h10_0><gjl>");
|
||||
|
||||
// Iterate over the items in the familiars list to add them to the response
|
||||
for (Jammer jammer : jammers) {
|
||||
stringBuilder.append("<j rid=\"" + jammer.getRid() + "\" id=\"" + jammer.getId() + "\" c=\""
|
||||
+ jammer.getCost() + "\" q=\"" + jammer.getQty() + "\" d=\"\" />");
|
||||
}
|
||||
|
||||
// Add closing tags
|
||||
stringBuilder.append("</gjl></h10_0>");
|
||||
|
||||
// Return the list
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public String GetUserTransactionsCount(Connection connection) {
|
||||
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
|
||||
|
||||
|
|
@ -157,20 +197,50 @@ public class TrunkPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public String AssetParam() {
|
||||
// Doesn't seem to be needed so we can just respond with an empty xml tag
|
||||
public String AssetParam(Element element, Connection connection) {
|
||||
/* This method would be used to update the server profile data for when familiars are started (setting start time)
|
||||
* Or when you use a jammer
|
||||
*
|
||||
* For familiars we can trust the profile data saved and load from those
|
||||
* For jammers, the profile doesn't update properly so we need to update the jammer used count when received
|
||||
*/
|
||||
|
||||
// Check for id equal to the jammer rid
|
||||
if (element.getAttribute("id").equals("80014a")) {
|
||||
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
|
||||
Integer newUsed = Integer.valueOf(element.getAttribute("p"));
|
||||
user.setJammersUsed(newUsed);
|
||||
userService.updateUserOnServer(connection, user);
|
||||
}
|
||||
|
||||
// Return this regardless of outcome (I don't believe a response is read from this)
|
||||
return "<h10_0><asp /></h10_0>";
|
||||
}
|
||||
|
||||
public String BuyFamiliar(Element element, Connection connection) {
|
||||
// Save this transaction to the DB
|
||||
PostTransaction(connection, PurchaseType.FAMILIAR, element.getAttribute("id"));
|
||||
PostTransaction(connection, PurchaseType.FAMILIAR, Integer.valueOf(element.getAttribute("id")));
|
||||
|
||||
// We always return LOOT_BALANCE so players are never charged for these items
|
||||
return "<h10_0><bf id=\"" + element.getAttribute("id") + "\" b=\"" + LOOT_BALANCE + "\" /></h10_0>";
|
||||
}
|
||||
|
||||
public void PostTransaction(Connection connection, PurchaseType purchaseType, String itemId) {
|
||||
public String BuyJammer(Element element, Connection connection) {
|
||||
// Save this transaction to the DB
|
||||
PostTransaction(connection, PurchaseType.JAMMER, Integer.valueOf(element.getAttribute("id")));
|
||||
|
||||
// Increase the amount of jammers a player has in their account
|
||||
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
|
||||
Integer qtyBought = jammerService.getQtyById(Integer.valueOf(element.getAttribute("id")));
|
||||
Integer currentTotal = user.getJammersTotal() != null ? user.getJammersTotal() : 0;
|
||||
user.setJammersTotal(currentTotal + qtyBought);
|
||||
userService.updateUserOnServer(connection, user);
|
||||
|
||||
// We always return LOOT_BALANCE so players are never charged for these items
|
||||
return "<h10_0><bj id=\"" + element.getAttribute("id") + "\" b=\"" + LOOT_BALANCE + "\" /></h10_0>";
|
||||
}
|
||||
|
||||
public void PostTransaction(Connection connection, PurchaseType purchaseType, Integer itemId) {
|
||||
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
|
||||
|
||||
// Get the date for this transaction
|
||||
|
|
@ -184,10 +254,24 @@ public class TrunkPlugin {
|
|||
case FAMILIAR:
|
||||
cost = familiarService.getCostById(itemId);
|
||||
break;
|
||||
case JAMMER:
|
||||
cost = jammerService.getCostById(itemId);
|
||||
break;
|
||||
}
|
||||
|
||||
// Get the rid of the item
|
||||
String rid = "";
|
||||
switch(purchaseType) {
|
||||
case FAMILIAR:
|
||||
rid = familiarService.getRidById(itemId);
|
||||
break;
|
||||
case JAMMER:
|
||||
rid = jammerService.getRidById(itemId);
|
||||
break;
|
||||
}
|
||||
|
||||
// Create a transaction xml tag
|
||||
String transaction = "<t id=\"" + itemId + "\" rid=\"" + itemId + "\" d=\"" + date + "\" c=\""
|
||||
String transaction = "<t id=\"" + itemId + "\" rid=\"" + rid + "\" d=\"" + date + "\" c=\""
|
||||
+ cost + "\" b=\"" + LOOT_BALANCE + "\" />";
|
||||
|
||||
// Append to the user's transaction history
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ public class UserPlugin {
|
|||
.rawBuddyList("")
|
||||
.transactionCount(0)
|
||||
.transactionHistory("")
|
||||
.jammersUsed(0)
|
||||
.jammersTotal(0)
|
||||
.build();
|
||||
|
||||
// 0 - Successfully registered
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.icedberries.UBFunkeysServer.DatabaseSetup;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Familiar;
|
||||
import com.icedberries.UBFunkeysServer.domain.Jammer;
|
||||
import com.icedberries.UBFunkeysServer.service.FamiliarService;
|
||||
import com.icedberries.UBFunkeysServer.service.JammerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
|
@ -16,10 +18,25 @@ public class TrunkData {
|
|||
@Autowired
|
||||
FamiliarService familiarService;
|
||||
|
||||
@Autowired
|
||||
JammerService jammerService;
|
||||
|
||||
// List of all familiar ids
|
||||
private final List<String> familiarIds = Arrays.asList("80036a", "80035a", "80034a", "80033a", "80032a", "80031a", "80030a",
|
||||
"80029a", "80028a", "80027a", "80026a", "80025a", "80017a", "80016a", "80015a", "80007a", "80006a",
|
||||
"80005a", "80004a", "80003a", "80002a", "80001a", "80000a");
|
||||
|
||||
public static final String JAMMER_RID = "80014a";
|
||||
private final List<Integer> JAMMER_PACKAGE_QTYS = Arrays.asList(1, 5, 10, 25, 50, 100);
|
||||
String PackageOf1 = "<j id=\"1\" rid=\"80014a\" c=\"10\" q=\"1\" d=\"\" />";
|
||||
String PackageOf5 = "<j id=\"2\" rid=\"80014a\" c=\"50\" q=\"5\" d=\"\" />";
|
||||
String PackageOf10 = "<j id=\"3\" rid=\"80014a\" c=\"100\" q=\"10\" d=\"\" />";
|
||||
String PackageOf25 = "<j id=\"4\" rid=\"80014a\" c=\"250\" q=\"25\" d=\"\" />";
|
||||
String PackageOf50 = "<j id=\"5\" rid=\"80014a\" c=\"500\" q=\"50\" d=\"\" />";
|
||||
String PackageOf100 = "<j id=\"6\" rid=\"80014a\" c=\"1000\" q=\"100\" d=\"\" />";
|
||||
|
||||
private final Integer JAMMER_COST = 10;
|
||||
|
||||
private final Integer FAMILIAR_COST = 100;
|
||||
private final Integer FAMILIAR_DISCOUNT_COST = 50;
|
||||
private final Integer FAMILIAR_DURATION = 720;
|
||||
|
|
@ -27,15 +44,17 @@ public class TrunkData {
|
|||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void insertFamiliars() {
|
||||
// Iterate over the familiar ids
|
||||
int idNum = 0;
|
||||
for (String id : familiarIds) {
|
||||
// Attempt to get it from the DB
|
||||
Familiar familiar = familiarService.findById(id).orElse(null);
|
||||
Familiar familiar = familiarService.findByRid(id).orElse(null);
|
||||
|
||||
// Only insert if the data is null
|
||||
if (familiar == null) {
|
||||
// Build a new familiar to insert
|
||||
Familiar newFamiliar = Familiar.builder()
|
||||
.id(id)
|
||||
.id(idNum)
|
||||
.rid(id)
|
||||
.cost(FAMILIAR_COST)
|
||||
.discountedCost(FAMILIAR_DISCOUNT_COST)
|
||||
.duration(FAMILIAR_DURATION)
|
||||
|
|
@ -44,6 +63,36 @@ public class TrunkData {
|
|||
// Save it to the db
|
||||
familiarService.save(newFamiliar);
|
||||
}
|
||||
|
||||
// Increment id
|
||||
idNum++;
|
||||
}
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void insertJammers() {
|
||||
// Iterate over the jammer package quantities
|
||||
int idNum = 0;
|
||||
for (Integer qty : JAMMER_PACKAGE_QTYS) {
|
||||
// Attempt to get from the DB
|
||||
Jammer jammer = jammerService.findByQty(qty).orElse(null);
|
||||
|
||||
// Only insert if the data is null
|
||||
if (jammer == null) {
|
||||
// Build a new jammer to insert
|
||||
Jammer newJammer = Jammer.builder()
|
||||
.id(idNum)
|
||||
.rid(JAMMER_RID)
|
||||
.cost(JAMMER_COST * qty)
|
||||
.qty(qty)
|
||||
.build();
|
||||
|
||||
// Save it to the db
|
||||
jammerService.save(newJammer);
|
||||
}
|
||||
|
||||
// Increment id
|
||||
idNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,12 @@ import javax.persistence.Table;
|
|||
@Table(name = "Familiars")
|
||||
public class Familiar {
|
||||
|
||||
// Item ID
|
||||
// DB ID
|
||||
@Id
|
||||
private String id;
|
||||
private Integer id;
|
||||
|
||||
// Item ID
|
||||
private String rid;
|
||||
|
||||
private Integer cost;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.icedberries.UBFunkeysServer.domain;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "Jammers")
|
||||
public class Jammer {
|
||||
|
||||
// DB ID
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
// Item ID
|
||||
private String rid;
|
||||
|
||||
private Integer cost;
|
||||
|
||||
private Integer qty;
|
||||
}
|
||||
|
|
@ -81,6 +81,10 @@ public class User {
|
|||
@Type(type = "org.hibernate.type.TextType")
|
||||
private String transactionHistory;
|
||||
|
||||
private Integer jammersTotal;
|
||||
|
||||
private Integer jammersUsed;
|
||||
|
||||
public java.util.UUID getConnectionId() {
|
||||
return java.util.UUID.fromString(connectionId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,18 @@ import org.springframework.data.repository.query.Param;
|
|||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface FamiliarRepository extends CrudRepository<Familiar, String> {
|
||||
public interface FamiliarRepository extends CrudRepository<Familiar, Integer> {
|
||||
|
||||
List<Familiar> findAll();
|
||||
|
||||
@Query("select familiar.cost from Familiar familiar where familiar.id = :id")
|
||||
Integer getCostById(@Param("id") String id);
|
||||
Integer getCostById(@Param("id") Integer id);
|
||||
|
||||
Optional<Familiar> findByRid(String rid);
|
||||
|
||||
@Query("select familiar.rid from Familiar familiar where familiar.id = :id")
|
||||
String getRidById(@Param("id") Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.icedberries.UBFunkeysServer.repository;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Jammer;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface JammerRepository extends CrudRepository<Jammer, Integer> {
|
||||
|
||||
@Query("select jammer.cost from Jammer jammer where jammer.id = :id")
|
||||
Integer getCostById(@Param("id") Integer id);
|
||||
|
||||
@Query("select jammer from Jammer jammer where jammer.qty = :qty")
|
||||
Optional<Jammer> findByQty(@Param("qty") Integer qty);
|
||||
|
||||
@Query("select jammer.rid from Jammer jammer where jammer.id = :id")
|
||||
String getRidById(@Param("id") Integer id);
|
||||
|
||||
@Query("select jammer.qty from Jammer jammer where jammer.id = :id")
|
||||
Integer getQtyById(@Param("id") Integer id);
|
||||
|
||||
List<Jammer> findAll();
|
||||
}
|
||||
|
|
@ -7,11 +7,13 @@ import java.util.Optional;
|
|||
|
||||
public interface FamiliarService {
|
||||
|
||||
Optional<Familiar> findById(String id);
|
||||
Optional<Familiar> findByRid(String rid);
|
||||
|
||||
Familiar save(Familiar familiar);
|
||||
|
||||
List<Familiar> findAll();
|
||||
|
||||
Integer getCostById(String id);
|
||||
Integer getCostById(Integer id);
|
||||
|
||||
String getRidById(Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.icedberries.UBFunkeysServer.service;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Jammer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface JammerService {
|
||||
|
||||
Integer getCostById(Integer id);
|
||||
|
||||
Jammer save(Jammer jammer);
|
||||
|
||||
Optional<Jammer> findByQty(Integer qty);
|
||||
|
||||
String getRidById(Integer id);
|
||||
|
||||
List<Jammer> findAll();
|
||||
|
||||
Integer getQtyById(Integer id);
|
||||
}
|
||||
|
|
@ -16,8 +16,8 @@ public class FamiliarServiceImpl implements FamiliarService {
|
|||
private final FamiliarRepository familiarRepository;
|
||||
|
||||
@Override
|
||||
public Optional<Familiar> findById(String id) {
|
||||
return familiarRepository.findById(id);
|
||||
public Optional<Familiar> findByRid(String rid) {
|
||||
return familiarRepository.findByRid(rid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -31,7 +31,12 @@ public class FamiliarServiceImpl implements FamiliarService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Integer getCostById(String id) {
|
||||
public Integer getCostById(Integer id) {
|
||||
return familiarRepository.getCostById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRidById(Integer id) {
|
||||
return familiarRepository.getRidById(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.icedberries.UBFunkeysServer.service.impl;
|
||||
|
||||
import com.icedberries.UBFunkeysServer.domain.Jammer;
|
||||
import com.icedberries.UBFunkeysServer.repository.JammerRepository;
|
||||
import com.icedberries.UBFunkeysServer.service.JammerService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class JammerServiceImpl implements JammerService {
|
||||
|
||||
private final JammerRepository jammerRepository;
|
||||
|
||||
@Override
|
||||
public Integer getCostById(Integer id) {
|
||||
return jammerRepository.getCostById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Jammer save(Jammer jammer) {
|
||||
return jammerRepository.save(jammer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Jammer> findByQty(Integer qty) {
|
||||
return jammerRepository.findByQty(qty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRidById(Integer id) {
|
||||
return jammerRepository.getRidById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Jammer> findAll() {
|
||||
return jammerRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getQtyById(Integer id) {
|
||||
return jammerRepository.getQtyById(id);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user