Exemple #1
0
        private void NewTestGame(NetTunnel tunnel)
        {
            TexasHoldem game = new TexasHoldem("Admin Test Game", 500, 1500, this);
            LobbyPlayer lob  = new LobbyPlayer("Admin", new NetTunnel(), 9999, this);

            game.JoinGame(lob, tunnel);
        }
Exemple #2
0
        private void NewGamePlayer(NetTunnel tunnel, string ticket)
        {
            if (string.IsNullOrEmpty(ticket))
            {
                Logger.Log(LogType.Error, "Received an empty ticket");
                tunnel.Destroy();
                return;
            }

            if (ticketRoomList.ContainsKey(ticket) && ticketPlayerList.ContainsKey(ticket))
            {
                LobbyPlayer lobbyPlayer = ticketPlayerList[ticket];
                CGameRoom   room        = ticketRoomList[ticket];

                room.JoinGame(lobbyPlayer, tunnel);

                ticketPlayerList.Remove(ticket);
                ticketRoomList.Remove(ticket);

                Logger.Log(LogType.Event, "Player " + lobbyPlayer.Name + " joined " + room.Name);
            }
            else
            {
                Logger.Log(LogType.Error, "Received an invalid ticket");
                tunnel.Destroy();
                return;
            }
        }
Exemple #3
0
 public LobbyPlayer(string username, NetTunnel tunnel, int bank, Server lobby)
 {
     this.lobby                               = lobby;
     this.name                                = username;
     this.bank                                = bank;
     this.tunnel                              = tunnel;
     this.tunnel.Identifier                   = username + " (LobbyPlayer)";
     this.tunnel.OnMessageReceivedEvent      += new NetTunnel.OnMessageReceivedCall(tunnel_OnMessageReceivedEvent);
     this.tunnel.OnUnexpectedDisconnectEvent += new NetTunnel.OnUnexpectedDisconnectCall(tunnel_OnUnexpectedDisconnectEvent);
 }
 public LobbyPlayer(string username, NetTunnel tunnel, int bank, Server lobby)
 {
     this.lobby = lobby;
     this.name = username;
     this.bank = bank;
     this.tunnel = tunnel;
     this.tunnel.Identifier = username + " (LobbyPlayer)";
     this.tunnel.OnMessageReceivedEvent += new NetTunnel.OnMessageReceivedCall(tunnel_OnMessageReceivedEvent);
     this.tunnel.OnUnexpectedDisconnectEvent += new NetTunnel.OnUnexpectedDisconnectCall(tunnel_OnUnexpectedDisconnectEvent);
 }
        private GamePlayer(LobbyPlayer lobbyPlayer, NetTunnel tunnel, GameRoom room)
        {
            this.name   = lobbyPlayer.Name;
            this.tunnel = tunnel;
            this.bank   = lobbyPlayer.Bank;

            this.lobbyPlayer = lobbyPlayer;
            this.gameRoom    = room;

            this.tunnel.OnMessageReceivedEvent      += new NetTunnel.OnMessageReceivedCall(tunnel_OnMessageReceivedEvent);
            this.tunnel.OnUnexpectedDisconnectEvent += new NetTunnel.OnUnexpectedDisconnectCall(tunnel_OnUnexpectedDisconnectEvent);
        }
        private GamePlayer(LobbyPlayer lobbyPlayer, NetTunnel tunnel, GameRoom room)
        {
            this.name = lobbyPlayer.Name;
            this.tunnel = tunnel;
            this.bank = lobbyPlayer.Bank;

            this.lobbyPlayer = lobbyPlayer;
            this.gameRoom = room;

            this.tunnel.OnMessageReceivedEvent += new NetTunnel.OnMessageReceivedCall(tunnel_OnMessageReceivedEvent);
            this.tunnel.OnUnexpectedDisconnectEvent += new NetTunnel.OnUnexpectedDisconnectCall(tunnel_OnUnexpectedDisconnectEvent);
        }
Exemple #7
0
        private void AcceptCallback(IAsyncResult ar)
        {
            try
            {
                Socket listener = (Socket)ar.AsyncState;
                Socket client   = listener.EndAccept(ar);

                Logger.Log(LogType.Event, "New connection to server");

                NetTunnel tunnel = new NetTunnel(client);

                string conType = tunnel.WaitMessage();

                if (string.IsNullOrEmpty(conType))
                {
                    Logger.Log(LogType.Error, "Did not specify connection type");
                    return;
                }
                else if (conType == "login")
                {
                    NewLobbyPlayer(tunnel);
                }
                else if (conType.StartsWith("joingame:"))
                {
                    NewGamePlayer(tunnel, conType.Substring("joingame:".Length));
                }
                else if (conType == "testgame")
                {
                    NewTestGame(tunnel);
                }
                else if (conType == "register")
                {
                    RegisterNewPlayer(tunnel);
                }
                else if (conType == "forgot")
                {
                    ResetPassword(tunnel);
                }
            }
            catch (Exception ex)
            {
                Logger.Log("From Server's AcceptCallback while handling new connection", ex);
            }

            try
            {
                listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
            }
            catch (Exception ex)
            {
                Logger.Log("From Server's AcceptCallback while restarting the listener", ex);
            }
        }
Exemple #8
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();
        }
Exemple #9
0
        private void NewLobbyPlayer(NetTunnel tunnel)
        {
            string username   = tunnel.WaitMessage();
            string hashedPass = tunnel.WaitMessage();

            if (string.IsNullOrEmpty(username))
            {
                Logger.Log(LogType.Error, "Blank username");
                tunnel.Destroy();
                return;
            }

            if (string.IsNullOrEmpty(hashedPass))
            {
                Logger.Log(LogType.Error, "Blank password");
                tunnel.Destroy();
                return;
            }

            LobbyPlayer lobbyPlayer = Database.Login(username, hashedPass, tunnel, this);

            if (lobbyPlayer == null)
            {
                tunnel.SendMessage("fail");
                tunnel.Destroy();
                Logger.Log(LogType.Event, "Bad login attempt (bad credentials) from " + username);
                return;
            }
            else if (lobbyList.ContainsKey(lobbyPlayer.Name))
            {
                if (lobbyList[lobbyPlayer.Name].Tunnel.SendMessage("alreadyin"))
                {
                    tunnel.SendMessage("fail");
                    tunnel.Destroy();
                    Logger.Log(LogType.Event, "Bad login attempt (existing player) from " + username);
                    return;
                }
                else
                {
                    tunnel.SendMessage("ok");
                }
            }
            else
            {
                tunnel.SendMessage("ok");
            }

            lobbyList.Add(lobbyPlayer.Name, lobbyPlayer);

            Logger.Log(LogType.Event, "Added player to lobby " + lobbyPlayer.Name);
        }
        protected CGamePlayer(LobbyPlayer lobbyPlayer, NetTunnel tunnel, CGameRoom gameRoom)
        {
            this.name = lobbyPlayer.Name;
            this.tunnel = tunnel;
            this.tunnel.Identifier = this.name + " (GamePlayer)";
            this.bank = lobbyPlayer.Bank;

            this.lobbyEntity = lobbyPlayer;
            this.lobbyEntity.GameRoomPlayers.Add(this);

            this.gameRoom = gameRoom;

            this.tunnel.OnUnexpectedDisconnectEvent += new NetTunnel.OnUnexpectedDisconnectCall(OnUnexpectedDisconnectEvent);
        }
        protected CGamePlayer(LobbyPlayer lobbyPlayer, NetTunnel tunnel, CGameRoom gameRoom)
        {
            this.name              = lobbyPlayer.Name;
            this.tunnel            = tunnel;
            this.tunnel.Identifier = this.name + " (GamePlayer)";
            this.bank              = lobbyPlayer.Bank;

            this.lobbyEntity = lobbyPlayer;
            this.lobbyEntity.GameRoomPlayers.Add(this);

            this.gameRoom = gameRoom;

            this.tunnel.OnUnexpectedDisconnectEvent += new NetTunnel.OnUnexpectedDisconnectCall(OnUnexpectedDisconnectEvent);
        }
