fix: improve minigame reconnect flow
This commit is contained in:
@@ -23,6 +23,7 @@ namespace XWorld.Framework.Protocol
|
||||
LobbyLeave = 15,
|
||||
WorldChatSend = 16,
|
||||
WorldChatMessage = 17,
|
||||
MatchCancel = 18,
|
||||
}
|
||||
|
||||
public sealed class HeartbeatMsg
|
||||
@@ -47,19 +48,23 @@ namespace XWorld.Framework.Protocol
|
||||
{
|
||||
public string GameId; // null 编码为空字符串
|
||||
public int Version;
|
||||
public int RequestId;
|
||||
|
||||
public byte[] Encode()
|
||||
{
|
||||
var w = new PacketWriter();
|
||||
w.WriteString(GameId);
|
||||
w.WriteVarInt(Version);
|
||||
w.WriteVarInt(RequestId);
|
||||
return w.ToArray();
|
||||
}
|
||||
|
||||
public static MatchRequestMsg Decode(byte[] data)
|
||||
{
|
||||
var r = new PacketReader(data);
|
||||
return new MatchRequestMsg { GameId = r.ReadString(), Version = r.ReadVarInt() };
|
||||
var m = new MatchRequestMsg { GameId = r.ReadString(), Version = r.ReadVarInt() };
|
||||
if (r.HasMore) m.RequestId = r.ReadVarInt();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +72,9 @@ namespace XWorld.Framework.Protocol
|
||||
{
|
||||
public string RoomId; // null 编码为空字符串
|
||||
public int Version;
|
||||
public string GameId;
|
||||
public int SelfPlayerId;
|
||||
public int RequestId;
|
||||
public List<PlayerInfo> Players = new List<PlayerInfo>();
|
||||
|
||||
public byte[] Encode()
|
||||
@@ -91,6 +98,8 @@ namespace XWorld.Framework.Protocol
|
||||
w.WriteVarInt(p.AppearanceType);
|
||||
w.WriteVarInt(p.AvatarId);
|
||||
}
|
||||
w.WriteVarInt(RequestId);
|
||||
w.WriteString(GameId);
|
||||
return w.ToArray();
|
||||
}
|
||||
|
||||
@@ -131,6 +140,14 @@ namespace XWorld.Framework.Protocol
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r.HasMore)
|
||||
{
|
||||
m.RequestId = r.ReadVarInt();
|
||||
}
|
||||
if (r.HasMore)
|
||||
{
|
||||
m.GameId = r.ReadString();
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -144,6 +161,24 @@ namespace XWorld.Framework.Protocol
|
||||
public int MaxPlayers;
|
||||
}
|
||||
|
||||
public sealed class MatchControlMsg
|
||||
{
|
||||
public int RequestId;
|
||||
|
||||
public byte[] Encode()
|
||||
{
|
||||
var w = new PacketWriter();
|
||||
w.WriteVarInt(RequestId);
|
||||
return w.ToArray();
|
||||
}
|
||||
|
||||
public static MatchControlMsg Decode(byte[] data)
|
||||
{
|
||||
var r = new PacketReader(data);
|
||||
return r.HasMore ? new MatchControlMsg { RequestId = r.ReadVarInt() } : new MatchControlMsg();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class GameListResponseMsg
|
||||
{
|
||||
public List<GameInfoMsg> Games = new List<GameInfoMsg>();
|
||||
@@ -187,19 +222,23 @@ namespace XWorld.Framework.Protocol
|
||||
{
|
||||
public string GameId;
|
||||
public int Version;
|
||||
public int RequestId;
|
||||
|
||||
public byte[] Encode()
|
||||
{
|
||||
var w = new PacketWriter();
|
||||
w.WriteString(GameId);
|
||||
w.WriteVarInt(Version);
|
||||
w.WriteVarInt(RequestId);
|
||||
return w.ToArray();
|
||||
}
|
||||
|
||||
public static MatchAssignedMsg Decode(byte[] data)
|
||||
{
|
||||
var r = new PacketReader(data);
|
||||
return new MatchAssignedMsg { GameId = r.ReadString(), Version = r.ReadVarInt() };
|
||||
var m = new MatchAssignedMsg { GameId = r.ReadString(), Version = r.ReadVarInt() };
|
||||
if (r.HasMore) m.RequestId = r.ReadVarInt();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,19 +307,23 @@ namespace XWorld.Framework.Protocol
|
||||
{
|
||||
public int Code;
|
||||
public string Message; // null 编码为空字符串
|
||||
public int RequestId;
|
||||
|
||||
public byte[] Encode()
|
||||
{
|
||||
var w = new PacketWriter();
|
||||
w.WriteVarInt(Code);
|
||||
w.WriteString(Message);
|
||||
w.WriteVarInt(RequestId);
|
||||
return w.ToArray();
|
||||
}
|
||||
|
||||
public static ErrorMsg Decode(byte[] data)
|
||||
{
|
||||
var r = new PacketReader(data);
|
||||
return new ErrorMsg { Code = r.ReadVarInt(), Message = r.ReadString() };
|
||||
var m = new ErrorMsg { Code = r.ReadVarInt(), Message = r.ReadString() };
|
||||
if (r.HasMore) m.RequestId = r.ReadVarInt();
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user