예제 #1
0
        public Server()
        {
            InitializeComponent();

            // Gets local IP address
            IPAddress serverIPAddress = Connection.GetLocalIP();

            lblServerIP.Text = $"IP: {serverIPAddress}";

            // Default port number, no option to change
            lblServerPort.Text       = "Ports: 8008 and 8009";
            clientsConnected         = 0;
            lblClientsConnected.Text = $"Clients Connected: {clientsConnected}";

            // Setup Sockects
            udpSocket = new UDPConnection();
            udpSocket.BindPort("8008");

            tcpSocket = new TCPConnection();
            tcpSocket.BindPort("8009");
            tcpSocket.Listen(maxPlayersNumber);

            serverEP      = new IPEndPoint(IPAddress.Parse(serverIPAddress.ToString()), Convert.ToInt16("8009"));
            serverDetails = Encoding.ASCII.GetBytes(serverEP.ToString());

            // Make the list of players the data source for the listbox
            listboxAvaPlayers.DataSource    = players;
            listboxAvaPlayers.DisplayMember = "playerName";

            StartrequestTimer();
        }
예제 #2
0
        private void EmptyError()
        {
            // Checks the user has entered the right values for name and port
            if ((string.IsNullOrWhiteSpace(txtPlayerName.Text)))
            {
                MessageBox.Show("Please Enter your Player Name!");
            }
            else if (!(Convert.ToInt32(txtPort.Text) >= 8000 && (Convert.ToInt32(txtPort.Text) <= 8009)))
            {
                MessageBox.Show("Please Enter the Port Number Between 8000 and 8009");
            }
            else
            {
                // Set up UDP Socket and bind to users choice
                udpSocket = new UDPConnection();
                udpSocket.BindPort(txtPort.Text);

                // Create a new Player object for user
                player = new Player(txtPlayerName.Text, playerEP = new IPEndPoint(Connection.GetLocalIP(), Convert.ToInt16(txtPort.Text, 10)));

                // Start checking for recevied messages and broadcast the users details
                StartrequestTimer();
                SendPlayerDetails(player);

                // Set the pnlGameSettins text
                lblPlayerName.Text = $"{player.PlayerName} : {player.Status}";
                lblIP.Text         = "IP: " + Connection.GetLocalIP();
                lblPort2.Text      = "Port: " + txtPort.Text;
                listBoxLobby.Items.Add(player.PlayerName);
                GetNumberOfPlayers();
                btnRemoveP.Enabled     = false;
                pnlGameSetting.Visible = true;
            }
        }