when banning an ip address, terminate the connection of everyone with that address
This commit is contained in:
parent
7faa033855
commit
eb06d6b4ea
3 changed files with 21 additions and 5 deletions
|
@ -394,6 +394,16 @@ int Servatrice::getUsersWithAddress(const QHostAddress &address) const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ServerSocketInterface *> Servatrice::getUsersWithAddressAsList(const QHostAddress &address) const
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&serverMutex);
|
||||||
|
QList<ServerSocketInterface *> result;
|
||||||
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
|
if (static_cast<ServerSocketInterface *>(clients[i])->getPeerAddress() == address)
|
||||||
|
result.append(static_cast<ServerSocketInterface *>(clients[i]));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int Servatrice::startSession(const QString &userName, const QString &address)
|
int Servatrice::startSession(const QString &userName, const QString &address)
|
||||||
{
|
{
|
||||||
if (authenticationMethod == AuthenticationNone)
|
if (authenticationMethod == AuthenticationNone)
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
void updateLoginMessage();
|
void updateLoginMessage();
|
||||||
ServerInfo_User getUserData(const QString &name);
|
ServerInfo_User getUserData(const QString &name);
|
||||||
int getUsersWithAddress(const QHostAddress &address) const;
|
int getUsersWithAddress(const QHostAddress &address) const;
|
||||||
|
QList<ServerSocketInterface *> getUsersWithAddressAsList(const QHostAddress &address) const;
|
||||||
QMap<QString, ServerInfo_User> getBuddyList(const QString &name);
|
QMap<QString, ServerInfo_User> getBuddyList(const QString &name);
|
||||||
QMap<QString, ServerInfo_User> getIgnoreList(const QString &name);
|
QMap<QString, ServerInfo_User> getIgnoreList(const QString &name);
|
||||||
bool isInBuddyList(const QString &whoseList, const QString &who);
|
bool isInBuddyList(const QString &whoseList, const QString &who);
|
||||||
|
|
|
@ -505,16 +505,21 @@ Response::ResponseCode ServerSocketInterface::cmdBanFromServer(const Command_Ban
|
||||||
servatrice->execSqlQuery(query);
|
servatrice->execSqlQuery(query);
|
||||||
servatrice->dbMutex.unlock();
|
servatrice->dbMutex.unlock();
|
||||||
|
|
||||||
|
QList<ServerSocketInterface *> userList = servatrice->getUsersWithAddressAsList(QHostAddress(address));
|
||||||
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
|
ServerSocketInterface *user = static_cast<ServerSocketInterface *>(server->getUsers().value(userName));
|
||||||
if (user) {
|
if (user && !userList.contains(user))
|
||||||
|
userList.append(user);
|
||||||
|
if (!userList.isEmpty()) {
|
||||||
Event_ConnectionClosed event;
|
Event_ConnectionClosed event;
|
||||||
event.set_reason(Event_ConnectionClosed::BANNED);
|
event.set_reason(Event_ConnectionClosed::BANNED);
|
||||||
if (cmd.has_visible_reason())
|
if (cmd.has_visible_reason())
|
||||||
event.set_reason_str(cmd.visible_reason());
|
event.set_reason_str(cmd.visible_reason());
|
||||||
SessionEvent *se = user->prepareSessionEvent(event);
|
for (int i = 0; i < userList.size(); ++i) {
|
||||||
user->sendProtocolItem(*se);
|
SessionEvent *se = userList[i]->prepareSessionEvent(event);
|
||||||
|
userList[i]->sendProtocolItem(*se);
|
||||||
|
userList[i]->deleteLater();
|
||||||
delete se;
|
delete se;
|
||||||
user->deleteLater();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response::RespOk;
|
return Response::RespOk;
|
||||||
|
|
Loading…
Reference in a new issue