Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of 2 new commands for the flipTracking service #19

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions Commands/Minecraft/ClickedCommand.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
using System.Threading.Tasks;
using hypixel;
using MessagePack;
using Newtonsoft.Json;
using RestSharp;

namespace Coflnet.Sky.Commands.MC
{
public class ClickedCommand : McCommand
{
public override Task Execute(MinecraftSocket socket, string arguments)
public async override Task Execute(MinecraftSocket socket, string arguments)
{
return Task.CompletedTask;

var command = JsonConvert.DeserializeObject<string>(arguments);

if (command.Split(" ")[0] != "/viewauction")
{
return;
}

var auctionUUID = command.Split(" ")[1];

//var affected = SubscribeEngine.Instance.Unsubscribe(userId, args.Topic,args.Type).Result;
var request = new RestRequest("Tracker/flipEvent/{auctionUUID}", Method.POST)
.AddJsonBody(new Arguments() { FlipTrackerEvent = FlipEventType.FLIP_CLICK, PlayerUUID = socket.McId })
.AddUrlSegment("auctionUUID", auctionUUID);
var response = await TrackerClient.Client.ExecuteAsync(request);
}

[MessagePackObject]
public class Arguments
{
[Key("playerUUID")]
public string PlayerUUID;
[Key("flipEventType")]
public FlipEventType FlipTrackerEvent;

}

public enum FlipEventType
{
FLIP_RECEIVE = 1,
FLIP_CLICK = 2,
PURCHASE_START = 4,
PURCHASE_CONFIRM = 8,
AUCTION_SOLD = 16
}
}
}
48 changes: 48 additions & 0 deletions Commands/Tracker/TrackFlipEventCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MessagePack;
using Newtonsoft.Json;
using RestSharp;

namespace hypixel
{
public class TrackFlipEventCommand : Command
{
public override async Task Execute(MessageData data)
{
using (var context = new HypixelContext())
{
var args = data.GetAs<Arguments>();

var request = new RestRequest("Tracker/flipEvent/{auctionUUID}", Method.POST)
matthias-luger marked this conversation as resolved.
Show resolved Hide resolved
.AddJsonBody(args)
.AddUrlSegment("auctionUUID", args.AuctionUUID);

var response = await TrackerClient.Client.ExecuteAsync(request);

await data.SendBack(new MessageData("flipEvent", null));
}
}

[MessagePackObject]
public class Arguments
{
[Key("playerUUID")]
public string PlayerUUID;
[Key("auctionUUID")]
public string AuctionUUID;
[Key("flipEventType")]
public FlipEventType FlipTrackerEvent;

}

public enum FlipEventType
{
FLIP_RECEIVE = 1,
FLIP_CLICK = 2,
PURCHASE_START = 4,
PURCHASE_CONFIRM = 8,
AUCTION_SOLD = 16
}
}
}
48 changes: 48 additions & 0 deletions Commands/Tracker/TrackNewFlipCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MessagePack;
using Newtonsoft.Json;
using RestSharp;

namespace hypixel
{
public class TrackNewFlipCommand : Command
{
public override async Task Execute(MessageData data)
{
using (var context = new HypixelContext())
{
var args = data.GetAs<Arguments>();

var request = new RestRequest("Tracker/newFlip/{auctionUUID}", Method.POST)
matthias-luger marked this conversation as resolved.
Show resolved Hide resolved
.AddJsonBody(args)
.AddUrlSegment("auctionUUID", args.AuctionUUID);

var response = await TrackerClient.Client.ExecuteAsync(request);

await data.SendBack(new MessageData("newFlip", null));
}
}

[MessagePackObject]
public class Arguments
{
[Key("auctionUUID")]
public string AuctionUUID;
[Key("targetPrice")]
public int TargetPrice;
[Key("finderType")]
public FinderType FinderType;

}

public enum FinderType
{
FLIPPER = 1,
LOWEST_BIN = 2,
SNIPER = 4,
AI = 8
}
}
}
14 changes: 14 additions & 0 deletions Commands/Tracker/TrackerClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
using RestSharp;

