From f116295ffe94f820b404443e4801926889f941ed Mon Sep 17 00:00:00 2001 From: JoshuaReason Date: Sat, 26 Jan 2019 20:42:33 +1100 Subject: [PATCH] Setting up seed --- Assets/Scenes/ClientScene.unity | 2 +- .../Scipts/Multiplayer/Core/LoginProtocol.cs | 1 + .../Scipts/Multiplayer/Core/PlayerProtocol.cs | 25 +++++++++++++++++++ .../Scipts/Multiplayer/Server/LoginManager.cs | 3 +++ .../Multiplayer/Server/ServerManager.cs | 3 +++ ProjectSettings/ProjectSettings.asset | 4 +-- 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Assets/Scenes/ClientScene.unity b/Assets/Scenes/ClientScene.unity index 36fe09f..ffc5f50 100644 --- a/Assets/Scenes/ClientScene.unity +++ b/Assets/Scenes/ClientScene.unity @@ -146,7 +146,7 @@ MonoBehaviour: Port: 4444 ConnectOnStart: 0 LobbyScene: LobbyScene - GameScene: TestScene + GameScene: MainScene Name: The Black Burrito IsConnected: 0 ID: 0 diff --git a/Assets/Scipts/Multiplayer/Core/LoginProtocol.cs b/Assets/Scipts/Multiplayer/Core/LoginProtocol.cs index 57773ac..d5dea20 100644 --- a/Assets/Scipts/Multiplayer/Core/LoginProtocol.cs +++ b/Assets/Scipts/Multiplayer/Core/LoginProtocol.cs @@ -10,5 +10,6 @@ namespace Multiplayer public const short Name = 301; public const short EnterLobby = 302; public const short LobbyCount = 303; + public const short Seed = 304; } } \ No newline at end of file diff --git a/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs b/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs index e406ca0..d5bac60 100644 --- a/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs +++ b/Assets/Scipts/Multiplayer/Core/PlayerProtocol.cs @@ -93,6 +93,31 @@ namespace Multiplayer } + public class longMsg : PlayerMsg + { + public long Long; + + public longMsg() { } + + public longMsg(byte PlayerID, long Long) : base(PlayerID) + { + this.Long = Long; + } + + + public override void Serialize(NetworkWriter writer) + { + base.Serialize(writer); + writer.Write(Long); + } + + public override void Deserialize(NetworkReader reader) + { + base.Deserialize(reader); + Long = reader.ReadInt64(); + } + } + public class StringMsg : PlayerMsg { diff --git a/Assets/Scipts/Multiplayer/Server/LoginManager.cs b/Assets/Scipts/Multiplayer/Server/LoginManager.cs index debd814..c1e022f 100644 --- a/Assets/Scipts/Multiplayer/Server/LoginManager.cs +++ b/Assets/Scipts/Multiplayer/Server/LoginManager.cs @@ -72,7 +72,10 @@ namespace Multiplayer private void StartGame() { foreach (Player player in ServerManager.AllPlayers.Values) + { + //player.Connection.Send(LoginMsgID.Seed, new longMsg(player.ID, ServerManager.Seed)); player.Connection.Send(PlayerMsgID.GameStart, new PlayerMsg(player.ID)); + } } private void GoToLobby() diff --git a/Assets/Scipts/Multiplayer/Server/ServerManager.cs b/Assets/Scipts/Multiplayer/Server/ServerManager.cs index d71b598..d6a031b 100644 --- a/Assets/Scipts/Multiplayer/Server/ServerManager.cs +++ b/Assets/Scipts/Multiplayer/Server/ServerManager.cs @@ -16,6 +16,7 @@ namespace Multiplayer [SerializeField] private int Port = 4444; + public long Seed; public Dictionary AllPlayers; @@ -49,6 +50,8 @@ namespace Multiplayer loginManager = new LoginManager(this); playerManager = new PlayerServerManager(this); + Seed = System.DateTime.Now.Ticks; + Server.Listen(Port); } diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index c9c7449..779df14 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d31e33f772a9cd3cd56ae66a5b981bb456d1201adab8595fc0337bc8261d1cfc -size 17761 +oid sha256:04c64ffa91d234bb532dee94ea9a205db3d37fe73723ed630fae3a154ed9266d +size 17790