private void broadcastUserListUpdate() { UserListUpdateMessage ulum = new UserListUpdateMessage(this.getUserList()); for (Session nextSession : session.getOpenSessions()) { try { nextSession.getBasicRemote().sendObject(ulum); } catch (IOException | EncodeException ex) { System.out.println("Error updating a client : " + ex.getMessage()); } } }
void processNewUser(NewUserMessage message) { String newUsername = this.validateUsername(message.getUsername()); NewUserMessage uMessage = new NewUserMessage(newUsername); try { session.getBasicRemote().sendObject(uMessage); } catch (IOException | EncodeException ioe) { System.out.println( "Error signing " + message.getUsername() + " into chat : " + ioe.getMessage()); } this.registerUser(newUsername); try { ResultSet rs = null, ds = null; String z, x; String url1 = "jdbc:mysql://localhost:3306/chat"; Connection conn1 = DriverManager.getConnection(url1, "root", "root"); Statement st1 = conn1.createStatement(); Statement st2 = conn1.createStatement(); String myQuery = "SELECT Message,Recepient FROM Log WHERE User = '******'"; System.out.println(myQuery); rs = st1.executeQuery("SELECT Message,Recepient FROM Log WHERE User = '******';"); while (rs.next()) { z = rs.getString("Message"); x = rs.getString("Recepient"); ChatUpdateMessage cdm1 = new ChatUpdateMessage(newUsername, z, x); try { session.getBasicRemote().sendObject(cdm1); } catch (IOException | EncodeException ex) { System.out.println("Error updating a client : " + ex.getMessage()); } } ds = st2.executeQuery("SELECT Message,User FROM Log WHERE Recepient = '" + newUsername + "';"); while (ds.next()) { z = ds.getString("Message"); x = ds.getString("User"); ChatUpdateMessage cdm2 = new ChatUpdateMessage(x, z, newUsername); try { session.getBasicRemote().sendObject(cdm2); } catch (IOException | EncodeException ex) { System.out.println("Error updating a client : " + ex.getMessage()); } } } catch (Exception e) { System.err.println("Got an exception! "); System.err.println(e.getMessage()); } this.broadcastUserListUpdate(); }
private void broadcastTranscriptUpdate() { String v = this.transcript.getRec(); String g; if (c.equals(v)) { for (Session nextSession : session.getOpenSessions()) { ChatUpdateMessage cdm = new ChatUpdateMessage( this.transcript.getLastUsername(), this.transcript.getLastMessage(), this.transcript.getRec()); try { nextSession.getBasicRemote().sendObject(cdm); } catch (IOException | EncodeException ex) { System.out.println("Error updating a client : " + ex.getMessage()); } } } else { for (Session nextSession : session.getOpenSessions()) { String check = this.transcript.getRec(); ChatUpdateMessage cdm = new ChatUpdateMessage( this.transcript.getLastUsername(), this.transcript.getLastMessage(), this.transcript.getRec()); g = (String) nextSession.getUserProperties().get(USERNAME_KEY); if (v.equals(g)) { try { nextSession.getBasicRemote().sendObject(cdm); } catch (IOException | EncodeException ex) { System.out.println("Error updating a client : " + ex.getMessage()); } } } } }