当前位置: 首页>>代码示例>>C++>>正文


C++ Member::authority方法代码示例

本文整理汇总了C++中Member::authority方法的典型用法代码示例。如果您正苦于以下问题:C++ Member::authority方法的具体用法?C++ Member::authority怎么用?C++ Member::authority使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Member的用法示例。


在下文中一共展示了Member::authority方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadMembers

void SecurityManager::loadMembers()
{
    if (isSql()) {
        loadSqlMembers();
        return;
    }
    const char *path = "serverdb/members.txt";
    const char *backup = "serverdb/members.backup.txt";
    {
        QDir d;
        d.mkdir("serverdb");
    }

    if (!QFile::exists(path) && QFile::exists(backup)) {
        QFile::rename(backup, path);
    }

    memberFile.setFileName(path);
    if (!memberFile.open(QFile::ReadWrite)) {
        throw QObject::tr("Error: cannot open the file that contains the members (%1)").arg(path);
    }

    int pos = memberFile.pos();
    while (!memberFile.atEnd()) {
        QByteArray arr = memberFile.readLine();
        QString s = QString::fromUtf8(arr.constData(), std::max(0,arr.length()-1)); //-1 to remove the \n

        QStringList ls = s.split('%');

        if (ls.size() >= 6 && isValid(ls[0])) {
            Member m (ls[0], ls[1].trimmed(), ls[2][0].toLatin1() - '0', ls[2][1] == '1', ls[3].trimmed().toLatin1(), ls[4].trimmed().toLatin1(), ls[5].trimmed());

            if (ls.size() >= 7) {
                m.ban_expire_time = ls[6].toInt();
            }

            m.filepos = pos;
            members[ls[0]] = m;

            /* Update pos for next iteration */
            pos = memberFile.pos();

            if (m.isBanned()) {
                bannedIPs.insert(m.ip, m.ban_expire_time);
                bannedMembers.insert(m.name.toLower(), std::pair<QString, int>(m.ip, m.ban_expire_time));
            }
            if (m.authority() > 0) {
                authed.insert(m.name);
            }
            playersByIp.insert(m.ip, m.name);
        }
        lastPlace = memberFile.pos();
    }

    //We also clean up the file by rewritting it with only the valid contents
    QFile temp (backup);
    if (!temp.open(QFile::WriteOnly | QFile::Truncate))
        throw QObject::tr("Impossible to change %1").arg(backup);

    pos = temp.pos();

    for(auto it = members.begin(); it != members.end(); ++it) {
        Member &m = it->second;
        m.write(&temp);
        m.filepos = pos;
        pos = temp.pos();
    }

    lastPlace = temp.pos();

    temp.flush();
    memberFile.remove();

    if (!temp.rename(path)) {
        throw QObject::tr("Error: cannot rename the file that contains the members (%1 -> %2)").arg(backup).arg(path);
    }

    temp.rename(path);

    if (!memberFile.open(QFile::ReadWrite)) {
        throw QObject::tr("Error: cannot reopen the file that contains the members (%1)").arg(path);
    }
}
开发者ID:Alicirno,项目名称:pokemon-online,代码行数:83,代码来源:security.cpp


注:本文中的Member::authority方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。