Skip to content

Commit

Permalink
Sync Loop
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyTech6 committed Nov 22, 2024
1 parent 9ddce4b commit 667f4c6
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Structs/Database.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using CrimsonBanned.Services;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using UnityEngine;

namespace CrimsonBanned.Structs;

Expand All @@ -30,7 +33,7 @@ public Database()
LoadDatabases();
}

private static async void LoadDatabases()
private static void LoadDatabases()
{
if (!Directory.Exists(Plugin.ConfigFiles)) { Directory.CreateDirectory(Plugin.ConfigFiles); }

Expand Down Expand Up @@ -67,13 +70,17 @@ private static async void LoadDatabases()
StartSQLConnection();
}

private static void StartSQLConnection()
private static async void StartSQLConnection()
{
if (!Settings.MySQLConfigured) return;

SQL = new();
SQL.Connect();
SQL.InitializeTables();
await Task.Yield();
SyncDB();

Core.StartCoroutine(SyncLoop());
}

public static void AddBan(Ban ban, List<Ban> list)
Expand Down Expand Up @@ -141,8 +148,6 @@ private static void SaveDatabases()

public static void SyncDB()
{
DataTable ChatDB = SQL.GetBans("Chat");

SyncTable(ChatBans, "Chat");
SyncTable(VoiceBans, "Voice");
SyncTable(Banned, "Banned");
Expand All @@ -166,4 +171,13 @@ private static void SyncTable(List<Ban> list, string tableName)
}
}
}

static IEnumerator SyncLoop()
{
while (true)
{
yield return new WaitForSeconds(3600);
SyncDB();
}
}
}

0 comments on commit 667f4c6

Please sign in to comment.