add OnStartHost and OnStopHost

This commit is contained in:
_nebula 2023-08-02 11:44:14 +01:00
parent e7160e709c
commit fb49c6e132
4 changed files with 34 additions and 0 deletions

View File

@ -69,6 +69,16 @@ public interface IQSBAPI
/// </summary>
UnityEvent<uint> OnPeerLeave();
/// <summary>
/// Invoked on the host when the server is first started.
/// </summary>
UnityEvent OnStartHost();
/// <summary>
/// Invoked on the host when the server is closed.
/// </summary>
UnityEvent OnStopHost();
/// <summary>
/// Sets some arbitrary data for a given player.
/// </summary>

View File

@ -69,6 +69,16 @@ public interface IQSBAPI
/// </summary>
UnityEvent<uint> OnPeerLeave();
/// <summary>
/// Invoked on the host when the server is first started.
/// </summary>
UnityEvent OnStartHost();
/// <summary>
/// Invoked on the host when the server is closed.
/// </summary>
UnityEvent OnStopHost();
/// <summary>
/// Sets some arbitrary data for a given player.
/// </summary>

View File

@ -32,6 +32,9 @@ public class QSBAPI : IQSBAPI
public UnityEvent<uint> OnPeerJoin() => QSBAPIEvents.OnPeerJoinEvent;
public UnityEvent<uint> OnPeerLeave() => QSBAPIEvents.OnPeerLeaveEvent;
public UnityEvent OnStartHost() => QSBAPIEvents.OnStartHostEvent;
public UnityEvent OnStopHost() => QSBAPIEvents.OnStopHostEvent;
public void SetCustomData<T>(uint playerId, string key, T data) => QSBPlayerManager.GetPlayer(playerId).SetCustomData(key, data);
public T GetCustomData<T>(uint playerId, string key) => QSBPlayerManager.GetPlayer(playerId).GetCustomData<T>(key);
@ -85,4 +88,7 @@ internal static class QSBAPIEvents
internal static PlayerEvent OnPeerJoinEvent = new();
internal static PlayerEvent OnPeerLeaveEvent = new();
internal static UnityEvent OnStartHostEvent = new();
internal static UnityEvent OnStopHostEvent = new();
}

View File

@ -36,6 +36,7 @@ using QSB.WorldSync;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using QSB.API;
using UnityEngine;
namespace QSB;
@ -402,8 +403,15 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
base.OnServerDisconnect(conn);
}
public override void OnStartServer()
{
QSBAPIEvents.OnStartHostEvent.Invoke();
base.OnStartServer();
}
public override void OnStopServer()
{
QSBAPIEvents.OnStopHostEvent.Invoke();
DebugLog.DebugWrite("OnStopServer", MessageType.Info);
Destroy(GetComponent<RespawnOnDeath>());
DebugLog.ToConsole("Server stopped!", MessageType.Info);