Exemplo n.º 1
0
    public MongoDBRef SpawnDefaultWorker(string workerName)
    {
        DB_Worker defaultWorker = new DB_Worker();

        defaultWorker.activity   = WORKER_ACTIVITY.IDLE;
        defaultWorker.workerName = workerName;

        //TODO: change default spawn location
        defaultWorker.location = GETNEXTAVAILABLESHIPDBREFERENCETESTTTT();

        //stats
        //**
        //TODO populate
        //**

        //appearance
        //**
        //TODO populate
        //**

        workerCollection.Insert(defaultWorker);

        //Add player reference to default spawn location
        //get location
        //TODO: make default spawn location a colony, not a ship (?)
        DB_Ship ship = FetchShipByID(defaultWorker.location.Id.AsObjectId);

        //get worker from db (for db ref)
        defaultWorker = FetchWorkerByName(workerName);
        //update location
        ship.workersOnBoard.Add(new MongoDBRef(COLLECTIONS.WORKERS, defaultWorker._id));
        updateShip(ship);

        return(new MongoDBRef("workers", workerCollection.FindOne(Query <DB_Worker> .EQ(w => w.workerName, workerName))._id));
    }
Exemplo n.º 2
0
        public void AlreadyCreatedSearch(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            // Cycle 0 - Check to see if we have the person in a local database as a PID
            // First find out if we already have the citizen
            // We need to ensure that we log what we are doing into the database
            var testDB = new DB_Worker(yamlc.GetLS("LODBC"),
                                       yamlc.GetLS("LSERVER"),  // server needed for IP based connections
                                       yamlc.GetLS("LDB"),
                                       yamlc.GetLS("LDBUN"),
                                       yamlc.GetLS("LDBPW"));

            // This is going to return a list of possible matches (should only be one)
            string[] ret = testDB.Read(yamlc.GetLM(yamlc.GetLM("SEARCH1")).Replace("#" + yamlc.GetLM("SEARCH1").ToUpper() + "#", MatchId));
            if (ret.Count() > 0)
            {
                PRET.Add("MATCHING", ret[0]);
                // We have a match, so would normally exit here
            }
        }
Exemplo n.º 3
0
        // If we don't find it locally, we need to say we don't
        public void TrawlRemoteDatabase(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            var testDB = new DB_Worker(yamlc.GetRS("RODBC"),
                                       yamlc.GetRS("RSERVER"),  // server needed for IP based connections
                                       yamlc.GetRS("RDB"),
                                       yamlc.GetRS("RDBUN"),
                                       yamlc.GetRS("RDBPW"));

            // Lets get the search count
            int cnt = Convert.ToInt32(yamlc.GetRM("SEARCHCOUNT"));

            for (int i = 1; i <= cnt; i++)
            {
                string[] post = new string[] { };   // Although this gets populated, we don't actually do anything with it as it also populates PRET

                string se = yamlc.GetRM("SEARCH" + i);

                QueryRemoteDB(ref PRET, ref yamlc, ref testDB, ref post, se);
            }
        }
        public dynamic Process(ref YAML_Config yamlc, ref Dictionary <string, string> PRET)
        {
            // Pret is where we are going to put all of our answers
            //Dictionary <string,string> PRET = new Dictionary <string,string>{};

            // Find out what the PID and LoA values are
            PRET.Add("PID", GetSafe(this.Pid));
            PRET.Add("LOA", GetSafe(this.LevelOfAssurance));
            PRET.Add("USERNAME", GetSafe(this.Username));
            PRET.Add("PASSWORD", GetSafe(this.Password));
            PRET.Add("ACCOUNTID", GetSafe(this.AccountId));

            // We need to pull out the Firstname, Surname, and DoB, all of these have optional
            // properties

            // FIRST NAME
            try
            {
                PRET.Add("FN", GetSafe(this.FirstName?.Value));
                PRET.Add("FNVER", GetSafe(this.FirstName?.Verified).ToString());
                PRET.Add("FNTO", GetSafe(this.FirstName?.ToDate));
                PRET.Add("FNFROM", GetSafe(this.FirstName?.FromDate));
            }
            catch
            {
                // Something went wrong with the forenames (object not defined)
            }
            // Not sure what it would do if there wasn't a surname?
            // SURNAME LIST
            try
            {
                var Surnames = this.Surnames.GetEnumerator();

                // Enumerate over the different surnames
                try
                {
                    var cnt = 0;
                    while (Surnames.MoveNext())
                    {
                        cnt++;

                        var SNto = GetSafe(Surnames.Current.ToDate);

                        DateTime dtTD  = DateTime.Now;
                        DateTime dtNow = DateTime.Now;

                        if (string.IsNullOrEmpty(SNto)) // ToDate couild be blank, meaning they are still there
                        {
                            PRET.Add("SURNAMETO", SNto);
                            PRET.Add("SURNAMEFROM", GetSafe(Surnames.Current.FromDate));
                            PRET.Add("SURNAME", GetSafe(Surnames.Current.Value));
                            PRET.Add("SURNAMEVER", GetSafe(Surnames.Current.Verified).ToString());
                        }
                        else          // ToDate could be ahead of Now, meaning they are still living there
                        {
                            dtTD = Convert.ToDateTime(SNto);
                            if (DateTime.Compare(dtTD, dtNow) >= 0)
                            {
                                PRET.Add("SURNAMETO", SNto);
                                PRET.Add("SURNAMEFROM", GetSafe(Surnames.Current.FromDate));
                                PRET.Add("SURNAME", GetSafe(Surnames.Current.Value));
                                PRET.Add("SURNAMEVER", GetSafe(Surnames.Current.Verified).ToString());
                            }
                        }
                    }
                }
                finally
                {
                    Surnames.Dispose();
                }
            }
            catch
            {
            }

            // Gender
            try
            {
                PRET.Add("GENDER", GetSafe(this.Gender?.Value));
                PRET.Add("GENDERVER", GetSafe(this.Gender?.Verified).ToString());
                PRET.Add("GENDERTO", GetSafe(this.Gender?.ToDate));
                PRET.Add("GENDERFROM", GetSafe(this.Gender?.FromDate));
            }
            catch
            {
                // No Gender information
            }
            // Date of Birth
            try
            {
                PRET.Add("DOB", GetSafe(this.DateOfBirth?.Value));
                PRET.Add("DOBRVER", GetSafe(this.DateOfBirth?.Verified).ToString());
                PRET.Add("DOBTO", GetSafe(this.DateOfBirth?.ToDate));
                PRET.Add("DOBFROM", GetSafe(this.DateOfBirth?.FromDate));
            }
            catch
            {
                // No DOB info
            }
            // If this is NULL then no address would be searched.
            var Address = GetSafe(this.Address);

            try
            {
                var PCto = GetSafe(Address.ToDate);

                // -------------------------------------------------------------------------------
                // We need to decide which of the Addresses to use
                // -------------------------------------------------------------------------------
                DateTime dtTD  = DateTime.Now;
                DateTime dtNow = DateTime.Now;

                if (string.IsNullOrEmpty(PCto)) // ToDate couild be blank, meaning they are still there
                {
                    PRET.Add("INTERNATIONALPOSTCODE", GetSafe(Address?.InternationalPostCode));
                    PRET.Add("POSTCODE", GetSafe(Address?.PostCode));
                    PRET.Add("POSTCODEVER", GetSafe(Address?.Verified).ToString());
                    PRET.Add("POSTCODEFROM", GetSafe(Address?.FromDate));
                    PRET.Add("POSTCODETO", PCto);
                }
                else          // ToDate could be ahead of Now, meaning they are still living there
                {
                    dtTD = Convert.ToDateTime(PCto);
                    if (DateTime.Compare(dtTD, dtNow) >= 0)
                    {
                        PRET.Add("INTERNATIONALPOSTCODE", GetSafe(Address?.InternationalPostCode));
                        PRET.Add("POSTCODE", GetSafe(Address?.PostCode));
                        PRET.Add("POSTCODEVER", GetSafe(Address?.Verified).ToString());
                        PRET.Add("POSTCODEFROM", GetSafe(Address?.FromDate));
                        PRET.Add("POSTCODETO", PCto);
                    }
                }

                var Lines = Address.Lines.GetEnumerator();

                // Enumerate over the different addresses
                try
                {
                    var cnt = 1;
                    while (Lines.MoveNext())
                    {
                        PRET.Add("ADDRESS" + cnt.ToString(), GetSafe(Lines.Current));
                        cnt++;
                    }
                }
                finally
                {
                    Lines.Dispose();
                }
            }
            catch
            {
                // We don't need to do anything
            }
            // We need to ensure that we log what we are doing into the database
            var testDB = new DB_Worker(yamlc.GetLS("LODBC"),
                                       yamlc.GetLS("LSERVER"),  // server needed for IP based connections
                                       yamlc.GetLS("LDB"),
                                       yamlc.GetLS("LDBUN"),
                                       yamlc.GetLS("LDBPW"));


            string[] ret = testDB.Read(yamlc.GetLM(yamlc.GetLM("SEARCH1")).Replace("#" + yamlc.GetLM("SEARCH1").ToUpper() + "#", PRET.GetValueOrDefault(yamlc.GetLM("SEARCH1").ToUpper())));

            if (ret.Count() > 0)
            {
                PRET.Add("ALREADYEXISTS", ret[0].ToString());
            }
            else
            {
                string   Y   = yamlc.GetLC("SEARCH1");
                string[] sep = new string[] { };
                int      cnt = 1;
                if (Y.Substring(0, 1) == "[")
                {
                    sep = Y.Substring(2, Y.Length - 4).Replace(" ", "").Split(",");
                    cnt = sep.Count();
                }
                else
                {
                    List <string> tmp = new List <string> {
                    };                                       // This is a bit rubbish!
                    tmp.Add(Y);
                    sep = tmp.ToArray();
                }

                // Check if we have an account number, if we don't add a NULL statement
                if (string.IsNullOrEmpty(PRET.GetValueOrDefault(sep[1].ToUpper())))
                {
                    PRET[sep[1].ToUpper()] = "NULL";
                }
                // We always need to add the account ID if we know it
                testDB.Go(yamlc.GetLC(yamlc.GetLC("SEARCH1")).Replace("#" + sep[0].ToUpper() + "#", PRET.GetValueOrDefault(sep[0].ToUpper()))
                          .Replace("#" + sep[1].ToUpper() + "#", PRET.GetValueOrDefault(sep[1].ToUpper()))
                          );

                // This tries to report what the line was that we created in the database
                string[] retchk = testDB.Read(yamlc.GetLM(yamlc.GetLM("SEARCH1")).Replace("#" + yamlc.GetLM("SEARCH1").ToUpper() + "#", PRET.GetValueOrDefault(yamlc.GetLM("SEARCH1").ToUpper())));

                if (retchk.Count() > 0)
                {
                    PRET.Add("INSERTED", retchk[0].ToString());
                }
                else
                {
                    PRET.Add("INSERTING", "NewRecord");
                }
            }

            // We always return the PRET, not a success or failure, that is handled in the value controller
            return(PRET);
        }
Exemplo n.º 5
0
    public bool CreateAccount(string username, string hashedPassword, string email)
    {
        //*********************************Account creation*********************************
        DB_Account account = new DB_Account();

        //validate email
        //TODO: send verification e-mail
        if (!Utility.IsEmail(email))
        {
            Debug.Log(string.Format("[Login Server]: Bad e-mail: ({0})", email));
            return(false);
        }
        if (FetchAccountByEmail(email) != null)
        {
            Debug.Log(string.Format("[Login Server]: E-mail taken: ({0})", email));
            return(false);
        }
        account.Email = email;

        //validate username
        if (!Utility.IsUsername(username))
        {
            Debug.Log(string.Format("[Login Server]: Bad username: ({0})", username));
            return(false);
        }
        account.Username = username;

        //TODO check password validity (don't delete me future Darren...)
        account.ShaPassword = hashedPassword;

        //get discriminator
        int discriminatorInt = 0;

        while (FetchAccountByUsernameAndDiscriminator(username + "#" + discriminatorInt.ToString().PadLeft(4, '0')) != null)
        {
            discriminatorInt++;
        }
        account.Discriminator = discriminatorInt.ToString().PadLeft(4, '0');

        //default to offline status
        account.Status = LoginStatus.Offline;

        //TODO: dynamically assign default sector
        account.Sector = SECTOR_CODE.REDSECTOR;

        account.CreatedOn = DateTime.Now;
        account.LastLogin = account.CreatedOn;
        //*********************************************************************************

        //*********************************Player creation*********************************
        DB_Player player = new DB_Player();

        player.Username      = account.Username;
        player.Discriminator = account.Discriminator;
        player.CreatedOn     = account.CreatedOn;
        player.LastLogin     = account.CreatedOn;

        //TODO: change up this worker generation so that we just call a createWorker(DB_Worker worker) method
        //assign default worker for new player
        //TODO: allow this worker to be customized (appearance/name)
        player.Workers = new List <MongoDBRef>();
        player.Workers.Add(SpawnDefaultWorker("DEFAULT WORKER NAME" + UnityEngine.Random.Range(0, 10000)));
        player.ActiveWorkerIndex = 0;
        //*********************************************************************************

        //now that all data is validated and set:
        //insert account
        accountCollection.Insert(account);
        //insert player
        playerCollection.Insert(player);

        //set default worker's owner ref
        //get player from db (for db ref)
        player = FetchPlayerByUsernameAndDiscriminator(account.Username + "#" + account.Discriminator);
        //get and update worker
        DB_Worker worker = FetchWorkerByID(player.Workers[player.ActiveWorkerIndex].Id.AsObjectId);

        worker.owner = new MongoDBRef(COLLECTIONS.PLAYERS, player._id);
        updateWorker(worker);

        //TODO: remove this TESTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
        //set default ship's owner ref
        //get and update ship
        DB_Ship ship = FetchShipByID(worker.location.Id.AsObjectId);

        ship.Owner = new MongoDBRef(COLLECTIONS.PLAYERS, player._id);
        updateShip(ship);

        return(true);
    }
Exemplo n.º 6
0
    public void updateWorker(DB_Worker workerUpdate)
    {
        IMongoQuery query = Query <DB_Worker> .EQ(w => w._id, workerUpdate._id);

        workerCollection.Update(query, Update <DB_Worker> .Replace(workerUpdate));
    }
Exemplo n.º 7
0
        // This function is a helper which will read the database, and add any results onto the PRET dictionary.
        // It will automatically do the substitution
        public void QueryRemoteDB(ref Dictionary <string, string> PRET, ref YAML_Config yamlc, ref DB_Worker testDB, ref string[] post, string Y)
        {
            string[] sep = new string[] {};
            int      cnt = 1;

            if (Y.Substring(0, 1) == "[")
            {
                sep = Y.Substring(2, Y.Length - 4).Replace(" ", "").Split(",");
                cnt = sep.Count();
            }
            else
            {
                List <string> tmp = new List <string> {
                };                                     // This is a bit rubbish!
                tmp.Add(Y);
                sep = tmp.ToArray();
            }

            string serstr = yamlc.GetRM(Y);

            for (int j = 0; j < cnt; j++)
            {
                if (sep[j].Substring(sep[j].Length - 1) == "?")
                {
                    sep[j] = sep[j].Substring(0, sep[j].Length - 1);
                    for (int m = 1; m < 10; m++)
                    {
                        string upr = sep[j].ToUpper() + m.ToString();
                        serstr = serstr.Replace("#" + upr + "#", PRET.GetValueOrDefault(upr));
#if DEBUG
                        Console.WriteLine(sep[j] + m.ToString() + " - " + PRET.GetValueOrDefault(upr));
#endif
                    }
                }
                else
                {
                    string upr = sep[j].ToUpper();
                    serstr = serstr.Replace("#" + upr + "#", PRET.GetValueOrDefault(upr));
#if DEBUG
                    Console.WriteLine(sep[j] + " - " + PRET.GetValueOrDefault(upr));
#endif
                }
            }

            string PR = sep[0].ToUpper();

            post = testDB.Read(serstr);

            PRET.Add("MATCHINGCOUNT" + PR, post.Count().ToString());

            for (int i = 0; i < post.Count(); i++)
            {
                PRET.Add(PR.Substring(0, 3) + (i + 1).ToString(), post[i]);
            }
        }