Implemented player menu with kick option (untested)
This commit is contained in:
@@ -13,6 +13,8 @@ text.loadgame=Load Game
|
|||||||
text.joingame=Join Game
|
text.joingame=Join Game
|
||||||
text.quit=Quit
|
text.quit=Quit
|
||||||
text.name=Name:
|
text.name=Name:
|
||||||
|
text.players={0} players online
|
||||||
|
text.server.kicked=You have been kicked from the server!
|
||||||
text.server.connected=A player has joined.
|
text.server.connected=A player has joined.
|
||||||
text.server.disconnected={0} has disconnected.
|
text.server.disconnected={0} has disconnected.
|
||||||
text.nohost=Can't host server on a custom map!
|
text.nohost=Can't host server on a custom map!
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import java.util.Arrays;
|
|||||||
public class NetClient extends Module {
|
public class NetClient extends Module {
|
||||||
boolean connecting = false;
|
boolean connecting = false;
|
||||||
boolean gotEntities = false;
|
boolean gotEntities = false;
|
||||||
|
boolean kicked = false;
|
||||||
float playerSyncTime = 2;
|
float playerSyncTime = 2;
|
||||||
float dataTimeout = 60*10;
|
float dataTimeout = 60*10;
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ public class NetClient extends Module {
|
|||||||
Net.handle(Connect.class, packet -> {
|
Net.handle(Connect.class, packet -> {
|
||||||
connecting = true;
|
connecting = true;
|
||||||
gotEntities = false;
|
gotEntities = false;
|
||||||
|
kicked = false;
|
||||||
Gdx.app.postRunnable(() -> {
|
Gdx.app.postRunnable(() -> {
|
||||||
Vars.ui.hideLoading();
|
Vars.ui.hideLoading();
|
||||||
Vars.ui.showLoading("$text.connecting.data");
|
Vars.ui.showLoading("$text.connecting.data");
|
||||||
@@ -65,6 +67,8 @@ public class NetClient extends Module {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Net.handle(Disconnect.class, packet -> {
|
Net.handle(Disconnect.class, packet -> {
|
||||||
|
if(kicked) return;
|
||||||
|
|
||||||
Gdx.app.postRunnable(() -> {
|
Gdx.app.postRunnable(() -> {
|
||||||
Timers.runFor(3f, () -> {
|
Timers.runFor(3f, () -> {
|
||||||
Vars.ui.hideLoading();
|
Vars.ui.hideLoading();
|
||||||
@@ -264,6 +268,12 @@ public class NetClient extends Module {
|
|||||||
Net.handle(ChatPacket.class, packet -> {
|
Net.handle(ChatPacket.class, packet -> {
|
||||||
//TODO
|
//TODO
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Net.handle(KickPacket.class, packet -> {
|
||||||
|
kicked = true;
|
||||||
|
Net.disconnect();
|
||||||
|
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.kicked"));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class Player extends DestructibleEntity implements Syncable{
|
|||||||
private static final float speed = 1.1f;
|
private static final float speed = 1.1f;
|
||||||
private static final float dashSpeed = 1.8f;
|
private static final float dashSpeed = 1.8f;
|
||||||
|
|
||||||
public String name = "player name";
|
public String name = "name";
|
||||||
public transient Weapon weapon = Weapon.blaster;
|
public transient Weapon weapon = Weapon.blaster;
|
||||||
public Mech mech = Mech.standard;
|
public Mech mech = Mech.standard;
|
||||||
public float angle;
|
public float angle;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package io.anuke.mindustry.entities.enemies;
|
||||||
|
|
||||||
|
public class StandardEnemy {
|
||||||
|
}
|
||||||
@@ -65,6 +65,11 @@ public class Net{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Kick a specified connection from the server.*/
|
||||||
|
public static void kickConnection(int id){
|
||||||
|
serverProvider.kick(id);
|
||||||
|
}
|
||||||
|
|
||||||
/**Returns a list of all connections IDs.*/
|
/**Returns a list of all connections IDs.*/
|
||||||
public static IntArray getConnections(){
|
public static IntArray getConnections(){
|
||||||
return serverProvider.getConnections();
|
return serverProvider.getConnections();
|
||||||
@@ -215,10 +220,12 @@ public class Net{
|
|||||||
public void close();
|
public void close();
|
||||||
/**Return all connected users.*/
|
/**Return all connected users.*/
|
||||||
public IntArray getConnections();
|
public IntArray getConnections();
|
||||||
/**Register classes to be sent.*/
|
/**Kick a certain connection.*/
|
||||||
public void register(Class<?>... types);
|
public void kick(int connection);
|
||||||
/**Returns the ping for a certain connection.*/
|
/**Returns the ping for a certain connection.*/
|
||||||
public int getPingFor(int connection);
|
public int getPingFor(int connection);
|
||||||
|
/**Register classes to be sent.*/
|
||||||
|
public void register(Class<?>... types);
|
||||||
/**Close all connections.*/
|
/**Close all connections.*/
|
||||||
public void dispose();
|
public void dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,4 +113,8 @@ public class Packets {
|
|||||||
public String name;
|
public String name;
|
||||||
public String text;
|
public String text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class KickPacket{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class Registrator {
|
|||||||
ConnectPacket.class,
|
ConnectPacket.class,
|
||||||
DisconnectPacket.class,
|
DisconnectPacket.class,
|
||||||
ChatPacket.class,
|
ChatPacket.class,
|
||||||
|
KickPacket.class,
|
||||||
|
|
||||||
Class.class,
|
Class.class,
|
||||||
byte[].class,
|
byte[].class,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Colors;
|
|||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.ucore.core.Draw;
|
import io.anuke.ucore.core.Draw;
|
||||||
import io.anuke.ucore.scene.ui.Image;
|
import io.anuke.ucore.scene.ui.Image;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
@@ -22,6 +23,11 @@ public class BorderImage extends Image{
|
|||||||
thickness = thick;
|
thickness = thick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BorderImage(TextureRegion region, float thick){
|
||||||
|
super(region);
|
||||||
|
thickness = thick;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Batch batch, float alpha){
|
public void draw(Batch batch, float alpha){
|
||||||
super.draw(batch, alpha);
|
super.draw(batch, alpha);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class MenuDialog extends FloatingDialog{
|
|||||||
}else {
|
}else {
|
||||||
ui.showHostServer();
|
ui.showHostServer();
|
||||||
}
|
}
|
||||||
}).disabled(b -> Net.active() || (Net.active() && !Net.server()));
|
}).disabled(b -> Net.active());
|
||||||
|
|
||||||
content().row();
|
content().row();
|
||||||
|
|
||||||
@@ -96,7 +96,14 @@ public class MenuDialog extends FloatingDialog{
|
|||||||
|
|
||||||
new imagebutton("icon-load", isize, () -> load.show()).text("$text.load").padTop(4f).disabled(Net.active());
|
new imagebutton("icon-load", isize, () -> load.show()).text("$text.load").padTop(4f).disabled(Net.active());
|
||||||
|
|
||||||
new imagebutton("icon-host", isize, () -> ui.showHostServer()).text("$text.host").padTop(4f);
|
new imagebutton("icon-host", isize, () -> {
|
||||||
|
if(Vars.world.getMap().custom){
|
||||||
|
ui.showError("$text.nohost");
|
||||||
|
}else {
|
||||||
|
ui.showHostServer();
|
||||||
|
}
|
||||||
|
}).text("$text.host")
|
||||||
|
.disabled(b -> Net.active()).padTop(4f);
|
||||||
|
|
||||||
new imagebutton("icon-quit", isize, () -> {
|
new imagebutton("icon-quit", isize, () -> {
|
||||||
Vars.ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
|
Vars.ui.showConfirm("$text.confirm", "$text.quit.confirm", () -> {
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package io.anuke.mindustry.ui.fragments;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.entities.Player;
|
||||||
|
import io.anuke.mindustry.net.Net;
|
||||||
|
import io.anuke.mindustry.ui.BorderImage;
|
||||||
|
import io.anuke.ucore.core.Draw;
|
||||||
|
import io.anuke.ucore.scene.builders.label;
|
||||||
|
import io.anuke.ucore.scene.builders.table;
|
||||||
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
import io.anuke.ucore.util.Bundles;
|
||||||
|
|
||||||
|
public class PlayerListFragment implements Fragment{
|
||||||
|
Table content = new Table();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(){
|
||||||
|
new table(){{
|
||||||
|
new table("pane"){{
|
||||||
|
new label(() -> Bundles.format("text.players", Vars.control.playerGroup.amount()));
|
||||||
|
row();
|
||||||
|
add(content).grow();
|
||||||
|
}}.end();
|
||||||
|
}}.end();
|
||||||
|
|
||||||
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rebuild(){
|
||||||
|
if(!Net.active()) return;
|
||||||
|
content.clear();
|
||||||
|
|
||||||
|
float h = 80f;
|
||||||
|
|
||||||
|
for(Player player : Vars.control.playerGroup.all()){
|
||||||
|
Table button = new Table("button");
|
||||||
|
button.left();
|
||||||
|
button.margin(0);
|
||||||
|
BorderImage image = new BorderImage(Draw.region(player.isAndroid ? "ship-standard" : "mech-standard"), 3f);
|
||||||
|
button.add(image).size(h);
|
||||||
|
button.add(player.name).pad(10);
|
||||||
|
|
||||||
|
if(Net.server() && !player.isLocal){
|
||||||
|
button.add().growY();
|
||||||
|
button.addIButton("icon-cancel", 14*3, () ->
|
||||||
|
Net.kickConnection(player.clientid)
|
||||||
|
).size(h);
|
||||||
|
}
|
||||||
|
|
||||||
|
content.add(button).padBottom(-5).width(250f);
|
||||||
|
content.row();
|
||||||
|
}
|
||||||
|
|
||||||
|
content.marginBottom(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,11 +9,13 @@ import io.anuke.mindustry.net.Net.SendMode;
|
|||||||
import io.anuke.mindustry.net.Net.ServerProvider;
|
import io.anuke.mindustry.net.Net.ServerProvider;
|
||||||
import io.anuke.mindustry.net.Packets.Connect;
|
import io.anuke.mindustry.net.Packets.Connect;
|
||||||
import io.anuke.mindustry.net.Packets.Disconnect;
|
import io.anuke.mindustry.net.Packets.Disconnect;
|
||||||
|
import io.anuke.mindustry.net.Packets.KickPacket;
|
||||||
import io.anuke.mindustry.net.Registrator;
|
import io.anuke.mindustry.net.Registrator;
|
||||||
import io.anuke.mindustry.net.Streamable;
|
import io.anuke.mindustry.net.Streamable;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
||||||
import io.anuke.ucore.UCore;
|
import io.anuke.ucore.UCore;
|
||||||
|
import io.anuke.ucore.core.Timers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@@ -99,6 +101,18 @@ public class KryoServer implements ServerProvider {
|
|||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void kick(int connection) {
|
||||||
|
Connection conn = getByID(connection);
|
||||||
|
|
||||||
|
conn.sendTCP(new KickPacket());
|
||||||
|
Timers.runTask(1f, () -> {
|
||||||
|
if(conn.isConnected()){
|
||||||
|
conn.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void host(int port) throws IOException {
|
public void host(int port) throws IOException {
|
||||||
server.bind(port, port);
|
server.bind(port, port);
|
||||||
|
|||||||
Reference in New Issue
Block a user