Ejemplo n.º 1
0
 internal static void SaveUserData(User userObj)
 {
     XElement user = GetUserXElement(userObj.UserName);
     if (user != null)
     {
         user.Element("Value").Value = userObj.Value.ToString();
     }
     else
     {
         XUsers.Add(
             new XElement("User",
                 new XElement("Name", userObj.UserName),
                 new XElement("Value", userObj.Value)));
     }
     XDoc.Save(_dbName);
 }
Ejemplo n.º 2
0
        private void _ircClient_OnChannelMessage(object sender, IrcEventArgs e)
        {
            string message = e.Data.Message;
            User user = GetUser(e.Data.Nick);
            if(user == null)
            {
                user = new User(e.Data.Nick, _defaultStartValue);
                _users.Add(user);
            }

            if (message.StartsWith("!bet"))
            {
                if (!BettingOpen)
                {
                    SendMessage(user.UserName + ": Betting is not open.");
                    return;
                }

                string[] split = message.Split(' ');
                if (split.Count() != 3)
                {
                    SendMessage(user.UserName + ": Invalid Bet. !bet ### <team name>");
                    return;
                }

                int value = 0;
                bool success = int.TryParse(split[1], out value);

                if (!success)
                {
                    SendMessage(user.UserName + ": Invalid Bet. !bet ### <team name>");
                    return;
                }

                if(value > user.Value)
                {
                    SendMessage(user.UserName + ": Cannot bet more than you have.");
                    return;
                }

                string teamName = split[2];
                if (teamName != _teamOne && teamName != _teamTwo)
                {
                    SendMessage(user.UserName + ": Invalid Bet. !bet ### <team name>");
                    return;
                }

                _bets.Add(new Bet() { User = user, BetValue = value, Team = teamName });
                user.Value -= value;
                _viewModel.OnPropertyChanged("BetsPlaced");
                _viewModel.OnPropertyChanged("TotalPot");
            }

            if (message.StartsWith("!credits"))
            {
                SendMessage(user.UserName + ": " + user.Value + " credits.");
            }
        }
Ejemplo n.º 3
0
        internal string Give(string giveUserName, string giveAmount)
        {
            string error = "";
            User user = GetUser(giveUserName);

            if(user == null)
            {
                user = new User(giveUserName, _defaultStartValue);
                _users.Add(user);
            }

            int value = 0;

            bool success = int.TryParse(giveAmount, out value);

            if (success)
            {
                user.Value += value;
                SendMessage("Gave " + giveUserName + " " + giveAmount + " credits.");
            }
            else
                error = "Failed to get number value from amount.";

            return error;
        }