improved banning and deck hashing

This commit is contained in:
Max-Wilhelm Bruker 2011-11-01 22:44:51 +01:00
parent 9fe8f6fc03
commit 632e9bbff3
22 changed files with 211 additions and 92 deletions

View file

@ -565,7 +565,13 @@ void DeckList::updateDeckHash()
}
}
cardList.sort();
deckHash = QCryptographicHash::hash(cardList.join(";").toUtf8(), QCryptographicHash::Sha1).toBase64().left(10);
QByteArray deckHashArray = QCryptographicHash::hash(cardList.join(";").toUtf8(), QCryptographicHash::Sha1);
quint64 number = (((quint64) (unsigned char) deckHashArray[0]) << 32)
+ (((quint64) (unsigned char) deckHashArray[1]) << 24)
+ (((quint64) (unsigned char) deckHashArray[2] << 16))
+ (((quint64) (unsigned char) deckHashArray[3]) << 8)
+ (quint64) (unsigned char) deckHashArray[4];
deckHash = QString::number(number, 32).rightJustified(8, '0');
emit deckHashChanged();
}

View file

@ -12,22 +12,24 @@ CardToMove::CardToMove(int _cardId, bool _faceDown, const QString &_pt, bool _ta
insertItem(new SerializableItem_Bool("tapped", _tapped));
}
ServerInfo_User::ServerInfo_User(const QString &_name, int _userLevel, const QString &_realName, Gender _gender, const QString &_country, const QByteArray &_avatarBmp)
ServerInfo_User::ServerInfo_User(const QString &_name, int _userLevel, const QString &_address, const QString &_realName, Gender _gender, const QString &_country, const QByteArray &_avatarBmp)
: SerializableItem_Map("user")
{
insertItem(new SerializableItem_String("name", _name));
insertItem(new SerializableItem_Int("userlevel", _userLevel));
insertItem(new SerializableItem_String("address", _address));
insertItem(new SerializableItem_String("real_name", _realName));
insertItem(new SerializableItem_Int("gender", _gender));
insertItem(new SerializableItem_String("country", _country));
insertItem(new SerializableItem_ByteArray("avatar_bmp", _avatarBmp));
}
ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete)
ServerInfo_User::ServerInfo_User(const ServerInfo_User *other, bool complete, bool moderatorInfo)
: SerializableItem_Map("user")
{
insertItem(new SerializableItem_String("name", other->getName()));
insertItem(new SerializableItem_Int("userlevel", other->getUserLevel()));
insertItem(new SerializableItem_String("address", moderatorInfo ? other->getAddress() : QString()));
insertItem(new SerializableItem_String("real_name", other->getRealName()));
insertItem(new SerializableItem_Int("gender", other->getGender()));
insertItem(new SerializableItem_String("country", other->getCountry()));

View file

@ -50,13 +50,15 @@ public:
Male = 0,
Female = 1
};
ServerInfo_User(const QString &_name = QString(), int _userLevel = IsNothing, const QString &_realName = QString(), Gender _gender = GenderUnknown, const QString &_country = QString(), const QByteArray &_avatarBmp = QByteArray());
ServerInfo_User(const ServerInfo_User *other, bool complete = true);
ServerInfo_User(const QString &_name = QString(), int _userLevel = IsNothing, const QString &_address = QString(), const QString &_realName = QString(), Gender _gender = GenderUnknown, const QString &_country = QString(), const QByteArray &_avatarBmp = QByteArray());
ServerInfo_User(const ServerInfo_User *other, bool complete = true, bool moderatorInfo = false);
static SerializableItem *newItem() { return new ServerInfo_User; }
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
void setName(const QString &_name) { static_cast<SerializableItem_String *>(itemMap.value("name"))->setData(_name); }
int getUserLevel() const { return static_cast<SerializableItem_Int *>(itemMap.value("userlevel"))->getData(); }
void setUserLevel(int _userLevel) { static_cast<SerializableItem_Int *>(itemMap.value("userlevel"))->setData(_userLevel); }
QString getAddress() const { return static_cast<SerializableItem_String *>(itemMap.value("address"))->getData(); }
void setAddress(const QString &_address) { static_cast<SerializableItem_String *>(itemMap.value("address"))->setData(_address); }
QString getRealName() const { return static_cast<SerializableItem_String *>(itemMap.value("real_name"))->getData(); }
Gender getGender() const { return static_cast<Gender>(static_cast<SerializableItem_Int *>(itemMap.value("gender"))->getData()); }
QString getCountry() const { return static_cast<SerializableItem_String *>(itemMap.value("country"))->getData(); }

View file

@ -489,10 +489,11 @@ Command_ShutdownServer::Command_ShutdownServer(const QString &_reason, int _minu
insertItem(new SerializableItem_String("reason", _reason));
insertItem(new SerializableItem_Int("minutes", _minutes));
}
Command_BanFromServer::Command_BanFromServer(const QString &_userName, int _minutes, const QString &_reason)
Command_BanFromServer::Command_BanFromServer(const QString &_userName, const QString &_address, int _minutes, const QString &_reason)
: ModeratorCommand("ban_from_server")
{
insertItem(new SerializableItem_String("user_name", _userName));
insertItem(new SerializableItem_String("address", _address));
insertItem(new SerializableItem_Int("minutes", _minutes));
insertItem(new SerializableItem_String("reason", _reason));
}

View file

@ -81,4 +81,4 @@
6:mulligan:i,number
7:update_server_message
7:shutdown_server:s,reason:i,minutes
8:ban_from_server:s,user_name:i,minutes:s,reason
8:ban_from_server:s,user_name:s,address:i,minutes:s,reason

View file

@ -743,8 +743,9 @@ public:
class Command_BanFromServer : public ModeratorCommand {
Q_OBJECT
public:
Command_BanFromServer(const QString &_userName = QString(), int _minutes = -1, const QString &_reason = QString());
Command_BanFromServer(const QString &_userName = QString(), const QString &_address = QString(), int _minutes = -1, const QString &_reason = QString());
QString getUserName() const { return static_cast<SerializableItem_String *>(itemMap.value("user_name"))->getData(); };
QString getAddress() const { return static_cast<SerializableItem_String *>(itemMap.value("address"))->getData(); };
int getMinutes() const { return static_cast<SerializableItem_Int *>(itemMap.value("minutes"))->getData(); };
QString getReason() const { return static_cast<SerializableItem_String *>(itemMap.value("reason"))->getData(); };
static SerializableItem *newItem() { return new Command_BanFromServer; }

View file

@ -57,6 +57,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
return authState;
ServerInfo_User *data = getUserData(name);
data->setAddress(session->getAddress());
name = data->getName(); // Compensate for case indifference
if (authState == PasswordRight) {

View file

@ -402,7 +402,7 @@ ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, Co
Server_ProtocolHandler *handler = server->getUsers().value(cmd->getUserName());
if (!handler)
return RespNameNotFound;
result = new ServerInfo_User(handler->getUserInfo());
result = new ServerInfo_User(handler->getUserInfo(), true, userInfo->getUserLevel() & ServerInfo_User::IsModerator);
}
cont->setResponse(new Response_GetUserInfo(cont->getCmdId(), RespOk, result));

View file

@ -106,6 +106,7 @@ public:
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
ServerInfo_User *getUserInfo() const { return userInfo; }
virtual QString getAddress() const = 0;
void setUserInfo(ServerInfo_User *_userInfo) { userInfo = _userInfo; }
const QMap<QString, ServerInfo_User *> &getBuddyList() const { return buddyList; }
const QMap<QString, ServerInfo_User *> &getIgnoreList() const { return ignoreList; }