From 8000f9075bb9bff9595a56adc71da9dc465511c1 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Thu, 28 Oct 2021 06:32:42 +0200 Subject: [PATCH 1/5] Implementation of 2 new commands for the flipTracking service --- Commands/Tracker/TrackFlipEventCommand.cs | 61 +++++++++++++++++++++++ Commands/Tracker/TrackNewFlipCommand.cs | 52 +++++++++++++++++++ Commands/Tracker/TrackerClient.cs | 14 ++++++ Models/FlipEventTrackingModel.cs | 43 ++++++++++++++++ Models/NewFlipTrackingModel.cs | 34 +++++++++++++ Socket/SkyblockBackEnd.cs | 3 +- 6 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 Commands/Tracker/TrackFlipEventCommand.cs create mode 100644 Commands/Tracker/TrackNewFlipCommand.cs create mode 100644 Commands/Tracker/TrackerClient.cs create mode 100644 Models/FlipEventTrackingModel.cs create mode 100644 Models/NewFlipTrackingModel.cs diff --git a/Commands/Tracker/TrackFlipEventCommand.cs b/Commands/Tracker/TrackFlipEventCommand.cs new file mode 100644 index 0000000..a7134ce --- /dev/null +++ b/Commands/Tracker/TrackFlipEventCommand.cs @@ -0,0 +1,61 @@ +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace hypixel +{ + public class TrackFlipEventCommand : Command + { + public override async Task Execute(MessageData data) + { + using (var context = new HypixelContext()) + { + var args = data.GetAs(); + var userId = data.UserId; + + var request = new RestRequest("Tracker/flipEvent", Method.POST) + .AddJsonBody(new FlipTrackingModel() { playerUUID = args.playerUUID, auctionUUID = args.auctionUUID, flipTrackerEvent = args.flipTrackerEvent, timestamp = args.timestamp }); + + await data.SendBack(new MessageData("flipEvent", null)); + } + } + + [MessagePackObject] + public class Arguments + { + [Key("playerUUID")] + public string playerUUID; + [Key("auctionUUID")] + public int auctionUUID; + [Key("event")] + public FlipTrackerEvent flipTrackerEvent; + [Key("timestamp")] + public long timestamp + { + set + { + if (value == 0) + { + End = DateTime.Now; + } + else + End = value.ThisIsNowATimeStamp(); + } + get + { + return End.ToUnix(); + } + } + + } + + public enum FlipTrackerEvent + { + PURCHASE_START = 1, + PURCHASE_CONFIRM = 2, + FLIP_RECEIVE = 4, + FLIP_CLICK = 8, + AUCTION_SOLD = 16 + } + } +} diff --git a/Commands/Tracker/TrackNewFlipCommand.cs b/Commands/Tracker/TrackNewFlipCommand.cs new file mode 100644 index 0000000..8a92cfc --- /dev/null +++ b/Commands/Tracker/TrackNewFlipCommand.cs @@ -0,0 +1,52 @@ +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace hypixel +{ + public class TrackNewFlipCommand : Command + { + public override async Task Execute(MessageData data) + { + using (var context = new HypixelContext()) + { + var args = data.GetAs(); + var userId = data.UserId; + + var request = new RestRequest("Tracker/newFlip", Method.POST) + .AddJsonBody(new FlipTrackingModel() { auctionUUID = args.auctionUUID, targetPrice = args.targetPrice, finderType = args.finderType, timestamp = args.timestamp }); + + await data.SendBack(new MessageData("newFlip", null)); + } + } + + [MessagePackObject] + public class Arguments + { + [Key("auctionUUID")] + public string auctionUUID; + [Key("targetPrice")] + public int targetPrice; + [Key("finderType")] + public string finderType; + [Key("timestamp")] + public long timestamp + { + set + { + if (value == 0) + { + End = DateTime.Now; + } + else + End = value.ThisIsNowATimeStamp(); + } + get + { + return End.ToUnix(); + } + } + + } + } +} diff --git a/Commands/Tracker/TrackerClient.cs b/Commands/Tracker/TrackerClient.cs new file mode 100644 index 0000000..332cdce --- /dev/null +++ b/Commands/Tracker/TrackerClient.cs @@ -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"]); + + } +} \ No newline at end of file diff --git a/Models/FlipEventTrackingModel.cs b/Models/FlipEventTrackingModel.cs new file mode 100644 index 0000000..3d11879 --- /dev/null +++ b/Models/FlipEventTrackingModel.cs @@ -0,0 +1,43 @@ + +using System.Collections.Generic; +using System.Linq; +using hypixel; + +namespace Coflnet.Sky.Filter +{ + public class FlipEventTrackingModel + { + [Key("playerUUID")] + public string playerUUID; + [Key("auctionUUID")] + public int auctionUUID; + [Key("event")] + public FlipTrackerEvent flipTrackerEvent; + [Key("timestamp")] + public long timestamp + { + set + { + if (value == 0) + { + End = DateTime.Now; + } + else + End = value.ThisIsNowATimeStamp(); + } + get + { + return End.ToUnix(); + } + } + } + + public enum FlipTrackerEvent + { + PURCHASE_START = 1, + PURCHASE_CONFIRM = 2, + FLIP_RECEIVE = 4, + FLIP_CLICK = 8, + AUCTION_SOLD = 16 + } +} \ No newline at end of file diff --git a/Models/NewFlipTrackingModel.cs b/Models/NewFlipTrackingModel.cs new file mode 100644 index 0000000..dc9ec0d --- /dev/null +++ b/Models/NewFlipTrackingModel.cs @@ -0,0 +1,34 @@ + +using System.Collections.Generic; +using System.Linq; +using hypixel; + +namespace Coflnet.Sky.Filter +{ + public class NewFlipTrackingModel + { + [Key("auctionUUID")] + public string auctionUUID; + [Key("targetPrice")] + public int targetPrice; + [Key("finderType")] + public string finderType; + [Key("timestamp")] + public long timestamp + { + set + { + if (value == 0) + { + End = DateTime.Now; + } + else + End = value.ThisIsNowATimeStamp(); + } + get + { + return End.ToUnix(); + } + } + } +} \ No newline at end of file diff --git a/Socket/SkyblockBackEnd.cs b/Socket/SkyblockBackEnd.cs index 2e21d70..d36bae5 100644 --- a/Socket/SkyblockBackEnd.cs +++ b/Socket/SkyblockBackEnd.cs @@ -130,7 +130,8 @@ static SkyblockBackEnd() Commands.Add("newAuctions", new NewAuctionsCommand()); Commands.Add("p", new PingCommand()); - + Commands.Add("trackNewFlip", new TrackNewFlipCommand()); + Commands.Add("trackFlipEvent", new TrackFlipEventCommand()); } From 6067c3a66f3e5fefcb1b197ec3b26a285564c15f Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Fri, 5 Nov 2021 21:31:43 +0100 Subject: [PATCH 2/5] send uuid in url --- Commands/Tracker/TrackFlipEventCommand.cs | 26 ++++---------- Commands/Tracker/TrackNewFlipCommand.cs | 25 ++++--------- Models/FlipEventTrackingModel.cs | 43 ----------------------- Models/NewFlipTrackingModel.cs | 34 ------------------ 4 files changed, 13 insertions(+), 115 deletions(-) delete mode 100644 Models/FlipEventTrackingModel.cs delete mode 100644 Models/NewFlipTrackingModel.cs diff --git a/Commands/Tracker/TrackFlipEventCommand.cs b/Commands/Tracker/TrackFlipEventCommand.cs index a7134ce..a83cfb5 100644 --- a/Commands/Tracker/TrackFlipEventCommand.cs +++ b/Commands/Tracker/TrackFlipEventCommand.cs @@ -1,6 +1,8 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; +using MessagePack; using Newtonsoft.Json; +using RestSharp; namespace hypixel { @@ -13,8 +15,9 @@ public override async Task Execute(MessageData data) var args = data.GetAs(); var userId = data.UserId; - var request = new RestRequest("Tracker/flipEvent", Method.POST) - .AddJsonBody(new FlipTrackingModel() { playerUUID = args.playerUUID, auctionUUID = args.auctionUUID, flipTrackerEvent = args.flipTrackerEvent, timestamp = args.timestamp }); + var request = new RestRequest("Tracker/flipEvent/{auctionUUID}", Method.POST) + .AddJsonBody(args) + .AddUrlSegment("auctionUUID", args.auctionUUID); await data.SendBack(new MessageData("flipEvent", null)); } @@ -26,26 +29,9 @@ public class Arguments [Key("playerUUID")] public string playerUUID; [Key("auctionUUID")] - public int auctionUUID; + public string auctionUUID; [Key("event")] public FlipTrackerEvent flipTrackerEvent; - [Key("timestamp")] - public long timestamp - { - set - { - if (value == 0) - { - End = DateTime.Now; - } - else - End = value.ThisIsNowATimeStamp(); - } - get - { - return End.ToUnix(); - } - } } diff --git a/Commands/Tracker/TrackNewFlipCommand.cs b/Commands/Tracker/TrackNewFlipCommand.cs index 8a92cfc..22bdc9b 100644 --- a/Commands/Tracker/TrackNewFlipCommand.cs +++ b/Commands/Tracker/TrackNewFlipCommand.cs @@ -1,6 +1,9 @@ +using System; using System.Text.RegularExpressions; using System.Threading.Tasks; +using MessagePack; using Newtonsoft.Json; +using RestSharp; namespace hypixel { @@ -13,8 +16,9 @@ public override async Task Execute(MessageData data) var args = data.GetAs(); var userId = data.UserId; - var request = new RestRequest("Tracker/newFlip", Method.POST) - .AddJsonBody(new FlipTrackingModel() { auctionUUID = args.auctionUUID, targetPrice = args.targetPrice, finderType = args.finderType, timestamp = args.timestamp }); + var request = new RestRequest("Tracker/newFlip/{auctionUUID}", Method.POST) + .AddJsonBody(args) + .AddUrlSegment("auctionUUID", args.auctionUUID); await data.SendBack(new MessageData("newFlip", null)); } @@ -30,22 +34,7 @@ public class Arguments [Key("finderType")] public string finderType; [Key("timestamp")] - public long timestamp - { - set - { - if (value == 0) - { - End = DateTime.Now; - } - else - End = value.ThisIsNowATimeStamp(); - } - get - { - return End.ToUnix(); - } - } + public DateTime timestamp; } } diff --git a/Models/FlipEventTrackingModel.cs b/Models/FlipEventTrackingModel.cs deleted file mode 100644 index 3d11879..0000000 --- a/Models/FlipEventTrackingModel.cs +++ /dev/null @@ -1,43 +0,0 @@ - -using System.Collections.Generic; -using System.Linq; -using hypixel; - -namespace Coflnet.Sky.Filter -{ - public class FlipEventTrackingModel - { - [Key("playerUUID")] - public string playerUUID; - [Key("auctionUUID")] - public int auctionUUID; - [Key("event")] - public FlipTrackerEvent flipTrackerEvent; - [Key("timestamp")] - public long timestamp - { - set - { - if (value == 0) - { - End = DateTime.Now; - } - else - End = value.ThisIsNowATimeStamp(); - } - get - { - return End.ToUnix(); - } - } - } - - public enum FlipTrackerEvent - { - PURCHASE_START = 1, - PURCHASE_CONFIRM = 2, - FLIP_RECEIVE = 4, - FLIP_CLICK = 8, - AUCTION_SOLD = 16 - } -} \ No newline at end of file diff --git a/Models/NewFlipTrackingModel.cs b/Models/NewFlipTrackingModel.cs deleted file mode 100644 index dc9ec0d..0000000 --- a/Models/NewFlipTrackingModel.cs +++ /dev/null @@ -1,34 +0,0 @@ - -using System.Collections.Generic; -using System.Linq; -using hypixel; - -namespace Coflnet.Sky.Filter -{ - public class NewFlipTrackingModel - { - [Key("auctionUUID")] - public string auctionUUID; - [Key("targetPrice")] - public int targetPrice; - [Key("finderType")] - public string finderType; - [Key("timestamp")] - public long timestamp - { - set - { - if (value == 0) - { - End = DateTime.Now; - } - else - End = value.ThisIsNowATimeStamp(); - } - get - { - return End.ToUnix(); - } - } - } -} \ No newline at end of file From 1be39e669b8c5819ca253720b82dd2d1df1df2d0 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Fri, 5 Nov 2021 21:57:12 +0100 Subject: [PATCH 3/5] property name changes --- Commands/Tracker/TrackFlipEventCommand.cs | 20 ++++++++++---------- Commands/Tracker/TrackNewFlipCommand.cs | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Commands/Tracker/TrackFlipEventCommand.cs b/Commands/Tracker/TrackFlipEventCommand.cs index a83cfb5..41e4053 100644 --- a/Commands/Tracker/TrackFlipEventCommand.cs +++ b/Commands/Tracker/TrackFlipEventCommand.cs @@ -17,7 +17,7 @@ public override async Task Execute(MessageData data) var request = new RestRequest("Tracker/flipEvent/{auctionUUID}", Method.POST) .AddJsonBody(args) - .AddUrlSegment("auctionUUID", args.auctionUUID); + .AddUrlSegment("auctionUUID", args.AuctionUUID); await data.SendBack(new MessageData("flipEvent", null)); } @@ -27,20 +27,20 @@ public override async Task Execute(MessageData data) public class Arguments { [Key("playerUUID")] - public string playerUUID; + public string PlayerUUID; [Key("auctionUUID")] - public string auctionUUID; - [Key("event")] - public FlipTrackerEvent flipTrackerEvent; + public string AuctionUUID; + [Key("flipEventType")] + public FlipEventType FlipTrackerEvent; } - public enum FlipTrackerEvent + public enum FlipEventType { - PURCHASE_START = 1, - PURCHASE_CONFIRM = 2, - FLIP_RECEIVE = 4, - FLIP_CLICK = 8, + FLIP_RECEIVE = 1, + FLIP_CLICK = 2, + PURCHASE_START = 4, + PURCHASE_CONFIRM = 8, AUCTION_SOLD = 16 } } diff --git a/Commands/Tracker/TrackNewFlipCommand.cs b/Commands/Tracker/TrackNewFlipCommand.cs index 22bdc9b..520d4ec 100644 --- a/Commands/Tracker/TrackNewFlipCommand.cs +++ b/Commands/Tracker/TrackNewFlipCommand.cs @@ -18,7 +18,7 @@ public override async Task Execute(MessageData data) var request = new RestRequest("Tracker/newFlip/{auctionUUID}", Method.POST) .AddJsonBody(args) - .AddUrlSegment("auctionUUID", args.auctionUUID); + .AddUrlSegment("auctionUUID", args.AuctionUUID); await data.SendBack(new MessageData("newFlip", null)); } @@ -28,14 +28,20 @@ public override async Task Execute(MessageData data) public class Arguments { [Key("auctionUUID")] - public string auctionUUID; + public string AuctionUUID; [Key("targetPrice")] - public int targetPrice; + public int TargetPrice; [Key("finderType")] - public string finderType; - [Key("timestamp")] - public DateTime timestamp; + public FinderType FinderType; } + + public enum FinderType + { + FLIPPER = 1, + LOWEST_BIN = 2, + SNIPER = 4, + KI = 8 + } } } From 088e9176b6daa0354600016b3cae3fc7cfca0108 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Sat, 6 Nov 2021 00:45:39 +0100 Subject: [PATCH 4/5] cr --- Commands/Tracker/TrackFlipEventCommand.cs | 3 +- Commands/Tracker/TrackNewFlipCommand.cs | 5 +- appsettings.json | 107 +++++++++++----------- 3 files changed, 60 insertions(+), 55 deletions(-) diff --git a/Commands/Tracker/TrackFlipEventCommand.cs b/Commands/Tracker/TrackFlipEventCommand.cs index 41e4053..293162e 100644 --- a/Commands/Tracker/TrackFlipEventCommand.cs +++ b/Commands/Tracker/TrackFlipEventCommand.cs @@ -13,12 +13,13 @@ public override async Task Execute(MessageData data) using (var context = new HypixelContext()) { var args = data.GetAs(); - var userId = data.UserId; var request = new RestRequest("Tracker/flipEvent/{auctionUUID}", Method.POST) .AddJsonBody(args) .AddUrlSegment("auctionUUID", args.AuctionUUID); + var response = await TrackerClient.Client.ExecuteAsync(request); + await data.SendBack(new MessageData("flipEvent", null)); } } diff --git a/Commands/Tracker/TrackNewFlipCommand.cs b/Commands/Tracker/TrackNewFlipCommand.cs index 520d4ec..6cfdf54 100644 --- a/Commands/Tracker/TrackNewFlipCommand.cs +++ b/Commands/Tracker/TrackNewFlipCommand.cs @@ -14,12 +14,13 @@ public override async Task Execute(MessageData data) using (var context = new HypixelContext()) { var args = data.GetAs(); - var userId = data.UserId; var request = new RestRequest("Tracker/newFlip/{auctionUUID}", Method.POST) .AddJsonBody(args) .AddUrlSegment("auctionUUID", args.AuctionUUID); + var response = await TrackerClient.Client.ExecuteAsync(request); + await data.SendBack(new MessageData("newFlip", null)); } } @@ -41,7 +42,7 @@ public enum FinderType FLIPPER = 1, LOWEST_BIN = 2, SNIPER = 4, - KI = 8 + AI = 8 } } } diff --git a/appsettings.json b/appsettings.json index 9c21daa..37abf7d 100644 --- a/appsettings.json +++ b/appsettings.json @@ -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 - } - ] - } } \ No newline at end of file From 2bcbcac2bffc24fc71b984861905c56c8e8d54e3 Mon Sep 17 00:00:00 2001 From: Matthias Luger Date: Sat, 6 Nov 2021 04:26:59 +0100 Subject: [PATCH 5/5] click command --- Commands/Minecraft/ClickedCommand.cs | 41 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Commands/Minecraft/ClickedCommand.cs b/Commands/Minecraft/ClickedCommand.cs index a1d97aa..0ecfc97 100644 --- a/Commands/Minecraft/ClickedCommand.cs +++ b/Commands/Minecraft/ClickedCommand.cs @@ -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(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 } } } \ No newline at end of file