13
0
Dieser Commit ist enthalten in:
Chaoscaot 2021-01-17 13:45:00 +01:00
Ursprung befec0fc1b
Commit 335e7584cc
4 geänderte Dateien mit 1 neuen und 175 gelöschten Zeilen

Datei anzeigen

@ -1,141 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem;
import de.steamwar.sql.Schematic;
import de.steamwar.sql.SchematicType;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClients;
import org.bukkit.entity.Player;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ExternalUpDownload {
private ExternalUpDownload(){}
public static void downloadSchemsFromWGW(Player player, String pw) {
BasicCookieStore cookieStore = new BasicCookieStore();
HttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
try {
//Login to WGW
HttpPost loginPost = new HttpPost("https://wargearworld.net/index.php");
MultipartEntity loginEntity = new MultipartEntity();
loginEntity.addPart("login-username", new StringBody(player.getName()));
loginEntity.addPart("login-password", new StringBody(pw));
loginEntity.addPart("send-login", new StringBody("login"));
loginPost.setEntity(loginEntity);
HttpResponse loginResponse = httpclient.execute(loginPost);
if(loginResponse.getStatusLine().getStatusCode() != 302) {
player.sendMessage(SchematicSystem.PREFIX + "§cLogin mit gegebenem Passwort nicht möglich.");
return;
}
//Prepare Schemdownload
HttpPost preparePost = new HttpPost("https://wargearworld.net/index.php");
MultipartEntity prepareEntity = new MultipartEntity();
prepareEntity.addPart("option", new StringBody("com_ajax"));
prepareEntity.addPart("module", new StringBody("account"));
prepareEntity.addPart("content", new StringBody("getDir"));
prepareEntity.addPart("data[dir]", new StringBody("/"));
prepareEntity.addPart("data[event]", new StringBody("download_all"));
prepareEntity.addPart("data[data]", new StringBody(""));
prepareEntity.addPart("format", new StringBody("raw"));
preparePost.setEntity(prepareEntity);
HttpResponse prepareResponse = httpclient.execute(preparePost);
InputStream content = prepareResponse.getEntity().getContent();
StringBuilder builder = new StringBuilder();
byte[] remover = new byte[67];
content.read(remover);
while (content.available() > 0) {
int readed = content.read();
if(readed == 46)
break;
builder.append((char) readed);
}
player.sendMessage(SchematicSystem.PREFIX + "§aWGW-Downloadlink erstellt...");
player.sendMessage("§ahttps://wargearworld.net/images/temp/schematics/" + builder.toString() + ".zip");
//Process Schems
player.sendMessage(SchematicSystem.PREFIX + "§aSchematics werden verarbeitet...");
ZipInputStream zipInputStream = new ZipInputStream(new URL("https://wargearworld.net/images/temp/schematics/" + builder.toString() + ".zip").openStream());
while (true) {
ZipEntry schematic = zipInputStream.getNextEntry();
if(schematic == null)
break;
if(schematic.isDirectory())
continue;
String[] schemName = schematic.getName().split("\\.");
StringBuilder name = new StringBuilder();
for (int i = 0; i < schemName.length - 1; i++) {
if(!name.toString().equals(""))
name.append(".");
name.append(replaceString(schemName[i]));
}
String schematicName = name.substring(0, Math.min(60, name.length()));
Schematic testSchem = Schematic.getSchemFromDB(schematicName, player.getUniqueId());
List<Byte> schemData = new ArrayList<>();
while (zipInputStream.available() == 1) {
schemData.add((byte) zipInputStream.read());
}
byte[] bytes = new byte[schemData.size()];
for (int i = 0; i < schemData.size(); i++) {
bytes[i] = schemData.get(i);
}
if(testSchem != null) {
int i = 1;
while (true) {
if(Schematic.getSchemFromDB(schematicName + "-" + i, player.getUniqueId()) == null) {
schematicName = schematicName + "-" + i;
break;
}
i++;
}
}
Schematic.createSchem(schematicName, player.getUniqueId(), "", SchematicType.Normal);
Schematic schem = Schematic.getSchemFromDB(schematicName, player.getUniqueId());
schem.saveFromBytes(bytes, schemName[schemName.length - 1].equals("schem"));
zipInputStream.closeEntry();
player.sendMessage(SchematicSystem.PREFIX + "§6Die Schematic §e" + schematic.getName() + " §6wurde von WarGearWorld.net als §e" + name.toString() + " §6heruntergeladen!");
}
player.sendMessage(SchematicSystem.PREFIX + "§aAlle deine Schematics wurden von §6W§7ar§6G§7ear§6W§7orld.net §aauf §eSteam§8War §atransferiert!");
zipInputStream.close();
} catch (Exception e) {
player.sendMessage("§cUnerwarteter Fehler beim Schematictransfer. Developer wurden benachrichtigt.");
throw new SecurityException(e);
} finally {
httpclient.getConnectionManager().shutdown();
}
}
private static String replaceString(String str) {
return str.replace("/", "-").replace("\\", "-").replace("<", "~").replace(">", "~").replace("^", "*").replace("°", "*").replace("'", "*").replace("\\", ":");
}
}

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.schematicsystem; package de.steamwar.schematicsystem;
import de.steamwar.core.CommandRemover; import de.steamwar.core.CommandRemover;
import de.steamwar.schematicsystem.commands.SchemTransferCommand;
import de.steamwar.schematicsystem.commands.SchematicCommand; import de.steamwar.schematicsystem.commands.SchematicCommand;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -50,7 +49,6 @@ public class SchematicSystem extends JavaPlugin {
CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem"); CommandRemover.removeAll("/schematic", "/schem", "//schematic", "//schem");
getCommand("schem").setExecutor(new SchematicCommand()); getCommand("schem").setExecutor(new SchematicCommand());
getCommand("schemtransfer").setExecutor(new SchemTransferCommand());
INSTANCE = this; INSTANCE = this;
} }
} }

Datei anzeigen

@ -1,30 +0,0 @@
package de.steamwar.schematicsystem.commands;
import de.steamwar.schematicsystem.ExternalUpDownload;
import de.steamwar.schematicsystem.SchematicSystem;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SchemTransferCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if(commandSender instanceof Player) {
if(args.length < 1) {
Player p = (Player) commandSender;
p.sendMessage("§6W§7ar§6G§7ear§6W§7orld Schematictransfer");
p.sendMessage("§7Mit diesem Command kannst du deine WGW-Schematics auf SteamWar übertragen");
p.sendMessage("§8/§eschemtransfer §8[§eDein WGW-Website Passwort§8]");
p.sendMessage("§cDISCLAIMER§8: §eWir nutzen dieses Passwort ausschließlich zum einmaligen Download der Schematics.");
p.sendMessage("§eWenn du uns das nicht glaubst, kannst du es gerne hier https://steamwar.de/devlabs/SteamWar/SchematicSystem/src/branch/master/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchemTranferCommand.java nachlesen oder die Schematics manuell übertragen.");
} else {
Bukkit.getScheduler().runTaskAsynchronously(SchematicSystem.INSTANCE, () -> ExternalUpDownload.downloadSchemsFromWGW((Player) commandSender, args[0]));
}
}
return true;
}
}

Datei anzeigen

@ -11,5 +11,4 @@ commands:
- schematic - schematic
- /schematic - /schematic
- /schem - /schem
check: check:
schemtransfer: