示例#1
0
        public async Task UpdateBalance(PokerUser pokerUser)
        {
            var currentUserModel = await _context.PokerUsers.FirstOrDefaultAsync(p => p.Username == pokerUser.Username);

            currentUserModel.Balance = pokerUser.Balance;
            await _context.SaveChangesAsync();
        }
        public void Estimate(PokerUser user, int estimation, int messageId = 0)
        {
            var session = GetSession(user);

            if (!EnsureSession(user))
            {
                return;
            }

            if (session.Poker == null)
            {
                messageSender.NoPokerRunning(user);
                return;
            }

            if (!session.CanUserEstimate(user))
            {
                messageSender.EstimationAlreadyCounted(user);
            }

            session.Estimate(user, estimation, messageId);
            if (messageId != 0)
            {
                messageSender.UpdateEstimation(user, estimation, messageId);
            }

            if (!session.IsEstimationCompleted())
            {
                return;
            }

            messageSender.SendPokerResult(session, session.Poker.ToString());
            session.ClearPoker();
        }
示例#3
0
        public void SendUserLeaveSession(PokerUser masterUser, PokerUser user)
        {
            var masterText = $"Der User {user} hat die Session verlassen!";
            var userText   = "Du hast die Session verlassen";

            bot.SendTextMessage(masterUser.ChatId, masterText);
            bot.SendTextMessage(user.ChatId, userText);
        }
 public ScrumPokerSession(PokerUser user, int id)
 {
     users = new LockedList <PokerUser> {
         user
     };
     Id         = id;
     MasterUser = user;
 }
        public void RemoveUser(PokerUser user)
        {
            var foundUser = users.FirstOrDefault(u => u.ChatId == user.ChatId);

            if (foundUser != null)
            {
                users.Remove((int)foundUser.ChatId);
            }
        }
        public void Estimate(PokerUser user, int estimation, int messageId = 0)
        {
            var userEstimation = Poker.Users.FirstOrDefault(ue => ue.User.ChatId == user.ChatId);

            if (userEstimation != null && !userEstimation.EstimationReceived)
            {
                userEstimation.SetEstimation(estimation);
            }
        }
示例#7
0
 public bool JoinToTable(int tableId, PokerUser pokerUser)
 {
     if (!Tables.Any(a => a.PokerUsers.Any(p => p.Username == pokerUser.Username)))
     {
         var table = Tables.FirstOrDefault(t => t.Id == tableId);
         table?.AddPlayer(pokerUser);
         return(true);
     }
     return(false);
 }
        private bool EnsureSession(PokerUser user)
        {
            var session = GetSession(user);

            if (session != null)
            {
                return(true);
            }
            messageSender.NoSessionForUser(user);
            return(false);
        }
示例#9
0
        public void PublishMessage(Message message)
        {
            var user = new PokerUser(message.Chat);

            var estimation = new EstimationMessage(user, message.Text);

            if (estimation.IsValid)
            {
                bus.Publish(estimation);
                return;
            }

            if (message.Text.StartsWith("/"))
            {
                var command = message.Text.Split(' ');
                switch (command[0].ToLower())
                {
                case "/startsession":
                    bus.Publish(new StartSessionMessage(user, message.Text));
                    return;

                case "/connect":
                    var connectMessage = new ConnectSessionMessage(user, message.Text);
                    bus.Publish(connectMessage);
                    return;

                case "/poker":
                    bus.Publish(new StartPokerMessage(user, message.Text));
                    return;

                case "/endpoker":
                    bus.Publish(new CancelPokerMessage(user, message.Text));
                    return;

                case "/leavesession":
                    bus.Publish(new LeaveSessionMessage(user, message.Text));
                    return;

                case "/showusers":
                    bus.Publish(new GetSessionUsersMessage(user, message.Text));
                    return;

                case "/showsessions":
                    bus.Publish(new ShowSessionsMessage(user, message.Text));
                    return;

                default:
                    bus.Publish(new UnknownCommandMessage(user, message.Text));
                    return;
                }
            }

            bus.Publish(new UnknownCommandMessage(user, message.Text));
        }
示例#10
0
 public int LeaveTable(int tableId, PokerUser pokerUser)
 {
     if (Tables.Any(a => a.PokerUsers.Any(p => p.Username == pokerUser.Username)))
     {
         var table      = Tables.FirstOrDefault(t => t.Id == tableId);
         var markedUser = table.PokerUsers.FirstOrDefault(p => p.Username == pokerUser.Username);
         var result     = table?.RemovePlayer(markedUser);
         return(tableId);
     }
     return(-1);
 }
