Skip to content

fix: connecting while starting game #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4001714
Added cancelling of char select closing when new player joins
LPLafontaineB Feb 14, 2022
021ab6a
Removed lock-in on characters when cancelling starting a new game
LPLafontaineB Feb 14, 2022
29bc14a
Cancel closing of lobby when a player disconnects in character selection
LPLafontaineB Feb 14, 2022
e4c0ab1
Resetting class info client-side when start game cancelled
LPLafontaineB Feb 14, 2022
a46a38f
cleanup
LPLafontaineB Feb 14, 2022
d715946
leaving a game session now sets every player as unready
LPLafontaineB Feb 15, 2022
51e21d3
Merge branch 'develop' into fix/connecting-while-starting-game
LPLafontaineB Mar 7, 2022
e114cd0
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 8, 2022
01ab2e8
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 8, 2022
a214a52
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 8, 2022
ce670b0
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 8, 2022
615d2c6
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 8, 2022
4b9b330
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
eac5bef
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
f62f3ce
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
f8f675e
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
3e060bc
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
9724743
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
e845b9f
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
3001226
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 9, 2022
5f17888
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 10, 2022
7a076ac
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 11, 2022
db13a89
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 11, 2022
ddbc9f6
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 11, 2022
7647704
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 11, 2022
faba0e6
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 11, 2022
6368a60
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 11, 2022
de43825
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 14, 2022
5cf00d8
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 14, 2022
7fd0442
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 14, 2022
30e206f
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 15, 2022
16f1e61
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 15, 2022
5655f12
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 15, 2022
e66de6c
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 15, 2022
bcf621d
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 15, 2022
1cd95c5
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 15, 2022
c746b2d
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 16, 2022
d3a2318
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 17, 2022
4468931
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 17, 2022
27d7297
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 17, 2022
f0e6622
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 17, 2022
06f3fa3
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 18, 2022
357a62d
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 18, 2022
6745b47
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 29, 2022
20b6f5b
Merge develop into fix/connecting-while-starting-game
netcode-ci-service Mar 29, 2022
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 @@ -332,6 +332,18 @@ void OnLobbyClosedChanged(bool wasLobbyClosed, bool isLobbyClosed)
{
ConfigureUIForLobbyMode(LobbyMode.LobbyEnding);
}
else
{
if (m_LastSeatSelected == -1)
{
ConfigureUIForLobbyMode(LobbyMode.ChooseSeat);
}
else
{
ConfigureUIForLobbyMode(LobbyMode.SeatChosen);
m_ClassInfoBox.ConfigureForClass(CharSelectData.AvatarConfiguration[m_LastSeatSelected].CharacterClass);
}
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ namespace Unity.Multiplayer.Samples.BossRoom.Server
[RequireComponent(typeof(CharSelectData))]
public class ServerCharSelectState : GameStateBehaviour
{
public override GameState ActiveState { get { return GameState.CharSelect; } }
public override GameState ActiveState => GameState.CharSelect;
public CharSelectData CharSelectData { get; private set; }

private ServerGameNetPortal m_ServerNetPortal;
Coroutine m_WaitToEndLobbyCoroutine;

private void Awake()
void Awake()
{
CharSelectData = GetComponent<CharSelectData>();
m_ServerNetPortal = GameObject.FindGameObjectWithTag("GameNetPortal").GetComponent<ServerGameNetPortal>();
}

private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
{
int idx = FindLobbyPlayerIdx(clientId);
if (idx == -1)
Expand Down Expand Up @@ -93,7 +92,7 @@ private void OnClientChangedSeat(ulong clientId, int newSeatIdx, bool lockedIn)
/// <summary>
/// Returns the index of a client in the master LobbyPlayer list, or -1 if not found
/// </summary>
private int FindLobbyPlayerIdx(ulong clientId)
int FindLobbyPlayerIdx(ulong clientId)
{
for (int i = 0; i < CharSelectData.LobbyPlayers.Count; ++i)
{
Expand All @@ -107,7 +106,7 @@ private int FindLobbyPlayerIdx(ulong clientId)
/// Looks through all our connections and sees if everyone has locked in their choice;
/// if so, we lock in the whole lobby, save state, and begin the transition to gameplay
/// </summary>
private void CloseLobbyIfReady()
void CloseLobbyIfReady()
{
foreach (CharSelectData.LobbyPlayerState playerInfo in CharSelectData.LobbyPlayers)
{
Expand All @@ -122,10 +121,42 @@ private void CloseLobbyIfReady()
SaveLobbyResults();

// Delay a few seconds to give the UI time to react, then switch scenes
StartCoroutine(WaitToEndLobby());
m_WaitToEndLobbyCoroutine = StartCoroutine(WaitToEndLobby());
}

private void SaveLobbyResults()
/// <summary>
/// Cancels the process of closing the lobby, so that if a new player joins, they are able to chose a character.
/// </summary>
void CancelCloseLobby()
{
if (m_WaitToEndLobbyCoroutine != null)
{
StopCoroutine(m_WaitToEndLobbyCoroutine);
}
CharSelectData.IsLobbyClosed.Value = false;
// Set all players unready so they can react to this cancellation
SetAllUnready();
}

void SetAllUnready()
{
for (int i = 0; i < CharSelectData.LobbyPlayers.Count; ++i)
{
// Set all locked players to active so that they have to confirm their choice again
if (CharSelectData.LobbyPlayers[i].SeatState == CharSelectData.SeatState.LockedIn)
{
CharSelectData.LobbyPlayers[i] = new CharSelectData.LobbyPlayerState(
CharSelectData.LobbyPlayers[i].ClientId,
CharSelectData.LobbyPlayers[i].PlayerName,
CharSelectData.LobbyPlayers[i].PlayerNum,
CharSelectData.SeatState.Active,
CharSelectData.LobbyPlayers[i].SeatIdx,
CharSelectData.LobbyPlayers[i].LastChangeTime);
}
}
}

void SaveLobbyResults()
{
foreach (CharSelectData.LobbyPlayerState playerInfo in CharSelectData.LobbyPlayers)
{
Expand All @@ -141,7 +172,7 @@ private void SaveLobbyResults()
}
}

private IEnumerator WaitToEndLobby()
IEnumerator WaitToEndLobby()
{
yield return new WaitForSeconds(3);
NetworkManager.SceneManager.LoadScene("BossRoom", LoadSceneMode.Single);
Expand Down Expand Up @@ -177,15 +208,15 @@ public override void OnNetworkSpawn()
}
}

private void OnSceneEvent(SceneEvent sceneEvent)
void OnSceneEvent(SceneEvent sceneEvent)
{
// We need to filter out the event that are not a client has finished loading the scene
if (sceneEvent.SceneEventType != SceneEventType.LoadComplete) return;
// When the client finishes loading the Lobby Map, we will need to Seat it
SeatNewPlayer(sceneEvent.ClientId);
}

private int GetAvailablePlayerNumber()
int GetAvailablePlayerNumber()
{
for (int possiblePlayerNumber = 0; possiblePlayerNumber < CharSelectData.k_MaxLobbyPlayers; ++possiblePlayerNumber)
{
Expand Down Expand Up @@ -213,8 +244,14 @@ bool IsPlayerNumberAvailable(int playerNumber)
return !found;
}

private void SeatNewPlayer(ulong clientId)
void SeatNewPlayer(ulong clientId)
{
// If lobby is closing and waiting to start the game, cancel to allow that new player to select a character
if (CharSelectData.IsLobbyClosed.Value)
{
CancelCloseLobby();
}

SessionPlayerData? sessionPlayerData = SessionManager<SessionPlayerData>.Instance.GetPlayerData(clientId);
if (sessionPlayerData.HasValue)
{
Expand All @@ -235,7 +272,7 @@ private void SeatNewPlayer(ulong clientId)
}
}

private void OnClientDisconnectCallback(ulong clientId)
void OnClientDisconnectCallback(ulong clientId)
{
// clear this client's PlayerNumber and any associated visuals (so other players know they're gone).
for (int i = 0; i < CharSelectData.LobbyPlayers.Count; ++i)
Expand All @@ -246,6 +283,19 @@ private void OnClientDisconnectCallback(ulong clientId)
break;
}
}


if (CharSelectData.IsLobbyClosed.Value)
{
// If lobby is closing and waiting to start the game, cancel so that other players can react to it, and
// wait for the player coming back if they want to.
CancelCloseLobby();
}
else
{
// If it is not closing, set everyone as unready for the same reason
SetAllUnready();
}
}
}
}