/* The SignIn MessageHandler * It handles messages of SIGN_IN_REQUEST type. */ private static void SignIn(RMessage message, TcpClient connection) { RMessage replyMessage; UserData user1 = (UserData)message.Data; UserData user2 = UserConnector.GetUser(user1.Username); // Check if the password match if (user2 != null && user2.Password != user1.Password) { user2 = null; } // If the credentials do not match, refuse the authentification if (user2 == null) { ServerCore.GetWorkerByConnection(connection).SendMessage( new RMessage(MessageType.SIGN_IN_REPLY, null)); return; } // If the user can authenticate, disconnect another user connected // with the same username if (user2 != null) { TcpClient previousConnection = ServerCore.GetConnectionById(user2.Id); if (previousConnection != null) { ServerCore.RemoveIdConnectionMapping(user2.Id, previousConnection); replyMessage = new RMessage( MessageType.SIGN_OUT_REPLY, user2); ServerCore.GetWorkerByConnection(previousConnection) .SendMessage(replyMessage); } } List <Object> payload = new List <Object>(); payload.Add(user2); // user data payload.Add(DomainConnector.GetAllDomains()); // all domains payload.Add(DomainConnector.GetUserValidations(user2.Id)); // domains for which the user has certificates replyMessage = new RMessage( MessageType.SIGN_IN_REPLY, payload); ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage); // If the user connected successfully, store the connection mapping if (user2 != null) { ServerCore.AddIdConnectionMapping(user2.Id, connection); } }