Add Registration functionality and tidy up master
authorEddie <dev@fun2be.me>
Wed, 3 Jun 2015 12:06:53 +0000 (13:06 +0100)
committerEddie <dev@fun2be.me>
Wed, 3 Jun 2015 12:06:53 +0000 (13:06 +0100)
37 files changed:
WSYD_Members.serialized [deleted file]
nbproject/project.properties
src/uk/ac/ntu/n0521366/wsyd/Launcher.java [new file with mode: 0644]
src/uk/ac/ntu/n0521366/wsyd/client/ClientGUI.java
src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.form
src/uk/ac/ntu/n0521366/wsyd/client/EditProfile.java
src/uk/ac/ntu/n0521366/wsyd/client/Login.java
src/uk/ac/ntu/n0521366/wsyd/libs/WSYD_Member.java
src/uk/ac/ntu/n0521366/wsyd/libs/WSYD_Member_Comparator_UserID.java
src/uk/ac/ntu/n0521366/wsyd/libs/WSYD_Member_Comparator_UserName.java
src/uk/ac/ntu/n0521366/wsyd/libs/logging/PacketHandler.java
src/uk/ac/ntu/n0521366/wsyd/libs/logging/TableModelHandler.java
src/uk/ac/ntu/n0521366/wsyd/libs/message/MessageAbstract.java
src/uk/ac/ntu/n0521366/wsyd/libs/message/MessageLogRecord.java
src/uk/ac/ntu/n0521366/wsyd/libs/message/MessageLogin.java
src/uk/ac/ntu/n0521366/wsyd/libs/message/MessageMember.java [new file with mode: 0644]
src/uk/ac/ntu/n0521366/wsyd/libs/message/MessagePresence.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/Network.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkMessage.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkMessageEvent.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkMessageEventGenerator.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkMessageEventListener.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkMessageEventListenerManager.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkServerAbstract.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkServerTCP.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkServerUDP.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkServerUDPMulticast.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkStream.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/ServiceAddressMap.java
src/uk/ac/ntu/n0521366/wsyd/libs/net/WSYD_SocketAddress.java
src/uk/ac/ntu/n0521366/wsyd/management/ServerManagement.form
src/uk/ac/ntu/n0521366/wsyd/management/ServerManagement.java
src/uk/ac/ntu/n0521366/wsyd/server/ServerSocial.java
test/uk/ac/ntu/n0521366/wsyd/libs/WSYD_MemberTest.java
test/uk/ac/ntu/n0521366/wsyd/libs/WSYD_Member_Comparator_UserIDTest.java
test/uk/ac/ntu/n0521366/wsyd/libs/WSYD_Member_Comparator_UserNameTest.java
test/uk/ac/ntu/n0521366/wsyd/libs/net/WSYD_SocketAddressTest.java

diff --git a/WSYD_Members.serialized b/WSYD_Members.serialized
deleted file mode 100644 (file)
index 553c40c..0000000
Binary files a/WSYD_Members.serialized and /dev/null differ
index d0bb991..9cc87a4 100644 (file)
@@ -5,7 +5,7 @@ annotation.processing.run.all.processors=true
 annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
 application.desc=Social Networking and Chat client and server
 application.title=WSYD
-application.vendor=TJ <hacker@iam.tj>
+application.vendor=Eddie Berrisford-Lynch <dev@fun2be.me>
 auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
 build.classes.dir=${build.dir}/classes
 build.classes.excludes=**/*.java,**/*.form
@@ -70,7 +70,7 @@ jnlp.signed=false
 jnlp.signing=
 jnlp.signing.alias=
 jnlp.signing.keystore=
-main.class=
+main.class=uk.ac.ntu.n0521366.wsyd.Launcher
 # Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
 manifest.custom.codebase=
 # Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
diff --git a/src/uk/ac/ntu/n0521366/wsyd/Launcher.java b/src/uk/ac/ntu/n0521366/wsyd/Launcher.java
new file mode 100644 (file)
index 0000000..03b1293
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package uk.ac.ntu.n0521366.wsyd;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import uk.ac.ntu.n0521366.wsyd.server.ServerSocial;
+import uk.ac.ntu.n0521366.wsyd.management.ServerManagement;
+import uk.ac.ntu.n0521366.wsyd.client.ClientGUI;
+
+/**
+ *
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
+ */
+public class Launcher {
+    
+    static class App implements Runnable {
+
+        private final Class<?> _classRef;
+        private final String[] _args;
+
+        public App(Class<?> classRef, String[] args) {
+            _classRef = classRef;
+            _args = args;
+        }
+
+        @Override
+        public void run() {
+            try {
+                ClassLoader cl = _classRef.getClassLoader();
+                try {
+                    Object o = cl.loadClass(_classRef.getName()).newInstance();
+                    Class<?> newClass = o.getClass();
+                    Method m = newClass.getMethod("main", String[].class);
+                    m.invoke(null, (Object) this._args);
+                } catch (ClassNotFoundException ex) {
+                    Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+                } catch (InstantiationException ex) {
+                    Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+                }
+            } catch (NoSuchMethodException ex) {
+                Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+            } catch (SecurityException ex) {
+                Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+            } catch (IllegalAccessException ex) {
+                Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+            } catch (IllegalArgumentException ex) {
+                Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+            } catch (InvocationTargetException ex) {
+                Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex);
+            }
+
+        }
+    }
+    static ArrayList<App> apps;
+
+    public static void main(String[] args) {
+        
+        apps = new ArrayList<>();
+        
+        apps.add(new App(    ServerSocial.class, args));
+        apps.add(new App(ServerManagement.class, args));
+        for (int qty = 1; qty <= 1; qty++) {
+            apps.add(new App(ClientGUI.class, args));
+        }
+        
+        for (App app: apps) {
+            System.out.println("Starting app " + app._classRef.getTypeName());
+            new Thread(app).start();
+        }
+    }
+    
+}
index 06daa9c..8fe4601 100644 (file)
@@ -1,7 +1,25 @@
 /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
  */
 package uk.ac.ntu.n0521366.wsyd.client;
 
@@ -11,6 +29,7 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.SortedMap;
 import javax.swing.JDialog;
@@ -20,9 +39,11 @@ import java.util.TreeSet;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.JProgressBar;
+import javax.swing.ProgressMonitor;
 import javax.swing.Timer;
 import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
 import uk.ac.ntu.n0521366.wsyd.libs.message.MessageLogin;
+import uk.ac.ntu.n0521366.wsyd.libs.message.MessageMember;
 import uk.ac.ntu.n0521366.wsyd.libs.net.Network;
 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessage;
 import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessageEvent;
@@ -43,18 +64,24 @@ public class ClientGUI extends javax.swing.JFrame implements NetworkMessageEvent
     
     private boolean loginSuccessful = false;
     
-    private boolean regiSuccessful = false;
+    private boolean registrationSuccessful = false;
+    
+    private final Login loginDialog = new Login(this, true);
+    private final EditProfile registrationDialog = new EditProfile(this, true);
     
-    private Login login = new Login(this, true);
+    /**
+     * Member record for this client's user.
+     */
+    private WSYD_Member myMember;
     
     Socket socialSocket;
     
     /**
      * Readable/displayable name of this application
      * 
-     * Will be assigned userID when SocialServer connection established
+     * TODO: title should be assigned userID when SocialServer connection established
      */
-    private String _title = null;
+    private  String _title = null;
     
     /**
      * Network services to address map.
@@ -417,34 +444,32 @@ public class ClientGUI extends javax.swing.JFrame implements NetworkMessageEvent
     }
     
     private void connectionDialog() {
-        JProgressBar progressBar = new JProgressBar(0,100);
-        progressBar.setValue(0);
-        progressBar.setIndeterminate(true);
-        progressBar.setString("Waiting for Server...");
-        progressBar.setStringPainted(true);
-        System.err.println("Progress Bar created");
-        
-        while (!_serviceToAddressMap.containsService("ServerSocialMC")) { 
-        }
+        /* FIXME: progress monitor
+        ProgressMonitor pm = new ProgressMonitor(this, "Waiting for the Server...", "", 0, 10);
+        pm.setMillisToPopup(100);
+        pm.setProgress(1);
+        */
+        while (!_serviceToAddressMap.containsService("ServerSocialMC"));
+
+        // pm.setProgress(10);
         
         try {
             socialSocket = new Socket(_serviceToAddressMap.getServiceAddress("ServerSocialMC").getAddress(), Network.PORTS_SERVER_SOCIAL);
             NetworkStream newStream = new NetworkStream(socialSocket, _tcpStreamManager);
             _tcpStreamManager.addStream(NetworkStreamManager.SERVERSOCIAL, newStream);
+            newStream.getEventManager().addNetworkMessageEventListener(this);
         } catch (IOException ex) {
             //Logger.getLogger(ClientGUI.class.getName()).log(Level.SEVERE, null, ex);
             System.err.println("IOException in connectionDialog()");
         }
-        //progressBar.setIndeterminate(false);
-        //progressBar.setValue(100);
         loginDialog();
     }
     
     private void loginDialog()
     {
-        //WSYD_Login login = new Login(this, true);
-        login.setLocationRelativeTo(null);
-        login.setVisible(true);
+        //WSYD_Login loginDialog = new Login(this, true);
+        loginDialog.setLocationRelativeTo(null);
+        loginDialog.setVisible(true);
         if (loginSuccessful)
         {
             this.setLocationRelativeTo(null);
@@ -469,40 +494,36 @@ public class ClientGUI extends javax.swing.JFrame implements NetworkMessageEvent
             result = true;
         }
         else {
-            // TODO: wrap a login message with credentials
             NetworkMessage message = new NetworkMessage("Login", null, new MessageLogin(uName, pWord));
-            _tcpStreamManager._tcpStreams.get(NetworkStreamManager.SERVERSOCIAL).write(message);
-            // TODO: send login credentials to server for verification
-            result = true;
+            NetworkStream ns = _tcpStreamManager._tcpStreams.get(NetworkStreamManager.SERVERSOCIAL);
+            if (ns != null) {
+                ns.write(message);                
+                result = true;
+            }
+            else
+                System.err.println(" validateLogin(): do not know where ServerSocial is");
         }
         return result;
     }
     
-    public void regiProfileDialog()
+    public void registrationProfileDialog()
     {
-        EditProfile registration = new EditProfile(this, true);
-        registration.setLocationRelativeTo(null);
-        registration.setVisible(true);
-        if (regiSuccessful)
-        {
-            login.dispose();
-            this.setLocationRelativeTo(null);
-            this.setVisible(true);
-        }
+        registrationDialog.setLocationRelativeTo(null);
+        registrationDialog.setVisible(true);
     }
     
-    public boolean confirmRegistration(String uName, String pWord, String bPlace, String cLocation, TreeSet interests, String bio)
+    public void confirmRegistration(WSYD_Member registrationData)
     {
-        System.out.println(uName);
-        System.out.println(pWord);
-        System.out.println(bPlace);
-        System.out.println(cLocation);
-        
-        System.out.println(bio);
-        //TO DO: If server accepts registration return true
-        regiSuccessful = true;
-        return true;
-        //return false;
+        // TODO: confirmRegistration(): submit registrationDialog data to SocialServer
+        if (registrationData != null) {
+            NetworkMessage message = new NetworkMessage("Register", null, new MessageMember(registrationData));
+            NetworkStream ns = this._tcpStreamManager._tcpStreams.get(NetworkStreamManager.SERVERSOCIAL);
+            if (ns != null) {
+                ns.write(message);
+            }
+            else
+                System.err.println("confirmRegistration(): do not know where SocialServer is");
+        }
     }
     
     
@@ -579,7 +600,37 @@ public class ClientGUI extends javax.swing.JFrame implements NetworkMessageEvent
         NetworkMessage nm = event.getNetworkMessage();
         if (nm == null)
             return;
-        
         System.err.println(MessageFormat.format("Network Message received with intent {0} from sender {1}", nm.getIntent(), nm.getSender()));
+        switch (nm.getIntent()) {
+            case "Login":
+                MessageLogin ml = (MessageLogin) nm.getMessage();
+                if (ml != null) {
+                    this.loginSuccessful = ml._loggedIn;
+                    if (ml._loggedIn)
+                        this.loginDialog.dispose();
+                    else
+                        loginDialog.setUserName("Invalid Login: retry");
+                }
+                break;
+            case "Register":
+                MessageMember mm = (MessageMember) nm.getMessage();
+                if (mm != null) {
+                    if (mm.getRegistered() == MessageMember.STATE.REGISTERED) {
+                        this.myMember = mm.getMember();
+                        this.registrationSuccessful = true;
+                        // dismiss the dialogs and show client's main window
+                        registrationDialog.dispose();
+                        loginDialog.dispose();
+                        this.setTitle("WSYD logged in as " + this.myMember._userName);
+                        this.setLocationRelativeTo(null);
+                        this.setVisible(true);
+                    } else
+                        javax.swing.JOptionPane.showMessageDialog(registrationDialog, mm.getStatus(), "Registration failed", javax.swing.JOptionPane.ERROR_MESSAGE);
+                }
+                break;
+            default:
+                System.err.println(MessageFormat.format("Unhandled NetworkMessage received with intent {0} from sender {1}", nm.getIntent(), nm.getSender()));
+                
+        }
     }
 }
index c822c42..55dca98 100644 (file)
@@ -27,6 +27,9 @@
   <SubComponents>
     <Component class="javax.swing.JLabel" name="gLabelUsername">
       <Properties>
+        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="gFieldUsername"/>
+        </Property>
         <Property name="text" type="java.lang.String" value="Username:"/>
       </Properties>
       <Constraints>
@@ -65,6 +68,9 @@
     </Component>
     <Component class="javax.swing.JLabel" name="gLabelPassword">
       <Properties>
+        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="gPFieldPassword"/>
+        </Property>
         <Property name="text" type="java.lang.String" value="Password:"/>
       </Properties>
       <Constraints>
     </Component>
     <Component class="javax.swing.JLabel" name="gLabelPConfirmation">
       <Properties>
-        <Property name="text" type="java.lang.String" value="Confirm:"/>
+        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="gPFieldPConfirmation"/>
+        </Property>
+        <Property name="text" type="java.lang.String" value="Password:"/>
+        <Property name="toolTipText" type="java.lang.String" value="Repeat password"/>
       </Properties>
       <Constraints>
         <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
         </Constraint>
       </Constraints>
     </Component>
-    <Component class="javax.swing.JLabel" name="gLabelBirthplace">
+    <Component class="javax.swing.JLabel" name="gLabelBirthDate">
       <Properties>
-        <Property name="text" type="java.lang.String" value="Birthplace:"/>
+        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="gFieldBirthDate"/>
+        </Property>
+        <Property name="text" type="java.lang.String" value="Birth Date:"/>
       </Properties>
       <Constraints>
         <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
         </Constraint>
       </Constraints>
     </Component>
-    <Component class="javax.swing.JTextField" name="gFieldBirthplace">
+    <Component class="javax.swing.JTextField" name="gFieldBirthDate">
       <Properties>
+        <Property name="text" type="java.lang.String" value="YYYY-mm-dd"/>
         <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
           <Dimension value="[100, 25]"/>
         </Property>
         </Property>
       </Properties>
       <Events>
-        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="gFieldBirthplaceActionPerformed"/>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="gFieldBirthDateActionPerformed"/>
       </Events>
       <Constraints>
         <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
     </Component>
     <Component class="javax.swing.JLabel" name="gLabelCurrLocation">
       <Properties>
+        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="gLabelCurrLocation"/>
+        </Property>
         <Property name="text" type="java.lang.String" value="Current City/Town:"/>
       </Properties>
       <Constraints>
     </Component>
     <Component class="javax.swing.JLabel" name="gLabelInterests">
       <Properties>
+        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="gListInterests"/>
+        </Property>
         <Property name="text" type="java.lang.String" value="Interests:"/>
       </Properties>
       <Constraints>
       <SubComponents>
         <Component class="javax.swing.JList" name="gListInterests">
           <Properties>
-            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
-              <StringArray count="8">
-                <StringItem index="0" value="Item1"/>
-                <StringItem index="1" value="Item2"/>
-                <StringItem index="2" value="Item3"/>
-                <StringItem index="3" value="Item4"/>
-                <StringItem index="4" value="Item5"/>
-                <StringItem index="5" value="Item6"/>
-                <StringItem index="6" value="Item7"/>
-                <StringItem index="7" value="Item8"/>
-              </StringArray>
+            <Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
+              <Connection code="getInterestsListModel()" type="code"/>
             </Property>
             <Property name="toolTipText" type="java.lang.String" value="Select the interests you have, they will be displayed (Hold CTRL + Click)"/>
           </Properties>
     </Container>
     <Component class="javax.swing.JLabel" name="gLabelBio">
       <Properties>
-        <Property name="text" type="java.lang.String" value="Bio:"/>
+        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
+          <ComponentRef name="gTAreaBio"/>
+        </Property>
+        <Property name="text" type="java.lang.String" value="Biography:"/>
       </Properties>
       <Constraints>
         <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
         <CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
       </StatementProvider>
       <Parameters>
-        <CodeExpression id="51_gLabelBirthplace">
-          <CodeVariable name="gLabelBirthplace" type="8194" declaredType="javax.swing.JLabel"/>
+        <CodeExpression id="51_gLabelBirthDate">
+          <CodeVariable name="gLabelBirthDate" type="8194" declaredType="javax.swing.JLabel"/>
           <ExpressionOrigin>
             <ExpressionProvider type="ComponentRef">
-              <ComponentRef name="gLabelBirthplace"/>
+              <ComponentRef name="gLabelBirthDate"/>
             </ExpressionProvider>
           </ExpressionOrigin>
         </CodeExpression>
         <CodeMethod name="add" class="java.awt.Container" parameterTypes="java.awt.Component, java.lang.Object"/>
       </StatementProvider>
       <Parameters>
-        <CodeExpression id="55_gFieldBirthplace">
-          <CodeVariable name="gFieldBirthplace" type="8194" declaredType="javax.swing.JTextField"/>
+        <CodeExpression id="55_gFieldBirthDate">
+          <CodeVariable name="gFieldBirthDate" type="8194" declaredType="javax.swing.JTextField"/>
           <ExpressionOrigin>
             <ExpressionProvider type="ComponentRef">
-              <ComponentRef name="gFieldBirthplace"/>
+              <ComponentRef name="gFieldBirthDate"/>
             </ExpressionProvider>
           </ExpressionOrigin>
         </CodeExpression>
index de8b655..a30def6 100644 (file)
@@ -1,6 +1,38 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
 package uk.ac.ntu.n0521366.wsyd.client;
 
