Skip to content

Commit

Permalink
Fix ICommonSession.Ping
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr committed Sep 20, 2024
1 parent c86cb0b commit ab8594b
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ END TEMPLATE-->

### Bugfixes

*None yet*
* Fixed `ICommonSession.Ping` always returning zero instead of the ping. Note that this will still return zero for client-side code when trying to get the ping of other players.

### Other

Expand Down
3 changes: 0 additions & 3 deletions Robust.Client/Player/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ private bool UpdatePlayerList(IEnumerable<SessionState> remotePlayers, bool full
// This is a new userid, so we create a new session.
DebugTools.Assert(state.UserId != LocalPlayer?.UserId);
var newSession = (ICommonSessionInternal)CreateAndAddSession(state.UserId, state.Name);
newSession.SetPing(state.Ping);
SetStatus(newSession, state.Status);
SetAttachedEntity(newSession, controlled, out _, true);
dirty = true;
Expand All @@ -271,7 +270,6 @@ private bool UpdatePlayerList(IEnumerable<SessionState> remotePlayers, bool full
// Check if the data is actually different
if (session.Name == state.Name
&& session.Status == state.Status
&& session.Ping == state.Ping
&& session.AttachedEntity == controlled)
{
continue;
Expand All @@ -280,7 +278,6 @@ private bool UpdatePlayerList(IEnumerable<SessionState> remotePlayers, bool full
dirty = true;
var local = (ICommonSessionInternal)session;
local.SetName(state.Name);
local.SetPing(state.Ping);
SetStatus(local, state.Status);
SetAttachedEntity(local, controlled, out _, true);
}
Expand Down
3 changes: 1 addition & 2 deletions Robust.Server/Player/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ private void HandlePlayerListReq(MsgPlayerListReq message)
{
UserId = client.UserId,
Name = client.Name,
Status = client.Status,
Ping = client.Channel!.Ping
Status = client.Status
};
list.Add(info);
}
Expand Down
5 changes: 4 additions & 1 deletion Robust.Shared/GameStates/SessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public sealed class SessionState
[ViewVariables]
public SessionStatus Status { get; set; }

// TODO PlayerManager
// Network ping information, though probably do it outside of SessionState to avoid re-sending the name and such
// for all players every few seconds.
[Obsolete("Ping data is not currently networked")]
[ViewVariables]
public short Ping { get; set; }

Expand All @@ -34,7 +38,6 @@ public SessionState Clone()
UserId = UserId,
Name = Name,
Status = Status,
Ping = Ping,
ControlledEntity = ControlledEntity
};
}
Expand Down
2 changes: 0 additions & 2 deletions Robust.Shared/Network/Messages/MsgPlayerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer
UserId = new NetUserId(buffer.ReadGuid()),
Name = buffer.ReadString(),
Status = (SessionStatus)buffer.ReadByte(),
Ping = buffer.ReadInt16()
};
Plyrs.Add(plyNfo);
}
Expand All @@ -40,7 +39,6 @@ public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer
buffer.Write(ply.UserId.UserId);
buffer.Write(ply.Name);
buffer.Write((byte) ply.Status);
buffer.Write(ply.Ping);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion Robust.Shared/Player/CommonSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ internal sealed class CommonSession : ICommonSessionInternal
public string Name { get; set; } = "<Unknown>";

[ViewVariables]
public short Ping { get; set; }
public short Ping
{
get => Channel?.Ping ?? _ping;
set => _ping = value;
}
private short _ping;

[ViewVariables]
public DateTime ConnectedTime { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion Robust.Shared/Player/ICommonSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ public interface ICommonSession
string Name { get; }

/// <summary>
/// Current connection latency of this session from the server to their client.
/// Current connection latency of this session. If <see cref="Channel"/> is not null this simply returns
/// <see cref="INetChannel.Ping"/>. This is not currently usable by client-side code that wants to try access ping
/// information of other players.
/// </summary>
short Ping { get; }
// TODO PlayerManager ping networking.

/// <summary>
/// The current network channel for this session.
Expand Down
3 changes: 3 additions & 0 deletions Robust.Shared/Player/SharedPlayerManager.State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public void GetPlayerStates(GameTick fromTick, List<SessionState> states)
if (LastStateUpdate < fromTick)
return;

// TODO PlayerManager delta states
// Track last update tick/time per session, and only send sessions that actually changed.

states.EnsureCapacity(InternalSessions.Count);
foreach (var player in InternalSessions.Values)
{
Expand Down

0 comments on commit ab8594b

Please sign in to comment.