public AbstractAriesServer(AbstractAriesServerConfig config, IKernel kernel) { _Sessions = new Sessions(this); this.Kernel = kernel; this.DAFactory = Kernel.Get <IDAFactory>(); this.Config = config; if (config.Public_Host == null || config.Internal_Host == null || config.Call_Sign == null || config.Binding == null) { throw new Exception("Server configuration missing required fields"); } Kernel.Bind <IAriesPacketRouter>().ToConstant(_Router); Kernel.Bind <ISessions>().ToConstant(this._Sessions); }
public LotContainer(IDAFactory da, LotContext context, ILotHost host, IKernel kernel, LotServerConfiguration config, IRealestateDomain realestate) { VM.UseWorld = false; DAFactory = da; Host = host; Context = context; Kernel = kernel; Config = config; JobLot = (context.Id & 0x40000000) > 0; if (JobLot) { var jobPacked = Context.DbId - 0x200; var jobLevel = (short)((jobPacked - 1) & 0xF); var jobType = (short)((jobPacked - 1) / 0xF); LotPersist = new DbLot { lot_id = Context.DbId, location = Context.Id, category = LotCategory.money, name = "{job:" + jobType + ":" + jobLevel + "}", admit_mode = 4 }; LotAdj = new List <DbLot>(); LotRoommates = new List <DbRoommate>(); Terrain = new VMTSOSurroundingTerrain(); for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { Terrain.Roads[x, y] = 0xF; //crossroads everywhere } } } else { using (var db = DAFactory.Get()) { LotPersist = db.Lots.Get(context.DbId); LotAdj = db.Lots.GetAdjToLocation(context.ShardId, LotPersist.location); LotRoommates = db.Roommates.GetLotRoommates(context.DbId); } Realestate = realestate.GetByShard(LotPersist.shard_id); GenerateTerrain(); } }
protected override void Bootstrap() { var shards = Kernel.Get <IShardsDomain>(); var shard = shards.GetById(Config.ID); if (shard == null) { throw new Exception("Unable to find a shard with id " + Config.ID + ", check it exists in the database"); } LOG.Info("City identified as " + shard.Name); var context = new CityServerContext(); context.ShardId = shard.Id; context.Config = Config; Kernel.Bind <CityServerContext>().ToConstant(context); Kernel.Bind <int>().ToConstant(shard.Id).Named("ShardId"); Kernel.Bind <CityServerConfiguration>().ToConstant(Config); Kernel.Bind <LotServerPicker>().To <LotServerPicker>().InSingletonScope(); Kernel.Bind <LotAllocations>().To <LotAllocations>().InSingletonScope(); IDAFactory da = Kernel.Get <IDAFactory>(); using (var db = da.Get()){ var version = ServerVersion.Get(); db.Shards.UpdateVersion(shard.Id, version.Name, version.Number); var oldClaims = db.LotClaims.GetAllByOwner(context.Config.Call_Sign).ToList(); if (oldClaims.Count > 0) { LOG.Warn("Detected " + oldClaims.Count + " previously allocated lot claims, perhaps the server did not shut down cleanly. Lot consistency may be affected."); db.LotClaims.RemoveAllByOwner(context.Config.Call_Sign); } var oldAvatarClaims = db.AvatarClaims.GetAllByOwner(context.Config.Call_Sign).ToList(); if (oldAvatarClaims.Count > 0) { LOG.Warn("Detected " + oldAvatarClaims.Count + " avatar claims, perhaps the server did not shut down cleanly. Avatar consistency may be affected."); db.AvatarClaims.DeleteAll(context.Config.Call_Sign); } } base.Bootstrap(); }
public AdminHostsController(IDAFactory daFactory, JWTFactory jwt, IGluonHostPool hostPool) : base("/admin") { JWTTokenAuthentication.Enable(this, jwt); this.Get["/hosts"] = _ => { this.DemandAdmin(); var hosts = hostPool.GetAll(); return(Response.AsJson(hosts.Select(x => new { role = x.Role, call_sign = x.CallSign, internal_host = x.InternalHost, public_host = x.PublicHost, connected = x.Connected, time_boot = x.BootTime }))); }; }
public AdminShardOpController(IDAFactory daFactory, JWTFactory jwt, ApiServer server) : base("/admin/shards") { JWTTokenAuthentication.Enable(this, jwt); DAFactory = daFactory; Server = server; After.AddItemToEndOfPipeline(x => { x.Response.WithHeader("Access-Control-Allow-Origin", "*"); }); Post["/shutdown"] = _ => { this.DemandAdmin(); var shutdown = this.Bind <ShutdownModel>(); var type = ShutdownType.SHUTDOWN; if (shutdown.update) { type = ShutdownType.UPDATE; } else if (shutdown.restart) { type = ShutdownType.RESTART; } //JWTUserIdentity user = (JWTUserIdentity)this.Context.CurrentUser; Server.RequestShutdown((uint)shutdown.timeout, type); return(Response.AsJson(true)); }; Post["/announce"] = _ => { this.DemandModerator(); var announce = this.Bind <AnnouncementModel>(); Server.BroadcastMessage(announce.sender, announce.subject, announce.message); return(Response.AsJson(true)); }; }
public ServerLotProvider([Named("ShardId")] int shardId, IRealestateDomain realestate, IDAFactory daFactory, IServerNFSProvider nfs) { OnMissingLazyLoad = true; OnLazyLoadCacheValue = false; ShardId = shardId; GlobalRealestate = realestate; Realestate = realestate.GetByShard(shardId); DAFactory = daFactory; NFS = nfs; CityRepresentation = new City() { City_NeighborhoodsVec = ImmutableList.Create <uint>(), City_OnlineLotVector = ImmutableList.Create <bool>(), City_ReservedLotVector = ImmutableList.Create <bool>(), City_ReservedLotInfo = ImmutableDictionary.Create <uint, bool>(), City_SpotlightsVector = ImmutableList.Create <uint>(), City_Top100ListIDs = ImmutableList.Create <uint>(), City_TopTenNeighborhoodsVector = ImmutableList.Create <uint>() }; }
public void Init(NameValueCollection appSettings) { Config = new ApiConfig(); Config.Maintainance = bool.Parse(appSettings["maintainance"]); Config.AuthTicketDuration = int.Parse(appSettings["authTicketDuration"]); Config.Regkey = appSettings["regkey"]; Config.Secret = appSettings["secret"]; Config.UpdateUrl = appSettings["updateUrl"]; Config.CDNUrl = appSettings["cdnUrl"]; Config.NFSdir = appSettings["nfsdir"]; Config.UseProxy = bool.Parse(appSettings["useProxy"]); Config.UpdateID = (appSettings["updateID"] == "") ? (int?)null : int.Parse(appSettings["updateID"]); Config.BranchName = appSettings["branchName"] ?? "beta"; // new smtp config vars if (appSettings["smtpHost"] != null && appSettings["smtpUser"] != null && appSettings["smtpPassword"] != null && appSettings["smtpPort"] != null) { Config.SmtpEnabled = true; Config.SmtpHost = appSettings["smtpHost"]; Config.SmtpUser = appSettings["smtpUser"]; Config.SmtpPassword = appSettings["smtpPassword"]; Config.SmtpPort = int.Parse(appSettings["smtpPort"]); } JWT = new JWTFactory(new JWTConfiguration() { Key = System.Text.UTF8Encoding.UTF8.GetBytes(Config.Secret) }); DAFactory = new MySqlDAFactory(new Database.DatabaseConfiguration() { ConnectionString = appSettings["connectionString"] }); Shards = new Shards(DAFactory); Shards.AutoUpdate(); }
public RegistrationHandler(CityServerContext context, IDAFactory daFactory, GameContent content) { Context = context; DAFactory = daFactory; Content = content; content.AvatarCollections.Get("ea_female_heads.col") .Select(x => content.AvatarPurchasables.Get(x.PurchasableOutfitId)).ToList() .ForEach(x => ValidFemaleOutfits.Add((uint)(x.OutfitID >> 32), x)); content.AvatarCollections.Get("ea_female.col") .Select(x => content.AvatarPurchasables.Get(x.PurchasableOutfitId)).ToList() .ForEach(x => ValidFemaleOutfits.Add((uint)(x.OutfitID >> 32), x)); content.AvatarCollections.Get("ea_male_heads.col") .Select(x => content.AvatarPurchasables.Get(x.PurchasableOutfitId)).ToList() .ForEach(x => ValidMaleOutfits.Add((uint)(x.OutfitID >> 32), x)); content.AvatarCollections.Get("ea_male.col") .Select(x => content.AvatarPurchasables.Get(x.PurchasableOutfitId)).ToList() .ForEach(x => ValidMaleOutfits.Add((uint)(x.OutfitID >> 32), x)); }
public void Init(NameValueCollection appSettings) { Config = new ApiConfig(); Config.Maintainance = bool.Parse(appSettings["maintainance"]); Config.AuthTicketDuration = int.Parse(appSettings["authTicketDuration"]); Config.Regkey = appSettings["regkey"]; Config.Secret = appSettings["secret"]; Config.UpdateUrl = appSettings["updateUrl"]; Config.NFSdir = appSettings["nfsdir"]; JWT = new JWTFactory(new JWTConfiguration() { Key = System.Text.UTF8Encoding.UTF8.GetBytes(Config.Secret) }); DAFactory = new MySqlDAFactory(new Database.DatabaseConfiguration() { ConnectionString = appSettings["connectionString"] }); Shards = new Shards(DAFactory); Shards.AutoUpdate(); }
public Shards(IDAFactory factory) { _DbFactory = factory; Poll(); }
public VoltronConnectionLifecycleHandler(LotHost lots, IDAFactory da) { Lots = lots; DAFactory = da; }
public AdminUsersController(IDAFactory daFactory, JWTFactory jwt) : base("/admin") { JWTTokenAuthentication.Enable(this, jwt); this.DAFactory = daFactory; this.After.AddItemToEndOfPipeline(x => { x.Response.WithHeader("Access-Control-Allow-Origin", "*"); }); //Get information about me, useful for the admin user interface to disable UI based on who you login as this.Get["/users/current"] = _ => { this.RequiresAuthentication(); JWTUserIdentity user = (JWTUserIdentity)this.Context.CurrentUser; using (var da = daFactory.Get()) { var userModel = da.Users.GetById(user.UserID); if (userModel == null) { throw new Exception("Unable to find user"); } return(Response.AsJson <User>(userModel)); } }; //Get the attributes of a specific user this.Get["/users/{id}"] = parameters => { this.DemandModerator(); using (var da = daFactory.Get()) { var userModel = da.Users.GetById((uint)parameters.id); if (userModel == null) { throw new Exception("Unable to find user"); } return(Response.AsJson <User>(userModel)); } }; //List users this.Get["/users"] = _ => { this.DemandModerator(); using (var da = daFactory.Get()) { var offset = this.Request.Query["offset"]; var limit = this.Request.Query["limit"]; if (offset == null) { offset = 0; } if (limit == null) { limit = 20; } if (limit > 100) { limit = 100; } var result = da.Users.All((int)offset, (int)limit); return(Response.AsPagedList <User>(result)); } }; //Create a new user this.Post["/users"] = x => { this.DemandModerator(); var user = this.Bind <UserCreateModel>(); if (user.is_admin) { //I need admin claim to do this this.DemandAdmin(); } using (var da = daFactory.Get()) { var userModel = new User(); userModel.username = user.username; userModel.email = user.email; userModel.is_admin = user.is_admin; userModel.is_moderator = user.is_moderator; userModel.user_state = UserState.valid; userModel.register_date = Epoch.Now; userModel.is_banned = false; var userId = da.Users.Create(userModel); userModel = da.Users.GetById(userId); if (userModel == null) { throw new Exception("Unable to find user"); } return(Response.AsJson <User>(userModel)); } return(null); }; }
public AdminOAuthController(IDAFactory daFactory, JWTFactory jwt) : base("/admin/oauth") { Post["/token"] = _ => { var grant_type = Request.Form["grant_type"]; if (grant_type == "password") { var username = Request.Form["username"]; var password = Request.Form["password"]; using (var da = daFactory.Get) { var user = da.Users.GetByUsername(username); if (user == null || user.is_banned || !(user.is_admin || user.is_moderator)) { return(Response.AsJson(new OAuthError { error = "unauthorized_client", error_description = "user_credentials_invalid" })); } var authSettings = da.Users.GetAuthenticationSettings(user.user_id); var isPasswordCorrect = PasswordHasher.Verify(password, new PasswordHash { data = authSettings.data, scheme = authSettings.scheme_class }); if (!isPasswordCorrect) { return(Response.AsJson(new OAuthError { error = "unauthorized_client", error_description = "user_credentials_invalid" })); } var identity = new JWTUserIdentity { UserName = user.username }; var claims = new List <string>(); if (user.is_admin || user.is_moderator) { claims.Add("moderator"); } if (user.is_admin) { claims.Add("admin"); } identity.Claims = claims; identity.UserID = user.user_id; var token = jwt.CreateToken(identity); return(Response.AsJson(new OAuthSuccess { access_token = token.Token, expires_in = token.ExpiresIn })); } } return(Response.AsJson(new OAuthError { error = "invalid_request", error_description = "unknown grant_type" })); }; }
public PurchaseLotHandler(CityServerContext context, IRealestateDomain realestate, IDAFactory da, IDataService dataService) { Context = context; GlobalRealestate = realestate; Realestate = realestate.GetByShard(context.ShardId); DA = da; DataService = dataService; }
public VoltronConnectionLifecycleHandler(ISessions sessions, IDataService dataService, IDAFactory da, CityServerContext context, LotServerPicker lotServers, CityLivenessEngine engine, EventSystem events, Neighborhoods neigh) { this.VoltronSessions = sessions.GetOrCreateGroup(Groups.VOLTRON); this.Sessions = sessions; this.DataService = dataService; this.DAFactory = da; this.Context = context; this.LotServers = lotServers; this.Liveness = engine; this.Events = events; this.Neigh = neigh; }
public ServerAvatarProvider([Named("ShardId")] int shardId, IDAFactory factory) { ShardId = shardId; DAFactory = factory; }
public AuthController(IDAFactory daFactory, ApiServerConfiguration config) { this.DAFactory = daFactory; Config = config; this.Get["/AuthLogin"] = _ => { var username = this.Request.Query["username"]; var password = this.Request.Query["password"]; var version = this.Request.Query["version"]; var clientid = (string)this.Request.Query["clientid"]; if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(Response.AsText(printError(ERROR_020_CODE, ERROR_020_MSG))); } AuthTicket ticket = null; using (var db = DAFactory.Get()) { var user = db.Users.GetByUsername(username); if (user == null || user.is_banned) { return(Response.AsText(printError(ERROR_110_CODE, ERROR_110_MSG))); } if (config.Maintainance && !(user.is_admin || user.is_moderator)) { return(Response.AsText(printError(ERROR_160_CODE, ERROR_160_MSG))); } var authSettings = db.Users.GetAuthenticationSettings(user.user_id); var isPasswordCorrect = PasswordHasher.Verify(password, new PasswordHash { data = authSettings.data, scheme = authSettings.scheme_class }); if (!isPasswordCorrect) { return(Response.AsText(printError(ERROR_110_CODE, ERROR_110_MSG))); } var tryIP = Request.Headers["X-Forwarded-For"].FirstOrDefault(); if (tryIP != null) { tryIP = tryIP.Substring(tryIP.LastIndexOf(',') + 1).Trim(); } var ip = tryIP ?? this.Request.UserHostAddress; var ban = db.Bans.GetByIP(ip); if (ban != null) { return(Response.AsText(printError(ERROR_110_CODE, ERROR_110_MSG))); } db.Users.UpdateClientID(user.user_id, clientid ?? "0"); /** Make a ticket **/ ticket = new AuthTicket(); ticket.ticket_id = Guid.NewGuid().ToString().Replace("-", ""); ticket.user_id = user.user_id; ticket.date = Epoch.Now; ticket.ip = ip; db.AuthTickets.Create(ticket); } return(Response.AsText("Valid=TRUE\r\nTicket=" + ticket.ticket_id.ToString() + "\r\n")); }; }
public BirthdayGiftTask(IDAFactory DAFactory, TaskTuning tuning, IGluonHostPool hostPool) { this.DAFactory = DAFactory; this.Tuning = tuning; this.HostPool = hostPool; }
public PruneDatabaseTask(IDAFactory DAFactory) { this.DAFactory = DAFactory; }
public ServerTop100Domain(IDAFactory DAFactory, CityServerContext context, MemoryCache cache) { Cache = cache; this.DAFactory = DAFactory; this.Context = context; }
public RegistrationController(IDAFactory daFactory, JWTFactory jwt, ApiServerConfiguration config) : base("/userapi/registration") { JWTTokenAuthentication.Enable(this, jwt); DAFactory = daFactory; After.AddItemToEndOfPipeline(x => { x.Response.WithHeader("Access-Control-Allow-Origin", "*"); }); //Create a new user Post["/"] = x => { var user = this.Bind <RegistrationModel>(); var tryIP = Request.Headers["X-Forwarded-For"].FirstOrDefault(); if (tryIP != null) { tryIP = tryIP.Substring(tryIP.LastIndexOf(',') + 1).Trim(); } var ip = tryIP ?? Request.UserHostAddress; user.username = user.username ?? ""; user.username = user.username.ToLowerInvariant(); user.email = user.email ?? ""; user.key = user.key ?? ""; string failReason = null; if (user.username.Length < 3) { failReason = "user_short"; } else if (user.username.Length > 24) { failReason = "user_long"; } else if (!USERNAME_VALIDATION.IsMatch(user.username ?? "")) { failReason = "user_invalid"; } else if ((user.password?.Length ?? 0) == 0) { failReason = "pass_required"; } if (failReason != null) { return(Response.AsJson(new RegistrationError() { error = "bad_request", error_description = failReason })); } bool isAdmin = false; if (config.Regkey != null && config.Regkey != user.key) { return(Response.AsJson(new RegistrationError() { error = "key_wrong", error_description = failReason })); } var passhash = PasswordHasher.Hash(user.password); using (var da = daFactory.Get) { //has this ip been banned? var ban = da.Bans.GetByIP(ip); if (ban != null) { return(Response.AsJson(new RegistrationError() { error = "registration_failed", error_description = "ip_banned" })); } //has this user registered a new account too soon after their last? var now = Epoch.Now; var prev = da.Users.GetByRegisterIP(ip); if (now - (prev.FirstOrDefault()?.register_date ?? 0) < REGISTER_THROTTLE_SECS) { //cannot create a new account this soon. return(Response.AsJson(new RegistrationError() { error = "registration_failed", error_description = "registrations_too_frequent" })); } //TODO: is this ip banned? var userModel = new User { username = user.username, email = user.email, is_admin = isAdmin, is_moderator = isAdmin, user_state = UserState.valid, register_date = now, is_banned = false, register_ip = ip, last_ip = ip }; var authSettings = new UserAuthenticate { scheme_class = passhash.scheme, data = passhash.data }; try { var userId = da.Users.Create(userModel); authSettings.user_id = userId; da.Users.CreateAuth(authSettings); userModel = da.Users.GetById(userId); if (userModel == null) { throw new Exception("Unable to find user"); } return(Response.AsJson(userModel)); } catch (Exception) { return(Response.AsJson(new RegistrationError() { error = "registration_failed", error_description = "user_exists" })); } } }; }
public ServerNeighborhoodProvider([Named("ShardId")] int shardId, IRealestateDomain realestate, IDAFactory daFactory, IServerNFSProvider nfs) { OnMissingLazyLoad = true; OnLazyLoadCacheValue = false; ShardId = shardId; GlobalRealestate = realestate; Realestate = realestate.GetByShard(shardId); DAFactory = daFactory; NFS = nfs; }
public BonusTask(IDAFactory DAFactory, TaskTuning tuning) { this.DAFactory = DAFactory; this.Tuning = tuning; }
public ServerMayorRatingProvider([Named("ShardId")] int shardId, IDAFactory factory) { this.ShardId = shardId; this.DAFactory = factory; }
public LotAllocation(IDAFactory da, CityServerContext context) { Context = context; DAFactory = da; }
public ToolInitDatabase(DatabaseInitOptions options, IDAFactory factory) { this.DAFactory = factory; }
public VoltronConnectionLifecycleHandler(ISessions sessions, IDataService dataService, IDAFactory da, CityServerContext context, LotServerPicker lotServers, CityLivenessEngine engine, EventSystem events) { VoltronSessions = sessions.GetOrCreateGroup(Groups.VOLTRON); Sessions = sessions; DataService = dataService; DAFactory = da; Context = context; LotServers = lotServers; Liveness = engine; Events = events; }
public MailHandler(ISessions sessions, IDataService dataService, IDAFactory da) { this.Sessions = sessions; this.DataService = dataService; this.DA = da; }
public VoltronConnectionLifecycleHandler(ISessions sessions, IDataService dataService, IDAFactory da, CityServerContext context, LotServerPicker lotServers) { this.VoltronSessions = sessions.GetOrCreateGroup(Groups.VOLTRON); this.DataService = dataService; this.DAFactory = da; this.Context = context; this.LotServers = lotServers; }
public LotServerClosedownHandler(LotAllocations lots, IDAFactory daFactory) { this.Lots = lots; this.DAFactory = daFactory; }