+import java.awt.Color;
+import java.lang.reflect.Array;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.TreeSet;
+import javax.swing.DefaultListModel;
+import javax.swing.JOptionPane;
+import javax.swing.ListModel;
+import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
 /*
  * To change this license header, choose License Headers in Project Properties.
  * To change this template file, choose Tools | Templates
@@ -21,6 +53,18 @@ public class EditProfile extends javax.swing.JDialog {
         initComponents();
     }
 
+    /**
+     *  Populate a model with the applications pre-defined interests.
+     * 
+     * @return the model
+     */
+    DefaultListModel getInterestsListModel() {
+        DefaultListModel<String> m = new DefaultListModel<>();
+        for (String i : WSYD_Member.Interests)
+            m.addElement(i);
+        System.err.println(m.toString());
+        return m;
+    }
     /**
      * This method is called from within the constructor to initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is always
@@ -39,8 +83,8 @@ public class EditProfile extends javax.swing.JDialog {
         gLabelPConfirmation = new javax.swing.JLabel();
         gPFieldPConfirmation = new javax.swing.JPasswordField();
         gLabelPWarning = new javax.swing.JLabel();
-        gLabelBirthplace = new javax.swing.JLabel();
-        gFieldBirthplace = new javax.swing.JTextField();
+        gLabelBirthDate = new javax.swing.JLabel();
+        gFieldBirthDate = new javax.swing.JTextField();
         gLabelCurrLocation = new javax.swing.JLabel();
         gFieldCurrLocation = new javax.swing.JTextField();
         gLabelInterests = new javax.swing.JLabel();
@@ -58,6 +102,7 @@ public class EditProfile extends javax.swing.JDialog {
         layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0};
         getContentPane().setLayout(layout);
 
+        gLabelUsername.setLabelFor(gFieldUsername);
         gLabelUsername.setText("Username:");
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 0;
@@ -84,6 +129,7 @@ public class EditProfile extends javax.swing.JDialog {
         gridBagConstraints.gridy = 0;
         getContentPane().add(gButtonConfirmation, gridBagConstraints);
 
+        gLabelPassword.setLabelFor(gPFieldPassword);
         gLabelPassword.setText("Password:");
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 0;
@@ -100,7 +146,9 @@ public class EditProfile extends javax.swing.JDialog {
         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
         getContentPane().add(gPFieldPassword, gridBagConstraints);
 
-        gLabelPConfirmation.setText("Confirm:");
+        gLabelPConfirmation.setLabelFor(gPFieldPConfirmation);
+        gLabelPConfirmation.setText("Password:");
+        gLabelPConfirmation.setToolTipText("Repeat password");
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 0;
         gridBagConstraints.gridy = 4;
@@ -121,25 +169,28 @@ public class EditProfile extends javax.swing.JDialog {
         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
         getContentPane().add(gLabelPWarning, gridBagConstraints);
 
-        gLabelBirthplace.setText("Birthplace:");
+        gLabelBirthDate.setLabelFor(gFieldBirthDate);
+        gLabelBirthDate.setText("Birth Date:");
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 0;
         gridBagConstraints.gridy = 6;
         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
-        getContentPane().add(gLabelBirthplace, gridBagConstraints);
+        getContentPane().add(gLabelBirthDate, gridBagConstraints);
 
-        gFieldBirthplace.setMinimumSize(new java.awt.Dimension(100, 25));
-        gFieldBirthplace.setPreferredSize(new java.awt.Dimension(200, 25));
-        gFieldBirthplace.addActionListener(new java.awt.event.ActionListener() {
+        gFieldBirthDate.setText("YYYY-mm-dd");
+        gFieldBirthDate.setMinimumSize(new java.awt.Dimension(100, 25));
+        gFieldBirthDate.setPreferredSize(new java.awt.Dimension(200, 25));
+        gFieldBirthDate.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
-                gFieldBirthplaceActionPerformed(evt);
+                gFieldBirthDateActionPerformed(evt);
             }
         });
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 2;
         gridBagConstraints.gridy = 6;
-        getContentPane().add(gFieldBirthplace, gridBagConstraints);
+        getContentPane().add(gFieldBirthDate, gridBagConstraints);
 
+        gLabelCurrLocation.setLabelFor(gLabelCurrLocation);
         gLabelCurrLocation.setText("Current City/Town:");
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 0;
@@ -154,6 +205,7 @@ public class EditProfile extends javax.swing.JDialog {
         gridBagConstraints.gridy = 8;
         getContentPane().add(gFieldCurrLocation, gridBagConstraints);
 
+        gLabelInterests.setLabelFor(gListInterests);
         gLabelInterests.setText("Interests:");
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 0;
@@ -161,11 +213,7 @@ public class EditProfile extends javax.swing.JDialog {
         gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
         getContentPane().add(gLabelInterests, gridBagConstraints);
 
-        gListInterests.setModel(new javax.swing.AbstractListModel() {
-            String[] strings = { "Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8" };
-            public int getSize() { return strings.length; }
-            public Object getElementAt(int i) { return strings[i]; }
-        });
+        gListInterests.setModel(getInterestsListModel());
         gListInterests.setToolTipText("Select the interests you have, they will be displayed (Hold CTRL + Click)");
         jScrollPane1.setViewportView(gListInterests);
 
@@ -175,7 +223,8 @@ public class EditProfile extends javax.swing.JDialog {
         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
         getContentPane().add(jScrollPane1, gridBagConstraints);
 
-        gLabelBio.setText("Bio:");
+        gLabelBio.setLabelFor(gTAreaBio);
+        gLabelBio.setText("Biography:");
         gridBagConstraints = new java.awt.GridBagConstraints();
         gridBagConstraints.gridx = 0;
         gridBagConstraints.gridy = 12;
@@ -201,25 +250,102 @@ public class EditProfile extends javax.swing.JDialog {
         pack();
     }// </editor-fold>//GEN-END:initComponents
 
-    private void gFieldBirthplaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldBirthplaceActionPerformed
+    private void gFieldBirthDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gFieldBirthDateActionPerformed
         // TODO add your handling code here:
-    }//GEN-LAST:event_gFieldBirthplaceActionPerformed
+    }//GEN-LAST:event_gFieldBirthDateActionPerformed
 
+    /**
+     * Verify the user-entered data before attempting to submit it to SocialServer.
+     * 
+     * Provides error feedback to the user in the form of a message dialog with a list of problems
+     * and sets the colour of field data to red if an error was found, or green otherwise.
+     * 
+     * @param evt
+     */
     private void gButtonConfirmationMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonConfirmationMouseClicked
         // TODO add your handling code here:
+        boolean dataGood = true; // assume user input is OK until errors found
+        ArrayList<String> errorMessages = new ArrayList<>();
+
+        String birthdateFormat = "YYYY-mm-dd";
+        SimpleDateFormat sd = new SimpleDateFormat(birthdateFormat);
+
+        WSYD_Member m = new WSYD_Member();
+
+        m._userName = this.gFieldUsername.getText();
+        if (m._userName.length() == 0) {
+            this.gFieldUsername.setForeground(Color.red);
+            errorMessages.add("Username cannot be empty");
+        }
+        else 
+            this.gFieldUsername.setForeground(Color.green);
+
+        if (Array.getLength(this.gPFieldPassword.getPassword()) == 0 || Array.getLength(this.gPFieldPConfirmation.getPassword()) == 0)  {
+            dataGood = false;
+            this.gPFieldPassword.setForeground(Color.red);
+            this.gPFieldPConfirmation.setForeground(Color.red);
+            errorMessages.add("Password cannot be empty");
+        } else if (!Arrays.equals(this.gPFieldPassword.getPassword(), this.gPFieldPConfirmation.getPassword())) {
+            dataGood = false;
+            this.gPFieldPassword.setForeground(Color.red);
+            this.gPFieldPConfirmation.setForeground(Color.red);
+            errorMessages.add("Passwords do not match");
+        } else {
+            this.gPFieldPassword.setForeground(Color.green);
+            this.gPFieldPConfirmation.setForeground(Color.green);            
+            m._password = new String(this.gPFieldPassword.getPassword());
+        }
+            
+        try {
+            m._birthDate = sd.parse(this.gFieldBirthDate.getText());
+            this.gFieldBirthDate.setForeground(Color.green);
+        } catch(java.text.ParseException e) {
+            dataGood = false;
+            this.gFieldBirthDate.setForeground(Color.red);
+            errorMessages.add("Birth Date format is " + birthdateFormat);
+        }
+
+        m._bio = this.gTAreaBio.getText();
+        m._currentLocation = this.gFieldCurrLocation.getText();
+
+        java.util.List<?> selectedInterests = this.gListInterests.getSelectedValuesList();
+        if (selectedInterests.isEmpty()) {
+            dataGood = false;
+            this.gListInterests.setForeground(Color.red);
+            errorMessages.add("Must select at least 1 interest");
+        } else
+            this.gListInterests.setForeground(Color.green);
+  
+        m._interests = new TreeSet<>();
+        m._interests.addAll(this.gListInterests.getSelectedValuesList());
+        if (!dataGood) {
+            DefaultListModel<String> errorModel = new DefaultListModel<>();
+            for (String s: errorMessages)
+                errorModel.addElement(s);
+            javax.swing.JList errorList = new javax.swing.JList();
+            errorList.setModel(errorModel);
+            JOptionPane.showMessageDialog(this, errorList, "Errors in Registration details", JOptionPane.ERROR_MESSAGE);
+        }
+        else {
+            // trigger sending of the data to SocialServer
+            ((ClientGUI)this.getOwner()).confirmRegistration(m);
+        }
+        // FIXME: gButtonConfirmationMouseClicked(): remove superceded code that has been commented out
+        /* 
         TreeSet<String> interests = null;
-        /*
+
         for (int i = 0; i < gListInterests.getModel().getSize(); i++)
         {
             interests.add(((String)gListInterests.getModel().getElementAt(i)));
-        }*/
+        }
         if (((ClientGUI)this.getOwner()).confirmRegistration(gFieldUsername.getText(),
                 new String(gPFieldPassword.getPassword()),
-                gFieldBirthplace.getText(),
+                gFieldBirthDate.getText(),
                 gFieldCurrLocation.getText(),
                 interests,
                 gTAreaBio.getText())) this.dispose();
         else gLabelPWarning.setText("Server failed to register. Retry.");
+        */
     }//GEN-LAST:event_gButtonConfirmationMouseClicked
 
     /**
@@ -267,11 +393,11 @@ public class EditProfile extends javax.swing.JDialog {
 
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JButton gButtonConfirmation;
-    private javax.swing.JTextField gFieldBirthplace;
+    private javax.swing.JTextField gFieldBirthDate;
     private javax.swing.JTextField gFieldCurrLocation;
     private javax.swing.JTextField gFieldUsername;
     private javax.swing.JLabel gLabelBio;
-    private javax.swing.JLabel gLabelBirthplace;
+    private javax.swing.JLabel gLabelBirthDate;
     private javax.swing.JLabel gLabelCurrLocation;
     private javax.swing.JLabel gLabelInterests;
     private javax.swing.JLabel gLabelPConfirmation;
index db417c1..27779e1 100644 (file)
@@ -1,7 +1,25 @@
 /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
+ * The MIT License
+ *
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
  */
 package uk.ac.ntu.n0521366.wsyd.client;
 
@@ -18,8 +36,13 @@ public class Login extends javax.swing.JDialog {
     public Login(java.awt.Frame parent, boolean modal) {
         super(parent, modal);
         initComponents();
+        this.getRootPane().setDefaultButton(gButtonLogin);
+             
+    }
+    public void setUserName(String newName) {
+        if (newName != null)
+        gFieldName.setText(newName);
     }
-
     /**
      * This method is called from within the constructor to initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is always
@@ -152,10 +175,14 @@ public class Login extends javax.swing.JDialog {
         // TODO add your handling code here:
     }//GEN-LAST:event_gFieldPasswordActionPerformed
 
+    /**
+     * Send the Username Password pair to the server to be validated.
+     * 
+     * @param evt 
+     */
     private void gButtonLoginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonLoginMouseClicked
         // TODO add your handling code here:
-        if (((ClientGUI)this.getOwner()).validateLogin(gFieldName.getText(), new String(gFieldPassword.getPassword()))); //this.dispose();
-        else gFieldName.setText("Invalid Login...");
+        ((ClientGUI)this.getOwner()).validateLogin(gFieldName.getText(), new String(gFieldPassword.getPassword()));
     }//GEN-LAST:event_gButtonLoginMouseClicked
 
     private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
@@ -169,7 +196,7 @@ public class Login extends javax.swing.JDialog {
 
     private void gButtonRegisterMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gButtonRegisterMouseClicked
         // TODO add your handling code here:
-        ((ClientGUI)this.getOwner()).regiProfileDialog();
+        ((ClientGUI)this.getOwner()).registrationProfileDialog();
     }//GEN-LAST:event_gButtonRegisterMouseClicked
 
     /**
index 621e147..7bd1acd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -25,6 +25,7 @@ package uk.ac.ntu.n0521366.wsyd.libs;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.TreeSet;
@@ -44,9 +45,15 @@ import java.util.logging.Level;
  * WSYD_Member_Comparator_UserID supports sorted Maps with userID as the sort key
  * WSYD_Member_Comparator_UserName supports sorted Sets and Collections with userName as the sort key
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_Member implements java.io.Serializable, java.lang.Comparable<WSYD_Member> {
+    
+    /**
+     * Choices for _interests
+     */
+    public static String[] Interests = {"Computers","Driving","DIY","Gardening","Games","Gym","Music","Reading" };
+    
     public long _userID;
     public String _userName;
     public String _password;
index bdcf4bf..e5a9d5b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +32,7 @@ import java.io.Serializable;
  * Implements serializable in order that the Collection using it doesn't cause 
  * deserialize Exceptions due to missing Comparator
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_Member_Comparator_UserID implements Comparator<Long>, Serializable {
     /**
index 2c31a06..db526a6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -32,7 +32,7 @@ import java.util.Comparator;
  * Implements serializable in order that the Collection using it doesn't cause 
  * deserialize Exceptions due to missing Comparator
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_Member_Comparator_UserName implements Comparator<WSYD_Member>, Serializable {
     /**
index b8a3da8..8bd688d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -40,7 +40,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessage;
  *
  * @see java.util.logging.Handler
  * @see uk.ac.ntu.n0521366.wsyd.libs.net.NetworkMessage
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class PacketHandler extends Handler {
 
index 6fea35a..fb48527 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +36,7 @@ import java.util.logging.Filter;
  * @see javax.swing.JScrollPane
  * @see javax.swing.JTable
  * @see javax.swing.table.DefaultTableModel
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class TableModelHandler extends Handler {
     
index 66530d8..54e5b2c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@ import java.net.InetAddress;
 /**
  * Base class of all Message types.
  * 
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public abstract class MessageAbstract implements Serializable {
     /**
@@ -38,18 +38,5 @@ public abstract class MessageAbstract implements Serializable {
      * @return E.g. "LogRecord", "FriendOnline", "ChatRequest"
      */
     public abstract String getMessageType();
-    
-    /**
-     * IP address of the sending host.
-     * 
-     * This should be set by the <em>receiving service</em> using the value obtained from
-     * the packet or connection the message arrived in.
-     * 
-     * FIXME: sourceAddress: is this really needed? the message encapsulated in a NetworkMessage already
-     */
-    public InetAddress sourceAddress;
-    
-    public MessageAbstract() {
-        sourceAddress = null;
-    }
+        
 }
