public async Task MakeUsersMe(DbUser u) { //Set basic values screen_name = u.screen_name; profile_image_url = u.profile_image_url; id = u.id; steam_id = u.steam_id; user_settings = u.user_settings; //Convert servers servers = new List <UsersMeReply_Server>(); List <string> clusterIds = new List <string>(); var found_servers = await u.GetGameServersAsync(Program.connection); foreach (var id in found_servers) { //Get server by ID var converted = MakeServer(id.Item1, id.Item2, u); servers.Add(converted); if (converted.cluster_id != null && !clusterIds.Contains(converted.cluster_id)) { clusterIds.Add(converted.cluster_id); } } //Convert clusters clusters = new List <UsersMeReply_Cluster>(); foreach (var c in clusterIds) { clusters.Add(new UsersMeReply_Cluster(await DbCluster.GetClusterById(Program.connection, MongoDB.Bson.ObjectId.Parse(c)))); } }
public static async Task OnPOSTRequest(Microsoft.AspNetCore.Http.HttpContext e, DbServer s, DbUser u) { //Decode settings var settings = Program.DecodePostBody <ManagementDataRequest>(e); //Set name if (settings.name != null) { s.display_name = settings.name; } //Set icon if (settings.icon_token == "%CLEAR_ICON") { s.image_url = DbServer.StaticGetPlaceholderIcon(Program.connection, s.display_name); s.has_custom_image = false; } else if (settings.icon_token != null) { var d = await Program.connection.GetUserContentByToken(settings.icon_token); if (d == null) { throw new StandardError("Couldn't get content token!", StandardErrorCode.InvalidInput); } if (d.application_id != ICON_APPLICATION_ID) { throw new StandardError("Content application ID did not match.", StandardErrorCode.InvalidInput); } if (d.uploader != u._id) { throw new StandardError("Content uploader ID did not match.", StandardErrorCode.InvalidInput); } s.image_url = d.url; s.has_custom_image = true; } //Set user lock s.SetLockFlag(1, settings.is_user_locked); //Set permissions s.SetPermissionFlags(settings.permissions); //Set cluster ID, if it is set if (settings.cluster_id != null && await DbCluster.GetClusterById(Program.connection, MongoDB.Bson.ObjectId.Parse(settings.cluster_id)) != null) { s.cluster_id = settings.cluster_id; } //Save await s.UpdateAsync(Program.connection); //Write response await OnGETRequest(e, s, u); }
public static async Task OnHttpRequest(Microsoft.AspNetCore.Http.HttpContext e, DbUser u) { //Set up our basic values UsersMeResponse response = new UsersMeResponse { screen_name = u.screen_name, profile_image_url = u.profile_image_url, id = u.id, steam_id = u.steam_id, user_settings = u.user_settings, servers = new List <UsersMeReply_Server>(), clusters = new List <UsersMeReply_Cluster>() }; //Fetch and convert our servers var servers = await u.GetGameServersAsync(Program.connection); List <string> clusterIds = new List <string>(); List <ObjectId> serverIds = new List <ObjectId>(); foreach (var s in servers) { //Add server serverIds.Add(s.Item1._id); //Get tribe info var tribe = await Program.connection.GetTribeByTribeIdAsync(s.Item1.id, s.Item2.tribe_id); //Get map info string mapName = null; var mapData = await s.Item1.GetMapEntryAsync(Program.connection); if (mapData != null) { mapName = mapData.displayName; } //Get closed reason, if any int close = -1; for (int i = 31; i >= 0; i--) { if (s.Item1.CheckLockFlag(i)) { close = i; } } //Check pseudo flags if (mapData == null) { close = 32; //MAP_NOT_SUPPORTED } //Create response UsersMeReply_Server sResponse = new UsersMeReply_Server { display_name = s.Item1.display_name, image_url = s.Item1.image_url, owner_uid = s.Item1.owner_uid, cluster_id = s.Item1.cluster_id, id = s.Item1.id, tribe_id = s.Item2.tribe_id, tribe_name = tribe.tribe_name, map_id = s.Item1.latest_server_map, map_name = mapName, permissions = s.Item1.GetPermissionFlagList(), closed_reason = close, user_prefs = await s.Item1.GetUserPrefs(Program.connection, u.id), endpoint_createsession = Program.config.endpoint_echo + $"/{s.Item1.id}/" + "create_session" }; //Add cluster if not added if (s.Item1.cluster_id != null && !clusterIds.Contains(s.Item1.cluster_id)) { clusterIds.Add(s.Item1.cluster_id); } //Add server response.servers.Add(sResponse); } //Add clusters foreach (var c in clusterIds) { //Get cluster data var cluster = await DbCluster.GetClusterById(Program.connection, MongoDB.Bson.ObjectId.Parse(c)); //Add cluster data response.clusters.Add(new UsersMeReply_Cluster { id = cluster.id, name = cluster.name }); } //Get messages response.alerts = await(await u.GetAlertBanners(Program.connection, serverIds)).ToListAsync(); //Write response await Program.QuickWriteJsonToDoc(e, response); }
public static async Task OnGETRequest(Microsoft.AspNetCore.Http.HttpContext e, DbServer s, DbUser u) { //Get cluster, if any DbCluster cluster = null; if (s.cluster_id != null) { cluster = await DbCluster.GetClusterById(Program.connection, MongoDB.Bson.ObjectId.Parse(s.cluster_id)); } //Get map entry string mapName = null; var mapEntry = await Program.connection.GetARKMapByInternalName(s.latest_server_map); if (mapEntry != null) { mapName = mapEntry.displayName; } //Get server status string status = "ONLINE"; string message = "Online"; if (s.CheckLockFlag(1)) { status = "ALERT"; message = "Locked"; } if (s.CheckLockFlag(0)) { status = "ALERT"; message = "Still Initializing..."; } if (s.CheckLockFlag(2)) { status = "OFFLINE"; message = "Locked by Admin"; } if (mapEntry == null) { status = "OFFLINE"; message = "Incompatible Map"; } //Check last connect time DateTime lastConnectTime = new DateTime(s.last_client_connect_time); if ((DateTime.UtcNow - lastConnectTime).TotalMinutes > 2.5f) { status = "OFFLINE"; message = $"Offline Since {lastConnectTime.ToShortDateString()}"; } //Look up all mods used and convert Dictionary <string, DbSteamModCache> mods = await s.GetAllServerMods(Program.connection, true); List <WebArkMod> modList = new List <WebArkMod>(); foreach (var mod in mods.Values) { if (mod == null) { modList.Add(null); } else { modList.Add(mod.GetWebVersion()); } } //Look up all admins List <ManagementData_User> admins = new List <ManagementData_User>(); admins.Add(await ManagementData_User.GetUser(u)); foreach (var id in s.admins) { admins.Add(await ManagementData_User.GetUser(await DbUser.GetUserByID(Program.connection, id))); } ManagementDataResponse m = new ManagementDataResponse { name = s.display_name, icon = s.image_url, is_user_locked = s.CheckLockFlag(1), permissions = s.GetPermissionFlagList(), settings = s.game_settings, cluster_id = s.cluster_id, cluster = cluster, status = status, alert = message, mods = modList, admins = admins, map_id = s.latest_server_map, map_name = mapName }; await Program.QuickWriteJsonToDoc(e, m); }