'Log in the previously unloggedin session and the player we by
now should know is connected to it. After this point we assume
the session to be logged in one way or another.
Args:
session (Session): The Session to authenticate.
player (Player): The Player identified as associated with this Session.
force (bool): Login also if the session thinks it\'s already logged in
(this can happen for auto-authenticating protocols)
testmode (bool, optional): This is used by unittesting for
faking login without any AMP being actually active.'

def login(self, session, player, force=False, testmode=False):

    if (session.logged_in and (not force)):
        return
    player.is_connected = True
    session.at_login(player)
    player.at_init()
    if player.db.FIRST_LOGIN:
        player.at_first_login()
        del player.db.FIRST_LOGIN
    player.at_pre_login()
    if (_MULTISESSION_MODE == 0):
        self.disconnect_duplicate_sessions(session)
    nsess = len(self.sessions_from_player(player))
    string = 'Logged    in:    {player}    {address}    ({nsessions}    session(s)    total)'
    string = string.format(player=player, address=session.address, nsessions=nsess)
    session.log(string)
    session.logged_in = True
    if (not testmode):
        self.server.amp_protocol.send_AdminServer2Portal(session, operation=SLOGIN, sessiondata={'logged_in': True})
    player.at_post_login(session=session)
