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

Add support for servers to periodically communicate with external services #3446

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

amoeba
Copy link
Contributor

@amoeba amoeba commented Feb 4, 2021

Hey all, I was talking about something I've built with @LtRipley36706 the other day and he thought other devs would be interested in seeing a PR so here it is:

It would be really interesting if ACE servers could communicate with external services. There's been a ton of discussion about how to do this, going back to #718. Providing an HTTP API is a really powerful idea but presents a ton of problems such as rate limiting, running read-only replicas of the database, and so on.

A lighter weight and simpler approach is to have ACE servers send any information to external services periodically. The biggest downside here is that the feature only works if the external service stays available.

What I've done here is created a new *Manager class called HeartbeatManager that based on code that already existed in ACE that sends a JSON payload to a configurable HTTP endpoint at a configurable interval. Think webhook.

The immediate thing ACE servers could do with this is broadcast whether the server is up and how many players are online to services such as https://treestats.net. People are very interested in how many players are on each server but the TreeStats way of tracking server populations requires players on each server to run my Decal plugin. And even then, the temporal resolution of the population data depends on how many players are running the plugin. With my system here, ACE servers could send their OnlineCount to TreeStats at intervals and we'd all have much better data to look at.

Some notes:

  1. This PR isn't done, I'm having some issues figuring out default values in the config
  2. The payload is hardcoded to send WorldName and OnlineCount but I think we could find some easy way to let users configure the Manager to send more info such as any config properties (xp rate, pk/npk, etc) or even information obtained from database queries such as total characters.
  3. This type of approach could even be used to send webhooks to Discord servers, Google Sheets, etc
  4. I'm open to another name. Maybe even WebhookManager

What do you all think? I'm open to both thoughts on the concept as well as specific comments on the PR.

This is a prety simple *Manager class that can send periodic requests to another server as a form of heartbeat. This is generally useful and could be used by a server to report uptime, player info, and so on.

Not qutie finished yet here but this works for my testing.
This isn't quite working yet
@amoeba amoeba marked this pull request as draft February 4, 2021 06:19
@gmriggs
Copy link
Collaborator

gmriggs commented Feb 4, 2021

👍 to the idea for sure!

Maybe someone can ping @FlaggAC about this as well... he brought up a discussion a few weeks ago about integrating the rcon protocol

@amoeba
Copy link
Contributor Author

amoeba commented Feb 4, 2021

👍 to the idea for sure!

Maybe someone can ping @FlaggAC about this as well... he brought up a discussion a few weeks ago about integrating the rcon protocol

Interesting, @gmriggs. Thanks for the pointer. I hadn't heard about that work but that's really cool.

};

HttpContent content = new StringContent(JsonConvert.SerializeObject(body));
response = client.PostAsync(endpoint, content).Result;
Copy link

Choose a reason for hiding this comment

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

Accessing Result will block. Is it safe to do this on this thread?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought this was fine but can change if this is problematic. Thanks for catching this @enknamel

@FlaggAC
Copy link
Contributor

FlaggAC commented Feb 8, 2021

Hey yes I spoke with the owner of battlemetrics.com and it might be a good thing for any AC Servers that wish to opt in to this. It would show public chat history, player login history, etc. - You can get an idea by going to https://www.battlemetrics.com/subscription/rcon and seeing what it offers.

Feel free to ping me in Discord if you want to work together on this or on your own - the guy sent me info on how to get it completely set up.

@amoeba
Copy link
Contributor Author

amoeba commented Feb 9, 2021

That's a pretty neat service, @FlaggAC , thanks for the pointer. Gives me some ideas for things I could add onto TreeStats.

I definitely like the idea of implementing something like rcon that gives servers two-way messaging and remote control. That said, I also like the relatively small size of the change I'm proposing here and am probably willing to put more time into it since it's scratching my own itch.

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.

None yet

4 participants