Пример #1
0
        /// <summary>
        /// Opens the Lobby Scene, starts and prepares the server, starts and prepares a client and connects it to the server.
        /// </summary>
        private void OpenLobbyHost()
        {
            //Initialize Scene
            groupLobby.SynchronizedInvoke(() =>
            {
                groupLobby.Visible           = true;
                buttonLobbyStartGame.Enabled = true;
                buttonLobbyStartGame.Focus();
            });

            //Initialize clientManager
            clientManager?.Shutdown(this, EventArgs.Empty);      //Reset Client
            clientManager = new NetClientManager();
            clientManager.OnPlayerListChanged += UpdatePlayerListBoxInLobby;
            clientManager.OnDisconnect        += ConnectionToServerLostInLobby;
            clientManager.OnGameStart         += ClientStartGame;

            //Initialize serverManager
            serverManager?.Shutdown(this, EventArgs.Empty);      //Reset Server
            serverManager              = new NetServerManager();
            serverManager.OnPortError += PortError;
            serverManager.StartServer();

            clientManager.Connect(IPAddress.Parse("127.0.0.1"));
        }
Пример #2
0
        /// <summary>
        /// Opens the search scene, starts and prepares a client.
        /// </summary>
        private void OpenSearch()
        {
            groupSearch.SynchronizedInvoke(() =>
            {
                groupSearch.Visible = true;
                buttonSearchScanNetwork.Focus();
            });

            clientManager?.Shutdown(this, EventArgs.Empty);
            clientManager             = new NetClientManager();
            clientManager.OnDiscover += AddServerToSearchListBox;
            clientManager.OnConnect  += ConnectSucceded;
        }