forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerListDebugUtils.cs
More file actions
91 lines (86 loc) · 3.59 KB
/
Copy pathPlayerListDebugUtils.cs
File metadata and controls
91 lines (86 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using Unity.Collections;
namespace Unity.NetCode.Samples.PlayerList
{
public static class PlayerListDebugUtils
{
public static FixedString128Bytes ToFixedString(PlayerListEntry entry)
{
var s = new FixedString128Bytes();
s.Append((FixedString32Bytes) "PlayerListEntry['");
s.Append(entry.State.NetworkId);
s.Append(':');
s.Append(',');
switch (entry.State.ChangeType)
{
case PlayerListEntry.ChangedRpc.UpdateType.PlayerDisconnect:
s.Append((FixedString64Bytes)nameof(PlayerListEntry.ChangedRpc.UpdateType.PlayerDisconnect));
break;
case PlayerListEntry.ChangedRpc.UpdateType.NewJoiner:
s.Append((FixedString64Bytes)nameof(PlayerListEntry.ChangedRpc.UpdateType.NewJoiner));
break;
case PlayerListEntry.ChangedRpc.UpdateType.ExistingPlayer:
s.Append((FixedString64Bytes)nameof(PlayerListEntry.ChangedRpc.UpdateType.ExistingPlayer));
break;
case PlayerListEntry.ChangedRpc.UpdateType.UsernameChange:
s.Append((FixedString64Bytes)nameof(PlayerListEntry.ChangedRpc.UpdateType.UsernameChange));
break;
default:
s.Append((int)entry.State.ChangeType);
break;
}
s.Append(entry.State.Username.Value);
s.Append(',');
s.Append(GetConnectionStatusFixedString(entry.State));
s.Append(']');
return s;
}
public static FixedString32Bytes GetConnectionStatusFixedString(PlayerListEntry.ChangedRpc rpc)
{
if (rpc.IsConnected)
return "Connected!";
switch (rpc.Reason)
{
case NetworkStreamDisconnectReason.Timeout:
return "Timed Out!";
case NetworkStreamDisconnectReason.MaxConnectionAttempts:
return "Could Not Connect!";
case NetworkStreamDisconnectReason.ClosedByRemote:
return "Disconnected!";
case NetworkStreamDisconnectReason.ConnectionClose:
return "ConnectionClosed!";
case NetworkStreamDisconnectReason.BadProtocolVersion:
return "BadProtocolVersion!";
case NetworkStreamDisconnectReason.InvalidRpc:
return "InvalidRpc!";
default:
var s = (FixedString32Bytes) "Err[";
s.Append((int) rpc.Reason);
s.Append(']');
s.Append('!');
return s;
}
}
public static FixedString128Bytes ToFixedString(PlayerListEntry.ClientRegisterUsernameRpc rpc)
{
var s = (FixedString128Bytes)nameof(PlayerListEntry.ClientRegisterUsernameRpc);
s.Append('[');
s.Append(rpc.Value);
s.Append(']');
return s;
}
public static FixedString128Bytes ToFixedString(PlayerListEntry.ChangedRpc rpc)
{
if (rpc.NetworkId == 0)
return (FixedString128Bytes)"ChangedRpc[null]";
var s = (FixedString128Bytes) "ChangedRpc[";
s.Append(rpc.NetworkId);
s.Append(':');
s.Append(GetConnectionStatusFixedString(rpc));
s.Append(',');
s.Append(rpc.Username.Value);
s.Append(']');
return s;
}
}
}