Skip to content

Commit 61a4edf

Browse files
feat: move session manager and relay utilities to utilities package (#438)
* Moved SessionManager and UnityRelayUtilities to the Utilities package * Renaming OnClientApprovalCheck method to more meaningful name * Deleted unused prefab
1 parent 47a3a3b commit 61a4edf

File tree

7 files changed

+14
-58
lines changed

7 files changed

+14
-58
lines changed

Assets/BossRoom/Prefabs/SessionManager.prefab

Lines changed: 0 additions & 46 deletions
This file was deleted.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ private void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager
178178

179179
Debug.Log("Host ApprovalCheck: connecting client GUID: " + connectionPayload.clientGUID);
180180

181-
gameReturnStatus = SessionManager<SessionPlayerData>.Instance.OnClientApprovalCheck(clientId, connectionPayload.clientGUID,
182-
new SessionPlayerData(clientId, connectionPayload.playerName, m_Portal.AvatarRegistry.GetRandomAvatar().Guid.ToNetworkGuid(), 0, true));
181+
gameReturnStatus = SessionManager<SessionPlayerData>.Instance.SetupConnectingPlayerSessionData(clientId, connectionPayload.clientGUID,
182+
new SessionPlayerData(clientId, connectionPayload.playerName, m_Portal.AvatarRegistry.GetRandomAvatar().Guid.ToNetworkGuid(), 0, true))
183+
? ConnectStatus.Success
184+
: ConnectStatus.LoggedInAgain;
183185

184186
//Test for Duplicate Login.
185187
if (gameReturnStatus == ConnectStatus.LoggedInAgain)

Assets/BossRoom/Prefabs/SessionManager.prefab.meta renamed to Packages/com.unity.multiplayer.samples.coop/Utilities/Net.meta

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/BossRoom/Scripts/Shared/Net/ConnectionManagement/SessionManager.cs renamed to Packages/com.unity.multiplayer.samples.coop/Utilities/Net/SessionManager.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,15 @@ private void Clear()
109109
}
110110

111111
/// <summary>
112-
/// Handles the flow when a user is connecting by testing for duplicate logins and populating the session's data.
113-
/// Invoked during the approval check and returns the connection status.
112+
/// Adds a connecting player's session data if it is a new connection, or updates their session data in case of a reconnection. If the connection is not valid, simply returns false.
114113
/// </summary>
115114
/// <param name="clientId">This is the clientId that Netcode assigned us on login. It does not persist across multiple logins from the same client. </param>
116115
/// <param name="clientGUID">This is the clientGUID that is unique to this client and persists accross multiple logins from the same client</param>
117116
/// <param name="sessionPlayerData">The player's initial data</param>
118-
/// <returns></returns>
119-
public ConnectStatus OnClientApprovalCheck(ulong clientId, string clientGUID, T sessionPlayerData)
117+
/// <returns>True if the player connection is valid (i.e. not a duplicate connection)</returns>
118+
public bool SetupConnectingPlayerSessionData(ulong clientId, string clientGUID, T sessionPlayerData)
120119
{
121-
ConnectStatus gameReturnStatus = ConnectStatus.Success;
120+
bool success = true;
122121

123122
//Test for Duplicate Login.
124123
if (m_ClientData.ContainsKey(clientGUID))
@@ -144,7 +143,7 @@ public ConnectStatus OnClientApprovalCheck(ulong clientId, string clientGUID, T
144143
}
145144
else
146145
{
147-
gameReturnStatus = ConnectStatus.LoggedInAgain;
146+
success = false;
148147
}
149148
}
150149
else
@@ -163,13 +162,13 @@ public ConnectStatus OnClientApprovalCheck(ulong clientId, string clientGUID, T
163162
}
164163

165164
//Populate our dictionaries with the SessionPlayerData
166-
if (gameReturnStatus == ConnectStatus.Success)
165+
if (success)
167166
{
168167
m_ClientIDToGuid[clientId] = clientGUID;
169168
m_ClientData[clientGUID] = sessionPlayerData;
170169
}
171170

172-
return gameReturnStatus;
171+
return success;
173172
}
174173

175174
/// <summary>

0 commit comments

Comments
 (0)