/* * @Author: 白哉 * @Description: * @Date: 2025年11月05日 星期三 11:11:14 * @Modify: */ using Logic; using Logic.AI; using MemoryPack; using RuntimeData; using System.Collections.Generic; using TH1_Logic.Chat; /* * 房主开始游戏 -> 主端直接开始,广播所有客户端游戏开始,走从端开游戏逻辑 * 游戏开始后 * 回合结束回合开始都由主端进行广播 * 主端回合操作直接通过,广播操作行为,从端复刻 * 从端回合操作发往主端,主端验证完毕后广播操作行为,从端复刻 */ namespace TH1_Logic.Steam { public enum P2PMsgType : byte { None = 0, // 基础字符串消息 String = 1, // 游戏开始 (房主 => 所有成员) GameStart = 2, // 请求行为 (成员 => 房主) ActionConfirm = 3, // 行为执行 (房主 => 所有成员) ActionExcute = 4, // 请求回合结束 (成员 => 房主) TurnEnd = 5, // 游戏校验 (成员 => 房主) MapConfirm = 6, // 强制更新 (房主 => 所有成员) ForceUpdate = 7, // 组队界面修改阵营 (成员 => 房主) ChangeCiv = 8, // 同步游戏房间数据 (房主 => 所有成员) UpdateLobbyData = 9, // 请求房间数据 (成员 => 房主) RequestLobbyData = 10, // 心跳 (成员 => 房主) Heartbeat = 11, // 成员状态同步 (房主 => 所有成员) MemberStateSync = 12, // 请求重连 (成员 => 房主) RequestForceUpdate = 13, // 心跳包回复 (任意成员 => 任意成员) HeartbeatReply = 14, // 聊天 ChatMessage = 15, // 邀请 InviteMessage = 16, // 网络压测工具消息 NetworkStress = 17, } public enum NetworkStressMessageKind : byte { Probe = 0, Ack = 1, ControlStart = 2, ControlStop = 3, Report = 4, } [MemoryPackable] [MemoryPackUnion(1, typeof(StringMessage))] [MemoryPackUnion(2, typeof(GameStartMessage))] [MemoryPackUnion(3, typeof(ActionConfirmMessage))] [MemoryPackUnion(4, typeof(ActionExcuteMessage))] [MemoryPackUnion(5, typeof(TurnEndMessage))] [MemoryPackUnion(6, typeof(MapConfirmMessage))] [MemoryPackUnion(7, typeof(ForceUpdateMessage))] [MemoryPackUnion(8, typeof(ChangeCivMessage))] [MemoryPackUnion(9, typeof(UpdateLobbyDataMessage))] [MemoryPackUnion(10, typeof(RequestLobbyDataMessage))] [MemoryPackUnion(11, typeof(HeartbeatMessage))] [MemoryPackUnion(12, typeof(MemberStateSyncMessage))] [MemoryPackUnion(13, typeof(RequestForceUpdateMessage))] [MemoryPackUnion(14, typeof(HeartbeatReplyMessage))] [MemoryPackUnion(15, typeof(ChatMessage))] [MemoryPackUnion(16, typeof(InviteMessage))] [MemoryPackUnion(17, typeof(NetworkStressMessage))] public abstract partial class BaseMessage { public abstract P2PMsgType MessageType { get; } } [MemoryPackable] public partial class StringMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.String; public string Content { get; set; } } [MemoryPackable] public partial class GameStartMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.GameStart; public MapData MapData { get; set; } public float Progress { get; set; } } [MemoryPackable] public partial class ActionConfirmMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.ActionConfirm; public ActionNetData ActionData { get; set; } } [MemoryPackable] public partial class ActionExcuteMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.ActionExcute; public ActionNetData ActionData { get; set; } public MapData Map { get; set; } } [MemoryPackable] public partial class TurnEndMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.TurnEnd; public uint PlayerId { get; set; } } [MemoryPackable] public partial class MapConfirmMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.MapConfirm; public ulong MemberId { get; set; } public uint PlayerId { get; set; } public int Index { get; set; } public ActionNetData ActionData { get; set; } } [MemoryPackable] public partial class ForceUpdateMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.ForceUpdate; public MapData MapData { get; set; } } [MemoryPackable] public partial class ChangeCivMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.ChangeCiv; public MemberCiv Civ { get; set; } } [MemoryPackable] public partial class UpdateLobbyDataMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.UpdateLobbyData; public MapConfig Config { get; set; } } [MemoryPackable] public partial class RequestLobbyDataMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.RequestLobbyData; public ulong MemberId { get; set; } } [MemoryPackable] public partial class HeartbeatMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.Heartbeat; public ulong MemberId { get; set; } public GameState State { get; set; } } [MemoryPackable] public partial class MemberStateSyncMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.MemberStateSync; public GameState State { get; set; } public ulong MemberId { get; set; } public Dictionary PlayerConfirm; } [MemoryPackable] public partial class RequestForceUpdateMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.RequestForceUpdate; public ulong MemberId { get; set; } } [MemoryPackable] public partial class HeartbeatReplyMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.HeartbeatReply; public ulong MemberId { get; set; } } [MemoryPackable] public partial class ChatMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.ChatMessage; public ChatItem Item { get; set; } } [MemoryPackable] public partial class InviteMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.InviteMessage; public LobbyListInfo LobbyInfo { get; set; } } [MemoryPackable] public partial class NetworkStressMessage : BaseMessage { public override P2PMsgType MessageType => P2PMsgType.NetworkStress; public NetworkStressMessageKind StressKind { get; set; } public string SessionId { get; set; } public string ScenarioName { get; set; } public ulong SenderMemberId { get; set; } public ulong TargetMemberId { get; set; } public long Sequence { get; set; } public long AckSequence { get; set; } public long SentUtcTicks { get; set; } public int PayloadBytes { get; set; } public int PayloadHash { get; set; } public bool Reliable { get; set; } public bool RequiresAck { get; set; } public float DurationSeconds { get; set; } public float MessagesPerSecond { get; set; } public int SmallPayloadBytes { get; set; } public int LargePayloadBytes { get; set; } public int LargeEveryMessages { get; set; } public float DropPercent { get; set; } public float UnreliablePercent { get; set; } public int JitterMinMs { get; set; } public int JitterMaxMs { get; set; } public int BurstPauseEveryMessages { get; set; } public int BurstPauseMs { get; set; } public int RandomSeed { get; set; } public byte[] Payload { get; set; } public string Text { get; set; } } }