mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交bug 艰难先这样
This commit is contained in:
@@ -28,6 +28,8 @@ namespace AppGame.Sync
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
|
||||
|
||||
base.Initialize();
|
||||
//默认玩家位置
|
||||
SetPlayerPosition(LVector3.Zero);
|
||||
@@ -174,6 +176,7 @@ namespace AppGame.Sync
|
||||
if (info is not null)
|
||||
{
|
||||
client.SetPoint($"{info.ip}:{info.port}");
|
||||
client.SetTileServer(info.server);
|
||||
|
||||
if (IsTileConnect(index))
|
||||
{
|
||||
@@ -194,8 +197,27 @@ namespace AppGame.Sync
|
||||
{
|
||||
Debug.Log($"[{index}] 卸载 Socket");
|
||||
App.Client.RemoveClient(client);
|
||||
//并且释放数据
|
||||
GetSystems<ISTileDataSystem>().ForEach(data =>
|
||||
{
|
||||
data.ClearTileData(index);
|
||||
});
|
||||
}
|
||||
Sockets.Remove(index);
|
||||
}
|
||||
public void RemoveSocket(string server)
|
||||
{
|
||||
Sockets.ToArray().ForEach(tile =>
|
||||
{
|
||||
if (tile.Value.TileServer != server) return;
|
||||
tile.Value.OnClose();
|
||||
Sockets.Remove(tile.Key);
|
||||
//并且释放数据
|
||||
GetSystems<ISTileDataSystem>().ForEach(data =>
|
||||
{
|
||||
data.ClearTileData(tile.Key);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -39,6 +39,9 @@ namespace AppGame.Sync
|
||||
//区块Socket
|
||||
public Dictionary<int, JNGTileClient> Sockets = new ();
|
||||
|
||||
//是否开始前尝试连接周围区块去恢复历史数据
|
||||
public bool isRecover = true;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化服务器
|
||||
/// </summary>
|
||||
@@ -47,6 +50,48 @@ namespace AppGame.Sync
|
||||
{
|
||||
|
||||
await base.OnInit();
|
||||
|
||||
if (isRecover)
|
||||
{
|
||||
|
||||
List<int> tileIds = GetTileGridIndex(TID);
|
||||
foreach (var tileId in tileIds)
|
||||
{
|
||||
var client = await AddSocket(tileId);
|
||||
if (client is null) continue;
|
||||
|
||||
//连接到附近区块 开始 恢复数据
|
||||
Debug.Log($"[JNGTileServerSystem] 连接到附近区块{tileId} 开始 恢复数据");
|
||||
var tileInfo = await client.NSyncTileGetTileInfo(TID);
|
||||
if (tileInfo is not null)
|
||||
{
|
||||
Debug.Log("[JNGTileServerSystem] 获取到恢复数据成功 正在恢复数据");
|
||||
|
||||
var message = new Dictionary<long, byte[]>();
|
||||
tileInfo.Data.Data.ForEach(frame =>
|
||||
{
|
||||
message.Clear();
|
||||
foreach (var data in frame.Messages)
|
||||
{
|
||||
message.Add(data.Key,data.Value.Data.ToByteArray());
|
||||
}
|
||||
GetSystems<ISStateDataSystem>().ForEach(child =>
|
||||
{
|
||||
if (child.NetID != frame.NetID) return;
|
||||
child.OnInsertUBytes(message);
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[JNGTileServerSystem] 获取到恢复数据失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Debug.Log("[JNGTileServerSystem] 恢复数据结束");
|
||||
|
||||
}
|
||||
|
||||
//添加Tile服务器
|
||||
App.Business.Send((int)NActionEnum.NAddTileServer,new JNAddTileServer()
|
||||
@@ -60,7 +105,7 @@ namespace AppGame.Sync
|
||||
Timers.Instance.SetInterval(1f, UpdateTileSocket);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override SLogicSystem[] NewLogicSystems()
|
||||
{
|
||||
return new SLogicSystem[]
|
||||
@@ -193,9 +238,9 @@ namespace AppGame.Sync
|
||||
return Sockets.Keys.Where(key => Sockets[key].IsOpen).ToArray();
|
||||
}
|
||||
|
||||
protected async Task AddSocket(int index)
|
||||
protected async Task<JNGTileClient> AddSocket(int index)
|
||||
{
|
||||
if (IsTileConnect(index)) return;
|
||||
if (IsTileConnect(index)) return null;
|
||||
|
||||
var client = new JNGTileClient();
|
||||
Sockets.Add(index,client);
|
||||
@@ -207,16 +252,23 @@ namespace AppGame.Sync
|
||||
{
|
||||
Debug.Log($"[{index}] 连接 Socket");
|
||||
client.SetPoint($"{info.ip}:{info.port}");
|
||||
client.SetTileServer(info.server);
|
||||
await client.OnInit();
|
||||
return client;
|
||||
}
|
||||
else
|
||||
{
|
||||
Sockets.Remove(index);
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void RemoveSocket(int index)
|
||||
/// <summary>
|
||||
/// 销毁Socket
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
public void RemoveSocket(int index)
|
||||
{
|
||||
if (Sockets.TryGetValue(index,out var client))
|
||||
{
|
||||
@@ -225,6 +277,15 @@ namespace AppGame.Sync
|
||||
}
|
||||
Sockets.Remove(index);
|
||||
}
|
||||
public void RemoveSocket(string server)
|
||||
{
|
||||
Sockets.ToArray().ForEach(tile =>
|
||||
{
|
||||
if (tile.Value.TileServer != server) return;
|
||||
tile.Value.OnClose();
|
||||
Sockets.Remove(tile.Key);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user