From d967c88e5b3a0f6c6e7b2f319978771f7df4d874 Mon Sep 17 00:00:00 2001 From: delvh Date: Fri, 7 Feb 2020 23:37:33 +0100 Subject: [PATCH 1/8] Implemented method to check for the validity of logins Warning: will only work once f/advanced_login of envoy-common will be merged into develop --- .../processors/LoginCredentialProcessor.java | 68 +++++++++++++++---- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index 4a7f2c8..9020937 100644 --- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -3,14 +3,18 @@ package envoy.server.processors; import java.io.IOException; import java.util.Arrays; import java.util.Date; +import java.util.InputMismatchException; import java.util.List; import java.util.stream.Collectors; +import javax.persistence.NoResultException; + import envoy.data.Contacts; import envoy.data.LoginCredentials; import envoy.data.Message.MessageStatus; import envoy.data.User; import envoy.data.User.UserStatus; +import envoy.event.HandshakeRejectionEvent; import envoy.server.ConnectionManager; import envoy.server.ObjectProcessor; import envoy.server.data.Message; @@ -40,7 +44,7 @@ public class LoginCredentialProcessor implements ObjectProcessor Date: Sun, 9 Feb 2020 16:37:53 +0100 Subject: [PATCH 2/8] added methods to signal an invalid login additionally added a failsafe to set all users to offline in case of shutdown of the server --- .../java/envoy/server/ConnectionManager.java | 12 ++++++++ .../server/database/PersistenceManager.java | 12 +++++++- .../processors/LoginCredentialProcessor.java | 30 +++++++++++-------- .../server/processors/MessageProcessor.java | 2 +- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/main/java/envoy/server/ConnectionManager.java b/src/main/java/envoy/server/ConnectionManager.java index 9dfd56b..73985bd 100644 --- a/src/main/java/envoy/server/ConnectionManager.java +++ b/src/main/java/envoy/server/ConnectionManager.java @@ -1,8 +1,10 @@ package envoy.server; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -98,4 +100,14 @@ public class ConnectionManager implements ISocketIdListener { * @since Envoy Server Standalone v0.1-alpha */ public boolean isOnline(long userId) { return sockets.containsKey(userId); } + + /** + * @return the userId of all users who are currently online + * @since Envoy Server Standalone v0.1-alpha + */ + public List getOnlineUsers() { + List onlineUsers = new ArrayList<>(); + sockets.forEach((userId, unimportant) -> onlineUsers.add(userId)); + return onlineUsers; + } } diff --git a/src/main/java/envoy/server/database/PersistenceManager.java b/src/main/java/envoy/server/database/PersistenceManager.java index 84587e6..c7b6f11 100644 --- a/src/main/java/envoy/server/database/PersistenceManager.java +++ b/src/main/java/envoy/server/database/PersistenceManager.java @@ -1,11 +1,14 @@ package envoy.server.database; +import java.util.Date; import java.util.List; import javax.persistence.EntityManager; import javax.persistence.EntityTransaction; import javax.persistence.Persistence; +import envoy.data.User.UserStatus; +import envoy.server.ConnectionManager; import envoy.server.data.ConfigItem; import envoy.server.data.Message; import envoy.server.data.User; @@ -32,7 +35,14 @@ public class PersistenceManager { */ private PersistenceManager() { transaction.begin(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> transaction.commit())); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + ConnectionManager.getInstance() + .getOnlineUsers() + .stream() + .map(this::getUserById) + .forEach(user -> { user.setStatus(UserStatus.OFFLINE); user.setLastSeen(new Date()); updateUser(user); }); + transaction.commit(); + })); } /** diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index 9020937..31ddbbd 100644 --- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -44,7 +44,7 @@ public class LoginCredentialProcessor implements ObjectProcessor { // Update the message status to RECEIVED message.setReceivedDate(new Date()); message.nextStatus(); - writeProxy.write(connectionManager.getSocketId(message.getSenderId()), new MessageStatusChangeEvent(message)); + writeProxy.write(socketId, new MessageStatusChangeEvent(message)); } catch (IOException e) { System.err.println("Recipient online. Failed to send message" + message.getId()); e.printStackTrace(); From b6763384fd3bcba790ebc393c2f30fdd834c030b Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 9 Feb 2020 20:41:29 +0100 Subject: [PATCH 3/8] fixed bug that made registering a new user impossible --- .../processors/LoginCredentialProcessor.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index 31ddbbd..d58f29b 100644 --- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -92,7 +92,7 @@ public class LoginCredentialProcessor implements ObjectProcessor Date: Wed, 12 Feb 2020 07:10:33 +0100 Subject: [PATCH 4/8] Clean-up, disabled SQL logging --- .settings/org.eclipse.jdt.core.prefs | 100 ++++++++++++++++++ .../java/envoy/server/ConnectionManager.java | 16 +-- src/main/java/envoy/server/Startup.java | 2 +- src/main/java/envoy/server/data/Message.java | 2 +- .../server/database/PersistenceManager.java | 2 +- .../processors/ContactOperationProcessor.java | 4 +- .../ContactsRequestEventProcessor.java | 2 +- .../IdGeneratorRequestProcessor.java | 4 +- .../processors/LoginCredentialProcessor.java | 47 ++++---- .../server/processors/MessageProcessor.java | 2 +- .../MessageStatusChangeProcessor.java | 2 +- .../processors/UserStatusChangeProcessor.java | 2 +- src/main/resources/META-INF/persistence.xml | 2 - 13 files changed, 143 insertions(+), 44 deletions(-) diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index db24ee7..8ded9c8 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,13 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullable.secondary= +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve @@ -6,10 +15,101 @@ org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.APILeak=warning +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=info org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled +org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/main/java/envoy/server/ConnectionManager.java b/src/main/java/envoy/server/ConnectionManager.java index 73985bd..e367be4 100644 --- a/src/main/java/envoy/server/ConnectionManager.java +++ b/src/main/java/envoy/server/ConnectionManager.java @@ -1,12 +1,6 @@ package envoy.server; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import com.jenkov.nioserver.ISocketIdListener; @@ -53,7 +47,7 @@ public class ConnectionManager implements ISocketIdListener { public void socketCancelled(long socketId) { if (!pendingSockets.remove(socketId)) { // notifying contacts of this users offline-going - envoy.server.data.User user = PersistenceManager.getPersistenceManager().getUserById(getUserIdBySocketId(socketId)); + envoy.server.data.User user = PersistenceManager.getInstance().getUserById(getUserIdBySocketId(socketId)); user.setStatus(UserStatus.OFFLINE); user.setLastSeen(new Date()); UserStatusChangeProcessor.updateUserStatus(user); @@ -105,9 +99,5 @@ public class ConnectionManager implements ISocketIdListener { * @return the userId of all users who are currently online * @since Envoy Server Standalone v0.1-alpha */ - public List getOnlineUsers() { - List onlineUsers = new ArrayList<>(); - sockets.forEach((userId, unimportant) -> onlineUsers.add(userId)); - return onlineUsers; - } + public Set getOnlineUsers() { return sockets.keySet(); } } diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java index e23bf69..7132343 100644 --- a/src/main/java/envoy/server/Startup.java +++ b/src/main/java/envoy/server/Startup.java @@ -53,7 +53,7 @@ public class Startup { } private static void initializeCurrentMessageId() { - PersistenceManager persMan = PersistenceManager.getPersistenceManager(); + PersistenceManager persMan = PersistenceManager.getInstance(); if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0")); } } \ No newline at end of file diff --git a/src/main/java/envoy/server/data/Message.java b/src/main/java/envoy/server/data/Message.java index e5d1fce..6eceb52 100644 --- a/src/main/java/envoy/server/data/Message.java +++ b/src/main/java/envoy/server/data/Message.java @@ -66,7 +66,7 @@ public class Message { * @since Envoy Server Standalone v0.1-alpha */ public Message(envoy.data.Message message) { - PersistenceManager persMan = PersistenceManager.getPersistenceManager(); + PersistenceManager persMan = PersistenceManager.getInstance(); id = message.getId(); status = message.getStatus(); text = message.getText(); diff --git a/src/main/java/envoy/server/database/PersistenceManager.java b/src/main/java/envoy/server/database/PersistenceManager.java index 16ec52f..07103e0 100644 --- a/src/main/java/envoy/server/database/PersistenceManager.java +++ b/src/main/java/envoy/server/database/PersistenceManager.java @@ -49,7 +49,7 @@ public class PersistenceManager { * @return the {@link PersistenceManager} singleton * @since Envoy Server Standalone v0.1-alpha */ - public static PersistenceManager getPersistenceManager() { return persistenceManager; } + public static PersistenceManager getInstance() { return persistenceManager; } /** * Adds a {@link User} to the database. diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java index 48ec6d9..ab7c6f7 100644 --- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java +++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java @@ -30,11 +30,11 @@ public class ContactOperationProcessor implements ObjectProcessor { - private PersistenceManager persistenceManager = PersistenceManager.getPersistenceManager(); - - @Override - public Class getInputClass() { return LoginCredentials.class; } + private final PersistenceManager persistenceManager = PersistenceManager.getInstance(); + private final ConnectionManager connectionManager = ConnectionManager.getInstance(); @Override public void process(LoginCredentials input, long socketId, ObjectWriteProxy writeProxy) throws IOException { @@ -44,10 +42,13 @@ public class LoginCredentialProcessor implements ObjectProcessor pendingMessages = PersistenceManager.getPersistenceManager().getUnreadMessages(user); + List pendingMessages = PersistenceManager.getInstance().getUnreadMessages(user); for (Message msg : pendingMessages) { - System.out.println("Sending message " + msg.toCommonMessage().toString()); + System.out.println("Sending message " + msg.toCommonMessage()); writeProxy.write(socketId, msg.toCommonMessage()); msg.setReceivedDate(new Date()); msg.setStatus(MessageStatus.RECEIVED); - PersistenceManager.getPersistenceManager().updateMessage(msg); + PersistenceManager.getInstance().updateMessage(msg); } } + @Override + public Class 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); } /** * @param credentials the input to evaluate + * @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 + * @return the database user matching the login credentials * @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 { - envoy.server.data.User user; - ConnectionManager connectionManager = ConnectionManager.getInstance(); - String userIdentifier = credentials.getIdentifier(); try { - // TODO will need to be replaced with the Identifier once implemented - user = persistenceManager.getUserByName(userIdentifier); + 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)); return null; } // Evaluating the correctness of the password hash - if (!Arrays.equals(credentials.getPasswordHash(), user.getPasswordHash())) - throw new InputMismatchException("User " + credentials.getIdentifier() + "tried logging in using a wrong password"); + if (!Arrays.equals(credentials.getPasswordHash(), user.getPasswordHash())) { + writeProxy.write(socketId, new HandshakeRejectionEvent(HandshakeRejectionEvent.WRONG_PASSWORD)); + return null; + } return user; } catch (NoResultException e) { // Checking if user exists @@ -111,6 +117,10 @@ public class LoginCredentialProcessor implements ObjectProcessor()); persistenceManager.addUser(user); return user; } diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java index 23a9b43..2b93336 100644 --- a/src/main/java/envoy/server/processors/MessageProcessor.java +++ b/src/main/java/envoy/server/processors/MessageProcessor.java @@ -42,6 +42,6 @@ public class MessageProcessor implements ObjectProcessor { System.err.println("Recipient online. Failed to send message" + message.getId()); e.printStackTrace(); } - PersistenceManager.getPersistenceManager().addMessage(new envoy.server.data.Message(message)); + PersistenceManager.getInstance().addMessage(new envoy.server.data.Message(message)); } } diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java index 216e028..045f866 100644 --- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java +++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java @@ -32,7 +32,7 @@ public class MessageStatusChangeProcessor implements ObjectProcessor { private static ObjectWriteProxy writeProxy; - private static PersistenceManager persistenceManager = PersistenceManager.getPersistenceManager(); + private static PersistenceManager persistenceManager = PersistenceManager.getInstance(); @Override public Class getInputClass() { return UserStatusChangeEvent.class; } diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml index 4d937c9..10effe7 100644 --- a/src/main/resources/META-INF/persistence.xml +++ b/src/main/resources/META-INF/persistence.xml @@ -20,8 +20,6 @@ value="org.hibernate.dialect.PostgreSQL95Dialect" /> - - From 98cbe81e14f132289f675ad079a21e8e38fc582c Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 12 Feb 2020 07:53:54 +0100 Subject: [PATCH 5/8] Increased ID generation range to 200 --- pom.xml | 2 +- .../envoy/server/processors/IdGeneratorRequestProcessor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index db5b8da..48f93ea 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ com.github.informatik-ag-ngl envoy-common - develop-SNAPSHOT + f~advanced_login-SNAPSHOT com.github.informatik-ag-ngl diff --git a/src/main/java/envoy/server/processors/IdGeneratorRequestProcessor.java b/src/main/java/envoy/server/processors/IdGeneratorRequestProcessor.java index adca064..39a900c 100644 --- a/src/main/java/envoy/server/processors/IdGeneratorRequestProcessor.java +++ b/src/main/java/envoy/server/processors/IdGeneratorRequestProcessor.java @@ -19,7 +19,7 @@ import envoy.server.net.ObjectWriteProxy; */ public class IdGeneratorRequestProcessor implements ObjectProcessor { - private static final long ID_RANGE = 2; + private static final long ID_RANGE = 200; @Override public Class getInputClass() { return IdGeneratorRequest.class; } From e84d88aa8858a96f8574b0ac36f53c8e357c5276 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 12 Feb 2020 17:35:58 +0100 Subject: [PATCH 6/8] Added Maven assembly plugin configuration for JAR packaging --- pom.xml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pom.xml b/pom.xml index 48f93ea..e6856c2 100644 --- a/pom.xml +++ b/pom.xml @@ -54,5 +54,30 @@ src/main/resources + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4.1 + + + package + + single + + + + + envoy.server.Startup + + + + jar-with-dependencies + + + + + + \ No newline at end of file From 9a06ed4a4534d73f4657831c36dd63706523f65c Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 12 Feb 2020 22:01:32 +0100 Subject: [PATCH 7/8] Fixed ConnectionManager#isOnline(long), moved ConnectionManager to net --- src/main/java/envoy/server/Startup.java | 1 + .../java/envoy/server/database/PersistenceManager.java | 2 +- .../java/envoy/server/{ => net}/ConnectionManager.java | 8 ++++---- .../server/processors/ContactOperationProcessor.java | 2 +- .../server/processors/ContactsRequestEventProcessor.java | 2 +- .../envoy/server/processors/LoginCredentialProcessor.java | 2 +- .../java/envoy/server/processors/MessageProcessor.java | 2 +- .../server/processors/MessageStatusChangeProcessor.java | 2 +- .../server/processors/UserStatusChangeProcessor.java | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) rename src/main/java/envoy/server/{ => net}/ConnectionManager.java (93%) diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java index 7132343..13cd852 100644 --- a/src/main/java/envoy/server/Startup.java +++ b/src/main/java/envoy/server/Startup.java @@ -8,6 +8,7 @@ import com.jenkov.nioserver.Server; import envoy.server.data.ConfigItem; import envoy.server.database.PersistenceManager; +import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectMessageProcessor; import envoy.server.net.ObjectMessageReader; import envoy.server.processors.*; diff --git a/src/main/java/envoy/server/database/PersistenceManager.java b/src/main/java/envoy/server/database/PersistenceManager.java index 07103e0..12ac446 100644 --- a/src/main/java/envoy/server/database/PersistenceManager.java +++ b/src/main/java/envoy/server/database/PersistenceManager.java @@ -8,10 +8,10 @@ import javax.persistence.EntityTransaction; import javax.persistence.Persistence; import envoy.data.User.UserStatus; -import envoy.server.ConnectionManager; import envoy.server.data.ConfigItem; import envoy.server.data.Message; import envoy.server.data.User; +import envoy.server.net.ConnectionManager; /** * Project: envoy-server-standalone
diff --git a/src/main/java/envoy/server/ConnectionManager.java b/src/main/java/envoy/server/net/ConnectionManager.java similarity index 93% rename from src/main/java/envoy/server/ConnectionManager.java rename to src/main/java/envoy/server/net/ConnectionManager.java index e367be4..9419ed3 100644 --- a/src/main/java/envoy/server/ConnectionManager.java +++ b/src/main/java/envoy/server/net/ConnectionManager.java @@ -1,4 +1,4 @@ -package envoy.server; +package envoy.server.net; import java.util.*; @@ -46,14 +46,14 @@ public class ConnectionManager implements ISocketIdListener { @Override public void socketCancelled(long socketId) { if (!pendingSockets.remove(socketId)) { - // notifying contacts of this users offline-going + // Notify contacts of this users offline-going envoy.server.data.User user = PersistenceManager.getInstance().getUserById(getUserIdBySocketId(socketId)); user.setStatus(UserStatus.OFFLINE); user.setLastSeen(new Date()); UserStatusChangeProcessor.updateUserStatus(user); - // removing the socket - sockets.entrySet().stream().filter(e -> e.getValue() == socketId).forEach(e -> sockets.remove(e.getValue())); + // Remove the socket + sockets.entrySet().removeIf(e -> e.getValue() == socketId); } } diff --git a/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/src/main/java/envoy/server/processors/ContactOperationProcessor.java index ab7c6f7..0a79197 100644 --- a/src/main/java/envoy/server/processors/ContactOperationProcessor.java +++ b/src/main/java/envoy/server/processors/ContactOperationProcessor.java @@ -5,9 +5,9 @@ import java.util.Arrays; import envoy.data.Contacts; import envoy.event.ContactOperationEvent; -import envoy.server.ConnectionManager; import envoy.server.ObjectProcessor; import envoy.server.database.PersistenceManager; +import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; /** diff --git a/src/main/java/envoy/server/processors/ContactsRequestEventProcessor.java b/src/main/java/envoy/server/processors/ContactsRequestEventProcessor.java index 5443211..fe003f4 100644 --- a/src/main/java/envoy/server/processors/ContactsRequestEventProcessor.java +++ b/src/main/java/envoy/server/processors/ContactsRequestEventProcessor.java @@ -6,10 +6,10 @@ import java.util.stream.Collectors; import envoy.data.Contacts; import envoy.event.ContactSearchRequest; import envoy.event.ContactSearchResult; -import envoy.server.ConnectionManager; import envoy.server.ObjectProcessor; import envoy.server.data.User; import envoy.server.database.PersistenceManager; +import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; /** diff --git a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index 00c4985..2e3b6e0 100644 --- a/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -12,10 +12,10 @@ import envoy.data.Message.MessageStatus; import envoy.data.User; import envoy.data.User.UserStatus; import envoy.event.HandshakeRejectionEvent; -import envoy.server.ConnectionManager; import envoy.server.ObjectProcessor; import envoy.server.data.Message; import envoy.server.database.PersistenceManager; +import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; /** diff --git a/src/main/java/envoy/server/processors/MessageProcessor.java b/src/main/java/envoy/server/processors/MessageProcessor.java index 2b93336..a1e4f7c 100644 --- a/src/main/java/envoy/server/processors/MessageProcessor.java +++ b/src/main/java/envoy/server/processors/MessageProcessor.java @@ -5,9 +5,9 @@ import java.util.Date; import envoy.data.Message; import envoy.event.MessageStatusChangeEvent; -import envoy.server.ConnectionManager; import envoy.server.ObjectProcessor; import envoy.server.database.PersistenceManager; +import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; /** diff --git a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java index 045f866..9949e43 100644 --- a/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java +++ b/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java @@ -5,9 +5,9 @@ import java.io.IOException; import envoy.data.Message.MessageStatus; import envoy.event.MessageStatusChangeEvent; import envoy.exception.EnvoyException; -import envoy.server.ConnectionManager; import envoy.server.ObjectProcessor; import envoy.server.database.PersistenceManager; +import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; /** diff --git a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java index d9ab89a..59f2ca3 100644 --- a/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java +++ b/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java @@ -4,10 +4,10 @@ import java.io.IOException; import envoy.data.User.UserStatus; import envoy.event.UserStatusChangeEvent; -import envoy.server.ConnectionManager; import envoy.server.ObjectProcessor; import envoy.server.data.User; import envoy.server.database.PersistenceManager; +import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectWriteProxy; /** From 9214c31a9114c51fe9e200592d71e9dc639d9780 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Thu, 13 Feb 2020 10:00:56 +0100 Subject: [PATCH 8/8] Updated alpha releases of envoy-common and java-nio-server in pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e6856c2..22bcff3 100644 --- a/pom.xml +++ b/pom.xml @@ -28,12 +28,12 @@ com.github.informatik-ag-ngl envoy-common - f~advanced_login-SNAPSHOT + v0.2-alpha com.github.informatik-ag-ngl java-nio-server - master-SNAPSHOT + v0.1-alpha org.hibernate