Tabs and spaces.
This commit is contained in:
parent
5e107cccb9
commit
17f5f43772
33 changed files with 306 additions and 306 deletions
|
|
@ -20,18 +20,18 @@ public class ClientConfigurationHandler implements HttpHandler {
|
|||
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
||||
if (cachedConfiguration == null) {
|
||||
String s = Json.stringifyJson(configuration);
|
||||
|
||||
|
||||
cachedConfiguration = s.getBytes();
|
||||
}
|
||||
String dateStr = new Date().toString();
|
||||
|
||||
|
||||
response.fields.put("Date", dateStr);
|
||||
response.fields.put("Content-Type", "text/plain");
|
||||
response.fields.put("Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
|
||||
response.fields.put("Last-modified", dateStr);
|
||||
response.fields.put("Content-Length", Integer.toString(cachedConfiguration.length));
|
||||
response.status = HttpStatus.OK;
|
||||
|
||||
|
||||
BufferedOutputStream out = null;
|
||||
out = new BufferedOutputStream(response.getBody());
|
||||
out.write(cachedConfiguration);
|
||||
|
|
|
|||
|
|
@ -31,26 +31,26 @@ public class ClientUpdateHandler implements HttpHandler {
|
|||
}
|
||||
|
||||
Pattern updatePathPattern = Pattern.compile("world/([^/]+)/([0-9]*)");
|
||||
private static final HttpStatus WorldNotFound = new HttpStatus(HttpStatus.NotFound.getCode(), "World Not Found");
|
||||
private static final HttpStatus WorldNotFound = new HttpStatus(HttpStatus.NotFound.getCode(), "World Not Found");
|
||||
@Override
|
||||
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
||||
|
||||
|
||||
Matcher match = updatePathPattern.matcher(path);
|
||||
|
||||
|
||||
if (!match.matches()) {
|
||||
response.status = HttpStatus.Forbidden;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String worldName = match.group(1);
|
||||
String timeKey = match.group(2);
|
||||
|
||||
|
||||
World world = server.getWorld(worldName);
|
||||
if (world == null) {
|
||||
response.status = WorldNotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
long current = System.currentTimeMillis();
|
||||
long since = 0;
|
||||
|
||||
|
|
@ -60,14 +60,14 @@ public class ClientUpdateHandler implements HttpHandler {
|
|||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Client.Update update = new Client.Update();
|
||||
update.timestamp = current;
|
||||
update.servertime = world.getTime() % 24000;
|
||||
update.hasStorm = world.hasStorm();
|
||||
update.isThundering = world.isThundering();
|
||||
|
||||
|
||||
|
||||
|
||||
Player[] players = playerList.getVisiblePlayers();
|
||||
update.players = new Client.Player[players.length];
|
||||
for(int i=0;i<players.length;i++) {
|
||||
|
|
@ -75,10 +75,10 @@ public class ClientUpdateHandler implements HttpHandler {
|
|||
Location pl = p.getLocation();
|
||||
update.players[i] = new Client.Player(p.getDisplayName(), pl.getWorld().getName(), pl.getX(), pl.getY(), pl.getZ());
|
||||
}
|
||||
|
||||
|
||||
update.updates = mapManager.getWorldUpdates(worldName, since);
|
||||
|
||||
|
||||
|
||||
|
||||
byte[] bytes = Json.stringifyJson(update).getBytes();
|
||||
|
||||
String dateStr = new Date().toString();
|
||||
|
|
@ -88,10 +88,10 @@ public class ClientUpdateHandler implements HttpHandler {
|
|||
response.fields.put(HttpField.LastModified, dateStr);
|
||||
response.fields.put(HttpField.ContentLength, Integer.toString(bytes.length));
|
||||
response.status = HttpStatus.OK;
|
||||
|
||||
|
||||
BufferedOutputStream out = null;
|
||||
out = new BufferedOutputStream(response.getBody());
|
||||
out.write(bytes);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@ public abstract class FileHandler implements HttpHandler {
|
|||
return m;
|
||||
return "application/octet-steam";
|
||||
}
|
||||
|
||||
|
||||
protected abstract InputStream getFileInput(String path, HttpRequest request, HttpResponse response);
|
||||
|
||||
|
||||
protected String getExtension(String path) {
|
||||
int dotindex = path.lastIndexOf('.');
|
||||
if (dotindex > 0)
|
||||
return path.substring(dotindex);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected final String formatPath(String path) {
|
||||
int qmark = path.indexOf('?');
|
||||
if (qmark >= 0)
|
||||
|
|
@ -54,11 +54,11 @@ public abstract class FileHandler implements HttpHandler {
|
|||
path = getDefaultFilename(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
protected String getDefaultFilename(String path) {
|
||||
return path + "index.html";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
||||
InputStream fileInput = null;
|
||||
|
|
@ -69,10 +69,10 @@ public abstract class FileHandler implements HttpHandler {
|
|||
response.status = HttpStatus.NotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String extension = getExtension(path);
|
||||
String mimeType = getMimeTypeFromExtension(extension);
|
||||
|
||||
|
||||
response.fields.put(HttpField.ContentType, mimeType);
|
||||
response.status = HttpStatus.OK;
|
||||
OutputStream out = response.getBody();
|
||||
|
|
|
|||
|
|
@ -32,4 +32,4 @@ public class FilesystemHandler extends FileHandler {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,4 @@ public class JarFileHandler extends FileHandler {
|
|||
protected InputStream getFileInput(String path, HttpRequest request, HttpResponse response) {
|
||||
return this.getClass().getResourceAsStream(root + "/" + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,16 +17,16 @@ import org.json.simple.parser.JSONParser;
|
|||
|
||||
public class SendMessageHandler implements HttpHandler {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
|
||||
|
||||
private static final JSONParser parser = new JSONParser();
|
||||
public Event<Message> onMessageReceived = new Event<SendMessageHandler.Message>();
|
||||
|
||||
|
||||
public int maximumMessageInterval = 1000;
|
||||
public String spamMessage = "\"You may only chat once every %interval% seconds.\"";
|
||||
private HashMap<String, WebUser> disallowedUsers = new HashMap<String, WebUser>();
|
||||
private LinkedList<WebUser> disallowedUserQueue = new LinkedList<WebUser>();
|
||||
private Object disallowedUsersLock = new Object();
|
||||
|
||||
|
||||
@Override
|
||||
public void handle(String path, HttpRequest request, HttpResponse response) throws Exception {
|
||||
if (!request.method.equals(HttpMethod.Post)) {
|
||||
|
|
@ -36,14 +36,14 @@ public class SendMessageHandler implements HttpHandler {
|
|||
}
|
||||
|
||||
InputStreamReader reader = new InputStreamReader(request.body);
|
||||
|
||||
|
||||
JSONObject o = (JSONObject)parser.parse(reader);
|
||||
final Message message = new Message();
|
||||
message.name = String.valueOf(o.get("name"));
|
||||
message.message = String.valueOf(o.get("message"));
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
|
||||
|
||||
synchronized(disallowedUsersLock) {
|
||||
// Allow users that user that are now allowed to send messages.
|
||||
while (!disallowedUserQueue.isEmpty()) {
|
||||
|
|
@ -55,7 +55,7 @@ public class SendMessageHandler implements HttpHandler {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WebUser user = disallowedUsers.get(message.name);
|
||||
if (user == null) {
|
||||
user = new WebUser() {{
|
||||
|
|
@ -71,14 +71,14 @@ public class SendMessageHandler implements HttpHandler {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
onMessageReceived.trigger(message);
|
||||
|
||||
|
||||
response.fields.put(HttpField.ContentLength, "0");
|
||||
response.status = HttpStatus.OK;
|
||||
response.getBody();
|
||||
}
|
||||
|
||||
|
||||
public static class Message {
|
||||
public String name;
|
||||
public String message;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue