Beispiel #1
0
        // only server to remotes
        void SendStatusToClient(bool accepted, NetworkConnection conn)
        {
            string      sceneName    = GetSceneName();
            var         state        = GameState.NoGame;
            MessageBase extraMessage = null;

            if (accepted)
            {
                state = gameState;

                if (gameState == GameState.NoGame || gameState == GameState.WillStart)
                {
                    // noop
                }
                else if (gameState == GameState.Playing || gameState == GameState.GameOver)
                {
                    if (gameServer == null)
                    {
                        Log.Error("No tengo server :(");
                    }
                    else
                    {
                        var initialMessages = new List <MessageBase>();
                        gameServer.WriteInitialData(initialMessages);
                        extraMessage = new StartGameMessage(sceneName, initialMessages);
                    }
                }
                else
                {
                    Log.Error("Unexpected state {0}...", gameState);
                }
            }

            conn.Send(MsgType.InitialStatus, new StatusMessage(accepted, sceneName, state, extraMessage));
        }
Beispiel #2
0
        // instantiates local client
        void InstantiateClientAsync(StartGameMessage message, OnClientInstantiated onFinishDelegate = null)
        {
            SetGameState(GameState.Preparing);
            LoadSceneAsync(message.scene, () =>
            {
                InstantiateClient(message);
                SetGameState(GameState.Playing);
                OnClientGameStarted(); // this is to hide game panel

                onFinishDelegate?.Invoke();
            });
        }
Beispiel #3
0
        // remote client
        public void StartClient(StartGameMessage initialMessages)
        {
            instance = this;

            this.mode = Mode.OnlineMode;
            this.isHosted = false;

            var intMsg = initialMessages.ReadInitialMessage<UnityEngine.Networking.NetworkSystem.IntegerMessage>();

            this.numRoles = intMsg.value;
            Log.Debug("Starting with {0} roles", this.numRoles);

            OnStartRemoteClient(initialMessages);
        }
Beispiel #4
0
        void PrepareToStartGame()
        {
            if (playersPerRole != null)
            {
                Log.Warn("playersPerRole already initialized");
            }

            var sceneName = GetSceneName();

            SetGameState(GameState.Preparing);
            numRoles = levelData.MaxPlayers;
            CollectPlayers();

            LoadSceneAsync(sceneName, () =>
            {
                InstantiateServer();

                // this is just to exclude DedicatedServer mode that doesn't exist yet
                if (state == DNMState.Offline)
                {
                    // instantiate local game client but no messaging
                    InstantiateClient(gameServer, Mode.OfflineMode, numRoles);
                    StartGame();
                    // TODO rest of things!
                }
                else if (state == DNMState.Host)
                {
                    // instantiate local client
                    InstantiateClient(gameServer, Mode.OnlineMode, numRoles);

                    var initialMessages = new List <MessageBase>();
                    gameServer.WriteInitialData(initialMessages);

                    var msg = new StartGameMessage(sceneName, initialMessages);

                    // message to create and initialize remote game clients
                    SendToAll(MsgType.StartGame, msg); // TODO ToAllRemote?
                }
                else
                {
                    Log.Error("DNM: unexpected state call of PrepareToStartGame '{0}'", state);
                }
            });
        }
Beispiel #5
0
 public virtual void OnStartRemoteClient(StartGameMessage initialMessages) { }
Beispiel #6
0
 // instantiates remote client
 void InstantiateClient(StartGameMessage startGameMessage)
 {
     InstantiateClientObject();
     gameClient.StartClient(startGameMessage);
 }