Added websocket support for no good reason
This commit is contained in:
@@ -38,6 +38,7 @@ public class Mindustry extends ModuleCore {
|
||||
@Override
|
||||
public void dispose() {
|
||||
platforms.onGameExit();
|
||||
Net.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ public class Vars{
|
||||
|
||||
//server port
|
||||
public static final int port = 6567;
|
||||
public static final int webPort = 6568;
|
||||
|
||||
public static Control control;
|
||||
public static Renderer renderer;
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
@@ -370,10 +371,10 @@ public class NetServer extends Module{
|
||||
|
||||
if(Timers.get("serverBlockSync", blockSyncTime)){
|
||||
|
||||
IntArray connections = Net.getConnections();
|
||||
Array<NetConnection> connections = new Array<>();
|
||||
|
||||
for(int i = 0; i < connections.size; i ++){
|
||||
int id = connections.get(i);
|
||||
int id = connections.get(i).id;
|
||||
Player player = this.connections.get(id);
|
||||
if(player == null) continue;
|
||||
int x = Mathf.scl2(player.x, Vars.tilesize);
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
package io.anuke.mindustry.graphics;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.camera;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.game.SpawnPoint;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Layer;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.StaticBlock;
|
||||
import io.anuke.ucore.core.Core;
|
||||
@@ -24,6 +20,11 @@ import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.graphics.CacheBatch;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.ucore.core.Core.camera;
|
||||
|
||||
public class BlockRenderer{
|
||||
private final static int chunksize = 32;
|
||||
private final static int initialRequests = 32*32;
|
||||
@@ -269,6 +270,6 @@ public class BlockRenderer{
|
||||
cache = null;
|
||||
if(cbatch != null)
|
||||
cbatch.dispose();
|
||||
cbatch = new CacheBatch(Vars.world.width() * Vars.world.height() * 3);
|
||||
cbatch = new CacheBatch(Vars.world.width() * Vars.world.height() * 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class DesktopInput extends InputHandler{
|
||||
for(int i = 1; i <= 6 && i <= control.getWeapons().size; i ++){
|
||||
if(Inputs.keyTap("weapon_" + i)){
|
||||
player.weaponLeft = player.weaponRight = control.getWeapons().get(i - 1);
|
||||
Vars.netClient.handleWeaponSwitch();
|
||||
if(Net.active()) Vars.netClient.handleWeaponSwitch();
|
||||
Vars.ui.hudfrag.updateWeapons();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntArray;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.async.AsyncExecutor;
|
||||
@@ -85,7 +84,7 @@ public class Net{
|
||||
}
|
||||
|
||||
/**Returns a list of all connections IDs.*/
|
||||
public static IntArray getConnections(){
|
||||
public static Array<? extends NetConnection> getConnections(){
|
||||
return serverProvider.getConnections();
|
||||
}
|
||||
|
||||
@@ -206,8 +205,8 @@ public class Net{
|
||||
}
|
||||
|
||||
public static void dispose(){
|
||||
clientProvider.dispose();
|
||||
serverProvider.dispose();
|
||||
if(clientProvider != null) clientProvider.dispose();
|
||||
if(serverProvider != null) serverProvider.dispose();
|
||||
executor.dispose();
|
||||
}
|
||||
|
||||
@@ -218,51 +217,51 @@ public class Net{
|
||||
}
|
||||
|
||||
/**Client implementation.*/
|
||||
public static interface ClientProvider {
|
||||
public interface ClientProvider {
|
||||
/**Connect to a server.*/
|
||||
public void connect(String ip, int port) throws IOException;
|
||||
void connect(String ip, int port) throws IOException;
|
||||
/**Send an object to the server.*/
|
||||
public void send(Object object, SendMode mode);
|
||||
void send(Object object, SendMode mode);
|
||||
/**Update the ping. Should be done every second or so.*/
|
||||
public void updatePing();
|
||||
void updatePing();
|
||||
/**Get ping in milliseconds. Will only be valid after a call to updatePing.*/
|
||||
public int getPing();
|
||||
int getPing();
|
||||
/**Disconnect from the server.*/
|
||||
public void disconnect();
|
||||
void disconnect();
|
||||
/**Discover servers. This should block for a certain amount of time, and will most likely be run in a different thread.*/
|
||||
public Array<Host> discover();
|
||||
Array<Host> discover();
|
||||
/**Ping a host. If an error occured, failed() should be called with the exception. */
|
||||
public void pingHost(String address, int port, Consumer<Host> valid, Consumer<IOException> failed);
|
||||
void pingHost(String address, int port, Consumer<Host> valid, Consumer<IOException> failed);
|
||||
/**Register classes to be sent.*/
|
||||
public void register(Class<?>... types);
|
||||
void register(Class<?>... types);
|
||||
/**Close all connections.*/
|
||||
public void dispose();
|
||||
void dispose();
|
||||
}
|
||||
|
||||
/**Server implementation.*/
|
||||
public static interface ServerProvider {
|
||||
public interface ServerProvider {
|
||||
/**Host a server at specified port.*/
|
||||
public void host(int port) throws IOException;
|
||||
void host(int port) throws IOException;
|
||||
/**Sends a large stream of data to a specific client.*/
|
||||
public void sendStream(int id, Streamable stream);
|
||||
void sendStream(int id, Streamable stream);
|
||||
/**Send an object to everyone connected.*/
|
||||
public void send(Object object, SendMode mode);
|
||||
void send(Object object, SendMode mode);
|
||||
/**Send an object to a specific client ID.*/
|
||||
public void sendTo(int id, Object object, SendMode mode);
|
||||
void sendTo(int id, Object object, SendMode mode);
|
||||
/**Send an object to everyone <i>except</i> a client ID.*/
|
||||
public void sendExcept(int id, Object object, SendMode mode);
|
||||
void sendExcept(int id, Object object, SendMode mode);
|
||||
/**Close the server connection.*/
|
||||
public void close();
|
||||
void close();
|
||||
/**Return all connected users.*/
|
||||
public IntArray getConnections();
|
||||
Array<? extends NetConnection> getConnections();
|
||||
/**Kick a certain connection.*/
|
||||
public void kick(int connection);
|
||||
void kick(int connection);
|
||||
/**Returns the ping for a certain connection.*/
|
||||
public int getPingFor(int connection);
|
||||
int getPingFor(NetConnection connection);
|
||||
/**Register classes to be sent.*/
|
||||
public void register(Class<?>... types);
|
||||
void register(Class<?>... types);
|
||||
/**Close all connections.*/
|
||||
public void dispose();
|
||||
void dispose();
|
||||
}
|
||||
|
||||
public enum SendMode{
|
||||
|
||||
16
core/src/io/anuke/mindustry/net/NetConnection.java
Normal file
16
core/src/io/anuke/mindustry/net/NetConnection.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
|
||||
public abstract class NetConnection {
|
||||
public final int id;
|
||||
public final String address;
|
||||
|
||||
public NetConnection(int id, String address){
|
||||
this.id = id;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public abstract void send(Object object, SendMode mode);
|
||||
public abstract void close();
|
||||
}
|
||||
Reference in New Issue
Block a user