Ejemplo n.º 1
0
        private void OnAuthenticateUserCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c = (AuthenticateUserCommand)command;
            var u = DataManager.Persistance.Get(c.Username);

            var ok = false;

            if (u != null)
            {
                client.PlayerName = u.DisplayName;
                if (DataManager.Persistance.Authenticate(c.Username, c.Password) != null)
                {
                    if (!Lobby.IsNameUsed(client.PlayerName))
                    {
                        Lobby.AddName(client.PlayerName);
                        ok = true;
                        client.SendCommand(c.ResponseSuccess());
                    }
                    else
                    {
                        client.SendCommand(c.ResponseFailure(TaluvaMessageId.NameAlreadyUsed, "The name is already used on the server!"));
                    }
                }
                else
                {
                    client.SendCommand(c.ResponseFailure(TaluvaMessageId.InvalidPassword, "Wrong Password!"));
                }
            }
            else
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.UsernameNotFound, "Your username was not in the database!"));
            }
            Logger.LogInformation("> Client authenticate to RegisteredMode Server as : {0}. Success={1}", c.Username, ok);
        }
Ejemplo n.º 2
0
        private void OnCreateUserCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c  = (CreateUserCommand)command;
            var ok = false;

            if (!DataManager.Persistance.IsUsernameExist(c.Username))
            {
                if (!DataManager.Persistance.IsDisplayNameExist(c.DisplayName))
                {
                    DataManager.Persistance.Register(new UserInfo(c.Username, c.Password, c.Email, c.DisplayName, 7500));
                    ok = true;
                    client.SendCommand(c.ResponseSuccess());
                }
                else
                {
                    client.SendCommand(c.ResponseFailure(TaluvaMessageId.NameAlreadyUsed, "The display name is already used on the server!"));
                }
            }
            else
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.UsernameAlreadyUsed, "The username is already used on the server!"));
            }

            Logger.LogInformation("> Client register to RegisteredMode Server as : {0}. Success={1}", c.Username, ok);
        }
 void OnIdentifyCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
 {
     var c = (IdentifyCommand)command;
     client.PlayerName = c.Name;
     var ok = !Lobby.IsNameUsed(c.Name) && !DataManager.Persistance.IsDisplayNameExist(c.Name);
     LogManager.Log(LogLevel.Message, "BluffinLobbyWorker.OnIdentifyCommandReceived", "> Client indentifying QuickMode server as : {0}. Success={1}", c.Name, ok);
     if (ok)
     {
         client.SendCommand(c.ResponseSuccess());
         Lobby.AddName(c.Name);
     }
     else
     {
         client.SendCommand(c.ResponseFailure(BluffinMessageId.NameAlreadyUsed,"The name is already used on the server!"));
     }
 }
Ejemplo n.º 4
0
        private void OnPlayerSitOutCommandReceived(AbstractCommand command, IBluffinClient client, RemotePlayer p)
        {
            var c = (PlayerSitOutCommand)command;

            client.SendCommand(c.ResponseSuccess());
            p.Game.SitOut(p.Player);
        }
Ejemplo n.º 5
0
        private void OnCheckUserExistCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c = (CheckUserExistCommand)command;
            var r = c.ResponseSuccess();

            r.Exist = DataManager.Persistance.IsUsernameExist(c.Username);
            client.SendCommand(r);
        }
Ejemplo n.º 6
0
        private void OnCheckDisplayExistCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c = (CheckDisplayExistCommand)command;
            var r = c.ResponseSuccess();

            r.Exist = Lobby.IsNameUsed(c.DisplayName) || DataManager.Persistance.IsDisplayNameExist(c.DisplayName);
            client.SendCommand(r);
        }
Ejemplo n.º 7
0
        void OnListTableCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c = (ListTableCommand)command;
            var r = c.ResponseSuccess();

            r.Tables = Lobby.ListTables(c.LobbyTypes);
            client.SendCommand(r);
        }
Ejemplo n.º 8
0
        void OnIdentifyCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c  = (IdentifyCommand)command;
            var ok = !Lobby.IsNameUsed(c.Name) && !DataManager.Persistance.IsDisplayNameExist(c.Name);

            Logger.LogInformation("> Client indentifying QuickMode server as : {0}. Success={1}", c.Name, ok);
            if (ok)
            {
                client.PlayerName = c.Name;
                Logger.LogClientIdentified(client);
                client.SendCommand(c.ResponseSuccess());
                Lobby.AddName(c.Name);
            }
            else
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.NameAlreadyUsed, "The name is already used on the server!"));
            }
        }
