Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 549a5fe

Browse files
CTRL C Force stty
1 parent a8c86de commit 549a5fe

File tree

16 files changed

+423
-90
lines changed

16 files changed

+423
-90
lines changed

API/src/main/java/be/alexandre01/dreamnetwork/api/DNUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import lombok.Getter;
1313
import lombok.Setter;
1414

15-
import java.util.concurrent.atomic.AtomicInteger;
16-
1715
/*
1816
↬ Made by Alexandre01Dev 😎
1917
↬ done on 02/09/2023 at 19:29
@@ -26,12 +24,16 @@ public DNUtils(){
2624
public static DNUtils get(){
2725
return instance;
2826
}
27+
2928
@Getter @Setter
3029
public ColorsData colorsData;
30+
3131
public abstract AccessibilityMenu createAccessibilityMenu();
3232
public abstract IScreen createScreen(IService service);
3333
public abstract ICallbackManager createCallbackManager();
3434
public abstract IRequestManager createClientRequestManager(UniversalConnection client);
3535
public abstract IConfigManager getConfigManager();
3636
public abstract IConsoleManager getConsoleManager();
37+
38+
public abstract void stop();
3739
}

API/src/main/java/be/alexandre01/dreamnetwork/api/console/Console.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,7 @@ public static void setBlockConsole(boolean blockConsole) {
120120
if(blockConsole){
121121
// System.out.println("Stopping console");
122122
if(thread != null){
123-
//thread.interrupt();
124123
ConsoleThread.stopCurrent();// tell the thread to stop
125-
/*try {
126-
thread.join(); // wait for the thread to stop
127-
} catch (InterruptedException e) {
128-
throw new RuntimeException(e);
129-
}*/
130124
}
131125
}else {
132126
// System.out.println("Rerun console");
@@ -159,7 +153,8 @@ public boolean onKill(LineReader reader) {
159153
try {
160154
while ((data = reader.readLine(Console.getFromLang("console.askExit"))) != null){
161155
if(data.equalsIgnoreCase("y") || data.equalsIgnoreCase("yes")){
162-
System.exit(0);
156+
// System.exit(0);
157+
DNUtils.get().stop();
163158
return false;
164159
}else {
165160
Console.debugPrint(Console.getFromLang("cancelled"));
@@ -572,7 +567,8 @@ public static void bug(Throwable e){
572567
public static void SIG_IGN(){
573568
if(!DNUtils.get().getConfigManager().getGlobalSettings().isSIG_IGN_Handler()){
574569
Console.debugPrint(Console.getFromLang("console.closed"));
575-
System.exit(0);
570+
//System.exit(0);
571+
DNUtils.get().stop();
576572
}
577573

578574
try {
@@ -657,6 +653,7 @@ public void run() {
657653
scheduler.shutdown();
658654
}
659655

656+
660657
} catch (IOException e) {
661658
e.printStackTrace();
662659
}

Core/src/main/java/be/alexandre01/dreamnetwork/core/Core.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import be.alexandre01.dreamnetwork.api.events.EventsFactory;
1414
import be.alexandre01.dreamnetwork.api.events.list.CoreInitEvent;
1515
import be.alexandre01.dreamnetwork.api.utils.files.yaml.YamlFileUtils;
16-
import be.alexandre01.dreamnetwork.api.utils.optional.Facultative;
1716
import be.alexandre01.dreamnetwork.core.connection.core.NettyServer;
1817
import be.alexandre01.dreamnetwork.core.connection.core.ReactorNettyServer;
1918
import be.alexandre01.dreamnetwork.core.connection.core.communication.RateLimiter;
@@ -31,7 +30,7 @@
3130
import be.alexandre01.dreamnetwork.core.connection.core.players.ServicePlayersManager;
3231
import be.alexandre01.dreamnetwork.core.console.formatter.ConciseFormatter;
3332
import be.alexandre01.dreamnetwork.core.console.formatter.Formatter;
34-
import be.alexandre01.dreamnetwork.core.installer.InstallerManager;
33+
import be.alexandre01.dreamnetwork.core.files.InstallerManager;
3534
import be.alexandre01.dreamnetwork.core.service.JVMContainer;
3635
import be.alexandre01.dreamnetwork.core.service.bundle.BundleManager;
3736
import be.alexandre01.dreamnetwork.core.service.jvm.JavaIndex;
@@ -50,7 +49,6 @@
5049
import java.io.IOException;
5150
import java.io.InputStream;
5251
import java.util.ArrayList;
53-
import java.util.Optional;
5452
import java.util.function.Consumer;
5553
import java.util.logging.FileHandler;
5654
import java.util.logging.Level;
@@ -310,7 +308,7 @@ public void accept(DreamExtension dreamExtension) {
310308

311309
if(Main.getGlobalSettings().isSIG_IGN_Handler()){
312310
if(!Config.isWindows()){
313-
String[] defSIGKILL = {"/bin/sh","-c","stty intr ^C </dev/tty"};
311+
String[] defSIGKILL = {"/bin/sh","-c","stty intr undef </dev/tty"};
314312
try {
315313
Runtime.getRuntime().exec(defSIGKILL);
316314
} catch (IOException e) {

Core/src/main/java/be/alexandre01/dreamnetwork/core/Main.java

Lines changed: 148 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.io.OutputStream;
56
import java.io.PrintStream;
67
import java.net.InetAddress;
78
import java.net.UnknownHostException;
@@ -13,6 +14,8 @@
1314
import be.alexandre01.dreamnetwork.api.addons.DreamExtension;
1415
import be.alexandre01.dreamnetwork.api.config.WSSettings;
1516
import be.alexandre01.dreamnetwork.api.console.Console;
17+
import be.alexandre01.dreamnetwork.api.service.IContainer;
18+
import be.alexandre01.dreamnetwork.api.utils.messages.Message;
1619
import be.alexandre01.dreamnetwork.core.commands.CommandReader;
1720
import be.alexandre01.dreamnetwork.api.service.IExecutor;
1821
import be.alexandre01.dreamnetwork.api.service.IService;
@@ -79,6 +82,7 @@ public class Main {
7982
@Getter private static ProcessHistory processHistory;
8083

8184
@Getter private static SecretFile secretFile;
85+
private static ReaderHistory readerHistory;
8286

8387
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
8488

@@ -134,7 +138,7 @@ public static void main(String[] args) throws NoSuchFieldException, IllegalAcces
134138
consoleReader = new ConsoleReader();
135139
consoleReader.init();
136140

137-
ReaderHistory readerHistory = new ReaderHistory();
141+
readerHistory = new ReaderHistory();
138142
readerHistory.init();
139143

140144
taskOperation = new TaskOperation();
@@ -217,69 +221,71 @@ public static void main(String[] args) throws NoSuchFieldException, IllegalAcces
217221

218222
Runtime.getRuntime().addShutdownHook(new Thread() {
219223
public void run() {
220-
try {
221-
disabling = true;
222-
if(instance != null){
223-
boolean isReady = false;
224-
for(IExecutor jvmExecutor : instance.getJvmContainer().jvmExecutors){
225-
if(!jvmExecutor.getServices().isEmpty()){
226-
ArrayList<Long> pIDs = new ArrayList<>();
227-
for(IService service : new ArrayList<>(jvmExecutor.getServices())){
228-
if(!service.isConnected()){
229-
service.kill();
230-
}
231-
if(service.getProcessID() != -1){
232-
if(!service.isConnected())
233-
ProcessUtils.killProcess(service.getProcessID());
234-
pIDs.add(service.getProcessID());
235-
}
236-
}
237-
getProcessHistory().getProcessHistoryIndex().put("TMPProcess", Base64.getEncoder().encodeToString(ProcessHistory.convert(pIDs).getBytes(StandardCharsets.UTF_8)));
238-
getProcessHistory().getProcessHistoryIndex().refreshFile();
239-
}
240-
241-
}
242-
243-
244-
if(consoleReader.sReader != null){
245-
for (String key : ReaderHistory.getLines().keySet()) {
246-
/* History h = ConsoleReader.sReader.getHistory();
247-
ArrayList<String> l = new ArrayList<>();
248-
for (int j = 0; j < h.size()-1; j++) {
249-
l.add(h.get(j));
250-
}*/
251-
ArrayList<String> l = new ArrayList<>(ReaderHistory.getLines().get(key));
252-
253-
List<String> tail = l.subList(Math.max(l.size() - 15, 0), l.size());
254-
readerHistory.getReaderHistoryIndex().put(key, Base64.getEncoder().encodeToString(ReaderHistory.convert(tail).getBytes(StandardCharsets.UTF_8)));
255-
readerHistory.getReaderHistoryIndex().refreshFile();
256-
257-
}
258-
}
259-
isReady = true;
260-
261-
262-
Core.getInstance().getAddonsManager().getAddons().values().forEach(DreamExtension::stop);
263-
outputStream.println(Console.getFromLang("main.shutdown"));
264-
try {
265-
Thread.sleep(2000);
266-
} catch (InterruptedException e) {
267-
e.printStackTrace();
268-
}
269-
}else {
270-
outputStream.println(Console.getFromLang("main.shutdown"));
271-
try {
272-
Thread.sleep(2000);
273-
} catch (InterruptedException e) {
274-
e.printStackTrace();
275-
}
276-
}
277-
278-
279-
}catch (Exception e){
280-
System.out.println(e.getMessage());
281-
e.printStackTrace();
282-
}
224+
if(!disabling)
225+
Main.stop();
226+
// try {
227+
// disabling = true;
228+
// if(instance != null){
229+
// boolean isReady = false;
230+
// for(IExecutor jvmExecutor : instance.getJvmContainer().jvmExecutors){
231+
// if(!jvmExecutor.getServices().isEmpty()){
232+
// ArrayList<Long> pIDs = new ArrayList<>();
233+
// for(IService service : new ArrayList<>(jvmExecutor.getServices())){
234+
// if(!service.isConnected()){
235+
// service.kill();
236+
// }
237+
// if(service.getProcessID() != -1){
238+
// if(!service.isConnected())
239+
// ProcessUtils.killProcess(service.getProcessID());
240+
// pIDs.add(service.getProcessID());
241+
// }
242+
// }
243+
// getProcessHistory().getProcessHistoryIndex().put("TMPProcess", Base64.getEncoder().encodeToString(ProcessHistory.convert(pIDs).getBytes(StandardCharsets.UTF_8)));
244+
// getProcessHistory().getProcessHistoryIndex().refreshFile();
245+
// }
246+
//
247+
// }
248+
//
249+
//
250+
// if(consoleReader.sReader != null){
251+
// for (String key : ReaderHistory.getLines().keySet()) {
252+
// /* History h = ConsoleReader.sReader.getHistory();
253+
// ArrayList<String> l = new ArrayList<>();
254+
// for (int j = 0; j < h.size()-1; j++) {
255+
// l.add(h.get(j));
256+
// }*/
257+
// ArrayList<String> l = new ArrayList<>(ReaderHistory.getLines().get(key));
258+
//
259+
// List<String> tail = l.subList(Math.max(l.size() - 15, 0), l.size());
260+
// readerHistory.getReaderHistoryIndex().put(key, Base64.getEncoder().encodeToString(ReaderHistory.convert(tail).getBytes(StandardCharsets.UTF_8)));
261+
// readerHistory.getReaderHistoryIndex().refreshFile();
262+
//
263+
// }
264+
// }
265+
// isReady = true;
266+
//
267+
//
268+
// Core.getInstance().getAddonsManager().getAddons().values().forEach(DreamExtension::stop);
269+
// outputStream.println(Console.getFromLang("main.shutdown"));
270+
// try {
271+
// Thread.sleep(2000);
272+
// } catch (InterruptedException e) {
273+
// e.printStackTrace();
274+
// }
275+
// }else {
276+
// outputStream.println(Console.getFromLang("main.shutdown"));
277+
// try {
278+
// Thread.sleep(2000);
279+
// } catch (InterruptedException e) {
280+
// e.printStackTrace();
281+
// }
282+
// }
283+
//
284+
//
285+
// }catch (Exception e){
286+
// System.out.println(e.getMessage());
287+
// e.printStackTrace();
288+
// }
283289

284290
}
285291
});
@@ -313,7 +319,6 @@ public void run() {
313319
}
314320

315321

316-
317322
loadClient();
318323
}
319324

@@ -333,4 +338,82 @@ public static void loadClient(){
333338
Core.getInstance().init();
334339

335340
}
341+
342+
public static void stop(){
343+
try {
344+
disabling = true;
345+
if(!Config.isWindows()){
346+
String[] defSIGKILL = {"/bin/sh","-c","stty intr ^C </dev/tty"};
347+
try {
348+
Runtime.getRuntime().exec(defSIGKILL);
349+
} catch (IOException e) {
350+
throw new RuntimeException(e);
351+
}
352+
}
353+
if(instance != null){
354+
boolean isReady = false;
355+
for(IExecutor jvmExecutor : instance.getJvmContainer().jvmExecutors){
356+
if(!jvmExecutor.getServices().isEmpty()){
357+
ArrayList<Long> pIDs = new ArrayList<>();
358+
for(IService service : new ArrayList<>(jvmExecutor.getServices())){
359+
if(!service.isConnected()){
360+
service.kill();
361+
}
362+
if(service.getProcessID() != -1){
363+
if(!service.isConnected())
364+
ProcessUtils.killProcess(service.getProcessID());
365+
pIDs.add(service.getProcessID());
366+
}
367+
}
368+
getProcessHistory().getProcessHistoryIndex().put("TMPProcess", Base64.getEncoder().encodeToString(ProcessHistory.convert(pIDs).getBytes(StandardCharsets.UTF_8)));
369+
getProcessHistory().getProcessHistoryIndex().refreshFile();
370+
}
371+
372+
}
373+
374+
375+
if(consoleReader.sReader != null){
376+
for (String key : ReaderHistory.getLines().keySet()) {
377+
/* History h = ConsoleReader.sReader.getHistory();
378+
ArrayList<String> l = new ArrayList<>();
379+
for (int j = 0; j < h.size()-1; j++) {
380+
l.add(h.get(j));
381+
}*/
382+
ArrayList<String> l = new ArrayList<>(ReaderHistory.getLines().get(key));
383+
384+
List<String> tail = l.subList(Math.max(l.size() - 15, 0), l.size());
385+
readerHistory.getReaderHistoryIndex().put(key, Base64.getEncoder().encodeToString(ReaderHistory.convert(tail).getBytes(StandardCharsets.UTF_8)));
386+
readerHistory.getReaderHistoryIndex().refreshFile();
387+
388+
}
389+
}
390+
isReady = true;
391+
392+
393+
Core.getInstance().getAddonsManager().getAddons().values().forEach(DreamExtension::stop);
394+
PrintStream outputStream = Console.getFormatter().getDefaultStream();
395+
outputStream.println(Console.getFromLang("main.shutdown"));
396+
try {
397+
Thread.sleep(2000);
398+
} catch (InterruptedException e) {
399+
e.printStackTrace();
400+
}
401+
}else {
402+
PrintStream outputStream = Console.getFormatter().getDefaultStream();
403+
outputStream.println(Console.getFromLang("main.shutdown"));
404+
try {
405+
Thread.sleep(2000);
406+
} catch (InterruptedException e) {
407+
e.printStackTrace();
408+
}
409+
}
410+
411+
412+
}catch (Exception e){
413+
System.out.println(e.getMessage());
414+
e.printStackTrace();
415+
}
416+
417+
System.exit(0);
418+
}
336419
}

Core/src/main/java/be/alexandre01/dreamnetwork/core/UtilsAPI.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,9 @@ public IConfigManager getConfigManager() {
8080
public IConsoleManager getConsoleManager(){
8181
return consoleManager;
8282
}
83+
84+
@Override
85+
public void stop() {
86+
Main.stop();
87+
}
8388
}

Core/src/main/java/be/alexandre01/dreamnetwork/core/commands/lists/QuitCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import be.alexandre01.dreamnetwork.api.commands.sub.NodeBuilder;
55
import be.alexandre01.dreamnetwork.api.console.Console;
66
import be.alexandre01.dreamnetwork.api.console.colors.Colors;
7+
import be.alexandre01.dreamnetwork.core.Main;
78

89
import static be.alexandre01.dreamnetwork.api.console.jline.completors.CustomTreeCompleter.node;
910

@@ -18,7 +19,7 @@ public QuitCommand(String quit) {
1819
commandExecutor = new CommandExecutor() {
1920
@Override
2021
public boolean execute(String[] args) {
21-
System.exit(0);
22+
Main.stop();
2223
return true;
2324
}
2425
};

Core/src/main/java/be/alexandre01/dreamnetwork/core/connection/core/CoreMessageEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io.netty.channel.ChannelHandlerContext;
55
import io.netty.handler.codec.MessageToByteEncoder;
66

7-
public class CoreMessageEncoder extends MessageToByteEncoder {
7+
public class CoreMessageEncoder extends MessageToByteEncoder<Object> {
88
@Override
99
protected void encode(ChannelHandlerContext ctx, Object o, ByteBuf output) throws Exception {
1010
if(o instanceof byte[]){

0 commit comments

Comments
 (0)