Response::ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, ResponseContainer &rc)
{
    if (authState == NotLoggedIn)
        return Response::RespLoginNeeded;
    
    QReadLocker locker(&server->clientsLock);
    
    QString receiver = QString::fromStdString(cmd.user_name());
    Server_AbstractUserInterface *userInterface = server->findUser(receiver);
    if (!userInterface)
        return Response::RespNameNotFound;
    if (databaseInterface->isInIgnoreList(receiver, QString::fromStdString(userInfo->name())))
        return Response::RespInIgnoreList;
    
    Event_UserMessage event;
    event.set_sender_name(userInfo->name());
    event.set_receiver_name(cmd.user_name());
    event.set_message(cmd.message());
    
    SessionEvent *se = prepareSessionEvent(event);
    userInterface->sendProtocolItem(*se);
    rc.enqueuePreResponseItem(ServerMessage::SESSION_EVENT, se);

    databaseInterface->logMessage(userInfo->id(), QString::fromStdString(userInfo->name()), QString::fromStdString(userInfo->address()), QString::fromStdString(cmd.message()), Server_DatabaseInterface::MessageTargetChat, userInterface->getUserInfo()->id(), receiver);

    return Response::RespOk;
}