Commit eb06d6b4 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

when banning an ip address, terminate the connection of everyone with that address

parent 7faa0338
...@@ -394,6 +394,16 @@ int Servatrice::getUsersWithAddress(const QHostAddress &address) const ...@@ -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: ...@@ -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 ...@@ -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);
delete se; userList[i]->sendProtocolItem(*se);
user->deleteLater(); userList[i]->deleteLater();
delete se;
}
} }
return Response::RespOk; return Response::RespOk;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment