Beispiel #1
0
 public User(string id, string name, UInt32 time, string ip, bool online, long last, UInt32 member, int karma, bool vac, DateTime first, UInt32 votes, Auth auth, bool watched, int warn)
 {
     this.id        = id;
     this.name      = name;
     this.time      = (int)time;
     this.ip        = ip;
     this.online    = online;
     this.last      = last;
     this.member    = (int)member;
     this.karma     = karma;
     this.vac       = vac;
     this.first     = first;
     this.votes     = (int)votes;
     this.auth      = auth;
     this.warn      = warn;
     this.safe_name = name.Replace("\"", "\\\"");
 }
Beispiel #2
0
        public User GetUserById(string id)
        {
            UInt64 proper_id = 0;

            if (!UInt64.TryParse(id, out proper_id))
            {
                return(null);
            }

            using (MySqlConnection connection = connect())
            {
                MySqlCommand query = new MySqlCommand("SELECT `id`, `name`, `time`, `ip`, `online`, `last`, `member`, `karma`, `vac`, `first`, `votes`, `auth`, `watched`, `warn` FROM `users` WHERE `id` = ?id;", connection);
                query.Prepare();
                query.Parameters.Add("?id", proper_id);


                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    if (!reader.HasRows)
                    {
                        return(null);
                    }

                    reader.Read();

                    User result = new User(reader["id"].ToString(), reader["name"].ToString(), (UInt32)reader["time"], reader["ip"].ToString(), (sbyte)reader["online"] == 1, (long)(UInt64)reader["last"], (UInt32)reader["member"], (int)reader["karma"], (sbyte)reader["vac"] == 1, (DateTime)reader["first"], (UInt32)reader["votes"], (String.IsNullOrEmpty(reader["auth"].ToString()) ? Auth.None : Auth.Parse(reader["auth"].ToString())), (sbyte)reader["watched"] == 1, (int)reader["warn"]);
                    return(result);
                }
            }
        }
Beispiel #3
0
        private void cron_userstats()
        {
            TimeSpan wait = (this.crons["cron_userstats"] - DateTime.Now);

            if (wait.TotalSeconds > 1)
            {
                Thread.Sleep(wait);
            }

            List <User> floatings = new List <User>();

            while (true)
            {
                Package status = new Package("status");
                status.RegisterCallback((Package result) =>
                {
                    MatchCollection matches   = Regex.Matches(result.Response, Program.validations["user-lines"]);
                    List <User> new_floatings = new List <User>();

                    foreach (Match submatch in matches)
                    {
                        User floating = new User(submatch.Groups[1].Value, submatch.Groups[2].Value, submatch.Groups[4].Value, submatch.Groups[5].Value);
                        User bound    = Data.Instance.GetUserById(floating.ID);
                        new_floatings.Add(floating);

                        // Check user online state
                        if (bound == null || !bound.Online)
                        {
                            rcon.Inject(new Package(0, 4, String.Format("User Connected: {0} ({1})", floating.SafeName, floating.ID)));
                            continue;
                        }

                        User pre_floating = floatings.Where(match => match.ID == floating.ID).FirstOrDefault();
                        if (pre_floating != null)
                        {
                            Auth previous = bound.Auth;
                            if (pre_floating.Time < floating.Time)
                            {
                                // Default add (10s -> 20s, add 10s)
                                bound.Time += floating.Time - pre_floating.Time;
                                Data.Instance.UserAddTime(bound, floating.Time - pre_floating.Time);
                            }
                            else if (pre_floating.Time > floating.Time)
                            {
                                // Disconnect at 10 seconds, reconnect with 5 seconds, add 5 seconds
                                bound.Time += floating.Time;
                                Data.Instance.UserAddTime(bound, floating.Time);
                            }
                            else
                            {
                                // Unlikely, don't do anything.
                                // Only case is when user connects, stays 3 seconds, disconnects, then connects and is scanned after 3 seconds
                                // They can only lose up to 10 seconds
                            }

                            if (bound.Auth != previous)     // Auth change
                            {
                                string text = Language.Say(String.Format("vip-{0}-grats", bound.Auth.ToString()), bound, bound.Name, bound.Auth);
                                if (text != null)
                                {
                                    rcon.Send(text);
                                }
                            }
                            bound.Save();
                        }
                    }
                    foreach (User user in Data.Instance.GetOnlineUsers())
                    {
                        if (new_floatings.Count(match => match.ID == user.ID) == 0)
                        {
                            if (!user_timeout.ContainsKey(user.ID))
                            {
                                user_timeout.Add(user.ID, DateTime.Now);
                                rcon.Send(Language.Say("tabout", user, user.Colour, user.Name));
                            }
                            if (user_timeout[user.ID].AddMinutes(5) < DateTime.Now)
                            {
                                user_timeout.Remove(user.ID);
                                rcon.Send(Language.Say("timeout", user, user.Colour, user.Name));
                                rcon.Inject(new Package(0, 4, String.Format("User Disconnected: {0}", user.SafeName)));
                                continue;
                            }
                        }
                        else if (user_timeout.ContainsKey(user.ID))
                        {
                            user_timeout.Remove(user.ID);
                            rcon.Send(Language.Say("tabin", user, user.Colour, user.Name));
                        }
                    }
                    floatings = new_floatings;
                });
                rcon.SendPackage(status);

                Data.Instance.SaveCron("cron_userstats", DateTime.Now.AddMilliseconds(1000 * 10));
                Thread.Sleep(1000 * 10);
            }
        }