Warn when the user doesn't provide a valid uri to /imgprint and /newlvl heightmap theme

This commit is contained in:
UnknownShadow200 2017-01-16 20:45:24 +11:00
parent 083201baa7
commit 2f2e5c3278
8 changed files with 52 additions and 13 deletions

View File

@ -41,8 +41,8 @@ namespace MCGalaxy
BlockBehaviour.SetupCoreHandlers();
// Custom permissions set by the user.
if (File.Exists("properties/block.properties")) {
string[] lines = File.ReadAllLines("properties/block.properties");
if (File.Exists(Paths.BlockPermsFile)) {
string[] lines = File.ReadAllLines(Paths.BlockPermsFile);
if (lines.Length > 0 && lines[0] == "#Version 2") {
LoadVersion2(lines);
} else {
@ -148,7 +148,7 @@ namespace MCGalaxy
}
static void SaveBlocksCore(IEnumerable<Blocks> givenList) {
using (StreamWriter w = new StreamWriter("properties/block.properties")) {
using (StreamWriter w = new StreamWriter(Paths.BlockPermsFile)) {
w.WriteLine("#Version 2");
w.WriteLine("# This file dictates which ranks may use what blocks");
w.WriteLine("# If someone has royally screwed up the ranks, just delete this file and let the server restart");

View File

@ -242,7 +242,7 @@ namespace MCGalaxy {
}
internal static void SaveExtColors() {
using (StreamWriter w = new StreamWriter("text/customcolors.txt")) {
using (StreamWriter w = new StreamWriter(Paths.CustomColorsFile)) {
foreach (CustomColor col in ExtColors) {
if (col.Undefined) continue;
w.WriteLine(col.Code + " " + col.Fallback + " " + col.Name + " " +
@ -252,8 +252,8 @@ namespace MCGalaxy {
}
internal static void LoadExtColors() {
if (!File.Exists("text/customcolors.txt")) return;
string[] lines = File.ReadAllLines("text/customcolors.txt");
if (!File.Exists(Paths.CustomColorsFile)) return;
string[] lines = File.ReadAllLines(Paths.CustomColorsFile);
CustomColor col = default(CustomColor);
for (int i = 0; i < lines.Length; i++) {

View File

@ -96,7 +96,7 @@ namespace MCGalaxy.Commands.Moderation {
StringBuilder all = new StringBuilder();
Player who = PlayerInfo.Find(name);
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
foreach (string line in File.ReadAllLines(Paths.TempRanksFile)) {
if (!line.CaselessStarts(name)) { all.AppendLine(line); continue; }
string[] parts = line.Split(' ');
@ -115,7 +115,7 @@ namespace MCGalaxy.Commands.Moderation {
}
static void Info(Player p, string name) {
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
foreach (string line in File.ReadAllLines(Paths.TempRanksFile)) {
if (!line.CaselessStarts(name)) continue;
PrintTempRankInfo(p, line); return;
}
@ -124,7 +124,7 @@ namespace MCGalaxy.Commands.Moderation {
static void List(Player p) {
int count = 0;
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
foreach (string line in File.ReadAllLines(Paths.TempRanksFile)) {
if (count == 0)
Player.Message(p, "&ePlayers with a temporary rank assigned:");
PrintTempRankInfo(p, line);

View File

@ -26,13 +26,18 @@ namespace MCGalaxy.Generator {
public static bool DownloadImage(string url, string dir, Player p) {
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
if (!url.StartsWith("http://") && !url.StartsWith("https://"))
if (!url.CaselessStarts("http://") && !url.CaselessStarts("https://"))
url = "http://" + url;
Uri uri;
if (!Uri.TryCreate(url, UriKind.Absolute, out uri)) {
Player.Message(p, "{0} is not a valid URL.", url); return false;
}
try {
using (WebClient client = new WebClient()) {
Player.Message(p, "Downloading file from: &f" + url);
client.DownloadFile(url, dir + "tempImage_" + p.name + ".bmp");
client.DownloadFile(uri, dir + "tempImage_" + p.name + ".bmp");
}
Player.Message(p, "Finished downloading image.");
return true;

View File

@ -621,6 +621,7 @@
<Compile Include="util\Formatter.cs" />
<Compile Include="util\IO\CP437Reader.cs" />
<Compile Include="util\IO\CP437Writer.cs" />
<Compile Include="util\IO\Paths.cs" />
<Compile Include="util\Math\DirUtils.cs" />
<Compile Include="util\Math\Vectors.cs" />
<Compile Include="util\MultiPageOutput.cs" />

View File

@ -221,7 +221,7 @@ namespace MCGalaxy {
[ConfigInt("ip-spam-count", "Spam control", null, 25, 0, 1000)]
public static int IPSpamCount = 10;
[ConfigInt("ip-spam-block-time", "Spam control", null, 30, 0, 1000)]
public static int IPSpamBlockTime = 300;
public static int IPSpamBlockTime = 180;
[ConfigInt("ip-spam-interval", "Spam control", null, 1, 0, 1000)]
public static int IPSpamInterval = 60;

View File

@ -126,7 +126,7 @@ namespace MCGalaxy.Tasks {
internal static void TemprankExpiry(SchedulerTask task) {
Player[] players = PlayerInfo.Online.Items;
foreach (string line in File.ReadAllLines("text/tempranks.txt"))
foreach (string line in File.ReadAllLines(Paths.TempRanksFile))
foreach (Player p in players)
{
if (!line.CaselessStarts(p.name)) continue;

33
MCGalaxy/util/IO/Paths.cs Normal file
View File

@ -0,0 +1,33 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace MCGalaxy {
public static class Paths {
public const string CustomColorsFile = "text/customcolors.txt";
public const string BlockPermsFile = "properties/block.properties";
public const string TempRanksFile = "text/tempranks.txt";
}
}