diff options
| author | 2020-05-03 21:06:38 +0100 | |
|---|---|---|
| committer | 2020-05-03 21:06:38 +0100 | |
| commit | 854f4d49407e45d67dd5754afd21a7e59970ca5b (patch) | |
| tree | 582e3245786f9723b5895b0c8d41087b0e6bb416 /src/main/java/cuchaz/enigma/gui/dialog | |
| parent | Rewrite search dialog (#233) (diff) | |
| download | enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.tar.gz enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.tar.xz enigma-fork-854f4d49407e45d67dd5754afd21a7e59970ca5b.zip | |
Multiplayer support (#221)
* First pass on multiplayer
* Apply review suggestions
* Dedicated Enigma server
* Don't jump to references when other users do stuff
* Better UI + translations
* french translation
* Apply review suggestions
* Document the protocol
* Fix most issues with scrolling.
* Apply review suggestions
* Fix zip hash issues + add a bit more logging
* Optimize zip hash
* Fix a couple of login bugs
* Add message log and user list
* Make Message an abstract class
* Make status bar work, add chat box
* Hide message log/users list when not connected
* Fix status bar not resetting entirely
* Run stop server task on server thread to prevent multithreading race conditions
* Add c2s message to packet id list
* Fix message scroll bar not scrolling to the end
* Formatting
* User list size -> ushort
* Combine contains and remove check
* Check removal before sending packet
* Add password to login packet
* Fix the GUI closing the rename text field when someone else renames something
* Update fr_fr.json
* oups
* Make connection/server create dialogs not useless if it fails once
* Refactor UI state updating
* Fix imports
* Fix Collab menu
* Fix NPE when rename not allowed
* Make the log file a configurable option
* Don't use modified UTF
* Update fr_fr.json
* Bump version to 0.15.4
* Apparently I can't spell neither words nor semantic versions
Co-authored-by: Yanis48 <doublecraft.official@gmail.com>
Co-authored-by: 2xsaiko <git@dblsaiko.net>
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/dialog')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/dialog/ConnectToServerDialog.java | 82 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/dialog/CreateServerDialog.java | 65 |
2 files changed, 147 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/ConnectToServerDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/ConnectToServerDialog.java new file mode 100644 index 0000000..c5f505c --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/dialog/ConnectToServerDialog.java | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | package cuchaz.enigma.gui.dialog; | ||
| 2 | |||
| 3 | import cuchaz.enigma.network.EnigmaServer; | ||
| 4 | import cuchaz.enigma.utils.I18n; | ||
| 5 | |||
| 6 | import javax.swing.*; | ||
| 7 | import java.awt.Frame; | ||
| 8 | |||
| 9 | public class ConnectToServerDialog { | ||
| 10 | |||
| 11 | public static Result show(Frame parentComponent) { | ||
| 12 | JTextField usernameField = new JTextField(System.getProperty("user.name"), 20); | ||
| 13 | JPanel usernameRow = new JPanel(); | ||
| 14 | usernameRow.add(new JLabel(I18n.translate("prompt.connect.username"))); | ||
| 15 | usernameRow.add(usernameField); | ||
| 16 | JTextField ipField = new JTextField(20); | ||
| 17 | JPanel ipRow = new JPanel(); | ||
| 18 | ipRow.add(new JLabel(I18n.translate("prompt.connect.ip"))); | ||
| 19 | ipRow.add(ipField); | ||
| 20 | JTextField portField = new JTextField(String.valueOf(EnigmaServer.DEFAULT_PORT), 10); | ||
| 21 | JPanel portRow = new JPanel(); | ||
| 22 | portRow.add(new JLabel(I18n.translate("prompt.port"))); | ||
| 23 | portRow.add(portField); | ||
| 24 | JPasswordField passwordField = new JPasswordField(20); | ||
| 25 | JPanel passwordRow = new JPanel(); | ||
| 26 | passwordRow.add(new JLabel(I18n.translate("prompt.password"))); | ||
| 27 | passwordRow.add(passwordField); | ||
| 28 | |||
| 29 | int response = JOptionPane.showConfirmDialog(parentComponent, new Object[]{usernameRow, ipRow, portRow, passwordRow}, I18n.translate("prompt.connect.title"), JOptionPane.OK_CANCEL_OPTION); | ||
| 30 | if (response != JOptionPane.OK_OPTION) { | ||
| 31 | return null; | ||
| 32 | } | ||
| 33 | |||
| 34 | String username = usernameField.getText(); | ||
| 35 | String ip = ipField.getText(); | ||
| 36 | int port; | ||
| 37 | try { | ||
| 38 | port = Integer.parseInt(portField.getText()); | ||
| 39 | } catch (NumberFormatException e) { | ||
| 40 | JOptionPane.showMessageDialog(parentComponent, I18n.translate("prompt.port.nan"), I18n.translate("prompt.connect.title"), JOptionPane.ERROR_MESSAGE); | ||
| 41 | return null; | ||
| 42 | } | ||
| 43 | if (port < 0 || port >= 65536) { | ||
| 44 | JOptionPane.showMessageDialog(parentComponent, I18n.translate("prompt.port.invalid"), I18n.translate("prompt.connect.title"), JOptionPane.ERROR_MESSAGE); | ||
| 45 | return null; | ||
| 46 | } | ||
| 47 | char[] password = passwordField.getPassword(); | ||
| 48 | |||
| 49 | return new Result(username, ip, port, password); | ||
| 50 | } | ||
| 51 | |||
| 52 | public static class Result { | ||
| 53 | private final String username; | ||
| 54 | private final String ip; | ||
| 55 | private final int port; | ||
| 56 | private final char[] password; | ||
| 57 | |||
| 58 | public Result(String username, String ip, int port, char[] password) { | ||
| 59 | this.username = username; | ||
| 60 | this.ip = ip; | ||
| 61 | this.port = port; | ||
| 62 | this.password = password; | ||
| 63 | } | ||
| 64 | |||
| 65 | public String getUsername() { | ||
| 66 | return username; | ||
| 67 | } | ||
| 68 | |||
| 69 | public String getIp() { | ||
| 70 | return ip; | ||
| 71 | } | ||
| 72 | |||
| 73 | public int getPort() { | ||
| 74 | return port; | ||
| 75 | } | ||
| 76 | |||
| 77 | public char[] getPassword() { | ||
| 78 | return password; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | } | ||
diff --git a/src/main/java/cuchaz/enigma/gui/dialog/CreateServerDialog.java b/src/main/java/cuchaz/enigma/gui/dialog/CreateServerDialog.java new file mode 100644 index 0000000..eea1dff --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/dialog/CreateServerDialog.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | package cuchaz.enigma.gui.dialog; | ||
| 2 | |||
| 3 | import cuchaz.enigma.network.EnigmaServer; | ||
| 4 | import cuchaz.enigma.utils.I18n; | ||
| 5 | |||
| 6 | import javax.swing.*; | ||
| 7 | import java.awt.*; | ||
| 8 | |||
| 9 | public class CreateServerDialog { | ||
| 10 | |||
| 11 | public static Result show(Frame parentComponent) { | ||
| 12 | JTextField portField = new JTextField(String.valueOf(EnigmaServer.DEFAULT_PORT), 10); | ||
| 13 | JPanel portRow = new JPanel(); | ||
| 14 | portRow.add(new JLabel(I18n.translate("prompt.port"))); | ||
| 15 | portRow.add(portField); | ||
| 16 | JPasswordField passwordField = new JPasswordField(20); | ||
| 17 | JPanel passwordRow = new JPanel(); | ||
| 18 | passwordRow.add(new JLabel(I18n.translate("prompt.password"))); | ||
| 19 | passwordRow.add(passwordField); | ||
| 20 | |||
| 21 | int response = JOptionPane.showConfirmDialog(parentComponent, new Object[]{portRow, passwordRow}, I18n.translate("prompt.create_server.title"), JOptionPane.OK_CANCEL_OPTION); | ||
| 22 | if (response != JOptionPane.OK_OPTION) { | ||
| 23 | return null; | ||
| 24 | } | ||
| 25 | |||
| 26 | int port; | ||
| 27 | try { | ||
| 28 | port = Integer.parseInt(portField.getText()); | ||
| 29 | } catch (NumberFormatException e) { | ||
| 30 | JOptionPane.showMessageDialog(parentComponent, I18n.translate("prompt.port.nan"), I18n.translate("prompt.create_server.title"), JOptionPane.ERROR_MESSAGE); | ||
| 31 | return null; | ||
| 32 | } | ||
| 33 | if (port < 0 || port >= 65536) { | ||
| 34 | JOptionPane.showMessageDialog(parentComponent, I18n.translate("prompt.port.invalid"), I18n.translate("prompt.create_server.title"), JOptionPane.ERROR_MESSAGE); | ||
| 35 | return null; | ||
| 36 | } | ||
| 37 | |||
| 38 | char[] password = passwordField.getPassword(); | ||
| 39 | if (password.length > EnigmaServer.MAX_PASSWORD_LENGTH) { | ||
| 40 | JOptionPane.showMessageDialog(parentComponent, I18n.translate("prompt.password.too_long"), I18n.translate("prompt.create_server.title"), JOptionPane.ERROR_MESSAGE); | ||
| 41 | return null; | ||
| 42 | } | ||
| 43 | |||
| 44 | return new Result(port, password); | ||
| 45 | } | ||
| 46 | |||
| 47 | public static class Result { | ||
| 48 | private final int port; | ||
| 49 | private final char[] password; | ||
| 50 | |||
| 51 | public Result(int port, char[] password) { | ||
| 52 | this.port = port; | ||
| 53 | this.password = password; | ||
| 54 | } | ||
| 55 | |||
| 56 | public int getPort() { | ||
| 57 | return port; | ||
| 58 | } | ||
| 59 | |||
| 60 | public char[] getPassword() { | ||
| 61 | return password; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | } | ||