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

feat: Scripted Chat Commands #675

Merged
merged 2 commits into from
Jan 2, 2025

Conversation

pacampbell
Copy link
Collaborator

  • Created a new scripting module to handle chat commands.
  • Migrated all existing chat commands to scripted chat commands.
  • Updated the help command to only list commands which fall within the AccountState limitations.
  • Updated many chat commands to have an account state of type Admin.
  • Added a new settings file ChatCommands.csx.
  • Support hotloading of modifying or adding new chat commands.

Checklist:

  • The project compiles
  • The PR targets develop branch

Copy link
Collaborator

@alborrajo alborrajo left a comment

Choose a reason for hiding this comment

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

Very good PR, nice job. Although i was thinking that we were avoiding exposing DdonGameServer and such directly in these scripts, using LibDdon as a proxy instead


public class ChatCommand : IChatCommand
{
public override AccountStateType AccountState => AccountStateType.Admin;
Copy link
Collaborator

Choose a reason for hiding this comment

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

heh

@pacampbell
Copy link
Collaborator Author

pacampbell commented Dec 31, 2024

Very good PR, nice job. Although i was thinking that we were avoiding exposing DdonGameServer and such directly in these scripts, using LibDdon as a proxy instead

Ideally we would probably want that but some things definitely need some refactoring to support that. This was mostly just a migrate what's there change. Almost everything is built around accessing directly through our server object. It's hard to get around that pattern unfortunately.

I should probably take some time to access settings through LibDdon. Not sure what to do about the objects that require the server though.


public override void Execute(DdonGameServer server, string[] command, GameClient client, ChatMessage message, List<ChatResponse> responses)
{
var handler = new ChatCommandHandler(server);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that this command is used often, but do we need to be careful invoking a new copy of this object every time? Not sure if script stuff changes this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's wasteful from a resource perspective, but also this is a debug command, so I am not super worried about it. I was thinking making LibDdon can make a cached set or something? One thing I am having trouble with is that since I made it such that implementation is shared across the Server and DdonGameServer projects, I am having trouble to get the server into the area where the constructor is passed. I can take another look or see if we can do something in the library instead.

}

sb.Append($"Weather:{server.WeatherManager.GetWeather()} ({weatherIndex}) ");
sb.Append($"{remainingSeconds}/{server.WeatherManager.WeatherLoopList[weatherIndex].TimeSec} seconds");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The moon information got added to this command a little bit ago, should be included here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you share which information you want? This is just a copy+paste of the command that existed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was confused, it was apparently this commit that somehow ended up in my area ranks branch. 949a6d7

- Created a new scripting module to handle chat commands.
- Migrated all existing chat commands to scripted chat commands.
- Updated the help command to only list commands which fall within the
  AccountState limitations.
- Updated many chat commands to have an account state of type Admin.
- Added a new settings file ChatCommands.csx.
- Support hotloading of modifying or adding new chat commands.
- Rename motherload.csx to motherlode.csx
- Added two new helper methods to LibDdon
  - LibDdon.GetSetting<t>(scriptName, key);
  - LibDdon.GetHandler<t>();
@pacampbell pacampbell merged commit db8d31c into sebastian-heinz:develop Jan 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants