Skip to content

Commit

Permalink
Added config
Browse files Browse the repository at this point in the history
  • Loading branch information
narrowtux committed Oct 11, 2012
1 parent 17473c5 commit b97beff
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ nb-configuration.xml
.idea
*.iml
*.ipr
*.iws
*.iws
/config.yml
16 changes: 16 additions & 0 deletions src/main/java/org/spout/flo/Flo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import java.util.LinkedList;
import java.util.List;

import org.spout.api.exception.ConfigurationException;
import org.spout.flo.server.Server;
import org.spout.flo.web.FloWebServer;

public class Flo {
private static Flo instance = null;
private FloConfiguration configuration;

public static Flo instance() {
return instance;
Expand All @@ -18,6 +20,12 @@ public static Flo instance() {

Flo () {
instance = this;
configuration = new FloConfiguration();
try {
configuration.load();
} catch (ConfigurationException e) {
e.printStackTrace();
}
webServer = new FloWebServer();

Runtime.getRuntime().addShutdownHook(new Thread() {
Expand All @@ -35,4 +43,12 @@ public void stop() {
public List<Server> getServers() {
return servers;
}

public FloWebServer getWebServer() {
return webServer;
}

public FloConfiguration getConfiguration() {
return configuration;
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/spout/flo/FloConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.spout.flo;

import java.io.File;

import org.spout.api.exception.ConfigurationException;
import org.spout.api.util.config.ConfigurationHolder;
import org.spout.api.util.config.ConfigurationHolderConfiguration;
import org.spout.api.util.config.yaml.YamlConfiguration;

public class FloConfiguration extends ConfigurationHolderConfiguration {

public static ConfigurationHolder BIND_ADDRESS = new ConfigurationHolder((Object) null, "bind.address");
public static ConfigurationHolder BIND_PORT = new ConfigurationHolder(80, "bind.port");
public static ConfigurationHolder BASE_SERVER_FOLDER = new ConfigurationHolder("servers/", "servers.basefolder");

public FloConfiguration() {
super(new YamlConfiguration(new File("config.yml")));
}

@Override
public void load() throws ConfigurationException {
super.load();
super.save();
}
}
20 changes: 18 additions & 2 deletions src/main/java/org/spout/flo/web/FloWebServer.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
package org.spout.flo.web;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.spout.flo.FloConfiguration;

import com.narrowtux.blueberry.Address;
import com.narrowtux.blueberry.BlueberryWebServer;

public class FloWebServer {
BlueberryWebServer server;
FloWebSocketHandler webSocketHandler;

public FloWebServer() {
server = new BlueberryWebServer();
server.bind(new Address(null, 5000)); //TODO configure
try {
server.bind(new Address(InetAddress.getByName(FloConfiguration.BIND_ADDRESS.getString(null)), FloConfiguration.BIND_PORT.getInt(5000)));
} catch (UnknownHostException e) {
e.printStackTrace();
return;
}
server.setApplicationName("Flo");
server.getHandlers().add(new ResourceFileHandler());
server.getHandlers().add(new FloWebSocketHandler());
webSocketHandler = new FloWebSocketHandler();
server.getHandlers().add(webSocketHandler);
server.start();
}

public FloWebSocketHandler getWebSocketHandler() {
return webSocketHandler;
}

public void stop() {
server.stop();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/css/flo.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#server-list {
margin-top: 5px;
width: 50%;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/js/servers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$("#btn-add-server").click(function() {
$("#modal-add-server").modal();
});
14 changes: 14 additions & 0 deletions src/main/resources/sites/servers.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

<h2>Servers</h2>
<div class="btn btn-success" id="btn-add-server">Add Server</div>

<table id="server-list" class="table-striped table-bordered table-hover">

<thead>
<tr>
<th>Server</th><th>Status</th><th>Actions</th>
Expand All @@ -26,5 +28,17 @@ <h2>Servers</h2>
</tr>
</tbody>
</table>

<div class="modal hide fade" id="modal-add-server">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Add Server</h3>
</div>
<div class="modal-body">
<form>
<input type="text" name="name" placeholder="Name of the server"/>
</form>
</div>
</div>

<script src="js/servers.js"></script>

0 comments on commit b97beff

Please sign in to comment.