Skip to content

Commit 36b63c6

Browse files
committed
Fix player name sync and session validation in UI
Improved player name synchronization in SessionPlayerData by introducing an RPC for setting names and ensuring correct authority handling. Updated MainMenuHUDController to properly validate session input and set the local player name before starting the game. Adjusted sun direction values in atmosphere-related material files for consistency.
1 parent fa8a9a7 commit 36b63c6

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

Red Strike/Assets/NetworkingSystem/SessionPlayerData.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace NetworkingSystem
77
public class SessionPlayerData : NetworkBehaviour
88
{
99
[Networked] public NetworkString<_32> SyncedName { get; set; }
10-
10+
1111
private ChangeDetector _changes;
1212

1313
public override void Spawned()
@@ -16,13 +16,20 @@ public override void Spawned()
1616

1717
if (Object.HasInputAuthority)
1818
{
19+
string myName = "Unknown";
20+
1921
if (GameBootstrap.Instance != null)
2022
{
21-
SyncedName = GameBootstrap.Instance.LocalPlayerName;
23+
myName = GameBootstrap.Instance.LocalPlayerName;
24+
}
25+
26+
if (Runner.IsServer)
27+
{
28+
SyncedName = myName;
2229
}
2330
else
2431
{
25-
SyncedName = $"Commander {Object.InputAuthority.PlayerId}";
32+
RPC_SetPlayerName(myName);
2633
}
2734
}
2835

@@ -40,13 +47,21 @@ public override void Render()
4047
}
4148
}
4249

50+
[Rpc(RpcSources.InputAuthority, RpcTargets.StateAuthority)]
51+
public void RPC_SetPlayerName(string name)
52+
{
53+
SyncedName = name;
54+
}
55+
4356
private void UpdateHUD()
4457
{
58+
if (string.IsNullOrEmpty(SyncedName.ToString())) return;
59+
4560
var hud = FindFirstObjectByType<DeploymentMonitorHUDController>();
46-
4761
if (hud != null)
4862
{
49-
int playerIndex = (Object.InputAuthority.PlayerId == 1) ? 1 : 2;
63+
int playerIndex = (Object.InputAuthority.PlayerId == 1) ? 1 : 2;
64+
5065
hud.UpdatePlayerName(playerIndex, SyncedName.ToString());
5166
}
5267
}

Red Strike/Assets/PlanetAtmosphereSystem/AtmosphereMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Material:
4747
- _GunesYonu: {r: -0.91, g: 0.4, b: 3.24, a: 0}
4848
- _RenkUzak: {r: 0, g: 0.10166844, b: 2.152374, a: 1}
4949
- _RenkYakin: {r: 0, g: 5.670685, b: 8, a: 1}
50-
- _SunDirection: {r: -0.057937633, g: -0.926762, b: 0.37115443, a: 0}
50+
- _SunDirection: {r: 0.0022653043, g: 0.99991494, b: -0.012847154, a: 0}
5151
m_BuildTextureStacks: []
5252
m_AllowLocking: 1
5353
--- !u!114 &1522106816477559216

Red Strike/Assets/PlanetAtmosphereSystem/CloudMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Material:
4343
m_Colors:
4444
- _Color: {r: 0, g: 3.8274493, b: 5.992155, a: 1}
4545
- _GunesYonu: {r: -1, g: 0, b: 0, a: 0}
46-
- _SunDirection: {r: -0.057937633, g: -0.926762, b: 0.37115443, a: 0}
46+
- _SunDirection: {r: 0.0022653043, g: 0.99991494, b: -0.012847154, a: 0}
4747
m_BuildTextureStacks: []
4848
m_AllowLocking: 1
4949
--- !u!114 &8499732345945835446

Red Strike/Assets/PlanetAtmosphereSystem/FogMaterial.mat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ Material:
5454
- _QueueControl: 0
5555
- _QueueOffset: 0
5656
m_Colors:
57-
- _SunDirection: {r: -0.057937633, g: -0.926762, b: 0.37115443, a: 0}
57+
- _SunDirection: {r: 0.0022653043, g: 0.99991494, b: -0.012847154, a: 0}
5858
m_BuildTextureStacks: []
5959
m_AllowLocking: 1

Red Strike/Assets/UISystem/MainMenuHUDController.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,11 @@ private void OnStartHostClicked()
278278
private void OnStartClientClicked()
279279
{
280280
string session = inputSessionName?.value;
281-
if (string.IsNullOrEmpty(session))
281+
if (!string.IsNullOrEmpty(session))
282282
{
283-
SetLobbyStatus("INVALID SESSION ID", Color.red);
284-
return;
283+
SetLobbyStatus("SEARCHING UPLINK...", Color.yellow);
285284
}
286-
SetLobbyStatus("SEARCHING UPLINK...", Color.yellow);
285+
GameBootstrap.Instance.LocalPlayerName = userManager?.currentUser.userName ?? "Unknown";
287286
GameBootstrap.Instance?.StartGame(GameMode.Client, session);
288287
}
289288

0 commit comments

Comments
 (0)