示例#11
0
        public void SendConnections(PokerUser user, ScrumPokerSession[] sessions)
        {
            var keyboardLayout = sessions.Select(s => new[]
            {
                GetButton(s)
            }).ToArray();
            var keyboardMarkupInternal = new InlineKeyboardMarkup(keyboardLayout);
            var text = "Wähle die Session!";

            bot.SendTextMessage(user.ChatId, text, false, false, 0, keyboardMarkupInternal);
        }
示例#12
0
        public void SendSessions(PokerUser user, ScrumPokerSession[] sessions)
        {
            var sb = new StringBuilder();

            foreach (var scrumPokerSession in sessions)
            {
                sb.AppendLine($"Session {scrumPokerSession.Id} von {scrumPokerSession.MasterUser}");
            }

            bot.SendTextMessage(user.ChatId, sb.ToString());
        }
        private bool EnsureMasterUser(PokerUser user)
        {
            var session = GetSession(user);

            if (session.MasterUser.ChatId == user.ChatId)
            {
                return(true);
            }

            messageSender.NotMasterUser(user);
            return(false);
        }
示例#14
0
        public void SendUsers(PokerUser[] allUsers, PokerUser user)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Folgede Benutzer nehmen teil:");
            foreach (var pokerUser in allUsers)
            {
                sb.AppendLine($"- {pokerUser}");
            }

            this.bot.SendTextMessage(user.ChatId, sb.ToString());
        }
示例#15
0
 public Player(PokerUser pokerUser)
 {
     Username     = pokerUser.Username;
     FirstName    = pokerUser.FirstName;
     LastName     = pokerUser.LastName;
     ConnectionId = pokerUser.ConnectionId;
     Balance      = pokerUser.Balance;
     IsActive     = true;
     IsDone       = false;
     CurrentRaise = 0;
     Cards        = new List <Card>();
 }
示例#16
0
        public string Add(PokerUser pokerUser)
        {
            string guid   = Guid.NewGuid().ToString();
            var    result = _currentUsers.TryAdd(guid, pokerUser);

            if (result)
            {
                Console.WriteLine($"Logged in - {guid} - {pokerUser?.Username}");
                return(guid);
            }
            return(null);
        }
示例#17
0
        public StartPokerMessage(PokerUser user, string message)
            : base(user, message)
        {
            var regex = new Regex(regexPattern);

            if (regex.IsMatch(message))
            {
                var match = regex.Match(message);
                var group = match.Groups[1];
                Description = group.Value;
            }
        }
示例#18
0
        public async Task LeaveTable(int tableId, PokerUser rawPokerUser)
        {
            var pokerUser = _pokerUserProvider.GetUser(rawPokerUser);

            if (pokerUser == null)
            {
                return;
            }
            _tableProvider.LeaveTable(tableId, pokerUser);
            await Groups.RemoveFromGroupAsync(Context.ConnectionId, tableId.ToString());

            await Clients.All.SendAsync("GetTables", _tableProvider.GetAllTableViews());
        }
        public int StartNewSession(PokerUser user)
        {
            var existingSession = GetSession(user);

            if (existingSession != null)
            {
                messageSender.UserAlreadyInSession(user);
                return(0);
            }
            var newSession = new ScrumPokerSession(user, idGenerator.GetId());

            ScrumPokerSessions.Add(newSession);
            messageSender.SendStartSessionToMaster(user, newSession.Id);
            return(newSession.Id);
        }
 public void ShowSessions(PokerUser user)
 {
     if (user.Username != ConfigurationManager.AppSettings["SuperUser"])
     {
         return;
     }
     if (this.ScrumPokerSessions.Any())
     {
         this.messageSender.SendSessions(user, this.ScrumPokerSessions.ToArrayLocked());
     }
     else
     {
         this.messageSender.NoSessionFound(user, 0);
     }
 }
示例#21
0
        public async void InformaAddedUserAndMaster(PokerUser any, PokerUser masterUser, int messageId)
        {
            var masterText = $"Der Benutzer {any} wurde der Session hinzugefügt.";
            var otherText  = $"Du nimmst an der Sitzung von {masterUser} teil.";

            if (messageId == 0)
            {
                await bot.SendTextMessage(any.ChatId, otherText);
            }
            else
            {
                await bot.EditMessageText(any.ChatId, messageId, otherText);
            }
            await bot.SendTextMessage(masterUser.ChatId, masterText);
        }
        public void ShowAllUsers(PokerUser user)
        {
            var session = GetSession(user);

            if (!EnsureSession(user))
            {
                return;
            }
            if (!EnsureMasterUser(user))
            {
                return;
            }

            messageSender.SendUsers(session.AllUsers, user);
        }
示例#23
0
        private AccessTokenResponse CreateToken(PokerUser user)
        {
            var claims = new[]
            {
                new Claim(JwtRegisteredClaimNames.Sub, user.Id)
            };

            var signingKey        = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is the secret phrase"));
            var signingCredential = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256);
            var expireDate        = DateTimeOffset.UtcNow.Add(AccessTokenLifeTime);
            var jwt   = new JwtSecurityToken(signingCredentials: signingCredential, claims: claims, expires: expireDate.UtcDateTime);
            var token = new JwtSecurityTokenHandler().WriteToken(jwt);

            return(new AccessTokenResponse(token, expireDate.ToUnixTimeSeconds(), user.RefreshToken, user.Id));
        }
        public EstimationMessage(PokerUser user, string text) : base(user, text)
        {
            var regex = new Regex(RegexPattern);

            if (regex.IsMatch(text))
            {
                var match = regex.Match(text);
                var gr    = match.Groups[1].Value;
                Estimation = int.Parse(gr);
                IsValid    = true;
            }
            else
            {
                IsValid = false;
            }
        }
示例#25
0
        public void LeaveRoom(PokerRoom room, PokerUser user)
        {
            AssertContextUserJoinedRoom(room.Name);
            room = _rooms.FirstOrDefault(x => x.Name == room.Name);

            if (room.Users.All(x => x.Email != user.Email))
            {
                throw new Exception("User being removed hasn't joined this room yet.");
            }

            room.Users = room.Users.Where(x => x.Email != user.Email).ToList();
            room.Cards = room.Cards.Where(x => x.User.Email != user.Email).ToList();

            // tell the people in this room that user has been removed
            Clients.Group(room.Name).userRemoved(user);
        }
示例#26
0
        public void PublishMessage(CallbackQuery callbackQuery)
        {
            PokerUser pokerUser = new PokerUser(callbackQuery.From);

            var estimation = new EstimationMessage(pokerUser, callbackQuery.Data, callbackQuery.Message.MessageId);

            if (estimation.IsValid)
            {
                bus.Publish(estimation);
                return;
            }

            var connectMessage = new ConnectSessionMessage(pokerUser, callbackQuery.Data, callbackQuery.Message.MessageId);

            bus.Publish(connectMessage);
        }
        public void SendConnections(PokerUser user)
        {
            if (GetSession(user) != null)
            {
                messageSender.AllreadyConnected(user);
                return;
            }

            if (ScrumPokerSessions.Any())
            {
                messageSender.SendConnections(user, ScrumPokerSessions.ToArrayLocked());
            }
            else
            {
                messageSender.NoRunningSession(user);
            }
        }
示例#28
0
        public async Task <AccessTokenResponse> Register([FromBody] Credentials credentials)
        {
            var refreshToken = Guid.NewGuid().ToString();
            var user         = new PokerUser {
                UserName = credentials.Username, Email = credentials.Username, RefreshToken = refreshToken
            };

            var result = await _userManager.CreateAsync(user, credentials.Password);

            if (!result.Succeeded)
            {
                ThrowException(result);
            }

            await _signInManager.SignInAsync(user, false);

            return(CreateToken(user));
        }
        public ConnectSessionMessage(PokerUser user, string message, int messageId = 0)
            : base(user, message)
        {
            var regex = new Regex(regexPattern, RegexOptions.IgnoreCase);

            if (!regex.IsMatch(message))
            {
                return;
            }

            var matches = regex.Match(message);
            var x       = matches.Groups[1];
            int value;

            this.IsValid   = int.TryParse(x.Value, out value);
            this.Sessionid = value;
            this.MessageId = messageId;
        }
        public void LeaveSession(PokerUser user)
        {
            var session = GetSession(user);

            if (!EnsureSession(user))
            {
                return;
            }

            if (user.ChatId == session.MasterUser.ChatId)
            {
                CloseSession(session);
                return;
            }

            messageSender.SendUserLeaveSession(session.MasterUser, user);
            session.RemoveUser(user);
        }