浏览代码

Changing the Relay message parsing to allow for validation of the message length, which was interfering with diagnosing the issue with DTLS. (Turns out it's on their end, and there's a fix coming today. But, this is still an improvement.)

/main/staging/relay_dtls
nathaniel.buck@unity3d.com 3 年前
当前提交
8344a95b
共有 1 个文件被更改,包括 19 次插入9 次删除
  1. 28
      Assets/Scripts/Relay/RelayUtpClient.cs

28
Assets/Scripts/Relay/RelayUtpClient.cs


{
if (cmd == NetworkEvent.Type.Data)
{
MsgType msgType = (MsgType)strm.ReadByte();
string id = ReadLengthAndString(ref strm);
if (id == m_localUser.ID || !m_localLobby.LobbyUsers.ContainsKey(id)) // We don't hold onto messages, since an incoming user will be fully initialized before they send events.
List<byte> msgContents = new List<byte>(ReadMessageContents(ref strm));
if (msgContents.Count < 3) // We require at a minimum - Message type, the length of the user ID, and the user ID.
MsgType msgType = (MsgType)msgContents[0];
int idLength = msgContents[1];
if (msgContents.Count < idLength + 2)
return;
string id = System.Text.Encoding.UTF8.GetString(msgContents.GetRange(2, idLength).ToArray());
if (id == m_localUser.ID || !m_localLobby.LobbyUsers.ContainsKey(id)) // We don't need to hold onto messages if the ID is absent; users are initialized before they send events.
return;
msgContents.RemoveRange(0, 2 + idLength);
string name = ReadLengthAndString(ref strm);
int nameLength = msgContents[0];
string name = System.Text.Encoding.UTF8.GetString(msgContents.GetRange(1, nameLength).ToArray());
EmoteType emote = (EmoteType)strm.ReadByte();
EmoteType emote = (EmoteType)msgContents[0];
UserStatus status = (UserStatus)strm.ReadByte();
UserStatus status = (UserStatus)msgContents[0];
m_localLobby.LobbyUsers[id].UserStatus = status;
}
else if (msgType == MsgType.StartCountdown)

/// <summary>
/// Relay uses raw pointers for efficiency. This converts them to byte arrays, assuming the stream contents are 1 byte for array length followed by contents.
/// </summary>
unsafe private string ReadLengthAndString(ref DataStreamReader strm)
unsafe private byte[] ReadMessageContents(ref DataStreamReader strm)
byte length = strm.ReadByte();
int length = strm.Length;
return System.Text.Encoding.UTF8.GetString(bytes);
return bytes;
}
/// <summary>

正在加载...
取消
保存