Пример #1
0
        /// <summary>
        ///     Starts the client and tries to connect to the given server.
        /// </summary>
        /// <param name="ipAddress">The server ip address.</param>
        /// <param name="port">The server port.</param>
        /// <param name="username">The username to connect with.</param>
        /// <param name="password">The password to use.</param>
        /// <param name="callback">This callback returns if the connection was successful.</param>
        public void ConnectToServer(string ipAddress, int port, string username, string password, Action <bool> callback)
        {
            if (CurrentRole == MultiplayerRole.Server)
            {
                callback.Invoke(false);
                return;
            }

            new Thread(() =>
            {
                // Try connect
                bool isConnected = CurrentClient.Connect(new ClientConfig(ipAddress, port, username, password));

                // Set the current role
                CurrentRole = isConnected ? MultiplayerRole.Client : MultiplayerRole.None;

                // Return the status
                callback.Invoke(isConnected);
            }).Start();
        }