diff --git a/Unity Server Project/bin/.gitignore b/Unity Server Project/bin/.gitignore new file mode 100644 index 0000000..44fde90 --- /dev/null +++ b/Unity Server Project/bin/.gitignore @@ -0,0 +1 @@ +/fr/ diff --git a/Unity Server Project/settings/network.conf b/Unity Server Project/settings/network.conf index e69de29..bcbb698 100644 --- a/Unity Server Project/settings/network.conf +++ b/Unity Server Project/settings/network.conf @@ -0,0 +1,2 @@ +# Le port d'ecoute du serveur +server.port=9999 \ No newline at end of file diff --git a/Unity Server Project/src/fr/technicalgames/MainServer.java b/Unity Server Project/src/fr/technicalgames/MainServer.java index ea058ad..ba34277 100644 --- a/Unity Server Project/src/fr/technicalgames/MainServer.java +++ b/Unity Server Project/src/fr/technicalgames/MainServer.java @@ -14,9 +14,9 @@ public class MainServer{ public static Server server; public static void main(String[] args) throws JAXBException { - Settings.loadSettings(); + Settings.loadSettings("settings/"); World.loadWorlds(); - server = new Server(9999); + server = new Server(Integer.parseInt(Settings.getValue("network.conf", "server.port"))); } } diff --git a/Unity Server Project/src/fr/technicalgames/settings/Settings.java b/Unity Server Project/src/fr/technicalgames/settings/Settings.java index ac94bf7..1366957 100644 --- a/Unity Server Project/src/fr/technicalgames/settings/Settings.java +++ b/Unity Server Project/src/fr/technicalgames/settings/Settings.java @@ -1,30 +1,63 @@ package fr.technicalgames.settings; +import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.HashMap; import fr.technicalgames.io.Log; public class Settings { - public static void loadSettings(){ - File t = new File("settings/"); + private static HashMap settings = new HashMap(); + + public static void loadSettings(String path){ + Log.println(Log.INFO, "Load configuration files..."); + File t = new File(path); for(File f : t.listFiles()){ - Log.println(Log.INFO, f.getName()); + settings.put(f.getName(), new SettingsFile(f.getName(), path)); } - } - - class SettingsFile{ - - private String filename; - private HashMap data = new HashMap(); - - public SettingsFile(String filename,String path){ - File f = new File(path + filename); - - } - - + Log.println(Log.INFO, "Configuration files loaded"); } + public static String getValue(String filename,String dataname){ + return settings.get(filename).getValue(dataname); + } + +} + +class SettingsFile{ + + private String filename; + private HashMap data = new HashMap(); + + public SettingsFile(String filename,String path){ + try { + File f = new File(path + filename); + FileInputStream fis = new FileInputStream(f); + + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + + String line = null; + while ((line = br.readLine()) != null) { + if(line.toCharArray()[0] != '#'){ + String[] line_set = line.split("="); + data.put(line_set[0], line_set[1]); + } + } + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + + public String getValue(String dataname){ + return data.get(dataname); + } + + }