mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交新概念 Tile从服务器
This commit is contained in:
11
JNFrame2/Assets/Scripts/AppGame/Systems/CServer/CServer.cs
Normal file
11
JNFrame2/Assets/Scripts/AppGame/Systems/CServer/CServer.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace AppGame.Systems.CServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户端角色
|
||||
/// </summary>
|
||||
public enum JNGClientRole : int
|
||||
{
|
||||
Player, //玩家
|
||||
SlaveServer //从服务器
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25def782de754dbfb15c0b04eaa50e66
|
||||
timeCreated: 1724642638
|
@@ -1,5 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Systems.CServer;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using JNGame.Network;
|
||||
@@ -57,10 +58,15 @@ namespace AppGame.Systems
|
||||
private void OnClientConnect(byte[] obj)
|
||||
{
|
||||
//向服务器发送玩家Id
|
||||
Send((int)GActionEnum.BindClientID,new RClientIDMessage()
|
||||
Send((int)GActionEnum.BindClientID,new GBindClientID()
|
||||
{
|
||||
ClientId = ClientId
|
||||
});
|
||||
//向服务器绑定角色
|
||||
Send((int)GActionEnum.BindClientRole,new GBindClientRole()
|
||||
{
|
||||
Role = (int)JNGClientRole.Player
|
||||
});
|
||||
//向服务器索要全量信息
|
||||
Send((int)NActionEnum.NSyncTileAllUpdate);
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using JNGame.Network;
|
||||
using Plugins.JNGame.Network;
|
||||
|
||||
namespace AppGame.Systems.CServer
|
||||
{
|
||||
public partial class JNGServer : JNTCPServer
|
||||
{
|
||||
|
||||
//客户端绑定的Id
|
||||
private Dictionary<string, int> ids = new();
|
||||
|
||||
//客户端角色
|
||||
private Dictionary<string, JNGClientRole> _roles = new();
|
||||
public Dictionary<string, JNGClientRole> Roles => _roles;
|
||||
|
||||
public void OnInit_Game()
|
||||
{
|
||||
|
||||
AddListener((int)GActionEnum.BindClientID,OnBindClientID);
|
||||
AddListener((int)GActionEnum.BindClientRole,OnBindClientRole);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定客户端Id
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnBindClientID(JNServerParam args)
|
||||
{
|
||||
var message = GBindClientID.Parser.ParseFrom(args.Message);
|
||||
ids[args.Client] = message.ClientId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定客户端角色
|
||||
/// </summary>
|
||||
private void OnBindClientRole(JNServerParam args)
|
||||
{
|
||||
|
||||
var message = GBindClientRole.Parser.ParseFrom(args.Message);
|
||||
_roles[args.Client] = (JNGClientRole)message.Role;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14c921a786654c3fb9bb74e0d0ba29bd
|
||||
timeCreated: 1724642902
|
@@ -1,28 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Sync;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Network;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.State.Tile;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
namespace AppGame.Systems
|
||||
namespace AppGame.Systems.CServer
|
||||
{
|
||||
public class JNGServer : JNTCPServer
|
||||
|
||||
public partial class JNGServer : JNTCPServer
|
||||
{
|
||||
|
||||
private int _index = 1;
|
||||
|
||||
private bool isInit = false;
|
||||
|
||||
//客户端绑定的Id
|
||||
private Dictionary<string, int> ids = new();
|
||||
|
||||
public override async Task OnInit()
|
||||
{
|
||||
@@ -33,7 +31,8 @@ namespace AppGame.Systems
|
||||
AddListener((int)NActionEnum.NSyncTileInput,OnNSyncTileInput);
|
||||
AddListener((int)NActionEnum.NSyncTileAllUpdate,OnNSyncTileAllUpdate);
|
||||
AddListener((int)NActionEnum.NSyncTileGetTileInfo,OnNSyncTileGetTileInfo);
|
||||
AddListener((int)GActionEnum.BindClientID,OnBindClientID);
|
||||
|
||||
OnInit_Game();
|
||||
|
||||
//连接
|
||||
await base.OnInit();
|
||||
@@ -49,18 +48,6 @@ namespace AppGame.Systems
|
||||
{
|
||||
return (await App.GAPI.NSyncTilePort).data;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 绑定客户端Id
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnBindClientID(JNServerParam args)
|
||||
{
|
||||
var message = RClientIDMessage.Parser.ParseFrom(args.Message);
|
||||
ids[args.Client] = message.ClientId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收帧数入
|
||||
@@ -100,13 +87,16 @@ namespace AppGame.Systems
|
||||
private void OnNSyncTileAllUpdate(JNServerParam args)
|
||||
{
|
||||
|
||||
if (App.Game.Server is not JNGTileServerSystem tileServer) return;
|
||||
if (App.Game.Server is not JNSSTileServerService tileServer) return;
|
||||
|
||||
var allData = new JNStateTileAllData();
|
||||
|
||||
allData.TId = tileServer.TID;
|
||||
allData.Data = new JNStateAllData();
|
||||
|
||||
//获取角色 根据角色 返回 全量数据
|
||||
Roles.TryGetValue(args.Client, out var role);
|
||||
|
||||
tileServer.GetSystems<ISTileDataSystem>().ForEach(data =>
|
||||
{
|
||||
|
||||
@@ -114,7 +104,22 @@ namespace AppGame.Systems
|
||||
allData.Data.Data.Add(item);
|
||||
|
||||
item.NetID = ((ISStateDataSystem)data).NetID;
|
||||
data.GetHostDataBytes().ForEach(keyValue =>
|
||||
|
||||
Dictionary<ulong, byte[]> byteData;
|
||||
switch (role)
|
||||
{
|
||||
case JNGClientRole.Player:
|
||||
byteData = data.GetHostDataBytes();
|
||||
break;
|
||||
case JNGClientRole.SlaveServer:
|
||||
byteData = data.GetHostDataBytesFilterSlave();
|
||||
break;
|
||||
default:
|
||||
byteData = new ();
|
||||
break;
|
||||
}
|
||||
|
||||
byteData.ForEach(keyValue =>
|
||||
{
|
||||
item.Messages[keyValue.Key] = new JNStateData() { Data = ByteString.CopyFrom(keyValue.Value) };
|
||||
});
|
||||
|
@@ -1,9 +1,8 @@
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Systems.CServer;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using JNGame.Network;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
namespace AppGame.Systems
|
||||
@@ -19,10 +18,24 @@ namespace AppGame.Systems
|
||||
private string _tileServer;
|
||||
public string TileServer => _tileServer;
|
||||
|
||||
private JNGClientRole _role;
|
||||
public JNGClientRole Role => _role;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置IP
|
||||
/// </summary>
|
||||
public void SetPoint(string point)
|
||||
{
|
||||
_point = point;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置角色
|
||||
/// </summary>
|
||||
public void SetRole(JNGClientRole role)
|
||||
{
|
||||
_role = role;
|
||||
}
|
||||
public void SetTileServer(string tileServer)
|
||||
{
|
||||
_tileServer = tileServer;
|
||||
@@ -49,6 +62,11 @@ namespace AppGame.Systems
|
||||
|
||||
private void OnClientConnect(byte[] obj)
|
||||
{
|
||||
//向服务器绑定角色
|
||||
Send((int)GActionEnum.BindClientRole,new GBindClientRole()
|
||||
{
|
||||
Role = (int)Role
|
||||
});
|
||||
//向服务器索要全量信息
|
||||
Send((int)NActionEnum.NSyncTileAllUpdate);
|
||||
}
|
||||
@@ -79,7 +97,7 @@ namespace AppGame.Systems
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 区块全量更新指定区块
|
||||
/// 获取指定区块状态
|
||||
/// </summary>
|
||||
public async Task<JNStateTileAllData> NSyncTileGetTileInfo(int index)
|
||||
{
|
||||
|
Reference in New Issue
Block a user