mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-08-03 16:39:37 +07:00
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.quit=Quit
|
||||
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.disconnected={0} has disconnected.
|
||||
text.nohost=Can't host server on a custom map!
|
||||
|
@ -37,6 +37,7 @@ import java.util.Arrays;
|
||||
public class NetClient extends Module {
|
||||
boolean connecting = false;
|
||||
boolean gotEntities = false;
|
||||
boolean kicked = false;
|
||||
float playerSyncTime = 2;
|
||||
float dataTimeout = 60*10;
|
||||
|
||||
@ -45,6 +46,7 @@ public class NetClient extends Module {
|
||||
Net.handle(Connect.class, packet -> {
|
||||
connecting = true;
|
||||
gotEntities = false;
|
||||
kicked = false;
|
||||
Gdx.app.postRunnable(() -> {
|
||||
Vars.ui.hideLoading();
|
||||
Vars.ui.showLoading("$text.connecting.data");
|
||||
@ -65,6 +67,8 @@ public class NetClient extends Module {
|
||||
});
|
||||
|
||||
Net.handle(Disconnect.class, packet -> {
|
||||
if(kicked) return;
|
||||
|
||||
Gdx.app.postRunnable(() -> {
|
||||
Timers.runFor(3f, () -> {
|
||||
Vars.ui.hideLoading();
|
||||
@ -264,6 +268,12 @@ public class NetClient extends Module {
|
||||
Net.handle(ChatPacket.class, packet -> {
|
||||
//TODO
|
||||
});
|
||||
|
||||
Net.handle(KickPacket.class, packet -> {
|
||||
kicked = true;
|
||||
Net.disconnect();
|
||||
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.kicked"));
|
||||
});
|
||||
}
|
||||
|
||||
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 dashSpeed = 1.8f;
|
||||
|
||||
public String name = "player name";
|
||||
public String name = "name";
|
||||
public transient Weapon weapon = Weapon.blaster;
|
||||
public Mech mech = Mech.standard;
|
||||
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.*/
|
||||
public static IntArray getConnections(){
|
||||
return serverProvider.getConnections();
|
||||
@ -215,10 +220,12 @@ public class Net{
|
||||
public void close();
|
||||
/**Return all connected users.*/
|
||||
public IntArray getConnections();
|
||||
/**Register classes to be sent.*/
|
||||
public void register(Class<?>... types);
|
||||
/**Kick a certain connection.*/
|
||||
public void kick(int connection);
|
||||
/**Returns the ping for a certain connection.*/
|
||||
public int getPingFor(int connection);
|
||||
/**Register classes to be sent.*/
|
||||
public void register(Class<?>... types);
|
||||
/**Close all connections.*/
|
||||
public void dispose();
|
||||
}
|
||||
|
@ -113,4 +113,8 @@ public class Packets {
|
||||
public String name;
|
||||
public String text;
|
||||
}
|
||||
|
||||
public static class KickPacket{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class Registrator {
|
||||
ConnectPacket.class,
|
||||
DisconnectPacket.class,
|
||||
ChatPacket.class,
|
||||
KickPacket.class,
|
||||
|
||||
Class.class,
|
||||
byte[].class,
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
import io.anuke.ucore.scene.ui.Image;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
@ -21,6 +22,11 @@ public class BorderImage extends Image{
|
||||
super(texture);
|
||||
thickness = thick;
|
||||
}
|
||||
|
||||
public BorderImage(TextureRegion region, float thick){
|
||||
super(region);
|
||||
thickness = thick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float alpha){
|
||||
|
@ -62,7 +62,7 @@ public class MenuDialog extends FloatingDialog{
|
||||
}else {
|
||||
ui.showHostServer();
|
||||
}
|
||||
}).disabled(b -> Net.active() || (Net.active() && !Net.server()));
|
||||
}).disabled(b -> Net.active());
|
||||
|
||||
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-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, () -> {
|
||||
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.Packets.Connect;
|
||||
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.Streamable;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -99,6 +101,18 @@ public class KryoServer implements ServerProvider {
|
||||
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
|
||||
public void host(int port) throws IOException {
|
||||
server.bind(port, port);
|
||||
|
Reference in New Issue
Block a user