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

Project restructure #28

Merged
merged 18 commits into from
Sep 7, 2024
Merged

Conversation

seionmoya
Copy link
Collaborator

@seionmoya seionmoya commented Sep 6, 2024

This is one huge PR.

Overview

While working on implementing Arena, I noticed that the project structure was ill-suited for handling multiple games + core backend. This is why the solution underwent significant restructuring.

Solution restructuring

In discussion with @nexus4880, all struct types (except MongoId) have been changed to class.
To reflect that these classes should not contain any methods, the namespace X.Models.X has been modified to X.DTO.X.

In discussion with @nexus4880, all FuyuBehaviour types have been renamed to FuyuController and use the Controller suffix to signify use.

In discussion with @Lacyway, Fuyu.Server.X has been renamed to Fuyu.Backend.X to better reflect it's use-case.

  • Fuyu.Backend: the backend application
  • Fuyu.Backend.Arena: all arena backend code
  • Fuyu.Backend.BSG: code shared among BSG games
  • Fuyu.Backend.Common: code shared among all backends
  • Fuyu.Backend.Core: Fuyu's backend (account handling mostly)
  • Fuyu.Backend.EFT: all EFT backend code
  • Fuyu.Common: a library with useful utilities and wrappers
  • Fuyu.Launcher: the launcher application
  • Fuyu.Launcher.Core: reusable launcher code (for if others want to make their own launcher)
  • Fuyu.Plugin.Arena: minimal patchset required to get into arena in offline mode
  • Fuyu.Plugin.Common: code shared among all plugins
  • Fuyu.Plugin.EFT: minimal patchset required to get into EFT in offline mode
  • Fuyu.Test.Backend.Arena: CI/CD validation for Fuyu.Backend.Arena
  • Fuyu.Test.Backend.Arena: CI/CD validation for Fuyu.Backend.Core
  • Fuyu.Test.Backend.Arena: CI/CD validation for Fuyu.Backend.EFT
  • Fuyu.Test.Common: CI/CD validation for Fuyu.Common
  • Zlib.Managed: a modified zlib library with EFT specific tweaks

Account system

Fuyu now has multiple account types;

  • Fuyu.Backend.Core.DTO.Account is Fuyu's main account. This contains login information and which games are registered to an account. A registered game can have multiple game accounts registered to it.
  • Fuyu.Backend.EFT.DTO.Account and Fuyu.Backend.Arena.DTO.Account are game accounts. These have save(s) bound to them bind to them (EFT has PvP and PvE, Arena has PvP).

Fuyu's main account and game accounts have separate AccountIds to prevent outside access to login information. A game account can never reach a Fuyu main account, but a Fuyu main account can reach a game account.

TL;DR: A safe way to support multiple games on the main account, with multiple game account slots per game.

While I understand that this system is complete overkill, I believe it's beneficial to make it adaptable for other games in the future.

Database and ORM

Each server has now a single Database and a single ORM. The Database contains all tables and has methods to load these tables. The ORM should be used for any access and modification to the database.

Modders can override the ORM's methods using HarmonyX to bind their own source.

This implementation is beneficial as it's easily tracable which database tables are being accessed and modified, as well as easier to deal with in IntelliSense (providing contextual names like languageId or CustomizationTemplate instead of Dictionary<string, string>).

Wipe profiles

Thanks to the database rework, modders can now register their own wipe profile types.

Removal of WebSocketSharp

It is too restrictive for our use-case and hasn't been properly maintained. With research from @nexus4880, System.Net.HttpListener has now replaced the library. Each HTTP server now runs on it's own thread.

Removal of thread optimizations

While I love doing these, I think I should keep the current code first and foremost dead-simple to work with. These can happen later when hot code loops have been identified.

Rationale

While I understand it is not beneficial to have such a huge PR, it couldn't be avoided due to the lack of separation from concerns. I could've hold off some naming changes like HttpBehaviour to HttpController, but it wouldn't have mattered due to everything being touched regardless.

I really hope I only have to break things once this way, it hasn't been fun to rework it all. It simply was too much. But I rather do it now while the codebase is relatively small than later.

Notes

While the tests succeed, the project cannot actually reach the main menu. I really need someone to step in and fix it as I've simply stared too long at the code. The issue occurs when reaching /client/game/profile/list (KeyNotFoundException). I assume that the sessionId is not properly registered into EftDatabase.Sessions.

Despite the PR not working, I want to get this merged so others can resume their work and can look into fixing the issue.

The Arena project structure is there, I want to finalize the EFT setup first before making Arena bootable.

Discussion

Having EFT and Arena use different game account ids might lead into issues in the future. I have no idea how I want to solve the problem yet. Ideas are welcome!

In order for game registration to work properly, I had to use cross-server comminucation over HTTP (see Fuyu.Backend.Core.Services.AccountService.RegisterGame()). Suggestions for a better solution would be much appriciated!

I've shortcutted the game login in the launcher by making accountId always 0 (see Account.razor). Currently I would need to implement /account/get/game in order to obtain the accountId required to start the game. We might need to think of a more elegant solution for handling this. Feedback is much appriciated!

We should probably look into making HttpListener operate async on it's own thread in order to handle multiple requests on the same thread simultaniously.

Once this is merged and I can get it to work well enough, I want to get Arena to load first into the main menu and then work on implementing the websocket server over HttpListener. It seems pretty doable.

@seionmoya seionmoya added bug Something isn't working enhancement New feature or request labels Sep 6, 2024
@seionmoya seionmoya self-assigned this Sep 6, 2024
@seionmoya seionmoya added help wanted launcher Related to Fuyu.Launcher backend Related to Fuyu.Backend client Related to Fuyu.Client tests Related to Fuyu.Tests labels Sep 6, 2024
Lacyway
Lacyway previously approved these changes Sep 6, 2024
Copy link
Member

@Lacyway Lacyway left a comment

Choose a reason for hiding this comment

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

These changes look good to me and the naming makes more sense from a programming perspective as the backend handles the data, not actual (maybe minor) game logic. This will alleviate a lot of confusion that has stemmed from the naming in the past.
I also like the idea of trying a new library for the Websocket, excited to see where it leads.

@seionmoya
Copy link
Collaborator Author

At request of @nexus4880 in discord I've modified the ORM to use SetOrAddX instead of SetX and AddX.

@seionmoya seionmoya merged commit 7225b61 into project-fika:main Sep 7, 2024
1 check passed
@seionmoya seionmoya deleted the rework-project-structure branch September 7, 2024 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Related to Fuyu.Backend bug Something isn't working client Related to Fuyu.Client enhancement New feature or request launcher Related to Fuyu.Launcher tests Related to Fuyu.Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants