From 0df60d9d01df4d73d282203c6b87b2a4fe82f685 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 31 Jul 2016 12:57:39 +0200 Subject: [PATCH] =?UTF-8?q?(merge=20avec=20precedent)=20Int=C3=A9gration?= =?UTF-8?q?=20de=20PandacubeWeb=20dans=20le=20code=20PHP=20actuel=20+=20Co?= =?UTF-8?q?rrections=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fr/pandacube/java/util/db/sql_tools/ORM.java | 7 +++---- .../util/network/packet/bytebuffer/ByteBuffer.java | 9 +++++---- .../packets/global/PacketServerException.java | 3 +-- .../java/util/network/server/TCPServer.java | 13 +++++++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/fr/pandacube/java/util/db/sql_tools/ORM.java b/src/fr/pandacube/java/util/db/sql_tools/ORM.java index 85e0b04..c3aaf72 100644 --- a/src/fr/pandacube/java/util/db/sql_tools/ORM.java +++ b/src/fr/pandacube/java/util/db/sql_tools/ORM.java @@ -89,11 +89,11 @@ public final class ORM { if (tables.contains(elemClass)) return; try { tables.add(elemClass); - Log.info("Start initializing SQL table "+elemClass.getName()); + //Log.info("Start Init SQL table "+elemClass.getSimpleName()); E instance = elemClass.newInstance(); String tableName = instance.tableName(); if (!tableExist(tableName)) createTable(instance); - Log.info("End of initializing SQL table "+elemClass.getName()); + //Log.info("End init SQL table "+elemClass.getSimpleName()); } catch (Exception|ExceptionInInitializerError e) { throw new ORMInitTableException(elemClass, e); } @@ -287,8 +287,7 @@ public final class ORM { * for(SQLPlayer p : players) { * System.out.println(p.get(SQLPlayer.playerDisplayName)); * } - * // TODO LIST - * - Gérer mise à jour relative d'un champ (incrément / décrément) + * // TODO mise à jour relative d'un champ (incrément / décrément) * } */ diff --git a/src/fr/pandacube/java/util/network/packet/bytebuffer/ByteBuffer.java b/src/fr/pandacube/java/util/network/packet/bytebuffer/ByteBuffer.java index c9440b9..cb7cb87 100644 --- a/src/fr/pandacube/java/util/network/packet/bytebuffer/ByteBuffer.java +++ b/src/fr/pandacube/java/util/network/packet/bytebuffer/ByteBuffer.java @@ -25,10 +25,11 @@ public class ByteBuffer implements Cloneable { } private void askForBufferExtension(int needed) { - if (buff.remaining() >= needed) return; - java.nio.ByteBuffer newBuff = java.nio.ByteBuffer.wrap(Arrays.copyOf(buff.array(), buff.array().length * 2)); - newBuff.position(buff.position()); - buff = newBuff; + while (buff.remaining() < needed) { + java.nio.ByteBuffer newBuff = java.nio.ByteBuffer.wrap(Arrays.copyOf(buff.array(), buff.array().length * 2)); + newBuff.position(buff.position()); + buff = newBuff; + } } @Override diff --git a/src/fr/pandacube/java/util/network/packet/packets/global/PacketServerException.java b/src/fr/pandacube/java/util/network/packet/packets/global/PacketServerException.java index 64f4d13..279d13a 100644 --- a/src/fr/pandacube/java/util/network/packet/packets/global/PacketServerException.java +++ b/src/fr/pandacube/java/util/network/packet/packets/global/PacketServerException.java @@ -21,8 +21,7 @@ public class PacketServerException extends PacketServer { @Override public void deserializeFromByteBuffer(ByteBuffer buffer) { - // TODO Auto-generated method stub - + exception = buffer.getString(); } diff --git a/src/fr/pandacube/java/util/network/server/TCPServer.java b/src/fr/pandacube/java/util/network/server/TCPServer.java index 18a6f3a..b9f60c8 100644 --- a/src/fr/pandacube/java/util/network/server/TCPServer.java +++ b/src/fr/pandacube/java/util/network/server/TCPServer.java @@ -8,6 +8,7 @@ import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; +import java.net.SocketException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.BlockingQueue; @@ -80,8 +81,10 @@ public class TCPServer extends Thread implements Closeable { Log.getLogger().log(Level.SEVERE, "Connexion impossible avec " + socketClient.getInetAddress()); } } + } catch(SocketException e) { + } catch (Exception e) { - Log.getLogger().log(Level.WARNING, "Plus aucune connexion ne peux être acceptée", e); + Log.warning("Plus aucune connexion ne peux être acceptée", e); } } @@ -136,6 +139,7 @@ public class TCPServer extends Thread implements Closeable { } } + } catch(SocketException e) { } catch (Exception e) { Log.severe("Closing connection " + address, e); } @@ -242,16 +246,17 @@ public class TCPServer extends Thread implements Closeable { public void close() { try { if (isClosed.get()) return; + isClosed.set(true); clients.forEach(el -> el.close()); - - socket.close(); - isClosed.set(true); + try { listener.onSocketClose(this); } catch(Exception e) { Log.severe("Exception while calling TCPServerListener.onSocketClose()", e); } + + socket.close(); } catch (IOException e) {} }