/// <summary> /// Handle data received by the server. /// </summary> /// <param name="id">The ID of the client that sent the packet.</param> /// <param name="packet">The server update packet.</param> public void HandleServerPacket(ushort id, ServerUpdatePacket packet) { // Execute corresponding packet handlers UnpackPacketDataDict( packet.GetPacketData(), (packetId, packetData) => ExecuteServerPacketHandler(id, packetId, packetData) ); // Execute corresponding packet handler for addon packet data of each addon in the packet foreach (var idPacketDataPair in packet.GetAddonPacketData()) { var addonId = idPacketDataPair.Key; var packetDataDict = idPacketDataPair.Value.PacketData; UnpackPacketDataDict( packetDataDict, (packetId, packetData) => ExecuteServerAddonPacketHandler( id, addonId, packetId, packetData ) ); } }
public void SetLostReliableData(ServerUpdatePacket lostPacket) { if (lostPacket.DataPacketIds.Contains(ServerPacketId.HelloServer)) { Logger.Get().Info(this, " Resending HelloServer data"); DataPacketIds.Add(ServerPacketId.HelloServer); HelloServer = lostPacket.HelloServer; } if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerEnterScene)) { Logger.Get().Info(this, " Resending PlayerEnterScene data"); DataPacketIds.Add(ServerPacketId.PlayerEnterScene); PlayerEnterScene = lostPacket.PlayerEnterScene; } if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerLeaveScene)) { Logger.Get().Info(this, " Resending PlayerLeaveScene data"); DataPacketIds.Add(ServerPacketId.PlayerLeaveScene); } if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerTeamUpdate)) { // Only update if the current packet does not already contain another team update // since we want the latest update to arrive if (!DataPacketIds.Contains(ServerPacketId.PlayerTeamUpdate)) { Logger.Get().Info(this, " Resending PlayerTeamUpdate data"); DataPacketIds.Add(ServerPacketId.PlayerTeamUpdate); PlayerTeamUpdate = lostPacket.PlayerTeamUpdate; } } if (lostPacket.DataPacketIds.Contains(ServerPacketId.PlayerSkinUpdate)) { // Only update if the current packet does not already contain another skin update // since we want the latest update to arrive if (!DataPacketIds.Contains(ServerPacketId.PlayerSkinUpdate)) { Logger.Get().Info(this, " Resending PlayerSkinUpdate data"); DataPacketIds.Add(ServerPacketId.PlayerSkinUpdate); PlayerSkinUpdate = lostPacket.PlayerSkinUpdate; } } }
/** * Handle data received by the server */ public void HandleServerPacket(ushort id, ServerUpdatePacket packet) { /*foreach (var item in packet.DataPacketIds) * { * Logger.Info(this,$"server to handle {Enum.GetName(typeof(ServerPacketId), item)}"); * } */ // Execute corresponding packet handlers if (packet.DataPacketIds.Contains(ServerPacketId.HelloServer)) { ExecuteServerPacketHandler(id, ServerPacketId.HelloServer, packet.HelloServer); } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerDisconnect)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerDisconnect, null); } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerUpdate)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerUpdate, packet.PlayerUpdate); } if (packet.DataPacketIds.Contains(ServerPacketId.EntityUpdate)) { foreach (var entityUpdate in packet.EntityUpdates.DataInstances) { ExecuteServerPacketHandler(id, ServerPacketId.EntityUpdate, entityUpdate); } } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerEnterScene)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerEnterScene, packet.PlayerEnterScene); } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerLeaveScene)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerLeaveScene, null); } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerDeath)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerDeath, null); } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerTeamUpdate)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerTeamUpdate, packet.PlayerTeamUpdate); } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerSkinUpdate)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerSkinUpdate, packet.PlayerSkinUpdate); } if (packet.DataPacketIds.Contains(ServerPacketId.PlayerEmoteUpdate)) { ExecuteServerPacketHandler(id, ServerPacketId.PlayerEmoteUpdate, packet.PlayerEmoteUpdate); } }