feat: start/stop server handling

The original app volume is also restored when the server is stopped.
This commit is contained in:
anavoi 2025-07-13 23:47:40 +02:00
commit 5eedbf2f1e
4 changed files with 35 additions and 7 deletions

View file

@ -4,6 +4,7 @@ using GB.Core;
using GB.Game;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
#pragma warning disable IDE0051 // Private member is unused
@ -34,11 +35,33 @@ public class GBSUServer : MonoBehaviour
public static void StartServer()
{
Helper.hosting = true;
AudioListener.volume = 0; // mute game audio
Plugin.AddServerComp(); // add custom GBSU server component
RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig(null); // the argument doesn't matter as we do stuff in the method
ServerConfig serverConfig = NetConfigLoader.LoadServerConfig(); // load default server config, because it can be overridden by args like -ip and -port
MonoSingleton<Global>.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config
MonoSingleton<Global>.Instance.UNetManager.GetComponent<GameManagerNew>().ChangeRotationConfig(gameConfig, 0); // set server's rotationconfig
}
public static void StopServer()
{
// WIP: At the moment the only way to stop the server is to exit/kill the game
Helper.hosting = false;
AudioListener.volume = Helper.saved_volume; // restore volume
// stop network listener
MonoSingleton<Global>.Instance.UNetManager.StopServer();
// destroy GBSU server comp
Plugin.DestroyServerComp();
// go back to main menu
SceneManager.LoadScene("Menu");
}
/*
public string GetRemainingRoundTime()
{