Skip to content

Commit 6c31e46

Browse files
Merge branch 'develop' into feat/jil/bigger-floor-pieces
2 parents 6ea071a + 7c849bf commit 6c31e46

File tree

8 files changed

+51
-41
lines changed

8 files changed

+51
-41
lines changed

Assets/BossRoom/Prefabs/NetworkingManager.prefab

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ MonoBehaviour:
4545
m_EditorClassIdentifier:
4646
m_ProtocolType: 0
4747
m_MaxPacketQueueSize: 512
48-
m_MaxPayloadSize: 16000
49-
m_MaxSendQueueSize: 98304
48+
m_MaxPayloadSize: 32000
49+
m_MaxSendQueueSize: 50000000
5050
m_HeartbeatTimeoutMS: 500
5151
m_ConnectTimeoutMS: 1000
5252
m_MaxConnectAttempts: 60
53-
m_DisconnectTimeoutMS: 30000
53+
m_DisconnectTimeoutMS: 10000
5454
ConnectionData:
5555
Address: 127.0.0.1
5656
Port: 7777
@@ -99,13 +99,13 @@ MonoBehaviour:
9999
m_Name:
100100
m_EditorClassIdentifier:
101101
m_ProtocolType: 1
102-
m_MaxPacketQueueSize: 256
102+
m_MaxPacketQueueSize: 512
103103
m_MaxPayloadSize: 32000
104-
m_MaxSendQueueSize: 98304
104+
m_MaxSendQueueSize: 50000000
105105
m_HeartbeatTimeoutMS: 500
106106
m_ConnectTimeoutMS: 1000
107107
m_MaxConnectAttempts: 60
108-
m_DisconnectTimeoutMS: 30000
108+
m_DisconnectTimeoutMS: 10000
109109
ConnectionData:
110110
Address: 127.0.0.1
111111
Port: 7777

Assets/BossRoom/Scripts/Client/Game/State/ClientCharSelectState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void OnLobbyPlayerStateChanged(NetworkListEvent<CharSelectData.LobbyPlayerState>
218218
// we haven't chosen a seat yet (or were kicked out of our seat by someone else)
219219
UpdateCharacterSelection(CharSelectData.SeatState.Inactive);
220220
// make sure our player num is properly set in Lobby UI
221-
OnAssignedPlayerNumber(CharSelectData.LobbyPlayers[localPlayerIdx].PlayerNum);
221+
OnAssignedPlayerNumber(CharSelectData.LobbyPlayers[localPlayerIdx].PlayerNumber);
222222
}
223223
else
224224
{
@@ -319,7 +319,7 @@ void UpdateSeats()
319319
// now actually update the seats in the UI
320320
for (int i = 0; i < m_PlayerSeats.Count; ++i)
321321
{
322-
m_PlayerSeats[i].SetState(curSeats[i].SeatState, curSeats[i].PlayerNum, curSeats[i].PlayerName);
322+
m_PlayerSeats[i].SetState(curSeats[i].SeatState, curSeats[i].PlayerNumber, curSeats[i].PlayerName);
323323
}
324324
}
325325

Assets/BossRoom/Scripts/Server/Game/State/ServerCharSelectState.cs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
5353
// Instead of granting lock request, change this player to Inactive state.
5454
CharSelectData.LobbyPlayers[idx] = new CharSelectData.LobbyPlayerState(clientId,
5555
CharSelectData.LobbyPlayers[idx].PlayerName,
56-
CharSelectData.LobbyPlayers[idx].PlayerNum,
56+
CharSelectData.LobbyPlayers[idx].PlayerNumber,
5757
CharSelectData.SeatState.Inactive);
5858

5959
// then early out
@@ -64,7 +64,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
6464

6565
CharSelectData.LobbyPlayers[idx] = new CharSelectData.LobbyPlayerState(clientId,
6666
CharSelectData.LobbyPlayers[idx].PlayerName,
67-
CharSelectData.LobbyPlayers[idx].PlayerNum,
67+
CharSelectData.LobbyPlayers[idx].PlayerNumber,
6868
lockedIn ? CharSelectData.SeatState.LockedIn : CharSelectData.SeatState.Active,
6969
newSeatIdx,
7070
Time.time);
@@ -81,7 +81,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
8181
CharSelectData.LobbyPlayers[i] = new CharSelectData.LobbyPlayerState(
8282
CharSelectData.LobbyPlayers[i].ClientId,
8383
CharSelectData.LobbyPlayers[i].PlayerName,
84-
CharSelectData.LobbyPlayers[i].PlayerNum,
84+
CharSelectData.LobbyPlayers[i].PlayerNumber,
8585
CharSelectData.SeatState.Inactive);
8686
}
8787
}
@@ -185,46 +185,52 @@ private void OnSceneEvent(SceneEvent sceneEvent)
185185
SeatNewPlayer(sceneEvent.ClientId);
186186
}
187187

188-
private int GetAvailablePlayerNum()
188+
private int GetAvailablePlayerNumber()
189189
{
190-
for (int possiblePlayerNum = 0; possiblePlayerNum < CharSelectData.k_MaxLobbyPlayers; ++possiblePlayerNum)
190+
for (int possiblePlayerNumber = 0; possiblePlayerNumber < CharSelectData.k_MaxLobbyPlayers; ++possiblePlayerNumber)
191191
{
192-
bool found = false;
193-
foreach (CharSelectData.LobbyPlayerState playerState in CharSelectData.LobbyPlayers)
192+
if (IsPlayerNumberAvailable(possiblePlayerNumber))
194193
{
195-
if (playerState.PlayerNum == possiblePlayerNum)
196-
{
197-
found = true;
198-
break;
199-
}
200-
}
201-
if (!found)
202-
{
203-
return possiblePlayerNum;
194+
return possiblePlayerNumber;
204195
}
205196
}
206197
// we couldn't get a Player# for this person... which means the lobby is full!
207198
return -1;
208199
}
209200

201+
bool IsPlayerNumberAvailable(int playerNumber)
202+
{
203+
bool found = false;
204+
foreach (CharSelectData.LobbyPlayerState playerState in CharSelectData.LobbyPlayers)
205+
{
206+
if (playerState.PlayerNumber == playerNumber)
207+
{
208+
found = true;
209+
break;
210+
}
211+
}
212+
213+
return !found;
214+
}
215+
210216
private void SeatNewPlayer(ulong clientId)
211217
{
212218
SessionPlayerData? sessionPlayerData = SessionManager<SessionPlayerData>.Instance.GetPlayerData(clientId);
213219
if (sessionPlayerData.HasValue)
214220
{
215221
var playerData = sessionPlayerData.Value;
216-
if (playerData.PlayerNum == -1)
222+
if (playerData.PlayerNumber == -1 || !IsPlayerNumberAvailable(playerData.PlayerNumber))
217223
{
218-
// If no player num already assigned, get an available one.
219-
playerData.PlayerNum = GetAvailablePlayerNum();
224+
// If no player num already assigned or if player num is no longer available, get an available one.
225+
playerData.PlayerNumber = GetAvailablePlayerNumber();
220226
}
221-
if (playerData.PlayerNum == -1)
227+
if (playerData.PlayerNumber == -1)
222228
{
223229
// Sanity check. We ran out of seats... there was no room!
224-
throw new Exception($"we shouldn't be here, connection approval should have refused this connection already for client ID {clientId} and player num {playerData.PlayerNum}");
230+
throw new Exception($"we shouldn't be here, connection approval should have refused this connection already for client ID {clientId} and player num {playerData.PlayerNumber}");
225231
}
226232

227-
CharSelectData.LobbyPlayers.Add(new CharSelectData.LobbyPlayerState(clientId, playerData.PlayerName, playerData.PlayerNum, CharSelectData.SeatState.Inactive));
233+
CharSelectData.LobbyPlayers.Add(new CharSelectData.LobbyPlayerState(clientId, playerData.PlayerName, playerData.PlayerNumber, CharSelectData.SeatState.Inactive));
228234
SessionManager<SessionPlayerData>.Instance.SetPlayerData(clientId, playerData);
229235
}
230236
}

Assets/BossRoom/Scripts/Shared/Game/State/CharSelectData.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ public struct LobbyPlayerState : INetworkSerializable, IEquatable<LobbyPlayerSta
2626

2727
private FixedPlayerName m_PlayerName; // I'm sad there's no 256Bytes fixed list :(
2828

29-
public int PlayerNum; // this player's assigned "P#". (0=P1, 1=P2, etc.)
29+
public int PlayerNumber; // this player's assigned "P#". (0=P1, 1=P2, etc.)
3030
public int SeatIdx; // the latest seat they were in. -1 means none
3131
public float LastChangeTime;
3232

3333
public SeatState SeatState;
3434

3535

36-
public LobbyPlayerState(ulong clientId, string name, int playerNum, SeatState state, int seatIdx = -1, float lastChangeTime = 0)
36+
public LobbyPlayerState(ulong clientId, string name, int playerNumber, SeatState state, int seatIdx = -1, float lastChangeTime = 0)
3737
{
3838
ClientId = clientId;
39-
PlayerNum = playerNum;
39+
PlayerNumber = playerNumber;
4040
SeatState = state;
4141
SeatIdx = seatIdx;
4242
LastChangeTime = lastChangeTime;
@@ -55,7 +55,7 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
5555
{
5656
serializer.SerializeValue(ref ClientId);
5757
serializer.SerializeValue(ref m_PlayerName);
58-
serializer.SerializeValue(ref PlayerNum);
58+
serializer.SerializeValue(ref PlayerNumber);
5959
serializer.SerializeValue(ref SeatState);
6060
serializer.SerializeValue(ref SeatIdx);
6161
serializer.SerializeValue(ref LastChangeTime);
@@ -65,7 +65,7 @@ public bool Equals(LobbyPlayerState other)
6565
{
6666
return ClientId == other.ClientId &&
6767
m_PlayerName.Equals(other.m_PlayerName) &&
68-
PlayerNum == other.PlayerNum &&
68+
PlayerNumber == other.PlayerNumber &&
6969
SeatIdx == other.SeatIdx &&
7070
LastChangeTime.Equals(other.LastChangeTime) &&
7171
SeatState == other.SeatState;

Assets/BossRoom/Scripts/Shared/Net/ConnectionManagement/ClientGameNetPortal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public async void StartClientUnityRelayModeAsync(string joinCode, Action<string>
190190
var (ipv4Address, port, allocationIdBytes, connectionData, hostConnectionData, key) = clientRelayUtilityTask.Result;
191191

192192
m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(allocationIdBytes.ToString(), joinCode, null, null);
193-
utp.SetRelayServerData(ipv4Address, port, allocationIdBytes, key, connectionData, hostConnectionData);
193+
utp.SetClientRelayData(ipv4Address, port, allocationIdBytes, key, connectionData, hostConnectionData, isSecure: true);
194194
}
195195
catch (Exception e)
196196
{

Assets/BossRoom/Scripts/Shared/Net/ConnectionManagement/GameNetPortal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public async void StartUnityRelayHost()
209209
m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(allocationIdBytes.ToString(), joinCode, null, null);
210210

211211
// we now need to set the RelayCode somewhere :P
212-
utp.SetRelayServerData(ipv4Address, port, allocationIdBytes, key, connectionData);
212+
utp.SetHostRelayData(ipv4Address, port, allocationIdBytes, key, connectionData, isSecure: true);
213213
}
214214
catch (Exception e)
215215
{

Assets/BossRoom/Scripts/Shared/Net/ConnectionManagement/SessionPlayerData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
55
public struct SessionPlayerData : ISessionPlayerData
66
{
77
public string PlayerName;
8-
public int PlayerNum;
8+
public int PlayerNumber;
99
public Vector3 PlayerPosition;
1010
public Quaternion PlayerRotation;
1111
public NetworkGuid AvatarNetworkGuid;
@@ -16,7 +16,7 @@ public SessionPlayerData(ulong clientID, string name, NetworkGuid avatarNetworkG
1616
{
1717
ClientID = clientID;
1818
PlayerName = name;
19-
PlayerNum = -1;
19+
PlayerNumber = -1;
2020
PlayerPosition = Vector3.zero;
2121
PlayerRotation = Quaternion.identity;
2222
AvatarNetworkGuid = avatarNetworkGuid;

Packages/com.unity.multiplayer.samples.coop/Utilities/Net/UnityRelayUtilities.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using UnityEngine;
45
using Unity.Services.Relay;
@@ -8,6 +9,7 @@ namespace Unity.Multiplayer.Samples.BossRoom
89
{
910
public static class UnityRelayUtilities
1011
{
12+
private const string kDtlsConnType = "dtls";
1113

1214
public static async
1315
Task<(string ipv4address, ushort port, byte[] allocationIdBytes, byte[] connectionData, byte[] key, string
@@ -37,7 +39,8 @@ public static async
3739
throw new Exception($"Creating join code request has failed: \n {exception.Message}");
3840
}
3941

40-
return (allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port, allocation.AllocationIdBytes,
42+
var dtlsEndpoint = allocation.ServerEndpoints.First(e => e.ConnectionType == kDtlsConnType);
43+
return (dtlsEndpoint.Host, (ushort)dtlsEndpoint.Port, allocation.AllocationIdBytes,
4144
allocation.ConnectionData, allocation.Key, joinCode);
4245
}
4346

@@ -59,7 +62,8 @@ public static async
5962
Debug.Log($"host: {allocation.HostConnectionData[0]} {allocation.HostConnectionData[1]}");
6063
Debug.Log($"client: {allocation.AllocationId}");
6164

62-
return (allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port, allocation.AllocationIdBytes,
65+
var dtlsEndpoint = allocation.ServerEndpoints.First(e => e.ConnectionType == kDtlsConnType);
66+
return (dtlsEndpoint.Host, (ushort)dtlsEndpoint.Port, allocation.AllocationIdBytes,
6367
allocation.ConnectionData, allocation.HostConnectionData, allocation.Key);
6468
}
6569
}

0 commit comments

Comments
 (0)