This commit is contained in:
2025-12-14 01:45:02 +01:00
parent 60d509344c
commit f03e13236f
30 changed files with 260 additions and 2480 deletions

View File

@@ -51,20 +51,6 @@ namespace KCM.Packets.Network
{
Main.helper.Log("Server Player Connected: " + Name + " Id: " + clientId + " SteamID: " + SteamId);
KCPlayer player;
if (Main.kCPlayers.TryGetValue(SteamId, out player))
{
player.id = clientId;
player.name = Name;
player.steamId = SteamId;
}
else
{
Main.kCPlayers[SteamId] = new KCPlayer(Name, clientId, SteamId);
}
Main.clientSteamIds[clientId] = SteamId;
List<KCPlayer> list = Main.kCPlayers.Select(x => x.Value).OrderBy(x => x.id).ToList();
if (list.Count > 0)
@@ -92,7 +78,36 @@ namespace KCM.Packets.Network
return;
byte[] bytes = LoadSaveLoadAtPathHook.saveData;
KCServer.EnqueueSaveTransfer(clientId, bytes);
int chunkSize = 900; // 900 bytes per chunk to fit within packet size limit
List<byte[]> chunks = SplitByteArrayIntoChunks(bytes, chunkSize);
Main.helper.Log("Save Transfer started!");
int sent = 0;
int packetsSent = 0;
for (int i = 0; i < chunks.Count; i++)
{
var chunk = chunks[i];
new SaveTransferPacket()
{
saveSize = bytes.Length,
saveDataChunk = chunk,
chunkId = i,
chunkSize = chunk.Length,
saveDataIndex = sent,
totalChunks = chunks.Count
}.Send(clientId);
Main.helper.Log(" ");
packetsSent++;
sent += chunk.Length;
}
Main.helper.Log($"Sent {packetsSent} save data chunks to client");
}
else
{

View File

@@ -1,35 +0,0 @@
using KCM.Attributes;
using KCM.StateManagement.Sync;
using System;
namespace KCM.Packets.Network
{
[NoServerRelay]
public class ResyncRequestPacket : Packet
{
public override ushort packetId => (ushort)Enums.Packets.ResyncRequest;
public string reason { get; set; }
public override void HandlePacketClient()
{
}
public override void HandlePacketServer()
{
try
{
if (!KCServer.IsRunning)
return;
SyncManager.SendResyncToClient(clientId, reason);
}
catch (Exception ex)
{
Main.helper.Log("Error handling ResyncRequestPacket on server");
Main.helper.Log(ex.ToString());
}
}
}
}

View File

@@ -38,8 +38,7 @@ namespace KCM.Packets.Network
Main.helper.Log("Sending client connected. Client ID is: " + clientId);
Main.kCPlayers[Main.PlayerSteamID] = new KCPlayer(KCClient.inst.Name, clientId, Main.PlayerSteamID);
Main.clientSteamIds[clientId] = Main.PlayerSteamID;
Main.kCPlayers.Add(Main.PlayerSteamID, new KCPlayer(KCClient.inst.Name, clientId, Main.PlayerSteamID));
Player.inst.PlayerLandmassOwner.teamId = clientId * 10 + 2;