namespace hypixel
{
public static class TrackerClient
{
public static RestClient Client = new RestClient("http://" + SimplerConfig.Config.Instance["TRACKER_HOST"]);
matthias-luger marked this conversation as resolved.
Show resolved Hide resolved

}
}
3 changes: 2 additions & 1 deletion Socket/SkyblockBackEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ static SkyblockBackEnd()
Commands.Add("newAuctions", new NewAuctionsCommand());
Commands.Add("p", new PingCommand());


Commands.Add("trackNewFlip", new TrackNewFlipCommand());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would the frontend need this command?

Commands.Add("trackFlipEvent", new TrackFlipEventCommand());

}

Expand Down
107 changes: 55 additions & 52 deletions appsettings.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"EveryOnePremium": false,
"AllowedHosts": "*",
"SKYCOMMANDS_HOST": "localhost:8008",
"MCCONNECT_HOST": "mcconnect",
"UPDATER_HOST": "updater",
"REDIS_HOST": "redis",
"SKYFLIPPER_HOST": "flipper",
"PAYMENTS_HOST": "payment",
"INDEXER_HOST": "indexer",
"SUBSCRIPTION_HOST": "subscription",
"TRACKER_HOST": "tracker",
"JAEGER_SERVICE_NAME": "sky-commands",
"JAEGER_AGENT_HOST": "jaeger",
"KAFKA_HOST": "kafka:9092",
"JAEGER_SAMPLER_TYPE": "ratelimiting",
"JAEGER_SAMPLER_PARAM": "2",
"TOPICS": {
"MISSING_AUCTION": "sky-canceledauction",
"SOLD_AUCTION": "sky-soldauction",
"AUCTION_ENDED": "sky-endedauction",
"FLIP": "sky-flip",
"SETTINGS_CHANGE": "sky-settings"
},
"IpRateLimiting": {
"EnableEndpointRateLimiting": false,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"EndpointWhitelist": [
"get:/api/license",
"*:/api/status"
],
"IpWhitelist": [
"::1/10",
"172.27.0.0/24"
],
"GeneralRules": [{
"Endpoint": "*",
"Period": "10s",
"Limit": 20
},
{
"Endpoint": "*",
"Period": "1m",
"Limit": 100
}
]
}
},
"EveryOnePremium":false,
"AllowedHosts": "*",
"SKYCOMMANDS_HOST": "localhost:8008",
"MCCONNECT_HOST":"mcconnect",
"UPDATER_HOST":"updater",
"REDIS_HOST":"redis",
"SKYFLIPPER_HOST": "flipper",
"PAYMENTS_HOST": "payment",
"INDEXER_HOST": "indexer",
"SUBSCRIPTION_HOST": "subscription",
"JAEGER_SERVICE_NAME": "sky-commands",
"JAEGER_AGENT_HOST": "jaeger",
"KAFKA_HOST": "kafka:9092",
"JAEGER_SAMPLER_TYPE": "ratelimiting",
"JAEGER_SAMPLER_PARAM": "2",
"TOPICS": {
"MISSING_AUCTION": "sky-canceledauction",
"SOLD_AUCTION": "sky-soldauction",
"AUCTION_ENDED": "sky-endedauction",
"FLIP": "sky-flip",
"SETTINGS_CHANGE": "sky-settings"
},
"IpRateLimiting": {
"EnableEndpointRateLimiting": false,
"StackBlockedRequests": false,
"RealIpHeader": "X-Real-IP",
"ClientIdHeader": "X-ClientId",
"HttpStatusCode": 429,
"EndpointWhitelist": [
"get:/api/license",
"*:/api/status"
],
"IpWhitelist": [ "::1/10", "172.27.0.0/24" ],
"GeneralRules": [
{
"Endpoint": "*",
"Period": "10s",
"Limit": 20
},
{
"Endpoint": "*",
"Period": "1m",
"Limit": 100
}
]
}
Comment on lines 1 to -54
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't reformat the whole file

}