mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-03-30 04:31:04 +02:00
Some bugfixes to make the client robust against crashes after deconnects
This commit is contained in:
committed by
praktimarc
parent
be99925b62
commit
de87c217f6
@@ -1 +1,2 @@
|
||||
do5sa
|
||||
##12390780900ß9'++++2e0NEY#####
|
||||
@@ -11,6 +11,8 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.value.ObservableStringValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import kst4contest.ApplicationConstants;
|
||||
@@ -514,7 +516,6 @@ public class ChatController {
|
||||
|
||||
// this.category = ChatCategory.VUHF;
|
||||
this.userName = ownChatMemberObject.getName();
|
||||
// this.password = "uxskezcj";
|
||||
this.hostname = "www.on4kst.info";
|
||||
this.port = port;
|
||||
}
|
||||
@@ -522,11 +523,12 @@ public class ChatController {
|
||||
/**
|
||||
* This constructor is used by the Main()-Class of the praktiKST javaFX-gui.
|
||||
*
|
||||
* @param setCategory
|
||||
*
|
||||
* @param setOwnChatMemberObject
|
||||
*/
|
||||
public ChatController(ChatMember setOwnChatMemberObject) {
|
||||
super();
|
||||
dbHandler = new DBController();
|
||||
|
||||
chatPreferences = new ChatPreferences();
|
||||
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 {
|
||||
|
||||
// messageBus = new SimpleStringProperty("_____est connection");
|
||||
|
||||
// ObservableStringValue test = new SimpleStringProperty("test");
|
||||
|
||||
// eventBus = test;
|
||||
|
||||
chatController = this;
|
||||
|
||||
// This block constructs a sample message
|
||||
@@ -625,7 +633,7 @@ public class ChatController {
|
||||
try {
|
||||
setDisconnectionPerformedByUser(false);
|
||||
|
||||
dbHandler = new DBController();
|
||||
// dbHandler = new DBController(); //TODO: old place to instantiuate the dbcontroller
|
||||
|
||||
messageRXBus = new LinkedBlockingQueue<ChatMessage>();
|
||||
messageTXBus = new LinkedBlockingQueue<ChatMessage>();
|
||||
|
||||
@@ -29,8 +29,6 @@ public class DBController {
|
||||
// private static final String DB_PATH = System.getProperty("praktiKST.db");
|
||||
private static String DB_PATH = ApplicationFileUtils.getFilePath(ApplicationConstants.APPLICATION_NAME, DATABASE_FILE);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
static {
|
||||
try {
|
||||
|
||||
@@ -11,11 +11,13 @@ import java.util.regex.Pattern;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import kst4contest.ApplicationConstants;
|
||||
import kst4contest.model.AirPlaneReflectionInfo;
|
||||
import kst4contest.model.ChatMember;
|
||||
import kst4contest.model.ChatMessage;
|
||||
import kst4contest.model.ClusterMessage;
|
||||
import kst4contest.utils.PlayAudioUtils;
|
||||
import kst4contest.view.Kst4ContestApplication;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -901,6 +903,10 @@ public class MessageBusManagementThread extends Thread {
|
||||
client.getLst_toAllMessageList().add(pwErrorMsg);
|
||||
}
|
||||
|
||||
// Kst4ContestApplication.alertWindowEvent("Password was wrong. Pse check!");
|
||||
|
||||
client.disconnect(ApplicationConstants.DISCSTRING_DISCONNECTONLY);
|
||||
|
||||
// this.client.disconnect();
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,11 @@ public class ReadUDPbyAirScoutMessageThread extends Thread {
|
||||
|
||||
if (received.contains(ApplicationConstants.DISCONNECT_RDR_POISONPILL)) {
|
||||
System.out.println("ReadUdpByASMsgTh, Info: got poison, now dieing....");
|
||||
try {
|
||||
terminateConnection();
|
||||
} catch (Exception e) {
|
||||
System.out.println("ASUDPRDR: catched error " + e.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -277,9 +282,13 @@ public class ReadUDPbyAirScoutMessageThread extends Thread {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -45,11 +45,11 @@ public class ReadUDPbyUCXMessageThread extends Thread {
|
||||
try {
|
||||
if (this.socket != null) {
|
||||
System.out.println(">>>>>>>>>>>>>>ReadUdpbyUCS: closing socket");
|
||||
this.socket.close();
|
||||
terminateConnection();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 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();
|
||||
System.out.println("ReadUdpByUCXTH: Socket not ready");
|
||||
|
||||
|
||||
|
||||
try {
|
||||
socket = new DatagramSocket(12060);
|
||||
socket = new DatagramSocket(client.getChatPreferences().getLogsynch_ucxUDPWkdCallListenerPort());
|
||||
socket.setSoTimeout(2000);
|
||||
} 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());
|
||||
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)) {
|
||||
System.out.println("ReadUdpByUCX, Info: got poison, now dieing....");
|
||||
socket.close();
|
||||
timeOutIndicator = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.client.isDisconnectionPerformedByUser()) {
|
||||
break;//TODO: what if it´s not the finally closage but a band channel change?
|
||||
}
|
||||
|
||||
if (!timeOutIndicator) {
|
||||
processUCXUDPMessage(received);
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
*/
|
||||
package kst4contest.controller;
|
||||
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.value.ObservableStringValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -20,6 +23,8 @@ public class StartChat {
|
||||
|
||||
System.out.println("[Startchat:] Starting new Chat instance");
|
||||
|
||||
// ObservableStringValue messageBus = new SimpleStringProperty("");
|
||||
|
||||
ChatController client = new ChatController();
|
||||
client.execute();
|
||||
|
||||
|
||||
@@ -130,13 +130,16 @@ public class ChatPreferences {
|
||||
* Station preferences
|
||||
*/
|
||||
|
||||
boolean loginAFKState = false; //always start as here
|
||||
String loginCallSign = "do5amf";
|
||||
String loginPassword = "";
|
||||
String loginName = "Marc";
|
||||
String loginLocator = "jn49fk";
|
||||
|
||||
ChatCategory loginChatCategory = new ChatCategory(2);
|
||||
IntegerProperty actualQTF = new SimpleIntegerProperty(360); // will be updated by user at runtime!
|
||||
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return loginCallSign;
|
||||
@@ -303,7 +313,6 @@ public class ChatPreferences {
|
||||
/**
|
||||
* actualQTF, int, QTF in degrees
|
||||
*
|
||||
* @param actualQTF, int, QTF in degrees
|
||||
*/
|
||||
|
||||
public StringProperty getMYQRG() {
|
||||
|
||||
@@ -5,10 +5,12 @@ import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
|
||||
import javafx.beans.value.ObservableStringValue;
|
||||
import javafx.scene.media.Media;
|
||||
import javafx.scene.media.MediaPlayer;
|
||||
import kst4contest.ApplicationConstants;
|
||||
import kst4contest.controller.ChatController;
|
||||
import kst4contest.controller.DBController;
|
||||
import kst4contest.controller.Utils4KST;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
@@ -74,6 +76,9 @@ import kst4contest.model.ClusterMessage;
|
||||
|
||||
|
||||
public class Kst4ContestApplication extends Application {
|
||||
// private static final Kst4ContestApplication dbcontroller = new DBController();
|
||||
|
||||
|
||||
|
||||
String chatState;
|
||||
ChatController chatcontroller;
|
||||
@@ -1632,8 +1637,49 @@ public class Kst4ContestApplication extends Application {
|
||||
fileMenu.getItems().add(m10);
|
||||
|
||||
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");
|
||||
|
||||
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>() {
|
||||
public void handle(ActionEvent event) {
|
||||
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");
|
||||
|
||||
@@ -1782,7 +1828,11 @@ public class Kst4ContestApplication extends Application {
|
||||
|
||||
}
|
||||
|
||||
// SimpleStringProperty messageBusOfChatCtrl = messageBus;
|
||||
MenuItem menuItemFileDisconnect;
|
||||
MenuItem menuItemOptionsAwayBack;
|
||||
|
||||
MenuItem menuItemOptionsSetFrequencyAsName;
|
||||
TextField txt_chatMessageUserInput = new TextField();
|
||||
TextField txt_ownqrg = new TextField();
|
||||
TextField txt_myQTF = new TextField();
|
||||
@@ -1795,6 +1845,8 @@ public class Kst4ContestApplication extends Application {
|
||||
|
||||
Stage settingsStage;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generates buttons out of pre made Strings, one button per given string in 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
|
||||
|
||||
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
|
||||
|
||||
@@ -2411,7 +2459,12 @@ public class Kst4ContestApplication extends Application {
|
||||
}
|
||||
|
||||
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());
|
||||
@@ -3499,20 +3552,24 @@ public class Kst4ContestApplication extends Application {
|
||||
Button btnOptionspnlDisconnectOnly = new Button("Disconnect");
|
||||
btnOptionspnlDisconnectOnly.setDisable(true);
|
||||
menuItemFileDisconnect.setDisable(true);
|
||||
menuItemOptionsAwayBack.setDisable(true);
|
||||
|
||||
if (chatcontroller.isDisconnected()) {
|
||||
|
||||
btnOptionspnlDisconnectOnly.setDisable(true);
|
||||
menuItemFileDisconnect.setDisable(true);
|
||||
menuItemOptionsAwayBack.setDisable(true);
|
||||
|
||||
} else if (chatcontroller.isConnectedAndNOTLoggedIn()) {
|
||||
btnOptionspnlDisconnectOnly.setDisable(true);
|
||||
menuItemFileDisconnect.setDisable(true);
|
||||
menuItemOptionsAwayBack.setDisable(true);
|
||||
}
|
||||
|
||||
else if (chatcontroller.isConnectedAndLoggedIn()) {
|
||||
btnOptionspnlDisconnectOnly.setDisable(false);
|
||||
menuItemFileDisconnect.setDisable(false);
|
||||
menuItemOptionsAwayBack.setDisable(false);
|
||||
}
|
||||
|
||||
btnOptionspnlDisconnectOnly.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@@ -3530,7 +3587,8 @@ public class Kst4ContestApplication extends Application {
|
||||
btnOptionspnlConnect.setDisable(false);
|
||||
btnOptionspnlDisconnect.setDisable(false);
|
||||
btnOptionspnlDisconnectOnly.setDisable(true);
|
||||
|
||||
menuItemOptionsSetFrequencyAsName.setDisable(true);
|
||||
menuItemOptionsAwayBack.setDisable(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3563,11 +3621,16 @@ public class Kst4ContestApplication extends Application {
|
||||
+ choiceBxChatChategory.getSelectionModel().getSelectedItem());
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
chatcontroller.execute(); // TODO:THAT IS THE MAIN POINT WHERE THE CHAT WILL BE STARTED...MUST CATCH
|
||||
// Passwordfailedexc in future
|
||||
|
||||
btnOptionspnlDisconnectOnly.setDisable(false);
|
||||
menuItemFileDisconnect.setDisable(false);
|
||||
menuItemOptionsAwayBack.setDisable(false);
|
||||
menuItemOptionsSetFrequencyAsName.setDisable(false);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
@@ -3585,7 +3648,8 @@ public class Kst4ContestApplication extends Application {
|
||||
choiceBxChatChategory.setDisable(true);
|
||||
btnOptionspnlConnect.setDisable(true);
|
||||
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) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@@ -3,3 +3,6 @@
|
||||
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;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
|
||||
Reference in New Issue
Block a user