display reason for ban to banned user

This commit is contained in:
Max-Wilhelm Bruker 2012-01-01 19:38:52 +01:00
parent 6344b987de
commit ff3eb9b5f4
19 changed files with 98 additions and 59 deletions

View file

@ -4,5 +4,12 @@ message Event_ConnectionClosed {
extend SessionEvent {
optional Event_ConnectionClosed ext = 1002;
}
optional string reason = 1;
enum CloseReason {
OTHER = 1;
SERVER_SHUTDOWN = 2;
TOO_MANY_CONNECTIONS = 3;
BANNED = 4;
}
optional CloseReason reason = 1;
optional string reason_str = 2;
}

View file

@ -13,4 +13,5 @@ message Command_BanFromServer {
optional string address = 2;
optional uint32 minutes = 3;
optional string reason = 4;
optional string visible_reason = 5;
}

View file

@ -19,6 +19,7 @@ message Response {
RespInIgnoreList = 16;
RespWouldOverwriteOldSession = 17;
RespChatFlood = 18;
RespUserIsBanned = 19;
}
enum ResponseType {
JOIN_ROOM = 1000;

View file

@ -8,4 +8,5 @@ message Response_Login {
optional ServerInfo_User user_info = 1;
repeated ServerInfo_User buddy_list = 2;
repeated ServerInfo_User ignore_list = 3;
optional string denied_reason_str = 4;
}

View file

@ -49,13 +49,13 @@ void Server::prepareDestroy()
delete roomIterator.next().value();
}
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password)
AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reasonStr)
{
QMutexLocker locker(&serverMutex);
if (name.size() > 35)
name = name.left(35);
AuthenticationResult authState = checkUserPassword(session, name, password);
if (authState == PasswordWrong)
AuthenticationResult authState = checkUserPassword(session, name, password, reasonStr);
if ((authState == NotLoggedIn) || (authState == UserIsBanned))
return authState;
ServerInfo_User data = getUserData(name);

View file

@ -11,7 +11,7 @@ class Server_Game;
class Server_Room;
class Server_ProtocolHandler;
enum AuthenticationResult { PasswordWrong = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3 };
enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3, UserIsBanned = 4 };
class Server : public QObject
{
@ -24,7 +24,7 @@ public:
mutable QMutex serverMutex;
Server(QObject *parent = 0);
~Server();
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password);
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason);
const QMap<int, Server_Room *> &getRooms() { return rooms; }
int getNextGameId() { return nextGameId++; }
@ -55,7 +55,7 @@ protected:
virtual int startSession(const QString &userName, const QString &address) = 0;
virtual void endSession(int sessionId) = 0;
virtual bool userExists(const QString &user) = 0;
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password) = 0;
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reason) = 0;
virtual ServerInfo_User getUserData(const QString &name) = 0;
int getUsersCount() const;
int getGamesCount() const;

View file

@ -85,7 +85,7 @@
#include <google/protobuf/descriptor.h>
Server_ProtocolHandler::Server_ProtocolHandler(Server *_server, QObject *parent)
: QObject(parent), server(_server), authState(PasswordWrong), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), sessionId(-1), timeRunning(0), lastDataReceived(0), gameListMutex(QMutex::Recursive)
: QObject(parent), server(_server), authState(NotLoggedIn), acceptsUserListChanges(false), acceptsRoomListChanges(false), userInfo(0), sessionId(-1), timeRunning(0), lastDataReceived(0), gameListMutex(QMutex::Recursive)
{
connect(server, SIGNAL(pingClockTimeout()), this, SLOT(pingClockTimeout()));
}
@ -247,7 +247,7 @@ Response::ResponseCode Server_ProtocolHandler::processSessionCommandContainer(co
Response::ResponseCode Server_ProtocolHandler::processRoomCommandContainer(const CommandContainer &cont, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
Server_Room *room = rooms.value(cont.room_id(), 0);
@ -282,7 +282,7 @@ Response::ResponseCode Server_ProtocolHandler::processRoomCommandContainer(const
Response::ResponseCode Server_ProtocolHandler::processGameCommandContainer(const CommandContainer &cont, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
gameListMutex.lock();
@ -493,11 +493,19 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
QString userName = QString::fromStdString(cmd.user_name()).simplified();
if (userName.isEmpty() || (userInfo != 0))
return Response::RespContextError;
authState = server->loginUser(this, userName, QString::fromStdString(cmd.password()));
if (authState == PasswordWrong)
return Response::RespWrongPassword;
if (authState == WouldOverwriteOldSession)
return Response::RespWouldOverwriteOldSession;
QString reasonStr;
AuthenticationResult res = server->loginUser(this, userName, QString::fromStdString(cmd.password()), reasonStr);
switch (res) {
case UserIsBanned: {
Response_Login *re = new Response_Login;
re->set_denied_reason_str(reasonStr.toStdString());
rc.setResponseExtension(re);
return Response::RespUserIsBanned;
}
case NotLoggedIn: return Response::RespWrongPassword;
case WouldOverwriteOldSession: return Response::RespWouldOverwriteOldSession;
default: authState = res;
}
userName = QString::fromStdString(userInfo->name());
Event_ServerMessage event;
@ -505,8 +513,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
rc.enqueuePostResponseItem(ServerMessage::SESSION_EVENT, prepareSessionEvent(event));
Response_Login *re = new Response_Login;
// XXX stimmt so nicht, beim alten Kopierkonstruktor wurde hier "true" übergeben
re->mutable_user_info()->CopyFrom(*userInfo);
re->mutable_user_info()->CopyFrom(copyUserInfo(true));
if (authState == PasswordRight) {
QMapIterator<QString, ServerInfo_User> buddyIterator(server->getBuddyList(userName));
@ -569,7 +576,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
Response::ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
QString receiver = QString::fromStdString(cmd.user_name());
@ -592,7 +599,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message
Response::ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
server->serverMutex.lock();
@ -618,7 +625,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_G
Response::ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
QString userName = QString::fromStdString(cmd.user_name());
@ -638,7 +645,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdGetUserInfo(const Command_GetU
Response::ResponseCode Server_ProtocolHandler::cmdListRooms(const Command_ListRooms & /*cmd*/, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
Event_ListRooms event;
@ -653,7 +660,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdListRooms(const Command_ListRo
Response::ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoom &cmd, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
if (rooms.contains(cmd.room_id()))
@ -681,7 +688,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoo
Response::ResponseCode Server_ProtocolHandler::cmdListUsers(const Command_ListUsers & /*cmd*/, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
Response_ListUsers *re = new Response_ListUsers;
@ -731,7 +738,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdRoomSay(const Command_RoomSay
Response::ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
if (server->getMaxGamesPerUser() > 0)
@ -779,7 +786,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdCreateGame(const Command_Creat
Response::ResponseCode Server_ProtocolHandler::cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room, ResponseContainer &rc)
{
if (authState == PasswordWrong)
if (authState == NotLoggedIn)
return Response::RespLoginNeeded;
QMutexLocker gameListLocker(&gameListMutex);