using System; using System.Collections.Generic; using UnityEngine; using Mirror; public class ServerMainController : MonoBehaviour { [Header("Status")] public string password = null; public List players; public List viewers; public GamePhase phase = GamePhase.UNINTIALIZED; [Header("Constants")] public const int MAX_CONNECTIONS = 32; public void ServerStart() { phase = GamePhase.LOBBY; NetworkServer.RegisterHandler(OnPlayerJoin); NetworkServer.RegisterHandler(OnViewerLink); NetworkServer.RegisterHandler(OnGameSettings); NetworkServer.RegisterHandler(OnActResults); NetworkServer.Listen(MAX_CONNECTIONS); } public void OnPlayerJoin(NetworkConnection connection, NetMessage.Connect.PlayerJoin message) { if(message.gamePassword != password) { connection.Send(new NetMessage.Error.InvalidPassword()); return; } Player newPlayer = new Player(message.playerName, new Guid()); players.Add(newPlayer); NetMessage.Connect.PlayerJoinSuccessful reply = new NetMessage.Connect.PlayerJoinSuccessful { player = newPlayer }; connection.Send(reply); } public void OnViewerLink(NetworkConnection connection, NetMessage.Connect.ViewerLink message) { if(message.gamePassword != password) { connection.Send(new NetMessage.Error.InvalidPassword()); return; } Viewer newViewer = new Viewer(new Guid()); viewers.Add(newViewer); NetMessage.Connect.ViewerLinkSuccessful reply = new NetMessage.Connect.ViewerLinkSuccessful { viewer = newViewer }; connection.Send(reply); } public void OnGameSettings(NetworkConnection connection, NetMessage.Game.Settings message) {} public void OnActResults(NetworkConnection connection, NetMessage.Act.Results message) {} }