151 lines
4.5 KiB
C#
151 lines
4.5 KiB
C#
using System.Text;
|
|
using Logic.AI;
|
|
using MemoryPack;
|
|
using RuntimeData;
|
|
|
|
|
|
/*
|
|
* 房主开始游戏 -> 主端直接开始,广播所有客户端游戏开始,走从端开游戏逻辑
|
|
* 游戏开始后
|
|
* 回合结束回合开始都由主端进行广播
|
|
* 主端回合操作直接通过,广播操作行为,从端复刻
|
|
* 从端回合操作发往主端,主端验证完毕后广播操作行为,从端复刻
|
|
*/
|
|
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,
|
|
}
|
|
|
|
|
|
[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))]
|
|
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; }
|
|
}
|
|
|
|
|
|
[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; }
|
|
}
|
|
|
|
|
|
[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; }
|
|
}
|
|
} |