This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/server/LoginCredentialProcessor.java

47 lines
1.4 KiB
Java
Raw Normal View History

package envoy.server;
import java.io.IOException;
import java.util.ArrayList;
import envoy.data.Contacts;
import envoy.data.LoginCredentials;
import envoy.data.User;
import envoy.server.net.ObjectWriteProxy;
/**
2019-12-30 15:15:25 +01:00
* This {@link ObjectProcessor} handles {@link LoginCredentials}.<br>
* <br>
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>LoginCredentialProcessor.java</strong><br>
* Created: <strong>30.12.2019</strong><br>
2019-12-30 15:15:25 +01:00
*
* @author Kai S. K. Engelbart
2019-12-30 15:15:25 +01:00
* @since Envoy Server Standalone v0.1-alpha
*/
public class LoginCredentialProcessor implements ObjectProcessor<LoginCredentials> {
// TODO: Acquire user IDs from database
private static long currentUserId = 1;
2019-12-30 15:15:25 +01:00
@Override
public Class<LoginCredentials> getInputClass() { return LoginCredentials.class; }
@Override
public void process(LoginCredentials input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
System.out.println(String.format("Received login credentials %s from socket ID %d", input, socketId));
// Create user
User user = new User(currentUserId++, input.getName());
ConnectionManager.getInstance().registerUser(socketId, user.getId());
// Create contacts
Contacts contacts = new Contacts(user.getId(), new ArrayList<>());
// Complete handshake
System.out.println("Sending user...");
writeProxy.write(socketId, user);
System.out.println("Sending contacts...");
writeProxy.write(socketId, contacts);
}
}