Exemple #12
0
        private void RegisterNewPlayer(NetTunnel tunnel)
        {
            string username = tunnel.WaitMessage();
            string email    = tunnel.WaitMessage();

            RegistrationResult res = Database.RegisterNewPlayer(username, email);

            if (res == RegistrationResult.Successful)
            {
                tunnel.SendMessage("ok");
            }
            else
            {
                tunnel.SendMessage("fail:" + Enum.GetName(typeof(RegistrationResult), res));
            }
        }
        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);
        }
        public static LobbyPlayer Login(string username, string password, NetTunnel tunnel, Server lobby)
        {
            CloseReader();

            Logger.Log(LogType.Event, username + " wants to login");
            try
            {
                string query = String.Format(
                    "SELECT * FROM {0} WHERE (Name='{1}' and Password='******')",
                    playerTableName, username, password);

                MySqlCommand cmd = new MySqlCommand(query, dbConnection);
                dbReader = cmd.ExecuteReader();

                if (dbReader.HasRows == false)
                {
                    CloseReader();
                    return(null);
                }

                int chips = Properties.Settings.Default.playerinichips;

                if (dbReader.Read())
                {
                    chips = dbReader.GetInt32("Chips");
                }

                CloseReader();

                query = String.Format(
                    "UPDATE {0} SET Active='1' WHERE Name='{1}'",
                    playerTableName, username);

                cmd      = new MySqlCommand(query, dbConnection);
                dbReader = cmd.ExecuteReader();
                CloseReader();

                Logger.Log(LogType.Event, username + " has supplied correct credentials");

                return(new LobbyPlayer(username, tunnel, chips, lobby));
            }
            catch (Exception ex)
            {
                Logger.Log("During login for " + username, ex);
                return(null);
            }
        }
Exemple #15
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);
        }
        public bool JoinGame(LobbyPlayer lobbyPlayer, NetTunnel tunnel)
        {
            string pname = lobbyPlayer.Name;

            if (spectators.ContainsKey(pname))
            {
                // should trigger unexpected disconnect and remove itself from list if disconnected
                if (spectators[pname].Tunnel.Ping())
                {
                    Logger.Log(LogType.Error, pname + " is already a spectator when he suppied the correct ticket to join " + name);

                    tunnel.SendMessage("fail");
                    return(false);
                }
            }

            CGamePlayer newPlayer = null;

            if (GAME_TYPE == typeof(TexasHoldem))
            {
                newPlayer = new THPlayer(lobbyPlayer, tunnel, this);
            }
            else
            {
                Logger.Log(LogType.Error, "unknown game type");
                tunnel.SendMessage("fail");
                return(false);
            }

            spectators.Add(pname, newPlayer);

            Logger.Log(LogType.Debug, pname + " joined game " + name);

            newPlayer.Tunnel.SendMessage(newPlayer.Name);
            newPlayer.Tunnel.SendMessage(this.name);
            newPlayer.Tunnel.SendMessage(BUY_IN.ToString("0"));
            newPlayer.Tunnel.SendMessage(MAX_BUY_IN.ToString("0"));

            newPlayer.Status = PlayerStatus.Standing;

            SendAllSeatInfo(newPlayer);

            return(true);
        }
Exemple #17
0
        private void ResetPassword(NetTunnel tunnel)
        {
            string username = tunnel.WaitMessage();
            string email    = tunnel.WaitMessage();

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(email))
            {
                return;
            }

            if (Database.ResetPassword(username, email))
            {
                tunnel.SendMessage("ok");
            }
            else
            {
                tunnel.SendMessage("fail");
            }
        }
Exemple #18
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);
     }
 }
