Esempio n. 1
0
 public JoinedMapData(CmrMap theMap, Denial theDenial, User theMapper, User theTester)
 {
     this.denial = theDenial;
     this.map = theMap;
     this.mapper = theMapper;
     this.tester = theTester;
 }
Esempio n. 2
0
 /// <summary>
 /// Saves the user to the Users table.
 /// </summary>
 /// <param name="user">The user.</param>
 public void SaveUser(User user)
 {
     var result = Users.Save(user);
 }
Esempio n. 3
0
 /// <summary>
 /// Adds the user to the database. Returns whether or not the user 
 /// </summary>
 /// <param name="user">The user.</param>
 /// <returns>Whether the operation was successful.</returns>
 public bool AddUser(User user)
 {
     if (user.Id != ObjectId.Empty) {
         Console.WriteLine("Trying to add a user whose ID has already been set ????");
         User dupe = this[user.Id];
         Console.WriteLine("currently in db\n" + dupe.ToString());
         Console.WriteLine("attempting to add\n" + user.ToString());
         Console.WriteLine("NOT ADDING TO DATABASE");
         return false;
     }
     Users.Save(user);
     return true;
 }
Esempio n. 4
0
        /// <summary>
        /// Attempts to set the Users password to the given password. 
        /// If no user exists by this nickname, create a new user.
        /// </summary>
        /// <param name="nickname">The nickname.</param>
        /// <param name="password">The password.</param>
        public bool AttemptRegistration(string nickname, string password)
        {
            User user = this[nickname];
            bool wasNull = false;
            if (user == null) {
                user = new User();
                user.Name = nickname;
                wasNull = true;
            }
            string nickLower = user.NameLower;
            if (FB.IsIdentified(nickLower, nickname)) {
                string[] hashes = GeneratePasswordHashes(password.Trim());
                if (!wasNull) {

                    user.Salt = hashes[0];
                    user.Password = hashes[1];
                    user.Name = nickname;
                    //userlist.Remove(nickname);
                    //userlist.Add(nickname, info);
                    SaveUser(user);
                } else {
                    user.Salt = hashes[0];
                    user.Password = hashes[1];
                    user.Name = nickname; //Overwrite name w/ new capitalization
                    SaveUser(user);
                }
                FB.Notice(nickname, "Successfully registered your nick with FurkieBot! Dont forget your password. You can always re-register if you forget the password.");
                FB.Notice(nickname, "You will now want to set your in-game dustforce name with FurkieBot. use \".setign dustforceLeaderboardName\" to set your IGN with FurkieBot.");
                return true;
            } else {
                FB.NoticeNotIdentified(nickname);
                return false;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes the database from the deprecated method of storage in FurkieBot v1. Loads users and maps from the UserList and Maps folders and puts their data into a mongo DB.
        /// </summary>
        public static void InitDBFromLocalFiles()
        {
            Console.WriteLine("Attempting to initialize the database from deprecated local files.");
            MongoDatabase db = DB.Database;
            if (DB._DB_NAME == DB._PRODUCTION_DB_NAME_DO_NOT_USE) {
                Console.WriteLine("HOLY SHIT YOU'RE ABOUT TO OVERWRITE PRODUCTION DB WITH WHATEVERS IN THOSE FILES! ARE YOU SURE? (y/n)");
                string input = Console.ReadLine();
                if (input.Trim().ToLower() == "y") {

                    Console.WriteLine("ARE YOU /REALLY/ SURE?????? (y/n)");
                    input = Console.ReadLine();
                    if (input.Trim().ToLower() == "y") {
                        Console.WriteLine("Ok");
                    } else {
                        throw new Exception("Quitting in a very non-graceful way because I dont remember how to System.Exit() in C#.");
                    }
                } else {
                    throw new Exception("Quitting in a very non-graceful way because I dont remember how to System.Exit() in C#.");
                }
            }
            #region clear the database.
            var collectionNames = db.GetCollectionNames();
            Console.WriteLine("Dropping collections....");
            foreach (string name in collectionNames) {
                if (name != "system.indexes") {
                    Console.WriteLine("Dropping collection: " + name);
                    db.DropCollection(name);
                }
            }
            Console.Write("Completed collection dropping. Collections now: ");
            collectionNames = db.GetCollectionNames();
            foreach (string name in collectionNames) {
                Console.WriteLine(name);
            }
            Console.WriteLine("Collections dropped.\n");
            #endregion

            UserManager UserMan = UserManager.Instance;
            MapManager MapMan = MapManager.Instance;

            #region Load Users
            string userbasepath = FurkieBot.USERLIST_PATH;
            string userJson = File.ReadAllText(userbasepath);
            Dictionary<string, PlayerInfo> oldUsers = JsonConvert.DeserializeObject<Dictionary<string, PlayerInfo>>(userJson);
            foreach (KeyValuePair<string, PlayerInfo> entry in oldUsers) {
                PlayerInfo oldUser = entry.Value;
                User newUser = new User();

                newUser.Admin = oldUser.admin;
                newUser.Name = oldUser.ircname;
                newUser.Notify = oldUser.notify;
                newUser.Password = oldUser.password;
                newUser.Salt = oldUser.salt;
                newUser.Streamurl = oldUser.streamurl;
                newUser.Tester = oldUser.tester;
                newUser.Rating = oldUser.rating;
                newUser.RandmapRating = oldUser.randmaprating;
                newUser.Trusted = oldUser.trusted;
                UserMan.AddUser(newUser);
                Console.WriteLine("Added user: "******"C:\CMR\MongoUserDumpAfterMigrateAdd.txt");

            #region Load Maps
            string basepath = FurkieBot.MAPS_PATH.ToLower();
            string[] mapfolders = Directory.GetDirectories(basepath);
            foreach (string s in mapfolders)
            {
                string filename = s + "\\maps.json";
                try {
                    string filetext = File.ReadAllText(filename);
                    string cmrNumber = (s.ToLower().Replace(basepath, ""));
                    int cmrInt = int.Parse(Regex.Split(cmrNumber, "/D")[0]);
                    Console.WriteLine("Attempting to load the maps for cmr number: " + cmrInt);
                    Dictionary<string, MapData> oldMaps = JsonConvert.DeserializeObject<Dictionary<string, MapData>>(filetext); //TODO real old file name
                    foreach (KeyValuePair<string, MapData> entry in oldMaps) {
                        CmrMap newMap = new CmrMap();
                        MapData oldMap = entry.Value;

                        newMap.CmrNo = cmrInt;

                        User tester = UserMan[oldMap.acceptedBy];
                        if (tester == null) {
                            tester = UserMan["EklipZ"];
                        }
                        newMap.Accepted = oldMap.accepted;
                        newMap.AcceptedById = tester.Id;

                        newMap.AtlasID = oldMap.id;

                        User author = UserMan[oldMap.author];
                        if (author != null) {
                            newMap.AuthorId = author.Id;
                        }

                        newMap.Filepath = "/" + cmrInt + "/" + oldMap.name;
                        newMap.IsDenied = false;
                        TimeSpan yearAgo = new TimeSpan(365, 0, 0, 0, 0);
                        newMap.LastModified = DB.UnixTimestamp;
                        newMap.Name = oldMap.name;

                        MapMan.AddMap(newMap);
                    }
                } catch (System.IO.FileNotFoundException e) {
                    Console.WriteLine("No file: " + filename + " found. Exception caught.");
                }
            }
            #endregion
            MapMan.DumpStateToFile(@"C:\CMR\MongoMapDumpAfterMigrateAdd.txt");

            Console.WriteLine("Done initializing database from deprecated filesystem structure. Press enter to continue.");
            Console.ReadLine();
        }