mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
show ban duration in client
This commit is contained in:
parent
78d188c462
commit
13b992cf12
15 changed files with 159 additions and 91 deletions
|
|
@ -12,4 +12,5 @@ message Event_ConnectionClosed {
|
|||
}
|
||||
optional CloseReason reason = 1;
|
||||
optional string reason_str = 2;
|
||||
optional uint32 end_time = 3;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,4 +9,5 @@ message Response_Login {
|
|||
repeated ServerInfo_User buddy_list = 2;
|
||||
repeated ServerInfo_User ignore_list = 3;
|
||||
optional string denied_reason_str = 4;
|
||||
optional uint64 denied_end_time = 5;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,14 +66,14 @@ void Server::prepareDestroy()
|
|||
roomsLock.unlock();
|
||||
}
|
||||
|
||||
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reasonStr)
|
||||
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reasonStr, int &secondsLeft)
|
||||
{
|
||||
if (name.size() > 35)
|
||||
name = name.left(35);
|
||||
|
||||
QWriteLocker locker(&clientsLock);
|
||||
|
||||
AuthenticationResult authState = checkUserPassword(session, name, password, reasonStr);
|
||||
AuthenticationResult authState = checkUserPassword(session, name, password, reasonStr, secondsLeft);
|
||||
if ((authState == NotLoggedIn) || (authState == UserIsBanned))
|
||||
return authState;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public:
|
|||
mutable QReadWriteLock clientsLock, roomsLock; // locking order: roomsLock before clientsLock
|
||||
Server(QObject *parent = 0);
|
||||
~Server();
|
||||
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason);
|
||||
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason, int &secondsLeft);
|
||||
const QMap<int, Server_Room *> &getRooms() { return rooms; }
|
||||
virtual int getNextGameId() { return nextGameId++; }
|
||||
virtual int getNextReplayId() { return nextReplayId++; }
|
||||
|
|
@ -111,7 +111,7 @@ protected:
|
|||
virtual qint64 startSession(const QString &userName, const QString &address) { return 0; }
|
||||
virtual void endSession(qint64 sessionId) { }
|
||||
virtual bool userExists(const QString &user) { return false; }
|
||||
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reason) { return UnknownUser; }
|
||||
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reason, int &secondsLeft) { return UnknownUser; }
|
||||
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
|
||||
int getUsersCount() const;
|
||||
int getGamesCount() const;
|
||||
|
|
|
|||
|
|
@ -337,11 +337,14 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
|
|||
if (userName.isEmpty() || (userInfo != 0))
|
||||
return Response::RespContextError;
|
||||
QString reasonStr;
|
||||
AuthenticationResult res = server->loginUser(this, userName, QString::fromStdString(cmd.password()), reasonStr);
|
||||
int banSecondsLeft = 0;
|
||||
AuthenticationResult res = server->loginUser(this, userName, QString::fromStdString(cmd.password()), reasonStr, banSecondsLeft);
|
||||
switch (res) {
|
||||
case UserIsBanned: {
|
||||
Response_Login *re = new Response_Login;
|
||||
re->set_denied_reason_str(reasonStr.toStdString());
|
||||
if (banSecondsLeft != 0)
|
||||
re->set_denied_end_time(QDateTime::currentDateTime().addSecs(banSecondsLeft).toTime_t());
|
||||
rc.setResponseExtension(re);
|
||||
return Response::RespUserIsBanned;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue