SanAndreasUnity/Assets/Scripts/Networking/CustomNetworkManager.cs
Lukas 0445f29dfd
Feature/mirror upgrade (#127)
* Updated SyncDictionary usage in SyncedBag.cs

- Removed the extra class that is no longer needed for SyncDictionary's
- Removed OP codes (OP_DIRTY) switch case that no longer exists (superseded by OP_SET)

Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com>

* Updated method names

Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com>

* Updated more string sync dictionaries

Ped_Networking.cs
VehicleController.cs
Player.cs
SyncedServerData.cs

Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com>

* Updated NetworkTime fields in NetStats.cs

Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com>

* Updated syncData types

Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com>

* Implemented conditional compilation to replace old isHeadless

Signed-off-by: Lukas Olson <lukasolson@greyblockgames.com>

* Updated hooks

* A few more syncDictionary upgrades

* Moved away from obsolete NetworkIdentity.spawned

* Updated SetDirtyBit to SetSyncVarDirtyBit in DeadBody.cs

* Updated ScriptingDefineSymbols for Mirror

* Updated JoinGameWindow.cs

* Use latest MirrorLite commit for submodule

* Use latest MirrorLite commit for submodule

* Reverted EditorSettings.asset to commit b1c9d38e3a

* Reverted JoinGameWindow.cs to commit b1c9d38e3a

* Changed method for headless mode in NetCmdLineHandler.cs

Changed from compiler defs to SanAndreasUnity helpers for determining headless mode in NetCmdLineHandler.cs

* Re-Added ConfigureHeadlessFrameRate override on CustomNetworkManager.cs

* Started updating JoinGameWindow.cs

- Commented out GUI errors
- Updated type 'DiscoveryInfo' to 'ServerResponse' in method ConnectFromDiscovery() params.
- Updated Connect() 'port' parameter to use type 'int' rather than 'ushort' as per Mirror conventions.

Co-authored-by: Lukas Olson <lukasolson@greyblockgames.com>
2022-04-02 20:15:08 +02:00

80 lines
No EOL
2.2 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using SanAndreasUnity.Utilities;
using SanAndreasUnity.Behaviours;
namespace SanAndreasUnity.Net
{
public class CustomNetworkManager : NetworkManager
{
public override void OnClientConnect()
{
if (NetStatus.IsServer)
{
// just do default action
base.OnClientConnect();
return;
}
// default method: if no scene was loaded, do Ready/AddPlayer
// we won't do this until loading process finishes
if (Loader.HasLoaded)
base.OnClientConnect();
}
public override void OnClientSceneChanged()
{
if (NetStatus.IsServer)
{
// just do default action
base.OnClientSceneChanged();
return;
}
// default method: do Ready/AddPlayer
// we won't do this until loading process finishes
if (Loader.HasLoaded)
base.OnClientSceneChanged();
}
void OnLoaderFinished()
{
if (F.IsAppInEditMode)
return;
if (NetStatus.IsServer) // don't do anything on server
return;
if (!NetworkClient.isConnected)
{
// client is not connected ? hmm... then loading process could not have started
Debug.LogErrorFormat("Loader finished, but client is not connected");
return;
}
// make client ready
if (NetworkClient.ready)
Debug.LogErrorFormat("Client was made ready before loader finished");
else
{
NetworkClient.Ready();
}
// add player if specified
if (autoCreatePlayer && NetworkClient.localPlayer == null)
{
NetworkClient.AddPlayer();
}
}
public override void ConfigureHeadlessFrameRate()
{
//Overriden so that other scripts can set the framerate without Mirror overriding it.
}
}
}