add config sending, fix some things in altcontrol

This commit is contained in:
Daniella / Tove 2024-06-01 01:50:16 +02:00
parent 614d9e2943
commit 5023a69ca2
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
7 changed files with 66 additions and 11 deletions

View file

@ -3,6 +3,7 @@ package com.baseband.client;
import com.baseband.client.event.Event;
import com.baseband.client.event.remote.RemoteEvent;
import com.baseband.client.event.remote.RemoteEventManager;
import com.baseband.client.registry.ConfigHandle;
import com.baseband.client.registry.Updater;
import com.baseband.client.event.EventManager;
import com.baseband.client.event.FMLEventHandler;
@ -13,6 +14,7 @@ import com.baseband.client.util.type.KeyBind;
import com.baseband.client.util.interact.ChatUtil;
import com.baseband.client.util.type.FeatureAction;
import com.baseband.client.util.misc.GlobalUtil;
import de.tudbut.parsing.TCN;
import de.tudbut.tools.Lock;
import net.minecraft.client.Minecraft;
import net.minecraftforge.common.MinecraftForge;
@ -37,6 +39,17 @@ public class BaseBand {
public static Feature[] features = new Feature[0];
public void cloneConfigFrom(TCN fullDB) {
for (Feature feature : features) {
for (ConfigHandle handle : feature.ownedHandles.values()) {
handle.cloneFrom(fullDB.getSub(handle.getName()));
}
}
for (Updater updater : updaters) {
updater.populate();
}
}
public static Updater registerUpdater(Updater updater) {
updaters.add(updater);
updater.populate();

View file

@ -33,16 +33,18 @@ public class RemoteEventManager {
private final Queue<RemoteEvent> toProcess = new LinkedList<>();
public void connect(String ip) {
if(isConnected())
end();
try {
if(isConnected())
end();
server = new ServerSocket(Setup.Port);
initServer();
} catch (IOException e) {
head = new Socket(ip, Setup.Port);
initClient();
BaseBand.notify("[Remote] Started as client.");
} catch (IOException ex) {
try {
head = new Socket(ip, Setup.Port);
initClient();
} catch (IOException ex) {
server = new ServerSocket(Setup.Port);
initServer();
BaseBand.notify("[Remote] Started as server.");
} catch (IOException e) {
BaseBand.notify("[Remote] Failed to start.");
}
}
@ -174,6 +176,8 @@ public class RemoteEventManager {
public void publish(RemoteEvent event) {
toSend.offer(event);
if(id == 0)
toProcess.offer(event);
}
public boolean isConnected() {

View file

@ -0,0 +1,22 @@
package com.baseband.client.event.remote.events;
import com.baseband.client.event.remote.RemoteEvent;
import com.baseband.client.registry.Configuration;
import com.baseband.client.util.adapt.FieldFinder;
import de.tudbut.obj.Save;
import de.tudbut.parsing.TCN;
import de.tudbut.tools.Registry;
public class RemoteConfigEvent extends RemoteEvent {
@Save
public TCN fatTCN;
public RemoteConfigEvent() {
try {
fatTCN = (TCN) FieldFinder.findUnmarked(Registry.class, TCN.class, 0).get(Configuration.INSTANCE.registry);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -239,7 +239,7 @@ public abstract class Feature extends ToggleButton implements SetCommand {
return getIDCategory() + "." + getIDName();
}
private final HashMap<String, ConfigHandle> ownedHandles = new HashMap<>();
public final HashMap<String, ConfigHandle> ownedHandles = new HashMap<>();
protected ConfigHandle config(String handle) {
if(ownedHandles.containsKey(handle)) {

View file

@ -1,6 +1,7 @@
package com.baseband.client.feature.client;
import com.baseband.client.BaseBand;
import com.baseband.client.event.remote.events.RemoteConfigEvent;
import com.baseband.client.event.remote.events.RemoteSendMessageEvent;
import com.baseband.client.feature.Feature;
import com.baseband.client.feature.category.ClientCategory;
@ -19,6 +20,12 @@ public class AltControl extends Feature {
@Gate(1)
public String ip = "localhost";
@Trigger("Send config to alts")
@Gate(M_ENABLED)
public void sendConfig() {
BaseBand.publish(new RemoteConfigEvent());
}
@Marker(1)
boolean notEnabled = true;
@ -39,6 +46,11 @@ public class AltControl extends Feature {
ChatUtil.simulateSend(event.message, false);
}
public void onConfig(RemoteConfigEvent event) {
BaseBand.notify("[AltControl] Received a config.");
BaseBand.INSTANCE.cloneConfigFrom(event.fatTCN);
}
@Override
public void onCommand(String[] args) {
if(!enabled)

View file

@ -26,6 +26,10 @@ public class ConfigHandle implements SetCommand {
return tcn;
}
public void cloneFrom(TCN tcn) {
this.tcn.map = tcn.map;
}
public void poll() {
for (Updater updater : onUpdate) {
updater.poll();

View file

@ -7,12 +7,12 @@ import java.io.IOException;
public class Configuration {
private final Registry registry = new Registry(Setup.get().RegistryFilename);
public final Registry registry = new Registry(Setup.get().RegistryFilename);
private Configuration() throws IOException {
}
private static final Configuration INSTANCE;
public static final Configuration INSTANCE;
static {
try {