-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from nexus4880/item-events
Item events and router restructuring
- Loading branch information
Showing
57 changed files
with
989 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Fuyu.Backend.EFT.DTO.Items | ||
{ | ||
public enum EItemRotation | ||
{ | ||
Horizontal, | ||
Vertical | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using Fuyu.Backend.BSG.ItemEvents.Models; | ||
|
||
namespace Fuyu.Backend.BSG.DTO.Responses | ||
{ | ||
[DataContract] | ||
public class ItemEventResponse | ||
{ | ||
[DataMember(Name = "profileChanges")] | ||
public Dictionary<string, ProfileChange> ProfileChanges { get; set; } = []; | ||
|
||
[DataMember(Name = "warnings")] | ||
public InventoryWarning[] InventoryWarnings = []; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Fuyu.Backend.BSG/ItemEvents/Controllers/IItemEventController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Fuyu.Common.Networking; | ||
|
||
namespace Fuyu.Backend.BSG.ItemEvents.Controllers | ||
{ | ||
public interface IItemEventController : IRouterController<ItemEventContext> | ||
{ | ||
public string Action { get; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Fuyu.Backend.BSG/ItemEvents/Controllers/ItemEventController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Fuyu.Backend.BSG.ItemEvents.Models; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fuyu.Backend.BSG.ItemEvents.Controllers | ||
{ | ||
public abstract class ItemEventController<TEvent> : IItemEventController where TEvent : BaseItemEvent | ||
{ | ||
public string Action { get; private set; } | ||
|
||
public ItemEventController(string action) | ||
{ | ||
Action = action; | ||
} | ||
|
||
public virtual bool IsMatch(ItemEventContext context) | ||
{ | ||
return context.Action == Action; | ||
} | ||
|
||
public Task RunAsync(ItemEventContext context) | ||
{ | ||
return RunAsync(context, context.GetData<TEvent>()); | ||
} | ||
|
||
public abstract Task RunAsync(ItemEventContext context, TEvent request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Fuyu.Backend.BSG.DTO.Responses; | ||
using Fuyu.Common.Networking; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Fuyu.Backend.BSG.ItemEvents | ||
{ | ||
public class ItemEventContext : IRouterContext | ||
{ | ||
public string SessionId { get; } | ||
public string Action { get; } | ||
public JToken Data { get; } | ||
public ItemEventResponse Response { get; } | ||
|
||
public ItemEventContext(string sessionId, string action, JToken data, ItemEventResponse response) | ||
{ | ||
SessionId = sessionId; | ||
Action = action; | ||
Data = data; | ||
Response = response; | ||
} | ||
|
||
public T GetData<T>() | ||
{ | ||
return Data.ToObject<T>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Fuyu.Backend.BSG.ItemEvents.Controllers; | ||
using Fuyu.Common.Networking; | ||
|
||
namespace Fuyu.Backend.BSG.ItemEvents | ||
{ | ||
public class ItemEventRouter : Router<IItemEventController, ItemEventContext> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.ItemEvents.Models | ||
{ | ||
[DataContract] | ||
public class BaseItemEvent | ||
{ | ||
[DataMember(Name = "Action")] | ||
public string Action { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.ItemEvents.Models | ||
{ | ||
[DataContract] | ||
public class InventoryWarning | ||
{ | ||
[DataMember(Name = "index")] | ||
public int RequestIndex { get; set; } | ||
|
||
[DataMember(Name = "errmsg")] | ||
public string ErrorMessage { get; set; } | ||
|
||
[DataMember(Name = "code")] | ||
public string ErrorCode { get; set; } | ||
|
||
[DataMember(Name = "data")] | ||
public object Data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Fuyu.Backend.BSG.ItemEvents.Models | ||
{ | ||
[DataContract] | ||
public class ProfileChange | ||
{ | ||
[DataMember(Name = "experience")] | ||
public int Experience; | ||
|
||
[DataMember(Name = "recipeUnlocked")] | ||
public Dictionary<string, bool> UnlockedRecipes = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Fuyu.Backend.EFT/Controllers/ClientGameProfileItemsMoving.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Fuyu.Backend.BSG.DTO.Responses; | ||
using Fuyu.Backend.BSG.ItemEvents; | ||
using Fuyu.Backend.EFT.ItemEvents.Controllers; | ||
using Fuyu.Common.Networking; | ||
using Fuyu.Common.Serialization; | ||
using Newtonsoft.Json.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fuyu.Backend.EFT.Controllers | ||
{ | ||
public class ClientGameProfileItemsMoving : HttpController | ||
{ | ||
private ItemEventRouter _router = new ItemEventRouter(); | ||
|
||
public ClientGameProfileItemsMoving() : base("/client/game/profile/items/moving") | ||
{ | ||
_router.AddController<CustomizationBuyEventController>(); | ||
_router.AddController<EatItemEventController>(); | ||
_router.AddController<InsureEventController>(); | ||
_router.AddController<InterGameTransferEventController>(); | ||
_router.AddController<MoveItemEventController>(); | ||
_router.AddController<ReadEncyclopediaEventController>(); | ||
_router.AddController<SellAllFromSavageEventController>(); | ||
_router.AddController<TraderRepairEventController>(); | ||
_router.AddController<TradingConfirmEventController>(); | ||
_router.AddController<ApplyInventoryChangesItemEventController>(); | ||
} | ||
|
||
public override async Task RunAsync(HttpContext context) | ||
{ | ||
var sessionId = context.GetSessionId(); | ||
var requestText = await context.GetTextAsync(); | ||
var requestObject = JObject.Parse(requestText); | ||
var requestData = requestObject.Value<JArray>("data"); | ||
var response = new ItemEventResponse | ||
{ | ||
ProfileChanges = [], | ||
InventoryWarnings = [] | ||
}; | ||
|
||
foreach (var itemRequest in requestData) | ||
{ | ||
var action = itemRequest.Value<string>("Action"); | ||
var itemEventContext = new ItemEventContext(sessionId, action, itemRequest, response); | ||
await _router.RouteAsync(itemEventContext); | ||
} | ||
|
||
await context.SendJsonAsync(Json.Stringify(new ResponseBody<ItemEventResponse> | ||
{ | ||
data = response | ||
})); | ||
} | ||
} | ||
} |
Oops, something went wrong.