|
| 1 | +/* |
| 2 | + * PROJECT: Cult of the Lamb Multiplayer Mod |
| 3 | + * LICENSE: MIT (https://spdx.org/licenses/MIT) |
| 4 | + * PURPOSE: Define the network class |
| 5 | + * COPYRIGHT: Copyright 2025 Neco-Arc <[email protected]> |
| 6 | + */ |
| 7 | + |
| 8 | +/* IMPORTS ********************************************************************/ |
| 9 | + |
| 10 | +using COTLMP.Ui; |
| 11 | +using UnityEngine; |
| 12 | +using UnityEngine.SceneManagement; |
| 13 | + |
| 14 | +/* CLASSES & CODE *************************************************************/ |
| 15 | + |
| 16 | +/** |
| 17 | + * @brief |
| 18 | + * The namespace for all network-related classes, enums and structs |
| 19 | + */ |
| 20 | +namespace COTLMP.Network |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @brief |
| 24 | + * The main class for network features |
| 25 | + */ |
| 26 | + internal class Network |
| 27 | + { |
| 28 | + /** |
| 29 | + * @brief |
| 30 | + * If the scene loaded is main menu, stop the integrated server |
| 31 | + * |
| 32 | + * @param[in] scene |
| 33 | + * The scene |
| 34 | + * |
| 35 | + * @param[in] _ |
| 36 | + * The scene load mode, unused |
| 37 | + */ |
| 38 | + private static void OnSceneLoaded(Scene scene, LoadSceneMode _) |
| 39 | + { |
| 40 | + if (scene.name.Equals("Main Menu")) |
| 41 | + { |
| 42 | + // set the quitting flag temporarily so it doesn't try to transition to the main menu on server stop |
| 43 | + PauseMenuPatches.Quitting = true; |
| 44 | + PauseMenuPatches.Server?.Dispose(); |
| 45 | + PauseMenuPatches.Quitting = false; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @brief |
| 51 | + * On game quitting, stop the integrated server |
| 52 | + */ |
| 53 | + private static void OnQuitting() |
| 54 | + { |
| 55 | + PauseMenuPatches.Quitting = true; |
| 56 | + PauseMenuPatches.Server?.Dispose(); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @brief |
| 61 | + * Initialize the network components |
| 62 | + */ |
| 63 | + public static void Initialize() |
| 64 | + { |
| 65 | + SceneManager.sceneLoaded += OnSceneLoaded; |
| 66 | + Application.quitting += OnQuitting; |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +/* EOF */ |
0 commit comments