mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
Tile服务器雏形..
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using JNGame.Network;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
@@ -9,14 +10,21 @@ namespace AppGame.Systems
|
||||
public class JNGClient : JNTCPClient
|
||||
{
|
||||
|
||||
private IPEndPoint _point;
|
||||
private string _point;
|
||||
private int _clientId;
|
||||
public int ClientId => _clientId;
|
||||
|
||||
public void SetPoint(IPEndPoint point)
|
||||
public void BindID(int clientId)
|
||||
{
|
||||
_clientId = clientId;
|
||||
}
|
||||
|
||||
public void SetPoint(string point)
|
||||
{
|
||||
_point = point;
|
||||
}
|
||||
|
||||
protected override async UniTask<IPEndPoint> GetEndPoint()
|
||||
protected override async UniTask<string> GetEndPoint()
|
||||
{
|
||||
await UniTask.NextFrame();
|
||||
return _point;
|
||||
@@ -27,12 +35,22 @@ namespace AppGame.Systems
|
||||
|
||||
//监听服务端事件
|
||||
AddListener((int)NActionEnum.NSyncStateDataUpdate,OnNSyncStateDataUpdate);
|
||||
AddListener((int)NActionEnum.ClientConnect,OnClientConnect);
|
||||
|
||||
//连接
|
||||
await base.OnInit();
|
||||
|
||||
}
|
||||
|
||||
private void OnClientConnect(byte[] obj)
|
||||
{
|
||||
//向服务器发送玩家Id
|
||||
Send((int)GActionEnum.BindClientID,new RClientIDMessage()
|
||||
{
|
||||
ClientId = ClientId
|
||||
});
|
||||
}
|
||||
|
||||
private void OnNSyncStateDataUpdate(byte[] data)
|
||||
{
|
||||
var info = JNStateItemData.Parser.ParseFrom(data);
|
||||
|
@@ -19,12 +19,8 @@ namespace AppGame.Systems
|
||||
|
||||
public override void AddClient(JNGClient client)
|
||||
{
|
||||
client.BindID(clientId);
|
||||
base.AddClient(client);
|
||||
//向服务器发送玩家Id
|
||||
client.Send((int)GActionEnum.BindClientID,new RClientIDMessage()
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ namespace AppGame.Systems
|
||||
private bool isInit = false;
|
||||
|
||||
//客户端绑定的Id
|
||||
private Dictionary<int, int> ids = new();
|
||||
private Dictionary<string, int> ids = new();
|
||||
|
||||
public override async Task OnInit()
|
||||
{
|
||||
@@ -80,9 +80,10 @@ namespace AppGame.Systems
|
||||
{
|
||||
var inputs = JNStateTileInputs.Parser.ParseFrom(args.Message);
|
||||
//只有绑定过ID 的客户端才可以执行操作
|
||||
if (!ids.ContainsKey(args.Client)) return;
|
||||
inputs.Message.Inputs.ForEach(child =>
|
||||
{
|
||||
child.ClientId = args.Client;
|
||||
child.ClientId = ids[args.Client];
|
||||
});
|
||||
App.Game.AddTileInput(inputs);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using JNGame.Network;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
@@ -9,14 +10,14 @@ namespace AppGame.Systems
|
||||
public class JNGTileClient : JNTCPClient
|
||||
{
|
||||
|
||||
private IPEndPoint _point;
|
||||
private string _point;
|
||||
|
||||
public void SetPoint(IPEndPoint point)
|
||||
public void SetPoint(string point)
|
||||
{
|
||||
_point = point;
|
||||
}
|
||||
|
||||
protected override async UniTask<IPEndPoint> GetEndPoint()
|
||||
protected override async UniTask<string> GetEndPoint()
|
||||
{
|
||||
await UniTask.NextFrame();
|
||||
return _point;
|
||||
|
Reference in New Issue
Block a user