Changed code as requested by @CyB3RC0nN0R
This commit is contained in:
parent
1d35de3a39
commit
b7af8aa7bd
@ -24,8 +24,6 @@ import envoy.event.Event;
|
||||
*/
|
||||
public class ObjectMessageProcessor implements IMessageProcessor {
|
||||
|
||||
private long currentUserID = 0;// temporary
|
||||
|
||||
@Override
|
||||
public void process(Message message, WriteProxy writeProxy) {
|
||||
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
|
||||
*/
|
||||
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;
|
||||
|
||||
// determining the type of the incoming object
|
||||
if (obj instanceof envoy.data.Message) {// if object is Message
|
||||
envoy.data.Message cast = (envoy.data.Message) obj;
|
||||
usage = cast.getClass();
|
||||
immediateResponse = isRecipientAvailable(-1); // TODO replace with wanted clientID
|
||||
} else if (obj instanceof Event) {// if object is Event
|
||||
usage = (Event<?>) obj;
|
||||
immediateResponse = isRecipientAvailable(-1); // TODO replace with wanted clientID
|
||||
} else if (obj instanceof LoginCredentials) {// if object is LoginCredential
|
||||
responseToSameSocket = true;
|
||||
LoginCredentials cast = (LoginCredentials) obj;
|
||||
usage = new User(currentUserID++, cast.getName());
|
||||
} else throw new IllegalArgumentException();
|
||||
|
||||
// handling of incoming object
|
||||
if (immediateResponse) {
|
||||
Message response = writeProxy.getMessage();
|
||||
if (responseToSameSocket) {
|
||||
response.socketId = request.socketId;
|
||||
@ -81,6 +87,17 @@ public class ObjectMessageProcessor implements IMessageProcessor {
|
||||
byte[] objBytes = baos.toByteArray();
|
||||
response.writeToMessage(objBytes);
|
||||
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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user