GBSU/Addons/GBSUClient.cs
2025-07-14 23:31:20 +02:00

32 lines
1 KiB
C#

using GB.Core;
using GB.Networking.Utils;
using GB.Platform.Lobby;
using UnityEngine;
namespace GBSU.Addons;
public class GBSUClient : MonoBehaviour
{
public static void JoinServer(string serverip, int serverport)
{
if (!Helper.hosting)
{
LobbyManager.Instance.LobbyStates.IP = serverip;
LobbyManager.Instance.LobbyStates.Port = serverport;
LobbyManager.Instance.LobbyStates.CurrentState = LobbyState.State.Ready | LobbyState.State.InGame;
LobbyManager.Instance.LocalBeasts.SetupNetMemberContext(true);
MonoSingleton<Global>.Instance.UNetManager.LaunchClient(serverip, serverport);
}
else
{
GBSUGui.PushError("You are currently hosting a game! Please stop your server before attempting to join.");
}
}
// this method should be used when something has went wrong
// because players can just use the escape menu to exit
public static void DisconnectFromServer()
{
GBNetUtils.DisconnectSelf(false);
}
}