Skip to content

Commit

Permalink
Fix a null reference in mob.ckey assignment (#2102)
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit authored Nov 19, 2024
1 parent 3b37b1c commit 8b4e62f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
11 changes: 6 additions & 5 deletions OpenDreamRuntime/DreamConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public sealed class DreamConnection {

[ViewVariables] public ICommonSession? Session { get; private set; }
[ViewVariables] public DreamObjectClient? Client { get; private set; }
[ViewVariables]
public DreamObjectMob? Mob {
[ViewVariables] public string Key { get; private set; }

[ViewVariables] public DreamObjectMob? Mob {
get => _mob;
set {
if (_mob != value) {
Expand Down Expand Up @@ -61,8 +62,7 @@ public DreamObjectMob? Mob {
}
}

[ViewVariables]
public DreamObjectMovable? Eye {
[ViewVariables] public DreamObjectMovable? Eye {
get => _eye;
set {
_eye = value;
Expand Down Expand Up @@ -93,8 +93,9 @@ public string? SelectedStatPanel {
}
}

public DreamConnection() {
public DreamConnection(string key) {
IoCManager.InjectDependencies(this);
Key = key;

_entitySystemManager.TryGetEntitySystem(out _screenOverlaySystem);
_entitySystemManager.TryGetEntitySystem(out _clientImagesSystem);
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/DreamManager.Connections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e) {

case SessionStatus.InGame: {
if (!_connections.TryGetValue(e.Session.UserId, out var connection)) {
connection = new DreamConnection();
connection = new DreamConnection(e.Session.Name);

_connections.Add(e.Session.UserId, connection);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Objects/DreamObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public string GetDisplayName(StringFormatEncoder.FormatSuffix? suffix = null) {
// /client is a little special and will return its key var
// TODO: Maybe this should be an override to GetDisplayName()?
if (this is DreamObjectClient client)
return client.Connection.Session!.Name;
return client.Connection.Key;

var name = GetRawName();
bool isProper = StringIsProper(name);
Expand Down
6 changes: 3 additions & 3 deletions OpenDreamRuntime/Objects/Types/DreamObjectClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ protected override void HandleDeletion(bool possiblyThreaded) {
protected override bool TryGetVar(string varName, out DreamValue value) {
switch (varName) {
case "ckey":
value = new(DreamProcNativeHelpers.Ckey(Connection.Session!.Name));
value = new(DreamProcNativeHelpers.Ckey(Connection.Key));
return true;
case "key":
value = new(Connection.Session!.Name);
value = new(Connection.Key);
return true;
case "mob":
value = new(Connection.Mob);
Expand All @@ -68,7 +68,7 @@ protected override bool TryGetVar(string varName, out DreamValue value) {
MD5 md5 = MD5.Create();
// Check on Robust.Shared.Network.NetUserData.HWId" if you want to seed from how RT does user identification.
// We don't use it here because it is probably not enough to ensure security, and (as of time of writing) only works on Windows machines.
byte[] brown = Encoding.UTF8.GetBytes(Connection.Session!.Name);
byte[] brown = Encoding.UTF8.GetBytes(Connection.Key);
byte[] hash = md5.ComputeHash(brown);
string hashStr = BitConverter.ToString(hash).Replace("-", "").ToLower().Substring(0,15); // Extracting the first 15 digits to ensure it'll fit in a 64-bit number

Expand Down
3 changes: 1 addition & 2 deletions OpenDreamRuntime/Objects/Types/DreamObjectMob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ protected override void SetVar(string varName, DreamValue value) {
Key = DreamProcNativeHelpers.Ckey(Key);

foreach (var connection in DreamManager.Connections) {
if (DreamProcNativeHelpers.Ckey(connection.Session!.Name) == Key) {
if (DreamProcNativeHelpers.Ckey(connection.Key) == Key) {
connection.Mob = this;
break;
}
}


break;
case "see_invisible":
value.TryGetValueAsInteger(out int seeVis);
Expand Down

0 comments on commit 8b4e62f

Please sign in to comment.