server shutdown function

This commit is contained in:
Max-Wilhelm Bruker 2011-06-24 18:45:39 +02:00
parent 5e3db65846
commit a4c3d48389
33 changed files with 1410 additions and 604 deletions

View file

@ -167,6 +167,15 @@ public:
void setGameId(int _gameId) { static_cast<SerializableItem_Int *>(itemMap.value("game_id"))->setData(_gameId); }
};
class ModeratorCommand : public Command {
Q_OBJECT
public:
ModeratorCommand(const QString &_cmdName)
: Command(_cmdName)
{
}
};
class AdminCommand : public Command {
Q_OBJECT
public:

View file

@ -65,19 +65,21 @@ ItemId_Event_DumpZone = 1063,
ItemId_Event_StopDumpZone = 1064,
ItemId_Event_RemoveFromList = 1065,
ItemId_Event_ServerMessage = 1066,
ItemId_Event_ConnectionClosed = 1067,
ItemId_Event_Message = 1068,
ItemId_Event_GameJoined = 1069,
ItemId_Event_UserLeft = 1070,
ItemId_Event_LeaveRoom = 1071,
ItemId_Event_RoomSay = 1072,
ItemId_Context_ReadyStart = 1073,
ItemId_Context_Concede = 1074,
ItemId_Context_DeckSelect = 1075,
ItemId_Context_UndoDraw = 1076,
ItemId_Context_MoveCard = 1077,
ItemId_Context_Mulligan = 1078,
ItemId_Command_UpdateServerMessage = 1079,
ItemId_Command_BanFromServer = 1080,
ItemId_Other = 1081
ItemId_Event_ServerShutdown = 1067,
ItemId_Event_ConnectionClosed = 1068,
ItemId_Event_Message = 1069,
ItemId_Event_GameJoined = 1070,
ItemId_Event_UserLeft = 1071,
ItemId_Event_LeaveRoom = 1072,
ItemId_Event_RoomSay = 1073,
ItemId_Context_ReadyStart = 1074,
ItemId_Context_Concede = 1075,
ItemId_Context_DeckSelect = 1076,
ItemId_Context_UndoDraw = 1077,
ItemId_Context_MoveCard = 1078,
ItemId_Context_Mulligan = 1079,
ItemId_Command_UpdateServerMessage = 1080,
ItemId_Command_ShutdownServer = 1081,
ItemId_Command_BanFromServer = 1082,
ItemId_Other = 1083
};

View file

@ -398,6 +398,12 @@ Event_ServerMessage::Event_ServerMessage(const QString &_message)
{
insertItem(new SerializableItem_String("message", _message));
}
Event_ServerShutdown::Event_ServerShutdown(const QString &_reason, int _minutes)
: GenericEvent("server_shutdown")
{
insertItem(new SerializableItem_String("reason", _reason));
insertItem(new SerializableItem_Int("minutes", _minutes));
}
Event_ConnectionClosed::Event_ConnectionClosed(const QString &_reason)
: GenericEvent("connection_closed")
{
@ -467,8 +473,14 @@ Command_UpdateServerMessage::Command_UpdateServerMessage()
: AdminCommand("update_server_message")
{
}
Command_ShutdownServer::Command_ShutdownServer(const QString &_reason, int _minutes)
: AdminCommand("shutdown_server")
{
insertItem(new SerializableItem_String("reason", _reason));
insertItem(new SerializableItem_Int("minutes", _minutes));
}
Command_BanFromServer::Command_BanFromServer(const QString &_userName, int _minutes)
: AdminCommand("ban_from_server")
: ModeratorCommand("ban_from_server")
{
insertItem(new SerializableItem_String("user_name", _userName));
insertItem(new SerializableItem_Int("minutes", _minutes));
@ -541,6 +553,7 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
itemNameHash.insert("generic_eventremove_from_list", Event_RemoveFromList::newItem);
itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::newItem);
itemNameHash.insert("generic_eventserver_shutdown", Event_ServerShutdown::newItem);
itemNameHash.insert("generic_eventconnection_closed", Event_ConnectionClosed::newItem);
itemNameHash.insert("generic_eventmessage", Event_Message::newItem);
itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem);
@ -554,5 +567,6 @@ void ProtocolItem::initializeHashAuto()
itemNameHash.insert("game_event_contextmove_card", Context_MoveCard::newItem);
itemNameHash.insert("game_event_contextmulligan", Context_Mulligan::newItem);
itemNameHash.insert("cmdupdate_server_message", Command_UpdateServerMessage::newItem);
itemNameHash.insert("cmdshutdown_server", Command_ShutdownServer::newItem);
itemNameHash.insert("cmdban_from_server", Command_BanFromServer::newItem);
}

View file

@ -64,6 +64,7 @@
3:stop_dump_zone:i,zone_owner_id:s,zone
4:remove_from_list:s,list:s,user_name
4:server_message:s,message
4:server_shutdown:s,reason:i,minutes
4:connection_closed:s,reason
4:message:s,sender_name:s,receiver_name:s,text
4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,spectators_can_talk:b,spectators_see_everything:b,resuming
@ -77,4 +78,5 @@
6:move_card
6:mulligan:i,number
7:update_server_message
7:ban_from_server:s,user_name:i,minutes
7:shutdown_server:s,reason:i,minutes
8:ban_from_server:s,user_name:i,minutes

View file

@ -598,6 +598,15 @@ public:
static SerializableItem *newItem() { return new Event_ServerMessage; }
int getItemId() const { return ItemId_Event_ServerMessage; }
};
class Event_ServerShutdown : public GenericEvent {
Q_OBJECT
public:
Event_ServerShutdown(const QString &_reason = QString(), int _minutes = -1);
QString getReason() const { return static_cast<SerializableItem_String *>(itemMap.value("reason"))->getData(); };
int getMinutes() const { return static_cast<SerializableItem_Int *>(itemMap.value("minutes"))->getData(); };
static SerializableItem *newItem() { return new Event_ServerShutdown; }
int getItemId() const { return ItemId_Event_ServerShutdown; }
};
class Event_ConnectionClosed : public GenericEvent {
Q_OBJECT
public:
@ -706,7 +715,16 @@ public:
static SerializableItem *newItem() { return new Command_UpdateServerMessage; }
int getItemId() const { return ItemId_Command_UpdateServerMessage; }
};
class Command_BanFromServer : public AdminCommand {
class Command_ShutdownServer : public AdminCommand {
Q_OBJECT
public:
Command_ShutdownServer(const QString &_reason = QString(), int _minutes = -1);
QString getReason() const { return static_cast<SerializableItem_String *>(itemMap.value("reason"))->getData(); };
int getMinutes() const { return static_cast<SerializableItem_Int *>(itemMap.value("minutes"))->getData(); };
static SerializableItem *newItem() { return new Command_ShutdownServer; }
int getItemId() const { return ItemId_Command_ShutdownServer; }
};
class Command_BanFromServer : public ModeratorCommand {
Q_OBJECT
public:
Command_BanFromServer(const QString &_userName = QString(), int _minutes = -1);

View file

@ -80,6 +80,13 @@ while (<file>) {
$parentConstructorCall = "$baseClass(\"$name1\")";
$constructorParamsH = "";
$constructorParamsCpp = "";
} elsif ($type == 8) {
$type = 'cmd';
$namePrefix = 'Command';
$baseClass = 'ModeratorCommand';
$parentConstructorCall = "$baseClass(\"$name1\")";
$constructorParamsH = "";
$constructorParamsCpp = "";
}
$className = $namePrefix . '_' . $name2;
$itemEnum .= "ItemId_$className = " . ++$itemId . ",\n";

View file

@ -23,6 +23,7 @@
#include "server_room.h"
#include "server_protocolhandler.h"
#include "protocol_datastructures.h"
#include <QCoreApplication>
#include <QDebug>
Server::Server(QObject *parent)

View file

@ -142,6 +142,17 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
default: return RespInvalidCommand;
}
}
ModeratorCommand *moderatorCommand = qobject_cast<ModeratorCommand *>(command);
if (moderatorCommand) {
qDebug() << "received ModeratorCommand";
if (!(userInfo->getUserLevel() & ServerInfo_User::IsModerator))
return RespLoginNeeded;
switch (command->getItemId()) {
case ItemId_Command_BanFromServer: return cmdBanFromServer(static_cast<Command_BanFromServer *>(command), cont);
default: return RespInvalidCommand;
}
}
AdminCommand *adminCommand = qobject_cast<AdminCommand *>(command);
if (adminCommand) {
qDebug() << "received AdminCommand";
@ -149,8 +160,8 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
return RespLoginNeeded;
switch (command->getItemId()) {
case ItemId_Command_ShutdownServer: return cmdShutdownServer(static_cast<Command_ShutdownServer *>(command), cont);
case ItemId_Command_UpdateServerMessage: return cmdUpdateServerMessage(static_cast<Command_UpdateServerMessage *>(command), cont);
case ItemId_Command_BanFromServer: return cmdBanFromServer(static_cast<Command_BanFromServer *>(command), cont);
default: return RespInvalidCommand;
}
}

View file

@ -87,8 +87,9 @@ private:
ResponseCode cmdDumpZone(Command_DumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
ResponseCode cmdRevealCards(Command_RevealCards *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
virtual ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdBanFromServer(Command_BanFromServer *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdShutdownServer(Command_ShutdownServer *cmd, CommandContainer *cont) = 0;
virtual ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage *cmd, CommandContainer *cont) = 0;
ResponseCode processCommandHelper(Command *command, CommandContainer *cont);
private slots: