//adds one scout to a user private void AddScoutToUSer(GeobieUser u) { if (IsUserRegistered(u)) { foreach (GeobieUser user in users) { if (u.Username.ToLower() == user.Username.ToLower() && !user.CurrentScouter) { user.NumberOfScouts++; user.NumCurrentScouts++; user.CurrentScouter = true; WriteToFile(); } else if (u.Username.ToLower() == user.Username.ToLower()) { user.NumCurrentScouts++; } } } else { users.Add(u); u.NumberOfScouts++; u.NumCurrentScouts++; u.CurrentScouter = true; WriteToFile(); } }
//adds a world the the list with the user who entered it public string AddWorld(string username, int world, string skill) { if (world > 0 && world <= 140) { //set up user to compare to the list GeobieUser u = new GeobieUser(username); GeobieWorld w = new GeobieWorld(world, username); if (!CheckIfWorldIsUsed(w)) { if (!w.IsFreeWorld) { string output = ""; //output switch (skill.ToLower()) { case "a": AddScoutToUSer(u); AddWorldToSkill("agil", w); output = u.Username + " added as a scout."; break; case "f": AddScoutToUSer(u); AddWorldToSkill("farm", w); output = u.Username + " added as a scout."; break; case "w": AddScoutToUSer(u); AddWorldToSkill("hunt", w); output = u.Username + " added as a scout."; break; default: output = "Incorrect skills."; break; } LastUpdated = DateTime.Now; return(output); } else { return("That world is not availble."); } } else { return("World is already registered."); } } else { return("Invalid world."); } }
//removes a world from the list public string RemoveWorld(int world) { GeobieWorld w = new GeobieWorld(world); string output = "World " + world + " removed."; if (skill1.Contains(w)) { for (int i = 0; i < skill1.Count; ++i) { if (w.Equals(skill1[i])) { GeobieUser u = new GeobieUser(skill1[i].ScoutName); if (users.Contains(u)) { RemoveScoutFromUser(u.Username); } } } skill1.Remove(w); } else if (skill2.Contains(w)) { for (int i = 0; i < skill2.Count; ++i) { if (w.Equals(skill2[i])) { GeobieUser u = new GeobieUser(skill2[i].ScoutName); if (users.Contains(u)) { RemoveScoutFromUser(u.Username); } } } skill2.Remove(w); } else if (skill3.Contains(w)) { for (int i = 0; i < skill3.Count; ++i) { if (w.Equals(skill3[i])) { GeobieUser u = new GeobieUser(skill3[i].ScoutName); if (users.Contains(u)) { RemoveScoutFromUser(u.Username); } } } skill3.Remove(w); } else { output = "World not found."; } return(output); }
//check if user is on the list private bool IsUserRegistered(GeobieUser user) { if (users.Contains(user)) { return(true); } else { return(false); } }
//reads geobie user data from file on startup private void ReadFromFile() { string filepath = Config.FILEPATH + "\\Geobie\\Users.txt"; var file = File.OpenRead(filepath); StreamReader sr = new StreamReader(file); string line = ""; while ((line = sr.ReadLine()) != null) { string[] values = line.Split(','); GeobieUser u = new GeobieUser(values[0]); u.NumberOfScouts = Convert.ToInt32(values[1]); users.Add(u); } sr.Dispose(); file.Dispose(); }