Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,36 +113,21 @@ public sealed class NetworkConnectionManager
/// client that disconnected. It is recommended to copy the message to some other property or field when
/// <see cref="OnClientDisconnectCallback"/> is invoked.
/// </remarks>
public string DisconnectReason
{
get
{
// For in-frequent event driven invocations, a method within a getter
// is "generally ok".
return GetDisconnectReason();
}
internal set
{
m_DisconnectReason = value;
}
}
public string DisconnectReason => GetDisconnectReason(); // fine as function because this call is infrequent

/// <summary>
/// Returns the conbined result of the locally applied <see cref="DisconnectReason"/> and the
/// server applied <see cref="ServerDisconnectReason"/>.
/// - If both values are empty or null, then it returns <see cref="string.Empty"/>.
/// - If either value is valid, then it returns that <see cref="string"/> value.
/// - If both values are valid, then it returns <see cref="DisconnectReason"/> followed by a
/// new line and then <see cref="ServerDisconnectReason"/>.
/// Gets the reason for why this client was disconnected if exists.
/// </summary>
/// <returns>A disconnect reason, if any.</returns>
/// <returns><see cref="ServerDisconnectReason"/> disconnect reason if it exists, otherwise <see cref="m_DisconnectReason"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal string GetDisconnectReason(string header = null)
internal string GetDisconnectReason()
{
var disconnectReason = string.IsNullOrEmpty(m_DisconnectReason) ? string.Empty : m_DisconnectReason;
var serverDisconnectReason = string.IsNullOrEmpty(ServerDisconnectReason) ? string.Empty : $"\n{ServerDisconnectReason}";
var headerInfo = string.IsNullOrEmpty(header) ? string.Empty : header;
return $"{headerInfo}{disconnectReason}{serverDisconnectReason}";
// TODO: fix this properly
if (!string.IsNullOrEmpty(ServerDisconnectReason))
{
return ServerDisconnectReason;
}
return m_DisconnectReason;
}

/// <summary>
Expand Down Expand Up @@ -590,7 +575,8 @@ private void GenerateDisconnectInformation(ulong clientId, ulong transportClient

if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
{
NetworkLog.LogInfo($"{DisconnectReason}");
var serverDisconnectReason = string.IsNullOrEmpty(ServerDisconnectReason) ? string.Empty : $"\n{ServerDisconnectReason}";
NetworkLog.LogInfo($"{m_DisconnectReason}{serverDisconnectReason}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
{
string reasonSent = Reason ?? string.Empty;

// Since we don't send a ConnectionApprovedMessage, the version for this message is encded with the message itself.
// Since we don't send a ConnectionApprovedMessage, the version for this message is encoded with the message itself.
// However, note that we HAVE received a ConnectionRequestMessage, so we DO have a valid targetVersion on this side of things.
// We just have to make sure the receiving side knows what version we sent it, since whoever has the higher version number is responsible for versioning and they may be the one with the higher version number.
BytePacker.WriteValueBitPacked(writer, Version);
Expand Down
Loading