本文整理汇总了C++中ServerInfo_User::set_name方法的典型用法代码示例。如果您正苦于以下问题:C++ ServerInfo_User::set_name方法的具体用法?C++ ServerInfo_User::set_name怎么用?C++ ServerInfo_User::set_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServerInfo_User
的用法示例。
在下文中一共展示了ServerInfo_User::set_name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: evalUserQueryResult
ServerInfo_User Servatrice_DatabaseInterface::evalUserQueryResult(const QSqlQuery *query, bool complete, bool withId)
{
ServerInfo_User result;
if (withId)
result.set_id(query->value(0).toInt());
result.set_name(query->value(1).toString().toStdString());
const int is_admin = query->value(2).toInt();
int userLevel = ServerInfo_User::IsUser | ServerInfo_User::IsRegistered;
if (is_admin == 1)
userLevel |= ServerInfo_User::IsAdmin | ServerInfo_User::IsModerator;
else if (is_admin == 2)
userLevel |= ServerInfo_User::IsModerator;
result.set_user_level(userLevel);
const QString country = query->value(3).toString();
if (!country.isEmpty())
result.set_country(country.toStdString());
const QString privlevel = query->value(4).toString();
if (!privlevel.isEmpty())
result.set_privlevel(privlevel.toStdString());
if (complete) {
const QString genderStr = query->value(5).toString();
if (genderStr == "m")
result.set_gender(ServerInfo_User::Male);
else if (genderStr == "f")
result.set_gender(ServerInfo_User::Female);
const QString realName = query->value(6).toString();
if (!realName.isEmpty())
result.set_real_name(realName.toStdString());
const QByteArray avatarBmp = query->value(7).toByteArray();
if (avatarBmp.size())
result.set_avatar_bmp(avatarBmp.data(), avatarBmp.size());
const QDateTime regDate = query->value(8).toDateTime();
if (!regDate.toString(Qt::ISODate).isEmpty()) {
qint64 accountAgeInSeconds = regDate.secsTo(QDateTime::currentDateTime());
result.set_accountage_secs(accountAgeInSeconds);
}
const QString email = query->value(9).toString();
if (!email.isEmpty())
result.set_email(email.toStdString());
const QString clientid = query->value(10).toString();
if (!clientid.isEmpty())
result.set_clientid(clientid.toStdString());
}
return result;
}
示例2: getUserData
ServerInfo_User Servatrice_DatabaseInterface::getUserData(const QString &name, bool withId)
{
ServerInfo_User result;
result.set_name(name.toStdString());
result.set_user_level(ServerInfo_User::IsUser);
if (server->getAuthenticationMethod() == Servatrice::AuthenticationSql) {
if (!checkSql())
return result;
QSqlQuery query(sqlDatabase);
query.prepare("select id, name, admin, realname, gender, country, avatar_bmp, registrationDate from " + server->getDbPrefix() + "_users where name = :name and active = 1");
query.bindValue(":name", name);
if (!execSqlQuery(query))
return result;
if (query.next())
return evalUserQueryResult(query, true, withId);
else
return result;
} else
return result;
}
示例3: getUserData
ServerInfo_User LocalServer_DatabaseInterface::getUserData(const QString &name, bool /*withId*/)
{
ServerInfo_User result;
result.set_name(name.toStdString());
return result;
}
示例4: loginUser
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reasonStr, int &secondsLeft, QString &clientid, QString &clientVersion, QString & /* connectionType */)
{
if (name.size() > 35)
name = name.left(35);
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, clientid, reasonStr, secondsLeft);
if (authState == NotLoggedIn || authState == UserIsBanned || authState == UsernameInvalid || authState == UserIsInactive)
return authState;
ServerInfo_User data = databaseInterface->getUserData(name, true);
data.set_address(session->getAddress().toStdString());
name = QString::fromStdString(data.name()); // Compensate for case indifference
if (authState == PasswordRight) {
if (users.contains(name) || databaseInterface->userSessionExists(name)) {
if (users.contains(name)) {
qDebug("Session already logged in, logging old session out");
Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::LOGGEDINELSEWERE);
event.set_reason_str("You have been logged out due to logging in at another location.");
event.set_end_time(QDateTime::currentDateTime().toTime_t());
SessionEvent *se = users.value(name)->prepareSessionEvent(event);
users.value(name)->sendProtocolItem(*se);
delete se;
users.value(name)->prepareDestroy();
} else {
qDebug() << "Active session and sessions table inconsistent, please validate session table information for user " << name;
}
}
} else if (authState == UnknownUser) {
// Change user name so that no two users have the same names,
// don't interfere with registered user names though.
if (getRegOnlyServerEnabled()) {
qDebug("Login denied: registration required");
databaseInterface->unlockSessionTables();
return RegistrationRequired;
}
QString tempName = name;
int i = 0;
while (users.contains(tempName) || databaseInterface->activeUserExists(tempName) || databaseInterface->userSessionExists(tempName))
tempName = name + "_" + QString::number(++i);
name = tempName;
data.set_name(name.toStdString());
}
QWriteLocker locker(&clientsLock);
databaseInterface->lockSessionTables();
users.insert(name, session);
qDebug() << "Server::loginUser:" << session << "name=" << name;
data.set_session_id(databaseInterface->startSession(name, session->getAddress(), clientid, session->getConnectionType()));
databaseInterface->unlockSessionTables();
usersBySessionId.insert(data.session_id(), session);
qDebug() << "session id:" << data.session_id();
session->setUserInfo(data);
Event_UserJoined event;
event.mutable_user_info()->CopyFrom(session->copyUserInfo(false));
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
for (int i = 0; i < clients.size(); ++i)
if (clients[i]->getAcceptsUserListChanges())
clients[i]->sendProtocolItem(*se);
delete se;
event.mutable_user_info()->CopyFrom(session->copyUserInfo(true, true, true));
locker.unlock();
if (clientid.isEmpty()){
// client id is empty, either out dated client or client has been modified
if (getClientIDRequiredEnabled())
return ClientIdRequired;
}
else {
// update users database table with client id
databaseInterface->updateUsersClientID(name, clientid);
}
databaseInterface->updateUsersLastLoginData(name, clientVersion);
se = Server_ProtocolHandler::prepareSessionEvent(event);
sendIsl_SessionEvent(*se);
delete se;
return authState;
}
示例5: loginUser
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reasonStr, int &secondsLeft)
{
if (name.size() > 35)
name = name.left(35);
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
QWriteLocker locker(&clientsLock);
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, reasonStr, secondsLeft);
if ((authState == NotLoggedIn) || (authState == UserIsBanned || authState == UsernameInvalid))
return authState;
ServerInfo_User data = databaseInterface->getUserData(name, true);
data.set_address(session->getAddress().toStdString());
name = QString::fromStdString(data.name()); // Compensate for case indifference
databaseInterface->lockSessionTables();
if (authState == PasswordRight) {
if (users.contains(name) || databaseInterface->userSessionExists(name)) {
qDebug("Login denied: would overwrite old session");
databaseInterface->unlockSessionTables();
return WouldOverwriteOldSession;
}
} else if (authState == UnknownUser) {
// Change user name so that no two users have the same names,
// don't interfere with registered user names though.
QSettings settings("servatrice.ini", QSettings::IniFormat);
bool requireReg = settings.value("authentication/regonly", 0).toBool();
if (requireReg) {
qDebug("Login denied: registration required");
databaseInterface->unlockSessionTables();
return RegistrationRequired;
}
QString tempName = name;
int i = 0;
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
tempName = name + "_" + QString::number(++i);
name = tempName;
data.set_name(name.toStdString());
}
users.insert(name, session);
qDebug() << "Server::loginUser:" << session << "name=" << name;
data.set_session_id(databaseInterface->startSession(name, session->getAddress()));
databaseInterface->unlockSessionTables();
usersBySessionId.insert(data.session_id(), session);
qDebug() << "session id:" << data.session_id();
session->setUserInfo(data);
Event_UserJoined event;
event.mutable_user_info()->CopyFrom(session->copyUserInfo(false));
SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
for (int i = 0; i < clients.size(); ++i)
if (clients[i]->getAcceptsUserListChanges())
clients[i]->sendProtocolItem(*se);
delete se;
event.mutable_user_info()->CopyFrom(session->copyUserInfo(true, true, true));
locker.unlock();
se = Server_ProtocolHandler::prepareSessionEvent(event);
sendIsl_SessionEvent(*se);
delete se;
return authState;
}