Some bugfixes to make the client robust against crashes after deconnects

This commit is contained in:
Marc Froehlich
2024-02-06 23:56:04 +01:00
committed by praktimarc
parent be99925b62
commit de87c217f6
10 changed files with 171 additions and 31 deletions

View File

@@ -1 +1,2 @@
do5sa do5sa
##12390780900ß9'++++2e0NEY#####

View File

@@ -11,6 +11,8 @@ import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableStringValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import kst4contest.ApplicationConstants; import kst4contest.ApplicationConstants;
@@ -514,7 +516,6 @@ public class ChatController {
// this.category = ChatCategory.VUHF; // this.category = ChatCategory.VUHF;
this.userName = ownChatMemberObject.getName(); this.userName = ownChatMemberObject.getName();
// this.password = "uxskezcj";
this.hostname = "www.on4kst.info"; this.hostname = "www.on4kst.info";
this.port = port; this.port = port;
} }
@@ -522,11 +523,12 @@ public class ChatController {
/** /**
* This constructor is used by the Main()-Class of the praktiKST javaFX-gui. * This constructor is used by the Main()-Class of the praktiKST javaFX-gui.
* *
* @param setCategory *
* @param setOwnChatMemberObject * @param setOwnChatMemberObject
*/ */
public ChatController(ChatMember setOwnChatMemberObject) { public ChatController(ChatMember setOwnChatMemberObject) {
super(); super();
dbHandler = new DBController();
chatPreferences = new ChatPreferences(); chatPreferences = new ChatPreferences();
chatPreferences.readPreferencesFromXmlFile(); // set the praktikst Prefs by file or default if file is corrupted chatPreferences.readPreferencesFromXmlFile(); // set the praktikst Prefs by file or default if file is corrupted
@@ -610,6 +612,12 @@ public class ChatController {
public void execute() throws InterruptedException, IOException { public void execute() throws InterruptedException, IOException {
// messageBus = new SimpleStringProperty("_____est connection");
// ObservableStringValue test = new SimpleStringProperty("test");
// eventBus = test;
chatController = this; chatController = this;
// This block constructs a sample message // This block constructs a sample message
@@ -625,7 +633,7 @@ public class ChatController {
try { try {
setDisconnectionPerformedByUser(false); setDisconnectionPerformedByUser(false);
dbHandler = new DBController(); // dbHandler = new DBController(); //TODO: old place to instantiuate the dbcontroller
messageRXBus = new LinkedBlockingQueue<ChatMessage>(); messageRXBus = new LinkedBlockingQueue<ChatMessage>();
messageTXBus = new LinkedBlockingQueue<ChatMessage>(); messageTXBus = new LinkedBlockingQueue<ChatMessage>();

View File

@@ -29,8 +29,6 @@ public class DBController {
// private static final String DB_PATH = System.getProperty("praktiKST.db"); // private static final String DB_PATH = System.getProperty("praktiKST.db");
private static String DB_PATH = ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, DATABASE_FILE); private static String DB_PATH = ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, DATABASE_FILE);
/* /*
static { static {
try { try {

View File

@@ -11,11 +11,13 @@ import java.util.regex.Pattern;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import kst4contest.ApplicationConstants;
import kst4contest.model.AirPlaneReflectionInfo; import kst4contest.model.AirPlaneReflectionInfo;
import kst4contest.model.ChatMember; import kst4contest.model.ChatMember;
import kst4contest.model.ChatMessage; import kst4contest.model.ChatMessage;
import kst4contest.model.ClusterMessage; import kst4contest.model.ClusterMessage;
import kst4contest.utils.PlayAudioUtils; import kst4contest.utils.PlayAudioUtils;
import kst4contest.view.Kst4ContestApplication;
/** /**
* *
@@ -901,6 +903,10 @@ public class MessageBusManagementThread extends Thread {
client.getLst_toAllMessageList().add(pwErrorMsg); client.getLst_toAllMessageList().add(pwErrorMsg);
} }
// Kst4ContestApplication.alertWindowEvent("Password was wrong. Pse check!");
client.disconnect(ApplicationConstants.DISCSTRING_DISCONNECTONLY);
// this.client.disconnect(); // this.client.disconnect();
} }

View File

@@ -116,6 +116,11 @@ public class ReadUDPbyAirScoutMessageThread extends Thread {
if (received.contains(ApplicationConstants.DISCONNECT_RDR_POISONPILL)) { if (received.contains(ApplicationConstants.DISCONNECT_RDR_POISONPILL)) {
System.out.println("ReadUdpByASMsgTh, Info: got poison, now dieing...."); System.out.println("ReadUdpByASMsgTh, Info: got poison, now dieing....");
try {
terminateConnection();
} catch (Exception e) {
System.out.println("ASUDPRDR: catched error " + e.getMessage());
}
break; break;
} }
@@ -277,9 +282,13 @@ public class ReadUDPbyAirScoutMessageThread extends Thread {
return apInfo; return apInfo;
} }
public boolean terminateConnection() throws IOException { public boolean terminateConnection() {
this.socket.close(); try {
this.socket.close();
} catch (Exception e) {
System.out.println("udpbyas: catched " + e.getMessage());
}
return true; return true;
} }

View File

@@ -45,11 +45,11 @@ public class ReadUDPbyUCXMessageThread extends Thread {
try { try {
if (this.socket != null) { if (this.socket != null) {
System.out.println(">>>>>>>>>>>>>>ReadUdpbyUCS: closing socket"); System.out.println(">>>>>>>>>>>>>>ReadUdpbyUCS: closing socket");
this.socket.close(); terminateConnection();
} }
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); System.out.println("UCXUDPRDR: catched error " + e.getMessage());
} }
} }
@@ -97,11 +97,26 @@ public class ReadUDPbyUCXMessageThread extends Thread {
nE.printStackTrace(); nE.printStackTrace();
System.out.println("ReadUdpByUCXTH: Socket not ready"); System.out.println("ReadUdpByUCXTH: Socket not ready");
try { try {
socket = new DatagramSocket(12060); socket = new DatagramSocket(client.getChatPreferences().getLogsynch_ucxUDPWkdCallListenerPort());
socket.setSoTimeout(2000); socket.setSoTimeout(2000);
} catch (SocketException e) { } catch (SocketException e) {
throw new RuntimeException(e); System.out.println("[ReadUDPByUCSMsgTH, Error]: socket in use or something:");
e.printStackTrace();
try {
socket = new DatagramSocket(null);
socket.setReuseAddress(true);
socket.bind(new InetSocketAddress(client.getChatPreferences().getLogsynch_ucxUDPWkdCallListenerPort()));
socket.receive(packet);
socket.setSoTimeout(3000);
} catch (Exception ex) {
System.out.println("ReadUDPByUCXMsgTh: Could not solve that. Program Restart needed.");
throw new RuntimeException(ex);
}
} }
} }
@@ -112,16 +127,20 @@ public class ReadUDPbyUCXMessageThread extends Thread {
String received = new String(packet.getData(), packet.getOffset(), packet.getLength()); String received = new String(packet.getData(), packet.getOffset(), packet.getLength());
received = received.trim(); received = received.trim();
if (this.client.isDisconnectionPerformedByUser()) {
break;//TODO: what if it´s not the finally closage but a band channel change? // System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<recv " + received);
}
if (received.contains(ApplicationConstants.DISCONNECT_RDR_POISONPILL)) { if (received.contains(ApplicationConstants.DISCONNECT_RDR_POISONPILL)) {
System.out.println("ReadUdpByUCX, Info: got poison, now dieing...."); System.out.println("ReadUdpByUCX, Info: got poison, now dieing....");
socket.close();
timeOutIndicator = true; timeOutIndicator = true;
break; break;
} }
if (this.client.isDisconnectionPerformedByUser()) {
break;//TODO: what if it´s not the finally closage but a band channel change?
}
if (!timeOutIndicator) { if (!timeOutIndicator) {
processUCXUDPMessage(received); processUCXUDPMessage(received);
} else { } else {

View File

@@ -3,6 +3,9 @@
*/ */
package kst4contest.controller; package kst4contest.controller;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableStringValue;
import java.io.IOException; import java.io.IOException;
/** /**
@@ -20,6 +23,8 @@ public class StartChat {
System.out.println("[Startchat:] Starting new Chat instance"); System.out.println("[Startchat:] Starting new Chat instance");
// ObservableStringValue messageBus = new SimpleStringProperty("");
ChatController client = new ChatController(); ChatController client = new ChatController();
client.execute(); client.execute();

View File

@@ -130,13 +130,16 @@ public class ChatPreferences {
* Station preferences * Station preferences
*/ */
boolean loginAFKState = false; //always start as here
String loginCallSign = "do5amf"; String loginCallSign = "do5amf";
String loginPassword = ""; String loginPassword = "";
String loginName = "Marc"; String loginName = "Marc";
String loginLocator = "jn49fk"; String loginLocator = "jn49fk";
ChatCategory loginChatCategory = new ChatCategory(2); ChatCategory loginChatCategory = new ChatCategory(2);
IntegerProperty actualQTF = new SimpleIntegerProperty(360); // will be updated by user at runtime! IntegerProperty actualQTF = new SimpleIntegerProperty(360); // will be updated by user at runtime!
/** /**
* Log Synch preferences * Log Synch preferences
*/ */
@@ -206,6 +209,13 @@ public class ChatPreferences {
// } // }
public boolean isLoginAFKState() {
return loginAFKState;
}
public void setLoginAFKState(boolean loginAFKState) {
this.loginAFKState = loginAFKState;
}
public String getLoginCallSign() { public String getLoginCallSign() {
return loginCallSign; return loginCallSign;
@@ -303,7 +313,6 @@ public class ChatPreferences {
/** /**
* actualQTF, int, QTF in degrees * actualQTF, int, QTF in degrees
* *
* @param actualQTF, int, QTF in degrees
*/ */
public StringProperty getMYQRG() { public StringProperty getMYQRG() {

View File

@@ -5,10 +5,12 @@ import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.*; import java.util.*;
import javafx.beans.value.ObservableStringValue;
import javafx.scene.media.Media; import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaPlayer;
import kst4contest.ApplicationConstants; import kst4contest.ApplicationConstants;
import kst4contest.controller.ChatController; import kst4contest.controller.ChatController;
import kst4contest.controller.DBController;
import kst4contest.controller.Utils4KST; import kst4contest.controller.Utils4KST;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
@@ -74,6 +76,9 @@ import kst4contest.model.ClusterMessage;
public class Kst4ContestApplication extends Application { public class Kst4ContestApplication extends Application {
// private static final Kst4ContestApplication dbcontroller = new DBController();
String chatState; String chatState;
ChatController chatcontroller; ChatController chatcontroller;
@@ -1632,8 +1637,49 @@ public class Kst4ContestApplication extends Application {
fileMenu.getItems().add(m10); fileMenu.getItems().add(m10);
Menu optionsMenu = new Menu("Options"); Menu optionsMenu = new Menu("Options");
MenuItem options1 = new MenuItem("Set QRG as name in Chat"); menuItemOptionsSetFrequencyAsName = new MenuItem("Set QRG as name in Chat");
menuItemOptionsSetFrequencyAsName.setDisable(true);
menuItemOptionsSetFrequencyAsName.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
ChatMessage sendMe = new ChatMessage();
sendMe.setMessageDirectedToServer(false);
sendMe.setMessageText("/SETNAME " + chatcontroller.getChatPreferences().getMYQRG().getValue());
chatcontroller.getMessageTXBus().add(sendMe);
}
});
menuItemOptionsAwayBack = new MenuItem("Show me as away in chat");
MenuItem options10 = new MenuItem("Show options"); MenuItem options10 = new MenuItem("Show options");
menuItemOptionsAwayBack.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
ChatMessage sendMe = new ChatMessage();
sendMe.setMessageDirectedToServer(false);
if (chatcontroller.getChatPreferences().isLoginAFKState()) {
menuItemOptionsAwayBack.setText("Show me as AWAY FROM chat!");
chatcontroller.getChatPreferences().setLoginAFKState(false);
sendMe.setMessageText("/BACK");
} else {
menuItemOptionsAwayBack.setText("Show me as ACTIVE in chat!");
chatcontroller.getChatPreferences().setLoginAFKState(true);
sendMe.setMessageText("/AWAY");
}
chatcontroller.getMessageTXBus().add(sendMe);
}
});
options10.setOnAction(new EventHandler<ActionEvent>() { options10.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
if (settingsStage.isShowing()) { if (settingsStage.isShowing()) {
@@ -1644,7 +1690,7 @@ public class Kst4ContestApplication extends Application {
} }
}); });
optionsMenu.getItems().addAll(options1, options10); optionsMenu.getItems().addAll(menuItemOptionsSetFrequencyAsName, menuItemOptionsAwayBack, options10);
Menu macroMenu = new Menu("Macros"); Menu macroMenu = new Menu("Macros");
@@ -1782,7 +1828,11 @@ public class Kst4ContestApplication extends Application {
} }
// SimpleStringProperty messageBusOfChatCtrl = messageBus;
MenuItem menuItemFileDisconnect; MenuItem menuItemFileDisconnect;
MenuItem menuItemOptionsAwayBack;
MenuItem menuItemOptionsSetFrequencyAsName;
TextField txt_chatMessageUserInput = new TextField(); TextField txt_chatMessageUserInput = new TextField();
TextField txt_ownqrg = new TextField(); TextField txt_ownqrg = new TextField();
TextField txt_myQTF = new TextField(); TextField txt_myQTF = new TextField();
@@ -1795,6 +1845,8 @@ public class Kst4ContestApplication extends Application {
Stage settingsStage; Stage settingsStage;
/** /**
* Generates buttons out of pre made Strings, one button per given string in the * Generates buttons out of pre made Strings, one button per given string in the
* buttontext-array. Buttonclick will add the buttontext + " " to the * buttontext-array. Buttonclick will add the buttontext + " " to the
@@ -2217,10 +2269,6 @@ public class Kst4ContestApplication extends Application {
// ChatCategory category = new ChatCategory(0); //TODO: get the Category out of the preferences-object // ChatCategory category = new ChatCategory(0); //TODO: get the Category out of the preferences-object
ChatMember ownChatMemberObject = new ChatMember(); ChatMember ownChatMemberObject = new ChatMember();
// ownChatMemberObject.setCallSign("DM5M");
// ownChatMemberObject.setPassword("antennen");
// ownChatMemberObject.setName("QRO 15dBd");
// ownChatMemberObject.setQra("JO51IJ");
chatcontroller = new ChatController(ownChatMemberObject); // instantiate the Chatcontroller with the user object chatcontroller = new ChatController(ownChatMemberObject); // instantiate the Chatcontroller with the user object
@@ -2411,7 +2459,12 @@ public class Kst4ContestApplication extends Application {
} }
else { else {
chatState = "DISCONNECTED, CHECK YOUR INTERNET-CONNECTION!"; chatState = "DISCONNECTED!";
chatcontroller.getChatPreferences().setChatState(chatState);
}
if (chatcontroller.isDisconnected()) {
chatState = "DISCONNECTED!";
chatcontroller.getChatPreferences().setChatState(chatState);
} }
primaryStage.setTitle(chatcontroller.getChatPreferences().getChatState()); primaryStage.setTitle(chatcontroller.getChatPreferences().getChatState());
@@ -3499,20 +3552,24 @@ public class Kst4ContestApplication extends Application {
Button btnOptionspnlDisconnectOnly = new Button("Disconnect"); Button btnOptionspnlDisconnectOnly = new Button("Disconnect");
btnOptionspnlDisconnectOnly.setDisable(true); btnOptionspnlDisconnectOnly.setDisable(true);
menuItemFileDisconnect.setDisable(true); menuItemFileDisconnect.setDisable(true);
menuItemOptionsAwayBack.setDisable(true);
if (chatcontroller.isDisconnected()) { if (chatcontroller.isDisconnected()) {
btnOptionspnlDisconnectOnly.setDisable(true); btnOptionspnlDisconnectOnly.setDisable(true);
menuItemFileDisconnect.setDisable(true); menuItemFileDisconnect.setDisable(true);
menuItemOptionsAwayBack.setDisable(true);
} else if (chatcontroller.isConnectedAndNOTLoggedIn()) { } else if (chatcontroller.isConnectedAndNOTLoggedIn()) {
btnOptionspnlDisconnectOnly.setDisable(true); btnOptionspnlDisconnectOnly.setDisable(true);
menuItemFileDisconnect.setDisable(true); menuItemFileDisconnect.setDisable(true);
menuItemOptionsAwayBack.setDisable(true);
} }
else if (chatcontroller.isConnectedAndLoggedIn()) { else if (chatcontroller.isConnectedAndLoggedIn()) {
btnOptionspnlDisconnectOnly.setDisable(false); btnOptionspnlDisconnectOnly.setDisable(false);
menuItemFileDisconnect.setDisable(false); menuItemFileDisconnect.setDisable(false);
menuItemOptionsAwayBack.setDisable(false);
} }
btnOptionspnlDisconnectOnly.setOnAction(new EventHandler<ActionEvent>() { btnOptionspnlDisconnectOnly.setOnAction(new EventHandler<ActionEvent>() {
@@ -3530,7 +3587,8 @@ public class Kst4ContestApplication extends Application {
btnOptionspnlConnect.setDisable(false); btnOptionspnlConnect.setDisable(false);
btnOptionspnlDisconnect.setDisable(false); btnOptionspnlDisconnect.setDisable(false);
btnOptionspnlDisconnectOnly.setDisable(true); btnOptionspnlDisconnectOnly.setDisable(true);
menuItemOptionsSetFrequencyAsName.setDisable(true);
menuItemOptionsAwayBack.setDisable(true);
} }
}); });
@@ -3563,11 +3621,16 @@ public class Kst4ContestApplication extends Application {
+ choiceBxChatChategory.getSelectionModel().getSelectedItem()); + choiceBxChatChategory.getSelectionModel().getSelectedItem());
try { try {
chatcontroller.execute(); // TODO:THAT IS THE MAIN POINT WHERE THE CHAT WILL BE STARTED...MUST CATCH chatcontroller.execute(); // TODO:THAT IS THE MAIN POINT WHERE THE CHAT WILL BE STARTED...MUST CATCH
// Passwordfailedexc in future // Passwordfailedexc in future
btnOptionspnlDisconnectOnly.setDisable(false); btnOptionspnlDisconnectOnly.setDisable(false);
menuItemFileDisconnect.setDisable(false); menuItemFileDisconnect.setDisable(false);
menuItemOptionsAwayBack.setDisable(false);
menuItemOptionsSetFrequencyAsName.setDisable(false);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@@ -3585,7 +3648,8 @@ public class Kst4ContestApplication extends Application {
choiceBxChatChategory.setDisable(true); choiceBxChatChategory.setDisable(true);
btnOptionspnlConnect.setDisable(true); btnOptionspnlConnect.setDisable(true);
btnOptionspnlDisconnect.setDisable(false); btnOptionspnlDisconnect.setDisable(false);
chatcontroller.setConnectedAndLoggedIn(true);
chatcontroller.setDisconnected(false);
} }
}); });
@@ -3689,6 +3753,24 @@ public class Kst4ContestApplication extends Application {
// } // }
} }
/**
* Informs a user about a warning, shows given String in simple alertwindow
*
*/
public static void alertWindowEvent(String warning) {
System.out.println("Alert due to ... " + warning);
// if(storageModel.dataSetChanged()) { // if the dataset has changed, alert the user with a popup
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.getButtonTypes().remove(ButtonType.OK);
// alert.getButtonTypes().add(ButtonType.CANCEL);
// alert.getButtonTypes().add(ButtonType.YES);
alert.setTitle("WARNING");
alert.setContentText(String.format(warning));
}
public static void main(String[] args) { public static void main(String[] args) {
launch(args); launch(args);
} }

View File

@@ -3,3 +3,6 @@
DM5M;Marc;JN49FL;StringProperty [value: 144.243 ];true;true;false;false;false;false;false;false DM5M;Marc;JN49FL;StringProperty [value: 144.243 ];true;true;false;false;false;false;false;false
DM5M;Marc;JO51JL;StringProperty [value: null];true;true;false;false;false;false;false;false DM5M;Marc;JO51JL;StringProperty [value: null];true;true;false;false;false;false;false;false
DM5M;Marc;JO51JL;StringProperty [value: null];true;true;true;false;false;false;false;false DM5M;Marc;JO51JL;StringProperty [value: null];true;true;true;false;false;false;false;false
DM5M;unknown;unknown;StringProperty [value: null];true;true;false;false;false;false;false;false
DF0GEB;Marc;JO51IJ;StringProperty [value: 144.174 ];true;true;false;false;false;false;false;false
DF0GEB;Marc;JO51IJ;StringProperty [value: 144.174 ];true;true;true;false;false;false;false;false