Ejemplo n.º 9
0
        private void OnGetUserCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c = (GetUserCommand)command;
            var u = DataManager.Persistance.Get(client.PlayerName);

            if (u == null)
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.UsernameNotFound, "Your username was not in the database. That's weird !"));
            }
            else
            {
                var r = c.ResponseSuccess();
                r.Email       = u.Email;
                r.DisplayName = u.DisplayName;
                r.Money       = u.TotalMoney;
                client.SendCommand(r);
            }
        }
Ejemplo n.º 10
0
        private void OnCreateTableCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c   = (CreateTableCommand)command;
            var res = Lobby.CreateTable(c);
            var r   = c.ResponseSuccess();

            Logger.LogInformation("> Client '{0}' {3}: {2}:{1}", client.PlayerName, c.Params.TableName, res, c.Params.Lobby.OptionType);
            r.IdTable = res;
            client.SendCommand(r);
        }
Ejemplo n.º 11
0
        private void OnCheckCompatibilityCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            const string MINIMUM_CLIENT_VERSION = "0.0.3.0";

            Assembly        assembly = typeof(AbstractCommand).Assembly;
            FileVersionInfo fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);

            var     c = (CheckCompatibilityCommand)command;
            Version vClient;
            bool    ok = Version.TryParse(c.ImplementedProtocolVersion, out vClient);

            if (ok)
            {
                client.SupportedProtocol = vClient;
            }
            client.ClientIdentification = c.ClientIdentification;
            Logger.LogClientAdditionalInfo(client);
            if (!ok || vClient < new Version(MINIMUM_CLIENT_VERSION))
            {
                var r = c.ResponseFailure(TaluvaMessageId.NotSupported, "The client must implement at least protocol version " + MINIMUM_CLIENT_VERSION);
                r.ImplementedProtocolVersion = fvi.FileVersion;
                r.ServerIdentification       = Server.Identification;
                client.SendCommand(r);
            }
            else
            {
                var r = c.ResponseSuccess();
                r.ImplementedProtocolVersion = fvi.FileVersion;
                r.ServerIdentification       = Server.Identification;
                r.SupportedLobbyTypes        = new[] { LobbyTypeEnum.QuickMode, LobbyTypeEnum.RegisteredMode };
                r.AvailableGames             = new[]
                {
                    new GameInfo
                    {
                        AvailableVariants = RuleFactory.Variants.Values.Where(x => x.GameType == GameTypeEnum.Standard).Select(x => x.Variant).ToArray(),
                        GameType          = GameTypeEnum.Standard,
                        MaxPlayers        = 4,
                        MinPlayers        = 2
                    },
                };
                client.SendCommand(r);
            }
        }
Ejemplo n.º 12
0
        private void OnPlayerSitInCommandReceived(AbstractCommand command, IBluffinClient client, RemotePlayer p)
        {
            UserInfo userInfo = null;
            var      c        = (PlayerSitInCommand)command;

            if (p.Game.Table.Params.Lobby.OptionType == LobbyTypeEnum.QuickMode)
            {
                p.Player.MoneySafeAmnt = 1500;//((LobbyOptionsQuickMode)p.Game.Table.Params.Lobby).StartingAmount;
            }
            else
            {
                int money = c.MoneyAmount;
                userInfo = DataManager.Persistance.Get(p.Client.PlayerName);
                if (userInfo == null || userInfo.TotalMoney < money)
                {
                    p.Player.MoneySafeAmnt = -1;
                }
                else
                {
                    userInfo.TotalMoney   -= money;
                    p.Player.MoneySafeAmnt = money;
                }
            }
            var seat = p.Game.Table.SitIn(p.Player, c.NoSeat);

            if (seat == null)
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.NoMoreSeats, "No seats available"));
                if (userInfo != null)
                {
                    userInfo.TotalMoney += p.Player.MoneySafeAmnt;
                }
            }
            else
            {
                var r = seat.NoSeat != c.NoSeat ? c.ResponseSuccess(TaluvaMessageId.SeatChanged, "The asked seat wasn't available, the server gave you another one.") : c.ResponseSuccess();
                r.NoSeat = seat.NoSeat;
                client.SendCommand(r);
                p.Game.AfterPlayerSat(p.Player);
            }
        }
Ejemplo n.º 13
0
        private void OnJoinTableCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c    = (JoinTableCommand)command;
            var game = (PokerGame)Lobby.GetGame(c.TableId);

            if (game == null || !game.IsRunning)
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.WrongTableState, "You can't join a game that isn't running !"));
                return;
            }
            var table = game.Table;

            if (table.Seats.Players().ContainsPlayerNamed(client.PlayerName))
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.NameAlreadyUsed, "Someone with your name is already in this game !"));
                return;
            }
            var rp = new RemotePlayer(game, new PlayerInfo(client.PlayerName, 0), client, c.TableId);

            if (!rp.JoinGame())
            {
                client.SendCommand(c.ResponseFailure(TaluvaMessageId.SpecificServerMessage, "Unknown failure"));
                return;
            }

            client.AddPlayer(rp);

            Logger.LogInformation("> Client '{0}' joined {2}:{1}", client.PlayerName, table.Params.TableName, c.TableId, rp.Player.NoSeat);


            var r = c.ResponseSuccess();

            r.GameHasStarted = rp.Game.IsPlaying;
            //r.BoardCards = rp.Game.Table.Cards.Select(x => x.ToString()).ToArray();
            r.Seats  = rp.AllSeats().ToList();
            r.Params = rp.Game.Table.Params;
            //r.TotalPotAmount = rp.Game.Table.Bank.MoneyAmount;
            //r.PotsAmount = rp.Game.Table.Bank.PotAmountsPadded(rp.Game.Table.Params.MaxPlayers).ToList();

            client.SendCommand(r);
        }
 private void OnCreateTableCommandReceived(AbstractCommand command, IBluffinClient client)
 {
     var c = (CreateTableCommand)command;
     var res = Lobby.CreateTable(c);
     var r = c.ResponseSuccess();
     Logger.LogInformation("> Client '{0}' {3}: {2}:{1}", client.PlayerName, c.Params.TableName, res, c.Params.Lobby.OptionType);
     r.IdTable = res;
     client.SendCommand(r);
 }
        private void OnCheckCompatibilityCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            const string minimumClientVersion = "3.0";
            const string currentServerVersion = "3.0.0";

            var c = (CheckCompatibilityCommand)command;
            Version vClient; 
            bool ok = Version.TryParse(c.ImplementedProtocolVersion,out vClient);
            if (!ok || vClient < new Version(minimumClientVersion))
            {
                var r = c.ResponseFailure(BluffinMessageId.NotSupported, "The client must implement at least protocol version " + minimumClientVersion);
                r.ImplementedProtocolVersion = currentServerVersion;
                client.SendCommand(r);
            }
            else
            {
                var r = c.ResponseSuccess();
                r.ImplementedProtocolVersion = currentServerVersion;
                r.SupportedLobbyTypes = new[] {LobbyTypeEnum.QuickMode, LobbyTypeEnum.RegisteredMode};
                r.AvailableGames = new[]
                {
                    new GameInfo
                    {
                        AvailableBlinds = new [] {BlindTypeEnum.Blinds},
                        AvailableLimits = new []{LimitTypeEnum.NoLimit},
                        AvailableVariants = RuleFactory.Variants.Values.Where(x => x.GameType == GameTypeEnum.CommunityCardsPoker).Select(x => x.Variant).ToArray(),
                        GameType = GameTypeEnum.CommunityCardsPoker,
                        MaxPlayers = 10,
                        MinPlayers = 2
                    },
                    new GameInfo
                    {
                        AvailableBlinds = new [] {BlindTypeEnum.Antes},
                        AvailableLimits = new []{LimitTypeEnum.NoLimit},
                        AvailableVariants = RuleFactory.Variants.Values.Where(x => x.GameType == GameTypeEnum.StudPoker).Select(x => x.Variant).ToArray(),
                        GameType = GameTypeEnum.StudPoker,
                        MaxPlayers = 10,
                        MinPlayers = 2
                    },
                    new GameInfo
                    {
                        AvailableBlinds = new [] {BlindTypeEnum.Antes},
                        AvailableLimits = new []{LimitTypeEnum.NoLimit},
                        AvailableVariants = RuleFactory.Variants.Values.Where(x => x.GameType == GameTypeEnum.DrawPoker).Select(x => x.Variant).ToArray(),
                        GameType = GameTypeEnum.DrawPoker,
                        MaxPlayers = 10,
                        MinPlayers = 2
                    }
                };
                client.SendCommand(r);
            }
        }
Ejemplo n.º 16
0
 private void OnPlayerSitInCommandReceived(AbstractBluffinCommand command, IBluffinClient client, RemotePlayer p)
 {
     UserInfo userInfo = null;
     var c = (PlayerSitInCommand)command;
     if (p.Game.Params.Lobby.OptionType == LobbyTypeEnum.QuickMode)
         p.Player.MoneySafeAmnt = ((LobbyOptionsQuickMode) p.Game.Params.Lobby).StartingAmount;
     else
     {
         int money = c.MoneyAmount;
         userInfo = DataManager.Persistance.Get(p.Client.PlayerName);
         if (userInfo == null || userInfo.TotalMoney < money)
             p.Player.MoneySafeAmnt = -1;
         else
         {
             userInfo.TotalMoney -= money;
             p.Player.MoneySafeAmnt = money;
         }
     }
     var seat = p.Game.GameTable.SitIn(p.Player, c.NoSeat);
     if (seat == null)
     {
         client.SendCommand(c.ResponseFailure(BluffinMessageId.NoMoreSeats, "No seats available"));
         if (userInfo != null)
             userInfo.TotalMoney += p.Player.MoneySafeAmnt; 
     }
     else
     {
         var r = (seat.NoSeat != c.NoSeat) ? c.ResponseSuccess(BluffinMessageId.SeatChanged, "The asked seat wasn't available, the server gave you another one.") : c.ResponseSuccess();
         r.NoSeat = seat.NoSeat;
         client.SendCommand(r);
         p.Game.AfterPlayerSat(p.Player);
     }
 }
Ejemplo n.º 17
0
 private void OnPlayerSitOutCommandReceived(AbstractBluffinCommand command, IBluffinClient client, RemotePlayer p)
 {
     var c = (PlayerSitOutCommand)command;
     client.SendCommand(c.ResponseSuccess());
     p.Game.SitOut(p.Player);
 }
 private void OnGetUserCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
 {
     var c = (GetUserCommand)command;
     var u = DataManager.Persistance.Get(client.PlayerName);
     if(u == null)
         client.SendCommand(c.ResponseFailure(BluffinMessageId.UsernameNotFound, "Your username was not in the database. That's weird !"));
     else
     {
         var r = c.ResponseSuccess();
         r.Email = u.Email;
         r.DisplayName = u.DisplayName;
         r.Money = u.TotalMoney;
         client.SendCommand(r);
     }
 }
        private void OnAuthenticateUserCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
        {
            var c = (AuthenticateUserCommand)command;
            var u = DataManager.Persistance.Get(c.Username);

            var ok = false;
            if (u != null)
            {
                client.PlayerName = u.DisplayName;
                if (DataManager.Persistance.Authenticate(c.Username, c.Password) != null)
                {
                    if (!Lobby.IsNameUsed(client.PlayerName))
                    {
                        Lobby.AddName(client.PlayerName);
                        ok = true;
                        client.SendCommand(c.ResponseSuccess());
                    }
                    else
                        client.SendCommand(c.ResponseFailure(BluffinMessageId.NameAlreadyUsed, "The name is already used on the server!"));
                }
                else
                    client.SendCommand(c.ResponseFailure(BluffinMessageId.InvalidPassword, "Wrong Password!"));
            }
            else
                client.SendCommand(c.ResponseFailure(BluffinMessageId.UsernameNotFound, "Your username was not in the database!"));
            LogManager.Log(LogLevel.Message, "BluffinLobbyWorker.OnAuthenticateUserCommandReceived", "> Client authenticate to RegisteredMode Server as : {0}. Success={1}", c.Username, ok);
        }
        private void OnCreateUserCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
        {
            var c = (CreateUserCommand)command;
            var ok = false;
            if (!DataManager.Persistance.IsUsernameExist(c.Username))
            {
                if (!DataManager.Persistance.IsDisplayNameExist(c.DisplayName))
                {
                    DataManager.Persistance.Register(new UserInfo(c.Username, c.Password, c.Email, c.DisplayName, 7500));
                    ok = true;
                    client.SendCommand(c.ResponseSuccess());
                }
                else
                    client.SendCommand(c.ResponseFailure(BluffinMessageId.NameAlreadyUsed, "The display name is already used on the server!"));
            }
            else
                client.SendCommand(c.ResponseFailure(BluffinMessageId.UsernameAlreadyUsed, "The username is already used on the server!"));

            LogManager.Log(LogLevel.Message, "BluffinLobbyWorker.OnCreateUserCommandReceived", "> Client register to RegisteredMode Server as : {0}. Success={1}", c.Username, ok);
        }
 private void OnCheckDisplayExistCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
 {
     var c = (CheckDisplayExistCommand)command;
     var r = c.ResponseSuccess();
     r.Exist = Lobby.IsNameUsed(c.DisplayName) || DataManager.Persistance.IsDisplayNameExist(c.DisplayName);
     client.SendCommand(r);
 }
 private void OnCheckUserExistCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
 {
     var c = (CheckUserExistCommand)command;
     var r = c.ResponseSuccess();
     r.Exist = DataManager.Persistance.IsUsernameExist(c.Username);
     client.SendCommand(r);
 }
 private void OnCreateTableCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
 {
     var c = (CreateTableCommand)command;
     var res = Lobby.CreateTable(c);
     var r = c.ResponseSuccess();
     LogManager.Log(LogLevel.Message, "BluffinLobbyWorker.OnCreateTableCommandReceived_{3}", "> Client '{0}' {3}: {2}:{1}", client.PlayerName, c.Params.TableName, res, c.Params.Lobby.OptionType);
     r.IdTable = res;
     client.SendCommand(r);
 }
        private void OnJoinTableCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
        {
            var c = (JoinTableCommand)command;
            var game = Lobby.GetGame(c.TableId);
            var table = game.GameTable;
            if (!game.IsRunning)
            {
                client.SendCommand(c.ResponseFailure(BluffinMessageId.WrongTableState, "You can't join a game that isn't running !"));
                return;
            }
            if (table.ContainsPlayer(client.PlayerName))
            {
                client.SendCommand(c.ResponseFailure(BluffinMessageId.NameAlreadyUsed, "Someone with your name is already in this game !"));
                return;
            }
            var rp = new RemotePlayer(game, new PlayerInfo(client.PlayerName, 0), client, c.TableId);
            if (!rp.JoinGame())
            {
                client.SendCommand(c.ResponseFailure(BluffinMessageId.SpecificServerMessage, "Unknown failure"));
                return;
            }

            client.AddPlayer(rp);

            LogManager.Log(LogLevel.Message, "BluffinLobbyWorker.OnJoinTableCommandReceived", "> Client '{0}' joined {2}:{1}", client.PlayerName, table.Params.TableName, c.TableId, rp.Player.NoSeat);
            client.SendCommand(c.ResponseSuccess());

            rp.SendTableInfo();
        }
 void OnListTableCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
 {
     var c = (ListTableCommand)command;
     var r = c.ResponseSuccess();
     r.Tables = Lobby.ListTables(c.LobbyTypes);
     client.SendCommand(r);
 }
        private void OnJoinTableCommandReceived(AbstractCommand command, IBluffinClient client)
        {
            var c = (JoinTableCommand)command;
            var game = (PokerGame)Lobby.GetGame(c.TableId);
            var table = game.Table;
            if (!game.IsRunning)
            {
                client.SendCommand(c.ResponseFailure(BluffinMessageId.WrongTableState, "You can't join a game that isn't running !"));
                return;
            }
            if (table.ContainsPlayer(client.PlayerName))
            {
                client.SendCommand(c.ResponseFailure(BluffinMessageId.NameAlreadyUsed, "Someone with your name is already in this game !"));
                return;
            }
            var rp = new RemotePlayer(game, new PlayerInfo(client.PlayerName, 0), client, Server, c.TableId);
            if (!rp.JoinGame())
            {
                client.SendCommand(c.ResponseFailure(BluffinMessageId.SpecificServerMessage, "Unknown failure"));
                return;
            }

            client.AddPlayer(rp);

            Logger.LogInformation("> Client '{0}' joined {2}:{1}", client.PlayerName, table.Params.TableName, c.TableId, rp.Player.NoSeat);


            var r = c.ResponseSuccess();

            r.GameHasStarted = rp.Game.IsPlaying;
            r.BoardCards = rp.Game.Table.Cards.Select(x => x.ToString()).ToArray();
            r.Seats = rp.AllSeats().ToList();
            r.Params = rp.Game.Table.Params;
            r.TotalPotAmount = rp.Game.Table.TotalPotAmnt;
            r.PotsAmount = rp.Game.Table.PotAmountsPadded.ToList();

            client.SendCommand(r);
        }
 private void OnCheckCompatibilityCommandReceived(AbstractBluffinCommand command, IBluffinClient client)
 {
     var c = (CheckCompatibilityCommand)command;
     Version vClient; 
     bool ok = Version.TryParse(c.ImplementedProtocolVersion,out vClient);
     if (!ok || vClient < new Version("1.0"))
     {
         var r = c.ResponseFailure(BluffinMessageId.NotSupported, "The client version must be at least 1.0");
         r.ImplementedProtocolVersion = "1.0";
         client.SendCommand(r);
     }
     else
     {
         var r = c.ResponseSuccess();
         r.ImplementedProtocolVersion = "1.0";
         r.SupportedLobbyTypes = new[] {LobbyTypeEnum.QuickMode, LobbyTypeEnum.RegisteredMode};
         r.Rules = RuleFactory.SupportedRules;
         client.SendCommand(r);
     }
 }