mirror of
				https://github.com/simon987/Much-Assembly-Required.git
				synced 2025-11-04 10:06:54 +00:00 
			
		
		
		
	Editor upload & reload buttons are now working. Floppy upload & download working.
This commit is contained in:
		
							parent
							
								
									315e33055e
								
							
						
					
					
						commit
						2c856aae80
					
				@ -154,7 +154,6 @@ public class GameServer implements Runnable {
 | 
				
			|||||||
        GameEvent event = new TickEvent(gameUniverse.getTime());
 | 
					        GameEvent event = new TickEvent(gameUniverse.getTime());
 | 
				
			||||||
        eventDispatcher.dispatch(event); //Ignore cancellation
 | 
					        eventDispatcher.dispatch(event); //Ignore cancellation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //Process user code
 | 
					        //Process user code
 | 
				
			||||||
        for (User user : gameUniverse.getUsers()) {
 | 
					        for (User user : gameUniverse.getUsers()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -189,7 +188,7 @@ public class GameServer implements Runnable {
 | 
				
			|||||||
            save();
 | 
					            save();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//        socketServer.tick();
 | 
					        socketServer.tick();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//        LogManager.LOGGER.info("Processed " + gameUniverse.getWorldCount() + " worlds (" + updatedWorlds +
 | 
					//        LogManager.LOGGER.info("Processed " + gameUniverse.getWorldCount() + " worlds (" + updatedWorlds +
 | 
				
			||||||
//                " updated)");
 | 
					//                " updated)");
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ package net.simon987.server;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import net.simon987.server.logging.LogManager;
 | 
					import net.simon987.server.logging.LogManager;
 | 
				
			||||||
import net.simon987.server.web.WebServer;
 | 
					import net.simon987.server.web.WebServer;
 | 
				
			||||||
 | 
					import spark.Spark;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Main {
 | 
					public class Main {
 | 
				
			||||||
@ -10,12 +11,15 @@ public class Main {
 | 
				
			|||||||
        ServerConfiguration config = new ServerConfiguration("config.properties");
 | 
					        ServerConfiguration config = new ServerConfiguration("config.properties");
 | 
				
			||||||
        LogManager.initialize(config);
 | 
					        LogManager.initialize(config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Load
 | 
					 | 
				
			||||||
        GameServer.INSTANCE.load();
 | 
					        GameServer.INSTANCE.load();
 | 
				
			||||||
        (new Thread(GameServer.INSTANCE)).start();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Web server
 | 
					        //Web server
 | 
				
			||||||
        new WebServer(GameServer.INSTANCE.getConfig());
 | 
					        WebServer webServer = new WebServer(GameServer.INSTANCE.getConfig());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Spark.awaitInitialization();
 | 
				
			||||||
 | 
					        GameServer.INSTANCE.setSocketServer(webServer.getSocketServer());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        (new Thread(GameServer.INSTANCE)).start();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					package net.simon987.server.web;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import net.simon987.server.GameServer;
 | 
				
			||||||
 | 
					import net.simon987.server.logging.LogManager;
 | 
				
			||||||
 | 
					import spark.Request;
 | 
				
			||||||
 | 
					import spark.Response;
 | 
				
			||||||
 | 
					import spark.Route;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class FloppyDownloadRoute implements Route {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Object handle(Request request, Response response) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String username = request.session().attribute("username");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (username != null) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            response.header("Content-Type", "application/octet-stream");
 | 
				
			||||||
 | 
					            response.header("Content-Disposition", "filename=\"floppy.bin\"");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                return GameServer.INSTANCE.getGameUniverse().getUser(username).getControlledUnit().getFloppyData().getBytes();
 | 
				
			||||||
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                String message = "Encountered exception while reading floppy data: " + e.getMessage();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                LogManager.LOGGER.severe(message);
 | 
				
			||||||
 | 
					                return message;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            response.status(403);
 | 
				
			||||||
 | 
					            return "Not logged in";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,67 @@
 | 
				
			|||||||
 | 
					package net.simon987.server.web;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import net.simon987.server.GameServer;
 | 
				
			||||||
 | 
					import net.simon987.server.logging.LogManager;
 | 
				
			||||||
 | 
					import spark.Request;
 | 
				
			||||||
 | 
					import spark.Response;
 | 
				
			||||||
 | 
					import spark.Route;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.servlet.MultipartConfigElement;
 | 
				
			||||||
 | 
					import javax.servlet.ServletException;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					import java.io.InputStream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class FloppyUploadRoute implements Route {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Object handle(Request request, Response response) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        String username = request.session().attribute("username");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (username != null) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                request.attribute("org.eclipse.jetty.multipartConfig",
 | 
				
			||||||
 | 
					                        new MultipartConfigElement("/tmp_floppy", 1474560L, -1L, 0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                try (InputStream is = request.raw().getPart("floppyData").getInputStream()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (is.available() == 1474560) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        byte[] bytes = new byte[1474560];
 | 
				
			||||||
 | 
					                        int bytesRead = is.read(bytes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        if (bytesRead == 1474560) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            try {
 | 
				
			||||||
 | 
					                                GameServer.INSTANCE.getGameUniverse().getUser(username).getControlledUnit().getFloppyData().setBytes(bytes);
 | 
				
			||||||
 | 
					                                return "ok";
 | 
				
			||||||
 | 
					                            } catch (Exception e) {
 | 
				
			||||||
 | 
					                                String message = "Encountered exception while writing floppy data: " + e.getMessage();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                LogManager.LOGGER.severe(message);
 | 
				
			||||||
 | 
					                                return message;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            return "Couldn't read floppy file";
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        return "File size must be 1474560 bytes";
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                } catch (IOException | ServletException e) {
 | 
				
			||||||
 | 
					                    e.printStackTrace();
 | 
				
			||||||
 | 
					                    return "Error reading floppy file: " + e.getMessage();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            } catch (IllegalStateException e) {
 | 
				
			||||||
 | 
					                return "File exceeds maximum size";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            response.status(403);
 | 
				
			||||||
 | 
					            return "Not logged in";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -2,7 +2,6 @@ package net.simon987.server.web;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import net.simon987.server.ServerConfiguration;
 | 
					import net.simon987.server.ServerConfiguration;
 | 
				
			||||||
import net.simon987.server.logging.LogManager;
 | 
					import net.simon987.server.logging.LogManager;
 | 
				
			||||||
import net.simon987.server.websocket.FloppyUploadRoute;
 | 
					 | 
				
			||||||
import net.simon987.server.websocket.SocketServer;
 | 
					import net.simon987.server.websocket.SocketServer;
 | 
				
			||||||
import org.apache.velocity.app.VelocityEngine;
 | 
					import org.apache.velocity.app.VelocityEngine;
 | 
				
			||||||
import spark.Spark;
 | 
					import spark.Spark;
 | 
				
			||||||
@ -12,6 +11,8 @@ import java.util.Properties;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class WebServer {
 | 
					public class WebServer {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private SocketServer socketServer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public WebServer(ServerConfiguration config) {
 | 
					    public WebServer(ServerConfiguration config) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Velocity config
 | 
					        //Velocity config
 | 
				
			||||||
@ -36,7 +37,8 @@ public class WebServer {
 | 
				
			|||||||
            LogManager.LOGGER.info("(Web) Enabled ssl");
 | 
					            LogManager.LOGGER.info("(Web) Enabled ssl");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Spark.webSocket("/socket", SocketServer.class);
 | 
					        socketServer = new SocketServer();
 | 
				
			||||||
 | 
					        Spark.webSocket("/socket", socketServer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Spark.get("/", new HomePage(), templateEngine);
 | 
					        Spark.get("/", new HomePage(), templateEngine);
 | 
				
			||||||
        Spark.get("/leaderboard", new LeaderBoardPage(), templateEngine);
 | 
					        Spark.get("/leaderboard", new LeaderBoardPage(), templateEngine);
 | 
				
			||||||
@ -49,8 +51,12 @@ public class WebServer {
 | 
				
			|||||||
        Spark.post("/change_password", new ChangePasswordRoute());
 | 
					        Spark.post("/change_password", new ChangePasswordRoute());
 | 
				
			||||||
        Spark.get("/server_info", new ServerInfoRoute());
 | 
					        Spark.get("/server_info", new ServerInfoRoute());
 | 
				
			||||||
        Spark.post("/floppy_upload", new FloppyUploadRoute());
 | 
					        Spark.post("/floppy_upload", new FloppyUploadRoute());
 | 
				
			||||||
 | 
					        Spark.get("/floppy_download", new FloppyDownloadRoute());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Spark.after((request, response) -> response.header("Content-Encoding", "gzip"));
 | 
					        Spark.after((request, response) -> response.header("Content-Encoding", "gzip"));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SocketServer getSocketServer() {
 | 
				
			||||||
 | 
					        return socketServer;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,40 +0,0 @@
 | 
				
			|||||||
package net.simon987.server.websocket;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import net.simon987.server.GameServer;
 | 
					 | 
				
			||||||
import net.simon987.server.logging.LogManager;
 | 
					 | 
				
			||||||
import org.json.simple.JSONObject;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class FloppyHandler implements MessageHandler {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    SocketServerDatabase db = new SocketServerDatabase(GameServer.INSTANCE.getConfig());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void handle(OnlineUser user, JSONObject json) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (json.get("t").equals("floppyDown")) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            LogManager.LOGGER.fine("(WS) Floppy download request from " + user.getUser().getUsername());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (user.getUser().isGuest()) {
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (user.getUser().getControlledUnit().getFloppyData() != null) {
 | 
					 | 
				
			||||||
                byte[] bytes = user.getUser().getControlledUnit().getFloppyData().getBytes();
 | 
					 | 
				
			||||||
                LogManager.LOGGER.severe("TODO FloppyHandler.handle()");
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        } else if (json.get("t").equals("floppyUp")) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            LogManager.LOGGER.fine("(WS) Floppy upload request from " + user.getUser().getUsername());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            //Check newly uploaded file on the database
 | 
					 | 
				
			||||||
            byte[] bytes = db.getFloppy(user.getUser().getUsername());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (bytes != null) {
 | 
					 | 
				
			||||||
                user.getUser().getControlledUnit().getFloppyData().setBytes(bytes);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -1,37 +0,0 @@
 | 
				
			|||||||
package net.simon987.server.websocket;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import spark.Request;
 | 
					 | 
				
			||||||
import spark.Response;
 | 
					 | 
				
			||||||
import spark.Route;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.servlet.MultipartConfigElement;
 | 
					 | 
				
			||||||
import javax.servlet.ServletException;
 | 
					 | 
				
			||||||
import java.io.IOException;
 | 
					 | 
				
			||||||
import java.io.InputStream;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class FloppyUploadRoute implements Route {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Object handle(Request request, Response response) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            request.attribute("org.eclipse.jetty.multipartConfig",
 | 
					 | 
				
			||||||
                    new MultipartConfigElement("/tmp_floppy", 1474560L, -1L, 0));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            try (InputStream is = request.raw().getPart("floppyData").getInputStream()) {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                System.out.println(is.available());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // Use the input stream to create a file
 | 
					 | 
				
			||||||
            } catch (IOException | ServletException e) {
 | 
					 | 
				
			||||||
                e.printStackTrace();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        } catch (IllegalStateException e) {
 | 
					 | 
				
			||||||
            System.out.println(e.getMessage());
 | 
					 | 
				
			||||||
            return "File exceeds maximum size";
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return "mh";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@ -30,7 +30,6 @@ public class SocketServer {
 | 
				
			|||||||
        messageDispatcher.addHandler(new CodeUploadHandler());
 | 
					        messageDispatcher.addHandler(new CodeUploadHandler());
 | 
				
			||||||
        messageDispatcher.addHandler(new CodeRequestHandler());
 | 
					        messageDispatcher.addHandler(new CodeRequestHandler());
 | 
				
			||||||
        messageDispatcher.addHandler(new KeypressHandler());
 | 
					        messageDispatcher.addHandler(new KeypressHandler());
 | 
				
			||||||
        messageDispatcher.addHandler(new FloppyHandler());
 | 
					 | 
				
			||||||
        messageDispatcher.addHandler(new DebugCommandHandler());
 | 
					        messageDispatcher.addHandler(new DebugCommandHandler());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -272,4 +272,44 @@
 | 
				
			|||||||
    -ms-flex: 0 0 25%;
 | 
					    -ms-flex: 0 0 25%;
 | 
				
			||||||
    flex: 0 0 25%;
 | 
					    flex: 0 0 25%;
 | 
				
			||||||
    max-width: 25%;
 | 
					    max-width: 25%;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** https://stackoverflow.com/questions/6410730/ */
 | 
				
			||||||
 | 
					@-webkit-keyframes rotating /* Safari and Chrome */
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    from {
 | 
				
			||||||
 | 
					        -webkit-transform: rotate(0deg);
 | 
				
			||||||
 | 
					        -o-transform: rotate(0deg);
 | 
				
			||||||
 | 
					        transform: rotate(0deg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    to {
 | 
				
			||||||
 | 
					        -webkit-transform: rotate(360deg);
 | 
				
			||||||
 | 
					        -o-transform: rotate(360deg);
 | 
				
			||||||
 | 
					        transform: rotate(360deg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@keyframes rotating {
 | 
				
			||||||
 | 
					    from {
 | 
				
			||||||
 | 
					        -ms-transform: rotate(0deg);
 | 
				
			||||||
 | 
					        -moz-transform: rotate(0deg);
 | 
				
			||||||
 | 
					        -webkit-transform: rotate(0deg);
 | 
				
			||||||
 | 
					        -o-transform: rotate(0deg);
 | 
				
			||||||
 | 
					        transform: rotate(0deg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    to {
 | 
				
			||||||
 | 
					        -ms-transform: rotate(360deg);
 | 
				
			||||||
 | 
					        -moz-transform: rotate(360deg);
 | 
				
			||||||
 | 
					        -webkit-transform: rotate(360deg);
 | 
				
			||||||
 | 
					        -o-transform: rotate(360deg);
 | 
				
			||||||
 | 
					        transform: rotate(360deg);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.rotating {
 | 
				
			||||||
 | 
					    -webkit-animation: rotating 2s linear infinite;
 | 
				
			||||||
 | 
					    -moz-animation: rotating 2s linear infinite;
 | 
				
			||||||
 | 
					    -ms-animation: rotating 2s linear infinite;
 | 
				
			||||||
 | 
					    -o-animation: rotating 2s linear infinite;
 | 
				
			||||||
 | 
					    animation: rotating 2s linear infinite;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.1 KiB  | 
@ -505,7 +505,8 @@ editorOnThemeChange();
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
document.getElementById("floppyIn").onchange = function () {
 | 
					document.getElementById("floppyIn").onchange = function () {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //document.getElementById("floppyUp").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\" aria-hidden=\"true\"></i>";
 | 
					    document.getElementById("floppyUp").innerHTML = '<i class="mi rotating">cached</i> Floppy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var formData = new FormData(document.getElementById("floppyForm"));
 | 
					    var formData = new FormData(document.getElementById("floppyForm"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -517,8 +518,6 @@ document.getElementById("floppyIn").onchange = function () {
 | 
				
			|||||||
        if (xhr.status === 200) {
 | 
					        if (xhr.status === 200) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (xhr.responseText === "ok") {
 | 
					            if (xhr.responseText === "ok") {
 | 
				
			||||||
                //Upload ok, notify the game server
 | 
					 | 
				
			||||||
                mar.client.notifyFloppyUp();
 | 
					 | 
				
			||||||
                alert("Uploaded floppy disk to the drive!")
 | 
					                alert("Uploaded floppy disk to the drive!")
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                alert(xhr.responseText)
 | 
					                alert(xhr.responseText)
 | 
				
			||||||
@ -528,7 +527,8 @@ document.getElementById("floppyIn").onchange = function () {
 | 
				
			|||||||
            alert("Couldn't upload floppy code (" + xhr.status + ")");
 | 
					            alert("Couldn't upload floppy code (" + xhr.status + ")");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        document.getElementById("floppyUp").innerHTML = "<i class=\"fa fa-long-arrow-up\" aria-hidden=\"true\"></i> <i class=\"fa fa-floppy-o\" aria-hidden=\"true\"></i>";
 | 
					        document.getElementById("floppyUp").innerHTML = '<i class="mi">file_upload</i> Floppy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    xhr.onerror = function (ev) {
 | 
					    xhr.onerror = function (ev) {
 | 
				
			||||||
        ev.preventDefault();
 | 
					        ev.preventDefault();
 | 
				
			||||||
 | 
				
			|||||||
@ -667,19 +667,6 @@ var GameClient = (function () {
 | 
				
			|||||||
            this.socket.send(JSON.stringify({ t: "k", k: key }));
 | 
					            this.socket.send(JSON.stringify({ t: "k", k: key }));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    GameClient.prototype.requestFloppy = function () {
 | 
					 | 
				
			||||||
        document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\"></i>";
 | 
					 | 
				
			||||||
        if (DEBUG) {
 | 
					 | 
				
			||||||
            console.log("[MAR] Requesting floppy");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        this.socket.send(JSON.stringify({ t: "floppyDown" }));
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    GameClient.prototype.notifyFloppyUp = function () {
 | 
					 | 
				
			||||||
        if (DEBUG) {
 | 
					 | 
				
			||||||
            console.log("[MAR] Notifying the game server of floppy upload");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        this.socket.send(JSON.stringify({ t: "floppyUp" }));
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
    GameClient.prototype.requestObjects = function () {
 | 
					    GameClient.prototype.requestObjects = function () {
 | 
				
			||||||
        if (DEBUG) {
 | 
					        if (DEBUG) {
 | 
				
			||||||
            console.log("[MAR] Requesting game objects");
 | 
					            console.log("[MAR] Requesting game objects");
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
<nav class="navbar navbar-expand-lg bg-primary navbar-light">
 | 
					<nav class="navbar navbar-expand-lg bg-primary navbar-light">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <a class="navbar-brand text-mono hvr-grow" href="/" title="Home"><img src="/images/tmp.png"></img></a>
 | 
					    <a class="navbar-brand text-mono hvr-grow" href="/" title="Home"><img src="/images/icon.png"></img></a>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse"
 | 
					    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse"
 | 
				
			||||||
            data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
 | 
					            data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,6 @@
 | 
				
			|||||||
                    <td>Test1</td>
 | 
					                    <td>Test1</td>
 | 
				
			||||||
                    <td>Test2</td>
 | 
					                    <td>Test2</td>
 | 
				
			||||||
                </tr>
 | 
					                </tr>
 | 
				
			||||||
                Account - M.A.R
 | 
					 | 
				
			||||||
                <tr>
 | 
					                <tr>
 | 
				
			||||||
                    <td>Test1</td>
 | 
					                    <td>Test1</td>
 | 
				
			||||||
                    <td>Test2</td>
 | 
					                    <td>Test2</td>
 | 
				
			||||||
 | 
				
			|||||||
@ -49,51 +49,63 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        ## EDITOR
 | 
					        ## EDITOR
 | 
				
			||||||
            <div id="editor-tab" style="display: none">
 | 
					            <div id="editor-tab" style="display: none">
 | 
				
			||||||
 | 
					                #if($session.attribute("username"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <div class="row">
 | 
					                    <div class="row">
 | 
				
			||||||
                    <div class="col-sm-4">
 | 
					                        <div class="col-sm-4">
 | 
				
			||||||
                        <select title="Select Theme" class="form-control" id="editorTheme"></select>
 | 
					                            <select title="Select Theme" class="form-control" id="editorTheme"></select>
 | 
				
			||||||
                    </div>
 | 
					                        </div>
 | 
				
			||||||
                    <div class="col-sm-2">
 | 
					
 | 
				
			||||||
                        <button class="btn btn-shadow btn-success text-mono regular-screen" href="#"><i class="mi">file_upload</i>
 | 
					                        <div class="col-sm-2">
 | 
				
			||||||
                            Upload
 | 
					                            <button onclick="mar.client.uploadCode(ace.edit('editor').getValue())"
 | 
				
			||||||
                        </button>
 | 
					                                    class="btn btn-shadow btn-success text-mono regular-screen" href="#"><i class="mi">file_upload</i>
 | 
				
			||||||
                        <button class="btn btn-shadow btn-success text-mono small-screen" href="#"><i class="mi">file_upload</i>
 | 
					                                Upload
 | 
				
			||||||
                        </button>
 | 
					                            </button>
 | 
				
			||||||
                    </div>
 | 
					                            <button class="btn btn-shadow btn-success text-mono small-screen" href="#"><i class="mi">file_upload</i>
 | 
				
			||||||
                    <div class="col-sm-2">
 | 
					                            </button>
 | 
				
			||||||
                        <button class="btn btn-shadow btn-danger text-mono regular-screen" href="#"><i
 | 
					                        </div>
 | 
				
			||||||
                                class="mi">replay</i> Reload
 | 
					                        <div class="col-sm-2">
 | 
				
			||||||
                        </button>
 | 
					                            <button class="btn btn-shadow btn-danger text-mono regular-screen"
 | 
				
			||||||
                        <button class="btn btn-shadow btn-danger text-mono small-screen" href="#"><i
 | 
					                                    onclick="mar.client.reloadCode()" href="#"><i
 | 
				
			||||||
                                class="mi">replay</i></button>
 | 
					                                    class="mi">replay</i> Reload
 | 
				
			||||||
                    </div>
 | 
					                            </button>
 | 
				
			||||||
                    <div class="col-sm-2">
 | 
					                            <button class="btn btn-shadow btn-danger text-mono small-screen"
 | 
				
			||||||
                        <button id="floppyUp" onclick="document.getElementById('floppyIn').click();"
 | 
					                                    onclick="mar.client.reloadCode()" href="#"><i
 | 
				
			||||||
                                class="btn btn-shadow btn-info text-mono regular-screen" href="#"><i class="mi">file_upload</i>
 | 
					                                    class="mi">replay</i></button>
 | 
				
			||||||
                            Floppy
 | 
					                        </div>
 | 
				
			||||||
                        </button>
 | 
					                        <div class="col-sm-2">
 | 
				
			||||||
                        <button class="btn btn-shadow btn-info text-mono small-screen" href="#"><i class="mi">file_upload</i>
 | 
					                            <button id="floppyUp" onclick="document.getElementById('floppyIn').click();"
 | 
				
			||||||
                        </button>
 | 
					                                    class="btn btn-shadow btn-info text-mono regular-screen" href="#"><i class="mi">file_upload</i>
 | 
				
			||||||
 | 
					                                Floppy
 | 
				
			||||||
 | 
					                            </button>
 | 
				
			||||||
 | 
					                            <button onclick="document.getElementById('floppyIn').click();"
 | 
				
			||||||
 | 
					                                    class="btn btn-shadow btn-info text-mono small-screen" href="#"><i class="mi">file_upload</i>
 | 
				
			||||||
 | 
					                            </button>
 | 
				
			||||||
 | 
					                        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        <div class="col-sm-2">
 | 
				
			||||||
 | 
					                            <button class="btn btn-shadow btn-info text-mono regular-screen"
 | 
				
			||||||
 | 
					                                    onclick="window.location.assign('floppy_download')"><i class="mi">file_download</i>
 | 
				
			||||||
 | 
					                                Floppy
 | 
				
			||||||
 | 
					                            </button>
 | 
				
			||||||
 | 
					                            <button class="btn btn-shadow btn-info text-mono small-screen"
 | 
				
			||||||
 | 
					                                    onclick="window.location.assign('floppy_download')"><i class="mi">file_download</i>
 | 
				
			||||||
 | 
					                            </button>
 | 
				
			||||||
 | 
					                        </div>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    <div class="col-sm-2">
 | 
					                    <form id="floppyForm" style="display: none;" enctype='multipart/form-data'>
 | 
				
			||||||
                        <button class="btn btn-shadow btn-info text-mono regular-screen" href="#"><i class="mi">file_download</i>
 | 
					                        <input id="floppyIn" type="file" name="floppyIn"/>
 | 
				
			||||||
                            Floppy
 | 
					                    </form>
 | 
				
			||||||
                        </button>
 | 
					 | 
				
			||||||
                        <button class="btn btn-shadow btn-info text-mono small-screen" href="#"><i class="mi">file_download</i>
 | 
					 | 
				
			||||||
                        </button>
 | 
					 | 
				
			||||||
                    </div>
 | 
					 | 
				
			||||||
                </div>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <form id="floppyForm" style="display: none;" enctype='multipart/form-data'>
 | 
					                    <div id="editor"></div>
 | 
				
			||||||
                    <input id="floppyIn" type="file" name="floppyIn"/>
 | 
					 | 
				
			||||||
                </form>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <div id="editor"></div>
 | 
					                    <script src="js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
 | 
				
			||||||
 | 
					                #else
 | 
				
			||||||
                <script src="js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
 | 
					                    <p style="text-align: left"><a href="/account">Login</a> to use the editor</p>
 | 
				
			||||||
 | 
					                #end
 | 
				
			||||||
                <script src="js/editor.js"></script>
 | 
					                <script src="js/editor.js"></script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
@ -142,7 +154,7 @@
 | 
				
			|||||||
            </p>
 | 
					            </p>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="noisy">
 | 
					        <div class="noisy">
 | 
				
			||||||
            <div id="consoleText" class="piece output noclick ctr-selection ctr-text">Hello World</div>
 | 
					            <div id="consoleText" class="piece output noclick ctr-selection ctr-text"></div>
 | 
				
			||||||
            <div class="piece scanlines noclick"></div>
 | 
					            <div class="piece scanlines noclick"></div>
 | 
				
			||||||
            <div class="piece glow noclick"></div>
 | 
					            <div class="piece glow noclick"></div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
				
			|||||||
@ -329,26 +329,7 @@ class GameClient {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public requestFloppy(): void {
 | 
					    à
 | 
				
			||||||
        //Start loading animation
 | 
					 | 
				
			||||||
        document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-cog fa-spin fa-fw\"></i>";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (DEBUG) {
 | 
					 | 
				
			||||||
            console.log("[MAR] Requesting floppy");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.socket.send(JSON.stringify({t: "floppyDown"}));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public notifyFloppyUp(): void {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (DEBUG) {
 | 
					 | 
				
			||||||
            console.log("[MAR] Notifying the game server of floppy upload");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        this.socket.send(JSON.stringify({t: "floppyUp"}));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public requestObjects(): void {
 | 
					    public requestObjects(): void {
 | 
				
			||||||
        if (DEBUG) {
 | 
					        if (DEBUG) {
 | 
				
			||||||
            console.log("[MAR] Requesting game objects");
 | 
					            console.log("[MAR] Requesting game objects");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user