Kaynağa Gözat

Merge pull request #15 from bartreedijk/feature/Server-new

Feature/server new
bartreedijk 10 yıl önce
ebeveyn
işleme
13bda76adf

+ 5 - 0
Proftaak Remote Healthcare/FietsClientV2/CurrentData.cs

@@ -29,6 +29,11 @@ namespace FietsClient
             return testResult;
         }
 
+        public String GetUserID()
+        {
+            return userID;
+        }
+
         public void setSession(Session s)
         {
             testResult.Add(s);

+ 10 - 2
Proftaak Remote Healthcare/FietsClientV2/Forms/PatientForm.cs

@@ -25,6 +25,11 @@ namespace FietsClient
             DataHandler.IncomingErrorEvent += HandleError; //initialize event
 
             _connection.IncomingChatmessageEvent += new TcpConnection.ChatmassegeDelegate(printMessage);
+
+            //TIJDELIJK STUK CODE OM MESSAGE TE TESTEN
+            _connection.SendString("6|TOM|TOM|Je bent een homo");
+            Console.WriteLine("Bericht versturen");
+            //EINDE TESTCODE
         }
 
         private void HandleError(string error)
@@ -112,9 +117,12 @@ namespace FietsClient
         {
             if(messageBox.Text != null)
             {
-                string message = messageBox.Text;
+                String[] data = new String[2];
+                data[0] = messageBox.Text;
+                data[1] = _connection.currentData.GetUserID();
                 messageBox.Clear();
-                _connection.SendChatMessage(message);
+
+                _connection.SendChatMessage(data);
             }
         }
 

+ 17 - 6
Proftaak Remote Healthcare/FietsClientV2/TCPConnection.cs

@@ -114,6 +114,7 @@ namespace FietsClient
                             break;
                         case "7":
                             string[] data = { response_parts[1], response_parts[2], response_parts[3] };
+                            SendChatMessage(data);
                             break;
                     }
                 }
@@ -145,11 +146,21 @@ namespace FietsClient
             SendString("5|" + userID + lib.JsonConverter.SerializeLastMeasurement(currentData.GetSessions().Last().GetLastMeasurement()));
         }
 	
-	public void SendChatMessage(string message)
+	public void SendChatMessage(string[] data)
         {
-            // send command ( cmdID | username sender | username patient | message )
-            string protocol = "6 | " + this.userID +" | "/* + idPatient */ + " | " + message;
-            SendString(protocol);
+            String receiverID = data[0];
+
+            if (currentData != null)
+            {
+                if (currentData.GetUserID() == receiverID)
+                {
+                    String message = data[1];
+
+                    // send command ( cmdID | username sender | username patient | message )
+                    string protocol = "6 | " + this.userID + " | " + receiverID + " | " + message;
+                    SendString(protocol);
+                }
+            }
         }
 
 	public void SendDistance(int distance)
@@ -167,12 +178,12 @@ namespace FietsClient
             SendString("12|" + userID + "|" + power);
         }
 	
-	public void SendString(string s)
+	    public void SendString(string s)
         {
+
             byte[] b = Encoding.ASCII.GetBytes(s);
             serverStream.Write(b, 0, b.Length);
             serverStream.Flush();
         }
-
     }
 }

+ 14 - 0
Proftaak Remote Healthcare/Server/Client.cs

@@ -92,6 +92,20 @@ namespace Server
                             currentUser.tests.Last().AddMeasurement(JsonConvert.DeserializeObject<Measurement>(response_parts[2]));
 
                             break;
+
+                        case "6": //chatberichten ontvangen van gebruikers
+
+                            //controleren of het bericht wel tekens bevat
+                            if (response_parts[3] != null)
+                            {
+                                String message = response_parts[3];
+                                String receiver = response_parts[2];
+                                String sender = response_parts[1];
+
+                                //bericht doorsturen naar alle actieve gebruikers (de Fietsclient zorgt ervoor dat alleen de geadresseerde het bericht kan zien)
+                                sendString("7|" + sender + "|" + receiver + "|" + message);      
+                            }
+                            break;
                     }
                 }
             }