40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
![]() |
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using BITKit;
|
||
|
using Net.Server;
|
||
|
|
||
|
namespace BITFALL
|
||
|
{
|
||
|
public class HostServer:ServerBase<NetPlayer,NetScene<NetPlayer>>{}
|
||
|
public class HostService : MonoBehaviour
|
||
|
{
|
||
|
public static event Action OnStartHost;
|
||
|
public static event Action OnStopHost;
|
||
|
private static readonly List<object> RPCHandles = new();
|
||
|
public static void AddRpcHandle(object handle) => RPCHandles.Add(handle);
|
||
|
public static void RemoveRpcHandle(object handle) => RPCHandles.Remove(handle);
|
||
|
private HostServer server;
|
||
|
public bool StartHost(ushort port)
|
||
|
{
|
||
|
if (server is not null && server.IsRunServer) return false;
|
||
|
server ??= new HostServer();
|
||
|
server.Start(port);
|
||
|
foreach (var x in RPCHandles)
|
||
|
{
|
||
|
server.AddRpcHandle(x);
|
||
|
}
|
||
|
OnStartHost?.Invoke();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public bool StopHost()
|
||
|
{
|
||
|
if (server is null || server.IsRunServer is false) return false;
|
||
|
server.Close();
|
||
|
OnStopHost?.Invoke();
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|