Example #1
0
        /// <summary>
        /// This is the event for when the "Connect" button is clicked on the Login GUI. When the button is pressed,
        /// it attempts to establish a connection with the given Server.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        private void Connect_To_Server(object o, EventArgs e)
        {
            if (this.server != null && this.server.socket.Connected)
            {
                logger.LogInformation("Shutting down the connection");
                this.server.socket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
                return;
            }

            logger.LogInformation("Asking the network code to connect to the server.");

            player_name = player_name_box.Text;
            if (player_name is "")
            {
                player_name = $"{new Random()}";
            }
            server_name = server_address_box?.Text;
            this.server = Networking.Connect_to_Server(Contact_Established, server_name);
        }