Merge pull request #1530 from ZeldaZach/fix_1527

Minors Fixes for #1527
This commit is contained in:
Zach 2015-09-18 10:18:12 -04:00
commit 1409b97490
2 changed files with 30 additions and 29 deletions

View file

@ -116,7 +116,7 @@ void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
soundEngine->playSound("private_message"); soundEngine->playSound("private_message");
if (settingsCache->getShowMessagePopup() && shouldShowSystemPopup(event)) if (settingsCache->getShowMessagePopup() && shouldShowSystemPopup(event))
showSystemPopup(event); showSystemPopup(event);
if (QString::fromStdString(event.sender_name()).simplified() == "Servatrice") if (QString::fromStdString(event.sender_name()).toLower().simplified() == "servatrice")
sayEdit->setDisabled(true); sayEdit->setDisabled(true);
emit userEvent(); emit userEvent();

View file

@ -125,29 +125,29 @@ bool ServerSocketInterface::initSession()
sendProtocolItem(*identSe); sendProtocolItem(*identSe);
delete identSe; delete identSe;
//limit the number of total users based on configuration settings //limit the number of total users based on configuration settings
bool enforceUserLimit = settingsCache->value("security/enable_max_user_limit", false).toBool(); bool enforceUserLimit = settingsCache->value("security/enable_max_user_limit", false).toBool();
if (enforceUserLimit){ if (enforceUserLimit){
int userLimit = settingsCache->value("security/max_users_total", 500).toInt(); int userLimit = settingsCache->value("security/max_users_total", 500).toInt();
int playerCount = (databaseInterface->getActiveUserCount() + 1); int playerCount = (databaseInterface->getActiveUserCount() + 1);
if (playerCount > userLimit){ if (playerCount > userLimit){
std::cerr << "Max Users Total Limit Reached, please increase the max_users_total setting." << std::endl; std::cerr << "Max Users Total Limit Reached, please increase the max_users_total setting." << std::endl;
logger->logMessage(QString("Max Users Total Limit Reached, please increase the max_users_total setting."), this); logger->logMessage(QString("Max Users Total Limit Reached, please increase the max_users_total setting."), this);
Event_ConnectionClosed event; Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::USER_LIMIT_REACHED); event.set_reason(Event_ConnectionClosed::USER_LIMIT_REACHED);
SessionEvent *se = prepareSessionEvent(event); SessionEvent *se = prepareSessionEvent(event);
sendProtocolItem(*se); sendProtocolItem(*se);
delete se; delete se;
return false; return false;
} }
} }
//allow unlimited number of connections from the trusted sources //allow unlimited number of connections from the trusted sources
QString trustedSources = settingsCache->value("security/trusted_sources","127.0.0.1,::1").toString(); QString trustedSources = settingsCache->value("security/trusted_sources","127.0.0.1,::1").toString();
if (trustedSources.contains(socket->peerAddress().toString(),Qt::CaseInsensitive)) if (trustedSources.contains(socket->peerAddress().toString(),Qt::CaseInsensitive))
return true; return true;
int maxUsers = servatrice->getMaxUsersPerAddress(); int maxUsers = servatrice->getMaxUsersPerAddress();
if ((maxUsers > 0) && (servatrice->getUsersWithAddress(socket->peerAddress()) >= maxUsers)) { if ((maxUsers > 0) && (servatrice->getUsersWithAddress(socket->peerAddress()) >= maxUsers)) {
Event_ConnectionClosed event; Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::TOO_MANY_CONNECTIONS); event.set_reason(Event_ConnectionClosed::TOO_MANY_CONNECTIONS);
@ -524,15 +524,16 @@ void ServerSocketInterface::deckDelDirHelper(int basePathId)
void ServerSocketInterface::sendServerMessage(const QString userName, const QString message) void ServerSocketInterface::sendServerMessage(const QString userName, const QString message)
{ {
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName)); ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
if (user) { if (!user)
Event_UserMessage event; return;
event.set_sender_name("Servatrice");
event.set_receiver_name(userName.toStdString()); Event_UserMessage event;
event.set_message(message.toStdString()); event.set_sender_name("Servatrice");
SessionEvent *se = user->prepareSessionEvent(event); event.set_receiver_name(userName.toStdString());
user->sendProtocolItem(*se); event.set_message(message.toStdString());
delete se; SessionEvent *se = user->prepareSessionEvent(event);
} user->sendProtocolItem(*se);
delete se;
} }
Response::ResponseCode ServerSocketInterface::cmdDeckDelDir(const Command_DeckDelDir &cmd, ResponseContainer & /*rc*/) Response::ResponseCode ServerSocketInterface::cmdDeckDelDir(const Command_DeckDelDir &cmd, ResponseContainer & /*rc*/)
@ -849,7 +850,7 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
QList<QString> moderatorList = server->getOnlineModeratorList(); QList<QString> moderatorList = server->getOnlineModeratorList();
QListIterator<QString> modIterator(moderatorList); QListIterator<QString> modIterator(moderatorList);
foreach(QString moderator, moderatorList) { foreach(QString moderator, moderatorList) {
QString notificationMessage = "A ban has been put in with the following details:"; QString notificationMessage = "A ban has been added:";
if (!userName.isEmpty()) if (!userName.isEmpty())
notificationMessage.append("\n Username: " + userName); notificationMessage.append("\n Username: " + userName);
if (!address.isEmpty()) if (!address.isEmpty())
@ -895,7 +896,7 @@ Response::ResponseCode ServerSocketInterface::cmdRegisterAccount(const Command_R
return Response::RespUsernameInvalid; return Response::RespUsernameInvalid;
} }
if (userName.toLower() == "servatrice") if (userName.toLower().simplified() == "servatrice")
return Response::RespUsernameInvalid; return Response::RespUsernameInvalid;
if(sqlInterface->userExists(userName)) if(sqlInterface->userExists(userName))