Skip to content

Commit

Permalink
added support for discord bot
Browse files Browse the repository at this point in the history
  • Loading branch information
RED1cat committed Apr 10, 2024
1 parent 81b4c5d commit c6f157f
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 269 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ Dedicated server for the [SkyCoop](https://github.com/Filigrani/SkyCoop) mod for
* `true` or `false`
* `SavingPeriod` - The period after which the server data will be saved.
* `RestartPerioud` - Unused or outdated.
## Configuring Server bot `botconfig`:
The server has the ability to send various notifications about its status at the expense of the discord bot.
* `token` - The bot's discord token.
* `infochannelid` - The ID of the channel where the server will send information about itself.
* `feedchannelid` - The ID of the channel where the server will send information about the connected players and statistics.
* `timetoupdatemessage` - The time in minutes after which the server information will be updated.
## Server Commands:
* `webhook` - It's unfinished at the moment.
* `webstats` - It's unfinished at the moment.
* `dsbot` - Sends a message via the bot's discord.
* `botstats` - Sends the current server statistics via the bot's discord.
* `crashsite` - Causes an airplane to crash in a random region.
* `whencrashsite` - Displays when the next plane crash or the statistics of the current one.
* `canclecrashsite` - Cancels the current crash site.
Expand Down
5 changes: 5 additions & 0 deletions SkyCoopDedicatedServer/ConsoleMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public void Initialize()
{
Task.Factory.StartNew(ReadConsole);
MyMod.Initialize();
Task.Run(DiscordManager.Init);

Timer timer1 = new Timer(EverySecond, null, 1000, 1000);
Timer timer2 = new Timer(EveryGameMinute, null, 5000, 5000);
Expand Down Expand Up @@ -62,13 +63,17 @@ private void EveryGameMinute(object obj)
private void DsSave(object obj)
{
MPSaveManager.SaveGlobalData();
DiscordManager.SaveConfig();
}
private void EveryMinute(object obj)
{
NetworkHelper.СheckingInternetConnection();
Task.Run(() => DiscordManager.ServerInfoUpdate(MyMod.CustomServerName, MyMod.PlayersOnServer, MyMod.MaxPlayers, $"{NetworkHelper.externalIp}:{NetworkHelper.port}", MyMod.BuildInfo.Version));
}
private void OnExiting()
{
Task task = Task.Run(() => DiscordManager.ServerInfoUpdate(MyMod.CustomServerName, MyMod.PlayersOnServer, MyMod.MaxPlayers, $"{NetworkHelper.externalIp}:{NetworkHelper.port}", MyMod.BuildInfo.Version, online: false));
while (!task.IsCompleted) { } //I know it's a terrible solution.
NetworkHelper.TryClosePort();
}
}
Expand Down
Loading

0 comments on commit c6f157f

Please sign in to comment.