Пример #1
0
    void HandlePlayer(int id)
    {
        SGCommand playerCommand = m_connection.ReceiveStream(id);

        if (playerCommand != null)
        {
            // Execute the command
            if (playerCommand.GetID() == SGCommandID.REFRESH_TIMEOUT)
            {
                m_playerTimeouts[id] = CONNECTION_TIMEOUT_LOOPS;
            }
            else
            {
                playerCommand.ExecuteCommand(m_cgManager);
                m_playerTimeouts[id]--;
            }
        }
        else
        {
            // Ask player for a no-timeout packet
            CGC_RefreshTimeout timeout = new CGC_RefreshTimeout(id);
            m_connection.TransmitStream(timeout.PackCommand(), id);
            m_playerTimeouts[id]--;
        }
    }
Пример #2
0
        static void Main(string[] args)
        {
            int port;

            ParseArgs(out port, args);

            ServerConnectionManager.Instance.InitializeServer(IPAddress.Any, port);

            Debug.Log("Waiting for connection...");
            ServerConnectionManager.Instance.ConnectToClient(0);
            Debug.Log("Waiting for connection...");
            ServerConnectionManager.Instance.ConnectToClient(1);
            Debug.Log("Both players connected! Starting game...");

            CGC_SetPlayerID setPlayer0 = new CGC_SetPlayerID(0);

            ServerConnectionManager.Instance.TransmitStream(setPlayer0.PackCommand(), 0);
            CGC_SetPlayerID setPlayer1 = new CGC_SetPlayerID(1);

            ServerConnectionManager.Instance.TransmitStream(setPlayer1.PackCommand(), 1);

            bool playing = true;

            CardGameManager cgManager = new CardGameManager();

            cgManager.RunGameLogic();

            while (playing)
            {
                SGCommand player1Command = ServerConnectionManager.Instance.ReceiveStream(0);
                if (player1Command != null)
                {
                    player1Command.ExecuteCommand(cgManager);
                }

                SGCommand player2Command = ServerConnectionManager.Instance.ReceiveStream(1);
                if (player2Command != null)
                {
                    player2Command.ExecuteCommand(cgManager);
                }

                bool connected = ServerConnectionManager.Instance.Connected();
                playing = connected;
            }


            /* TO-DO list
             *  1. Replace all "CGVisualManager.instance.AddCommand(command)" calls with transmitting
             *      the appropriate bitstream to each client
             *  2. Replace all the scripts in the unity project with these ones
             *  3. Re-build this project using the scripts in the unity folder so both projects use the same files
             *  4. Write a servercommand system similar to CGCommand for
             *     sending requests back to the server
             *  5. Document how everything works!
             *  6. Add wait in main server loop
             *
             *
             *
             *
             */
        }