Commit 5b736c39 authored by Brian Foster's avatar Brian Foster

discord auction announcements pt 1

parent ec13b4ad
......@@ -7,6 +7,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 {
......@@ -67,6 +68,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);
DiscordSender.auctionAdd(newItem.getItemID(), newItem.getPrice(), newItem.getAmount(), newItem.getSellerName());
} else {
Item item = new Item(newItem.getItemID(), newItem.getAmount());
if (item.getDef().isStackable()) {
......
package com.openrsc.server.net;
import com.openrsc.server.external.EntityHandler;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
public class DiscordSender {
private static String discordUrl = "https://discordapp.com/api/webhooks/597525640895397900/MVZYoeHXhju1_h74NwT4Kffv3g1wpNsNLeWl7YhhECSOXNuwwTXrR3_YJcGRGFpAOcFu";
public static void auctionAdd(int itemID, int price, int amount, String player) {
String addMessage = String.format("{\"content\": \"%s has auctioned %d x %s, priced at %d.\"}", player, amount, EntityHandler.getItemDef(itemID).getName(), price);
try {
sendToDiscord(addMessage);
} catch(Exception e) {
// swallow for now
}
}
private static void sendToDiscord(String auctionMessage) throws Exception {
String jsonPostBody = String.format("{\"content\": \"%s\"}", auctionMessage);
java.net.URL url = new java.net.URL(discordUrl);
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);
}
}
}
......@@ -7,12 +7,15 @@ import com.openrsc.server.content.market.Market;
import com.openrsc.server.model.entity.npc.Npc;
import com.openrsc.server.model.entity.player.Player;
import com.openrsc.server.model.world.World;
import com.openrsc.server.net.Packet;
import com.openrsc.server.net.rsc.ActionSender;
import com.openrsc.server.net.rsc.PacketHandler;
import com.openrsc.server.plugins.Functions;
import com.openrsc.server.util.rsc.DataConversions;
public class InterfaceOptionHandler implements PacketHandler {
......@@ -223,12 +226,11 @@ 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