Added ping marker to servers

This commit is contained in:
Anuken 2020-08-19 17:11:37 -04:00
parent 7251fa4a03
commit 5df2a3e625
7 changed files with 25 additions and 12 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

View File

@ -243,11 +243,11 @@ public class ContentLoader{
}
public Block block(int id){
return (Block)getByID(ContentType.block, id);
return getByID(ContentType.block, id);
}
public Block block(String name){
return (Block)getByName(ContentType.block, name);
return getByName(ContentType.block, name);
}
public Seq<Item> items(){
@ -255,7 +255,7 @@ public class ContentLoader{
}
public Item item(int id){
return (Item)getByID(ContentType.item, id);
return getByID(ContentType.item, id);
}
public Seq<Liquid> liquids(){
@ -263,7 +263,7 @@ public class ContentLoader{
}
public Liquid liquid(int id){
return (Liquid)getByID(ContentType.liquid, id);
return getByID(ContentType.liquid, id);
}
public Seq<BulletType> bullets(){
@ -271,7 +271,7 @@ public class ContentLoader{
}
public BulletType bullet(int id){
return (BulletType)getByID(ContentType.bullet, id);
return getByID(ContentType.bullet, id);
}
public Seq<SectorPreset> sectors(){

View File

@ -180,6 +180,7 @@ public class ArcNetProvider implements NetProvider{
Threads.daemon(() -> {
try{
DatagramSocket socket = new DatagramSocket();
long time = Time.millis();
socket.send(new DatagramPacket(new byte[]{-2, 1}, 2, InetAddress.getByName(address), port));
socket.setSoTimeout(2000);
@ -187,7 +188,7 @@ public class ArcNetProvider implements NetProvider{
socket.receive(packet);
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));
}catch(Exception e){
@ -199,6 +200,7 @@ public class ArcNetProvider implements NetProvider{
@Override
public void discoverServers(Cons<Host> callback, Runnable done){
Seq<InetAddress> foundAddresses = new Seq<>();
long time = Time.millis();
client.discoverHosts(port, multicastGroup, multicastPort, 3000, packet -> {
Core.app.post(() -> {
try{
@ -206,7 +208,7 @@ public class ArcNetProvider implements NetProvider{
return;
}
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);
foundAddresses.add(packet.getAddress());
}catch(Exception e){

View File

@ -16,7 +16,8 @@ public class Host{
public final @Nullable String modeName;
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.address = address;
this.players = players;

View File

@ -88,7 +88,7 @@ public class NetworkIO{
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 map = readString(buffer);
int players = buffer.getInt();
@ -100,7 +100,7 @@ public class NetworkIO{
String description = 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){

View File

@ -1,6 +1,7 @@
package mindustry.ui.dialogs;
import arc.*;
import arc.graphics.*;
import arc.input.*;
import arc.math.*;
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.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);
if(host.ping > 0){
t.row();
t.add(Iconc.chartBar + " " + host.ping + "ms").color(Color.gray).left();
}
}).expand().left().bottom().padLeft(12f).padBottom(8);
}
@ -434,9 +439,13 @@ public class JoinDialog extends BaseDialog{
defaultServers.clear();
val.asArray().each(child -> defaultServers.add(child.getString("address", "<invalid>")));
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 -> {});
}

View File

@ -305,6 +305,7 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
try{
SteamID lobby = smat.getLobbyByIndex(i);
Host out = new Host(
-1, //invalid ping
smat.getLobbyData(lobby, "name"),
"steam:" + lobby.handle(),
smat.getLobbyData(lobby, "mapname"),