Esempio n. 1
0
        public static LoginResponse Login(string login, string password)
        {
            var db = new DbDataContext();
            var hp = SpringAccount.HashPassword(password);

            var user = db.SpringAccounts.SingleOrDefault(x => x.Name == login);

            if (user == null)
            {
                return(LoginResponse.InvalidLogin);
            }

            if (user.Password != hp)
            {
                return(LoginResponse.InvalidPassword);
            }

            if (user.Players == null)
            {
                return(LoginResponse.Unregistered);
            }

            user.Players.IsActive = true;
            db.SubmitChanges();
            return(LoginResponse.Ok);
        }
		static void Main(string[] args)
		{
			var db = new DbDataContext();

			var dict = db.SpringAccounts.ToDictionary(x => x.SpringAccountID);

			var path = args.Length > 0 ? args[0] : @"accounts.txt";
			using (var r = new StreamReader(path)) {
				string line;
				while ((line = r.ReadLine()) != null) {
					try {
						var parts = line.Split(' ');
						if (parts.Length < 9) {
							Trace.TraceError("Faulty line: ", line);
							continue;
						}

						var name = parts[0];
						var pass = parts[1];
						var flags = parts[2];
						var cookie = int.Parse(parts[3]);
						var lastLogin = ConvertTimestamp(double.Parse(parts[4])/1000);
						var lastIP = parts[5];
						var registered = ConvertTimestamp(double.Parse(parts[6])/1000);
						var country = parts[7];
						var id = int.Parse(parts[8]);

						SpringAccount de = null;
						dict.TryGetValue(id, out de);
						SpringAccount ac = null;

						Console.WriteLine(string.Format("{0} {1}", id, name));
						if (de == null || name != de.Name || pass != de.Password || cookie != de.UserCookie || lastIP != de.LastIP) {
							if (de == null) {
								ac = new SpringAccount();
								db.SpringAccounts.InsertOnSubmit(ac);
							}
							else ac = db.SpringAccounts.SingleOrDefault(x => x.SpringAccountID == id);

							ac.SpringAccountID = id;
							ac.Name = name;
							ac.Flags = flags;
							ac.Password = pass;
							ac.UserCookie = cookie;
							ac.LastLogin = lastLogin;
							ac.LastIP = lastIP;
							ac.Created = registered;
							ac.LastCountry = country;
							Console.Write(" CHANGED!");
							db.SubmitChanges();
						}
					} catch (Exception e) {
						Console.WriteLine("Problem importing line: {0}: {1}", line, e);
						db = new DbDataContext();
					}
				}
			}
		}
Esempio n. 3
0
        public static RegisterResponse Register(string login, string password)
        {
            using (var t = new TransactionScope()) {
                var db   = new DbDataContext();
                var user = db.SpringAccounts.SingleOrDefault(x => x.Name == login);
                if (user == null)
                {
                    return(RegisterResponse.NotValidSpringLogin);
                }

                if (user.Players != null)
                {
                    return(RegisterResponse.AlreadyRegistered);
                }

                if (db.SpringAccounts.Any(x => x.UserCookie == user.UserCookie && x.Players != null))
                {
                    return(RegisterResponse.IsSmurf);
                }

                if (user.Password != SpringAccount.HashPassword(password))
                {
                    return(RegisterResponse.NotValidSpringPassword);
                }

                // create player and assign to smallest alliance
                var player = new Player()
                {
                    IsActive = true, StarSystem = db.StarSystems.OrderBy(x => x.Players.Where(y => y.IsActive).Count()).First()
                };
                user.Players          = player;
                player.MothershipName = player.SpringAccount.Name + "'s mothership";

                // create his planet
                var mg        = new MapGen();
                var hisPlanet = mg.CreateHomeworld(player.StarSystem.CelestialObject);
                hisPlanet.Name   = player.SpringAccount.Name + "'s home";
                hisPlanet.Player = player;
                player.StarSystem.CelestialObject.ChildCelestialObjects.Add(hisPlanet);

                hisPlanet.UpdateIncomeInfo();

                db.SubmitChanges();

                var e = db.AddEvent(EventType.Player, "{0} joined the {1}", player.Name, player.StarSystem.Name);
                e.Connect(player);
                e.Connect(hisPlanet);
                db.MarkDirty();
                db.SubmitChanges();
                t.Complete();
                return(RegisterResponse.Ok);
            }
        }
 partial void DeleteSpringAccount(SpringAccount instance);
 partial void UpdateSpringAccount(SpringAccount instance);
 partial void InsertSpringAccount(SpringAccount instance);
 public Player GetPlayer(string login, string password)
 {
     return
         (SpringAccounts.Where(x => x.Name == login && x.Password == SpringAccount.HashPassword(password) && x.Players != null && x.Players.IsActive).Select
              (x => x.Players).SingleOrDefault());
 }