mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 17:00:52 +01:00
Fix scheduler for Shockwave
This commit is contained in:
parent
83ce7a0f6b
commit
f875eb4e29
@ -1,5 +1,7 @@
|
|||||||
package gearth.protocol;
|
package gearth.protocol;
|
||||||
|
|
||||||
|
import gearth.extensions.parsers.HDirection;
|
||||||
|
import gearth.protocol.connection.HClient;
|
||||||
import gearth.protocol.packethandler.shockwave.packets.ShockPacketIncoming;
|
import gearth.protocol.packethandler.shockwave.packets.ShockPacketIncoming;
|
||||||
import gearth.protocol.packethandler.shockwave.packets.ShockPacketOutgoing;
|
import gearth.protocol.packethandler.shockwave.packets.ShockPacketOutgoing;
|
||||||
|
|
||||||
@ -9,6 +11,14 @@ public enum HPacketFormat {
|
|||||||
WEDGIE_INCOMING,
|
WEDGIE_INCOMING,
|
||||||
WEDGIE_OUTGOING;
|
WEDGIE_OUTGOING;
|
||||||
|
|
||||||
|
public static HPacketFormat getFormat(HClient client, HMessage.Direction direction) {
|
||||||
|
if (client != HClient.SHOCKWAVE) {
|
||||||
|
return EVA_WIRE;
|
||||||
|
} else {
|
||||||
|
return direction == HMessage.Direction.TOCLIENT ? WEDGIE_INCOMING : WEDGIE_OUTGOING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public HPacket createPacket(String data) {
|
public HPacket createPacket(String data) {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case EVA_WIRE:
|
case EVA_WIRE:
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package gearth.services.scheduler;
|
package gearth.services.scheduler;
|
||||||
|
|
||||||
|
import gearth.extensions.parsers.HDirection;
|
||||||
import gearth.protocol.HConnection;
|
import gearth.protocol.HConnection;
|
||||||
import gearth.protocol.HMessage;
|
import gearth.protocol.HMessage;
|
||||||
import gearth.protocol.HPacket;
|
import gearth.protocol.HPacket;
|
||||||
|
import gearth.protocol.HPacketFormat;
|
||||||
|
import gearth.protocol.connection.HClient;
|
||||||
|
import gearth.protocol.connection.HState;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -13,7 +17,7 @@ public class Scheduler<T extends ScheduleItem> {
|
|||||||
|
|
||||||
private List<T> scheduleItems = new ArrayList<>();
|
private List<T> scheduleItems = new ArrayList<>();
|
||||||
|
|
||||||
public Scheduler(HConnection connection) {
|
public Scheduler(final HConnection connection) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
long t = System.currentTimeMillis();
|
long t = System.currentTimeMillis();
|
||||||
long changed = 1;
|
long changed = 1;
|
||||||
@ -27,6 +31,12 @@ public class Scheduler<T extends ScheduleItem> {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (connection.getState() != HState.CONNECTED) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final HClient clientType = connection.getClientType();
|
||||||
|
|
||||||
set.clear();
|
set.clear();
|
||||||
for (int i = size() - 1; i >= 0; i--) {
|
for (int i = size() - 1; i >= 0; i--) {
|
||||||
set.add(get(i));
|
set.add(get(i));
|
||||||
@ -37,18 +47,18 @@ public class Scheduler<T extends ScheduleItem> {
|
|||||||
Interval cur = item.getDelayProperty().get();
|
Interval cur = item.getDelayProperty().get();
|
||||||
for (int i = 0; i < changed; i++) {
|
for (int i = 0; i < changed; i++) {
|
||||||
if ((t - i) % cur.getDelay() == cur.getOffset()) {
|
if ((t - i) % cur.getDelay() == cur.getOffset()) {
|
||||||
HPacket hPacket = new HPacket(item.getPacketAsStringProperty().get());
|
final HMessage.Direction direction = item.getDestinationProperty().get();
|
||||||
|
final HPacketFormat format = HPacketFormat.getFormat(clientType, direction);
|
||||||
|
final HPacket hPacket = format.createPacket(item.getPacketAsStringProperty().get());
|
||||||
|
|
||||||
if (item.getDestinationProperty().get() == HMessage.Direction.TOSERVER) {
|
if (direction == HMessage.Direction.TOSERVER) {
|
||||||
connection.sendToServer(hPacket);
|
connection.sendToServer(hPacket);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
connection.sendToClient(hPacket);
|
connection.sendToClient(hPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long newT = System.currentTimeMillis();
|
long newT = System.currentTimeMillis();
|
||||||
|
Loading…
Reference in New Issue
Block a user