index 485b879..74cc642 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@ import java.util.logging.LogRecord;
  * A specialised message containing a LogRecord
  * 
  * @see java.util.logging.LogRecord
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class MessageLogRecord extends MessageAbstract {
     private static final String _type = "LogRecord";
index 608bc89..6c58f52 100644 (file)
  */
 package uk.ac.ntu.n0521366.wsyd.libs.message;
 
+import java.io.Serializable;
+
 /**
  * Message used to authenticate a login with the SocialServer.
  *
  * @author eddie
  */
-public class MessageLogin extends MessageAbstract {
+public class MessageLogin extends MessageAbstract implements Serializable {
     
+    /**
+     * Message type.
+     */
     private static final String _type = "Login";
     
+    /**
+     * A Username.
+     */
     public final String _uName;
     
+    /**
+     * A password.
+     */
     public final String _uPass;
     
+    /**
+     * After login the user's ID.
+     */
     public long _userID = 0;
     
+    /**
+     * Result of a login request.
+     */
     public boolean _loggedIn = false;
     
+    /**
+     * Make the Message printable.
+     * 
+     * @return human readable text
+     */
+    public String toString() {
+        return new String("_uName:" + _uName + 
+                          ",_uPass:" + _uPass +
+                          ",_userID:" + _userID +
+                          ",_loggedIn:" + _loggedIn
+        );
+    }
+    
+    /** 
+     *  The Message Class type.
+     * 
+     * @return Message type
+     */
     public static String getType() {
         return _type;
     }
@@ -54,9 +89,14 @@ public class MessageLogin extends MessageAbstract {
         this._uPass = null;
     }
     
+    /**
+     * Construct with a Username Password pair.
+     * 
+     * @param uName Username
+     * @param uPass Password
+     */
     public MessageLogin (String uName, String uPass) {
         this._uName = uName;
         this._uPass = uPass;
-    }
-    
+    }  
 }
diff --git a/src/uk/ac/ntu/n0521366/wsyd/libs/message/MessageMember.java b/src/uk/ac/ntu/n0521366/wsyd/libs/message/MessageMember.java
new file mode 100644 (file)
index 0000000..c04648c
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * The MIT License
+ *
+ * Copyright 2015 TJ <hacker@iam.tj>.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package uk.ac.ntu.n0521366.wsyd.libs.message;
+
+import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
+
+/**
+ * A specialised message containing a WSYD_Member.
+ * 
+ * @author TJ <hacker@iam.tj>
+ */
+public class MessageMember extends MessageAbstract {
+
+    public static enum STATE {UNREGISTERED, REGISTERED};
+    private static final String _type = "WSYD_Member";
+    
+    private WSYD_Member _member;
+    private STATE _registered;
+    private String _status;
+    
+    public static String getType() {
+        return _type;
+    }
+
+    @Override
+    public String getMessageType() {
+        return _type;
+    }
+    
+    public MessageMember(WSYD_Member member, STATE registered, String status) {
+        _member = member;
+        _registered = registered;
+        _status = status;
+    }
+    
+    public MessageMember(WSYD_Member member) {
+        this(member, STATE.UNREGISTERED, null);
+    }
+    
+    public MessageMember() {
+        this(null, STATE.UNREGISTERED, null);
+    }
+    
+    /**
+     * Get the Member contained in this message.
+     * 
+     * @return 
+     */
+    public WSYD_Member getMember() {
+        return _member;
+    }
+        
+    /**
+     * Current registration state of the member record contained in this message.
+     * 
+     * @return
+     */
+    public STATE getRegistered() {
+        return _registered;
+    }
+
+    /**
+     * Update the registration state of the member record contained in this message.
+     * 
+     * @param registered 
+     */
+    public void setRegistered(STATE registered) {
+        _registered = registered;
+    }
+    
+    /**
+     * Get registration status message.
+     * 
+     * @return 
+     */
+    public String getStatus() {
+        return _status;
+    }
+    
+    /**
+     * Set registration status message.
+     * 
+     * ServerSocial may set this with text describing why a registration failed.
+     * @param status 
+     */
+    public void setStatus(String status) {
+        _status = status;
+    }
+}
\ No newline at end of file
index 2c6143e..0f2cb37 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +27,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.net.WSYD_SocketAddress;
 
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class MessagePresence extends MessageAbstract {
     private static final String _type = "Presence";
index 0f02897..c899501 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,7 @@ import java.net.UnknownHostException;
 
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class Network {
     public static final int PORTS_SERVER_SOCIAL = 50000;
index a513e72..dac7c9b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -35,7 +35,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.message.MessageAbstract;
  * Wraps an object and intent label together for passing over a network.
  * 
  * @see NetworkMessageEvent
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class NetworkMessage implements Serializable, Cloneable {
     /**
@@ -64,7 +64,7 @@ public class NetworkMessage implements Serializable, Cloneable {
      */
     long _key;
 
-    Class<?> _class;
+    // Class<?> _class;
     MessageAbstract _message;
     
     /**
@@ -75,10 +75,24 @@ public class NetworkMessage implements Serializable, Cloneable {
         _intent = null;
         _serviceSender = null;
         _serviceTarget = null;
-        _class = null;
+        // _class = null;
         _message = null;
     }
     
+    /**
+     * Make the NetworkMessage printable.
+     * 
+     * @return human readable text
+     */
+    @Override
+    public String toString() {
+        return new String("_serializedLength:" + _serializeLength + 
+                          ",_intent:" + _intent +
+                          ",_serviceSender:" + _serviceSender +
+                          ",_serviceTarget:" + _serviceTarget +
+                          ",_message:" + _message.toString()
+                          );
+    }
     /**
      * Create a message for passing over the network.
      * 
@@ -98,7 +112,7 @@ public class NetworkMessage implements Serializable, Cloneable {
         _serviceSender = null;
         _serviceTarget = target;
         _message = message;
-        _class = _message.getClass();
+        // _class = _message.getClass();
     }
     
     /**
index 7aae560..7d36958 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj.
+ * Copyright 2015 Eddie Berrisfor-Lynch <dev@fun2be.me>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -30,7 +30,7 @@ import java.util.EventObject;
  * 
  * @see NetworkMessageEventGenerator
  * @see NetworkMessageEventListener
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class NetworkMessageEvent extends EventObject {
     /**
index 66ed1c2..3a7c762 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -30,7 +30,7 @@ package uk.ac.ntu.n0521366.wsyd.libs.net;
  * @see NetworkMessageEvent
  * @see NetworkMessageEventListener
  * @see NetworkMessageEventListenerManager
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public interface NetworkMessageEventGenerator {
     /**
index 72508b2..dda2718 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -29,7 +29,7 @@ package uk.ac.ntu.n0521366.wsyd.libs.net;
  * @see NetworkMessage
  * @see NetworkMessageEvent
  * @see NetworkMessageEventGenerator
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public interface NetworkMessageEventListener {
     public void NetworkMessageReceived(NetworkMessageEvent event);
index 7c18a2c..885ced8 100644 (file)
@@ -99,7 +99,8 @@ public class NetworkMessageEventListenerManager implements NetworkMessageEventGe
     public synchronized void fireNetworkMessageEvent(NetworkMessage message) {
         NetworkMessageEvent event = new NetworkMessageEvent(this, message);
         for (NetworkMessageEventListenerWithIntent intentListener : _NetworkMessageEventListeners) {
-            if (intentListener._intent.equals(message._intent) || intentListener._intent == null)
+            System.err.println("fireNetworkMessageEvent() intent: " + intentListener._intent);
+            if (intentListener._intent == null ||  (intentListener._intent != null && intentListener._intent.equals(message._intent)))
                 intentListener._listener.NetworkMessageReceived(event);
         }
     }
index 3a866df..9dd6445 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -63,7 +63,7 @@ import javax.swing.SwingWorker;
  * 
  * @see javax.swing.SwingWorker
  * 
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public abstract class NetworkServerAbstract extends SwingWorker<Integer, NetworkMessage> {
 
index e68987f..fc1744b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.message.MessageNetworkStream;
  * or in a Swing GUI application as a background worker thread.
  *
  * @see NetworkServerAbstract
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class NetworkServerTCP extends NetworkServerAbstract {
     
index fda95b5..5763d54 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -42,7 +42,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.message.MessageLogRecord;
  * or in a Swing GUI application as a background worker thread.
  *
  * @see NetworkServerAbstract
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class NetworkServerUDP extends NetworkServerAbstract {
     /**
index 4f8bf03..fe008aa 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -34,7 +34,7 @@ import java.util.Enumeration;
 
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class NetworkServerUDPMulticast extends NetworkServerUDP {
     
index 48da1b7..d451e89 100644 (file)
@@ -89,8 +89,12 @@ public class NetworkStream extends SwingWorker<Boolean, NetworkMessage> {
         boolean expectingLong = true;
         
         while (!this.isCancelled()) {
-            
             // check for incoming message
+            if (_socketIS.available() > 0) {
+                System.err.println(" reading Object from stream, bytes available: " + _socketIS.available());
+                read();
+            }
+            /*
             if (_ois.available() >= expectedLength) {
                 if (expectingLong == true) {                  
                     expectedLength = _ois.readLong();
@@ -105,6 +109,7 @@ public class NetworkStream extends SwingWorker<Boolean, NetworkMessage> {
                     expectingLong = true;
                 }
             }
+            */
             // send a queued message
             NetworkMessage temp = this.sendMessage();
             if (temp != null) {
@@ -140,12 +145,10 @@ public class NetworkStream extends SwingWorker<Boolean, NetworkMessage> {
             try {             
                 _oos.writeObject(message);
                 _oos.flush();
-                long messageSize = _baos.size();
-                _socketOS.writeLong(messageSize);
-                System.err.println(" bytes to write: " + messageSize);
-                _baos.writeTo(_socketOS);
+                Long messageSize = new Long(_baos.size());
+                _socketOS.writeObject(message);
                 _socketOS.flush();
-                System.err.println("baos.size()=" + _baos.size());
+                System.err.println(" bytes written: " + messageSize);
                 
                 result = true;
                 
@@ -169,17 +172,17 @@ public class NetworkStream extends SwingWorker<Boolean, NetworkMessage> {
         
         try {
             NetworkMessage message = null;
+            String s = null;
 
-            try {
-                message = (NetworkMessage)_ois.readObject();
-            } catch (java.io.OptionalDataException ex) {
-                System.err.println("Length: " + ex.length + " EOF: " + ex.eof);
-                ex.printStackTrace();
-            }
+            message = (NetworkMessage)_ois.readObject();
+            System.err.println(" received: " + message.toString());
             message.setKey(_key);
             publish(message);
             
             result = true;
+        } catch (java.io.OptionalDataException ex) {
+            System.err.println("Length: " + ex.length + " EOF: " + ex.eof);
+            ex.printStackTrace();
         } catch (IOException ex) {
             Logger.getLogger(NetworkStream.class.getName()).log(Level.SEVERE, null, ex);
             // FIXME: Replace logger
index 80e825f..5a1e1f6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iamtj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,8 @@ import java.util.logging.Logger;
 /**
  * Maps service names on hosts to  an InetAddress:Port pair.
  * 
- * @author TJ <hacker@iamtj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
+
  */
 public class ServiceAddressMap {
     /**
index e66d60a..d818632 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -43,7 +43,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.net.Network;
  * 
  * Serializable to allow passing between separate local and remote processes
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_SocketAddress implements java.io.Serializable {
     Boolean _multicast;
index 3d3ba16..fd295d9 100644 (file)
@@ -28,7 +28,7 @@
             <Property name="editable" type="boolean" value="false"/>
             <Property name="columns" type="int" value="20"/>
             <Property name="rows" type="int" value="5"/>
-            <Property name="text" type="java.lang.String" value="Server Management client&#xa;&#xa9; Copyright 2015 TJ &lt;hacker@iam.tj&gt;&#xa;&#xa;&lt;&lt;&lt; Click on the mug to learn more!&#xa;&#xa;I will disappear in 20 seconds.&#xa;&#xa;"/>
+            <Property name="text" type="java.lang.String" value="Server Management client&#xa;&#xa9; Copyright 2015 Eddie Berrisford-Lynch &lt;dev@fun2be.me&gt;&#xa;&#xa;&lt;&lt;&lt; Click on the mug to learn more!&#xa;&#xa;I will disappear in 20 seconds.&#xa;&#xa;"/>
             <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
               <Border info="null"/>
             </Property>
index 6f82236..cafcc64 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -56,7 +56,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.net.*;
 import uk.ac.ntu.n0521366.wsyd.libs.net.ServiceAddressMap.LastSeenHost;
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class ServerManagement extends javax.swing.JFrame implements NetworkMessageEventListener, Filter {
     /**
@@ -347,7 +347,7 @@ public class ServerManagement extends javax.swing.JFrame implements NetworkMessa
         gTextAreaAbout.setEditable(false);
         gTextAreaAbout.setColumns(20);
         gTextAreaAbout.setRows(5);
-        gTextAreaAbout.setText("Server Management client\n© Copyright 2015 TJ <hacker@iam.tj>\n\n<<< Click on the mug to learn more!\n\nI will disappear in 20 seconds.\n\n");
+        gTextAreaAbout.setText("Server Management client\n© Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>\n\n<<< Click on the mug to learn more!\n\nI will disappear in 20 seconds.\n\n");
         gTextAreaAbout.setBorder(null);
         gDialogAbout.getContentPane().add(gTextAreaAbout);
         gTextAreaAbout.setBounds(310, 30, 270, 200);
index 45c5412..639c482 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * The MIT License
  *
- * Copyright 2015 TJ <hacker@iam.tj>.
+ * Copyright 2015 Eddie Berrisford-Lynch <dev@fun2be.me>.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -57,6 +57,7 @@ import javax.swing.Timer;
 import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member;
 import uk.ac.ntu.n0521366.wsyd.libs.WSYD_Member_Comparator_UserID;
 import uk.ac.ntu.n0521366.wsyd.libs.message.MessageLogin;
+import uk.ac.ntu.n0521366.wsyd.libs.message.MessageMember;
 import uk.ac.ntu.n0521366.wsyd.libs.message.MessageMemberState;
 import uk.ac.ntu.n0521366.wsyd.libs.message.MessagePresence;
 import uk.ac.ntu.n0521366.wsyd.libs.message.MessageServerControl;
@@ -83,7 +84,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.net.ServiceAddressMap.LastSeenHost;
  * exitRequested and restartRequested. This can be done by an optional
  * Management GUI application.
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public final class ServerSocial implements NetworkMessageEventListener, ConnectionEstablishedEventListener {
     /**
@@ -441,19 +442,47 @@ public final class ServerSocial implements NetworkMessageEventListener, Connecti
         return result;
     }
     
+    private void notifyMemberPrescence(long userID, boolean state) {
+        NetworkMessage message = new NetworkMessage("MemberNotification", null, new MessageMemberState(userID, state));
+        for (long ID : _membersOnline) {
+            _tcpStreamManager._tcpStreams.get(ID).write(message);
+        }
+    }
+    
+    private void memberOnline (long userID) {
+        if (!_membersOnline.contains(userID)) {
+            notifyMemberPrescence(userID, true);
+            _membersOnline.add(userID);
+        }
+    }
+    
+    private void memberOffline (long userID) {
+        if (_membersOnline.contains(userID)) {
+            _membersOnline.remove(userID);
+            notifyMemberPrescence(userID, false);
+        }
+    }
+
+    @Override
+    public void connectionEstablished(ConnectionEstablishedEvent event) {
+        System.err.println("connectionEstablished()");
+        event.getStream().getEventManager().addNetworkMessageEventListener(this);
+    }
+    /**
+     * Process received network messages.
+     * 
+     * @param event the network message event
+     */
     @Override
     public void NetworkMessageReceived(NetworkMessageEvent event)
     {
-        System.err.println("NetworkMessage received");
-        //TODO: NetworkMessageReceived: Handle Messages
         NetworkMessage nm = event.getNetworkMessage();
         if (nm == null)
             return;
-        //Exit or Restart?
-        System.err.println("Packet Received for intent " + nm.getIntent());
+        System.err.println("NetworkMessage received for intent " + nm.getIntent());
         String type = nm.getMessage().getMessageType();
         switch (nm.getIntent()) {
-            case "Control":
+            case "Control": // Exit or Restart?
                 if (type.equals(MessageServerControl.getType())) { // ServerControl
                     if ("ServerManagement".equals(nm.getSender())) {
                         MessageServerControl mp = (MessageServerControl)nm.getMessage();
@@ -464,6 +493,7 @@ public final class ServerSocial implements NetworkMessageEventListener, Connecti
                 break;
             case "Login":
                 if (type.equals(MessageLogin.getType())) {
+                    NetworkStream ns = _tcpStreamManager._tcpStreams.get(nm.getKey());
                     MessageLogin ml = (MessageLogin)nm.getMessage();
                     
                     Set<Map.Entry<Long, WSYD_Member>> tempSet = _members.entrySet();
@@ -475,34 +505,54 @@ public final class ServerSocial implements NetworkMessageEventListener, Connecti
                             ml._loggedIn = true;
                             _tcpStreamManager.updateKey(nm.getKey(), element.getKey()); // replace temp key in stream manager
                             _membersOnline.add(element.getKey()); // make the member online
+                            break;
+                        }
+                    }
+                    if (ns != null)
+                        ns.write(nm);
+                    else
+                        System.err.println("Login: cannot find stream for ID:" + nm.getKey());
+                }
+            case "Register":
+                if (type.equals(MessageMember.getType())) {
+                    NetworkStream ns = _tcpStreamManager._tcpStreams.get(nm.getKey());
+                    MessageMember mm = (MessageMember)nm.getMessage();
+                    // assume username can be registered unless username found
+                    mm.setRegistered(MessageMember.STATE.REGISTERED);
+                    
+                    Set<Map.Entry<Long, WSYD_Member>> tempSet = _members.entrySet();
+                    Iterator<Map.Entry<Long, WSYD_Member>> tempIter = tempSet.iterator();
+                    while (tempIter.hasNext()) {
+                        Map.Entry<Long, WSYD_Member> element = tempIter.next();
+                        if (element.getValue()._userName.equals(mm.getMember()._userName)) {
+                            mm.setRegistered(MessageMember.STATE.UNREGISTERED);
+                            mm.setStatus("Member already registered: " + mm.getMember()._userName);
+                            break;
                         }
                     }
-                    _tcpStreamManager._tcpStreams.get(nm.getKey()).write(nm);
+                    // register the new member
+                    if (mm.getRegistered() == MessageMember.STATE.REGISTERED) {
+                        // get the next unallocated user ID
+                        long newUserID = _members.lastKey().longValue() + 1;
+                        _members.put(newUserID, mm.getMember());
+                        // update the object so the ID can be returned to the client
+                        mm.getMember()._userID = newUserID;
+                        // update the on-disk membership data
+                        writeMembers(_membersFile);
+                    }
+                    if (ns != null)
+                        ns.write(nm);
+                    else
+                        System.err.println("Login: cannot find stream for ID:" + nm.getKey());
+                    
                 }
+                break;
+            default:
+                System.err.println("Unhandled NetworkMessage received for intent " + nm.getIntent());
         }
         
     }
     
-    private void notifyMemberPrescence(long userID, boolean state) {
-        NetworkMessage message = new NetworkMessage("MemberNotification", null, new MessageMemberState(userID, state));
-        for (long ID : _membersOnline) {
-            _tcpStreamManager._tcpStreams.get(ID).write(message);
-        }
-    }
-    
-    private void memberOnline (long userID) {
-        if (!_membersOnline.contains(userID)) {
-            notifyMemberPrescence(userID, true);
-            _membersOnline.add(userID);
-        }
-    }
-    
-    private void memberOffline (long userID) {
-        if (_membersOnline.contains(userID)) {
-            _membersOnline.remove(userID);
-            notifyMemberPrescence(userID, false);
-        }
-    }
 
     /**
      * Entry point which starts, restarts, and exits the application.
@@ -520,12 +570,4 @@ public final class ServerSocial implements NetworkMessageEventListener, Connecti
             }
         }
     }
-
-    @Override
-    public void connectionEstablished(ConnectionEstablishedEvent event) {
-        System.err.println("connectionEstablished()");
-        event.getStream().getEventManager().addNetworkMessageEventListener(this);
-    }
 }
-    
-
index 364ec84..a493cc5 100644 (file)
@@ -36,7 +36,7 @@ import java.util.TreeSet;
 
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_MemberTest {
     public WSYD_Member instance;
index a1d6f55..9e73e52 100644 (file)
@@ -33,7 +33,7 @@ import static org.junit.Assert.*;
 
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_Member_Comparator_UserIDTest {
     WSYD_Member_Comparator_UserID instance;
index ecbfbae..e6e20c8 100644 (file)
@@ -32,7 +32,7 @@ import static org.junit.Assert.*;
 
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_Member_Comparator_UserNameTest {
     WSYD_Member_Comparator_UserName instance;
index 4e5f57e..fb07078 100644 (file)
@@ -43,7 +43,7 @@ import uk.ac.ntu.n0521366.wsyd.libs.net.WSYD_SocketAddress.Protocol;
 
 /**
  *
- * @author TJ <hacker@iam.tj>
+ * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_SocketAddressTest {