Better error handling on Steam

This commit is contained in:
Anuken
2020-09-22 13:12:21 -04:00
parent 5895e2f23c
commit 3a466475fd
4 changed files with 23 additions and 18 deletions

View File

@ -1365,7 +1365,6 @@ public class UnitTypes implements ContentList{
trailX = 5.5f; trailX = 5.5f;
trailY = -4f; trailY = -4f;
trailScl = 1.9f; trailScl = 1.9f;
rotateShooting = false;
abilities.add(new StatusFieldAbility(StatusEffects.overclock, 60f * 6, 60f * 6f, 60f)); abilities.add(new StatusFieldAbility(StatusEffects.overclock, 60f * 6, 60f * 6f, 60f));

View File

@ -61,7 +61,7 @@ public class ArcNetProvider implements NetProvider{
try{ try{
net.handleClientReceived(object); net.handleClientReceived(object);
}catch(Throwable e){ }catch(Throwable e){
handleException(e); net.handleException(e);
} }
}); });
@ -144,14 +144,14 @@ public class ArcNetProvider implements NetProvider{
try{ try{
client.run(); client.run();
}catch(Exception e){ }catch(Exception e){
if(!(e instanceof ClosedSelectorException)) handleException(e); if(!(e instanceof ClosedSelectorException)) net.handleException(e);
} }
}); });
client.connect(5000, ip, port, port); client.connect(5000, ip, port, port);
success.run(); success.run();
}catch(Exception e){ }catch(Exception e){
handleException(e); net.handleException(e);
} }
}); });
} }
@ -269,16 +269,6 @@ public class ArcNetProvider implements NetProvider{
return null; return null;
} }
void handleException(Throwable e){
if(e instanceof ArcNetException){
Core.app.post(() -> net.showError(new IOException("mismatch")));
}else if(e instanceof ClosedChannelException){
Core.app.post(() -> net.showError(new IOException("alreadyconnected")));
}else{
Core.app.post(() -> net.showError(e));
}
}
class ArcConnection extends NetConnection{ class ArcConnection extends NetConnection{
public final Connection connection; public final Connection connection;

View File

@ -1,10 +1,11 @@
package mindustry.net; package mindustry.net;
import arc.*; import arc.*;
import arc.struct.*;
import arc.func.*; import arc.func.*;
import arc.util.*; import arc.net.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.pooling.*; import arc.util.pooling.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.net.Packets.*; import mindustry.net.Packets.*;
@ -13,6 +14,7 @@ import net.jpountz.lz4.*;
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.nio.channels.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@ -36,6 +38,16 @@ public class Net{
this.provider = provider; this.provider = provider;
} }
public void handleException(Throwable e){
if(e instanceof ArcNetException){
Core.app.post(() -> showError(new IOException("mismatch")));
}else if(e instanceof ClosedChannelException){
Core.app.post(() -> showError(new IOException("alreadyconnected")));
}else{
Core.app.post(() -> showError(e));
}
}
/** Display a network error. Call on the graphics thread. */ /** Display a network error. Call on the graphics thread. */
public void showError(Throwable e){ public void showError(Throwable e){

View File

@ -79,10 +79,14 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback,
Log.err(e); Log.err(e);
} }
}else if(currentServer != null && fromID == currentServer.getAccountID()){ }else if(currentServer != null && fromID == currentServer.getAccountID()){
net.handleClientReceived(output); try{
net.handleClientReceived(output);
}catch(Throwable t){
net.handleException(t);
}
} }
}catch(SteamException e){ }catch(SteamException e){
e.printStackTrace(); Log.err(e);
} }
} }
} }