public override bool ReadParams(CommandReader cmd) { // get image URL string urlstr = cmd.Next(); if (!WorldCommands.parseUrl(ref urlstr, Player)) { return(false); } // validate the image URL Uri url; if (!Uri.TryCreate(urlstr, UriKind.Absolute, out url)) { Player.Message("DrawImage: Invalid URL given."); return(false); } else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps)) { Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed."); return(false); } ImageUrl = url; // Check if player gave optional second argument (palette name) string paletteName = cmd.Next(); if (paletteName != null) { Palette = BlockPalette.FindPalette(paletteName); if (Palette == null) { Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"", paletteName, BlockPalette.Palettes.JoinToString(pal => pal.Name)); return(false); } } else { // default to "Light" (lit single-layer) palette Palette = BlockPalette.FindPalette("Light"); } // All set return(true); }
public override bool ReadParams(CommandReader cmd) { // get image URL string str = cmd.Next(); if (str.NullOrWhiteSpace()) { return(false); } // if string starts with "++", load image from imgur if (str.StartsWith("++")) { str = "http://i.imgur.com/" + str.Substring(2) + ".png"; } // prepend the protocol, if needed (assume http) if (!str.CaselessStarts("http://") && !str.CaselessStarts("https://")) { str = "http://" + str; } // Convert imgur web page url to direct image url if (str.StartsWith("http://imgur.com/")) { str = "http://i.imgur.com/" + str.Substring("http://imgur.com/".Length) + ".png"; } if (str.StartsWith("https://imgur.com/")) { str = "https://i.imgur.com/" + str.Substring("https://imgur.com/".Length) + ".png"; } if (!str.CaselessEnds(".png") && !str.CaselessEnds(".jpg") && !str.CaselessEnds(".gif")) { Player.Message("URL must be a link to an image"); return(false); } // validate the image URL Uri url; if (!Uri.TryCreate(str, UriKind.Absolute, out url)) { Player.Message("DrawImage: Invalid URL given."); return(false); } else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps)) { Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed."); return(false); } else if (!url.Host.CaselessEquals("i.imgur.com")) { Player.Message("For safety reasons we only accept images uploaded to &9http://imgur.com/ &SSorry for this inconvenience."); return(false); } ImageUrl = url; // Check if player gave optional second argument (palette name) string paletteName = cmd.Next(); if (paletteName != null) { Palette = BlockPalette.FindPalette(paletteName); if (Palette == null) { Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"", paletteName, BlockPalette.Palettes.JoinToString(pal => pal.Name)); return(false); } } else { // default to "Light" (lit single-layer) palette Palette = BlockPalette.FindPalette("Light"); } // All set return(true); }