Ejemplo n.º 1
0
    // --- CLIENT CALLBACKS ---

    // Called on client when we connect to the server.
    void OnClientConnect(NetworkMessage msg)
    {
        // Immediately skip setup on connect if we're running in headless mode
        if (ConnectFourNPC.IsHeadlessMode())
        {
            SkipSetup();
        }

        // If we've already completed setup (this happens if this connect is a re-connect after the setup), immediately ready-up
        if (completedSetup)
        {
            // Re-send our board offset/size messages
            SendBoardSizeMessage();
            SendBoardOffsetMessage();

            // Set client state to ready on the server
            ClientScene.Ready(NetworkManager.Client.connection);

            // Show the board visuals
            ConnectFourBoard.Instance.ShowBoard();
        }

        // Begin setup
        else
        {
            Debug.Log("[CLIENT] ConnectFourBoardSetup : OnClientConnect - Starting board setup...");

            doingPlacement = true;
            FadeInitialHandle(true);
            boardSetupCanvas.DOFade(1.0f, 0.5f);
        }
    }
Ejemplo n.º 2
0
    // Send BoardSizeMessage to server, only if the board size isn't fixed (i.e. the other player already set the board size)
    void SendBoardSizeMessage()
    {
        // Never send board size if we already have one, or if this is a headless instance
        if (hasFixedBoardSize || ConnectFourNPC.IsHeadlessMode())
        {
            return;
        }

        var boardSizeMsg = new BoardSizeMessage()
        {
            playerId = NetworkManager.PlayerID,
            size     = new Vector2(GetBoardWidth(), GetBoardHeight()),
        };

        Debug.Log("[CLIENT] ConnectFourBoardSetup : SendBoardSizeMessage - Sending board size of " + boardSizeMsg.size);

        NetworkManager.Client.Send(ConnectFourMsgType.BoardSize, boardSizeMsg);
    }
Ejemplo n.º 3
0
    void Awake()
    {
        Instance = this;

        // Don't run the headless instance in the editor (mainly because we don't have a solid reference to a build executable)
        if (Settings.Current.gameMode == Settings.GAME_MODE_SINGLEPLAYER)
        {
            if (Application.isEditor)
            {
                Debug.LogError("ConnectFourNPC : Cannot start singleplayer instance in editor!");
                return;
            }

            // Check if we're running in headless/batchmode, and if so, enable the AI immediately
            if (IsHeadlessMode())
            {
                Debug.Log("--- RUNNING IN HEADLESS MODE ---");
                IsEnabled = true;
            }

            // Otherwise start the headless instance
            else
            {
                // The headless instance config is always the opposite of the host config
                string headlessConfig = (Settings.Current.networkConfig == Settings.NETWORK_CONFIG_CLIENT) ?
                                        Settings.NETWORK_CONFIG_HOST : Settings.NETWORK_CONFIG_CLIENT;

                // Log to a different file (otherwise the data is logged to the same file as the host)
                string logFilePath = "\"" + System.IO.Path.GetDirectoryName(Settings.Current.LogFilePath) + "\\output_log_headless.txt\"";

                // Construct ProcessStartInfo
                var startInfo = new System.Diagnostics.ProcessStartInfo()
                {
                    FileName  = Settings.Current.ExecutablePath,
                    Arguments = string.Format("-batchmode -nographics -logFile {0} -config {1} -mode {2} -address {3} -meta_enabled {4}", logFilePath, headlessConfig, Settings.GAME_MODE_SINGLEPLAYER, "127.0.0.1", false),
                };

                // Start process
                headlessProcess = System.Diagnostics.Process.Start(startInfo);

                Debug.Log("ConnectFourNPC : Started headless process (id: " + headlessProcess.Id + ") using the following arguments:\n" + headlessProcess.StartInfo.FileName + " " + headlessProcess.StartInfo.Arguments);
            }
        }
    }