Пример #1
0
        private bool tunnel_OnMessageReceivedEvent(string msg)
        {
            if (msg.StartsWith("sit:"))
            {
                int seatnum = int.MaxValue;
                if (int.TryParse(msg.Substring("sit:".Length), out seatnum))
                {
                    if (gameRoom.OnAttemptSitEvent(this, seatnum))
                    {
                        Logger.Log(LogType.Event, name + " sat down");
                        this.status = PlayerStatus.Sitting;
                    }
                    else
                    {
                        tunnel.SendMessage("fail");
                        Logger.Log(LogType.Error, name + " failed to sit");
                    }
                }
                else
                {
                    Logger.Log(LogType.Error, name + " sent a malformed message '" + msg + "'");
                }

                return(true);
            }
            else if (msg.StartsWith("chat:"))
            {
                gameRoom.OnChatEvent(name, msg.Substring("chat:".Length));
                return(true);
            }
            else if (msg == "stand")
            {
                gameRoom.OnStandEvent(this);
                return(true);
            }
            else if (msg == "reqbank")
            {
                this.SetBank(this.bank);
                return(true);
            }
            else if (msg == "quit")
            {
                QuitRoom();

                return(true);
            }
            else if (msg.StartsWith("withdraw:"))
            {
                int amount = int.MaxValue;
                if (int.TryParse(msg.Substring("withdraw:".Length), out amount))
                {
                    WithdrawBank(amount);
                    gameRoom.BroadcastSeatInfo(this);
                }

                return(true);
            }

            return(false);
        }
Пример #2
0
        private bool tunnel_OnMessageReceivedEvent(string msg)
        {
            if (msg.StartsWith("chat:"))
            {
                lobby.OnGlobalChatEvent(name, msg.Substring("chat:".Length));
                return(true);
            }
            else if (msg.StartsWith("join:"))
            {
                int    gameID    = -1;
                string gameIDStr = msg.Substring("join:".Length);
                if (int.TryParse(gameIDStr, out gameID))
                {
                    string ticket = lobby.OnJoinGameRequestEvent(this, gameID);
                    if (string.IsNullOrEmpty(ticket))
                    {
                        this.tunnel.SendMessage("ticket:invalid");
                    }
                    else
                    {
                        this.tunnel.SendMessage("ticket:" + ticket);
                    }
                }
                else
                {
                    Logger.Log(LogType.Error, name + " tried to join with non-integer gameID");

                    this.tunnel.SendMessage("ticket:invalid");
                }

                return(true);
            }
            else if (msg == "quit")
            {
                Logger.Log(LogType.Event, name + " has quit");

                Quit();

                return(true);
            }
            else if (msg == "reqgames")
            {
                Logger.Log(LogType.Debug, name + " requested game list");
                lobby.OnRequestGameListEvent(this);

                return(true);
            }
            else if (msg == "reqbank")
            {
                Logger.Log(LogType.Debug, name + " requested bank amount");

                tunnel.SendMessage("bank:" + this.bank.ToString("0"));

                return(true);
            }

            return(false);
        }
Пример #3
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);
        }
Пример #4
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));
            }
        }
Пример #5
0
        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);
        }
Пример #6
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");
            }
        }
Пример #7
0
        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;
        }
Пример #8
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");
            }
        }
Пример #9
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));
        }
Пример #10
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);
        }
Пример #11
0
        protected virtual bool OnMessageReceivedEvent(string msg)
        {
            if (msg.StartsWith("chat:"))
            {
                gameRoom.BroadcastChat(name, msg.Substring("chat:".Length));

                return(true);
            }
            else if (msg == "reqbank")
            {
                Logger.Log(LogType.Debug, name + " requested bank amount");

                SetBank(bank);

                return(true);
            }
            else if (msg == "quit")
            {
                Logger.Log(LogType.Debug, name + " is quitting game room");

                Quit();

                return(true);
            }
            else if (msg.StartsWith("sit:"))
            {
                int i = 0;
                if (int.TryParse(msg.Substring("sit:".Length), out i))
                {
                    Logger.Log(LogType.Debug, name + " is trying to sit in " + gameRoom.Name);

                    if (gameRoom.SitDown(this, i) == false)
                    {
                        // ok was sent inside gameRoom.SitDown along with all seat info
                        tunnel.SendMessage("fail");
                    }
                }
                else
                {
                    Logger.Log(LogType.Error, name + " sent sit request with bad integer");

                    tunnel.SendMessage("sit:fail");
                }

                return(true);
            }
            else if (msg == "stand")
            {
                Logger.Log(LogType.Debug, name + " stood up in " + gameRoom.Name);

                DepositBank(wallet);
                gameRoom.StandUp(this);

                return(true);
            }
            else if (msg.StartsWith("sitin"))
            {
                Logger.Log(LogType.Debug, name + " is starting to play in " + gameRoom.Name);

                gameRoom.SitIn(this);

                return(true);
            }
            else if (msg.StartsWith("sitout"))
            {
                Logger.Log(LogType.Debug, name + " is sitting out in " + gameRoom.Name);

                gameRoom.SitOut(this);

                return(true);
            }
            else if (msg == "refill")
            {
                Logger.Log(LogType.Debug, name + " requested a refill");

                int chipsInPlay = lobbyEntity.ChipsInPlay;
                int totalChips  = lobbyEntity.Bank + chipsInPlay;
                if (totalChips < gameRoom.BuyIn)
                {
                    lobbyEntity.SetBank(gameRoom.BuyIn - chipsInPlay);
                }

                return(true);
            }
            else if (msg.StartsWith("withdraw:"))
            {
                Logger.Log(LogType.Debug, name + " is trying to withdraw");

                int i = 0;
                if (int.TryParse(msg.Substring("withdraw:".Length), out i))
                {
                    WithdrawBank(i);
                }
                else
                {
                    SetBank(bank);

                    Logger.Log(LogType.Error, name + " tried to withdraw a non-integer amount");
                }

                return(true);
            }
            else if (msg.StartsWith("deposit:"))
            {
                Logger.Log(LogType.Debug, name + " is trying to deposit");

                int i = 0;
                if (int.TryParse(msg.Substring("deposit:".Length), out i))
                {
                    DepositBank(i);
                }
                else
                {
                    SetBank(bank);

                    Logger.Log(LogType.Error, name + " tried to deposit a non-integer amount");
                }

                return(true);
            }

            return(false);
        }