更新了网络服务接口定义
This commit is contained in:
@@ -1,32 +1,134 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
#if UNITY
|
||||
using UnityEngine;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 该接口为基础的网络接口,包括了网络服务,服务端接口,客户端接口的基本定义 e.g.
|
||||
* ⭐INetProvider 网络服务接口的基本定义
|
||||
* ⭐INetServer 服务端接口的基本定义
|
||||
* ⭐INetClient 客户端接口的基本定义
|
||||
*/
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit
|
||||
{
|
||||
/// <summary>
|
||||
/// 网络提供服务,包括了基础网络服务,e.g
|
||||
/// ⭐向服务器发送指令
|
||||
/// ⭐向所有客户端发送指令
|
||||
/// ⭐向单个客户端发送指令
|
||||
/// ⭐监听与取消监听网络命令
|
||||
/// ⭐从服务器获取数据
|
||||
/// ⭐从客户端获取数据
|
||||
/// ⭐添加Rpc处理服务
|
||||
/// ⭐向服务器发送Rpc
|
||||
/// ⭐向所有客户端发送Rpc
|
||||
/// </summary>
|
||||
public interface INetProvider
|
||||
{
|
||||
void ServerRpc(Action<string> action, params object[] pars);
|
||||
void ServerRpc(Action<object> action, params object[] pars);
|
||||
/// <summary>
|
||||
/// 向服务端发送指令
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
void ServerCommand<T>();
|
||||
/// <summary>
|
||||
/// 向所有客户端发送指令
|
||||
/// </summary>
|
||||
/// <typeparam name="T">远程指令类型</typeparam>
|
||||
void RpcClientCommand<T>();
|
||||
/// <summary>
|
||||
/// 向单个客户端发送指令
|
||||
/// </summary>
|
||||
/// <param name="id">客户端ID</param>
|
||||
/// <typeparam name="T">远程指令类型</typeparam>
|
||||
void ClientCommand<T>(int id);
|
||||
/// <summary>
|
||||
/// 从服务端获取数据
|
||||
/// </summary>
|
||||
/// <param name="addressablePath">可寻址路劲 e.g. Key</param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
UniTask<T> GetFromServer<T>(string addressablePath=Constant.System.Internal);
|
||||
/// <summary>
|
||||
/// 从客户端获取数据
|
||||
/// </summary>
|
||||
/// <param name="id">客户端ID</param>
|
||||
/// <param name="addressablePath">可寻址路劲 e.g. Key</param>
|
||||
/// <typeparam name="T">远程指令类型</typeparam>
|
||||
/// <returns></returns>
|
||||
UniTask<T> GetFromClient<T>(int id,string addressablePath=Constant.System.Internal);
|
||||
/// <summary>
|
||||
/// 添加RPC远程服务,服务类型为需要的方法标记[RPC]
|
||||
/// </summary>
|
||||
/// <param name="rpcHandle">RPC服务实例</param>
|
||||
void AddRpcHandle(object rpcHandle);
|
||||
/// <summary>
|
||||
/// 监听远程指令
|
||||
/// </summary>
|
||||
/// <param name="handle">远程指令回调</param>
|
||||
/// <typeparam name="T">远程指令类型</typeparam>
|
||||
void AddCommandListener<T>(Action<T> handle);
|
||||
/// <summary>
|
||||
/// 取消监听远程指令
|
||||
/// </summary>
|
||||
/// <param name="handle">远程指令回调</param>
|
||||
/// <typeparam name="T">远程指令类型</typeparam>
|
||||
void RemoveCommandListener<T>(Action<T> handle);
|
||||
/// <summary>
|
||||
/// 向服务端发送Rpc
|
||||
/// </summary>
|
||||
/// <param name="rpcName">RPC名称</param>
|
||||
/// <param name="pars">RPC参数</param>
|
||||
void SendRT(string rpcName, params object[] pars);
|
||||
/// <summary>
|
||||
/// 向指定客户端发送Rpc
|
||||
/// </summary>
|
||||
/// <param name="id">远程客户端Id</param>
|
||||
/// <param name="rpcName">RPC名称</param>
|
||||
/// <param name="pars">RPC参数</param>
|
||||
void SendTargetRT(int id, string rpcName, params object[] pars);
|
||||
/// <summary>
|
||||
/// 向所有客户端发送Rpc
|
||||
/// </summary>
|
||||
/// <param name="rpcName">RPC名称</param>
|
||||
/// <param name="pars">RPC参数</param>
|
||||
void SendAllRT(string rpcName, params object[] pars);
|
||||
#if UNITY
|
||||
void ServerRpc(Action<UnityEngine.Object> action, params object[] pars);
|
||||
void ClientRpc(Action<UnityEngine.Object> action, params object[] pars);
|
||||
void ServerRpc(Action<UnityEngine.GameObject> action, params object[] pars);
|
||||
void ClientRpc(Action<UnityEngine.GameObject> action, params object[] pars);
|
||||
#endif
|
||||
|
||||
////void ServerRpc<T>(Action<T> action,params object[] pars);
|
||||
}
|
||||
/// <summary>
|
||||
/// 服务端接口,支持服务端的基本功能
|
||||
/// ⭐开启服务器(支持指定端口)
|
||||
/// ⭐停止服务器
|
||||
/// ⭐服务器运行状态
|
||||
/// </summary>
|
||||
public interface INetServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 回调:当客户端连接时
|
||||
/// </summary>
|
||||
public event Action<int> OnClientConnect;
|
||||
/// <summary>
|
||||
/// 回调:当客户端断开连接时
|
||||
/// </summary>
|
||||
public event Action<int> OnClientDisconnected;
|
||||
/// <summary>
|
||||
/// 运行服务端
|
||||
/// </summary>
|
||||
/// <param name="port">端口,默认为27014</param>
|
||||
void StartServer(ushort port = 27014);
|
||||
void StopServer();
|
||||
/// <summary>
|
||||
/// 停止服务端
|
||||
/// </summary>
|
||||
/// <param name="dispose">可选参数:强行释放,默认为false</param>
|
||||
void StopServer(bool dispose);
|
||||
/// <summary>
|
||||
/// (只读)服务器是否正在运行
|
||||
/// </summary>
|
||||
bool IsRunningServer { get; }
|
||||
}
|
||||
|
||||
public interface INetClient
|
||||
{
|
||||
public event Action OnConnected;
|
||||
public event Action OnDisconnected;
|
||||
public event Action OnConnectedFailed;
|
||||
UniTask<bool> Connect(string address="localhost",ushort port=27014);
|
||||
bool IsConnected { get; }
|
||||
int Ping { get; }
|
||||
void Disconnect();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user