XNet/XNet.Business/Dto/SyncMsg.cs
2025-12-29 17:24:47 +08:00

167 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using MessagePack;
using XNet.Business.Dto;
using XNet.Business.Net;
namespace XNet.Business
{
// WebSocket消息类型枚举
public enum WsMsgType : ushort
{
SUBSCRIBE_ROOM = 0x0000, // 客户端订阅实例
/// <summary>
/// 登录
/// </summary>
LOGIN = 0x0001,
/// <summary>
/// 房间群发信息
/// </summary>
ROOM_MSG = 0x0002,
/// <summary>
/// 房间群发信息,自己不接收
/// </summary>
ROOM_MSG_OTHER = 0x0003,
/// <summary>
/// 用户下线
/// </summary>
OFFLINE = 0x0004,
/// <summary>
/// 用户做主机
/// </summary>
HOST = 0x0005,
/// <summary>
/// 本局游戏结束
/// </summary>
GAME_END = 0x0006,
/// <summary>
/// 心跳包请求
/// </summary>
HEART_BEAT = 0x0007,
/// <summary>
/// 心跳包响应
/// </summary>
HEART_BEAT_REPLY = 0x0008,
/// <summary>
/// 加入或者创建房间
/// </summary>
CREATE_OR_JOIN_ROOM = 0x0009,
/// <summary>
/// 个人私有的消息
/// </summary>
PRIVATGE = 0x0010,
/// <summary>
/// 添加AI玩家
/// </summary>
ADD_AI_PLAYER = 0x0011,
/// <summary>
/// 删除所有AI
/// </summary>
DELETE_ALL_AI_PLAYER = 0x0012,
/// <summary>
/// 发送给自己的消息
/// </summary>
TO_SELF = 0x0013,
/// <summary>
/// 公开或者关闭房间
/// </summary>
ENABLE_ROOM_PUBLIC = 0x0014,
/// <summary>
/// 启用或者关闭AI
/// </summary>
ENABLE_AI = 0x0015,
/// <summary>
/// 游戏将要结束,改变倒计时文字为闪烁或红色
/// </summary>
GAME_WILLOVER = 0x0016,
/// <summary>
/// 本局游戏将要结束
/// </summary>
GAME_WILL_END = 0x0017,
/// <summary>
/// Agent位置同步消息
/// </summary>
AGENT_POSITION_SYNC = 0x0018,
/// <summary>
/// Agent角度同步消息
/// </summary>
AGENT_ROTATION_SYNC = 0x0019,
}
// 客户端订阅实例的请求消息
[MessagePackObject]
public class SubscribeInstanceReq
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
}
// Agent位置同步消息服务端推送
[MessagePackObject]
public class AgentLocationSyncMsg
{
[Key("agentIdx")]
public int AgentIdx { get; set; }
[Key("position")]
public Vec3? Position { get; set; }
[Key("rotation")]
public Vec3? Rotation { get; set; }
}
/// <summary>
/// 房间信息
/// </summary>
[MessagePackObject]
public class RoomMsg<T>
{
[Key("roomId")]
public string RoomId { get; set; } = string.Empty;
[Key("type")]
public WsMsgType Type { get; set; }
[Key("senderId")]
public string SenderId { get; set; } = string.Empty;
[Key("data")]
public T? Data { get; set; } = default;
}
/// <summary>
/// 消息基类
/// </summary>
[MessagePackObject]
public class BaseMsg
{
[Key("type")]
public WsMsgType Type { get; set; }
[Key("senderId")]
public string SenderId { get; set; } = string.Empty;
[Key("data")]
public byte[]? Data { get; set; } = default;
}
//// WebSocket通用消息包装
//[MessagePackObject]
//public class WsMessage<T>
//{
// [Key("type")]
// public WsMsgType Type { get; set; }
// [Key("data")]
// public T? Data { get; set; } = default;
//}
}