diff --git a/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java b/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java index 3c730e7..2e49482 100644 --- a/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java +++ b/dethsquare/core/src/main/java/com/ezardlabs/dethsquare/multiplayer/Network.java @@ -350,26 +350,44 @@ public class Network { socket.setKeepAlive(true); while (socket.isConnected()) { String command = in.readLine(); - if (command != null) { - switch (command) { - case INSTANTIATE: - processInstantiation(in.readLine()); - break; - case DESTROY: - processDestruction(in.readLine()); - break; - case REQUEST_STATE: - sendState(in.readLine()); - break; - default: - System.out.println("Unknown command:" + command); - break; - } + if (command == null) { + /* + * EOF = le pair a fermé la connexion. SANS ce garde, la + * boucle spinait à 100% CPU PAR CONNEXION MORTE pour + * toujours : readLine() rend null instantanément et + * isConnected() ne passe JAMAIS false sur une fermeture + * distante (état local seulement). C'était le gel du + * MacBook complet au ballon (retour v0.12.0 : chaque + * déconnexion du client multi laissait un cœur à + * fond, cumulé au jeu GL et à l'émulateur). + */ + GameLog.i("LS-NET", "Multiplayer : connexion TCP fermée par le pair"); + break; + } + switch (command) { + case INSTANTIATE: + String instantiateMsg = in.readLine(); + if (instantiateMsg == null) break; + processInstantiation(instantiateMsg); + break; + case DESTROY: + String destroyMsg = in.readLine(); + if (destroyMsg == null) break; + processDestruction(destroyMsg); + break; + case REQUEST_STATE: + String requestMsg = in.readLine(); + if (requestMsg == null) break; + sendState(requestMsg); + break; + default: + GameLog.d("LS-NET", "Multiplayer : commande TCP inconnue '" + command + "'"); + break; } } in.close(); } catch (IOException e) { - e.printStackTrace(); + GameLog.e("LS-NET", "Multiplayer : reader TCP interrompu", e); } } }