mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-31 01:44:22 +07:00
Display banned status in Steam lobbies
This commit is contained in:
parent
351c2c84f2
commit
3232e97d1a
@ -250,9 +250,10 @@ public class JoinDialog extends BaseDialog{
|
||||
buildServer(host, server.content, false);
|
||||
}
|
||||
|
||||
void buildServer(Host host, Table content, boolean inner){
|
||||
void buildServer(Host host, Table content, boolean local){
|
||||
content.top().left();
|
||||
String versionString = getVersionString(host);
|
||||
boolean isBanned = local && Vars.steam && host.description != null && host.description.equals("[banned]");
|
||||
String versionString = getVersionString(host) + (isBanned ? "[red] [banned]" : "");
|
||||
|
||||
float twidth = targetWidth() - 40f;
|
||||
|
||||
@ -260,7 +261,7 @@ public class JoinDialog extends BaseDialog{
|
||||
|
||||
Color color = Pal.gray;
|
||||
|
||||
if(inner){
|
||||
if(local){
|
||||
content.table(Tex.whiteui, t -> {
|
||||
t.left();
|
||||
t.setColor(color);
|
||||
@ -274,7 +275,7 @@ public class JoinDialog extends BaseDialog{
|
||||
t.setColor(color);
|
||||
t.left();
|
||||
|
||||
if(!host.description.isEmpty()){
|
||||
if(!host.description.isEmpty() && !isBanned){
|
||||
//limit newlines.
|
||||
int count = 0;
|
||||
StringBuilder result = new StringBuilder(host.description.length());
|
||||
|
@ -107,6 +107,9 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
|
||||
Events.on(WaveEvent.class, e -> updateWave());
|
||||
Events.run(Trigger.newGame, this::updateWave);
|
||||
|
||||
Events.on(PlayerIpBanEvent.class, e -> updateBans(e.ip));
|
||||
Events.on(PlayerIpUnbanEvent.class, e -> updateBans(e.ip));
|
||||
}
|
||||
|
||||
public boolean isSteamClient(){
|
||||
@ -207,6 +210,12 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the ban list so that lobbies don't appear for banned players. The list will only be updated when a steam player is banned/unbanned. */
|
||||
void updateBans(String changed){
|
||||
if(changed != null && !changed.startsWith("steam:")) return; //hacky way to ignore non-steam ids
|
||||
smat.setLobbyData(currentLobby, "banned", netServer.admins.bannedIPs.select(ip -> ip.contains("steam:")).reduce(new StringBuilder(), (ip, str) -> str.append(ip.substring(6)).append(',')).toString()); //list of handles split by commas
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeServer(){
|
||||
provider.closeServer();
|
||||
@ -321,6 +330,11 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
String mode = smat.getLobbyData(lobby, "gamemode");
|
||||
//make sure versions are equal, don't list incompatible lobbies
|
||||
if(mode == null || mode.isEmpty() || (Version.build != -1 && Strings.parseInt(smat.getLobbyData(lobby, "version"), -1) != Version.build)) continue;
|
||||
|
||||
String banList = smat.getLobbyData(lobby, "banned");
|
||||
|
||||
boolean banned = banList.length() > 0 && Structs.contains(banList.split(","), SVars.user.user.getSteamID().getAccountID() + "");
|
||||
|
||||
Host out = new Host(
|
||||
-1, //invalid ping
|
||||
smat.getLobbyData(lobby, "name"),
|
||||
@ -332,7 +346,7 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
smat.getLobbyData(lobby, "versionType"),
|
||||
Gamemode.valueOf(mode),
|
||||
smat.getLobbyMemberLimit(lobby),
|
||||
"",
|
||||
banned ? "[banned]" : "",
|
||||
null
|
||||
);
|
||||
hosts.add(out);
|
||||
@ -365,6 +379,7 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
|
||||
smat.setLobbyData(steamID, "versionType", Version.type);
|
||||
smat.setLobbyData(steamID, "wave", state.wave + "");
|
||||
smat.setLobbyData(steamID, "gamemode", state.rules.mode().name() + "");
|
||||
updateBans(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user