public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication) { SpecialModData modData = UploadedModsManager.Instance.GetSpecialModInfoFromId(arguments["modId"]); if (modData == null) { return(new VerifyModResponse() { Error = "Could not find mod" }); } if (modData.Verified) { return(new VerifyModResponse() { Error = "Mod aready verified." }); } modData.Verified = true; modData.Save(); return(new VerifyModResponse() { Message = "Verified mod." }); }
public override void OnOperation(HttpListenerContext context, Authentication authentication) { string id = context.Request.QueryString["id"]; if (!UploadedModsManager.Instance.HasModWithIdBeenUploaded(id)) { Utils.SendErrorPage(context.Response, "No mod with the id \"" + id + "\" has been uploaded", true, HttpStatusCode.NotFound); return; } string path = UploadedModsManager.Instance.GetZippedFileForMod(id); byte[] data = File.ReadAllBytes(path); string displayName = UploadedModsManager.Instance.GetModInfoFromId(id).DisplayName + ".zip"; displayName = displayName.Replace(' ', '_'); foreach (char c in Path.GetInvalidFileNameChars()) { displayName = displayName.Replace(c, '_'); } SpecialModData specialModData = UploadedModsManager.Instance.GetSpecialModInfoFromId(id); specialModData.Downloads++; specialModData.Save(); HttpStream httpStream = new HttpStream(context.Response); httpStream.SendFile(data, displayName); httpStream.Close(); }
public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication) { string targetModId = arguments["targetModId"]; string commentBody = arguments["commentBody"]; if (targetModId == null || commentBody == null) { return(new PostCommentResponse() { Error = "All fields were not filled out" }); } if (!authentication.IsSignedIn) { return(new PostCommentResponse() { Error = "You are not signed in." }); } if (!UploadedModsManager.Instance.HasModWithIdBeenUploaded(targetModId)) { return(new PostCommentResponse() { Error = "That mod does not exist" }); } SpecialModData specialModData = UploadedModsManager.Instance.GetSpecialModInfoFromId(targetModId); string userId = authentication.UserID; string sanitized = commentBody.Replace("<", "<").Replace(">", ">"); sanitized = sanitized.Replace("\n", "<br>"); Comment comment = Comment.CreateNewComment(userId, sanitized); specialModData.Comments.Add(comment); specialModData.Save(); return(new PostCommentResponse() { message = "Comment posted." }); }
public override string OnOperation(Arguments arguments, Authentication authentication) { ContentType = "application/json"; string modId = arguments["modId"]; string commentId = arguments["commentId"]; if (modId == null || commentId == null) { return("false"); } if (!authentication.IsSignedIn) { return("false"); } if (!UploadedModsManager.Instance.HasModWithIdBeenUploaded(modId)) { return("false"); } SpecialModData specialModData = UploadedModsManager.Instance.GetSpecialModInfoFromId(modId); Comment comment = specialModData.GetCommentWithCommentID(commentId); if (comment == null) { return("false"); } string userId = authentication.UserID; bool hasLiked = comment.UsersWhoLikedThis.Contains(userId); return(hasLiked ? "true" : "false"); }
public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication) { KeyValuePair <SpecialModData, ModInfo>[] mods = UploadedModsManager.Instance.GetAllUploadedMods(); List <string> selectedModIds = new List <string>(); for (int i = 0; i < mods.Length; i++) { bool include = Search(mods[i], arguments); if (include) { selectedModIds.Add(mods[i].Value.UniqueID); } } if (arguments["sortOrder"] == "liked") { selectedModIds.Sort(delegate(string a, string b) { SpecialModData specialAData = UploadedModsManager.Instance.GetSpecialModInfoFromId(a); SpecialModData specialBData = UploadedModsManager.Instance.GetSpecialModInfoFromId(b); return(specialBData.Likes - specialAData.Likes); }); } else if (arguments["sortOrder"] == "downloads") { selectedModIds.Sort(delegate(string a, string b) { SpecialModData specialAData = UploadedModsManager.Instance.GetSpecialModInfoFromId(a); SpecialModData specialBData = UploadedModsManager.Instance.GetSpecialModInfoFromId(b); return(specialBData.Downloads - specialAData.Downloads); }); } else if (arguments["sortOrder"] == "postedDate") { selectedModIds.Sort(delegate(string a, string b) { SpecialModData specialAData = UploadedModsManager.Instance.GetSpecialModInfoFromId(a); SpecialModData specialBData = UploadedModsManager.Instance.GetSpecialModInfoFromId(b); return((int)(specialBData.PostedDate - specialAData.PostedDate)); }); } else if (arguments["sortOrder"] == "editedDate") { selectedModIds.Sort(delegate(string a, string b) { SpecialModData specialAData = UploadedModsManager.Instance.GetSpecialModInfoFromId(a); SpecialModData specialBData = UploadedModsManager.Instance.GetSpecialModInfoFromId(b); return((int)(specialBData.UpdatedDate - specialAData.UpdatedDate)); }); } return(new SearchOperationResponse() { ModIds = selectedModIds }); }
public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication) { string modId = arguments["modId"]; string commentId = arguments["commentId"]; bool likeState = arguments["likeState"]; if (modId == null || commentId == null) { return(new LikeCommentRequestResponse() { Error = "All fields were not filled out" }); } if (!authentication.IsSignedIn) { return(new LikeCommentRequestResponse() { Error = "You are not signed in." }); } if (!UploadedModsManager.Instance.HasModWithIdBeenUploaded(modId)) { return(new LikeCommentRequestResponse() { Error = "No mod with that id exists" }); } string userId = authentication.UserID; User user = UserManager.Instance.GetUserFromId(userId); SpecialModData modData = UploadedModsManager.Instance.GetSpecialModInfoFromId(modId); Comment comment = modData.GetCommentWithCommentID(commentId); if (likeState) { if (!comment.UsersWhoLikedThis.Contains(userId)) { comment.UsersWhoLikedThis.Add(userId); modData.Save(); } else { return(new LikeCommentRequestResponse() { Error = "You have already liked that comment!" }); } } else { if (comment.UsersWhoLikedThis.Contains(userId)) { comment.UsersWhoLikedThis.Remove(userId); modData.Save(); } else { return(new LikeCommentRequestResponse() { Error = "You havent liked that comment." }); } } return(new LikeCommentRequestResponse() { message = "Your liked status has been updated!" }); }
public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication) { DeleteCommentRequest request = new DeleteCommentRequest() { targetCommentId = arguments["targetCommentId"], targetModId = arguments["targetModId"] }; if (!request.IsValidRequest()) { return(new DeleteCommentResponse() { Error = "All fields were not filled out" }); } if (!authentication.HasAtLeastAuthenticationLevel(AuthenticationLevel.BasicUser)) { return(new DeleteCommentResponse() { Error = "You are not signed in" }); } if (!UploadedModsManager.Instance.HasModWithIdBeenUploaded(request.targetModId)) { return(new DeleteCommentResponse() { Error = "That mod does not exist" }); } SpecialModData specialModData = UploadedModsManager.Instance.GetSpecialModInfoFromId(request.targetModId); string userId = authentication.UserID; Comment comment = specialModData.GetCommentWithCommentID(request.targetCommentId); if (comment == null) { return(new DeleteCommentResponse() { Error = "There is no comment with that id on that mod" }); } if (userId != comment.PosterUserId && !authentication.HasAtLeastAuthenticationLevel(AuthenticationLevel.Admin)) { return(new DeleteCommentResponse() { Error = "You do not have premission to delete this comment" }); } specialModData.DeleteCommentWithId(request.targetCommentId); specialModData.Save(); return(new DeleteCommentResponse() { message = "Comment deleted." }); }
public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication) { LikeRequestData request = new LikeRequestData() { likedModId = arguments["likedModId"], likeState = arguments["likeState"] }; if (!request.IsValidRequest()) { return(new LikeRequestResponse() { Error = "All fields were not filled out" }); } if (!authentication.IsSignedIn) { return(new LikeRequestResponse() { Error = "You are not signed in." }); } if (!UploadedModsManager.Instance.HasModWithIdBeenUploaded(request.likedModId)) { return(new LikeRequestResponse() { Error = "No mod with that id exists" }); } string userId = authentication.UserID; User user = UserManager.Instance.GetUserFromId(userId); SpecialModData modData = UploadedModsManager.Instance.GetSpecialModInfoFromId(request.likedModId); if (request.likeState) { if (!user.LikedMods.Contains(request.likedModId)) { user.LikedMods.Add(request.likedModId); user.Save(); modData.Likes++; modData.Save(); } else { return(new LikeRequestResponse() { Error = "You have already liked that mod!" }); } } else { if (user.LikedMods.Contains(request.likedModId)) { user.LikedMods.Remove(request.likedModId); user.Save(); modData.Likes--; modData.Save(); } else { return(new LikeRequestResponse() { Error = "You havent liked that mod!" }); } } return(new LikeRequestResponse() { message = "Your liked status has been updated!" }); }