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
d8d45632
Commit
d8d45632
authored
Dec 24, 2010
by
Max-Wilhelm Bruker
Browse files
initial commit for rooms
parent
76a13be3
Changes
21
Hide whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
d8d45632
...
@@ -78,7 +78,7 @@ HEADERS += src/counter.h \
...
@@ -78,7 +78,7 @@ HEADERS += src/counter.h \
..
/
common
/
server_arrow
.
h
\
..
/
common
/
server_arrow
.
h
\
..
/
common
/
server_card
.
h
\
..
/
common
/
server_card
.
h
\
..
/
common
/
server_cardzone
.
h
\
..
/
common
/
server_cardzone
.
h
\
..
/
common
/
server_
chatchannel
.
h
\
..
/
common
/
server_
room
.
h
\
..
/
common
/
server_counter
.
h
\
..
/
common
/
server_counter
.
h
\
..
/
common
/
server_game
.
h
\
..
/
common
/
server_game
.
h
\
..
/
common
/
server_player
.
h
\
..
/
common
/
server_player
.
h
\
...
@@ -154,7 +154,7 @@ SOURCES += src/counter.cpp \
...
@@ -154,7 +154,7 @@ SOURCES += src/counter.cpp \
..
/
common
/
server
.
cpp
\
..
/
common
/
server
.
cpp
\
..
/
common
/
server_card
.
cpp
\
..
/
common
/
server_card
.
cpp
\
..
/
common
/
server_cardzone
.
cpp
\
..
/
common
/
server_cardzone
.
cpp
\
..
/
common
/
server_
chatchannel
.
cpp
\
..
/
common
/
server_
room
.
cpp
\
..
/
common
/
server_game
.
cpp
\
..
/
common
/
server_game
.
cpp
\
..
/
common
/
server_player
.
cpp
\
..
/
common
/
server_player
.
cpp
\
..
/
common
/
server_protocolhandler
.
cpp
..
/
common
/
server_protocolhandler
.
cpp
...
...
common/protocol.cpp
View file @
d8d45632
...
@@ -14,7 +14,7 @@ void ProtocolItem::initializeHash()
...
@@ -14,7 +14,7 @@ void ProtocolItem::initializeHash()
initializeHashAuto
();
initializeHashAuto
();
registerSerializableItem
(
"move_card_to_zone"
,
MoveCardToZone
::
newItem
);
registerSerializableItem
(
"move_card_to_zone"
,
MoveCardToZone
::
newItem
);
registerSerializableItem
(
"
chat_channel
"
,
ServerInfo_
ChatChannel
::
newItem
);
registerSerializableItem
(
"
room
"
,
ServerInfo_
Room
::
newItem
);
registerSerializableItem
(
"user"
,
ServerInfo_User
::
newItem
);
registerSerializableItem
(
"user"
,
ServerInfo_User
::
newItem
);
registerSerializableItem
(
"game"
,
ServerInfo_Game
::
newItem
);
registerSerializableItem
(
"game"
,
ServerInfo_Game
::
newItem
);
registerSerializableItem
(
"card_counter"
,
ServerInfo_CardCounter
::
newItem
);
registerSerializableItem
(
"card_counter"
,
ServerInfo_CardCounter
::
newItem
);
...
@@ -44,9 +44,10 @@ void ProtocolItem::initializeHash()
...
@@ -44,9 +44,10 @@ void ProtocolItem::initializeHash()
registerSerializableItem
(
"respdeck_upload"
,
Response_DeckUpload
::
newItem
);
registerSerializableItem
(
"respdeck_upload"
,
Response_DeckUpload
::
newItem
);
registerSerializableItem
(
"respdump_zone"
,
Response_DumpZone
::
newItem
);
registerSerializableItem
(
"respdump_zone"
,
Response_DumpZone
::
newItem
);
registerSerializableItem
(
"generic_eventlist_games"
,
Event_ListGames
::
newItem
);
registerSerializableItem
(
"room_eventlist_games"
,
Event_ListGames
::
newItem
);
registerSerializableItem
(
"room_eventjoin_room"
,
Event_JoinRoom
::
newItem
);
registerSerializableItem
(
"generic_eventuser_joined"
,
Event_UserJoined
::
newItem
);
registerSerializableItem
(
"generic_eventuser_joined"
,
Event_UserJoined
::
newItem
);
registerSerializableItem
(
"generic_eventlist_
chat_channel
s"
,
Event_List
ChatChannel
s
::
newItem
);
registerSerializableItem
(
"generic_eventlist_
room
s"
,
Event_List
Room
s
::
newItem
);
registerSerializableItem
(
"game_eventjoin"
,
Event_Join
::
newItem
);
registerSerializableItem
(
"game_eventjoin"
,
Event_Join
::
newItem
);
registerSerializableItem
(
"game_eventgame_state_changed"
,
Event_GameStateChanged
::
newItem
);
registerSerializableItem
(
"game_eventgame_state_changed"
,
Event_GameStateChanged
::
newItem
);
registerSerializableItem
(
"game_eventplayer_properties_changed"
,
Event_PlayerPropertiesChanged
::
newItem
);
registerSerializableItem
(
"game_eventplayer_properties_changed"
,
Event_PlayerPropertiesChanged
::
newItem
);
...
@@ -55,8 +56,6 @@ void ProtocolItem::initializeHash()
...
@@ -55,8 +56,6 @@ void ProtocolItem::initializeHash()
registerSerializableItem
(
"game_eventdraw_cards"
,
Event_DrawCards
::
newItem
);
registerSerializableItem
(
"game_eventdraw_cards"
,
Event_DrawCards
::
newItem
);
registerSerializableItem
(
"game_eventreveal_cards"
,
Event_RevealCards
::
newItem
);
registerSerializableItem
(
"game_eventreveal_cards"
,
Event_RevealCards
::
newItem
);
registerSerializableItem
(
"game_eventping"
,
Event_Ping
::
newItem
);
registerSerializableItem
(
"game_eventping"
,
Event_Ping
::
newItem
);
registerSerializableItem
(
"chat_eventchat_list_players"
,
Event_ChatListPlayers
::
newItem
);
registerSerializableItem
(
"chat_eventchat_join_channel"
,
Event_ChatJoinChannel
::
newItem
);
}
}
TopLevelProtocolItem
::
TopLevelProtocolItem
()
TopLevelProtocolItem
::
TopLevelProtocolItem
()
...
@@ -284,36 +283,29 @@ GameEventContext::GameEventContext(const QString &_contextName)
...
@@ -284,36 +283,29 @@ GameEventContext::GameEventContext(const QString &_contextName)
{
{
}
}
Chat
Event
::
Chat
Event
(
const
QString
&
_eventName
,
const
QString
&
_channel
)
Room
Event
::
Room
Event
(
const
QString
&
_eventName
,
int
_roomId
)
:
ProtocolItem
(
"
chat
_event"
,
_eventName
)
:
ProtocolItem
(
"
room
_event"
,
_eventName
)
{
{
insertItem
(
new
SerializableItem_
String
(
"channel"
,
_channel
));
insertItem
(
new
SerializableItem_
Int
(
"room_id"
,
_roomId
));
}
}
Event_List
ChatChannel
s
::
Event_List
ChatChannel
s
(
const
QList
<
ServerInfo_
ChatChannel
*>
&
_channel
List
)
Event_List
Room
s
::
Event_List
Room
s
(
const
QList
<
ServerInfo_
Room
*>
&
_room
List
)
:
GenericEvent
(
"list_
chat_channel
s"
)
:
GenericEvent
(
"list_
room
s"
)
{
{
for
(
int
i
=
0
;
i
<
_
channel
List
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
_
room
List
.
size
();
++
i
)
itemList
.
append
(
_
channel
List
[
i
]);
itemList
.
append
(
_
room
List
[
i
]);
}
}
Event_ChatListPlayers
::
Event_ChatListPlayers
(
const
QString
&
_channel
,
const
QList
<
ServerInfo_User
*>
&
_playerList
)
Event_JoinRoom
::
Event_JoinRoom
(
int
_roomId
,
ServerInfo_User
*
_info
)
:
ChatEvent
(
"chat_list_players"
,
_channel
)
:
RoomEvent
(
"join_room"
,
_roomId
)
{
for
(
int
i
=
0
;
i
<
_playerList
.
size
();
++
i
)
itemList
.
append
(
_playerList
[
i
]);
}
Event_ChatJoinChannel
::
Event_ChatJoinChannel
(
const
QString
&
_channel
,
ServerInfo_User
*
_info
)
:
ChatEvent
(
"chat_join_channel"
,
_channel
)
{
{
if
(
!
_info
)
if
(
!
_info
)
_info
=
new
ServerInfo_User
;
_info
=
new
ServerInfo_User
;
insertItem
(
_info
);
insertItem
(
_info
);
}
}
Event_ListGames
::
Event_ListGames
(
const
QList
<
ServerInfo_Game
*>
&
_gameList
)
Event_ListGames
::
Event_ListGames
(
int
_roomId
,
const
QList
<
ServerInfo_Game
*>
&
_gameList
)
:
Generic
Event
(
"list_games"
)
:
Room
Event
(
"list_games"
,
_roomId
)
{
{
for
(
int
i
=
0
;
i
<
_gameList
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
_gameList
.
size
();
++
i
)
itemList
.
append
(
_gameList
[
i
]);
itemList
.
append
(
_gameList
[
i
]);
...
...
common/protocol.h
View file @
d8d45632
...
@@ -25,9 +25,8 @@ enum ItemId {
...
@@ -25,9 +25,8 @@ enum ItemId {
ItemId_Command_DeckUpload
=
ItemId_Other
+
100
,
ItemId_Command_DeckUpload
=
ItemId_Other
+
100
,
ItemId_Command_DeckSelect
=
ItemId_Other
+
101
,
ItemId_Command_DeckSelect
=
ItemId_Other
+
101
,
ItemId_Command_SetSideboardPlan
=
ItemId_Other
+
102
,
ItemId_Command_SetSideboardPlan
=
ItemId_Other
+
102
,
ItemId_Event_ListChatChannels
=
ItemId_Other
+
200
,
ItemId_Event_ListRooms
=
ItemId_Other
+
200
,
ItemId_Event_ChatListPlayers
=
ItemId_Other
+
201
,
ItemId_Event_JoinRoom
=
ItemId_Other
+
201
,
ItemId_Event_ChatJoinChannel
=
ItemId_Other
+
202
,
ItemId_Event_ListGames
=
ItemId_Other
+
203
,
ItemId_Event_ListGames
=
ItemId_Other
+
203
,
ItemId_Event_UserJoined
=
ItemId_Other
+
204
,
ItemId_Event_UserJoined
=
ItemId_Other
+
204
,
ItemId_Event_GameStateChanged
=
ItemId_Other
+
205
,
ItemId_Event_GameStateChanged
=
ItemId_Other
+
205
,
...
@@ -136,15 +135,15 @@ public:
...
@@ -136,15 +135,15 @@ public:
int
getPrivatePlayerId
()
const
{
return
privatePlayerId
;
}
int
getPrivatePlayerId
()
const
{
return
privatePlayerId
;
}
};
};
class
Chat
Command
:
public
Command
{
class
Room
Command
:
public
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
Chat
Command
(
const
QString
&
_cmdName
,
const
QString
&
_channel
)
Room
Command
(
const
QString
&
_cmdName
,
int
_roomId
)
:
Command
(
_cmdName
)
:
Command
(
_cmdName
)
{
{
insertItem
(
new
SerializableItem_
String
(
"channel"
,
_channel
));
insertItem
(
new
SerializableItem_
Int
(
"room_id"
,
_roomId
));
}
}
QStr
in
g
get
Channel
()
const
{
return
static_cast
<
SerializableItem_
String
*>
(
itemMap
.
value
(
"
channel
"
))
->
getData
();
}
in
t
get
RoomId
()
const
{
return
static_cast
<
SerializableItem_
Int
*>
(
itemMap
.
value
(
"
room_id
"
))
->
getData
();
}
};
};
class
GameCommand
:
public
Command
{
class
GameCommand
:
public
Command
{
...
@@ -304,44 +303,35 @@ public:
...
@@ -304,44 +303,35 @@ 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
Chat
Event
:
public
ProtocolItem
{
class
Room
Event
:
public
ProtocolItem
{
Q_OBJECT
Q_OBJECT
public:
public:
Chat
Event
(
const
QString
&
_eventName
,
const
QString
&
_channel
);
Room
Event
(
const
QString
&
_eventName
,
int
_roomId
);
QStr
in
g
get
Channel
()
const
{
return
static_cast
<
SerializableItem_
String
*>
(
itemMap
.
value
(
"
channel
"
))
->
getData
();
}
in
t
get
RoomId
()
const
{
return
static_cast
<
SerializableItem_
Int
*>
(
itemMap
.
value
(
"
room_id
"
))
->
getData
();
}
};
};
class
Event_List
ChatChannel
s
:
public
GenericEvent
{
class
Event_List
Room
s
:
public
GenericEvent
{
Q_OBJECT
Q_OBJECT
public:
public:
Event_List
ChatChannel
s
(
const
QList
<
ServerInfo_
ChatChannel
*>
&
_channel
List
=
QList
<
ServerInfo_
ChatChannel
*>
());
Event_List
Room
s
(
const
QList
<
ServerInfo_
Room
*>
&
_room
List
=
QList
<
ServerInfo_
Room
*>
());
int
getItemId
()
const
{
return
ItemId_Event_List
ChatChannel
s
;
}
int
getItemId
()
const
{
return
ItemId_Event_List
Room
s
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_List
ChatChannel
s
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_List
Room
s
;
}
QList
<
ServerInfo_
ChatChannel
*>
getChannel
List
()
const
{
return
typecastItemList
<
ServerInfo_
ChatChannel
*>
();
}
QList
<
ServerInfo_
Room
*>
getRoom
List
()
const
{
return
typecastItemList
<
ServerInfo_
Room
*>
();
}
};
};
class
Event_
ChatListPlayers
:
public
Chat
Event
{
class
Event_
JoinRoom
:
public
Room
Event
{
Q_OBJECT
Q_OBJECT
public:
public:
Event_ChatListPlayers
(
const
QString
&
_channel
=
QString
(),
const
QList
<
ServerInfo_User
*>
&
_playerList
=
QList
<
ServerInfo_User
*>
());
Event_JoinRoom
(
int
_roomId
=
-
1
,
ServerInfo_User
*
_info
=
0
);
int
getItemId
()
const
{
return
ItemId_Event_ChatListPlayers
;
}
int
getItemId
()
const
{
return
ItemId_Event_JoinRoom
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_ChatListPlayers
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_JoinRoom
;
}
QList
<
ServerInfo_User
*>
getPlayerList
()
const
{
return
typecastItemList
<
ServerInfo_User
*>
();
}
};
class
Event_ChatJoinChannel
:
public
ChatEvent
{
Q_OBJECT
public:
Event_ChatJoinChannel
(
const
QString
&
_channel
=
QString
(),
ServerInfo_User
*
_info
=
0
);
int
getItemId
()
const
{
return
ItemId_Event_ChatJoinChannel
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_ChatJoinChannel
;
}
ServerInfo_User
*
getUserInfo
()
const
{
return
static_cast
<
ServerInfo_User
*>
(
itemMap
.
value
(
"user"
));
}
ServerInfo_User
*
getUserInfo
()
const
{
return
static_cast
<
ServerInfo_User
*>
(
itemMap
.
value
(
"user"
));
}
};
};
class
Event_ListGames
:
public
Generic
Event
{
class
Event_ListGames
:
public
Room
Event
{
Q_OBJECT
Q_OBJECT
public:
public:
Event_ListGames
(
const
QList
<
ServerInfo_Game
*>
&
_gameList
=
QList
<
ServerInfo_Game
*>
());
Event_ListGames
(
int
_roomId
=
-
1
,
const
QList
<
ServerInfo_Game
*>
&
_gameList
=
QList
<
ServerInfo_Game
*>
());
int
getItemId
()
const
{
return
ItemId_Event_ListGames
;
}
int
getItemId
()
const
{
return
ItemId_Event_ListGames
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_ListGames
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_ListGames
;
}
QList
<
ServerInfo_Game
*>
getGameList
()
const
{
return
typecastItemList
<
ServerInfo_Game
*>
();
}
QList
<
ServerInfo_Game
*>
getGameList
()
const
{
return
typecastItemList
<
ServerInfo_Game
*>
();
}
...
...
common/protocol_datastructures.cpp
View file @
d8d45632
...
@@ -3,11 +3,13 @@
...
@@ -3,11 +3,13 @@
#include
<QXmlStreamReader>
#include
<QXmlStreamReader>
#include
<QXmlStreamWriter>
#include
<QXmlStreamWriter>
ServerInfo_
ChatChannel
::
ServerInfo_
ChatChannel
(
const
QString
&
_name
,
const
QString
&
_description
,
int
_playerCount
,
bool
_autoJoin
)
ServerInfo_
Room
::
ServerInfo_
Room
(
int
_roomId
,
const
QString
&
_name
,
const
QString
&
_description
,
int
_gameCount
,
int
_playerCount
,
bool
_autoJoin
)
:
SerializableItem_Map
(
"
chat_channel
"
)
:
SerializableItem_Map
(
"
room
"
)
{
{
insertItem
(
new
SerializableItem_Int
(
"room_id"
,
_roomId
));
insertItem
(
new
SerializableItem_String
(
"name"
,
_name
));
insertItem
(
new
SerializableItem_String
(
"name"
,
_name
));
insertItem
(
new
SerializableItem_String
(
"description"
,
_description
));
insertItem
(
new
SerializableItem_String
(
"description"
,
_description
));
insertItem
(
new
SerializableItem_Int
(
"game_count"
,
_gameCount
));
insertItem
(
new
SerializableItem_Int
(
"player_count"
,
_playerCount
));
insertItem
(
new
SerializableItem_Int
(
"player_count"
,
_playerCount
));
insertItem
(
new
SerializableItem_Bool
(
"auto_join"
,
_autoJoin
));
insertItem
(
new
SerializableItem_Bool
(
"auto_join"
,
_autoJoin
));
}
}
...
...
common/protocol_datastructures.h
View file @
d8d45632
...
@@ -20,12 +20,14 @@ enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, Re
...
@@ -20,12 +20,14 @@ enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, Re
// list index, whereas cards in any other zone are referenced by their ids.
// list index, whereas cards in any other zone are referenced by their ids.
enum
ZoneType
{
PrivateZone
,
PublicZone
,
HiddenZone
};
enum
ZoneType
{
PrivateZone
,
PublicZone
,
HiddenZone
};
class
ServerInfo_
ChatChannel
:
public
SerializableItem_Map
{
class
ServerInfo_
Room
:
public
SerializableItem_Map
{
public:
public:
ServerInfo_ChatChannel
(
const
QString
&
_name
=
QString
(),
const
QString
&
_description
=
QString
(),
int
_playerCount
=
-
1
,
bool
_autoJoin
=
false
);
ServerInfo_Room
(
int
_id
=
-
1
,
const
QString
&
_name
=
QString
(),
const
QString
&
_description
=
QString
(),
int
_gameCount
=
-
1
,
int
_playerCount
=
-
1
,
bool
_autoJoin
=
false
);
static
SerializableItem
*
newItem
()
{
return
new
ServerInfo_ChatChannel
;
}
static
SerializableItem
*
newItem
()
{
return
new
ServerInfo_Room
;
}
int
getRoomId
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"room_id"
))
->
getData
();
}
QString
getName
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"name"
))
->
getData
();
}
QString
getName
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"name"
))
->
getData
();
}
QString
getDescription
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"description"
))
->
getData
();
}
QString
getDescription
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"description"
))
->
getData
();
}
int
getGameCount
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"game_count"
))
->
getData
();
}
int
getPlayerCount
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"player_count"
))
->
getData
();
}
int
getPlayerCount
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"player_count"
))
->
getData
();
}
bool
getAutoJoin
()
const
{
return
static_cast
<
SerializableItem_Bool
*>
(
itemMap
.
value
(
"auto_join"
))
->
getData
();
}
bool
getAutoJoin
()
const
{
return
static_cast
<
SerializableItem_Bool
*>
(
itemMap
.
value
(
"auto_join"
))
->
getData
();
}
};
};
...
...
common/protocol_item_ids.h
View file @
d8d45632
...
@@ -2,73 +2,72 @@ enum AutoItemId {
...
@@ -2,73 +2,72 @@ enum AutoItemId {
ItemId_Command_Ping
=
1001
,
ItemId_Command_Ping
=
1001
,
ItemId_Command_Login
=
1002
,
ItemId_Command_Login
=
1002
,
ItemId_Command_Message
=
1003
,
ItemId_Command_Message
=
1003
,
ItemId_Command_GetUserInfo
=
1004
,
ItemId_Command_ListUsers
=
1004
,
ItemId_Command_DeckList
=
1005
,
ItemId_Command_GetUserInfo
=
1005
,
ItemId_Command_DeckNewDir
=
1006
,
ItemId_Command_DeckList
=
1006
,
ItemId_Command_DeckDelDir
=
1007
,
ItemId_Command_DeckNewDir
=
1007
,
ItemId_Command_DeckDel
=
1008
,
ItemId_Command_DeckDelDir
=
1008
,
ItemId_Command_DeckDownload
=
1009
,
ItemId_Command_DeckDel
=
1009
,
ItemId_Command_ListChatChannels
=
1010
,
ItemId_Command_DeckDownload
=
1010
,
ItemId_Command_ChatJoinChannel
=
1011
,
ItemId_Command_ListRooms
=
1011
,
ItemId_Command_ChatLeaveChannel
=
1012
,
ItemId_Command_JoinRoom
=
1012
,
ItemId_Command_ChatSay
=
1013
,
ItemId_Command_LeaveRoom
=
1013
,
ItemId_Command_ListGames
=
1014
,
ItemId_Command_RoomSay
=
1014
,
ItemId_Command_ListUsers
=
1015
,
ItemId_Command_CreateGame
=
1015
,
ItemId_Command_CreateGame
=
1016
,
ItemId_Command_JoinGame
=
1016
,
ItemId_Command_JoinGame
=
1017
,
ItemId_Command_LeaveGame
=
1017
,
ItemId_Command_LeaveGame
=
1018
,
ItemId_Command_Say
=
1018
,
ItemId_Command_Say
=
1019
,
ItemId_Command_Shuffle
=
1019
,
ItemId_Command_Shuffle
=
1020
,
ItemId_Command_Mulligan
=
1020
,
ItemId_Command_Mulligan
=
1021
,
ItemId_Command_RollDie
=
1021
,
ItemId_Command_RollDie
=
1022
,
ItemId_Command_DrawCards
=
1022
,
ItemId_Command_DrawCards
=
1023
,
ItemId_Command_MoveCard
=
1023
,
ItemId_Command_MoveCard
=
1024
,
ItemId_Command_FlipCard
=
1024
,
ItemId_Command_FlipCard
=
1025
,
ItemId_Command_AttachCard
=
1025
,
ItemId_Command_AttachCard
=
1026
,
ItemId_Command_CreateToken
=
1026
,
ItemId_Command_CreateToken
=
1027
,
ItemId_Command_CreateArrow
=
1027
,
ItemId_Command_CreateArrow
=
1028
,
ItemId_Command_DeleteArrow
=
1028
,
ItemId_Command_DeleteArrow
=
1029
,
ItemId_Command_SetCardAttr
=
1029
,
ItemId_Command_SetCardAttr
=
1030
,
ItemId_Command_SetCardCounter
=
1030
,
ItemId_Command_SetCardCounter
=
1031
,
ItemId_Command_IncCardCounter
=
1031
,
ItemId_Command_IncCardCounter
=
1032
,
ItemId_Command_ReadyStart
=
1032
,
ItemId_Command_ReadyStart
=
1033
,
ItemId_Command_Concede
=
1033
,
ItemId_Command_Concede
=
1034
,
ItemId_Command_IncCounter
=
1034
,
ItemId_Command_IncCounter
=
1035
,
ItemId_Command_CreateCounter
=
1035
,
ItemId_Command_CreateCounter
=
1036
,
ItemId_Command_SetCounter
=
1036
,
ItemId_Command_SetCounter
=
1037
,
ItemId_Command_DelCounter
=
1037
,
ItemId_Command_DelCounter
=
1038
,
ItemId_Command_NextTurn
=
1038
,
ItemId_Command_NextTurn
=
1039
,
ItemId_Command_SetActivePhase
=
1039
,
ItemId_Command_SetActivePhase
=
1040
,
ItemId_Command_DumpZone
=
1040
,
ItemId_Command_DumpZone
=
1041
,
ItemId_Command_StopDumpZone
=
1041
,
ItemId_Command_StopDumpZone
=
1042
,
ItemId_Command_RevealCards
=
1042
,
ItemId_Command_RevealCards
=
1043
,
ItemId_Event_Say
=
1043
,
ItemId_Event_Say
=
1044
,
ItemId_Event_Leave
=
1044
,
ItemId_Event_Leave
=
1045
,
ItemId_Event_GameClosed
=
1045
,
ItemId_Event_GameClosed
=
1046
,
ItemId_Event_Shuffle
=
1046
,
ItemId_Event_Shuffle
=
1047
,
ItemId_Event_RollDie
=
1047
,
ItemId_Event_RollDie
=
1048
,
ItemId_Event_MoveCard
=
1048
,
ItemId_Event_MoveCard
=
1049
,
ItemId_Event_FlipCard
=
1049
,
ItemId_Event_FlipCard
=
1050
,
ItemId_Event_DestroyCard
=
1050
,
ItemId_Event_DestroyCard
=
1051
,
ItemId_Event_AttachCard
=
1051
,
ItemId_Event_AttachCard
=
1052
,
ItemId_Event_CreateToken
=
1052
,
ItemId_Event_CreateToken
=
1053
,
ItemId_Event_DeleteArrow
=
1053
,
ItemId_Event_DeleteArrow
=
1054
,
ItemId_Event_SetCardAttr
=
1054
,
ItemId_Event_SetCardAttr
=
1055
,
ItemId_Event_SetCardCounter
=
1055
,
ItemId_Event_SetCardCounter
=
1056
,
ItemId_Event_SetCounter
=
1056
,
ItemId_Event_SetCounter
=
1057
,
ItemId_Event_DelCounter
=
1057
,
ItemId_Event_DelCounter
=
1058
,
ItemId_Event_SetActivePlayer
=
1058
,
ItemId_Event_SetActivePlayer
=
1059
,
ItemId_Event_SetActivePhase
=
1059
,
ItemId_Event_SetActivePhase
=
1060
,
ItemId_Event_DumpZone
=
1060
,
ItemId_Event_DumpZone
=
1061
,
ItemId_Event_StopDumpZone
=
1061
,
ItemId_Event_StopDumpZone
=
1062
,
ItemId_Event_ServerMessage
=
1062
,
ItemId_Event_ServerMessage
=
1063
,
ItemId_Event_Message
=
1063
,
ItemId_Event_Message
=
1064
,
ItemId_Event_GameJoined
=
1064
,
ItemId_Event_GameJoined
=
1065
,
ItemId_Event_UserLeft
=
1065
,
ItemId_Event_UserLeft
=
1066
,
ItemId_Event_LeaveRoom
=
1066
,
ItemId_Event_ChatLeaveChannel
=
1067
,
ItemId_Event_RoomSay
=
1067
,
ItemId_Event_ChatSay
=
1068
,
ItemId_Context_ReadyStart
=
1068
,
ItemId_Context_ReadyStart
=
1069
,
ItemId_Context_Concede
=
1069
,
ItemId_Context_Concede
=
1070
,
ItemId_Context_DeckSelect
=
1070
,
ItemId_Context_DeckSelect
=
1071
,
ItemId_Other
=
1071
ItemId_Other
=
1072
};
};
common/protocol_items.cpp
View file @
d8d45632
...
@@ -17,6 +17,10 @@ Command_Message::Command_Message(const QString &_userName, const QString &_text)
...
@@ -17,6 +17,10 @@ Command_Message::Command_Message(const QString &_userName, const QString &_text)
insertItem
(
new
SerializableItem_String
(
"user_name"
,
_userName
));
insertItem
(
new
SerializableItem_String
(
"user_name"
,
_userName
));
insertItem
(
new
SerializableItem_String
(
"text"
,
_text
));
insertItem
(
new
SerializableItem_String
(
"text"
,
_text
));
}
}
Command_ListUsers
::
Command_ListUsers
()
:
Command
(
"list_users"
)
{
}
Command_GetUserInfo
::
Command_GetUserInfo
(
const
QString
&
_userName
)
Command_GetUserInfo
::
Command_GetUserInfo
(
const
QString
&
_userName
)
:
Command
(
"get_user_info"
)
:
Command
(
"get_user_info"
)
{
{
...
@@ -47,34 +51,26 @@ Command_DeckDownload::Command_DeckDownload(int _deckId)
...
@@ -47,34 +51,26 @@ Command_DeckDownload::Command_DeckDownload(int _deckId)
{
{
insertItem
(
new
SerializableItem_Int
(
"deck_id"
,
_deckId
));
insertItem
(
new
SerializableItem_Int
(
"deck_id"
,
_deckId
));
}
}
Command_List
ChatChannel
s
::
Command_List
ChatChannel
s
()
Command_List
Room
s
::
Command_List
Room
s
()
:
Command
(
"list_
chat_channel
s"
)
:
Command
(
"list_
room
s"
)
{
{
}
}
Command_
ChatJoinChannel
::
Command_ChatJoinChannel
(
const
QString
&
_channel
)
Command_
JoinRoom
::
Command_JoinRoom
(
int
_roomId
)
:
Command
(
"
chat_join_channel
"
)
:
Command
(
"
join_room
"
)
{
{
insertItem
(
new
SerializableItem_
String
(
"channel"
,
_channel
));
insertItem
(
new
SerializableItem_
Int
(
"room_id"
,
_roomId
));
}
}
Command_
Chat
Leave
Channel
::
Command_
Chat
Leave
Channel
(
const
QString
&
_channel
)
Command_Leave
Room
::
Command_Leave
Room
(
int
_roomId
)
:
Chat
Command
(
"
chat_
leave_
channel"
,
_channel
)
:
Room
Command
(
"leave_
room"
,
_roomId
)
{
{
}
}
Command_
Chat
Say
::
Command_
ChatSay
(
const
QString
&
_channel
,
const
QString
&
_message
)
Command_
Room
Say
::
Command_
RoomSay
(
int
_roomId
,
const
QString
&
_message
)
:
Chat
Command
(
"
chat
_say"
,
_
channel
)
:
Room
Command
(
"
room
_say"
,
_
roomId
)
{
{
insertItem
(
new
SerializableItem_String
(
"message"
,
_message
));
insertItem
(
new
SerializableItem_String
(
"message"
,
_message
));
}
}
Command_ListGames
::
Command_ListGames
()
Command_CreateGame
::
Command_CreateGame
(
int
_roomId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
)
:
Command
(
"list_games"
)
:
RoomCommand
(
"create_game"
,
_roomId
)
{
}
Command_ListUsers
::
Command_ListUsers
()
:
Command
(
"list_users"
)
{
}
Command_CreateGame
::
Command_CreateGame
(
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
)
:
Command
(
"create_game"
)
{
{
insertItem
(
new
SerializableItem_String
(
"description"
,
_description
));
insertItem
(
new
SerializableItem_String
(
"description"
,
_description
));
insertItem
(
new
SerializableItem_String
(
"password"
,
_password
));
insertItem
(
new
SerializableItem_String
(
"password"
,
_password
));
...
@@ -84,8 +80,8 @@ Command_CreateGame::Command_CreateGame(const QString &_description, const QStrin
...
@@ -84,8 +80,8 @@ Command_CreateGame::Command_CreateGame(const QString &_description, const QStrin
insertItem
(
new
SerializableItem_Bool
(
"spectators_can_talk"
,
_spectatorsCanTalk
));
insertItem
(
new
SerializableItem_Bool
(
"spectators_can_talk"
,
_spectatorsCanTalk
));
insertItem
(
new
SerializableItem_Bool
(
"spectators_see_everything"
,
_spectatorsSeeEverything
));
insertItem
(
new
SerializableItem_Bool
(
"spectators_see_everything"
,
_spectatorsSeeEverything
));
}
}
Command_JoinGame
::
Command_JoinGame
(
int
_gameId
,
const
QString
&
_password
,
bool
_spectator
)
Command_JoinGame
::
Command_JoinGame
(
int
_roomId
,
int
_gameId
,
const
QString
&
_password
,
bool
_spectator
)
:
Command
(
"join_game"
)
:
Room
Command
(
"join_game"
,
_roomId
)
{
{
insertItem
(
new
SerializableItem_Int
(
"game_id"
,
_gameId
));
insertItem
(
new
SerializableItem_Int
(
"game_id"
,
_gameId
));
insertItem
(
new
SerializableItem_String
(
"password"
,
_password
));
insertItem
(
new
SerializableItem_String
(
"password"
,
_password
));
...
@@ -417,13 +413,13 @@ Event_UserLeft::Event_UserLeft(const QString &_userName)
...
@@ -417,13 +413,13 @@ Event_UserLeft::Event_UserLeft(const QString &_userName)
{
{
insertItem
(
new
SerializableItem_String
(
"user_name"
,
_userName
));
insertItem
(
new
SerializableItem_String
(
"user_name"
,
_userName
));
}
}
Event_
Chat
Leave
Channel
::
Event_
Chat
Leave
Channel
(
const
QString
&
_channel
,
const
QString
&
_playerName
)
Event_Leave
Room
::
Event_Leave
Room
(
int
_roomId
,
const
QString
&
_playerName
)
:
Chat
Event
(
"
chat_
leave_
channel"
,
_channel
)
:
Room
Event
(
"leave_
room"
,
_roomId
)
{
{
insertItem
(
new
SerializableItem_String
(
"player_name"
,
_playerName
));
insertItem
(
new
SerializableItem_String
(
"player_name"
,
_playerName
));
}
}
Event_
Chat
Say
::
Event_
ChatSay
(
const
QString
&
_channel
,
const
QString
&
_playerName
,
const
QString
&
_message
)
Event_
Room
Say
::
Event_
RoomSay
(
int
_roomId
,
const
QString
&
_playerName
,
const
QString
&
_message
)
:
Chat
Event
(
"
chat
_say"
,
_
channel
)
:
Room
Event
(
"
room
_say"
,
_
roomId
)
{
{
insertItem
(
new
SerializableItem_String
(
"player_name"
,
_playerName
));
insertItem
(
new
SerializableItem_String
(
"player_name"
,
_playerName
));
insertItem
(
new
SerializableItem_String
(
"message"
,
_message
));
insertItem
(
new
SerializableItem_String
(
"message"
,
_message
));
...
@@ -446,18 +442,17 @@ void ProtocolItem::initializeHashAuto()
...
@@ -446,18 +442,17 @@ void ProtocolItem::initializeHashAuto()
itemNameHash
.
insert
(
"cmdping"
,
Command_Ping
::
newItem
);
itemNameHash
.
insert
(
"cmdping"
,
Command_Ping
::
newItem
);
itemNameHash
.
insert
(
"cmdlogin"
,
Command_Login
::
newItem
);
itemNameHash
.
insert
(
"cmdlogin"
,
Command_Login
::
newItem
);
itemNameHash
.
insert
(
"cmdmessage"
,
Command_Message
::
newItem
);
itemNameHash
.
insert
(
"cmdmessage"
,
Command_Message
::
newItem
);
itemNameHash
.
insert
(
"cmdlist_users"
,
Command_ListUsers
::
newItem
);
itemNameHash
.
insert
(
"cmdget_user_info"
,
Command_GetUserInfo
::
newItem
);
itemNameHash
.
insert
(
"cmdget_user_info"
,
Command_GetUserInfo
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_list"
,
Command_DeckList
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_list"
,
Command_DeckList
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_new_dir"
,
Command_DeckNewDir
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_new_dir"
,
Command_DeckNewDir
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_del_dir"
,
Command_DeckDelDir
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_del_dir"
,
Command_DeckDelDir
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_del"
,
Command_DeckDel
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_del"
,
Command_DeckDel
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_download"
,
Command_DeckDownload
::
newItem
);
itemNameHash
.
insert
(
"cmddeck_download"
,
Command_DeckDownload
::
newItem
);
itemNameHash
.
insert
(
"cmdlist_chat_channels"
,
Command_ListChatChannels
::
newItem
);
itemNameHash
.
insert
(
"cmdlist_rooms"
,
Command_ListRooms
::
newItem
);
itemNameHash
.
insert
(
"cmdchat_join_channel"
,
Command_ChatJoinChannel
::
newItem
);
itemNameHash
.
insert
(
"cmdjoin_room"
,
Command_JoinRoom
::
newItem
);
itemNameHash
.
insert
(
"cmdchat_leave_channel"
,
Command_ChatLeaveChannel
::
newItem
);
itemNameHash
.
insert
(
"cmdleave_room"
,
Command_LeaveRoom
::
newItem
);
itemNameHash
.
insert
(
"cmdchat_say"
,
Command_ChatSay
::
newItem
);
itemNameHash
.
insert
(
"cmdroom_say"
,
Command_RoomSay
::
newItem
);
itemNameHash
.
insert
(
"cmdlist_games"
,
Command_ListGames
::
newItem
);
itemNameHash
.
insert
(
"cmdlist_users"
,
Command_ListUsers
::
newItem
);
itemNameHash
.
insert
(
"cmdcreate_game"
,
Command_CreateGame
::
newItem
);
itemNameHash
.
insert
(
"cmdcreate_game"
,
Command_CreateGame
::
newItem
);
itemNameHash
.
insert
(
"cmdjoin_game"
,
Command_JoinGame
::
newItem
);
itemNameHash
.
insert
(
"cmdjoin_game"
,
Command_JoinGame
::
newItem
);
itemNameHash
.
insert
(
"cmdleave_game"
,
Command_LeaveGame
::
newItem
);
itemNameHash
.
insert
(
"cmdleave_game"
,
Command_LeaveGame
::
newItem
);
...
@@ -509,8 +504,8 @@ void ProtocolItem::initializeHashAuto()
...
@@ -509,8 +504,8 @@ void ProtocolItem::initializeHashAuto()
itemNameHash
.
insert
(
"generic_eventmessage"
,
Event_Message
::
newItem
);
itemNameHash
.
insert
(
"generic_eventmessage"
,
Event_Message
::
newItem
);
itemNameHash
.
insert
(
"generic_eventgame_joined"
,
Event_GameJoined
::
newItem
);
itemNameHash
.
insert
(
"generic_eventgame_joined"
,
Event_GameJoined
::
newItem
);
itemNameHash
.
insert
(
"generic_eventuser_left"
,
Event_UserLeft
::
newItem
);
itemNameHash
.
insert
(
"generic_eventuser_left"
,
Event_UserLeft
::
newItem
);
itemNameHash
.
insert
(
"
chat
_event
chat_
leave_
channel
"
,
Event_
Chat
Leave
Channel
::
newItem
);
itemNameHash
.
insert
(
"
room
_eventleave_
room
"
,
Event_Leave
Room
::
newItem
);
itemNameHash
.
insert
(
"
chat
_event
chat
_say"
,
Event_
Chat
Say
::
newItem
);
itemNameHash
.
insert
(
"
room
_event
room
_say"
,
Event_
Room
Say
::
newItem
);
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
);
...
...
common/protocol_items.dat
View file @
d8d45632
0:ping
0:ping
0:login:s,username:s,password
0:login:s,username:s,password
0:message:s,user_name:s,text
0:message:s,user_name:s,text
0:list_users
0:get_user_info:s,user_name
0:get_user_info:s,user_name
0:deck_list
0:deck_list
0:deck_new_dir:s,path:s,dir_name
0:deck_new_dir:s,path:s,dir_name
0:deck_del_dir:s,path
0:deck_del_dir:s,path
0:deck_del:i,deck_id
0:deck_del:i,deck_id
0:deck_download:i,deck_id
0:deck_download:i,deck_id
0:list_chat_channels
0:list_rooms
0:chat_join_channel:s,channel
0:join_room:i,room_id
1:chat_leave_channel
1:leave_room
1:chat_say:s,message
1:room_say:s,message
0:list_games
1:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
0:list_users
1:join_game:i,game_id:s,password:b,spectator
0:create_game:s,description:s,password:i,max_players:b,spectators_allowed:b,spectators_need_password:b,spectators_can_talk:b,spectators_see_everything
0:join_game:i,game_id:s,password:b,spectator
2:leave_game
2:leave_game
2:say:s,message
2:say:s,message
2:shuffle
2:shuffle
...
@@ -64,8 +63,8 @@
...
@@ -64,8 +63,8 @@
4:message:s,sender_name:s,receiver_name:s,text
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
4:game_joined:i,game_id:s,game_description:i,player_id:b,spectator:b,spectators_can_talk:b,spectators_see_everything:b,resuming
4:user_left:s,user_name
4:user_left:s,user_name
5:
chat_
leave_
channel
:s,player_name
5:leave_
room
:s,player_name
5:
chat
_say:s,player_name:s,message
5:
room
_say:s,player_name:s,message
6:ready_start
6:ready_start
6:concede
6:concede
6:deck_select:i,deck_id
6:deck_select:i,deck_id
common/protocol_items.h
View file @
d8d45632
...
@@ -28,6 +28,13 @@ public:
...
@@ -28,6 +28,13 @@ public:
static
SerializableItem
*
newItem
()
{
return
new
Command_Message
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_Message
;
}
int
getItemId
()
const
{
return
ItemId_Command_Message
;
}
int
getItemId
()
const
{
return
ItemId_Command_Message
;
}
};
};
class
Command_ListUsers
:
public
Command
{
Q_OBJECT
public:
Command_ListUsers
();
static
SerializableItem
*
newItem
()
{
return
new
Command_ListUsers
;
}
int
getItemId
()
const
{
return
ItemId_Command_ListUsers
;
}
};
class
Command_GetUserInfo
:
public
Command
{
class
Command_GetUserInfo
:
public
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
...
@@ -76,54 +83,40 @@ public:
...
@@ -76,54 +83,40 @@ public:
static
SerializableItem
*
newItem
()
{
return
new
Command_DeckDownload
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_DeckDownload
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckDownload
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeckDownload
;
}
};
};
class
Command_List
ChatChannel
s
:
public
Command
{
class
Command_List
Room
s
:
public
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
Command_List
ChatChannel
s
();
Command_List
Room
s
();
static
SerializableItem
*
newItem
()
{
return
new
Command_List
ChatChannel
s
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_List
Room
s
;
}
int
getItemId
()
const
{
return
ItemId_Command_List
ChatChannel
s
;
}
int
getItemId
()
const
{
return
ItemId_Command_List
Room
s
;
}
};
};
class
Command_
ChatJoinChannel
:
public
Command
{
class
Command_
JoinRoom
:
public
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
Command_
ChatJoinChannel
(
const
QString
&
_channel
=
QString
()
);
Command_
JoinRoom
(
int
_roomId
=
-
1
);
QStr
in
g
get
Channel
()
const
{
return
static_cast
<
SerializableItem_
String
*>
(
itemMap
.
value
(
"
channel
"
))
->
getData
();
};
in
t
get
RoomId
()
const
{
return
static_cast
<
SerializableItem_
Int
*>
(
itemMap
.
value
(
"
room_id
"
))
->
getData
();
};
static
SerializableItem
*
newItem
()
{
return
new
Command_
ChatJoinChannel
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_
JoinRoom
;
}
int
getItemId
()
const
{
return
ItemId_Command_
ChatJoinChannel
;
}
int
getItemId
()
const
{
return
ItemId_Command_
JoinRoom
;
}
};
};
class
Command_
Chat
Leave
Channel
:
public
Chat
Command
{
class
Command_Leave
Room
:
public
Room
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
Command_
Chat
Leave
Channel
(
const
QString
&
_channel
=
QString
()
);
Command_Leave
Room
(
int
_roomId
=
-
1
);
static
SerializableItem
*
newItem
()
{
return
new
Command_
Chat
Leave
Channel
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_Leave
Room
;
}
int
getItemId
()
const
{
return
ItemId_Command_
Chat
Leave
Channel
;
}
int
getItemId
()
const
{
return
ItemId_Command_Leave
Room
;
}
};
};
class
Command_
Chat
Say
:
public
Chat
Command
{
class
Command_
Room
Say
:
public
Room
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
Command_
ChatSay
(
const
QString
&
_channel
=
QString
()
,
const
QString
&
_message
=
QString
());
Command_
RoomSay
(
int
_roomId
=
-
1
,
const
QString
&
_message
=
QString
());
QString
getMessage
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"message"
))
->
getData
();
};
QString
getMessage
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"message"
))
->
getData
();
};
static
SerializableItem
*
newItem
()
{
return
new
Command_ChatSay
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_RoomSay
;
}
int
getItemId
()
const
{
return
ItemId_Command_ChatSay
;
}
int
getItemId
()
const
{
return
ItemId_Command_RoomSay
;
}
};
class
Command_ListGames
:
public
Command
{
Q_OBJECT
public:
Command_ListGames
();
static
SerializableItem
*
newItem
()
{
return
new
Command_ListGames
;
}
int
getItemId
()
const
{
return
ItemId_Command_ListGames
;
}
};
class
Command_ListUsers
:
public
Command
{
Q_OBJECT
public:
Command_ListUsers
();
static
SerializableItem
*
newItem
()
{
return
new
Command_ListUsers
;
}
int
getItemId
()
const
{
return
ItemId_Command_ListUsers
;
}
};
};
class
Command_CreateGame
:
public
Command
{
class
Command_CreateGame
:
public
Room
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
Command_CreateGame
(
const
QString
&
_description
=
QString
(),
const
QString
&
_password
=
QString
(),
int
_maxPlayers
=
-
1
,
bool
_spectatorsAllowed
=
false
,
bool
_spectatorsNeedPassword
=
false
,
bool
_spectatorsCanTalk
=
false
,
bool
_spectatorsSeeEverything
=
false
);
Command_CreateGame
(
int
_roomId
=
-
1
,
const
QString
&
_description
=
QString
(),
const
QString
&
_password
=
QString
(),
int
_maxPlayers
=
-
1
,
bool
_spectatorsAllowed
=
false
,
bool
_spectatorsNeedPassword
=
false
,
bool
_spectatorsCanTalk
=
false
,
bool
_spectatorsSeeEverything
=
false
);
QString
getDescription
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"description"
))
->
getData
();
};
QString
getDescription
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"description"
))
->
getData
();
};
QString
getPassword
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"password"
))
->
getData
();
};
QString
getPassword
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"password"
))
->
getData
();
};
int
getMaxPlayers
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"max_players"
))
->
getData
();
};
int
getMaxPlayers
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"max_players"
))
->
getData
();
};
...
@@ -134,10 +127,10 @@ public:
...
@@ -134,10 +127,10 @@ public:
static
SerializableItem
*
newItem
()
{
return
new
Command_CreateGame
;
}
static
SerializableItem
*
newItem
()
{
return
new
Command_CreateGame
;
}
int
getItemId
()
const
{
return
ItemId_Command_CreateGame
;
}
int
getItemId
()
const
{
return
ItemId_Command_CreateGame
;
}
};
};
class
Command_JoinGame
:
public
Command
{
class
Command_JoinGame
:
public
Room
Command
{
Q_OBJECT
Q_OBJECT
public:
public:
Command_JoinGame
(
int
_gameId
=
-
1
,
const
QString
&
_password
=
QString
(),
bool
_spectator
=
false
);
Command_JoinGame
(
int
_roomId
=
-
1
,
int
_gameId
=
-
1
,
const
QString
&
_password
=
QString
(),
bool
_spectator
=
false
);
int
getGameId
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"game_id"
))
->
getData
();
};
int
getGameId
()
const
{
return
static_cast
<
SerializableItem_Int
*>
(
itemMap
.
value
(
"game_id"
))
->
getData
();
};
QString
getPassword
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"password"
))
->
getData
();
};
QString
getPassword
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"password"
))
->
getData
();
};
bool
getSpectator
()
const
{
return
static_cast
<
SerializableItem_Bool
*>
(
itemMap
.
value
(
"spectator"
))
->
getData
();
};
bool
getSpectator
()
const
{
return
static_cast
<
SerializableItem_Bool
*>
(
itemMap
.
value
(
"spectator"
))
->
getData
();
};
...
@@ -617,22 +610,22 @@ public:
...
@@ -617,22 +610,22 @@ public:
static
SerializableItem
*
newItem
()
{
return
new
Event_UserLeft
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_UserLeft
;
}
int
getItemId
()
const
{
return
ItemId_Event_UserLeft
;
}
int
getItemId
()
const
{
return
ItemId_Event_UserLeft
;
}
};
};
class
Event_
Chat
Leave
Channel
:
public
Chat
Event
{
class
Event_Leave
Room
:
public
Room
Event
{
Q_OBJECT
Q_OBJECT
public:
public:
Event_
Chat
Leave
Channel
(
const
QString
&
_channel
=
QString
()
,
const
QString
&
_playerName
=
QString
());
Event_Leave
Room
(
int
_roomId
=
-
1
,
const
QString
&
_playerName
=
QString
());
QString
getPlayerName
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"player_name"
))
->
getData
();
};
QString
getPlayerName
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"player_name"
))
->
getData
();
};
static
SerializableItem
*
newItem
()
{
return
new
Event_
Chat
Leave
Channel
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_Leave
Room
;
}
int
getItemId
()
const
{
return
ItemId_Event_
Chat
Leave
Channel
;
}
int
getItemId
()
const
{
return
ItemId_Event_Leave
Room
;
}
};
};
class
Event_
Chat
Say
:
public
Chat
Event
{
class
Event_
Room
Say
:
public
Room
Event
{
Q_OBJECT
Q_OBJECT
public:
public:
Event_
ChatSay
(
const
QString
&
_channel
=
QString
()
,
const
QString
&
_playerName
=
QString
(),
const
QString
&
_message
=
QString
());
Event_
RoomSay
(
int
_roomId
=
-
1
,
const
QString
&
_playerName
=
QString
(),
const
QString
&
_message
=
QString
());
QString
getPlayerName
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"player_name"
))
->
getData
();
};
QString
getPlayerName
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"player_name"
))
->
getData
();
};
QString
getMessage
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"message"
))
->
getData
();
};
QString
getMessage
()
const
{
return
static_cast
<
SerializableItem_String
*>
(
itemMap
.
value
(
"message"
))
->
getData
();
};
static
SerializableItem
*
newItem
()
{
return
new
Event_
Chat
Say
;
}
static
SerializableItem
*
newItem
()
{
return
new
Event_
Room
Say
;
}
int
getItemId
()
const
{
return
ItemId_Event_
Chat
Say
;
}
int
getItemId
()
const
{
return
ItemId_Event_
Room
Say
;
}
};
};
class
Context_ReadyStart
:
public
GameEventContext
{
class
Context_ReadyStart
:
public
GameEventContext
{
Q_OBJECT
Q_OBJECT
...
...
common/protocol_mc.pl
View file @
d8d45632
...
@@ -34,10 +34,10 @@ while (<file>) {
...
@@ -34,10 +34,10 @@ while (<file>) {
}
elsif
(
$type
==
1
)
{
}
elsif
(
$type
==
1
)
{
$type
=
'
cmd
';
$type
=
'
cmd
';
$namePrefix
=
'
Command
';
$namePrefix
=
'
Command
';
$baseClass
=
'
Chat
Command
';
$baseClass
=
'
Room
Command
';
$parentConstructorCall
=
"
$baseClass
(
\"
$name1
\"
, _
channel
)
";
$parentConstructorCall
=
"
$baseClass
(
\"
$name1
\"
, _
roomId
)
";
$constructorParamsH
=
"
const QString &_channel = QString()
";
$constructorParamsH
=
"
int _roomId = -1
";
$constructorParamsCpp
=
"
const QString &_channel
";
$constructorParamsCpp
=
"
int _roomId
";
}
elsif
(
$type
==
2
)
{
}
elsif
(
$type
==
2
)
{
$type
=
'
cmd
';
$type
=
'
cmd
';
$namePrefix
=
'
Command
';
$namePrefix
=
'
Command
';
...
@@ -60,12 +60,12 @@ while (<file>) {
...
@@ -60,12 +60,12 @@ while (<file>) {
$constructorParamsH
=
"";
$constructorParamsH
=
"";
$constructorParamsCpp
=
"";
$constructorParamsCpp
=
"";
}
elsif
(
$type
==
5
)
{
}
elsif
(
$type
==
5
)
{
$type
=
'
chat
_event
';
$type
=
'
room
_event
';
$namePrefix
=
'
Event
';
$namePrefix
=
'
Event
';
$baseClass
=
'
Chat
Event
';
$baseClass
=
'
Room
Event
';
$parentConstructorCall
=
"
$baseClass
(
\"
$name1
\"
, _
channel
)
";
$parentConstructorCall
=
"
$baseClass
(
\"
$name1
\"
, _
roomId
)
";
$constructorParamsH
=
"
const QString &_channel = QString()
";
$constructorParamsH
=
"
int _roomId = -1
";
$constructorParamsCpp
=
"
const QString &_channel
";
$constructorParamsCpp
=
"
int _roomId
";
}
elsif
(
$type
==
6
)
{
}
elsif
(
$type
==
6
)
{
$type
=
'
game_event_context
';
$type
=
'
game_event_context
';
$namePrefix
=
'
Context
';
$namePrefix
=
'
Context
';
...
...
common/server.cpp
View file @
d8d45632
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#include
"server.h"
#include
"server.h"
#include
"server_game.h"
#include
"server_game.h"
#include
"server_counter.h"
#include
"server_counter.h"
#include
"server_
chatchannel
.h"
#include
"server_
room
.h"
#include
"server_protocolhandler.h"
#include
"server_protocolhandler.h"
#include
"protocol_datastructures.h"
#include
"protocol_datastructures.h"
#include
<QDebug>
#include
<QDebug>
...
@@ -69,17 +69,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
...
@@ -69,17 +69,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
return
authState
;
return
authState
;
}
}
Server_Game
*
Server
::
createGame
(
const
QString
&
description
,
const
QString
&
password
,
int
maxPlayers
,
bool
spectatorsAllowed
,
bool
spectatorsNeedPassword
,
bool
spectatorsCanTalk
,
bool
spectatorsSeeEverything
,
Server_ProtocolHandler
*
creator
)
{
Server_Game
*
newGame
=
new
Server_Game
(
creator
,
nextGameId
++
,
description
,
password
,
maxPlayers
,
spectatorsAllowed
,
spectatorsNeedPassword
,
spectatorsCanTalk
,
spectatorsSeeEverything
,
this
);
games
.
insert
(
newGame
->
getGameId
(),
newGame
);
connect
(
newGame
,
SIGNAL
(
gameClosing
()),
this
,
SLOT
(
gameClosing
()));
broadcastGameListUpdate
(
newGame
);
return
newGame
;
}
void
Server
::
addClient
(
Server_ProtocolHandler
*
client
)
void
Server
::
addClient
(
Server_ProtocolHandler
*
client
)
{
{
clients
<<
client
;
clients
<<
client
;
...
@@ -106,56 +95,29 @@ Server_Game *Server::getGame(int gameId) const
...
@@ -106,56 +95,29 @@ Server_Game *Server::getGame(int gameId) const
return
games
.
value
(
gameId
);
return
games
.
value
(
gameId
);
}
}
void
Server
::
broadcastGameListUpdate
(
Server_Game
*
game
)
void
Server
::
broadcastRoomUpdate
()
{
QList
<
ServerInfo_Game
*>
eventGameList
;
if
(
game
->
getPlayerCount
())
// Game is open
eventGameList
.
append
(
new
ServerInfo_Game
(
game
->
getGameId
(),
game
->
getDescription
(),
!
game
->
getPassword
().
isEmpty
(),
game
->
getPlayerCount
(),
game
->
getMaxPlayers
(),
new
ServerInfo_User
(
game
->
getCreatorInfo
()),
game
->
getSpectatorsAllowed
(),
game
->
getSpectatorsNeedPassword
(),
game
->
getSpectatorCount
()
));
else
// Game is closing
eventGameList
.
append
(
new
ServerInfo_Game
(
game
->
getGameId
(),
QString
(),
false
,
0
,
game
->
getMaxPlayers
(),
0
,
false
,
0
));
Event_ListGames
*
event
=
new
Event_ListGames
(
eventGameList
);
for
(
int
i
=
0
;
i
<
clients
.
size
();
i
++
)
if
(
clients
[
i
]
->
getAcceptsGameListChanges
())
clients
[
i
]
->
sendProtocolItem
(
event
,
false
);
delete
event
;
}
void
Server
::
broadcastChannelUpdate
()
{
{
Server_
ChatChannel
*
channel
=
static_cast
<
Server_
ChatChannel
*>
(
sender
());
Server_
Room
*
room
=
static_cast
<
Server_
Room
*>
(
sender
());
QList
<
ServerInfo_
ChatChannel
*>
event
Channel
List
;
QList
<
ServerInfo_
Room
*>
event
Room
List
;
event
Channel
List
.
append
(
new
ServerInfo_
ChatChannel
(
channel
->
getName
(),
channel
->
getDescription
(),
channel
->
size
(),
channel
->
getAutoJoin
()));
event
Room
List
.
append
(
new
ServerInfo_
Room
(
room
->
getId
(),
room
->
getName
(),
room
->
getDescription
(),
room
->
getGames
().
size
(),
room
->
size
(),
room
->
getAutoJoin
()));
Event_List
ChatChannel
s
*
event
=
new
Event_List
ChatChannels
(
eventChannel
List
);
Event_List
Room
s
*
event
=
new
Event_List
Rooms
(
eventRoom
List
);
for
(
int
i
=
0
;
i
<
clients
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
clients
.
size
();
++
i
)
if
(
clients
[
i
]
->
getAccepts
ChatChannel
ListChanges
())
if
(
clients
[
i
]
->
getAccepts
Room
ListChanges
())
clients
[
i
]
->
sendProtocolItem
(
event
,
false
);
clients
[
i
]
->
sendProtocolItem
(
event
,
false
);
delete
event
;
delete
event
;
}
}
void
Server
::
gameClosing
()
void
Server
::
gameClosing
(
int
gameId
)
{
{
qDebug
(
"Server::gameClosing"
);
qDebug
(
"Server::gameClosing"
);
Server_Game
*
game
=
static_cast
<
Server_Game
*>
(
sender
());
games
.
remove
(
gameId
);
broadcastGameListUpdate
(
game
);
games
.
remove
(
games
.
key
(
game
));
}
}
void
Server
::
add
ChatChannel
(
Server_ChatChannel
*
newChannel
)
void
Server
::
add
Room
(
Server_Room
*
newRoom
)
{
{
chatChannels
.
insert
(
newChannel
->
getName
(),
newChannel
);
rooms
.
insert
(
newRoom
->
getId
(),
newRoom
);
connect
(
newChannel
,
SIGNAL
(
channelInfoChanged
()),
this
,
SLOT
(
broadcastChannelUpdate
()));
connect
(
newRoom
,
SIGNAL
(
roomInfoChanged
()),
this
,
SLOT
(
broadcastRoomUpdate
()));
connect
(
newRoom
,
SIGNAL
(
gameCreated
(
Server_Game
*
)),
this
,
SLOT
(
gameCreated
(
Server_Game
*
)));
connect
(
newRoom
,
SIGNAL
(
gameClosing
(
int
)),
this
,
SLOT
(
gameClosing
(
int
)));
}
}
common/server.h
View file @
d8d45632
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include
<QMap>
#include
<QMap>
class
Server_Game
;
class
Server_Game
;
class
Server_
ChatChannel
;
class
Server_
Room
;
class
Server_ProtocolHandler
;
class
Server_ProtocolHandler
;
class
ServerInfo_User
;
class
ServerInfo_User
;
...
@@ -18,22 +18,21 @@ class Server : public QObject
...
@@ -18,22 +18,21 @@ class Server : public QObject
signals:
signals:
void
pingClockTimeout
();
void
pingClockTimeout
();
private
slots
:
private
slots
:
void
gameClosing
();
void
gameClosing
(
int
gameId
);
void
broadcast
Channel
Update
();
void
broadcast
Room
Update
();
public:
public:
Server
(
QObject
*
parent
=
0
);
Server
(
QObject
*
parent
=
0
);
~
Server
();
~
Server
();
AuthenticationResult
loginUser
(
Server_ProtocolHandler
*
session
,
QString
&
name
,
const
QString
&
password
);
AuthenticationResult
loginUser
(
Server_ProtocolHandler
*
session
,
QString
&
name
,
const
QString
&
password
);
QList
<
Server_Game
*>
getGames
()
const
{
return
games
.
values
();
}
QList
<
Server_Game
*>
getGames
()
const
{
return
games
.
values
();
}
Server_Game
*
getGame
(
int
gameId
)
const
;
Server_Game
*
getGame
(
int
gameId
)
const
;
const
QMap
<
QStr
in
g
,
Server_
ChatChannel
*>
&
getChatChannel
s
()
{
return
chatChannel
s
;
}
const
QMap
<
in
t
,
Server_
Room
*>
&
getRoom
s
()
{
return
room
s
;
}
void
broadcastGameListUpdate
(
Server_Game
*
game
);
int
getNextGameId
()
{
return
nextGameId
++
;
}
const
QMap
<
QString
,
Server_ProtocolHandler
*>
&
getUsers
()
const
{
return
users
;
}
const
QMap
<
QString
,
Server_ProtocolHandler
*>
&
getUsers
()
const
{
return
users
;
}
void
addClient
(
Server_ProtocolHandler
*
player
);
void
addClient
(
Server_ProtocolHandler
*
player
);
void
removeClient
(
Server_ProtocolHandler
*
player
);
void
removeClient
(
Server_ProtocolHandler
*
player
);
virtual
QString
getLoginMessage
()
const
=
0
;
virtual
QString
getLoginMessage
()
const
=
0
;
Server_Game
*
createGame
(
const
QString
&
description
,
const
QString
&
password
,
int
maxPlayers
,
bool
spectatorsAllowed
,
bool
spectatorsNeedPassword
,
bool
spectatorsCanTalk
,
bool
spectatorsSeeEverything
,
Server_ProtocolHandler
*
creator
);
virtual
bool
getGameShouldPing
()
const
=
0
;
virtual
bool
getGameShouldPing
()
const
=
0
;
virtual
int
getMaxGameInactivityTime
()
const
=
0
;
virtual
int
getMaxGameInactivityTime
()
const
=
0
;
...
@@ -42,12 +41,12 @@ protected:
...
@@ -42,12 +41,12 @@ protected:
QMap
<
int
,
Server_Game
*>
games
;
QMap
<
int
,
Server_Game
*>
games
;
QList
<
Server_ProtocolHandler
*>
clients
;
QList
<
Server_ProtocolHandler
*>
clients
;
QMap
<
QString
,
Server_ProtocolHandler
*>
users
;
QMap
<
QString
,
Server_ProtocolHandler
*>
users
;
QMap
<
QStr
in
g
,
Server_
ChatChannel
*>
chatChannel
s
;
QMap
<
in
t
,
Server_
Room
*>
room
s
;
virtual
AuthenticationResult
checkUserPassword
(
const
QString
&
user
,
const
QString
&
password
)
=
0
;
virtual
AuthenticationResult
checkUserPassword
(
const
QString
&
user
,
const
QString
&
password
)
=
0
;
virtual
ServerInfo_User
*
getUserData
(
const
QString
&
name
)
=
0
;
virtual
ServerInfo_User
*
getUserData
(
const
QString
&
name
)
=
0
;
int
nextGameId
;
int
nextGameId
;
void
add
ChatChannel
(
Server_ChatChannel
*
newChannel
);
void
add
Room
(
Server_Room
*
newRoom
);
};
};
#endif
#endif
common/server_chatchannel.cpp
deleted
100644 → 0
View file @
76a13be3
#include
"server_chatchannel.h"
#include
"server_protocolhandler.h"
Server_ChatChannel
::
Server_ChatChannel
(
const
QString
&
_name
,
const
QString
&
_description
,
bool
_autoJoin
,
const
QString
&
_joinMessage
)
:
name
(
_name
),
description
(
_description
),
autoJoin
(
_autoJoin
),
joinMessage
(
_joinMessage
)
{
}
void
Server_ChatChannel
::
addClient
(
Server_ProtocolHandler
*
client
)
{
sendChatEvent
(
new
Event_ChatJoinChannel
(
name
,
new
ServerInfo_User
(
client
->
getUserInfo
())));
append
(
client
);
QList
<
ServerInfo_User
*>
eventUserList
;
for
(
int
i
=
0
;
i
<
size
();
++
i
)
eventUserList
.
append
(
new
ServerInfo_User
(
at
(
i
)
->
getUserInfo
()));
Event_ChatListPlayers
*
eventCLP
=
new
Event_ChatListPlayers
(
name
,
eventUserList
);
client
->
enqueueProtocolItem
(
eventCLP
);
client
->
enqueueProtocolItem
(
new
Event_ChatSay
(
name
,
QString
(),
joinMessage
));
emit
channelInfoChanged
();
}
void
Server_ChatChannel
::
removeClient
(
Server_ProtocolHandler
*
client
)
{
removeAt
(
indexOf
(
client
));
sendChatEvent
(
new
Event_ChatLeaveChannel
(
name
,
client
->
getUserInfo
()
->
getName
()));
emit
channelInfoChanged
();
}
void
Server_ChatChannel
::
say
(
Server_ProtocolHandler
*
client
,
const
QString
&
s
)
{
sendChatEvent
(
new
Event_ChatSay
(
name
,
client
->
getUserInfo
()
->
getName
(),
s
));
}
void
Server_ChatChannel
::
sendChatEvent
(
ChatEvent
*
event
)
{
for
(
int
i
=
0
;
i
<
size
();
++
i
)
at
(
i
)
->
sendProtocolItem
(
event
,
false
);
delete
event
;
}
common/server_game.cpp
View file @
d8d45632
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
***************************************************************************/
#include
"server.h"
#include
"server.h"
#include
"server_room.h"
#include
"server_game.h"
#include
"server_game.h"
#include
"server_protocolhandler.h"
#include
"server_protocolhandler.h"
#include
"server_arrow.h"
#include
"server_arrow.h"
...
@@ -27,12 +28,12 @@
...
@@ -27,12 +28,12 @@
#include
<QTimer>
#include
<QTimer>
#include
<QDebug>
#include
<QDebug>
Server_Game
::
Server_Game
(
Server_ProtocolHandler
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
,
Server
*
parent
)
Server_Game
::
Server_Game
(
Server_ProtocolHandler
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
,
Server
_Room
*
parent
)
:
QObject
(
parent
),
creatorInfo
(
new
ServerInfo_User
(
_creator
->
getUserInfo
())),
gameStarted
(
false
),
gameId
(
_gameId
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
),
activePlayer
(
-
1
),
activePhase
(
-
1
),
spectatorsAllowed
(
_spectatorsAllowed
),
spectatorsNeedPassword
(
_spectatorsNeedPassword
),
spectatorsCanTalk
(
_spectatorsCanTalk
),
spectatorsSeeEverything
(
_spectatorsSeeEverything
),
inactivityCounter
(
0
)
:
QObject
(
parent
),
creatorInfo
(
new
ServerInfo_User
(
_creator
->
getUserInfo
())),
gameStarted
(
false
),
gameId
(
_gameId
),
description
(
_description
),
password
(
_password
),
maxPlayers
(
_maxPlayers
),
activePlayer
(
-
1
),
activePhase
(
-
1
),
spectatorsAllowed
(
_spectatorsAllowed
),
spectatorsNeedPassword
(
_spectatorsNeedPassword
),
spectatorsCanTalk
(
_spectatorsCanTalk
),
spectatorsSeeEverything
(
_spectatorsSeeEverything
),
inactivityCounter
(
0
)
{
{
addPlayer
(
_creator
,
false
,
false
);
addPlayer
(
_creator
,
false
,
false
);
if
(
parent
->
getGameShouldPing
())
{
if
(
parent
->
getServer
()
->
getGameShouldPing
())
{
pingClock
=
new
QTimer
(
this
);
pingClock
=
new
QTimer
(
this
);
connect
(
pingClock
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
pingClockTimeout
()));
connect
(
pingClock
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
pingClockTimeout
()));
pingClock
->
start
(
1000
);
pingClock
->
start
(
1000
);
...
@@ -71,7 +72,7 @@ void Server_Game::pingClockTimeout()
...
@@ -71,7 +72,7 @@ void Server_Game::pingClockTimeout()
}
}
sendGameEvent
(
new
Event_Ping
(
pingList
));
sendGameEvent
(
new
Event_Ping
(
pingList
));
const
int
maxTime
=
static_cast
<
Server
*>
(
parent
())
->
getMaxGameInactivityTime
();
const
int
maxTime
=
static_cast
<
Server
_Room
*>
(
parent
())
->
getServer
()
->
getMaxGameInactivityTime
();
if
(
allPlayersInactive
)
{
if
(
allPlayersInactive
)
{
if
((
++
inactivityCounter
>=
maxTime
)
&&
(
maxTime
>
0
))
if
((
++
inactivityCounter
>=
maxTime
)
&&
(
maxTime
>
0
))
deleteLater
();
deleteLater
();
...
@@ -193,7 +194,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
...
@@ -193,7 +194,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
players
.
insert
(
playerId
,
newPlayer
);
players
.
insert
(
playerId
,
newPlayer
);
if
(
broadcastUpdate
)
if
(
broadcastUpdate
)
qobject_cast
<
Server
*>
(
parent
())
->
broadcastGameListUpdate
(
this
);
qobject_cast
<
Server
_Room
*>
(
parent
())
->
broadcastGameListUpdate
(
this
);
return
newPlayer
;
return
newPlayer
;
}
}
...
@@ -231,7 +232,7 @@ void Server_Game::removePlayer(Server_Player *player)
...
@@ -231,7 +232,7 @@ void Server_Game::removePlayer(Server_Player *player)
deleteLater
();
deleteLater
();
else
if
(
!
spectator
)
else
if
(
!
spectator
)
stopGameIfFinished
();
stopGameIfFinished
();
qobject_cast
<
Server
*>
(
parent
())
->
broadcastGameListUpdate
(
this
);
qobject_cast
<
Server
_Room
*>
(
parent
())
->
broadcastGameListUpdate
(
this
);
}
}
void
Server_Game
::
setActivePlayer
(
int
_activePlayer
)
void
Server_Game
::
setActivePlayer
(
int
_activePlayer
)
...
@@ -391,3 +392,23 @@ void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
...
@@ -391,3 +392,23 @@ void Server_Game::sendGameEventToPlayer(Server_Player *player, GameEvent *event)
{
{
player
->
sendProtocolItem
(
new
GameEventContainer
(
QList
<
GameEvent
*>
()
<<
event
,
gameId
));
player
->
sendProtocolItem
(
new
GameEventContainer
(
QList
<
GameEvent
*>
()
<<
event
,
gameId
));
}
}
ServerInfo_Game
*
Server_Game
::
getInfo
()
const
{
if
(
players
.
isEmpty
())
// Game is open
return
new
ServerInfo_Game
(
getGameId
(),
QString
(),
false
,
0
,
getMaxPlayers
(),
0
,
false
,
0
);
else
// Game is closing
return
new
ServerInfo_Game
(
getGameId
(),
getDescription
(),
!
getPassword
().
isEmpty
(),
getPlayerCount
(),
getMaxPlayers
(),
new
ServerInfo_User
(
getCreatorInfo
()),
getSpectatorsAllowed
(),
getSpectatorsNeedPassword
(),
getSpectatorCount
()
);
}
\ No newline at end of file
common/server_game.h
View file @
d8d45632
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
#include
"protocol.h"
#include
"protocol.h"
class
QTimer
;
class
QTimer
;
class
Server
;
class
Server
_Room
;
class
ServerInfo_User
;
class
ServerInfo_User
;
class
Server_Game
:
public
QObject
{
class
Server_Game
:
public
QObject
{
...
@@ -52,8 +52,9 @@ signals:
...
@@ -52,8 +52,9 @@ signals:
private
slots
:
private
slots
:
void
pingClockTimeout
();
void
pingClockTimeout
();
public:
public:
Server_Game
(
Server_ProtocolHandler
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
,
Server
*
parent
);
Server_Game
(
Server_ProtocolHandler
*
_creator
,
int
_gameId
,
const
QString
&
_description
,
const
QString
&
_password
,
int
_maxPlayers
,
bool
_spectatorsAllowed
,
bool
_spectatorsNeedPassword
,
bool
_spectatorsCanTalk
,
bool
_spectatorsSeeEverything
,
Server
_Room
*
parent
);
~
Server_Game
();
~
Server_Game
();
ServerInfo_Game
*
getInfo
()
const
;
ServerInfo_User
*
getCreatorInfo
()
const
{
return
creatorInfo
;
}
ServerInfo_User
*
getCreatorInfo
()
const
{
return
creatorInfo
;
}
bool
getGameStarted
()
const
{
return
gameStarted
;
}
bool
getGameStarted
()
const
{
return
gameStarted
;
}
int
getPlayerCount
()
const
;
int
getPlayerCount
()
const
;
...
...
common/server_protocolhandler.cpp
View file @
d8d45632
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include
"server_protocolhandler.h"
#include
"server_protocolhandler.h"
#include
"protocol.h"
#include
"protocol.h"
#include
"protocol_items.h"
#include
"protocol_items.h"
#include
"server_
chatchannel
.h"
#include
"server_
room
.h"
#include
"server_card.h"
#include
"server_card.h"
#include
"server_arrow.h"
#include
"server_arrow.h"
#include
"server_cardzone.h"
#include
"server_cardzone.h"
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
#include
<QDateTime>
#include
<QDateTime>
Server_ProtocolHandler
::
Server_ProtocolHandler
(
Server
*
_server
,
QObject
*
parent
)
Server_ProtocolHandler
::
Server_ProtocolHandler
(
Server
*
_server
,
QObject
*
parent
)
:
QObject
(
parent
),
server
(
_server
),
authState
(
PasswordWrong
),
acceptsGameListChanges
(
false
),
acceptsUserListChanges
(
false
),
accepts
ChatChannel
ListChanges
(
false
),
userInfo
(
0
),
lastCommandTime
(
QDateTime
::
currentDateTime
())
:
QObject
(
parent
),
server
(
_server
),
authState
(
PasswordWrong
),
acceptsUserListChanges
(
false
),
accepts
Room
ListChanges
(
false
),
userInfo
(
0
),
lastCommandTime
(
QDateTime
::
currentDateTime
())
{
{
connect
(
server
,
SIGNAL
(
pingClockTimeout
()),
this
,
SLOT
(
pingClockTimeout
()));
connect
(
server
,
SIGNAL
(
pingClockTimeout
()),
this
,
SLOT
(
pingClockTimeout
()));
}
}
...
@@ -37,9 +37,9 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
...
@@ -37,9 +37,9 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
p
->
setProtocolHandler
(
0
);
p
->
setProtocolHandler
(
0
);
}
}
QMapIterator
<
QStr
in
g
,
Server_
ChatChannel
*>
chatChannelIterator
(
chatChannel
s
);
QMapIterator
<
in
t
,
Server_
Room
*>
roomIterator
(
room
s
);
while
(
chatChannel
Iterator
.
hasNext
())
while
(
room
Iterator
.
hasNext
())
chatChannel
Iterator
.
next
().
value
()
->
removeClient
(
this
);
room
Iterator
.
next
().
value
()
->
removeClient
(
this
);
delete
userInfo
;
delete
userInfo
;
}
}
...
@@ -54,20 +54,22 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
...
@@ -54,20 +54,22 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
{
{
lastCommandTime
=
QDateTime
::
currentDateTime
();
lastCommandTime
=
QDateTime
::
currentDateTime
();
Chat
Command
*
chat
Command
=
qobject_cast
<
Chat
Command
*>
(
command
);
Room
Command
*
room
Command
=
qobject_cast
<
Room
Command
*>
(
command
);
GameCommand
*
gameCommand
=
qobject_cast
<
GameCommand
*>
(
command
);
GameCommand
*
gameCommand
=
qobject_cast
<
GameCommand
*>
(
command
);
if
(
chat
Command
)
{
if
(
room
Command
)
{
qDebug
()
<<
"received
Chat
Command:
channel
="
<<
chat
Command
->
get
Channel
();
qDebug
()
<<
"received
Room
Command:
roomId
="
<<
room
Command
->
get
RoomId
();
if
(
authState
==
PasswordWrong
)
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
return
RespLoginNeeded
;
Server_
ChatChannel
*
channel
=
chatChannel
s
.
value
(
chat
Command
->
get
Channel
(),
0
);
Server_
Room
*
room
=
room
s
.
value
(
room
Command
->
get
RoomId
(),
0
);
if
(
!
channel
)
if
(
!
room
)
return
RespNameNotFound
;
return
RespNameNotFound
;
switch
(
command
->
getItemId
())
{
switch
(
command
->
getItemId
())
{
case
ItemId_Command_ChatLeaveChannel
:
return
cmdChatLeaveChannel
(
qobject_cast
<
Command_ChatLeaveChannel
*>
(
command
),
cont
,
channel
);
case
ItemId_Command_LeaveRoom
:
return
cmdLeaveRoom
(
qobject_cast
<
Command_LeaveRoom
*>
(
command
),
cont
,
room
);
case
ItemId_Command_ChatSay
:
return
cmdChatSay
(
qobject_cast
<
Command_ChatSay
*>
(
command
),
cont
,
channel
);
case
ItemId_Command_RoomSay
:
return
cmdRoomSay
(
qobject_cast
<
Command_RoomSay
*>
(
command
),
cont
,
room
);
case
ItemId_Command_CreateGame
:
return
cmdCreateGame
(
qobject_cast
<
Command_CreateGame
*>
(
command
),
cont
,
room
);
case
ItemId_Command_JoinGame
:
return
cmdJoinGame
(
qobject_cast
<
Command_JoinGame
*>
(
command
),
cont
,
room
);
}
}
}
else
if
(
gameCommand
)
{
}
else
if
(
gameCommand
)
{
qDebug
()
<<
"received GameCommand: game ="
<<
gameCommand
->
getGameId
();
qDebug
()
<<
"received GameCommand: game ="
<<
gameCommand
->
getGameId
();
...
@@ -125,12 +127,9 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
...
@@ -125,12 +127,9 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
case
ItemId_Command_DeckUpload
:
return
cmdDeckUpload
(
qobject_cast
<
Command_DeckUpload
*>
(
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_DeckDownload
:
return
cmdDeckDownload
(
qobject_cast
<
Command_DeckDownload
*>
(
command
),
cont
);
case
ItemId_Command_GetUserInfo
:
return
cmdGetUserInfo
(
qobject_cast
<
Command_GetUserInfo
*>
(
command
),
cont
);
case
ItemId_Command_GetUserInfo
:
return
cmdGetUserInfo
(
qobject_cast
<
Command_GetUserInfo
*>
(
command
),
cont
);
case
ItemId_Command_List
ChatChannel
s
:
return
cmdList
ChatChannel
s
(
qobject_cast
<
Command_List
ChatChannel
s
*>
(
command
),
cont
);
case
ItemId_Command_List
Room
s
:
return
cmdList
Room
s
(
qobject_cast
<
Command_List
Room
s
*>
(
command
),
cont
);
case
ItemId_Command_
ChatJoinChannel
:
return
cmdChatJoinChannel
(
qobject_cast
<
Command_
ChatJoinChannel
*>
(
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
);
case
ItemId_Command_ListUsers
:
return
cmdListUsers
(
qobject_cast
<
Command_ListUsers
*>
(
command
),
cont
);
case
ItemId_Command_ListGames
:
return
cmdListGames
(
qobject_cast
<
Command_ListGames
*>
(
command
),
cont
);
case
ItemId_Command_CreateGame
:
return
cmdCreateGame
(
qobject_cast
<
Command_CreateGame
*>
(
command
),
cont
);
case
ItemId_Command_JoinGame
:
return
cmdJoinGame
(
qobject_cast
<
Command_JoinGame
*>
(
command
),
cont
);
}
}
}
}
return
RespInvalidCommand
;
return
RespInvalidCommand
;
...
@@ -273,51 +272,50 @@ ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, Co
...
@@ -273,51 +272,50 @@ ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, Co
return
RespNothing
;
return
RespNothing
;
}
}
ResponseCode
Server_ProtocolHandler
::
cmdList
ChatChannel
s
(
Command_List
ChatChannel
s
*
/*cmd*/
,
CommandContainer
*
cont
)
ResponseCode
Server_ProtocolHandler
::
cmdList
Room
s
(
Command_List
Room
s
*
/*cmd*/
,
CommandContainer
*
cont
)
{
{
if
(
authState
==
PasswordWrong
)
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
return
RespLoginNeeded
;
QList
<
ServerInfo_
ChatChannel
*>
event
Channel
List
;
QList
<
ServerInfo_
Room
*>
event
Room
List
;
QMapIterator
<
QStr
in
g
,
Server_
ChatChannel
*>
channel
Iterator
(
server
->
get
ChatChannel
s
());
QMapIterator
<
in
t
,
Server_
Room
*>
room
Iterator
(
server
->
get
Room
s
());
while
(
channel
Iterator
.
hasNext
())
{
while
(
room
Iterator
.
hasNext
())
{
Server_
ChatChannel
*
c
=
channel
Iterator
.
next
().
value
();
Server_
Room
*
r
=
room
Iterator
.
next
().
value
();
event
Channel
List
.
append
(
new
ServerInfo_
ChatChannel
(
c
->
getName
(),
c
->
getDescription
(),
c
->
size
(),
c
->
getAutoJoin
()));
event
Room
List
.
append
(
new
ServerInfo_
Room
(
r
->
getId
(),
r
->
getName
(),
r
->
getDescription
(),
r
->
getGames
().
size
(),
r
->
size
(),
r
->
getAutoJoin
()));
}
}
cont
->
enqueueItem
(
new
Event_List
ChatChannels
(
eventChannel
List
));
cont
->
enqueueItem
(
new
Event_List
Rooms
(
eventRoom
List
));
accepts
ChatChannel
ListChanges
=
true
;
accepts
Room
ListChanges
=
true
;
return
RespOk
;
return
RespOk
;
}
}
ResponseCode
Server_ProtocolHandler
::
cmd
ChatJoinChannel
(
Command_ChatJoinChannel
*
cmd
,
CommandContainer
*
cont
)
ResponseCode
Server_ProtocolHandler
::
cmd
JoinRoom
(
Command_JoinRoom
*
cmd
,
CommandContainer
*
cont
)
{
{
if
(
authState
==
PasswordWrong
)
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
return
RespLoginNeeded
;
if
(
chatChannel
s
.
contains
(
cmd
->
get
Channel
()))
if
(
room
s
.
contains
(
cmd
->
get
RoomId
()))
return
RespContextError
;
return
RespContextError
;
QMap
<
QString
,
Server_ChatChannel
*>
allChannels
=
server
->
getChatChannels
();
Server_Room
*
r
=
server
->
getRooms
().
value
(
cmd
->
getRoomId
(),
0
);
Server_ChatChannel
*
c
=
allChannels
.
value
(
cmd
->
getChannel
(),
0
);
if
(
!
r
)
if
(
!
c
)
return
RespNameNotFound
;
return
RespNameNotFound
;
c
->
addClient
(
this
);
r
->
addClient
(
this
);
chatChannel
s
.
insert
(
cmd
->
get
Channel
(),
c
);
room
s
.
insert
(
r
->
get
Id
(),
r
);
return
RespOk
;
return
RespOk
;
}
}
ResponseCode
Server_ProtocolHandler
::
cmd
Chat
Leave
Channel
(
Command_
Chat
Leave
Channel
*
/*cmd*/
,
CommandContainer
*
cont
,
Server_
ChatChannel
*
channel
)
ResponseCode
Server_ProtocolHandler
::
cmdLeave
Room
(
Command_Leave
Room
*
/*cmd*/
,
CommandContainer
*
cont
,
Server_
Room
*
room
)
{
{
chatChannel
s
.
remove
(
channel
->
get
Name
());
room
s
.
remove
(
room
->
get
Id
());
channel
->
removeClient
(
this
);
room
->
removeClient
(
this
);
return
RespOk
;
return
RespOk
;
}
}
ResponseCode
Server_ProtocolHandler
::
cmd
Chat
Say
(
Command_
Chat
Say
*
cmd
,
CommandContainer
*
cont
,
Server_
ChatChannel
*
channel
)
ResponseCode
Server_ProtocolHandler
::
cmd
Room
Say
(
Command_
Room
Say
*
cmd
,
CommandContainer
*
cont
,
Server_
Room
*
room
)
{
{
channel
->
say
(
this
,
cmd
->
getMessage
());
room
->
say
(
this
,
cmd
->
getMessage
());
return
RespOk
;
return
RespOk
;
}
}
...
@@ -337,39 +335,12 @@ ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, C
...
@@ -337,39 +335,12 @@ ResponseCode Server_ProtocolHandler::cmdListUsers(Command_ListUsers * /*cmd*/, C
return
RespNothing
;
return
RespNothing
;
}
}
ResponseCode
Server_ProtocolHandler
::
cmdListGames
(
Command_ListGames
*
/*cmd*/
,
CommandContainer
*
cont
)
ResponseCode
Server_ProtocolHandler
::
cmdCreateGame
(
Command_CreateGame
*
cmd
,
CommandContainer
*
cont
,
Server_Room
*
room
)
{
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
const
QList
<
Server_Game
*>
&
gameList
=
server
->
getGames
();
QList
<
ServerInfo_Game
*>
eventGameList
;
for
(
int
i
=
0
;
i
<
gameList
.
size
();
++
i
)
{
Server_Game
*
g
=
gameList
[
i
];
eventGameList
.
append
(
new
ServerInfo_Game
(
g
->
getGameId
(),
g
->
getDescription
(),
!
g
->
getPassword
().
isEmpty
(),
g
->
getPlayerCount
(),
g
->
getMaxPlayers
(),
new
ServerInfo_User
(
g
->
getCreatorInfo
()),
g
->
getSpectatorsAllowed
(),
g
->
getSpectatorsNeedPassword
(),
g
->
getSpectatorCount
()
));
}
cont
->
enqueueItem
(
new
Event_ListGames
(
eventGameList
));
acceptsGameListChanges
=
true
;
return
RespOk
;
}
ResponseCode
Server_ProtocolHandler
::
cmdCreateGame
(
Command_CreateGame
*
cmd
,
CommandContainer
*
cont
)
{
{
if
(
authState
==
PasswordWrong
)
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
return
RespLoginNeeded
;
Server_Game
*
game
=
server
->
createGame
(
cmd
->
getDescription
(),
cmd
->
getPassword
(),
cmd
->
getMaxPlayers
(),
cmd
->
getSpectatorsAllowed
(),
cmd
->
getSpectatorsNeedPassword
(),
cmd
->
getSpectatorsCanTalk
(),
cmd
->
getSpectatorsSeeEverything
(),
this
);
Server_Game
*
game
=
room
->
createGame
(
cmd
->
getDescription
(),
cmd
->
getPassword
(),
cmd
->
getMaxPlayers
(),
cmd
->
getSpectatorsAllowed
(),
cmd
->
getSpectatorsNeedPassword
(),
cmd
->
getSpectatorsCanTalk
(),
cmd
->
getSpectatorsSeeEverything
(),
this
);
Server_Player
*
creator
=
game
->
getPlayers
().
values
().
first
();
Server_Player
*
creator
=
game
->
getPlayers
().
values
().
first
();
games
.
insert
(
game
->
getGameId
(),
QPair
<
Server_Game
*
,
Server_Player
*>
(
game
,
creator
));
games
.
insert
(
game
->
getGameId
(),
QPair
<
Server_Game
*
,
Server_Player
*>
(
game
,
creator
));
...
@@ -378,7 +349,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
...
@@ -378,7 +349,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd, Comm
return
RespOk
;
return
RespOk
;
}
}
ResponseCode
Server_ProtocolHandler
::
cmdJoinGame
(
Command_JoinGame
*
cmd
,
CommandContainer
*
cont
)
ResponseCode
Server_ProtocolHandler
::
cmdJoinGame
(
Command_JoinGame
*
cmd
,
CommandContainer
*
cont
,
Server_Room
*
room
)
{
{
if
(
authState
==
PasswordWrong
)
if
(
authState
==
PasswordWrong
)
return
RespLoginNeeded
;
return
RespLoginNeeded
;
...
@@ -386,7 +357,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandC
...
@@ -386,7 +357,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd, CommandC
if
(
games
.
contains
(
cmd
->
getGameId
()))
if
(
games
.
contains
(
cmd
->
getGameId
()))
return
RespContextError
;
return
RespContextError
;
Server_Game
*
g
=
server
->
getGame
(
cmd
->
getGameId
());
Server_Game
*
g
=
room
->
getGame
s
().
value
(
cmd
->
getGameId
());
if
(
!
g
)
if
(
!
g
)
return
RespNameNotFound
;
return
RespNameNotFound
;
...
...
common/server_protocolhandler.h
View file @
d8d45632
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
class
Server_Player
;
class
Server_Player
;
class
Server_Card
;
class
Server_Card
;
class
ServerInfo_User
;
class
ServerInfo_User
;
class
Server_Room
;
class
QTimer
;
class
QTimer
;
class
Server_ProtocolHandler
:
public
QObject
{
class
Server_ProtocolHandler
:
public
QObject
{
...
@@ -17,15 +18,14 @@ class Server_ProtocolHandler : public QObject {
...
@@ -17,15 +18,14 @@ class Server_ProtocolHandler : public QObject {
protected:
protected:
Server
*
server
;
Server
*
server
;
QMap
<
int
,
QPair
<
Server_Game
*
,
Server_Player
*>
>
games
;
QMap
<
int
,
QPair
<
Server_Game
*
,
Server_Player
*>
>
games
;
QMap
<
QStr
in
g
,
Server_
ChatChannel
*>
chatChannel
s
;
QMap
<
in
t
,
Server_
Room
*>
room
s
;
Server
*
getServer
()
const
{
return
server
;
}
Server
*
getServer
()
const
{
return
server
;
}
QPair
<
Server_Game
*
,
Server_Player
*>
getGame
(
int
gameId
)
const
;
QPair
<
Server_Game
*
,
Server_Player
*>
getGame
(
int
gameId
)
const
;
AuthenticationResult
authState
;
AuthenticationResult
authState
;
bool
acceptsGameListChanges
;
bool
acceptsUserListChanges
;
bool
acceptsUserListChanges
;
bool
accepts
ChatChannel
ListChanges
;
bool
accepts
Room
ListChanges
;
ServerInfo_User
*
userInfo
;
ServerInfo_User
*
userInfo
;
private:
private:
...
@@ -45,14 +45,13 @@ private:
...
@@ -45,14 +45,13 @@ private:
virtual
ResponseCode
cmdDeckUpload
(
Command_DeckUpload
*
cmd
,
CommandContainer
*
cont
)
=
0
;
virtual
ResponseCode
cmdDeckUpload
(
Command_DeckUpload
*
cmd
,
CommandContainer
*
cont
)
=
0
;
virtual
ResponseCode
cmdDeckDownload
(
Command_DeckDownload
*
cmd
,
CommandContainer
*
cont
)
=
0
;
virtual
ResponseCode
cmdDeckDownload
(
Command_DeckDownload
*
cmd
,
CommandContainer
*
cont
)
=
0
;
ResponseCode
cmdGetUserInfo
(
Command_GetUserInfo
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdGetUserInfo
(
Command_GetUserInfo
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdList
ChatChannel
s
(
Command_List
ChatChannel
s
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdList
Room
s
(
Command_List
Room
s
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmd
ChatJoinChannel
(
Command_ChatJoinChannel
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmd
JoinRoom
(
Command_JoinRoom
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmd
Chat
Leave
Channel
(
Command_
Chat
Leave
Channel
*
cmd
,
CommandContainer
*
cont
,
Server_
ChatChannel
*
channel
);
ResponseCode
cmdLeave
Room
(
Command_Leave
Room
*
cmd
,
CommandContainer
*
cont
,
Server_
Room
*
room
);
ResponseCode
cmd
Chat
Say
(
Command_
Chat
Say
*
cmd
,
CommandContainer
*
cont
,
Server_
ChatChannel
*
channel
);
ResponseCode
cmd
Room
Say
(
Command_
Room
Say
*
cmd
,
CommandContainer
*
cont
,
Server_
Room
*
room
);
ResponseCode
cmdListUsers
(
Command_ListUsers
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdListUsers
(
Command_ListUsers
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdListGames
(
Command_ListGames
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdCreateGame
(
Command_CreateGame
*
cmd
,
CommandContainer
*
cont
,
Server_Room
*
room
);
ResponseCode
cmdCreateGame
(
Command_CreateGame
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdJoinGame
(
Command_JoinGame
*
cmd
,
CommandContainer
*
cont
,
Server_Room
*
room
);
ResponseCode
cmdJoinGame
(
Command_JoinGame
*
cmd
,
CommandContainer
*
cont
);
ResponseCode
cmdLeaveGame
(
Command_LeaveGame
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
ResponseCode
cmdLeaveGame
(
Command_LeaveGame
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
ResponseCode
cmdConcede
(
Command_Concede
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
ResponseCode
cmdConcede
(
Command_Concede
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
ResponseCode
cmdReadyStart
(
Command_ReadyStart
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
ResponseCode
cmdReadyStart
(
Command_ReadyStart
*
cmd
,
CommandContainer
*
cont
,
Server_Game
*
game
,
Server_Player
*
player
);
...
@@ -91,9 +90,8 @@ public:
...
@@ -91,9 +90,8 @@ public:
~
Server_ProtocolHandler
();
~
Server_ProtocolHandler
();
void
playerRemovedFromGame
(
Server_Game
*
game
);
void
playerRemovedFromGame
(
Server_Game
*
game
);
bool
getAcceptsGameListChanges
()
const
{
return
acceptsGameListChanges
;
}
bool
getAcceptsUserListChanges
()
const
{
return
acceptsUserListChanges
;
}
bool
getAcceptsUserListChanges
()
const
{
return
acceptsUserListChanges
;
}
bool
getAccepts
ChatChannel
ListChanges
()
const
{
return
accepts
ChatChannel
ListChanges
;
}
bool
getAccepts
Room
ListChanges
()
const
{
return
accepts
Room
ListChanges
;
}
ServerInfo_User
*
getUserInfo
()
const
{
return
userInfo
;
}
ServerInfo_User
*
getUserInfo
()
const
{
return
userInfo
;
}
void
setUserInfo
(
ServerInfo_User
*
_userInfo
)
{
userInfo
=
_userInfo
;
}
void
setUserInfo
(
ServerInfo_User
*
_userInfo
)
{
userInfo
=
_userInfo
;
}
const
QDateTime
&
getLastCommandTime
()
const
{
return
lastCommandTime
;
}
const
QDateTime
&
getLastCommandTime
()
const
{
return
lastCommandTime
;
}
...
...
common/server_room.cpp
0 → 100644
View file @
d8d45632
#include
"server_room.h"
#include
"server_protocolhandler.h"
#include
"server_game.h"
Server_Room
::
Server_Room
(
int
_id
,
const
QString
&
_name
,
const
QString
&
_description
,
bool
_autoJoin
,
const
QString
&
_joinMessage
,
Server
*
parent
)
:
QObject
(
parent
),
id
(
_id
),
name
(
_name
),
description
(
_description
),
autoJoin
(
_autoJoin
),
joinMessage
(
_joinMessage
)
{
}
Server
*
Server_Room
::
getServer
()
const
{
return
static_cast
<
Server
*>
(
parent
());
}
QList
<
ServerInfo_User
*>
Server_Room
::
addClient
(
Server_ProtocolHandler
*
client
)
{
sendRoomEvent
(
new
Event_JoinRoom
(
id
,
new
ServerInfo_User
(
client
->
getUserInfo
())));
append
(
client
);
QList
<
ServerInfo_User
*>
eventUserList
;
for
(
int
i
=
0
;
i
<
size
();
++
i
)
eventUserList
.
append
(
new
ServerInfo_User
(
at
(
i
)
->
getUserInfo
()));
emit
roomInfoChanged
();
return
eventUserList
;
}
void
Server_Room
::
removeClient
(
Server_ProtocolHandler
*
client
)
{
removeAt
(
indexOf
(
client
));
sendRoomEvent
(
new
Event_LeaveRoom
(
id
,
client
->
getUserInfo
()
->
getName
()));
emit
roomInfoChanged
();
}
void
Server_Room
::
say
(
Server_ProtocolHandler
*
client
,
const
QString
&
s
)
{
sendRoomEvent
(
new
Event_RoomSay
(
id
,
client
->
getUserInfo
()
->
getName
(),
s
));
}
void
Server_Room
::
sendRoomEvent
(
RoomEvent
*
event
)
{
for
(
int
i
=
0
;
i
<
size
();
++
i
)
at
(
i
)
->
sendProtocolItem
(
event
,
false
);
delete
event
;
}
void
Server_Room
::
broadcastGameListUpdate
(
Server_Game
*
game
)
{
Event_ListGames
*
event
=
new
Event_ListGames
(
id
,
QList
<
ServerInfo_Game
*>
()
<<
game
->
getInfo
());
for
(
int
i
=
0
;
i
<
size
();
i
++
)
at
(
i
)
->
sendProtocolItem
(
event
,
false
);
delete
event
;
}
Server_Game
*
Server_Room
::
createGame
(
const
QString
&
description
,
const
QString
&
password
,
int
maxPlayers
,
bool
spectatorsAllowed
,
bool
spectatorsNeedPassword
,
bool
spectatorsCanTalk
,
bool
spectatorsSeeEverything
,
Server_ProtocolHandler
*
creator
)
{
Server_Game
*
newGame
=
new
Server_Game
(
creator
,
static_cast
<
Server
*>
(
parent
())
->
getNextGameId
(),
description
,
password
,
maxPlayers
,
spectatorsAllowed
,
spectatorsNeedPassword
,
spectatorsCanTalk
,
spectatorsSeeEverything
,
this
);
games
.
insert
(
newGame
->
getGameId
(),
newGame
);
connect
(
newGame
,
SIGNAL
(
gameClosing
()),
this
,
SLOT
(
removeGame
()));
broadcastGameListUpdate
(
newGame
);
emit
gameCreated
(
newGame
);
return
newGame
;
}
void
Server_Room
::
removeGame
()
{
Server_Game
*
game
=
static_cast
<
Server_Game
*>
(
sender
());
broadcastGameListUpdate
(
game
);
games
.
remove
(
game
->
getGameId
());
emit
gameClosing
(
game
->
getGameId
());
}
common/server_
chatchannel
.h
→
common/server_
room
.h
View file @
d8d45632
#ifndef
CHATCHANNEL
_H
#ifndef
SERVER_ROOM
_H
#define
CHATCHANNEL
_H
#define
SERVER_ROOM
_H
#include
<QList>
#include
<QList>
#include
<QMap>
#include
<QObject>
#include
<QObject>
#include
<QStringList>
#include
<QStringList>
class
Server_ProtocolHandler
;
class
Server_ProtocolHandler
;
class
ChatEvent
;
class
RoomEvent
;
class
ServerInfo_User
;
class
Server_Game
;
class
Server
;
class
Server_
ChatChannel
:
public
QObject
,
public
QList
<
Server_ProtocolHandler
*>
{
class
Server_
Room
:
public
QObject
,
public
QList
<
Server_ProtocolHandler
*>
{
Q_OBJECT
Q_OBJECT
signals:
signals:
void
channelInfoChanged
();
void
roomInfoChanged
();
void
gameCreated
(
Server_Game
*
game
);
void
gameClosing
(
int
gameId
);
private:
private:
int
id
;
QString
name
;
QString
name
;
QString
description
;
QString
description
;
bool
autoJoin
;
bool
autoJoin
;
QString
joinMessage
;
QString
joinMessage
;
QMap
<
int
,
Server_Game
*>
games
;
private
slots
:
void
removeGame
();
public:
public:
Server_ChatChannel
(
const
QString
&
_name
,
const
QString
&
_description
,
bool
_autoJoin
,
const
QString
&
_joinMessage
);
Server_Room
(
int
_id
,
const
QString
&
_name
,
const
QString
&
_description
,
bool
_autoJoin
,
const
QString
&
_joinMessage
,
Server
*
parent
);
int
getId
()
const
{
return
id
;
}
QString
getName
()
const
{
return
name
;
}
QString
getName
()
const
{
return
name
;
}
QString
getDescription
()
const
{
return
description
;
}
QString
getDescription
()
const
{
return
description
;
}
bool
getAutoJoin
()
const
{
return
autoJoin
;
}
bool
getAutoJoin
()
const
{
return
autoJoin
;
}
void
addClient
(
Server_ProtocolHandler
*
client
);
const
QMap
<
int
,
Server_Game
*>
&
getGames
()
const
{
return
games
;
}
Server
*
getServer
()
const
;
QList
<
ServerInfo_User
*>
addClient
(
Server_ProtocolHandler
*
client
);
void
removeClient
(
Server_ProtocolHandler
*
client
);
void
removeClient
(
Server_ProtocolHandler
*
client
);
void
say
(
Server_ProtocolHandler
*
client
,
const
QString
&
s
);
void
say
(
Server_ProtocolHandler
*
client
,
const
QString
&
s
);
void
broadcastGameListUpdate
(
Server_Game
*
game
);
Server_Game
*
createGame
(
const
QString
&
description
,
const
QString
&
password
,
int
maxPlayers
,
bool
spectatorsAllowed
,
bool
spectatorsNeedPassword
,
bool
spectatorsCanTalk
,
bool
spectatorsSeeEverything
,
Server_ProtocolHandler
*
creator
);
void
send
Chat
Event
(
Chat
Event
*
event
);
void
send
Room
Event
(
Room
Event
*
event
);
};
};
#endif
#endif
servatrice/servatrice.pro
View file @
d8d45632
...
@@ -27,7 +27,7 @@ HEADERS += src/servatrice.h \
...
@@ -27,7 +27,7 @@ HEADERS += src/servatrice.h \
..
/
common
/
server_arrow
.
h
\
..
/
common
/
server_arrow
.
h
\
..
/
common
/
server_card
.
h
\
..
/
common
/
server_card
.
h
\
..
/
common
/
server_cardzone
.
h
\
..
/
common
/
server_cardzone
.
h
\
..
/
common
/
server_
chatchannel
.
h
\
..
/
common
/
server_
room
.
h
\
..
/
common
/
server_counter
.
h
\
..
/
common
/
server_counter
.
h
\
..
/
common
/
server_game
.
h
\
..
/
common
/
server_game
.
h
\
..
/
common
/
server_player
.
h
\
..
/
common
/
server_player
.
h
\
...
@@ -48,7 +48,7 @@ SOURCES += src/main.cpp \
...
@@ -48,7 +48,7 @@ SOURCES += src/main.cpp \
..
/
common
/
server
.
cpp
\
..
/
common
/
server
.
cpp
\
..
/
common
/
server_card
.
cpp
\
..
/
common
/
server_card
.
cpp
\
..
/
common
/
server_cardzone
.
cpp
\
..
/
common
/
server_cardzone
.
cpp
\
..
/
common
/
server_
chatchannel
.
cpp
\
..
/
common
/
server_
room
.
cpp
\
..
/
common
/
server_game
.
cpp
\
..
/
common
/
server_game
.
cpp
\
..
/
common
/
server_player
.
cpp
\
..
/
common
/
server_player
.
cpp
\
..
/
common
/
server_protocolhandler
.
cpp
..
/
common
/
server_protocolhandler
.
cpp
Prev
1
2
Next
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