fix Remote id generation, print some debug info about new selections
This commit is contained in:
parent
4dbfe3aaf0
commit
ed03536d5a
4 changed files with 20 additions and 20 deletions
|
@ -4,9 +4,12 @@ import com.baseband.client.BaseBand;
|
|||
import com.baseband.client.event.remote.RemoteEvent;
|
||||
import com.baseband.client.event.remote.RemoteEventManager;
|
||||
import com.baseband.client.util.interact.BlockUtils;
|
||||
import com.baseband.client.util.misc.GlobalUtil;
|
||||
import com.baseband.client.util.type.Selection;
|
||||
import de.tudbut.obj.Save;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SelectEvent extends RemoteEvent {
|
||||
@Save
|
||||
public Selection selection;
|
||||
|
@ -21,6 +24,7 @@ public class SelectEvent extends RemoteEvent {
|
|||
if(BaseBand.remoteEventManager.isConnected()) {
|
||||
RemoteEventManager manager = BaseBand.remoteEventManager;
|
||||
Selection[] splitSelection = BlockUtils.splitSelection1D(selection, manager.getPeers());
|
||||
GlobalUtil.LOGGER.info("Split selection: {}", Arrays.toString(splitSelection));
|
||||
if(splitSelection.length > manager.getID())
|
||||
return splitSelection[manager.getID()];
|
||||
else return null;
|
||||
|
|
|
@ -27,7 +27,7 @@ public class RemoteEventManager {
|
|||
public final ArrayList<Socket> clients = new ArrayList<>();
|
||||
public ServerSocket server = null;
|
||||
|
||||
private int id = -1, peers = 0, maxID = 0;
|
||||
private int id = -1, peers = 0;
|
||||
|
||||
private final Queue<RemoteEvent> toSend = new LinkedList<>();
|
||||
private final Queue<RemoteEvent> toProcess = new LinkedList<>();
|
||||
|
@ -59,7 +59,7 @@ public class RemoteEventManager {
|
|||
} catch (IOException ignored) {}
|
||||
clients.clear();
|
||||
id = -1;
|
||||
maxID = 0;
|
||||
peers = 0;
|
||||
server = null;
|
||||
head = null;
|
||||
BaseBand.ifFeatureEnabled(AltControl.class, f -> f.setEnabled(false));
|
||||
|
@ -78,7 +78,6 @@ public class RemoteEventManager {
|
|||
private void runServer() {
|
||||
try {
|
||||
id = 0;
|
||||
maxID = 0;
|
||||
server.setSoTimeout(1);
|
||||
while(server != null) {
|
||||
try {
|
||||
|
@ -90,7 +89,7 @@ public class RemoteEventManager {
|
|||
s.getOutputStream().flush();
|
||||
s.setSoTimeout(1);
|
||||
clients.add(s);
|
||||
publish(new RemoteInitEvent(++maxID, clients.size()));
|
||||
publish(new RemoteInitEvent(clients.size()));
|
||||
BaseBand.notify("[Remote] Client connected.");
|
||||
} else {
|
||||
s.close();
|
||||
|
@ -101,7 +100,7 @@ public class RemoteEventManager {
|
|||
for (int i = 0; i < clients.size(); i++) {
|
||||
Socket client = clients.get(i);
|
||||
try {
|
||||
client.getOutputStream().write(0);
|
||||
client.getOutputStream().write(i);
|
||||
new TypedOutputStream(client.getOutputStream()).writeString(stringEvent);
|
||||
client.getOutputStream().flush();
|
||||
} catch (IOException e) {
|
||||
|
@ -147,13 +146,13 @@ public class RemoteEventManager {
|
|||
BaseBand.notify("[Remote] Connected.");
|
||||
while(head != null) {
|
||||
while(!toSend.isEmpty()) {
|
||||
o.write(0);
|
||||
o.write(id);
|
||||
String stringEvent = JSON.write((TCN)ConfigSaverTCN2.write(toSend.poll(), false, false));
|
||||
tos.writeString(stringEvent);
|
||||
o.flush();
|
||||
}
|
||||
try {
|
||||
if (i.read() == -1) {
|
||||
if ((id = i.read()) == -1) {
|
||||
BaseBand.notify("[Remote] Connection ended.");
|
||||
end();
|
||||
return;
|
||||
|
@ -181,15 +180,8 @@ public class RemoteEventManager {
|
|||
while(!toProcess.isEmpty()) {
|
||||
RemoteEvent event = toProcess.poll();
|
||||
if(event instanceof RemoteInitEvent) {
|
||||
peers = ((RemoteInitEvent) event).clients;
|
||||
if(id == -1) {
|
||||
id = ((RemoteInitEvent) event).id;
|
||||
BaseBand.notify("[Remote] Received ID: " + id + ". Peers connected: " + peers + ".");
|
||||
}
|
||||
else {
|
||||
maxID = ((RemoteInitEvent) event).id;
|
||||
BaseBand.notify("[Remote] Someone connected with ID " + maxID + ". Peers connected: " + peers + ".");
|
||||
}
|
||||
peers = ((RemoteInitEvent) event).peers;
|
||||
BaseBand.notify("[Remote] Peers connected: " + peers + ".");
|
||||
}
|
||||
else {
|
||||
BaseBand.eventManager.publish(event);
|
||||
|
|
|
@ -5,10 +5,9 @@ import de.tudbut.obj.Save;
|
|||
|
||||
public class RemoteInitEvent extends RemoteEvent {
|
||||
@Save
|
||||
public int id, clients;
|
||||
public int peers;
|
||||
|
||||
public RemoteInitEvent(int id, int clients) {
|
||||
this.id = id;
|
||||
this.clients = clients;
|
||||
public RemoteInitEvent(int peers) {
|
||||
this.peers = peers;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,4 +30,9 @@ public class Selection {
|
|||
Vec3i size = size();
|
||||
return Math.max(size.getX(), size.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Selection[" + area() + "B from " + pos1 + " to " + pos2 + "]";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue