Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
bd9e142d
Commit
bd9e142d
authored
Jan 14, 2011
by
Max-Wilhelm Bruker
Browse files
added admin tab; server status message update
parent
714a0eee
Changes
20
Hide whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
bd9e142d
...
@@ -58,6 +58,7 @@ HEADERS += src/abstractcounter.h \
...
@@ -58,6 +58,7 @@ HEADERS += src/abstractcounter.h \
src
/
tab_game
.
h
\
src
/
tab_game
.
h
\
src
/
tab_deck_storage
.
h
\
src
/
tab_deck_storage
.
h
\
src
/
tab_supervisor
.
h
\
src
/
tab_supervisor
.
h
\
src
/
tab_admin
.
h
\
src
/
userlist
.
h
\
src
/
userlist
.
h
\
src
/
userinfobox
.
h
\
src
/
userinfobox
.
h
\
src
/
remotedecklist_treewidget
.
h
\
src
/
remotedecklist_treewidget
.
h
\
...
@@ -139,6 +140,7 @@ SOURCES += src/abstractcounter.cpp \
...
@@ -139,6 +140,7 @@ SOURCES += src/abstractcounter.cpp \
src
/
tab_game
.
cpp
\
src
/
tab_game
.
cpp
\
src
/
tab_deck_storage
.
cpp
\
src
/
tab_deck_storage
.
cpp
\
src
/
tab_supervisor
.
cpp
\
src
/
tab_supervisor
.
cpp
\
src
/
tab_admin
.
cpp
\
src
/
userlist
.
cpp
\
src
/
userlist
.
cpp
\
src
/
userinfobox
.
cpp
\
src
/
userinfobox
.
cpp
\
src
/
remotedecklist_treewidget
.
cpp
\
src
/
remotedecklist_treewidget
.
cpp
\
...
...
cockatrice/src/localserverinterface.h
View file @
bd9e142d
...
@@ -16,6 +16,7 @@ private:
...
@@ -16,6 +16,7 @@ private:
ResponseCode
cmdDeckDel
(
Command_DeckDel
*
/*cmd*/
,
CommandContainer
*
/*cont*/
)
{
return
RespFunctionNotAllowed
;
}
ResponseCode
cmdDeckDel
(
Command_DeckDel
*
/*cmd*/
,
CommandContainer
*
/*cont*/
)
{
return
RespFunctionNotAllowed
;
}
ResponseCode
cmdDeckUpload
(
Command_DeckUpload
*
/*cmd*/
,
CommandContainer
*
/*cont*/
)
{
return
RespFunctionNotAllowed
;
}
ResponseCode
cmdDeckUpload
(
Command_DeckUpload
*
/*cmd*/
,
CommandContainer
*
/*cont*/
)
{
return
RespFunctionNotAllowed
;
}
ResponseCode
cmdDeckDownload
(
Command_DeckDownload
*
/*cmd*/
,
CommandContainer
*
/*cont*/
)
{
return
RespFunctionNotAllowed
;
}
ResponseCode
cmdDeckDownload
(
Command_DeckDownload
*
/*cmd*/
,
CommandContainer
*
/*cont*/
)
{
return
RespFunctionNotAllowed
;
}
ResponseCode
cmdUpdateServerMessage
(
Command_UpdateServerMessage
*
/*cmd*/
,
CommandContainer
*
/*cont*/
)
{
return
RespFunctionNotAllowed
;
}
public:
public:
LocalServerInterface
(
LocalServer
*
_server
);
LocalServerInterface
(
LocalServer
*
_server
);
~
LocalServerInterface
();
~
LocalServerInterface
();
...
...
cockatrice/src/remoteclient.cpp
View file @
bd9e142d
...
@@ -43,15 +43,16 @@ void RemoteClient::slotConnected()
...
@@ -43,15 +43,16 @@ void RemoteClient::slotConnected()
void
RemoteClient
::
loginResponse
(
ProtocolResponse
*
response
)
void
RemoteClient
::
loginResponse
(
ProtocolResponse
*
response
)
{
{
Response_Login
*
resp
=
qobject_cast
<
Response_Login
*>
(
response
);
if
(
response
->
getResponseCode
()
==
RespOk
)
{
if
(
!
resp
)
Response_Login
*
resp
=
qobject_cast
<
Response_Login
*>
(
response
);
disconnectFromServer
();
if
(
!
resp
)
{
disconnectFromServer
();
if
(
resp
->
getResponseCode
()
==
RespOk
)
{
return
;
}
setStatus
(
StatusLoggedIn
);
setStatus
(
StatusLoggedIn
);
emit
userInfoChanged
(
resp
->
getUserInfo
());
emit
userInfoChanged
(
resp
->
getUserInfo
());
}
else
{
}
else
{
emit
serverError
(
resp
->
getResponseCode
());
emit
serverError
(
resp
onse
->
getResponseCode
());
setStatus
(
StatusDisconnecting
);
setStatus
(
StatusDisconnecting
);
}
}
}
}
...
...
cockatrice/src/tab_admin.cpp
0 → 100644
View file @
bd9e142d
#include
<QVBoxLayout>
#include
<QPushButton>
#include
<QGroupBox>
#include
<QMessageBox>
#include
"tab_admin.h"
#include
"abstractclient.h"
#include
"protocol_items.h"
TabAdmin
::
TabAdmin
(
AbstractClient
*
_client
,
QWidget
*
parent
)
:
Tab
(
parent
),
client
(
_client
)
{
updateServerMessageButton
=
new
QPushButton
;
connect
(
updateServerMessageButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actUpdateServerMessage
()));
QVBoxLayout
*
vbox
=
new
QVBoxLayout
;
vbox
->
addWidget
(
updateServerMessageButton
);
vbox
->
addStretch
();
adminGroupBox
=
new
QGroupBox
;
adminGroupBox
->
setLayout
(
vbox
);
adminGroupBox
->
setEnabled
(
false
);
unlockButton
=
new
QPushButton
;
connect
(
unlockButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actUnlock
()));
lockButton
=
new
QPushButton
;
lockButton
->
setEnabled
(
false
);
connect
(
lockButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actLock
()));
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addWidget
(
adminGroupBox
);
mainLayout
->
addWidget
(
unlockButton
);
mainLayout
->
addWidget
(
lockButton
);
retranslateUi
();
setLayout
(
mainLayout
);
}
void
TabAdmin
::
retranslateUi
()
{
updateServerMessageButton
->
setText
(
tr
(
"Update server &message"
));
adminGroupBox
->
setTitle
(
tr
(
"Server administration functions"
));
unlockButton
->
setText
(
tr
(
"&Unlock functions"
));
lockButton
->
setText
(
tr
(
"&Lock functions"
));
}
void
TabAdmin
::
actUpdateServerMessage
()
{
client
->
sendCommand
(
new
Command_UpdateServerMessage
());
}
void
TabAdmin
::
actUnlock
()
{
if
(
QMessageBox
::
question
(
this
,
tr
(
"Unlock administration functions"
),
tr
(
"Do you really want to unlock the administration functions?"
),
QMessageBox
::
Yes
|
QMessageBox
::
No
)
==
QMessageBox
::
Yes
)
{
adminGroupBox
->
setEnabled
(
true
);
lockButton
->
setEnabled
(
true
);
unlockButton
->
setEnabled
(
false
);
}
}
void
TabAdmin
::
actLock
()
{
adminGroupBox
->
setEnabled
(
false
);
lockButton
->
setEnabled
(
false
);
unlockButton
->
setEnabled
(
true
);
}
\ No newline at end of file
cockatrice/src/tab_admin.h
0 → 100644
View file @
bd9e142d
#ifndef TAB_ADMIN_H
#define TAB_ADMIN_H
#include
"tab.h"
class
AbstractClient
;
class
QGroupBox
;
class
QPushButton
;
class
TabAdmin
:
public
Tab
{
Q_OBJECT
private:
AbstractClient
*
client
;
QPushButton
*
updateServerMessageButton
;
QGroupBox
*
adminGroupBox
;
QPushButton
*
unlockButton
,
*
lockButton
;
private
slots
:
void
actUpdateServerMessage
();
void
actUnlock
();
void
actLock
();
public:
TabAdmin
(
AbstractClient
*
_client
,
QWidget
*
parent
=
0
);
void
retranslateUi
();
QString
getTabText
()
const
{
return
tr
(
"Administration"
);
}
};
#endif
cockatrice/src/tab_server.cpp
View file @
bd9e142d
...
@@ -163,6 +163,7 @@ void TabServer::retranslateUi()
...
@@ -163,6 +163,7 @@ void TabServer::retranslateUi()
void
TabServer
::
processServerMessageEvent
(
Event_ServerMessage
*
event
)
void
TabServer
::
processServerMessageEvent
(
Event_ServerMessage
*
event
)
{
{
serverInfoBox
->
setHtml
(
event
->
getMessage
());
serverInfoBox
->
setHtml
(
event
->
getMessage
());
emit
userEvent
();
}
}
void
TabServer
::
processListUsersResponse
(
ProtocolResponse
*
response
)
void
TabServer
::
processListUsersResponse
(
ProtocolResponse
*
response
)
...
...
cockatrice/src/tab_supervisor.cpp
View file @
bd9e142d
...
@@ -5,13 +5,14 @@
...
@@ -5,13 +5,14 @@
#include
"tab_room.h"
#include
"tab_room.h"
#include
"tab_game.h"
#include
"tab_game.h"
#include
"tab_deck_storage.h"
#include
"tab_deck_storage.h"
#include
"tab_admin.h"
#include
"tab_message.h"
#include
"tab_message.h"
#include
"protocol_items.h"
#include
"protocol_items.h"
#include
"pixmapgenerator.h"
#include
"pixmapgenerator.h"
#include
<QDebug>
#include
<QDebug>
TabSupervisor
::
TabSupervisor
(
QWidget
*
parent
)
TabSupervisor
::
TabSupervisor
(
QWidget
*
parent
)
:
QTabWidget
(
parent
),
client
(
0
),
tabServer
(
0
),
tabDeckStorage
(
0
)
:
QTabWidget
(
parent
),
client
(
0
),
tabServer
(
0
),
tabDeckStorage
(
0
)
,
tabAdmin
(
0
)
{
{
tabChangedIcon
=
new
QIcon
(
":/resources/icon_tab_changed.svg"
);
tabChangedIcon
=
new
QIcon
(
":/resources/icon_tab_changed.svg"
);
setElideMode
(
Qt
::
ElideRight
);
setElideMode
(
Qt
::
ElideRight
);
...
@@ -69,8 +70,17 @@ void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *userInfo)
...
@@ -69,8 +70,17 @@ void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *userInfo)
myAddTab
(
tabServer
);
myAddTab
(
tabServer
);
updatePingTime
(
0
,
-
1
);
updatePingTime
(
0
,
-
1
);
tabDeckStorage
=
new
TabDeckStorage
(
client
);
if
(
userInfo
->
getUserLevel
()
&
ServerInfo_User
::
IsRegistered
)
{
myAddTab
(
tabDeckStorage
);
tabDeckStorage
=
new
TabDeckStorage
(
client
);
myAddTab
(
tabDeckStorage
);
}
else
tabDeckStorage
=
0
;
if
(
userInfo
->
getUserLevel
()
&
ServerInfo_User
::
IsAdmin
)
{
tabAdmin
=
new
TabAdmin
(
client
);
myAddTab
(
tabAdmin
);
}
else
tabAdmin
=
0
;
retranslateUi
();
retranslateUi
();
}
}
...
@@ -124,6 +134,8 @@ void TabSupervisor::updatePingTime(int value, int max)
...
@@ -124,6 +134,8 @@ void TabSupervisor::updatePingTime(int value, int max)
{
{
if
(
!
tabServer
)
if
(
!
tabServer
)
return
;
return
;
if
(
tabServer
->
getContentsChanged
())
return
;
setTabIcon
(
0
,
QIcon
(
PingPixmapGenerator
::
generatePixmap
(
15
,
value
,
max
)));
setTabIcon
(
0
,
QIcon
(
PingPixmapGenerator
::
generatePixmap
(
15
,
value
,
max
)));
}
}
...
...
cockatrice/src/tab_supervisor.h
View file @
bd9e142d
...
@@ -11,6 +11,7 @@ class TabServer;
...
@@ -11,6 +11,7 @@ class TabServer;
class
TabRoom
;
class
TabRoom
;
class
TabGame
;
class
TabGame
;
class
TabDeckStorage
;
class
TabDeckStorage
;
class
TabAdmin
;
class
TabMessage
;
class
TabMessage
;
class
RoomEvent
;
class
RoomEvent
;
class
GameEventContainer
;
class
GameEventContainer
;
...
@@ -28,6 +29,7 @@ private:
...
@@ -28,6 +29,7 @@ private:
QList
<
AbstractClient
*>
localClients
;
QList
<
AbstractClient
*>
localClients
;
TabServer
*
tabServer
;
TabServer
*
tabServer
;
TabDeckStorage
*
tabDeckStorage
;
TabDeckStorage
*
tabDeckStorage
;
TabAdmin
*
tabAdmin
;
QMap
<
int
,
TabRoom
*>
roomTabs
;
QMap
<
int
,
TabRoom
*>
roomTabs
;
QMap
<
int
,
TabGame
*>
gameTabs
;
QMap
<
int
,
TabGame
*>
gameTabs
;
QMap
<
QString
,
TabMessage
*>
messageTabs
;
QMap
<
QString
,
TabMessage
*>
messageTabs
;
...
...
common/protocol.h
View file @
bd9e142d
...
@@ -162,6 +162,15 @@ public:
...
@@ -162,6 +162,15 @@ public:
void
setGameId
(
int
_gameId
)
{
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"game_id"
))
->
setData
(
_gameId
);
}
void
setGameId
(
int
_gameId
)
{
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"game_id"
))
->
setData
(
_gameId
);
}
};
};
class
AdminCommand
:
public
Command
{
Q_OBJECT
public:
AdminCommand
(
const
QString
&
_cmdName
)
:
Command
(
_cmdName
)
{
}
};
class
Command_DeckUpload
:
public
Command
{
class
Command_DeckUpload
:
public
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
...
...
common/protocol_item_ids.h
View file @
bd9e142d
...
@@ -69,5 +69,6 @@ ItemId_Event_RoomSay = 1067,
...
@@ -69,5 +69,6 @@ ItemId_Event_RoomSay = 1067,
ItemId_Context_ReadyStart
=
1068
,
ItemId_Context_ReadyStart
=
1068
,
ItemId_Context_Concede
=
1069
,
ItemId_Context_Concede
=
1069
,
ItemId_Context_DeckSelect
=
1070
,
ItemId_Context_DeckSelect
=
1070
,
ItemId_Other
=
1071
ItemId_Command_UpdateServerMessage
=
1071
,
ItemId_Other
=
1072
};
};
common/protocol_items.cpp
View file @
bd9e142d
...
@@ -437,6 +437,10 @@ Context_DeckSelect::Context_DeckSelect(int _deckId)
...
@@ -437,6 +437,10 @@ Context_DeckSelect::Context_DeckSelect(int _deckId)
{
{
insertItem
(
new
SerializableItem_Int
(
"deck_id"
,
_deckId
));
insertItem
(
new
SerializableItem_Int
(
"deck_id"
,
_deckId
));
}
}
Command_UpdateServerMessage
::
Command_UpdateServerMessage
()
:
AdminCommand
(
"update_server_message"
)
{
}
void
ProtocolItem
::
initializeHashAuto
()
void
ProtocolItem
::
initializeHashAuto
()
{
{
itemNameHash
.
insert
(
"cmdping"
,
Command_Ping
::
newItem
);
itemNameHash
.
insert
(
"cmdping"
,
Command_Ping
::
newItem
);
...
@@ -509,4 +513,5 @@ void ProtocolItem::initializeHashAuto()
...
@@ -509,4 +513,5 @@ void ProtocolItem::initializeHashAuto()
itemNameHash
.
insert
(
"game_event_contextready_start"
,
Context_ReadyStart
::
newItem
);
itemNameHash
.
insert
(
"game_event_contextready_start"
,
Context_ReadyStart
::
newItem
);
itemNameHash
.
insert
(
"game_event_contextconcede"
,
Context_Concede
::
newItem
);
itemNameHash
.
insert
(
"game_event_contextconcede"
,
Context_Concede
::
newItem
);
itemNameHash
.
insert
(
"game_event_contextdeck_select"
,
Context_DeckSelect
::
newItem
);
itemNameHash
.
insert
(
"game_event_contextdeck_select"
,
Context_DeckSelect
::
newItem
);
itemNameHash
.
insert
(
"cmdupdate_server_message"
,
Command_UpdateServerMessage
::
newItem
);
}
}
common/protocol_items.dat
View file @
bd9e142d
...
@@ -68,3 +68,4 @@
...
@@ -68,3 +68,4 @@
6:ready_start
6:ready_start
6:concede
6:concede
6:deck_select:i,deck_id
6:deck_select:i,deck_id
7:update_server_message
\ No newline at end of file
common/protocol_items.h
View file @
bd9e142d
...
@@ -649,5 +649,12 @@ public:
...
@@ -649,5 +649,12 @@ public:
static
SerializableItem
*
newItem
()
{
return
new
Context_DeckSelect
;
}
static
SerializableItem
*
newItem
()
{
return
new
Context_DeckSelect
;
}
int
getItemId
()
const
{
return
ItemId_Context_DeckSelect
;
}
int
getItemId
()
const
{
return
ItemId_Context_DeckSelect
;
}
};
};
class
Command_UpdateServerMessage
:
public
AdminCommand
{
Q_OBJECT
public:
Command_UpdateServerMessage
();
static
SerializableItem
*
newItem
()
{
return
new
Command_UpdateServerMessage
;
}
int
getItemId
()
const
{
return
ItemId_Command_UpdateServerMessage
;
}
};
#endif
#endif
common/protocol_mc.pl
View file @
bd9e142d
...
@@ -73,6 +73,13 @@ while (<file>) {
...
@@ -73,6 +73,13 @@ while (<file>) {
$parentConstructorCall
=
"
$baseClass
(
\"
$name1
\"
)
";
$parentConstructorCall
=
"
$baseClass
(
\"
$name1
\"
)
";
$constructorParamsH
=
"";
$constructorParamsH
=
"";
$constructorParamsCpp
=
"";
$constructorParamsCpp
=
"";
}
elsif
(
$type
==
7
)
{
$type
=
'
cmd
';
$namePrefix
=
'
Command
';
$baseClass
=
'
AdminCommand
';
$parentConstructorCall
=
"
$baseClass
(
\"
$name1
\"
)
";
$constructorParamsH
=
"";
$constructorParamsCpp
=
"";
}
}
$className
=
$namePrefix
.
'
_
'
.
$name2
;
$className
=
$namePrefix
.
'
_
'
.
$name2
;
$itemEnum
.=
"
ItemId_
$className
=
"
.
++
$itemId
.
"
,
\n
";
$itemEnum
.=
"
ItemId_
$className
=
"
.
++
$itemId
.
"
,
\n
";
...
...
common/serializable_item.cpp
View file @
bd9e142d
#include
"serializable_item.h"
#include
"serializable_item.h"
#include
<QXmlStreamReader>
#include
<QXmlStreamReader>
#include
<QXmlStreamWriter>
#include
<QXmlStreamWriter>
#include
<QDebug>
QHash
<
QString
,
SerializableItem
::
NewItemFunction
>
SerializableItem
::
itemNameHash
;
QHash
<
QString
,
SerializableItem
::
NewItemFunction
>
SerializableItem
::
itemNameHash
;
SerializableItem
*
SerializableItem
::
getNewItem
(
const
QString
&
name
)
SerializableItem
*
SerializableItem
::
getNewItem
(
const
QString
&
name
)
...
...
common/server_protocolhandler.cpp
View file @
bd9e142d
...
@@ -55,7 +55,6 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
...
@@ -55,7 +55,6 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
lastCommandTime
=
QDateTime
::
currentDateTime
();
lastCommandTime
=
QDateTime
::
currentDateTime
();
RoomCommand
*
roomCommand
=
qobject_cast
<
RoomCommand
*>
(
command
);
RoomCommand
*
roomCommand
=
qobject_cast
<
RoomCommand
*>
(
command
);
GameCommand
*
gameCommand
=
qobject_cast
<
GameCommand
*>
(
command
);
if
(
roomCommand
)
{
if
(
roomCommand
)
{
qDebug
()
<<
"received RoomCommand: roomId ="
<<
roomCommand
->
getRoomId
();
qDebug
()
<<
"received RoomCommand: roomId ="
<<
roomCommand
->
getRoomId
();
if
(
authState
==
PasswordWrong
)
if
(
authState
==
PasswordWrong
)
...
@@ -66,12 +65,15 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
...
@@ -66,12 +65,15 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
return
RespNameNotFound
;
return
RespNameNotFound
;
switch
(
command
->
getItemId
())
{
switch
(
command
->
getItemId
())
{
case
ItemId_Command_LeaveRoom
:
return
cmdLeaveRoom
(
qobject_cast
<
Command_LeaveRoom
*>
(
command
),
cont
,
room
);
case
ItemId_Command_LeaveRoom
:
return
cmdLeaveRoom
(
static_cast
<
Command_LeaveRoom
*>
(
command
),
cont
,
room
);
case
ItemId_Command_RoomSay
:
return
cmdRoomSay
(
qobject_cast
<
Command_RoomSay
*>
(
command
),
cont
,
room
);
case
ItemId_Command_RoomSay
:
return
cmdRoomSay
(
static_cast
<
Command_RoomSay
*>
(
command
),
cont
,
room
);
case
ItemId_Command_CreateGame
:
return
cmdCreateGame
(
qobject_cast
<
Command_CreateGame
*>
(
command
),
cont
,
room
);
case
ItemId_Command_CreateGame
:
return
cmdCreateGame
(
static_cast
<
Command_CreateGame
*>
(
command
),
cont
,
room
);
case
ItemId_Command_JoinGame
:
return
cmdJoinGame
(
qobject_cast
<
Command_JoinGame
*>
(
command
),
cont
,
room
);
case
ItemId_Command_JoinGame
:
return
cmdJoinGame
(
static_cast
<
Command_JoinGame
*>
(
command
),
cont
,
room
);
default:
return
RespInvalidCommand
;
}
}
}
else
if
(
gameCommand
)
{
}
GameCommand
*
gameCommand
=
qobject_cast
<
GameCommand
*>
(
command
);
if
(
gameCommand
)
{
qDebug
()
<<
"received GameCommand: game ="
<<
gameCommand
->
getGameId
();
qDebug
()
<<
"received GameCommand: game ="
<<
gameCommand
->
getGameId
();
if
(
authState
==
PasswordWrong
)
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
return
RespLoginNeeded
;
...
@@ -85,54 +87,65 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
...
@@ -85,54 +87,65 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
Server_Player
*
player
=
gamePair
.
second
;
Server_Player
*
player
=
gamePair
.
second
;
switch
(
command
->
getItemId
())
{
switch
(
command
->
getItemId
())
{
case
ItemId_Command_DeckSelect
:
return
cmdDeckSelect
(
qobject_cast
<
Command_DeckSelect
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DeckSelect
:
return
cmdDeckSelect
(
static_cast
<
Command_DeckSelect
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetSideboardPlan
:
return
cmdSetSideboardPlan
(
qobject_cast
<
Command_SetSideboardPlan
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetSideboardPlan
:
return
cmdSetSideboardPlan
(
static_cast
<
Command_SetSideboardPlan
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_LeaveGame
:
return
cmdLeaveGame
(
qobject_cast
<
Command_LeaveGame
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_LeaveGame
:
return
cmdLeaveGame
(
static_cast
<
Command_LeaveGame
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_ReadyStart
:
return
cmdReadyStart
(
qobject_cast
<
Command_ReadyStart
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_ReadyStart
:
return
cmdReadyStart
(
static_cast
<
Command_ReadyStart
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Concede
:
return
cmdConcede
(
qobject_cast
<
Command_Concede
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Concede
:
return
cmdConcede
(
static_cast
<
Command_Concede
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Say
:
return
cmdSay
(
qobject_cast
<
Command_Say
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Say
:
return
cmdSay
(
static_cast
<
Command_Say
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Shuffle
:
return
cmdShuffle
(
qobject_cast
<
Command_Shuffle
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Shuffle
:
return
cmdShuffle
(
static_cast
<
Command_Shuffle
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Mulligan
:
return
cmdMulligan
(
qobject_cast
<
Command_Mulligan
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_Mulligan
:
return
cmdMulligan
(
static_cast
<
Command_Mulligan
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_RollDie
:
return
cmdRollDie
(
qobject_cast
<
Command_RollDie
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_RollDie
:
return
cmdRollDie
(
static_cast
<
Command_RollDie
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DrawCards
:
return
cmdDrawCards
(
qobject_cast
<
Command_DrawCards
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DrawCards
:
return
cmdDrawCards
(
static_cast
<
Command_DrawCards
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_MoveCard
:
return
cmdMoveCard
(
qobject_cast
<
Command_MoveCard
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_MoveCard
:
return
cmdMoveCard
(
static_cast
<
Command_MoveCard
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_FlipCard
:
return
cmdFlipCard
(
qobject_cast
<
Command_FlipCard
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_FlipCard
:
return
cmdFlipCard
(
static_cast
<
Command_FlipCard
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_AttachCard
:
return
cmdAttachCard
(
qobject_cast
<
Command_AttachCard
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_AttachCard
:
return
cmdAttachCard
(
static_cast
<
Command_AttachCard
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_CreateToken
:
return
cmdCreateToken
(
qobject_cast
<
Command_CreateToken
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_CreateToken
:
return
cmdCreateToken
(
static_cast
<
Command_CreateToken
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_CreateArrow
:
return
cmdCreateArrow
(
qobject_cast
<
Command_CreateArrow
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_CreateArrow
:
return
cmdCreateArrow
(
static_cast
<
Command_CreateArrow
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DeleteArrow
:
return
cmdDeleteArrow
(
qobject_cast
<
Command_DeleteArrow
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DeleteArrow
:
return
cmdDeleteArrow
(
static_cast
<
Command_DeleteArrow
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetCardAttr
:
return
cmdSetCardAttr
(
qobject_cast
<
Command_SetCardAttr
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetCardAttr
:
return
cmdSetCardAttr
(
static_cast
<
Command_SetCardAttr
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetCardCounter
:
return
cmdSetCardCounter
(
qobject_cast
<
Command_SetCardCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetCardCounter
:
return
cmdSetCardCounter
(
static_cast
<
Command_SetCardCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_IncCardCounter
:
return
cmdIncCardCounter
(
qobject_cast
<
Command_IncCardCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_IncCardCounter
:
return
cmdIncCardCounter
(
static_cast
<
Command_IncCardCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_IncCounter
:
return
cmdIncCounter
(
qobject_cast
<
Command_IncCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_IncCounter
:
return
cmdIncCounter
(
static_cast
<
Command_IncCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_CreateCounter
:
return
cmdCreateCounter
(
qobject_cast
<
Command_CreateCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_CreateCounter
:
return
cmdCreateCounter
(
static_cast
<
Command_CreateCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetCounter
:
return
cmdSetCounter
(
qobject_cast
<
Command_SetCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetCounter
:
return
cmdSetCounter
(
static_cast
<
Command_SetCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DelCounter
:
return
cmdDelCounter
(
qobject_cast
<
Command_DelCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DelCounter
:
return
cmdDelCounter
(
static_cast
<
Command_DelCounter
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_NextTurn
:
return
cmdNextTurn
(
qobject_cast
<
Command_NextTurn
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_NextTurn
:
return
cmdNextTurn
(
static_cast
<
Command_NextTurn
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetActivePhase
:
return
cmdSetActivePhase
(
qobject_cast
<
Command_SetActivePhase
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_SetActivePhase
:
return
cmdSetActivePhase
(
static_cast
<
Command_SetActivePhase
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DumpZone
:
return
cmdDumpZone
(
qobject_cast
<
Command_DumpZone
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_DumpZone
:
return
cmdDumpZone
(
static_cast
<
Command_DumpZone
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_StopDumpZone
:
return
cmdStopDumpZone
(
qobject_cast
<
Command_StopDumpZone
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_StopDumpZone
:
return
cmdStopDumpZone
(
static_cast
<
Command_StopDumpZone
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_RevealCards
:
return
cmdRevealCards
(
qobject_cast
<
Command_RevealCards
*>
(
command
),
cont
,
game
,
player
);
case
ItemId_Command_RevealCards
:
return
cmdRevealCards
(
static_cast
<
Command_RevealCards
*>
(
command
),
cont
,
game
,
player
);
default:
return
RespInvalidCommand
;
}
}
}
else
{
}
qDebug
()
<<
"received generic Command"
;
AdminCommand
*
adminCommand
=
qobject_cast
<
AdminCommand
*>
(
command
);
if
(
adminCommand
)
{
qDebug
()
<<
"received AdminCommand"
;
if
(
!
(
userInfo
->
getUserLevel
()
&
ServerInfo_User
::
IsAdmin
))
return
RespLoginNeeded
;
switch
(
command
->
getItemId
())
{
switch
(
command
->
getItemId
())
{
case
ItemId_Command_Ping
:
return
cmdPing
(
qobject_cast
<
Command_Ping
*>
(
command
),
cont
);
case
ItemId_Command_UpdateServerMessage
:
return
cmdUpdateServerMessage
(
static_cast
<
Command_UpdateServerMessage
*>
(
command
),
cont
);
case
ItemId_Command_Login
:
return
cmdLogin
(
qobject_cast
<
Command_Login
*>
(
command
),
cont
);
default:
return
RespInvalidCommand
;
case
ItemId_Command_Message
:
return
cmdMessage
(
qobject_cast
<
Command_Message
*>
(
command
),
cont
);
case
ItemId_Command_DeckList
:
return
cmdDeckList
(
qobject_cast
<
Command_DeckList
*>
(
command
),
cont
);
case
ItemId_Command_DeckNewDir
:
return
cmdDeckNewDir
(
qobject_cast
<
Command_DeckNewDir
*>
(
command
),
cont
);
case
ItemId_Command_DeckDelDir
:
return
cmdDeckDelDir
(
qobject_cast
<
Command_DeckDelDir
*>
(
command
),
cont
);
case
ItemId_Command_DeckDel
:
return
cmdDeckDel
(
qobject_cast
<
Command_DeckDel
*>
(
command
),
cont
);
case
ItemId_Command_DeckUpload
:
return
cmdDeckUpload
(
qobject_cast
<
Command_DeckUpload
*>
(
command
),
cont
);
case
ItemId_Command_DeckDownload
:
return
cmdDeckDownload
(
qobject_cast
<
Command_DeckDownload
*>
(
command
),
cont
);
case
ItemId_Command_GetUserInfo
:
return
cmdGetUserInfo
(
qobject_cast
<
Command_GetUserInfo
*>
(
command
),
cont
);
case
ItemId_Command_ListRooms
:
return
cmdListRooms
(
qobject_cast
<
Command_ListRooms
*>
(
command
),
cont
);
case
ItemId_Command_JoinRoom
:
return
cmdJoinRoom
(
qobject_cast
<
Command_JoinRoom
*>
(
command
),
cont
);
case
ItemId_Command_ListUsers
:
return
cmdListUsers
(
qobject_cast
<
Command_ListUsers
*>
(
command
),
cont
);
}
}
}
}
return
RespInvalidCommand
;
qDebug
()
<<
"received generic Command"
;
switch
(
command
->
getItemId
())
{
case
ItemId_Command_Ping
:
return
cmdPing
(
static_cast
<
Command_Ping
*>
(
command
),
cont
);
case
ItemId_Command_Login
:
return
cmdLogin
(
static_cast
<
Command_Login
*>
(
command
),
cont
);
case
ItemId_Command_Message
:
return
cmdMessage
(
static_cast
<
Command_Message
*>
(
command
),
cont
);
case
ItemId_Command_DeckList
:
return
cmdDeckList
(
static_cast
<
Command_DeckList
*>
(
command
),
cont
);
case
ItemId_Command_DeckNewDir
:
return
cmdDeckNewDir
(
static_cast
<
Command_DeckNewDir
*>
(
command
),
cont
);
case
ItemId_Command_DeckDelDir
:
return
cmdDeckDelDir
(
static_cast
<
Command_DeckDelDir
*>
(
command
),
cont
);
case
ItemId_Command_DeckDel
:
return
cmdDeckDel
(
static_cast
<
Command_DeckDel
*>
(
command
),
cont
);
case
ItemId_Command_DeckUpload
:
return
cmdDeckUpload
(
static_cast
<
Command_DeckUpload
*>
(
command
),
cont
);
case
ItemId_Command_DeckDownload
:
return
cmdDeckDownload
(
static_cast
<
Command_DeckDownload
*>
(
command
),
cont
);
case
ItemId_Command_GetUserInfo
:
return
cmdGetUserInfo
(
static_cast
<
Command_GetUserInfo
*>
(
command
),
cont
);
case
ItemId_Command_ListRooms
:
return
cmdListRooms
(
static_cast
<
Command_ListRooms
*>
(
command
),
cont
);
case
ItemId_Command_JoinRoom
:
return
cmdJoinRoom
(
static_cast
<
Command_JoinRoom
*>
(
command
),
cont
);
case
ItemId_Command_ListUsers
:
return
cmdListUsers
(
static_cast
<
Command_ListUsers
*>
(
command
),
cont
);
default:
return
RespInvalidCommand
;
}
}
}
void
Server_ProtocolHandler
::
processCommandContainer
(
CommandContainer
*
cont
)
void
Server_ProtocolHandler
::
processCommandContainer
(
CommandContainer
*
cont
)
...
...
common/server_protocolhandler.h
View file @
bd9e142d
...
@@ -81,6 +81,7 @@ private:
...
@@ -81,6 +81,7 @@ private:
ResponseCode
cmdDumpZone
(
Command_DumpZone
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
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
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
);
ResponseCode
cmdRevealCards
(
Command_RevealCards
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
virtual
ResponseCode
cmdUpdateServerMessage
(
Command_UpdateServerMessage
*
cmd
,
CommandContainer
*
cont
)
=
0
;
ResponseCode
processCommandHelper
(
Command
*
command
,
CommandContainer
*
cont
);
ResponseCode
processCommandHelper
(
Command
*
command
,
CommandContainer
*
cont
);
private
slots
:
private
slots
:
...
...
servatrice/src/servatrice.cpp
View file @
bd9e142d
...
@@ -192,15 +192,24 @@ ServerInfo_User *Servatrice::getUserData(const QString &name)
...
@@ -192,15 +192,24 @@ ServerInfo_User *Servatrice::getUserData(const QString &name)
}
else
}
else
return
new
ServerInfo_User
(
name
,
ServerInfo_User
::
IsUser
);
return
new
ServerInfo_User
(
name
,
ServerInfo_User
::
IsUser
);
}
}
#include
<QDebug>
void
Servatrice
::
updateLoginMessage
()
void
Servatrice
::
updateLoginMessage
()
{
{
checkSql
();
checkSql
();
QSqlQuery
query
;
QSqlQuery
query
;
query
.
prepare
(
"select message from "
+
dbPrefix
+
"_servermessages order by timest desc limit 1"
);
query
.
prepare
(
"select message from "
+
dbPrefix
+
"_servermessages order by timest desc limit 1"
);
if
(
execSqlQuery
(
query
))
if
(
execSqlQuery
(
query
))
if
(
query
.
next
())
if
(
query
.
next
())
{
loginMessage
=
query
.
value
(
0
).
toString
();
loginMessage
=
query
.
value
(
0
).
toString
();
Event_ServerMessage
*
event
=
new
Event_ServerMessage
(
loginMessage
);
QMapIterator
<
QString
,
Server_ProtocolHandler
*>
usersIterator
(
users
);
while
(
usersIterator
.
hasNext
())
{
usersIterator
.
next
().
value
()
->
sendProtocolItem
(
event
,
false
);
qDebug
()
<<
"sent message to"
<<
usersIterator
.
value
()
->
getUserInfo
()
->
getName
();
}
delete
event
;
}
}
}
void
Servatrice
::
statusUpdate
()
void
Servatrice
::
statusUpdate
()
...
...
servatrice/src/serversocketinterface.cpp
View file @
bd9e142d
...
@@ -323,3 +323,12 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd, C
...
@@ -323,3 +323,12 @@ ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd, C
cont
->
setResponse
(
new
Response_DeckDownload
(
cont
->
getCmdId
(),
RespOk
,
deck
));
cont
->
setResponse
(
new
Response_DeckDownload
(
cont
->
getCmdId
(),
RespOk
,
deck
));
return
RespNothing
;
return
RespNothing
;
}
}
// ADMIN FUNCTIONS.
// Permission is checked by the calling function.
ResponseCode
ServerSocketInterface
::
cmdUpdateServerMessage
(
Command_UpdateServerMessage
*
cmd
,
CommandContainer
*
cont
)
{
servatrice
->
updateLoginMessage
();
return
RespOk
;
}
servatrice/src/serversocketinterface.h
View file @
bd9e142d
...
@@ -55,6 +55,7 @@ private:
...
@@ -55,6 +55,7 @@ private:
ResponseCode
cmdDeckUpload
(
Command_DeckUpload
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdDeckUpload
(
Command_DeckUpload
*
cmd
,
CommandContainer
*
cont
);
DeckList
*
getDeckFromDatabase
(
int
deckId
);
DeckList
*
getDeckFromDatabase
(
int
deckId
);
ResponseCode
cmdDeckDownload
(
Command_DeckDownload
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdDeckDownload
(
Command_DeckDownload
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdUpdateServerMessage
(
Command_UpdateServerMessage
*
cmd
,
CommandContainer
*
cont
);
public:
public:
ServerSocketInterface
(
Servatrice
*
_server
,
QTcpSocket
*
_socket
,
QObject
*
parent
=
0
);
ServerSocketInterface
(
Servatrice
*
_server
,
QTcpSocket
*
_socket
,
QObject
*
parent
=
0
);
~
ServerSocketInterface
();
~
ServerSocketInterface
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment