public static void Main(string[] args) { List<Box> boxes = new List<Box> (); Console.WriteLine ("Hej! Velkommen til kasse-bygger 1.0 <tm>"); do { Console.WriteLine ("Nu skal vi bygge en kasse!"); int h = GetValue ("Højde? "); int w = GetValue ("Bredde? "); int d = GetValue ("Dybde? "); Box b = new Box (h, w, d); Console.Write ("Her er din kasse: "); Console.WriteLine (b); Console.WriteLine ("Volume = " + b.Volume ().ToString ()); boxes.Add(b); Console.WriteLine("Vil du lave flere kasser? (y for ja)"); } while (Console.ReadKey().KeyChar == 'y'); Console.WriteLine ("Her er dine kasser:"); int count = 0; foreach (Box b in boxes) { Console.WriteLine (b); count = count + 1; // eller count++ } Console.WriteLine ("I alt var der " + count + " kasser"); Console.WriteLine (); Console.WriteLine ("Tryk en tast for at afslutte kasse-bygger 1.0!"); Console.ReadKey (); }
public void ReloadForMap(String map) { using (var reader = database.QueryReader("SELECT * FROM Boxes WHERE WorldID=@0", map)) { AllBoxes.Clear(); while (reader.Read()) { int X1 = reader.Get<int>("X1"); int Y1 = reader.Get<int>("Y1"); int height = reader.Get<int>("height"); int width = reader.Get<int>("width"); int Protected = reader.Get<int>("Protected"); string mergedids = reader.Get<string>("UserIds"); string name = reader.Get<string>("BoxName"); string owner = reader.Get<string>("Owner"); string groups = reader.Get<string>("Groups"); int z = reader.Get<int>("Z"); string[] splitids = mergedids.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); Box r = new Box(new Rectangle(X1, Y1, width, height), name, owner, Protected != 0, Main.worldID.ToString(), z); r.SetAllowedGroups(groups); try { for (int i = 0; i < splitids.Length; i++) { int id; if (Int32.TryParse(splitids[i], out id)) // if unparsable, it's not an int, so silently skip r.AllowedIDs.Add(id); else Log.Warn("One of your UserIDs is not a usable integer: " + splitids[i]); } } catch (Exception e) { Log.Error("Your database contains invalid UserIDs (they should be ints)."); Log.Error("A lot of things will fail because of this. You must manually delete and re-create the allowed field."); Log.Error(e.ToString()); Log.Error(e.StackTrace); } AllBoxes.Add(r); } } }
protected bool IsOwner(TSPlayer player, Box box) { return (player.UserAccountName == box.Owner || player.Group.HasPermission("boxes.admin") || player.Group.Name == "superadmin"); }