Commit 029086a9 authored by Marwolf's avatar Marwolf 💬

Merge branch '2.0.0' into '2.0.0'

auction house discord feed

See merge request !2225
parents 28480145 19cebaf5
......@@ -104,6 +104,8 @@
<entry key = "show_unidentified_herb_names">false</entry>
<entry key = "crystal_key_gives_xp">false</entry>
<entry key = "looted_chests_stuck">false</entry>
<entry key = "want_discord_updates">false</entry> <!-- Should a discord webhook be called for auction house changes? -->
<entry key = "discord_webhook_url">null</entry> <!-- Discord Webhook URL -->
<!-- Bank -->
<entry key = "right_click_bank">false</entry>
......
......@@ -104,6 +104,8 @@
<entry key = "proper_magic_tree_name">true</entry> <!-- MODIFIED -->
<entry key = "crystal_key_gives_xp">true</entry> <!-- MODIFIED -->
<entry key = "looted_chests_stuck">true</entry> <!-- MODIFIED -->
<entry key = "want_discord_updates">false</entry>
<entry key = "discord_webhook_url">null</entry>
<!-- Bank -->
<entry key = "right_click_bank">true</entry> <!-- MODIFIED -->
......
......@@ -104,6 +104,8 @@
<entry key = "proper_magic_tree_name">true</entry> <!-- MODIFIED -->
<entry key = "crystal_key_gives_xp">true</entry> <!-- MODIFIED -->
<entry key = "looted_chests_stuck">true</entry> <!-- MODIFIED -->
<entry key = "want_discord_updates">false</entry>
<entry key = "discord_webhook_url">null</entry>
<!-- Bank -->
<entry key = "right_click_bank">true</entry> <!-- MODIFIED -->
......
......@@ -104,6 +104,8 @@
<entry key = "proper_magic_tree_name">false</entry>
<entry key = "crystal_key_gives_xp">false</entry>
<entry key = "looted_chests_stuck">false</entry>
<entry key = "want_discord_updates">false</entry>
<entry key = "discord_webhook_url">null</entry>
<!-- Bank -->
<entry key = "right_click_bank">true</entry> <!-- MODIFIED -->
......
......@@ -104,6 +104,8 @@
<entry key = "proper_magic_tree_name">true</entry> <!-- MODIFIED -->
<entry key = "crystal_key_gives_xp">true</entry> <!-- MODIFIED -->
<entry key = "looted_chests_stuck">true</entry> <!-- MODIFIED -->
<entry key = "want_discord_updates">false</entry>
<entry key = "discord_webhook_url">null</entry>
<!-- Bank -->
<entry key = "right_click_bank">true</entry> <!-- MODIFIED -->
......
......@@ -104,6 +104,8 @@
<entry key = "proper_magic_tree_name">false</entry>
<entry key = "crystal_key_gives_xp">false</entry>
<entry key = "looted_chests_stuck">false</entry>
<entry key = "want_discord_updates">false</entry>
<entry key = "discord_webhook_url">null</entry>
<!-- Bank -->
<entry key = "right_click_bank">false</entry>
......
......@@ -247,6 +247,8 @@ public final class Constants {
public static boolean PROPER_MAGIC_TREE_NAME = false;
public static boolean CRYSTAL_KEY_GIVES_XP = false;
public static boolean LOOTED_CHESTS_STUCK = false;
public static boolean WANT_DISCORD_UPDATES = false;
public static String DISCORD_WEBHOOK_URL = "";
public static int MAX_TICKS_UNTIL_FULL_WALKING_SPEED = 5;
//strict check on level requirements for "glitched" validations on rsc
......@@ -372,6 +374,8 @@ public final class Constants {
PROPER_MAGIC_TREE_NAME = Boolean.parseBoolean(props.getProperty("proper_magic_tree_name"));
CRYSTAL_KEY_GIVES_XP = Boolean.parseBoolean(props.getProperty("crystal_key_gives_xp"));
LOOTED_CHESTS_STUCK = Boolean.parseBoolean(props.getProperty("looted_chests_stuck"));
WANT_DISCORD_UPDATES = Boolean.parseBoolean(props.getProperty("want_discord_updates"));
DISCORD_WEBHOOK_URL = props.getProperty("discord_webhook_url");
NPC_KILL_LIST = Boolean.parseBoolean(props.getProperty("npc_kill_list"));
NPC_KILL_MESSAGES = Boolean.parseBoolean(props.getProperty("npc_kill_messages"));
......
package com.openrsc.server.content.market.task;
import com.openrsc.server.Constants;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
......@@ -8,6 +9,7 @@ import com.openrsc.server.external.ItemDefinition;
import com.openrsc.server.model.container.Item;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.model.world.World;
import com.openrsc.server.net.DiscordSender;
import com.openrsc.server.net.rsc.ActionSender;
public class BuyMarketItemTask extends MarketTask {
......@@ -25,6 +27,7 @@ public class BuyMarketItemTask extends MarketTask {
@Override
public void doTask() {
MarketItem item = MarketDatabase.getAuctionItem(auctionID);
boolean updateDiscord = false;
if (item == null) {
ActionSender.sendBox(playerBuyer, "@red@[Auction House - Error] % @whi@ This item is sold out! % Click 'Refresh' to update the Auction.", false);
......@@ -62,11 +65,13 @@ public class BuyMarketItemTask extends MarketTask {
}
playerBuyer.getInventory().remove(10, auctionPrice);
ActionSender.sendBox(playerBuyer, "@gre@[Auction House - Success] % @whi@ The item has been placed to your inventory.", false);
updateDiscord = true;
playerBuyer.save();
} else if (!playerBuyer.getBank().full()) {
playerBuyer.getBank().add(new Item(item.getItemID(), amount));
playerBuyer.getInventory().remove(10, auctionPrice);
ActionSender.sendBox(playerBuyer, "@gre@[Auction House - Success] % @whi@ The item has been placed to your bank.", false);
updateDiscord = true;
playerBuyer.save();
} else {
ActionSender.sendBox(playerBuyer, "@red@[Auction House - Error] % @whi@ Unable to buy auction, no space left in your inventory or bank.", false);
......@@ -93,6 +98,10 @@ public class BuyMarketItemTask extends MarketTask {
if (item.getAmountLeft() == 0) MarketDatabase.setSoldOut(item);
else MarketDatabase.update(item);
Market.getInstance().addRequestOpenAuctionHouseTask(playerBuyer);
if (updateDiscord && Constants.GameServer.WANT_DISCORD_UPDATES) {
DiscordSender.auctionBuy(item);
}
}
}
package com.openrsc.server.content.market.task;
import com.openrsc.server.Constants;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
......@@ -7,6 +8,7 @@ import com.openrsc.server.external.EntityHandler;
import com.openrsc.server.external.ItemDefinition;
import com.openrsc.server.model.container.Item;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.DiscordSender;
import com.openrsc.server.net.rsc.ActionSender;
public class CancelMarketItemTask extends MarketTask {
......@@ -21,6 +23,7 @@ public class CancelMarketItemTask extends MarketTask {
@Override
public void doTask() {
boolean updateDiscord = false;
MarketItem item = MarketDatabase.getAuctionItem(auctionID);
if (item != null) {
int itemIndex = item.getItemID();
......@@ -32,16 +35,21 @@ public class CancelMarketItemTask extends MarketTask {
owner.getInventory().add(new Item(itemIndex, 1));
else owner.getInventory().add(new Item(itemIndex, amount));
ActionSender.sendBox(owner, "@gre@[Auction House - Success] % @whi@ The item has been canceled and returned to your inventory.", false);
updateDiscord = true;
}
} else if (!owner.getBank().full()) {
if (MarketDatabase.cancel(item)) {
owner.getBank().add(new Item(itemIndex, amount));
ActionSender.sendBox(owner, "@gre@[Auction House - Success] % @whi@ The item has been canceled and returned to your bank. % Talk with a Banker to collect your item(s).", false);
updateDiscord = true;
}
} else
ActionSender.sendBox(owner, "@red@[Auction House - Error] % @whi@ Unable to cancel auction! % % @red@Reason: @whi@No space left in your bank or inventory.", false);
}
Market.getInstance().addRequestOpenAuctionHouseTask(owner);
if (updateDiscord && Constants.GameServer.WANT_DISCORD_UPDATES) {
DiscordSender.auctionCancel(item);
}
}
}
package com.openrsc.server.content.market.task;
import com.openrsc.server.Constants;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.DiscordSender;
import com.openrsc.server.net.rsc.ActionSender;
public class ModeratorDeleteAuctionTask extends MarketTask {
......@@ -18,6 +20,7 @@ public class ModeratorDeleteAuctionTask extends MarketTask {
@Override
public void doTask() {
boolean updateDiscord = false;
if (!player.isMod()) {
player.setSuspiciousPlayer(true);
ActionSender.sendBox(player, "@red@[Auction House - Error] % @whi@ Unable to remove auction", false);
......@@ -29,10 +32,14 @@ public class ModeratorDeleteAuctionTask extends MarketTask {
if (MarketDatabase.setSoldOut(item)) {
MarketDatabase.addCollectableItem("Removed by " + player.getStaffName(), itemIndex, amount, item.getSeller());
ActionSender.sendBox(player, "@gre@[Auction House - Success] % @whi@ Item has been removed from Auctions. % % Returned to collections for: " + item.getSellerName(), false);
updateDiscord = true;
} else
ActionSender.sendBox(player, "@red@[Auction House - Error] % @whi@ Unable to remove auction", false);
}
Market.getInstance().addRequestOpenAuctionHouseTask(player);
if (updateDiscord && Constants.GameServer.WANT_DISCORD_UPDATES) {
DiscordSender.auctionModDelete(item);
}
}
}
}
package com.openrsc.server.content.market.task;
import com.openrsc.server.Constants;
import com.openrsc.server.content.market.Market;
import com.openrsc.server.content.market.MarketDatabase;
import com.openrsc.server.content.market.MarketItem;
......@@ -7,6 +8,7 @@ import com.openrsc.server.external.EntityHandler;
import com.openrsc.server.external.ItemDefinition;
import com.openrsc.server.model.container.Item;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.net.DiscordSender;
import com.openrsc.server.net.rsc.ActionSender;
public class NewMarketItemTask extends MarketTask {
......@@ -22,6 +24,7 @@ public class NewMarketItemTask extends MarketTask {
@Override
public void doTask() {
ItemDefinition def = EntityHandler.getItemDef(newItem.getItemID());
boolean updateDiscord = false;
if (newItem.getItemID() == 10 || def.isUntradable()) {
ActionSender.sendBox(owner, "@red@[Auction House - Error] % @whi@ You cannot sell that item on auction house!", false);
......@@ -67,6 +70,7 @@ public class NewMarketItemTask extends MarketTask {
if (MarketDatabase.add(newItem)) {
//ActionSender.sendBox(owner, "@gre@[Auction House - Success] % @whi@ Auction has been listed % " + newItem.getAmount() + "x @yel@" + def.getName() + " @whi@for @yel@" + newItem.getPrice() + "gp % @whi@Completed auction fee: @gre@" + feeCost + "gp", false);
ActionSender.sendBox(owner, "@gre@[Auction House - Success] % @whi@ Auction has been listed % " + newItem.getAmount() + "x @yel@" + def.getName() + " @whi@for @yel@" + newItem.getPrice() + "gp", false);
updateDiscord = true;
} else {
Item item = new Item(newItem.getItemID(), newItem.getAmount());
if (item.getDef().isStackable()) {
......@@ -79,5 +83,8 @@ public class NewMarketItemTask extends MarketTask {
ActionSender.sendBox(owner, "@red@[Auction House - Error] % @whi@ Failed to add item to Auction. % Item(s) have been returned to your inventory.", false);
}
Market.getInstance().addRequestOpenAuctionHouseTask(owner);
if (updateDiscord && Constants.GameServer.WANT_DISCORD_UPDATES) {
DiscordSender.auctionAdd(newItem);
}
}
}
package com.openrsc.server.net;
import com.openrsc.server.Constants;
import com.openrsc.server.content.market.MarketItem;
import com.openrsc.server.external.EntityHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
public class DiscordSender {
private static final Logger LOGGER = LogManager.getLogger();
public static void auctionAdd(MarketItem addItem) {
String pluralHandlerMessage = addItem.getAmount() > 1
? "%d x %s, priced at %d coins each, auctioned by %s. %d hours left."
: "%d x %s, priced at %d coins, auctioned by %s. %d hours left.";
String addMessage = String.format(pluralHandlerMessage,
addItem.getAmount(),
EntityHandler.getItemDef(addItem.getItemID()).getName(),
addItem.getPrice() / addItem.getAmount(),
addItem.getSellerName(),
addItem.getHoursLeft()
);
try {
sendToDiscord(addMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
}
public static void auctionBuy(MarketItem buyItem) {
String buyMessage = String.format("%s purchased from %s. %d left in auction.",
EntityHandler.getItemDef(buyItem.getItemID()).getName(),
buyItem.getSellerName(),
buyItem.getAmountLeft()
);
try {
sendToDiscord(buyMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
}
public static void auctionCancel(MarketItem cancelItem) {
String cancelMessage = String.format("%d x %s cancelled from auction by %s.",
cancelItem.getAmount(),
EntityHandler.getItemDef(cancelItem.getItemID()).getName(),
cancelItem.getSellerName()
);
try {
sendToDiscord(cancelMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
}
public static void auctionModDelete(MarketItem deleteItem) {
String cancelMessage = String.format("%d x %s, auctioned by %s, has been deleted by moderator.",
deleteItem.getAmount(),
EntityHandler.getItemDef(deleteItem.getItemID()).getName(),
deleteItem.getSellerName()
);
try {
sendToDiscord(cancelMessage);
} catch(Exception e) {
LOGGER.catching(e);
}
}
private static void sendToDiscord(String auctionMessage) throws Exception {
String jsonPostBody = String.format("{\"content\": \"%s\"}", auctionMessage);
java.net.URL url = new java.net.URL(Constants.GameServer.DISCORD_WEBHOOK_URL);
URLConnection con = url.openConnection();
HttpURLConnection http = (HttpURLConnection) con;
http.setRequestMethod("POST");
http.setDoOutput(true);
byte[] out = jsonPostBody.getBytes(StandardCharsets.UTF_8);
int length = out.length;
http.setFixedLengthStreamingMode(length);
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
http.connect();
try (OutputStream os = http.getOutputStream()) {
os.write(out);
}
}
}
......@@ -223,12 +223,10 @@ public class InterfaceOptionHandler implements PacketHandler {
int itemID = p.readInt();
int amount = p.readInt();
int price = p.readInt();
Market.getInstance().addNewAuctionItemTask(player, itemID, amount, price);
break;
case 2:
int auctionID = p.readInt();
Market.getInstance().addCancelAuctionItemTask(player, auctionID);
break;
case 3:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment