Created method to extract all currently online members of a group
additionally, refactored every ".Id" to ".ID"
This commit is contained in:
@ -38,18 +38,18 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
|
||||
private final ConnectionManager connectionManager = ConnectionManager.getInstance();
|
||||
|
||||
@Override
|
||||
public void process(LoginCredentials input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||
public void process(LoginCredentials input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
|
||||
UserStatusChangeProcessor.setWriteProxy(writeProxy);
|
||||
System.out.println(String.format("Received login credentials %s from socket ID %d", input, socketId));
|
||||
System.out.println(String.format("Received login credentials %s from socket ID %d", input, socketID));
|
||||
|
||||
envoy.server.data.User user = getUser(input, socketId, writeProxy);
|
||||
envoy.server.data.User user = getUser(input, socketID, writeProxy);
|
||||
|
||||
// Not logged in successfully
|
||||
if (user == null) {
|
||||
System.out.println("Rejecting handshake on socket " + socketId);
|
||||
System.out.println("Rejecting handshake on socket " + socketID);
|
||||
return;
|
||||
}
|
||||
connectionManager.registerUser(user.getID(), socketId);
|
||||
connectionManager.registerUser(user.getID(), socketID);
|
||||
|
||||
// Notifies contacts of this users online-going and updates his status in the
|
||||
// database
|
||||
@ -62,14 +62,14 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
|
||||
|
||||
// Complete handshake
|
||||
System.out.println("Sending user...");
|
||||
writeProxy.write(socketId, user.toCommon());
|
||||
writeProxy.write(socketID, user.toCommon());
|
||||
System.out.println("Sending contacts...");
|
||||
writeProxy.write(socketId, contacts);
|
||||
writeProxy.write(socketID, contacts);
|
||||
System.out.println("Acquiring pending messages for the client...");
|
||||
List<Message> pendingMessages = PersistenceManager.getInstance().getUnreadMessages(user);
|
||||
for (Message msg : pendingMessages) {
|
||||
System.out.println("Sending message " + msg.toCommonMessage());
|
||||
writeProxy.write(socketId, msg.toCommonMessage());
|
||||
writeProxy.write(socketID, msg.toCommonMessage());
|
||||
msg.setReceivedDate(new Date());
|
||||
msg.setStatus(MessageStatus.RECEIVED);
|
||||
PersistenceManager.getInstance().updateMessage(msg);
|
||||
@ -79,13 +79,13 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
|
||||
@Override
|
||||
public Class<LoginCredentials> getInputClass() { return LoginCredentials.class; }
|
||||
|
||||
private envoy.server.data.User getUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||
return credentials.isRegistration() ? newUser(credentials, socketId, writeProxy) : checkForExistingUser(credentials, socketId, writeProxy);
|
||||
private envoy.server.data.User getUser(LoginCredentials credentials, long socketID, ObjectWriteProxy writeProxy) throws IOException {
|
||||
return credentials.isRegistration() ? newUser(credentials, socketID, writeProxy) : checkForExistingUser(credentials, socketID, writeProxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param credentials the input to evaluate
|
||||
* @param socketId the socket ID at which the client performing the handshake
|
||||
* @param socketID the socket ID at which the client performing the handshake
|
||||
* is connected
|
||||
* @param writeProxy the {@link ObjectWriteProxy} to use if login was not
|
||||
* successful
|
||||
@ -93,34 +93,34 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
|
||||
* @throws IOException if sending the failed login back to the client failed
|
||||
* @since Envoy Server Standalone v0.1-alpha
|
||||
*/
|
||||
private envoy.server.data.User checkForExistingUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||
private envoy.server.data.User checkForExistingUser(LoginCredentials credentials, long socketID, ObjectWriteProxy writeProxy) throws IOException {
|
||||
try {
|
||||
envoy.server.data.User user = persistenceManager.getUserByName(credentials.getIdentifier());
|
||||
|
||||
// Checking if user is already online
|
||||
if (connectionManager.isOnline(user.getID())) {
|
||||
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.ALREADY_ONLINE));
|
||||
writeProxy.write(socketID, new HandshakeRejectionEvent(HandshakeRejectionEvent.ALREADY_ONLINE));
|
||||
return null;
|
||||
}
|
||||
// Evaluating the correctness of the password hash
|
||||
if (!Arrays.equals(credentials.getPasswordHash(), user.getPasswordHash())) {
|
||||
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.WRONG_PASSWORD));
|
||||
writeProxy.write(socketID, new HandshakeRejectionEvent(HandshakeRejectionEvent.WRONG_PASSWORD));
|
||||
return null;
|
||||
}
|
||||
return user;
|
||||
} catch (NoResultException e) {
|
||||
// Checking if user exists
|
||||
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_DOES_NOT_EXIST));
|
||||
writeProxy.write(socketID, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_DOES_NOT_EXIST));
|
||||
} catch (InputMismatchException e) {
|
||||
// Checking if the given password hash is correct
|
||||
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.WRONG_PASSWORD));
|
||||
writeProxy.write(socketID, new HandshakeRejectionEvent(HandshakeRejectionEvent.WRONG_PASSWORD));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param credentials the credentials upon which to create the new {@link User}
|
||||
* @param socketId the socketID at which the client performing the handshake
|
||||
* @param socketID the socketID at which the client performing the handshake
|
||||
* is connected
|
||||
* @param writeProxy the write proxy used to notify the client about handshake
|
||||
* rejection
|
||||
@ -128,12 +128,12 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
|
||||
* @throws IOException if sending the failed login back to the client failed
|
||||
* @since Envoy Server Standalone v0.1-alpha
|
||||
*/
|
||||
private envoy.server.data.User newUser(LoginCredentials credentials, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
||||
private envoy.server.data.User newUser(LoginCredentials credentials, long socketID, ObjectWriteProxy writeProxy) throws IOException {
|
||||
try {
|
||||
// Checking that no user already has this identifier
|
||||
PersistenceManager.getInstance().getUserByName(credentials.getIdentifier());
|
||||
// this code only gets executed if this user already exists
|
||||
writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_EXISTS_ALREADY));
|
||||
writeProxy.write(socketID, new HandshakeRejectionEvent(HandshakeRejectionEvent.USER_EXISTS_ALREADY));
|
||||
return null;
|
||||
} catch (NoResultException e) {
|
||||
// Creation of a new user
|
||||
|
Reference in New Issue
Block a user