mirror of
https://gitee.com/xiarenalofs/squad-rain-ops-mini.git
synced 2026-08-04 20:46:33 +08:00
60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using Microsoft.Extensions.Hosting;
|
|
using RainOpsMini.Helpers;
|
|
using RainOpsMini;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using RainOpsMini; // Ensure Program is visible
|
|
|
|
namespace RainOpsMini.Services
|
|
{
|
|
public class VipExpirationCheckService : BackgroundService
|
|
{
|
|
private readonly string _adminConfigPath;
|
|
|
|
public VipExpirationCheckService()
|
|
{
|
|
_adminConfigPath = Path.Combine(Directory.GetCurrentDirectory(), "SquadGame", "ServerConfig", "Admins.cfg");
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
RainOpsLog.Log("VIP Expiration Check Service started.");
|
|
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
{
|
|
try
|
|
{
|
|
// 1. Sync to Admin.cfg
|
|
// Ensure directory exists
|
|
Directory.CreateDirectory(Path.GetDirectoryName(_adminConfigPath)!);
|
|
|
|
if (!File.Exists(_adminConfigPath))
|
|
{
|
|
File.WriteAllText(_adminConfigPath, "// Created by RainOpsMini\n");
|
|
}
|
|
|
|
// This method filters out expired members when writing to the file
|
|
VipStorage.SyncToAdminConfig(_adminConfigPath);
|
|
|
|
// 2. Execute RCON command if connected
|
|
if (Program.Client != null && Program.Client.IsConnected)
|
|
{
|
|
// AdminReloadServerConfig reloads the admins.cfg file
|
|
await Program.Client.SendCommandAsync("AdminReloadServerConfig");
|
|
RainOpsLog.Log($"[VipCheck] Admin.cfg synced and reloaded at {DateTime.Now}");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RainOpsLog.Log($"[VipCheck] Error: {ex.Message}");
|
|
}
|
|
|
|
// Wait 10 minutes
|
|
await Task.Delay(TimeSpan.FromMinutes(10), stoppingToken);
|
|
}
|
|
}
|
|
}
|
|
}
|