feat: start/stop server handling
The original app volume is also restored when the server is stopped.
This commit is contained in:
parent
962bcaf199
commit
5eedbf2f1e
4 changed files with 35 additions and 7 deletions
|
|
@ -67,20 +67,14 @@ Set CLI arguments: -ip, -port (optionally -maplist)
|
||||||
{
|
{
|
||||||
if (File.Exists(Helper.GameConfigPath))
|
if (File.Exists(Helper.GameConfigPath))
|
||||||
{
|
{
|
||||||
Helper.hosting = true;
|
|
||||||
|
|
||||||
AudioListener.volume = 0; // mute game audio
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Plugin.AddServerComp(); // add custom GBSU server component
|
|
||||||
GBSUServer.StartServer();
|
GBSUServer.StartServer();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PushError("Looks like you've caught a bug! Please send your log file to us :)\n" + e);
|
PushError("Looks like you've caught a bug! Please send your log file to us :)\n" + e);
|
||||||
Helper.hosting = false;
|
GBSUServer.StopServer();
|
||||||
Plugin.DestroyServerComp();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -131,6 +125,13 @@ Make sure to download a file from the examples given and rename it to config.jso
|
||||||
{
|
{
|
||||||
Helper.FlipVSync();
|
Helper.FlipVSync();
|
||||||
}
|
}
|
||||||
|
if (Helper.hosting)
|
||||||
|
{
|
||||||
|
if (GUI.Button(new Rect(195f, 330f, 170f, 30f), "Stop server"))
|
||||||
|
{
|
||||||
|
GBSUServer.StopServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
GUI.Label(new Rect(20f, 365f, 365f, 400f), $@"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using GB.Core;
|
||||||
using GB.Game;
|
using GB.Game;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
#pragma warning disable IDE0051 // Private member is unused
|
#pragma warning disable IDE0051 // Private member is unused
|
||||||
|
|
||||||
|
|
@ -34,11 +35,33 @@ public class GBSUServer : MonoBehaviour
|
||||||
|
|
||||||
public static void StartServer()
|
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
|
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
|
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.LaunchServer(serverConfig); // launch the server with the server config
|
||||||
MonoSingleton<Global>.Instance.UNetManager.GetComponent<GameManagerNew>().ChangeRotationConfig(gameConfig, 0); // set server's rotationconfig
|
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()
|
public string GetRemainingRoundTime()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ public class Helper
|
||||||
public static string serverip = null;
|
public static string serverip = null;
|
||||||
public static int serverport = 5999;
|
public static int serverport = 5999;
|
||||||
public static bool hosting = false;
|
public static bool hosting = false;
|
||||||
|
public static float saved_volume;
|
||||||
public static void DisableAnalytics()
|
public static void DisableAnalytics()
|
||||||
{
|
{
|
||||||
// Try disabling analytics https://docs.unity3d.com/ScriptReference/Analytics.Analytics-deviceStatsEnabled.html
|
// Try disabling analytics https://docs.unity3d.com/ScriptReference/Analytics.Analytics-deviceStatsEnabled.html
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,9 @@ public class Plugin : BaseUnityPlugin
|
||||||
|
|
||||||
// "-maplist" CLI
|
// "-maplist" CLI
|
||||||
Helper.CheckCustomRotationPath();
|
Helper.CheckCustomRotationPath();
|
||||||
|
|
||||||
|
// store app volume in a variable to restore it if needed
|
||||||
|
Helper.saved_volume = AudioListener.volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void GBSUCompInit()
|
private static void GBSUCompInit()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue