Added ping marker to servers
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB |
@@ -243,11 +243,11 @@ public class ContentLoader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Block block(int id){
|
public Block block(int id){
|
||||||
return (Block)getByID(ContentType.block, id);
|
return getByID(ContentType.block, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block block(String name){
|
public Block block(String name){
|
||||||
return (Block)getByName(ContentType.block, name);
|
return getByName(ContentType.block, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Seq<Item> items(){
|
public Seq<Item> items(){
|
||||||
@@ -255,7 +255,7 @@ public class ContentLoader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Item item(int id){
|
public Item item(int id){
|
||||||
return (Item)getByID(ContentType.item, id);
|
return getByID(ContentType.item, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Seq<Liquid> liquids(){
|
public Seq<Liquid> liquids(){
|
||||||
@@ -263,7 +263,7 @@ public class ContentLoader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Liquid liquid(int id){
|
public Liquid liquid(int id){
|
||||||
return (Liquid)getByID(ContentType.liquid, id);
|
return getByID(ContentType.liquid, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Seq<BulletType> bullets(){
|
public Seq<BulletType> bullets(){
|
||||||
@@ -271,7 +271,7 @@ public class ContentLoader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BulletType bullet(int id){
|
public BulletType bullet(int id){
|
||||||
return (BulletType)getByID(ContentType.bullet, id);
|
return getByID(ContentType.bullet, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Seq<SectorPreset> sectors(){
|
public Seq<SectorPreset> sectors(){
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
Threads.daemon(() -> {
|
Threads.daemon(() -> {
|
||||||
try{
|
try{
|
||||||
DatagramSocket socket = new DatagramSocket();
|
DatagramSocket socket = new DatagramSocket();
|
||||||
|
long time = Time.millis();
|
||||||
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
|
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
|
||||||
socket.setSoTimeout(2000);
|
socket.setSoTimeout(2000);
|
||||||
|
|
||||||
@@ -187,7 +188,7 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
||||||
Host host = NetworkIO.readServerData(packet.getAddress().getHostAddress(), buffer);
|
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
|
||||||
|
|
||||||
Core.app.post(() -> valid.get(host));
|
Core.app.post(() -> valid.get(host));
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
@@ -199,6 +200,7 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
@Override
|
@Override
|
||||||
public void discoverServers(Cons<Host> callback, Runnable done){
|
public void discoverServers(Cons<Host> callback, Runnable done){
|
||||||
Seq<InetAddress> foundAddresses = new Seq<>();
|
Seq<InetAddress> foundAddresses = new Seq<>();
|
||||||
|
long time = Time.millis();
|
||||||
client.discoverHosts(port, multicastGroup, multicastPort, 3000, packet -> {
|
client.discoverHosts(port, multicastGroup, multicastPort, 3000, packet -> {
|
||||||
Core.app.post(() -> {
|
Core.app.post(() -> {
|
||||||
try{
|
try{
|
||||||
@@ -206,7 +208,7 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
ByteBuffer buffer = ByteBuffer.wrap(packet.getData());
|
||||||
Host host = NetworkIO.readServerData(packet.getAddress().getHostAddress(), buffer);
|
Host host = NetworkIO.readServerData((int)Time.timeSinceMillis(time), packet.getAddress().getHostAddress(), buffer);
|
||||||
callback.get(host);
|
callback.get(host);
|
||||||
foundAddresses.add(packet.getAddress());
|
foundAddresses.add(packet.getAddress());
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ public class Host{
|
|||||||
public final @Nullable String modeName;
|
public final @Nullable String modeName;
|
||||||
public int ping, port = Vars.port;
|
public int ping, port = Vars.port;
|
||||||
|
|
||||||
public Host(String name, String address, String mapname, int wave, int players, int version, String versionType, Gamemode mode, int playerLimit, String description, String modeName){
|
public Host(int ping, String name, String address, String mapname, int wave, int players, int version, String versionType, Gamemode mode, int playerLimit, String description, String modeName){
|
||||||
|
this.ping = ping;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.players = players;
|
this.players = players;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class NetworkIO{
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Host readServerData(String hostAddress, ByteBuffer buffer){
|
public static Host readServerData(int ping, String hostAddress, ByteBuffer buffer){
|
||||||
String host = readString(buffer);
|
String host = readString(buffer);
|
||||||
String map = readString(buffer);
|
String map = readString(buffer);
|
||||||
int players = buffer.getInt();
|
int players = buffer.getInt();
|
||||||
@@ -100,7 +100,7 @@ public class NetworkIO{
|
|||||||
String description = readString(buffer);
|
String description = readString(buffer);
|
||||||
String modeName = readString(buffer);
|
String modeName = readString(buffer);
|
||||||
|
|
||||||
return new Host(host, hostAddress, map, wave, players, version, vertype, gamemode, limit, description, modeName.isEmpty() ? null : modeName);
|
return new Host(ping, host, hostAddress, map, wave, players, version, vertype, gamemode, limit, description, modeName.isEmpty() ? null : modeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeString(ByteBuffer buffer, String string, int maxlen){
|
private static void writeString(ByteBuffer buffer, String string, int maxlen){
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.ui.dialogs;
|
package mindustry.ui.dialogs;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
|
import arc.graphics.*;
|
||||||
import arc.input.*;
|
import arc.input.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
@@ -233,6 +234,10 @@ public class JoinDialog extends BaseDialog{
|
|||||||
t.add("[lightgray]" + (Core.bundle.format("players" + (host.players == 1 && host.playerLimit <= 0 ? ".single" : ""), (host.players == 0 ? "[lightgray]" : "[accent]") + host.players + (host.playerLimit > 0 ? "[lightgray]/[accent]" + host.playerLimit : "")+ "[lightgray]"))).left();
|
t.add("[lightgray]" + (Core.bundle.format("players" + (host.players == 1 && host.playerLimit <= 0 ? ".single" : ""), (host.players == 0 ? "[lightgray]" : "[accent]") + host.players + (host.playerLimit > 0 ? "[lightgray]/[accent]" + host.playerLimit : "")+ "[lightgray]"))).left();
|
||||||
t.row();
|
t.row();
|
||||||
t.add("[lightgray]" + Core.bundle.format("save.map", host.mapname) + "[lightgray] / " + (host.modeName == null ? host.mode.toString() : host.modeName)).width(targetWidth() - 10f).left().get().setEllipsis(true);
|
t.add("[lightgray]" + Core.bundle.format("save.map", host.mapname) + "[lightgray] / " + (host.modeName == null ? host.mode.toString() : host.modeName)).width(targetWidth() - 10f).left().get().setEllipsis(true);
|
||||||
|
if(host.ping > 0){
|
||||||
|
t.row();
|
||||||
|
t.add(Iconc.chartBar + " " + host.ping + "ms").color(Color.gray).left();
|
||||||
|
}
|
||||||
}).expand().left().bottom().padLeft(12f).padBottom(8);
|
}).expand().left().bottom().padLeft(12f).padBottom(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,9 +439,13 @@ public class JoinDialog extends BaseDialog{
|
|||||||
defaultServers.clear();
|
defaultServers.clear();
|
||||||
val.asArray().each(child -> defaultServers.add(child.getString("address", "<invalid>")));
|
val.asArray().each(child -> defaultServers.add(child.getString("address", "<invalid>")));
|
||||||
Log.info("Fetched @ global servers.", defaultServers.size);
|
Log.info("Fetched @ global servers.", defaultServers.size);
|
||||||
}catch(Throwable ignored){}
|
}catch(Throwable ignored){
|
||||||
|
Log.err("Failed to parse community servers.");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}catch(Throwable ignored){}
|
}catch(Throwable e){
|
||||||
|
Log.err("Failed to fetch community servers.");
|
||||||
|
}
|
||||||
}, t -> {});
|
}, t -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -305,6 +305,7 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
|||||||
try{
|
try{
|
||||||
SteamID lobby = smat.getLobbyByIndex(i);
|
SteamID lobby = smat.getLobbyByIndex(i);
|
||||||
Host out = new Host(
|
Host out = new Host(
|
||||||
|
-1, //invalid ping
|
||||||
smat.getLobbyData(lobby, "name"),
|
smat.getLobbyData(lobby, "name"),
|
||||||
"steam:" + lobby.handle(),
|
"steam:" + lobby.handle(),
|
||||||
smat.getLobbyData(lobby, "mapname"),
|
smat.getLobbyData(lobby, "mapname"),
|
||||||
|
|||||||
Reference in New Issue
Block a user