Update
This commit is contained in:
parent
6258438d44
commit
1424e84840
4 changed files with 54 additions and 18 deletions
1
Unity Server Project/bin/.gitignore
vendored
Normal file
1
Unity Server Project/bin/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/fr/
|
|
@ -0,0 +1,2 @@
|
|||
# Le port d'ecoute du serveur
|
||||
server.port=9999
|
|
@ -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")));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String,SettingsFile> settings = new HashMap<String,SettingsFile>();
|
||||
|
||||
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<String,String> data = new HashMap<String,String>();
|
||||
|
||||
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<String,String> data = new HashMap<String,String>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue