Commit 02dbfc29 authored by Winfried Lötzsch's avatar Winfried Lötzsch

Merge branch 'javaDoccc' into 'master'

well know ports server config, added some javadoc



See merge request !17
parents ea5856c2 31199daa
package gone.lib.common;
/**
* Created by winfr on 27.09.2016.
* enum to store the different roles clients can have
*
* @author winfried
*/
public enum ClientRole {
Player,
......
package gone.lib.common;
/**
* Created by Winfried on 23.09.2016.
* constant strings we regularly use for the network communication
*
* @author Winfried
*/
public final class NetworkConstants {
public static final String STARTINGLINE = "--..--";
......
package gone.lib.common;
/**
* Created by matthias on 22.06.16.
* store the different possible rc standards
*
* @author matthias
*/
public enum RcStandard {
ICWS88,
......
......@@ -22,6 +22,17 @@ public class ClientConfig extends ConfigParameters {
/* constructor */
/**
* constructor
* @param width the width of the active window (ui)
* @param height the height of the active window (ui)
* @param warriorName the name of the warrior
* @param pathToRcFile the default path to the redcode file
* @param inetAddress the last used server address
* @param portLastServer the port that fits to that server address
* @param rcStandard the last used rc standard
* @param language the last used language
*/
public ClientConfig(int width, int height, String warriorName, String pathToRcFile,
InetAddress inetAddress, int portLastServer, RcStandard rcStandard,
Language language) {
......
package gone.lib.config;
/**
* parent class for server config and client config
*
* @author matthias
*/
public class ConfigParameters {
......
package gone.lib.config;
/**
* possible configuration types
*
* @author matthias
*/
public enum ConfigTypes {
......
......@@ -12,8 +12,9 @@ import java.util.prefs.InvalidPreferencesFormatException;
import java.util.prefs.Preferences;
/**
* loads the default / user config file
* loads the default/user config file (client, server)
* the config file is stored as a preferences file (xml key=value, utf8)
* xml dtd used: http://java.sun.com/dtd/preferences.dtd
*
* @author matthias
*/
......@@ -22,6 +23,10 @@ public class LoadConfigFile {
/* constructor */
/**
* empty constructor, because we set the ConfigParameters variable
* later via a call to either loadClientPrefs or loadServerPrefs
*/
public LoadConfigFile() {
this.configParameters = new ConfigParameters();
}
......@@ -35,14 +40,16 @@ public class LoadConfigFile {
/* class methods */
/**
* loads a config pref file, transfer it into a intern ClientConfig object
* loads a client config pref file, transfer it into a intern ClientConfig object
* @param defaultFilePath location of the default config file
* @param userFilePath location of the user config file
* @throws IOException if file not found
* @throws IllegalArgumentException
* @param configTypes type of the config to be loaded
* @throws IOException if the file is not found
* @throws InvalidPreferencesFormatException preferences are not formatted correct (xml dtd)
*/
public void loadClientPrefs(String defaultFilePath, String userFilePath, ConfigTypes configTypes)
throws IOException, IllegalArgumentException, InvalidPreferencesFormatException {
throws IOException, InvalidPreferencesFormatException {
String nodeName = configTypes.toString();
// create and load default prefs
......@@ -71,6 +78,13 @@ public class LoadConfigFile {
userPrefs.getInt("SERVER_PORT", 65500), rcStd, defLang);
}
/**
* loads a server config pref file, transfer it into a intern ClientConfig object
* @param path location of the config file
* @param configTypes type of the config to be loaded
* @throws IOException if the file is not found
* @throws InvalidPreferencesFormatException preferences are not formatted correct
*/
public void loadServerPrefs(String path, ConfigTypes configTypes)
throws IOException, InvalidPreferencesFormatException {
......
......@@ -11,7 +11,8 @@ import java.util.prefs.Preferences;
/**
* updates the user config file with new values
* the config file is stored as a key=value file, we use: java.util.Properties
* the config file is stored as a preferences file (xml key=value, utf8)
* xml dtd used: http://java.sun.com/dtd/preferences.dtd
*
* @author matthias
*/
......@@ -32,15 +33,15 @@ public class SaveConfigFile {
}
/**
* * transfer the config parameters to a property file and save this
* to our user config file
* @param params our object with the actual parameters
* @param userFilePath where the user config file is located (absolute path)
* @throws IllegalArgumentException
* @throws IOException
* transfer the config parameters to a preferences object and save this
* to the user config file
* @param params our client config object that stores the actual parameters
* @param userFilePath location to save the config file
* @param nodeName string representing the config type
* @throws IOException if file is not found
*/
private void saveClientConfig(ClientConfig params, String userFilePath, String nodeName)
throws IllegalArgumentException, IOException {
throws IOException {
if (userFilePath.isEmpty()) {
throw new IllegalArgumentException("user file path should not be empty!");
......@@ -78,6 +79,14 @@ public class SaveConfigFile {
out.close();
}
/**
* transfer the config parameters to a preferences object and save this
* to the user config file
* @param params our client config object that stores the actual parameters
* @param userFilePath location to save the config file
* @param nodeName string representing the config type
* @throws IOException if file is not found
*/
private void saveServerConfig(ServerConfig params, String userFilePath, String nodeName)
throws IOException {
......
......@@ -49,8 +49,9 @@ public class ServerConfig extends ConfigParameters {
}
public void setPort(int port) {
if (port < 0 || port > 65535) {
throw new IllegalArgumentException("port must be >= 0 && <= 65535");
// well know ports, tcp range
if (port < 1024 || port > 65535) {
throw new IllegalArgumentException("port must be >= 1024 && <= 65535");
}
this.port = port;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment