Skip to content

Commit

Permalink
Handle disconnect and server/client stop
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed May 29, 2024
1 parent 0925ad7 commit 9066e9d
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 254 deletions.
2 changes: 1 addition & 1 deletion Assets/Scenes/CraterTown.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 662445327}
m_IndirectSpecularColor: {r: 0.062285002, g: 0.21922584, b: 0.4949425, a: 1}
m_IndirectSpecularColor: {r: 0.062542364, g: 0.2194215, b: 0.49499997, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down
14 changes: 1 addition & 13 deletions Assets/Scenes/Menu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 785370674}
m_IndirectSpecularColor: {r: 0.062482566, g: 0.21938902, b: 0.4950583, a: 1}
m_IndirectSpecularColor: {r: 0.062451348, g: 0.21931733, b: 0.49487647, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -416,18 +416,6 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 3717336014748129540, guid: 0e2ad36662a02c3488301a5286b27635, type: 3}
propertyPath: startingBody
value:
objectReference: {fileID: 11400000, guid: 0abfdcb5f304f2647b378f82907d538c, type: 2}
- target: {fileID: 3717336014748129540, guid: 0e2ad36662a02c3488301a5286b27635, type: 3}
propertyPath: startingBarrel
value:
objectReference: {fileID: 11400000, guid: 9c1da148c8d07ab428c6bc9a70aecae8, type: 2}
- target: {fileID: 3717336014748129540, guid: 0e2ad36662a02c3488301a5286b27635, type: 3}
propertyPath: startingExtension
value:
objectReference: {fileID: 11400000, guid: 2c332edf0b10a07489ea78f82b8f7045, type: 2}
- target: {fileID: 8579357797008554893, guid: 0e2ad36662a02c3488301a5286b27635, type: 3}
propertyPath: m_Name
value: StaticInfo
Expand Down
18 changes: 11 additions & 7 deletions Assets/Scenes/TrainingMode.unity
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b18a938eb13d13540b14e958b874d1b0, type: 3}
m_Name:
m_EditorClassIdentifier:
playerPrefab: {fileID: 2770875744502568649, guid: 1ccbc17fde8c55a21ac6331f0517f402, type: 3}
spawnPoints:
- {fileID: 1104924655}
playerSelectItemPrefab: {fileID: 0}
aIOpponent: {fileID: 0}
aIBidder: {fileID: 0}
aiIdentity: {fileID: 0}
globalHUDController: {fileID: 0}
overrideMatchManager: 1
--- !u!4 &168459266
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -4278,6 +4272,10 @@ PrefabInstance:
propertyPath: m_ConstrainProportionsScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 508678544827238946, guid: e795d78bc3458864bad12d1dc75182fb, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1245620792704334073, guid: e795d78bc3458864bad12d1dc75182fb, type: 3}
propertyPath: m_Materials.Array.size
value: 1
Expand All @@ -4294,7 +4292,13 @@ PrefabInstance:
propertyPath: m_Mesh
value:
objectReference: {fileID: 962209921104072034, guid: 96e02cb082c4f82d495b4b45861a50f6, type: 3}
m_RemovedComponents: []
- target: {fileID: 5543259695900803521, guid: e795d78bc3458864bad12d1dc75182fb, type: 3}
propertyPath: m_IsTrigger
value: 1
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 508678544827238946, guid: e795d78bc3458864bad12d1dc75182fb, type: 3}
- {fileID: 3873721530690488933, guid: e795d78bc3458864bad12d1dc75182fb, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Augment/AugmentImplementations/Fire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void AddFireToProjectile(GunStats gunstats)

private void PlayShotAudio(GunStats stats)
{
if (!gunController)
if (!gunController || !audioSource)
return;
audioSource.clip = lighterSounds.RandomElement();
audioSource.Play();
Expand Down
1 change: 0 additions & 1 deletion Assets/Scripts/Augment/BulletController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private void Start()
[ClientRpc]
private void RpcSeedRandom(int seed)
{
Debug.Log($"Seed {seed}");
random = new Random(seed);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private void Start()
[ClientRpc]
private void RpcSeedRandom(int seed)
{
Debug.Log($"Seed {seed}");
random = new System.Random(seed);
}

Expand Down
4 changes: 0 additions & 4 deletions Assets/Scripts/Augment/GunController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ private void CmdFire(Quaternion rotation)
private void RpcFire(Quaternion rotation)
{
onFireStart?.Invoke(stats);
// TODO does this work? if so, remove output
//if (authority)
//projectile.projectileOutput = outputs[0];
//projectile.projectileOutput = outputs[0];
projectile.projectileOutput = outputs[0];
projectile.projectileRotation = rotation;
ActuallyFire();
Expand Down
42 changes: 24 additions & 18 deletions Assets/Scripts/Control&Input/ItemSelectManager.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Mirror;
using UnityEngine;

// TODO remove first two structs if unused
internal struct StartTrackingMessage : NetworkMessage
{
}

internal struct ReadyToTrackMessage : NetworkMessage
{
}

internal struct ClientReadyMessage : NetworkMessage
{
}
Expand Down Expand Up @@ -45,27 +37,29 @@ public void StartTrackingMenus()

if (isServer)
{
InitializeServerData();
NetworkServer.RegisterHandler<ClientReadyMessage>(OnClientReady);
NetworkServer.RegisterHandler<ClientNotReadyMessage>(OnClientNotReady);
InitializeServerState();
}
}

private void InitializeServerState()
{
clientReadyByID = Peer2PeerTransport.Connections
.ToDictionary(c => c.connectionId, c => false);
((Peer2PeerTransport)NetworkManager.singleton).OnDisconnect += OnDisconnect;
NetworkServer.RegisterHandler<ClientReadyMessage>(OnClientReady);
NetworkServer.RegisterHandler<ClientNotReadyMessage>(OnClientNotReady);
}

private void OnDestroy()
{
if (isServer)
{
((Peer2PeerTransport)Peer2PeerTransport.singleton).OnDisconnect -= OnDisconnect;
NetworkServer.UnregisterHandler<ClientReadyMessage>();
NetworkServer.UnregisterHandler<ClientNotReadyMessage>();
}
}

private void InitializeServerData()
{
clientReadyByID = Peer2PeerTransport.Connections
.ToDictionary(c => c.connectionId, c => false);
}

[Server]
private void Finish()
{
Expand All @@ -75,6 +69,7 @@ private void Finish()
[ClientRpc]
private void RpcFinish()
{
((Peer2PeerTransport)Peer2PeerTransport.singleton).UpdateLoadout();
StartCoroutine(MatchController.Singleton.WaitAndStartNextRound());
}

Expand Down Expand Up @@ -107,9 +102,20 @@ private void OnClientNotReady(NetworkConnectionToClient connection, ClientNotRea
}
}

private void OnDisconnect(int connectionID)
{
clientReadyByID.Remove(connectionID);
CheckIfAllAreReady();
}

private void OnClientReady(NetworkConnectionToClient connection, ClientReadyMessage message)
{
clientReadyByID[connection.connectionId] = true;
CheckIfAllAreReady();
}

private void CheckIfAllAreReady()
{
var allClientsAreReady = clientReadyByID.Values.All(m => m);
if (allClientsAreReady)
{
Expand Down
3 changes: 1 addition & 2 deletions Assets/Scripts/Control&Input/ItemSelectMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using TMPro;
using SecretName;

public class ItemSelectMenu : MonoBehaviour
Expand Down Expand Up @@ -60,7 +59,7 @@ public class ItemSelectMenu : MonoBehaviour

private AugmentType selectedType = AugmentType.Body;

private ItemSelectSlot selectedSlot => (selectedType) switch
private ItemSelectSlot selectedSlot => selectedType switch
{
AugmentType.Body => bodySlot,
AugmentType.Barrel => barrelSlot,
Expand Down
Loading

0 comments on commit 9066e9d

Please sign in to comment.