Changed code as requested by @CyB3RC0nN0R

This commit is contained in:
delvh 2019-12-29 17:52:57 +01:00
parent 1d35de3a39
commit b7af8aa7bd

View File

@ -24,8 +24,6 @@ import envoy.event.Event;
*/ */
public class ObjectMessageProcessor implements IMessageProcessor { public class ObjectMessageProcessor implements IMessageProcessor {
private long currentUserID = 0;// temporary
@Override @Override
public void process(Message message, WriteProxy writeProxy) { public void process(Message message, WriteProxy writeProxy) {
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(message.sharedArray, message.offset + 4, message.length - 4))) { try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(message.sharedArray, message.offset + 4, message.length - 4))) {
@ -51,19 +49,27 @@ public class ObjectMessageProcessor implements IMessageProcessor {
* @since Envoy Server Standalone v0.1-alpha * @since Envoy Server Standalone v0.1-alpha
*/ */
private void handleObject(Message request, WriteProxy writeProxy, Object obj) throws IllegalArgumentException { private void handleObject(Message request, WriteProxy writeProxy, Object obj) throws IllegalArgumentException {
boolean responseToSameSocket = false;
long currentUserID = 0; // TODO temporary. Only for testing purposes
boolean responseToSameSocket = false, immediateResponse = true;
Object usage; Object usage;
// determining the type of the incoming object
if (obj instanceof envoy.data.Message) {// if object is Message if (obj instanceof envoy.data.Message) {// if object is Message
envoy.data.Message cast = (envoy.data.Message) obj; envoy.data.Message cast = (envoy.data.Message) obj;
usage = cast.getClass(); usage = cast.getClass();
immediateResponse = isRecipientAvailable(-1); // TODO replace with wanted clientID
} else if (obj instanceof Event) {// if object is Event } else if (obj instanceof Event) {// if object is Event
usage = (Event<?>) obj; usage = (Event<?>) obj;
immediateResponse = isRecipientAvailable(-1); // TODO replace with wanted clientID
} else if (obj instanceof LoginCredentials) {// if object is LoginCredential } else if (obj instanceof LoginCredentials) {// if object is LoginCredential
responseToSameSocket = true; responseToSameSocket = true;
LoginCredentials cast = (LoginCredentials) obj; LoginCredentials cast = (LoginCredentials) obj;
usage = new User(currentUserID++, cast.getName()); usage = new User(currentUserID++, cast.getName());
} else throw new IllegalArgumentException(); } else throw new IllegalArgumentException();
// handling of incoming object
if (immediateResponse) {
Message response = writeProxy.getMessage(); Message response = writeProxy.getMessage();
if (responseToSameSocket) { if (responseToSameSocket) {
response.socketId = request.socketId; response.socketId = request.socketId;
@ -81,6 +87,17 @@ public class ObjectMessageProcessor implements IMessageProcessor {
byte[] objBytes = baos.toByteArray(); byte[] objBytes = baos.toByteArray();
response.writeToMessage(objBytes); response.writeToMessage(objBytes);
writeProxy.enqueue(response); writeProxy.enqueue(response);
}
}
/**
* This method determines if the recipient is online
*
* @param otherClientID the ID of the recipient
* @return true, if the recipient is online
* @since Envoy Server Standalone v0.1-alpha
*/
private boolean isRecipientAvailable(long otherClientID) {
return false;// TODO needs to be adapted to return true if the wanted client is online
} }
} }