|
@@ -4,7 +4,16 @@ import de.nplusc.izc.MegatronBridge.Models.CustomAudio;
|
|
|
import de.nplusc.izc.MegatronBridge.Models.MovementActions;
|
|
|
import de.nplusc.izc.MegatronBridge.Models.OnboardAudio;
|
|
|
import de.nplusc.izc.MegatronBridge.Models.RawAction;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.server.ResponseStatusException;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class MegatronService
|
|
@@ -21,21 +30,33 @@ public class MegatronService
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //validator error
|
|
|
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Out of Range");
|
|
|
}
|
|
|
}
|
|
|
public void executeRaw(RawAction action)
|
|
|
{
|
|
|
- if(action.getPSK().equals(MegatronBridgeApplication.PSK))
|
|
|
+ boolean sus=false;
|
|
|
+ if(action.getpsk()==null)
|
|
|
+ {
|
|
|
+ sus=true;
|
|
|
+ System.out.println("it smells fishy");
|
|
|
+ }
|
|
|
+ if(action.getCommand()==null)
|
|
|
+ {
|
|
|
+ sus=true;
|
|
|
+ System.out.println("it smells fishy again");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!sus&&action.getpsk().equals(MegatronBridgeApplication.PSK))
|
|
|
{
|
|
|
CommandQueueItem itm = new CommandQueueItem();
|
|
|
itm.type=CommandType.RawCommand;
|
|
|
- itm.patharg=action.getCommand();
|
|
|
+ itm.extendedArg =action.getCommand();
|
|
|
MegatronBridgeApplication.spammer.getQueue().add(itm);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //"from __future__ import braces
|
|
|
+ throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "from __future__ import braces");
|
|
|
}
|
|
|
}
|
|
|
public void playOnbardAudio(OnboardAudio audio)
|
|
@@ -51,36 +72,25 @@ public class MegatronService
|
|
|
case SND_BOOTUP -> 6;
|
|
|
};
|
|
|
CommandQueueItem itm = new CommandQueueItem();
|
|
|
- itm.type=CommandType.CustomAudio;
|
|
|
+ itm.type=CommandType.OnboardAudio;
|
|
|
itm.argument=internalId;
|
|
|
MegatronBridgeApplication.spammer.getQueue().add(itm);
|
|
|
}
|
|
|
+
|
|
|
+ public String[] listAudio()
|
|
|
+ {
|
|
|
+ return audioMapTable.stream().map((o)->o.ID()).toList().toArray(new String[audioMapTable.size()]);
|
|
|
+ }
|
|
|
+
|
|
|
public void playCustomAudio(CustomAudio audio)
|
|
|
{
|
|
|
- int internalId = switch(audio.getTargetSample())
|
|
|
+ final String ref = audio.getTargetSample();
|
|
|
+ InternalAudioMapping mapping = audioMapTable.stream().filter(o->o.ID().equals(ref)).findFirst().orElseGet(()->null);
|
|
|
+ if(mapping==null)
|
|
|
{
|
|
|
- case ROGERROGER -> 0;
|
|
|
- case R2D2_BEEPERY -> 1;
|
|
|
- case JFO_SFX_MACHINEPOWERUP -> 2;
|
|
|
- case JFO_AUTHENTICATED -> 3;
|
|
|
- case JFO_CHARGED_AND_READY -> 4;
|
|
|
- case JFO_CORE_PROGRAMMING_MODIFIED -> 5;
|
|
|
- case JFO_RECALIBRATING -> 6;
|
|
|
- case JFO_SCANNING -> 7;
|
|
|
- case JFO_SYSTEM_REBOOTED -> 8;
|
|
|
- case JFO_SYSTEM_MALFUNCTION -> 9;
|
|
|
- case R2D2_DEMOTIVATED -> 10;
|
|
|
- case GB_STARTUP_SOUND -> 11;
|
|
|
- case WORMS_BITTEKOMMENGROSSERVOGEL -> 12;
|
|
|
- case GLADOS_OHDUBISTES -> 19;
|
|
|
- case GLADOS_NICHT_REINFALLEN -> 20;
|
|
|
- case GLADOS_PLANB -> 21;
|
|
|
- case GLADOS_SEID_IHR_DEFEKT -> 22;
|
|
|
- case HALLELUJAH -> 23;
|
|
|
- case P2TURRET_FAIL -> 24;
|
|
|
- case WORMS_OEDE -> 25;
|
|
|
- case OPTIMUSPRIME -> 26;
|
|
|
- };
|
|
|
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "from __future__ import braces");
|
|
|
+ }
|
|
|
+ int internalId=mapping.index();
|
|
|
if(audio.isWiggleMouth())
|
|
|
{
|
|
|
internalId|=0x1_00_00;
|
|
@@ -90,6 +100,7 @@ public class MegatronService
|
|
|
itm.argument=internalId;
|
|
|
MegatronBridgeApplication.spammer.getQueue().add(itm);
|
|
|
}
|
|
|
+
|
|
|
public void wiggle(MovementActions action)
|
|
|
{
|
|
|
int internalId = switch(action)
|
|
@@ -109,9 +120,53 @@ public class MegatronService
|
|
|
}
|
|
|
public void wiggleMouth()
|
|
|
{
|
|
|
+ System.out.println("Mundwerk wiggler");
|
|
|
CommandQueueItem itm = new CommandQueueItem();
|
|
|
itm.type=CommandType.MundwerkToggle;
|
|
|
MegatronBridgeApplication.spammer.getQueue().add(itm);
|
|
|
}
|
|
|
- //TODO sent audio
|
|
|
+
|
|
|
+ public void streamAudio(MultipartFile file)
|
|
|
+ {
|
|
|
+ if(file.getSize()>60*11000)
|
|
|
+ {
|
|
|
+ throw new ResponseStatusException(HttpStatus.PAYLOAD_TOO_LARGE, "forget it....");
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ CommandQueueItem itm = new CommandQueueItem();
|
|
|
+ itm.type=CommandType.StreamAudio;
|
|
|
+ byte[] tmp = file.getBytes();
|
|
|
+ itm.streamData= Arrays.copyOfRange(tmp,0,tmp.length&(~0b00111111)); //trim down to nearest 64 byte chunk
|
|
|
+ MegatronBridgeApplication.spammer.getQueue().add(itm);
|
|
|
+ } catch (IOException e)
|
|
|
+ {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "oupps");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<InternalAudioMapping> audioMapTable = loadMappings();
|
|
|
+
|
|
|
+ private static List<InternalAudioMapping> loadMappings(){
|
|
|
+ LinkedList list = new LinkedList<>();
|
|
|
+ try (BufferedReader in = new BufferedReader(new FileReader(ResourceUtils.getFile("classpath:audiomapping.lst")));){
|
|
|
+
|
|
|
+ in.lines().forEach(line->
|
|
|
+ {
|
|
|
+ String[] linesplit = line.split(":");
|
|
|
+ int index = Integer.decode(linesplit[1]);
|
|
|
+ list.add(new InternalAudioMapping(linesplit[0],index));
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+record InternalAudioMapping(String ID, int index)
|
|
|
+{}
|