Skip to content

Commit 2f8b609

Browse files
committed
fixed a time bug
1 parent 3ed59cc commit 2f8b609

5 files changed

Lines changed: 45 additions & 16 deletions

File tree

Basis/Packages/com.basis.framework/BasisUI/Menus/Main Menu Providers/UserListProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Basis.Scripts.Networking.NetworkedAvatar;
55
using System;
66
using System.Collections.Generic;
7+
using Unity.Mathematics;
78
using UnityEngine;
89
using UnityEngine.UI;
910

@@ -542,9 +543,9 @@ private static Vector3 GetRemotePosition(BasisPlayer p)
542543
return p.transform.position;
543544
}
544545

545-
private static string FormatJoinedAgo(float joinTime)
546+
private static string FormatJoinedAgo(double joinTime)
546547
{
547-
float ago = Mathf.Max(0f, Time.realtimeSinceStartup - joinTime);
548+
float ago = (float)math.max(0f, Time.realtimeSinceStartupAsDouble - joinTime);
548549
if (ago < 60f)
549550
return BasisLocalization.Get("menu.players.joinedAgoSeconds", Mathf.FloorToInt(ago));
550551
if (ago < 3600f)

Basis/Packages/com.basis.framework/Networking/BasisNetworkPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public ushort get_playerId()
114114
/// Used to sort the players UI by arrival order and to display "joined Xs ago".
115115
/// Captured here because the server doesn't send a join timestamp.
116116
/// </summary>
117-
public float JoinTime = Time.realtimeSinceStartup;
117+
public double JoinTime = Time.realtimeSinceStartupAsDouble;
118118
public Dictionary<byte, ServerAvatarDataMessageQueue> NextMessages = new Dictionary<byte, ServerAvatarDataMessageQueue>();
119119
public struct ServerAvatarDataMessageQueue
120120
{

Basis/Packages/com.basis.framework/Networking/IServerDirectorySource.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public static void Register(IServerDirectorySource source)
5555

5656
public static void Unregister(string sourceId)
5757
{
58-
if (string.IsNullOrEmpty(sourceId)) return;
58+
if (string.IsNullOrEmpty(sourceId))
59+
{
60+
return;
61+
}
62+
5963
bool removed = false;
6064
lock (_lock)
6165
{
@@ -68,7 +72,11 @@ public static void Unregister(string sourceId)
6872
}
6973
}
7074
}
71-
if (!removed) return;
75+
if (!removed)
76+
{
77+
return;
78+
}
79+
7280
try { SourcesChanged?.Invoke(); }
7381
catch (Exception ex) { BasisDebug.LogError($"SourcesChanged handler threw: {ex.Message}"); }
7482
}

Basis/Packages/com.basis.framework/Networking/SavedServerStore.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,34 @@ public static List<SavedServerEntry> Load()
5454
try
5555
{
5656
string path = Path.Combine(Application.persistentDataPath, FileName);
57-
if (!File.Exists(path)) return new List<SavedServerEntry>();
57+
if (!File.Exists(path))
58+
{
59+
return new List<SavedServerEntry>();
60+
}
61+
5862
string json = File.ReadAllText(path);
5963
SavedServerListWrapper wrapper = JsonUtility.FromJson<SavedServerListWrapper>(json);
60-
if (wrapper == null || wrapper.Entries == null) return new List<SavedServerEntry>();
64+
if (wrapper == null || wrapper.Entries == null)
65+
{
66+
return new List<SavedServerEntry>();
67+
}
68+
6169
foreach (SavedServerEntry e in wrapper.Entries)
6270
{
63-
if (e == null) continue;
64-
if (string.IsNullOrEmpty(e.Id)) e.Id = Guid.NewGuid().ToString("N");
65-
if (e.Port == 0) e.Port = 4296;
71+
if (e == null)
72+
{
73+
continue;
74+
}
75+
76+
if (string.IsNullOrEmpty(e.Id))
77+
{
78+
e.Id = Guid.NewGuid().ToString("N");
79+
}
80+
81+
if (e.Port == 0)
82+
{
83+
e.Port = 4296;
84+
}
6685
}
6786
return wrapper.Entries;
6887
}
@@ -93,8 +112,6 @@ public static void Save(List<SavedServerEntry> entries)
93112
/// and the Server-typed content-share orb so they all parse identically.
94113
/// Returns false if the address segment ends up empty.
95114
/// </summary>
96-
public static bool TryParseConnectionString(
97-
string raw, out string address, out ushort port, out bool portProvided, out string password)
98-
=> LNLConnectionTargetParser.TryParseConnectionString(raw, out address, out port, out portProvided, out password);
115+
public static bool TryParseConnectionString(string raw, out string address, out ushort port, out bool portProvided, out string password) => LNLConnectionTargetParser.TryParseConnectionString(raw, out address, out port, out portProvided, out password);
99116
}
100117
}

Basis/Packages/com.basis.framework/Networking/SavedServersDirectorySource.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public sealed class SavedServersDirectorySource : IServerDirectorySource
2626

2727
public static void Initialize()
2828
{
29-
if (Instance != null) return;
29+
if (Instance != null)
30+
{
31+
return;
32+
}
33+
3034
Instance = new SavedServersDirectorySource();
3135
BasisServerDirectoryRegistry.Register(Instance);
3236
}
@@ -93,7 +97,6 @@ private ServerDirectoryEntry BuildEntry(SavedServerEntry s)
9397
};
9498
}
9599

96-
public static bool IsDefaultEntryId(string id)
97-
=> string.Equals(id, DefaultServerId, StringComparison.OrdinalIgnoreCase);
100+
public static bool IsDefaultEntryId(string id) => string.Equals(id, DefaultServerId, StringComparison.OrdinalIgnoreCase);
98101
}
99102
}

0 commit comments

Comments
 (0)