Skip to content

Commit

Permalink
Merge pull request #31 from rheimus/master
Browse files Browse the repository at this point in the history
Better temp fix for windows issues
  • Loading branch information
superzanti committed Nov 30, 2015
2 parents dd7df53 + 291a8f2 commit 817b696
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 199 deletions.
118 changes: 63 additions & 55 deletions src/main/java/com/superzanti/serversync/ServerSyncRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import java.util.Arrays;
import java.util.List;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

import org.apache.logging.log4j.Logger;

import com.superzanti.lib.RefStrings;

import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import com.superzanti.lib.RefStrings;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

@Mod(modid = RefStrings.MODID, name = RefStrings.NAME, version = RefStrings.VERSION)
public class ServerSyncRegistry {
Expand All @@ -33,71 +33,79 @@ public class ServerSyncRegistry {
protected static List<String> IGNORE_LIST;
protected static int BUTTON_ID;
protected static String LAST_UPDATE;

protected static final String CLIENT_PROXY = "com.superzanti.serversync.ClientProxy";
protected static final String SERVER_PROXY = "com.superzanti.serversync.CommonProxy";
@SidedProxy(modId = RefStrings.MODID, clientSide = CLIENT_PROXY, serverSide = SERVER_PROXY)
protected static CommonProxy proxy;
protected static CommonProxy proxy;

@EventHandler
public static void PreLoad(FMLPreInitializationEvent PreEvent) {

//MinecraftForge.EVENT_BUS.register(new SyncClient());

// MinecraftForge.EVENT_BUS.register(new SyncClient());

// setup the logger for the mod
logger = PreEvent.getModLog();

// Grab the configuration file and load in the values
config = new Configuration(PreEvent.getSuggestedConfigurationFile());

config.load();

SERVER_IP = config.getString("SERVER_IP", "ServerConnection", "127.0.0.1", "The IP address of the server");
SERVER_PORT = config.getInt("SERVER_PORT", "ServerConnection", 38067, 1, 49151, "The port that your server will be serving on");
MINECRAFT_PORT = config.getInt("MINECRAFT_PORT", "ServerConnection", 25565, 1, 49151, "The port in which the minecraft server is running, not the serversync port");

SECURE_CHECK = config.getString("SECURE_CHECK", "ServerEncryption", "0ba4439ee9a46d9d9f14c60f88f45f87", "The check command security key phrase");
SECURE_CHECKMODS = config.getString("SECURE_CHECKMODS", "ServerEncryption", "3dd3152ae3e427aa2817df12570ea708", "The check-mods command security key phrase");
SECURE_RECURSIVE = config.getString("SECURE_RECURSIVE", "ServerEncryption", "f8e45531a3ea3d5c1247b004985175a4", "The recursive command security key phrase");
SECURE_CHECKSUM = config.getString("SECURE_CHECKSUM", "ServerEncryption", "226190d94b21d1b0c7b1a42d855e419d", "The checksum command security key phrase");
SECURE_UPDATE = config.getString("SECURE_UPDATE", "ServerEncryption", "3ac340832f29c11538fbe2d6f75e8bcc", "The update command security key phrase");
SECURE_EXISTS = config.getString("SECURE_EXISTS", "ServerEncryption", "e087923eb5dd1310f5f25ddd5ae5b580", "The exists command security key phrase");
SECURE_EXIT = config.getString("SECURE_EXIT", "ServerEncryption", "f24f62eeb789199b9b2e467df3b1876b", "The exit command security key phrase");

String[] defaultList = {
"./mods/CustomMainMenu-MC1.7.10-1.5.jar",
"./config/CustomMainMenu/mainmenu.json",
"./config/forge.cfg",
"./config/forgeChunkLoading.cfg",
"./config/splash.properties"
};
//String[] ignoreList = config.getStringList("IGNORE_LIST", "IgnoredFiles", defaultList, "These files are ignored by serversync");

Property ignoreList = config.get("IgnoredFiles", "IGNORE_LIST", defaultList, "These files are ignored by serversync. DO NOT IGNORE serversync.cfg");
SERVER_PORT = config.getInt("SERVER_PORT", "ServerConnection", 38067, 1, 49151,
"The port that your server will be serving on");
MINECRAFT_PORT = config.getInt("MINECRAFT_PORT", "ServerConnection", 25565, 1, 49151,
"The port in which the minecraft server is running, not the serversync port");

SECURE_CHECK = config.getString("SECURE_CHECK", "ServerEncryption", "0ba4439ee9a46d9d9f14c60f88f45f87",
"The check command security key phrase");
SECURE_CHECKMODS = config.getString("SECURE_CHECKMODS", "ServerEncryption", "3dd3152ae3e427aa2817df12570ea708",
"The check-mods command security key phrase");
SECURE_RECURSIVE = config.getString("SECURE_RECURSIVE", "ServerEncryption", "f8e45531a3ea3d5c1247b004985175a4",
"The recursive command security key phrase");
SECURE_CHECKSUM = config.getString("SECURE_CHECKSUM", "ServerEncryption", "226190d94b21d1b0c7b1a42d855e419d",
"The checksum command security key phrase");
SECURE_UPDATE = config.getString("SECURE_UPDATE", "ServerEncryption", "3ac340832f29c11538fbe2d6f75e8bcc",
"The update command security key phrase");
SECURE_EXISTS = config.getString("SECURE_EXISTS", "ServerEncryption", "e087923eb5dd1310f5f25ddd5ae5b580",
"The exists command security key phrase");
SECURE_EXIT = config.getString("SECURE_EXIT", "ServerEncryption", "f24f62eeb789199b9b2e467df3b1876b",
"The exit command security key phrase");

String[] defaultList = { "./mods/CustomMainMenu-MC1.7.10-1.5.jar", "./config/CustomMainMenu/mainmenu.json",
"./config/forge.cfg", "./config/forgeChunkLoading.cfg", "./config/splash.properties" };
// String[] ignoreList = config.getStringList("IGNORE_LIST",
// "IgnoredFiles", defaultList, "These files are ignored by
// serversync");

Property ignoreList = config.get("IgnoredFiles", "IGNORE_LIST", defaultList,
"These files are ignored by serversync. DO NOT IGNORE serversync.cfg");
IGNORE_LIST = Arrays.asList(ignoreList.getStringList());

BUTTON_ID = config.getInt("ButtonID", "GUI", 6001, 0, 2147483647, "The ID of the button that connects to the server and updates");

LAST_UPDATE = config.getString("LAST_UPDATE", "StorageVariables", "20150608_000500", "DO NOT EDIT THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING! (If you are a server feel free to change it as much as you want to update your clients)");

BUTTON_ID = config.getInt("ButtonID", "GUI", 6001, 0, 2147483647,
"The ID of the button that connects to the server and updates");

LAST_UPDATE = config.getString("LAST_UPDATE", "StorageVariables", "20150608_000500",
"DO NOT EDIT THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING! (If you are a server feel free to change it as much as you want to update your clients)");

// loading the configuration from its file
config.save();
// Client side
if(proxy.isClient()){
logger.info("I am a client");
ClientProxy.syncclient = new SyncClient();
MinecraftForge.EVENT_BUS.register(ClientProxy.syncclient);
MinecraftForge.EVENT_BUS.register(new GuiScreenHandler());
}
//Server side
if(proxy.isServer()){
logger.info("I am a server");
config.save();

// Client side
if (proxy.isClient()) {
logger.info("I am a client");
ClientProxy.syncclient = new SyncClient();
MinecraftForge.EVENT_BUS.register(ClientProxy.syncclient);
MinecraftForge.EVENT_BUS.register(new GuiScreenHandler());
}

// Server side
if (proxy.isServer()) {
logger.info("I am a server");
SyncServer syncserver = new SyncServer();
Thread syncthread = new Thread(syncserver);
syncthread.start();
}
return;
}
return;
}
}
46 changes: 34 additions & 12 deletions src/main/java/com/superzanti/serversync/SyncClient.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.superzanti.serversync;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

import com.superzanti.lib.RefStrings;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiErrorScreen;
import net.minecraft.client.gui.GuiMainMenu;
Expand All @@ -14,9 +19,6 @@
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.server.FMLServerHandler;

@SideOnly(Side.CLIENT)
public class SyncClient implements GuiYesNoCallback{
Expand All @@ -29,6 +31,8 @@ public class SyncClient implements GuiYesNoCallback{
private static GuiErrorScreen guierrorscreen;
private static GuiScreenWorking guiscreenworking;

public static Path absoluteModsDirectory = null;


protected SyncClient() {
ServerSyncRegistry.logger.info("Client Selected! Read for client routine...");
Expand All @@ -53,12 +57,13 @@ protected static void updateScreenWorking(int newPercent, String statusMessage){
@SubscribeEvent
public void onEachTick(DrawScreenEvent.Pre event){

if(syncclientconnecction.getFinished()){
if(syncclientconnecction.getErrors()){
if(SyncClientConnection.getFinished()){
if(SyncClientConnection.getErrors()){
guierrorscreen = new GuiErrorScreen("There was an error while connecting", "Is your config file is the same as the server's? Is the server on?");
Minecraft.getMinecraft().displayGuiScreen(guierrorscreen);
GuiScreenHandler.doesButtonWork = false;
} else if (syncclientconnecction.getUpdates()){
} else if (SyncClientConnection.getUpdates()){

guiyesno = new GuiYesNo((GuiYesNoCallback) this, "You will need to re-launch minecraft to apply the changes.", "Would you like to do this now?", 0);
Minecraft.getMinecraft().displayGuiScreen(guiyesno);
GuiScreenHandler.doesButtonWork = false;
Expand All @@ -73,10 +78,27 @@ public void onEachTick(DrawScreenEvent.Pre event){

@Override
public void confirmClicked(boolean yesButton, int whatsThisInt) {
if(yesButton)
FMLCommonHandler.instance().exitJava(0, true);
else
if(yesButton) {
final class Shutdown extends Thread {
String modsDir = Paths.get("mods/").toAbsolutePath().toString();

@Override
public void run() {
try {
//new File(modsDir + "/imHere").createNewFile();// Creates in base mods foler
// Not running ? needs more time perhaps
Runtime.getRuntime().exec("java -cp "+RefStrings.MODID+"-"+RefStrings.VERSION+".jar runme.Main", null, new File(modsDir));
} catch (Exception e) {
e.printStackTrace();
}
}

}
Runtime.getRuntime().addShutdownHook(new Shutdown());
FMLCommonHandler.instance().exitJava(0, false);
} else {
Minecraft.getMinecraft().displayGuiScreen(guimainmenu);
}
}

}
Loading

0 comments on commit 817b696

Please sign in to comment.