mirror of
https://github.com/Steffo99/better-tee.git
synced 2024-11-27 17:14:18 +00:00
Commit changes
This commit is contained in:
parent
40dbe98652
commit
ad95c93b3a
11 changed files with 205 additions and 72 deletions
|
@ -36,6 +36,9 @@ public abstract class ActController : MonoBehaviour
|
|||
public virtual void ActInit() {
|
||||
phase = ActPhase.INIT;
|
||||
|
||||
canvas = GameObject.FindGameObjectWithTag("Canvas")?.GetComponent<Canvas>();
|
||||
eventSystem = GameObject.FindGameObjectWithTag("EventSystem")?.GetComponent<EventSystem>();
|
||||
|
||||
if(settings == null) {
|
||||
throw new MissingSettingsException();
|
||||
}
|
||||
|
@ -72,9 +75,7 @@ public abstract class ActController : MonoBehaviour
|
|||
}
|
||||
|
||||
protected virtual void Start() {
|
||||
canvas = GameObject.FindGameObjectWithTag("Canvas")?.GetComponent<Canvas>();
|
||||
eventSystem = GameObject.FindGameObjectWithTag("EventSystem")?.GetComponent<EventSystem>();
|
||||
ActInit();
|
||||
|
||||
}
|
||||
|
||||
protected virtual void Update() {
|
||||
|
|
7
Assets/Code/GamePhase.cs
Normal file
7
Assets/Code/GamePhase.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
public enum GamePhase {
|
||||
UNINTIALIZED,
|
||||
LOBBY,
|
||||
ACTS,
|
||||
RESULTS,
|
||||
ENDED
|
||||
}
|
12
Assets/Code/GameSettings.cs
Normal file
12
Assets/Code/GameSettings.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class GameSettings
|
||||
{
|
||||
public string gameName;
|
||||
public List<ActSettings> acts;
|
||||
public int minimumPlayers = 0;
|
||||
public int maximumPlayers = 8;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 26964efd4b147744fb4bb183d75abaa6
|
||||
guid: 26d9ed1fc6252ef45bc911937e14f5ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
78
Assets/Code/NetMessage.cs
Normal file
78
Assets/Code/NetMessage.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using Mirror;
|
||||
|
||||
|
||||
namespace NetMessage
|
||||
{
|
||||
namespace Error
|
||||
{
|
||||
public class InvalidPassword : MessageBase {}
|
||||
}
|
||||
|
||||
namespace Connect
|
||||
{
|
||||
public class PlayerJoin : MessageBase
|
||||
{
|
||||
public string playerName;
|
||||
public string gamePassword;
|
||||
}
|
||||
|
||||
public class PlayerJoinSuccessful : MessageBase
|
||||
{
|
||||
public Player player;
|
||||
|
||||
public PlayerJoinSuccessful(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
public class ViewerLink : MessageBase
|
||||
{
|
||||
public string gamePassword;
|
||||
}
|
||||
|
||||
public class ViewerLinkSuccessful : MessageBase
|
||||
{
|
||||
public Viewer viewer;
|
||||
|
||||
public ViewerLinkSuccessful(Viewer viewer) {
|
||||
this.viewer = viewer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public class Settings : MessageBase
|
||||
{
|
||||
public GameSettings settings;
|
||||
}
|
||||
|
||||
public class Start : MessageBase
|
||||
{
|
||||
public Player[] players;
|
||||
}
|
||||
|
||||
public class End : MessageBase
|
||||
{
|
||||
public Player[] leaderboard;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Act
|
||||
{
|
||||
public class Init : MessageBase
|
||||
{
|
||||
public ActSettings settings;
|
||||
}
|
||||
|
||||
public class Start : MessageBase {}
|
||||
|
||||
public class Results : MessageBase
|
||||
{
|
||||
public ActResults results;
|
||||
}
|
||||
|
||||
public class End : MessageBase {}
|
||||
}
|
||||
}
|
11
Assets/Code/NetMessage.cs.meta
Normal file
11
Assets/Code/NetMessage.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 772d776767c9da042a636c466296b9e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,48 +0,0 @@
|
|||
using System;
|
||||
using Mirror;
|
||||
|
||||
|
||||
namespace NetMessages {
|
||||
|
||||
public class ErrorMessage : MessageBase
|
||||
{
|
||||
public string errorName;
|
||||
public string errorDescription = "";
|
||||
}
|
||||
|
||||
public class PlayerConnectionMessage : MessageBase
|
||||
{
|
||||
public string playerName;
|
||||
public string gamePassword;
|
||||
}
|
||||
|
||||
public class ViewerConnectionMessage : MessageBase
|
||||
{
|
||||
public string gamePassword;
|
||||
}
|
||||
|
||||
public class ConnectionSuccessfulResponse : MessageBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class GameStartMessage : MessageBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ActSettingsMessage : MessageBase
|
||||
{
|
||||
public ActSettings settings;
|
||||
}
|
||||
|
||||
public class ActResultsMessage : MessageBase
|
||||
{
|
||||
public ActResults results;
|
||||
}
|
||||
|
||||
public class ActEndNotification : MessageBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
12
Assets/Code/Player.cs
Normal file
12
Assets/Code/Player.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
[Serializable]
|
||||
public struct Player {
|
||||
public string name;
|
||||
public Guid guid;
|
||||
|
||||
public Player(string name, Guid guid) {
|
||||
this.name = name;
|
||||
this.guid = guid;
|
||||
}
|
||||
}
|
|
@ -5,8 +5,14 @@ using Mirror;
|
|||
|
||||
public class PlayerMainController : MonoBehaviour
|
||||
{
|
||||
[Header("WIP")]
|
||||
public string address = "127.0.0.1:44444";
|
||||
void Start() {
|
||||
ConnectToServer(address);
|
||||
}
|
||||
|
||||
[Header("Objects")]
|
||||
public ActController currentAct;
|
||||
public ActController currentAct = null;
|
||||
|
||||
[Header("Prefabs")]
|
||||
public GameObject drawingControllerPrefab;
|
||||
|
@ -34,18 +40,38 @@ public class PlayerMainController : MonoBehaviour
|
|||
|
||||
public void ConnectToServer(string address) {
|
||||
NetworkClient.Connect(address);
|
||||
NetworkClient.RegisterHandler<NetMessages.ConnectionSuccessfulResponse>(OnConnectionSuccessful);
|
||||
NetworkClient.RegisterHandler<NetMessages.GameStartMessage>(OnGameStart);
|
||||
NetworkClient.RegisterHandler<NetMessages.ActSettingsMessage>(OnActSettings);
|
||||
NetworkClient.RegisterHandler<NetMessages.ActEndNotification>(OnActEnd);
|
||||
NetworkClient.RegisterHandler<NetMessage.Connect.PlayerJoinSuccessful>(OnPlayerJoinSuccessful);
|
||||
NetworkClient.RegisterHandler<NetMessage.Game.Settings>(OnGameSettings);
|
||||
NetworkClient.RegisterHandler<NetMessage.Game.Start>(OnGameStart);
|
||||
NetworkClient.RegisterHandler<NetMessage.Game.End>(OnGameEnd);
|
||||
NetworkClient.RegisterHandler<NetMessage.Act.Init>(OnActInit);
|
||||
NetworkClient.RegisterHandler<NetMessage.Act.Start>(OnActStart);
|
||||
NetworkClient.RegisterHandler<NetMessage.Act.End>(OnActEnd);
|
||||
}
|
||||
|
||||
public void OnConnectionSuccessful(NetworkConnection connection, NetMessages.ConnectionSuccessfulResponse message) {}
|
||||
public void OnGameStart(NetworkConnection connection, NetMessages.GameStartMessage message) {}
|
||||
public void OnActEnd(NetworkConnection connection, NetMessages.ActEndNotification message) {}
|
||||
protected void OnPlayerJoinSuccessful(NetworkConnection connection, NetMessage.Connect.PlayerJoinSuccessful message) {}
|
||||
|
||||
public void OnActSettings(NetworkConnection connection, NetMessages.ActSettingsMessage message) {
|
||||
protected void OnGameSettings(NetworkConnection connection, NetMessage.Game.Settings message) {}
|
||||
|
||||
protected void OnGameStart(NetworkConnection connection, NetMessage.Game.Start message) {}
|
||||
|
||||
protected void OnGameEnd(NetworkConnection connection, NetMessage.Game.End message) {}
|
||||
|
||||
protected void OnActInit(NetworkConnection connection, NetMessage.Act.Init message) {
|
||||
LoadAct(message.settings);
|
||||
currentAct.ActInit();
|
||||
}
|
||||
|
||||
protected void OnActStart(NetworkConnection connection, NetMessage.Act.Start message) {
|
||||
currentAct.ActStart();
|
||||
}
|
||||
|
||||
protected void OnActEnd(NetworkConnection connection, NetMessage.Act.End message) {
|
||||
currentAct.ActEnd();
|
||||
//SEND RESULTS HERE
|
||||
|
||||
//test this
|
||||
Destroy(currentAct);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,24 +1,48 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class ServerMainController : MonoBehaviour
|
||||
{
|
||||
[Header("Status")]
|
||||
public bool isListening = false;
|
||||
public string password = null;
|
||||
public List<Player> players;
|
||||
public List<Viewer> viewers;
|
||||
public GamePhase phase = GamePhase.UNINTIALIZED;
|
||||
|
||||
[Header("Constants")]
|
||||
public const int MAX_CONNECTIONS = 32;
|
||||
|
||||
public void ServerStart() {
|
||||
phase = GamePhase.LOBBY;
|
||||
NetworkServer.Listen(MAX_CONNECTIONS);
|
||||
NetworkServer.RegisterHandler<NetMessages.PlayerConnectionMessage>(OnPlayerConnect);
|
||||
NetworkServer.RegisterHandler<NetMessages.ViewerConnectionMessage>(OnViewerConnect);
|
||||
NetworkServer.RegisterHandler<NetMessages.ActResultsMessage>(OnActResults);
|
||||
isListening = true;
|
||||
NetworkServer.RegisterHandler<NetMessage.Connect.PlayerJoin>(OnPlayerJoin);
|
||||
NetworkServer.RegisterHandler<NetMessage.Connect.ViewerLink>(OnViewerLink);
|
||||
NetworkServer.RegisterHandler<NetMessage.Game.Settings>(OnGameSettings);
|
||||
NetworkServer.RegisterHandler<NetMessage.Act.Results>(OnActResults);
|
||||
}
|
||||
|
||||
public void OnPlayerConnect(NetworkConnection connection, NetMessages.PlayerConnectionMessage message) {}
|
||||
public void OnViewerConnect(NetworkConnection connection, NetMessages.ViewerConnectionMessage message) {}
|
||||
public void OnActResults(NetworkConnection connection, NetMessages.ActResultsMessage message) {}
|
||||
public void OnPlayerJoin(NetworkConnection connection, NetMessage.Connect.PlayerJoin message) {
|
||||
if(message.gamePassword != password) {
|
||||
connection.Send<NetMessage.Error.InvalidPassword>(new NetMessage.Error.InvalidPassword());
|
||||
return;
|
||||
}
|
||||
Player newPlayer = new Player(message.playerName, new Guid());
|
||||
players.Add(newPlayer);
|
||||
connection.Send<NetMessage.Connect.PlayerJoinSuccessful>(new NetMessage.Connect.PlayerJoinSuccessful(newPlayer));
|
||||
}
|
||||
|
||||
public void OnViewerLink(NetworkConnection connection, NetMessage.Connect.ViewerLink message) {
|
||||
if(message.gamePassword != password) {
|
||||
connection.Send<NetMessage.Error.InvalidPassword>(new NetMessage.Error.InvalidPassword());
|
||||
return;
|
||||
}
|
||||
Viewer newViewer = new Viewer(new Guid());
|
||||
viewers.Add(newViewer);
|
||||
connection.Send<NetMessage.Connect.ViewerLinkSuccessful>(new NetMessage.Connect.ViewerLinkSuccessful(newViewer));
|
||||
}
|
||||
|
||||
public void OnGameSettings(NetworkConnection connection, NetMessage.Game.Settings message) {}
|
||||
public void OnActResults(NetworkConnection connection, NetMessage.Act.Results message) {}
|
||||
}
|
||||
|
|
10
Assets/Code/Viewer.cs
Normal file
10
Assets/Code/Viewer.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
|
||||
|
||||
public class Viewer {
|
||||
public Guid guid;
|
||||
|
||||
public Viewer(Guid guid) {
|
||||
this.guid = guid;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue