Ejemplo n.º 1
0
 private void chatTypeBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter && chatTypeBox.Text.Length > 0)
     {
         nt.Send("chatmsg");
         nt.Send(chatTypeBox.Text);
     }
 }
Ejemplo n.º 2
0
        private void NewClientEvent(IAsyncResult ar)
        {
            TcpListener listener = (TcpListener)ar.AsyncState;
            TcpClient   client   = listener.EndAcceptTcpClient(ar);

            TcpClientConnected.Set();
            string    c;
            NetTunnel nt  = new NetTunnel(client, timeout);
            int       err = nt.Receive(out c);

            if (err == 0)
            {
                if (c == "joinlobby")
                {
                    string n;
                    err = nt.Receive(out n);
                    LobbyListEntry lle = new LobbyListEntry();
                    lle.name = n;
                    lle.tc   = client;
                    err      = nt.Send("Test String");

                    string ip_str = client.Client.LocalEndPoint.ToString();

                    lle.i = lobby_list.Count;

                    lobby_list.Add(lle);
                }
                else if (c == "joingame")
                {
                    string game_id;
                    string n;
                    string seat;
                    err = nt.Receive(out game_id);
                    err = nt.Receive(out n);
                    err = nt.Receive(out seat);
                    bool success = ((GameRoom)game_rooms[int.Parse(game_id)]).AddPlayer(new GamePlayer(client, n, 0), int.Parse(seat));
                    if (success)
                    {
                        err = nt.Send("You have joined " + game_id);
                    }
                    else
                    {
                        err = nt.Send("joined failed" + game_id);
                    }
                }
            }

            RestartTcpListeningCallback d = new RestartTcpListeningCallback(RestartTcpListening);

            d.Invoke();
        }
Ejemplo n.º 3
0
        public Client(string username_)
        {
            InitializeComponent();
            this.username = username_;
            label1.Text = label1.Text + "\n" + username;

            lobbyTunnel = new NetTunnel(500);
            lobbyTunnel.Connect(address, 5000);
            lobbyTunnel.Send ("joinlobby");
            lobbyTunnel.Send (username);

            string WelcomeMessage;
            lobbyTunnel.Receive(out WelcomeMessage);
            receiveGameList();
            MessageBox.Show(WelcomeMessage);
        }
Ejemplo n.º 4
0
        public Client(string username_)
        {
            InitializeComponent();
            this.username = username_;
            label1.Text   = label1.Text + "\n" + username;

            lobbyTunnel = new NetTunnel(500);
            lobbyTunnel.Connect(address, 5000);
            lobbyTunnel.Send("joinlobby");
            lobbyTunnel.Send(username);

            string WelcomeMessage;

            lobbyTunnel.Receive(out WelcomeMessage);
            receiveGameList();
            MessageBox.Show(WelcomeMessage);
        }
Ejemplo n.º 5
0
 private void RequestHandler()
 {
     for (int i = 0; i < lobby_list.Count; i++)
     {
         while (((LobbyListEntry)lobby_list[i]).tc.Available > 0)
         {
             string    c;
             TcpClient tc  = ((LobbyListEntry)lobby_list[i]).tc;
             NetTunnel nt  = new NetTunnel(tc, timeout);
             int       err = nt.Receive(out c);
             if (err == 0)
             {
                 if (c == "requestroomlist")
                 {
                     for (int j = 0; j < game_rooms.Count; j++)
                     {
                         err = nt.Send(((GameRoom)game_rooms[j]).id.ToString() + "," + ((GameRoom)game_rooms[j]).name + "," + ((GameRoom)game_rooms[j]).player_cnt + "," + ((GameRoom)game_rooms[j]).chips);
                     }
                     err = nt.Send("endaddgame");
                     //MessageBox.Show("request received, " + Convert.ToString(err));
                 }
                 else if (c == "requsers")
                 {
                     string game_id;
                     err = nt.Receive(out game_id);
                     for (int j = 0; j < ((GameRoom)game_rooms[int.Parse(game_id)]).player.Length; j++)
                     {
                         if (((GameRoom)game_rooms[int.Parse(game_id)]).player[j].active)
                         {
                             err = nt.Send(((GameRoom)game_rooms[int.Parse(game_id)]).player[j].name + "," + ((GameRoom)game_rooms[int.Parse(game_id)]).player[j].chips);
                         }
                     }
                     err = nt.Send("endplayerlist");
                 }
             }
             Thread.Sleep(0);
         }
         Thread.Sleep(0);
     }
 }
Ejemplo n.º 6
0
        private void receiveGameList()
        {
            lobbyTunnel.Send("requestroomlist");
            rooms.Clear();
            listView1.Items.Clear();
            while (true)
            {
                string tmp;
                lobbyTunnel.Receive(out tmp);
                if (tmp == "endaddgame")
                {
                    listView1.Columns[0].Width = listView1.Width * 5 / 100;
                    listView1.Columns[1].Width = listView1.Width * 59 / 100;
                    listView1.Columns[2].Width = listView1.Width * 15 / 100;
                    listView1.Columns[3].Width = listView1.Width * 20 / 100;
                    return;
                }
                else
                {
                    GameListEntry gle  = new GameListEntry();
                    string[]      game = tmp.Split(',');

                    if (game.Length == 4)
                    {
                        gle.gameID      = game[0];
                        gle.gameName    = game[1];
                        gle.playerCount = game[2];
                        gle.totalChips  = game[3];
                        rooms.Add(gle);
                        ListViewItem lvi = new ListViewItem(game);
                        listView1.Items.Add(lvi);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public GameRoom(string ticket)
        {
            InitializeComponent();

            this.txtGroup = new System.Windows.Forms.TextBox[9];
            for (int i = 0; i < this.txtGroup.Length; i++)
            {
                this.txtGroup[i] = new System.Windows.Forms.TextBox();

                this.txtGroup[i].BackColor   = System.Drawing.Color.Khaki;
                this.txtGroup[i].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                this.txtGroup[i].Cursor      = System.Windows.Forms.Cursors.Default;
                this.txtGroup[i].Location    = new System.Drawing.Point(0, 0 + i * 25);
                this.txtGroup[i].Name        = "txtGroup[" + i.ToString() + "]";
                this.txtGroup[i].ReadOnly    = true;
                this.txtGroup[i].Size        = new System.Drawing.Size(107, 20);
                this.txtGroup[i].TabIndex    = 0;
                this.txtGroup[i].TextAlign   = System.Windows.Forms.HorizontalAlignment.Center;
            }
            for (int i = 0; i < this.txtGroup.Length; i++)
            {
                this.Controls.Add(this.txtGroup[i]);
            }

            nt = new NetTunnel(100);
            nt.Connect(address, 5000);
            nt.StartAsyncReceive();
            nt.Send("useticket");
            nt.Send(ticket);

            string tmp;

            nt.Receive(out tmp, 5000);
            getTableStatus();
            string success;
            bool   temp = nt.Receive(out success, 10000);

            MessageBox.Show(success + temp.ToString());
        }
Ejemplo n.º 8
0
        public GameRoom(string ticket)
        {
            InitializeComponent();

            this.txtGroup = new System.Windows.Forms.TextBox[9];
            for (int i = 0; i < this.txtGroup.Length; i++)
            {
                this.txtGroup[i] = new System.Windows.Forms.TextBox();

                this.txtGroup[i].BackColor = System.Drawing.Color.Khaki;
                this.txtGroup[i].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                this.txtGroup[i].Cursor = System.Windows.Forms.Cursors.Default;
                this.txtGroup[i].Location = new System.Drawing.Point(0, 0 + i * 25);
                this.txtGroup[i].Name = "txtGroup[" + i.ToString() + "]";
                this.txtGroup[i].ReadOnly = true;
                this.txtGroup[i].Size = new System.Drawing.Size(107, 20);
                this.txtGroup[i].TabIndex = 0;
                this.txtGroup[i].TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            }
            for (int i = 0; i < this.txtGroup.Length; i++)
            {
                this.Controls.Add(this.txtGroup[i]);
            }

            nt = new NetTunnel(100);
            nt.Connect(address, 5000);
            nt.StartAsyncReceive();
            nt.Send("useticket");
            nt.Send(ticket);

            string tmp;
            nt.Receive(out tmp,5000);
            getTableStatus();
            string success;
            bool temp = nt.Receive(out success, 10000);
            MessageBox.Show(success + temp.ToString());
        }
Ejemplo n.º 9
0
 private void RequestHandler()
 {
     for (int i = 0; i < lobby_list.Count; i++)
     {
         while (((LobbyListEntry)lobby_list[i]).tc.Available > 0)
         {
             string c;
             TcpClient tc = ((LobbyListEntry)lobby_list[i]).tc;
             NetTunnel nt = new NetTunnel(tc, timeout);
             int err = nt.Receive(out c);
             if (err == 0)
             {
                 if (c == "requestroomlist")
                 {
                     for (int j = 0; j < game_rooms.Count; j++)
                     {
                         err = nt.Send(((GameRoom)game_rooms[j]).id.ToString() + "," + ((GameRoom)game_rooms[j]).name + "," + ((GameRoom)game_rooms[j]).player_cnt + "," + ((GameRoom)game_rooms[j]).chips);
                     }
                     err = nt.Send("endaddgame");
                     //MessageBox.Show("request received, " + Convert.ToString(err));
                 }
                 else if (c == "requsers")
                 {
                     string game_id;
                     err = nt.Receive(out game_id);
                     for (int j = 0; j < ((GameRoom)game_rooms[int.Parse(game_id)]).player.Length; j++)
                     {
                         if (((GameRoom)game_rooms[int.Parse(game_id)]).player[j].active)
                         {
                             err = nt.Send(((GameRoom)game_rooms[int.Parse(game_id)]).player[j].name + "," + ((GameRoom)game_rooms[int.Parse(game_id)]).player[j].chips);
                         }
                     }
                     err = nt.Send("endplayerlist");
                 }
             }
             Thread.Sleep(0);
         }
         Thread.Sleep(0);
     }
 }
Ejemplo n.º 10
0
        private void NewClientEvent(IAsyncResult ar)
        {
            TcpListener listener = (TcpListener)ar.AsyncState;
            TcpClient client = listener.EndAcceptTcpClient(ar);
            TcpClientConnected.Set();
            string c;
            NetTunnel nt = new NetTunnel(client, timeout);
            int err = nt.Receive(out c);
            if (err == 0)
            {
                if (c == "joinlobby")
                {
                    string n;
                    err = nt.Receive(out n);
                    LobbyListEntry lle = new LobbyListEntry();
                    lle.name = n;
                    lle.tc = client;
                    err = nt.Send("Test String");

                    string ip_str = client.Client.LocalEndPoint.ToString();

                    lle.i = lobby_list.Count;

                    lobby_list.Add(lle);
                }
                else if (c == "joingame")
                {
                    string game_id;
                    string n;
                    string seat;
                    err = nt.Receive(out game_id);
                    err = nt.Receive(out n);
                    err = nt.Receive(out seat);
                    bool success = ((GameRoom)game_rooms[int.Parse(game_id)]).AddPlayer(new GamePlayer(client, n, 0), int.Parse(seat));
                    if (success)
                    {
                        err = nt.Send("You have joined " + game_id);
                    }
                    else
                    {
                        err = nt.Send("joined failed" + game_id);
                    }
                }

            }

            RestartTcpListeningCallback d = new RestartTcpListeningCallback(RestartTcpListening);
            d.Invoke();
        }