Advertisement
Guest User

Untitled

a guest
May 27th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1.     ...    
  2.  
  3.         } else if(messageType.equals("SENDMESSAGE") || messageType.equals("SENDMSG")) {
  4.             String[] bodyParts = messageBody.split(" ");
  5.             if(bodyParts.length > 1) {
  6.                 String recipient = bodyParts[0];
  7.                 String message = messageBody.substring(recipient.length()+1, messageBody.length());
  8.                 //find recipient
  9.                 Optional<ConnectedClient> recipientClient = connectedClients.stream().filter(c -> c.getUsername().equals(recipient)).findAny();
  10.                 if(recipientClient.isPresent()) {
  11.                     recipientClient.get().send(client.getUsername() + " -> " + recipientClient.get().getUsername() + ": " + message);
  12.                     client.send("Message sent");
  13.                 } else {
  14.                     client.send("Message could not be sent: no recipient by that name");
  15.                 }
  16.             }
  17.  
  18.     ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement