Skip to content
Open
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
36 changes: 27 additions & 9 deletions Robust.Server/Player/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public override void Initialize(int maxPlayers)
_network.Connecting += OnConnecting;
_network.Connected += NewSession;
_network.Disconnect += EndSession;
PlayerStatusChanged += OnPlayerStatusChanged;
}

public override void Shutdown()
Expand All @@ -61,6 +62,7 @@ public override void Shutdown()
_network.Connecting -= OnConnecting;
_network.Connected -= NewSession;
_network.Disconnect -= EndSession;
PlayerStatusChanged -= OnPlayerStatusChanged;
}

private Task OnConnecting(NetConnectingArgs args)
Expand Down Expand Up @@ -126,7 +128,7 @@ private void HandlePlayerListReq(MsgPlayerListReq message)
if (!session.InitialResourcesDone)
return;

SendPlayerList(channel, session);
CompleteConnecting(session);
}

public void MarkPlayerResourcesSent(INetChannel channel)
Expand All @@ -137,19 +139,35 @@ public void MarkPlayerResourcesSent(INetChannel channel)
if (!session.InitialPlayerListReqDone)
return;

SendPlayerList(channel, session);
CompleteConnecting(session);
}

private void SendPlayerList(INetChannel channel, CommonSession session)
// transition the session to connected now,
// player list is deferred until the session reaches InGame
private void CompleteConnecting(CommonSession session)
{
var players = Sessions;
var netMsg = new MsgPlayerList();

// client session is complete, set their status accordingly.
// This is done before the packet is built, so that the client
// can see themselves Connected.
session.ConnectedTime = DateTime.UtcNow;
SetStatus(session, SessionStatus.Connected);
session.InitialPlayerListPending = true;
}

private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
{
if (e.NewStatus != SessionStatus.InGame)
return;

var session = (CommonSession) e.Session;
if (!session.InitialPlayerListPending)
return;

session.InitialPlayerListPending = false;
SendPlayerList(session.Channel);
}

private void SendPlayerList(INetChannel channel)
{
var players = Sessions;
var netMsg = new MsgPlayerList();

var list = new List<SessionState>();
foreach (var client in players)
Expand Down
2 changes: 2 additions & 0 deletions Robust.Shared/Player/CommonSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public short Ping
public bool InitialPlayerListReqDone;
[ViewVariables]
public bool InitialResourcesDone;
[ViewVariables]
public bool InitialPlayerListPending;

public override string ToString() => Name;

Expand Down
Loading