Exemple #19
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());
        }
        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());
        }
 public THPlayer(LobbyPlayer lobbyPlayer, NetTunnel tunnel, CGameRoom gameRoom)
     : base(lobbyPlayer, tunnel, gameRoom)
 {
     tunnel.OnMessageReceivedEvent += new NetTunnel.OnMessageReceivedCall(OnMessageReceivedEvent);
 }
        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();
        }
 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);
     }
 }
        private void NewGamePlayer(NetTunnel tunnel, string ticket)
        {
            if (string.IsNullOrEmpty(ticket))
            {
                Logger.Log(LogType.Error, "Received an empty ticket");
                tunnel.Destroy();
                return;
            }

            if (ticketRoomList.ContainsKey(ticket) && ticketPlayerList.ContainsKey(ticket))
            {
                LobbyPlayer lobbyPlayer = ticketPlayerList[ticket];
                CGameRoom room = ticketRoomList[ticket];

                room.JoinGame(lobbyPlayer, tunnel);

                ticketPlayerList.Remove(ticket);
                ticketRoomList.Remove(ticket);

                Logger.Log(LogType.Event, "Player " + lobbyPlayer.Name + " joined " + room.Name);
            }
            else
            {
                Logger.Log(LogType.Error, "Received an invalid ticket");
                tunnel.Destroy();
                return;
            }
        }
        private void AcceptCallback(IAsyncResult ar)
        {
            try
            {
                Socket listener = (Socket)ar.AsyncState;
                Socket client = listener.EndAccept(ar);

                Logger.Log(LogType.Event, "New connection to server");

                NetTunnel tunnel = new NetTunnel(client);

                string conType = tunnel.WaitMessage();

                if (string.IsNullOrEmpty(conType))
                {
                    Logger.Log(LogType.Error, "Did not specify connection type");
                    return;
                }
                else if (conType == "login")
                {
                    NewLobbyPlayer(tunnel);
                }
                else if (conType.StartsWith("joingame:"))
                {
                    NewGamePlayer(tunnel, conType.Substring("joingame:".Length));
                }
                else if (conType == "testgame")
                {
                    NewTestGame(tunnel);
                }
                else if (conType == "register")
                {
                    RegisterNewPlayer(tunnel);
                }
                else if (conType == "forgot")
                {
                    ResetPassword(tunnel);
                }
            }
            catch (Exception ex)
            {
                Logger.Log("From Server's AcceptCallback while handling new connection", ex);
            }

            try
            {
                listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
            }
            catch (Exception ex)
            {
                Logger.Log("From Server's AcceptCallback while restarting the listener", ex);
            }
        }
        public bool JoinGame(LobbyPlayer lobbyPlayer, NetTunnel tunnel)
        {
            string pname = lobbyPlayer.Name;
            if (spectators.ContainsKey(pname))
            {
                // should trigger unexpected disconnect and remove itself from list if disconnected
                if (spectators[pname].Tunnel.Ping())
                {
                    Logger.Log(LogType.Error, pname + " is already a spectator when he suppied the correct ticket to join " + name);

                    tunnel.SendMessage("fail");
                    return false;
                }
            }

            CGamePlayer newPlayer = null;

            if (GAME_TYPE == typeof(TexasHoldem))
                newPlayer = new THPlayer(lobbyPlayer, tunnel, this);
            else
            {
                Logger.Log(LogType.Error, "unknown game type");
                tunnel.SendMessage("fail");
                return false;
            }

            spectators.Add(pname, newPlayer);

            Logger.Log(LogType.Debug, pname + " joined game " + name);

            newPlayer.Tunnel.SendMessage(newPlayer.Name);
            newPlayer.Tunnel.SendMessage(this.name);
            newPlayer.Tunnel.SendMessage(BUY_IN.ToString("0"));
            newPlayer.Tunnel.SendMessage(MAX_BUY_IN.ToString("0"));

            newPlayer.Status = PlayerStatus.Standing;

            SendAllSeatInfo(newPlayer);

            return true;
        }
        public static LobbyPlayer Login(string username, string password, NetTunnel tunnel, Server lobby)
        {
            CloseReader();

            Logger.Log(LogType.Event, username + " wants to login");
            try
            {
                string query = String.Format(
                    "SELECT * FROM {0} WHERE (Name='{1}' and Password='******')",
                    playerTableName, username, password);

                MySqlCommand cmd = new MySqlCommand(query, dbConnection);
                dbReader = cmd.ExecuteReader();

                if (dbReader.HasRows == false)
                {
                    CloseReader();
                    return null;
                }

                int chips = Properties.Settings.Default.playerinichips;

                if (dbReader.Read())
                    chips = dbReader.GetInt32("Chips");

                CloseReader();

                query = String.Format(
                    "UPDATE {0} SET Active='1' WHERE Name='{1}'",
                    playerTableName, username);

                cmd = new MySqlCommand(query, dbConnection);
                dbReader = cmd.ExecuteReader();
                CloseReader();

                Logger.Log(LogType.Event, username + " has supplied correct credentials");

                return new LobbyPlayer(username, tunnel, chips, lobby);
            }
            catch (Exception ex)
            {
                Logger.Log("During login for " + username, ex);
                return null;
            }
        }
        private void RegisterNewPlayer(NetTunnel tunnel)
        {
            string username = tunnel.WaitMessage();
            string email = tunnel.WaitMessage();

            RegistrationResult res = Database.RegisterNewPlayer(username, email);
            if (res == RegistrationResult.Successful)
                tunnel.SendMessage("ok");
            else
                tunnel.SendMessage("fail:" + Enum.GetName(typeof(RegistrationResult), res));
        }
 private void NewTestGame(NetTunnel tunnel)
 {
     TexasHoldem game = new TexasHoldem("Admin Test Game", 500, 1500, this);
     LobbyPlayer lob = new LobbyPlayer("Admin", new NetTunnel(), 9999, this);
     game.JoinGame(lob, tunnel);
 }
 public static GamePlayer GamePlayerFromLobbyPlayer(LobbyPlayer player, NetTunnel tunnel, GameRoom room)
 {
     return new GamePlayer(player, tunnel, room);
 }
        private void ResetPassword(NetTunnel tunnel)
        {
            string username = tunnel.WaitMessage();
            string email = tunnel.WaitMessage();

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(email))
                return;

            if (Database.ResetPassword(username, email))
            {
                tunnel.SendMessage("ok");
            }
            else
            {
                tunnel.SendMessage("fail");
            }
        }
 private void tunnel_OnUnexpectedDisconnectEvent(NetTunnel tunnel)
 {
     this.QuitRoom();
 }
 private void tunnel_OnUnexpectedDisconnectEvent(NetTunnel tunnel)
 {
     this.QuitRoom();
 }
        private void NewLobbyPlayer(NetTunnel tunnel)
        {
            string username = tunnel.WaitMessage();
            string hashedPass = tunnel.WaitMessage();

            if (string.IsNullOrEmpty(username))
            {
                Logger.Log(LogType.Error, "Blank username");
                tunnel.Destroy();
                return;
            }

            if (string.IsNullOrEmpty(hashedPass))
            {
                Logger.Log(LogType.Error, "Blank password");
                tunnel.Destroy();
                return;
            }

            LobbyPlayer lobbyPlayer = Database.Login(username, hashedPass, tunnel, this);

            if (lobbyPlayer == null)
            {
                tunnel.SendMessage("fail");
                tunnel.Destroy();
                Logger.Log(LogType.Event, "Bad login attempt (bad credentials) from " + username);
                return;
            }
            else if (lobbyList.ContainsKey(lobbyPlayer.Name))
            {
                if (lobbyList[lobbyPlayer.Name].Tunnel.SendMessage("alreadyin"))
                {
                    tunnel.SendMessage("fail");
                    tunnel.Destroy();
                    Logger.Log(LogType.Event, "Bad login attempt (existing player) from " + username);
                    return;
                }
                else
                {
                    tunnel.SendMessage("ok");
                }
            }
            else
            {
                tunnel.SendMessage("ok");
            }

            lobbyList.Add(lobbyPlayer.Name, lobbyPlayer);

            Logger.Log(LogType.Event, "Added player to lobby " + lobbyPlayer.Name);
        }
        private void tunnel_OnUnexpectedDisconnectEvent(NetTunnel tunnel)
        {
            Logger.Log(LogType.Debug, "Unexpected Disconnect Event from LobbyPlayer" + name);

            Quit();
        }
Exemple #36
0
        private void tunnel_OnUnexpectedDisconnectEvent(NetTunnel tunnel)
        {
            Logger.Log(LogType.Debug, "Unexpected Disconnect Event from LobbyPlayer" + name);

            Quit();
        }
Exemple #37
0
 public THPlayer(LobbyPlayer lobbyPlayer, NetTunnel tunnel, CGameRoom gameRoom) : base(lobbyPlayer, tunnel, gameRoom)
 {
     tunnel.OnMessageReceivedEvent += new NetTunnel.OnMessageReceivedCall(OnMessageReceivedEvent);
 }
 public static GamePlayer GamePlayerFromLobbyPlayer(LobbyPlayer player, NetTunnel tunnel, GameRoom room)
 {
     return(new GamePlayer(player, tunnel, room));
 }