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
29bf3d37
Commit
29bf3d37
authored
Nov 02, 2009
by
Max-Wilhelm Bruker
Browse files
some server code
parent
6923c98d
Changes
18
Expand all
Hide whitespace changes
Inline
Side-by-side
common/protocol.cpp
View file @
29bf3d37
...
...
@@ -22,7 +22,6 @@ bool ProtocolItem::read(QXmlStreamReader *xml)
if
(
xml
->
name
()
==
getItemType
())
{
extractParameters
();
qDebug
()
<<
"FERTIG"
;
deleteLater
();
return
true
;
}
else
{
QString
tagName
=
xml
->
name
().
toString
();
...
...
@@ -111,6 +110,7 @@ void ProtocolResponse::extractParameters()
void
ProtocolResponse
::
initializeHash
()
{
responseHash
.
insert
(
"ok"
,
RespOk
);
responseHash
.
insert
(
"invalid_command"
,
RespInvalidCommand
);
responseHash
.
insert
(
"name_not_found"
,
RespNameNotFound
);
responseHash
.
insert
(
"login_needed"
,
RespLoginNeeded
);
responseHash
.
insert
(
"context_error"
,
RespContextError
);
...
...
common/protocol.h
View file @
29bf3d37
...
...
@@ -6,6 +6,7 @@
#include
<QHash>
#include
<QObject>
#include
<QDebug>
#include
"protocol_item_ids.h"
class
QXmlStreamReader
;
class
QXmlStreamWriter
;
...
...
@@ -29,6 +30,7 @@ private:
static
void
initializeHashAuto
();
public:
static
const
int
protocolVersion
=
4
;
virtual
int
getItemId
()
const
=
0
;
ProtocolItem
(
const
QString
&
_itemName
);
static
void
initializeHash
();
static
ProtocolItem
*
getNewItem
(
const
QString
&
name
);
...
...
@@ -45,7 +47,15 @@ protected:
QString
getItemType
()
const
{
return
"cmd"
;
}
void
extractParameters
();
public:
Command
(
const
QString
&
_itemName
,
int
_cmdId
=
-
1
);
Command
(
const
QString
&
_itemName
=
QString
(),
int
_cmdId
=
-
1
);
int
getCmdId
()
const
{
return
cmdId
;
}
};
class
InvalidCommand
:
public
Command
{
Q_OBJECT
public:
InvalidCommand
()
:
Command
()
{
}
int
getItemId
()
const
{
return
ItemId_Other
;
}
};
class
ChatCommand
:
public
Command
{
...
...
@@ -87,7 +97,7 @@ public:
class
ProtocolResponse
:
public
ProtocolItem
{
Q_OBJECT
public:
enum
ResponseCode
{
Resp
Ok
,
RespNameNotFound
,
RespLoginNeeded
,
RespContextError
,
RespWrongPassword
,
RespSpectatorsNotAllowed
};
enum
ResponseCode
{
Resp
Nothing
,
RespOk
,
RespInvalidCommand
,
RespNameNotFound
,
RespLoginNeeded
,
RespContextError
,
RespWrongPassword
,
RespSpectatorsNotAllowed
};
private:
int
cmdId
;
ResponseCode
responseCode
;
...
...
@@ -97,6 +107,7 @@ protected:
void
extractParameters
();
public:
ProtocolResponse
(
int
_cmdId
=
-
1
,
ResponseCode
_responseCode
=
RespOk
);
int
getItemId
()
const
{
return
ItemId_Other
;
}
static
void
initializeHash
();
static
ProtocolItem
*
newItem
()
{
return
new
ProtocolResponse
;
}
};
...
...
common/protocol_item_ids.h
0 → 100644
View file @
29bf3d37
enum
AutoItemId
{
ItemId_Command_Ping
=
1001
,
ItemId_Command_Login
=
1002
,
ItemId_Command_ChatListChannels
=
1003
,
ItemId_Command_ChatJoinChannel
=
1004
,
ItemId_Command_ChatLeaveChannel
=
1005
,
ItemId_Command_ChatSay
=
1006
,
ItemId_Command_ListGames
=
1007
,
ItemId_Command_CreateGame
=
1008
,
ItemId_Command_JoinGame
=
1009
,
ItemId_Command_LeaveGame
=
1010
,
ItemId_Command_Say
=
1011
,
ItemId_Command_Shuffle
=
1012
,
ItemId_Command_RollDie
=
1013
,
ItemId_Command_DrawCards
=
1014
,
ItemId_Command_MoveCard
=
1015
,
ItemId_Command_CreateToken
=
1016
,
ItemId_Command_CreateArrow
=
1017
,
ItemId_Command_DeleteArrow
=
1018
,
ItemId_Command_SetCardAttr
=
1019
,
ItemId_Command_ReadyStart
=
1020
,
ItemId_Command_IncCounter
=
1021
,
ItemId_Command_AddCounter
=
1022
,
ItemId_Command_SetCounter
=
1023
,
ItemId_Command_DelCounter
=
1024
,
ItemId_Command_NextTurn
=
1025
,
ItemId_Command_SetActivePhase
=
1026
,
ItemId_Command_DumpZone
=
1027
,
ItemId_Command_StopDumpZone
=
1028
,
ItemId_Command_DumpAll
=
1029
,
ItemId_Command_SubmitDeck
=
1030
,
ItemId_Event_Say
=
1031
,
ItemId_Event_Join
=
1032
,
ItemId_Event_Leave
=
1033
,
ItemId_Event_GameClosed
=
1034
,
ItemId_Event_ReadyStart
=
1035
,
ItemId_Event_SetupZones
=
1036
,
ItemId_Event_GameStart
=
1037
,
ItemId_Event_Shuffle
=
1038
,
ItemId_Event_RollDie
=
1039
,
ItemId_Event_MoveCard
=
1040
,
ItemId_Event_CreateToken
=
1041
,
ItemId_Event_CreateArrow
=
1042
,
ItemId_Event_DeleteArrow
=
1043
,
ItemId_Event_SetCardAttr
=
1044
,
ItemId_Event_AddCounter
=
1045
,
ItemId_Event_SetCounter
=
1046
,
ItemId_Event_DelCounter
=
1047
,
ItemId_Event_SetActivePlayer
=
1048
,
ItemId_Event_SetActivePhase
=
1049
,
ItemId_Event_DumpZone
=
1050
,
ItemId_Event_StopDumpZone
=
1051
,
ItemId_Event_Welcome
=
1052
,
ItemId_Other
=
1053
};
common/protocol_items.cpp
View file @
29bf3d37
...
...
@@ -137,11 +137,11 @@ void Command_MoveCard::extractParameters()
y
=
parameters
[
"y"
].
toInt
();
faceDown
=
(
parameters
[
"face_down"
]
==
"1"
);
}
Command_CreateToken
::
Command_CreateToken
(
int
_gameId
,
const
QString
&
_zone
,
const
QString
&
_
n
ame
,
const
QString
&
_pt
,
int
_x
,
int
_y
)
:
GameCommand
(
"create_token"
,
_gameId
),
zone
(
_zone
),
name
(
_n
ame
),
pt
(
_pt
),
x
(
_x
),
y
(
_y
)
Command_CreateToken
::
Command_CreateToken
(
int
_gameId
,
const
QString
&
_zone
,
const
QString
&
_
cardN
ame
,
const
QString
&
_pt
,
int
_x
,
int
_y
)
:
GameCommand
(
"create_token"
,
_gameId
),
zone
(
_zone
),
cardName
(
_cardN
ame
),
pt
(
_pt
),
x
(
_x
),
y
(
_y
)
{
setParameter
(
"zone"
,
zone
);
setParameter
(
"name"
,
n
ame
);
setParameter
(
"
card_
name"
,
cardN
ame
);
setParameter
(
"pt"
,
pt
);
setParameter
(
"x"
,
x
);
setParameter
(
"y"
,
y
);
...
...
@@ -150,19 +150,19 @@ void Command_CreateToken::extractParameters()
{
GameCommand
::
extractParameters
();
zone
=
parameters
[
"zone"
];
n
ame
=
parameters
[
"name"
];
cardN
ame
=
parameters
[
"
card_
name"
];
pt
=
parameters
[
"pt"
];
x
=
parameters
[
"x"
].
toInt
();
y
=
parameters
[
"y"
].
toInt
();
}
Command_CreateArrow
::
Command_CreateArrow
(
int
_gameId
,
int
_startPlayerId
,
const
QString
&
_startZone
,
int
_startCardId
,
int
_targetPlayerId
,
const
QString
&
_target
Player
Zone
,
int
_targetCardId
,
int
_color
)
:
GameCommand
(
"create_arrow"
,
_gameId
),
startPlayerId
(
_startPlayerId
),
startZone
(
_startZone
),
startCardId
(
_startCardId
),
targetPlayerId
(
_targetPlayerId
),
target
Player
Zone
(
_target
Player
Zone
),
targetCardId
(
_targetCardId
),
color
(
_color
)
Command_CreateArrow
::
Command_CreateArrow
(
int
_gameId
,
int
_startPlayerId
,
const
QString
&
_startZone
,
int
_startCardId
,
int
_targetPlayerId
,
const
QString
&
_targetZone
,
int
_targetCardId
,
int
_color
)
:
GameCommand
(
"create_arrow"
,
_gameId
),
startPlayerId
(
_startPlayerId
),
startZone
(
_startZone
),
startCardId
(
_startCardId
),
targetPlayerId
(
_targetPlayerId
),
targetZone
(
_targetZone
),
targetCardId
(
_targetCardId
),
color
(
_color
)
{
setParameter
(
"start_player_id"
,
startPlayerId
);
setParameter
(
"start_zone"
,
startZone
);
setParameter
(
"start_card_id"
,
startCardId
);
setParameter
(
"target_player_id"
,
targetPlayerId
);
setParameter
(
"target_
player_
zone"
,
target
Player
Zone
);
setParameter
(
"target_zone"
,
targetZone
);
setParameter
(
"target_card_id"
,
targetCardId
);
setParameter
(
"color"
,
color
);
}
...
...
@@ -173,7 +173,7 @@ void Command_CreateArrow::extractParameters()
startZone
=
parameters
[
"start_zone"
];
startCardId
=
parameters
[
"start_card_id"
].
toInt
();
targetPlayerId
=
parameters
[
"target_player_id"
].
toInt
();
target
Player
Zone
=
parameters
[
"target_
player_
zone"
];
targetZone
=
parameters
[
"target_zone"
];
targetCardId
=
parameters
[
"target_card_id"
].
toInt
();
color
=
parameters
[
"color"
].
toInt
();
}
...
...
common/protocol_items.dat
View file @
29bf3d37
...
...
@@ -13,8 +13,8 @@
2:roll_die:i,sides
2:draw_cards:i,number
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down
2:create_token:s,zone:s,name:s,pt:i,x:i,y
2:create_arrow:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_
player_
zone:i,target_card_id:i,color
2:create_token:s,zone:s,
card_
name:s,pt:i,x:i,y
2:create_arrow:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_zone:i,target_card_id:i,color
2:delete_arrow:i,arrow_id
2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
2:ready_start
...
...
common/protocol_items.h
View file @
29bf3d37
...
...
@@ -9,6 +9,7 @@ private:
public:
Command_Ping
();
static
ProtocolItem
*
newItem
()
{
return
new
Command_Ping
;
}
int
getItemId
()
const
{
return
ItemId_Command_Ping
;
}
};
class
Command_Login
:
public
Command
{
Q_OBJECT
...
...
@@ -20,6 +21,7 @@ public:
QString
getUsername
()
const
{
return
username
;
}
QString
getPassword
()
const
{
return
password
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_Login
;
}
int
getItemId
()
const
{
return
ItemId_Command_Login
;
}
protected:
void
extractParameters
();
};
...
...
@@ -29,6 +31,7 @@ private:
public:
Command_ChatListChannels
();
static
ProtocolItem
*
newItem
()
{
return
new
Command_ChatListChannels
;
}
int
getItemId
()
const
{
return
ItemId_Command_ChatListChannels
;
}
};
class
Command_ChatJoinChannel
:
public
Command
{
Q_OBJECT
...
...
@@ -38,6 +41,7 @@ public:
Command_ChatJoinChannel
(
const
QString
&
_channel
=
QString
());
QString
getChannel
()
const
{
return
channel
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_ChatJoinChannel
;
}
int
getItemId
()
const
{
return
ItemId_Command_ChatJoinChannel
;
}
protected:
void
extractParameters
();
};
...
...
@@ -47,6 +51,7 @@ private:
public:
Command_ChatLeaveChannel
(
const
QString
&
_channel
=
QString
());
static
ProtocolItem
*
newItem
()
{
return
new
Command_ChatLeaveChannel
;
}
int
getItemId
()
const
{
return
ItemId_Command_ChatLeaveChannel
;
}
};
class
Command_ChatSay
:
public
ChatCommand
{
Q_OBJECT
...
...
@@ -56,6 +61,7 @@ public:
Command_ChatSay
(
const
QString
&
_channel
=
QString
(),
const
QString
&
_message
=
QString
());
QString
getMessage
()
const
{
return
message
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_ChatSay
;
}
int
getItemId
()
const
{
return
ItemId_Command_ChatSay
;
}
protected:
void
extractParameters
();
};
...
...
@@ -65,6 +71,7 @@ private:
public:
Command_ListGames
();
static
ProtocolItem
*
newItem
()
{
return
new
Command_ListGames
;
}
int
getItemId
()
const
{
return
ItemId_Command_ListGames
;
}
};
class
Command_CreateGame
:
public
Command
{
Q_OBJECT
...
...
@@ -80,6 +87,7 @@ public:
int
getMaxPlayers
()
const
{
return
maxPlayers
;
}
bool
getSpectatorsAllowed
()
const
{
return
spectatorsAllowed
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_CreateGame
;
}
int
getItemId
()
const
{
return
ItemId_Command_CreateGame
;
}
protected:
void
extractParameters
();
};
...
...
@@ -95,6 +103,7 @@ public:
QString
getPassword
()
const
{
return
password
;
}
bool
getSpectator
()
const
{
return
spectator
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_JoinGame
;
}
int
getItemId
()
const
{
return
ItemId_Command_JoinGame
;
}
protected:
void
extractParameters
();
};
...
...
@@ -104,6 +113,7 @@ private:
public:
Command_LeaveGame
(
int
_gameId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Command_LeaveGame
;
}
int
getItemId
()
const
{
return
ItemId_Command_LeaveGame
;
}
};
class
Command_Say
:
public
GameCommand
{
Q_OBJECT
...
...
@@ -113,6 +123,7 @@ public:
Command_Say
(
int
_gameId
=
-
1
,
const
QString
&
_message
=
QString
());
QString
getMessage
()
const
{
return
message
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_Say
;
}
int
getItemId
()
const
{
return
ItemId_Command_Say
;
}
protected:
void
extractParameters
();
};
...
...
@@ -122,6 +133,7 @@ private:
public:
Command_Shuffle
(
int
_gameId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Command_Shuffle
;
}
int
getItemId
()
const
{
return
ItemId_Command_Shuffle
;
}
};
class
Command_RollDie
:
public
GameCommand
{
Q_OBJECT
...
...
@@ -131,6 +143,7 @@ public:
Command_RollDie
(
int
_gameId
=
-
1
,
int
_sides
=
-
1
);
int
getSides
()
const
{
return
sides
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_RollDie
;
}
int
getItemId
()
const
{
return
ItemId_Command_RollDie
;
}
protected:
void
extractParameters
();
};
...
...
@@ -142,6 +155,7 @@ public:
Command_DrawCards
(
int
_gameId
=
-
1
,
int
_number
=
-
1
);
int
getNumber
()
const
{
return
number
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DrawCards
;
}
int
getItemId
()
const
{
return
ItemId_Command_DrawCards
;
}
protected:
void
extractParameters
();
};
...
...
@@ -163,6 +177,7 @@ public:
int
getY
()
const
{
return
y
;
}
bool
getFaceDown
()
const
{
return
faceDown
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_MoveCard
;
}
int
getItemId
()
const
{
return
ItemId_Command_MoveCard
;
}
protected:
void
extractParameters
();
};
...
...
@@ -170,18 +185,19 @@ class Command_CreateToken : public GameCommand {
Q_OBJECT
private:
QString
zone
;
QString
n
ame
;
QString
cardN
ame
;
QString
pt
;
int
x
;
int
y
;
public:
Command_CreateToken
(
int
_gameId
=
-
1
,
const
QString
&
_zone
=
QString
(),
const
QString
&
_
n
ame
=
QString
(),
const
QString
&
_pt
=
QString
(),
int
_x
=
-
1
,
int
_y
=
-
1
);
Command_CreateToken
(
int
_gameId
=
-
1
,
const
QString
&
_zone
=
QString
(),
const
QString
&
_
cardN
ame
=
QString
(),
const
QString
&
_pt
=
QString
(),
int
_x
=
-
1
,
int
_y
=
-
1
);
QString
getZone
()
const
{
return
zone
;
}
QString
getName
()
const
{
return
n
ame
;
}
QString
get
Card
Name
()
const
{
return
cardN
ame
;
}
QString
getPt
()
const
{
return
pt
;
}
int
getX
()
const
{
return
x
;
}
int
getY
()
const
{
return
y
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_CreateToken
;
}
int
getItemId
()
const
{
return
ItemId_Command_CreateToken
;
}
protected:
void
extractParameters
();
};
...
...
@@ -192,19 +208,20 @@ private:
QString
startZone
;
int
startCardId
;
int
targetPlayerId
;
QString
target
Player
Zone
;
QString
targetZone
;
int
targetCardId
;
int
color
;
public:
Command_CreateArrow
(
int
_gameId
=
-
1
,
int
_startPlayerId
=
-
1
,
const
QString
&
_startZone
=
QString
(),
int
_startCardId
=
-
1
,
int
_targetPlayerId
=
-
1
,
const
QString
&
_target
Player
Zone
=
QString
(),
int
_targetCardId
=
-
1
,
int
_color
=
-
1
);
Command_CreateArrow
(
int
_gameId
=
-
1
,
int
_startPlayerId
=
-
1
,
const
QString
&
_startZone
=
QString
(),
int
_startCardId
=
-
1
,
int
_targetPlayerId
=
-
1
,
const
QString
&
_targetZone
=
QString
(),
int
_targetCardId
=
-
1
,
int
_color
=
-
1
);
int
getStartPlayerId
()
const
{
return
startPlayerId
;
}
QString
getStartZone
()
const
{
return
startZone
;
}
int
getStartCardId
()
const
{
return
startCardId
;
}
int
getTargetPlayerId
()
const
{
return
targetPlayerId
;
}
QString
getTarget
Player
Zone
()
const
{
return
target
Player
Zone
;
}
QString
getTargetZone
()
const
{
return
targetZone
;
}
int
getTargetCardId
()
const
{
return
targetCardId
;
}
int
getColor
()
const
{
return
color
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_CreateArrow
;
}
int
getItemId
()
const
{
return
ItemId_Command_CreateArrow
;
}
protected:
void
extractParameters
();
};
...
...
@@ -216,6 +233,7 @@ public:
Command_DeleteArrow
(
int
_gameId
=
-
1
,
int
_arrowId
=
-
1
);
int
getArrowId
()
const
{
return
arrowId
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DeleteArrow
;
}
int
getItemId
()
const
{
return
ItemId_Command_DeleteArrow
;
}
protected:
void
extractParameters
();
};
...
...
@@ -233,6 +251,7 @@ public:
QString
getAttrName
()
const
{
return
attrName
;
}
QString
getAttrValue
()
const
{
return
attrValue
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_SetCardAttr
;
}
int
getItemId
()
const
{
return
ItemId_Command_SetCardAttr
;
}
protected:
void
extractParameters
();
};
...
...
@@ -242,6 +261,7 @@ private:
public:
Command_ReadyStart
(
int
_gameId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Command_ReadyStart
;
}
int
getItemId
()
const
{
return
ItemId_Command_ReadyStart
;
}
};
class
Command_IncCounter
:
public
GameCommand
{
Q_OBJECT
...
...
@@ -253,6 +273,7 @@ public:
int
getCounterId
()
const
{
return
counterId
;
}
int
getDelta
()
const
{
return
delta
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_IncCounter
;
}
int
getItemId
()
const
{
return
ItemId_Command_IncCounter
;
}
protected:
void
extractParameters
();
};
...
...
@@ -270,6 +291,7 @@ public:
int
getRadius
()
const
{
return
radius
;
}
int
getValue
()
const
{
return
value
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_AddCounter
;
}
int
getItemId
()
const
{
return
ItemId_Command_AddCounter
;
}
protected:
void
extractParameters
();
};
...
...
@@ -283,6 +305,7 @@ public:
int
getCounterId
()
const
{
return
counterId
;
}
int
getValue
()
const
{
return
value
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_SetCounter
;
}
int
getItemId
()
const
{
return
ItemId_Command_SetCounter
;
}
protected:
void
extractParameters
();
};
...
...
@@ -294,6 +317,7 @@ public:
Command_DelCounter
(
int
_gameId
=
-
1
,
int
_counterId
=
-
1
);
int
getCounterId
()
const
{
return
counterId
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DelCounter
;
}
int
getItemId
()
const
{
return
ItemId_Command_DelCounter
;
}
protected:
void
extractParameters
();
};
...
...
@@ -303,6 +327,7 @@ private:
public:
Command_NextTurn
(
int
_gameId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Command_NextTurn
;
}
int
getItemId
()
const
{
return
ItemId_Command_NextTurn
;
}
};
class
Command_SetActivePhase
:
public
GameCommand
{
Q_OBJECT
...
...
@@ -312,6 +337,7 @@ public:
Command_SetActivePhase
(
int
_gameId
=
-
1
,
int
_phase
=
-
1
);
int
getPhase
()
const
{
return
phase
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_SetActivePhase
;
}
int
getItemId
()
const
{
return
ItemId_Command_SetActivePhase
;
}
protected:
void
extractParameters
();
};
...
...
@@ -327,6 +353,7 @@ public:
QString
getZoneName
()
const
{
return
zoneName
;
}
int
getNumberCards
()
const
{
return
numberCards
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_DumpZone
;
}
int
getItemId
()
const
{
return
ItemId_Command_DumpZone
;
}
protected:
void
extractParameters
();
};
...
...
@@ -340,6 +367,7 @@ public:
int
getPlayerId
()
const
{
return
playerId
;
}
QString
getZoneName
()
const
{
return
zoneName
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Command_StopDumpZone
;
}
int
getItemId
()
const
{
return
ItemId_Command_StopDumpZone
;
}
protected:
void
extractParameters
();
};
...
...
@@ -349,6 +377,7 @@ private:
public:
Command_DumpAll
(
int
_gameId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Command_DumpAll
;
}
int
getItemId
()
const
{
return
ItemId_Command_DumpAll
;
}
};
class
Command_SubmitDeck
:
public
GameCommand
{
Q_OBJECT
...
...
@@ -356,6 +385,7 @@ private:
public:
Command_SubmitDeck
(
int
_gameId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Command_SubmitDeck
;
}
int
getItemId
()
const
{
return
ItemId_Command_SubmitDeck
;
}
};
class
Event_Say
:
public
GameEvent
{
Q_OBJECT
...
...
@@ -365,6 +395,7 @@ public:
Event_Say
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
,
const
QString
&
_message
=
QString
());
QString
getMessage
()
const
{
return
message
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_Say
;
}
int
getItemId
()
const
{
return
ItemId_Event_Say
;
}
protected:
void
extractParameters
();
};
...
...
@@ -378,6 +409,7 @@ public:
QString
getPlayerName
()
const
{
return
playerName
;
}
bool
getSpectator
()
const
{
return
spectator
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_Join
;
}
int
getItemId
()
const
{
return
ItemId_Event_Join
;
}
protected:
void
extractParameters
();
};
...
...
@@ -387,6 +419,7 @@ private:
public:
Event_Leave
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Event_Leave
;
}
int
getItemId
()
const
{
return
ItemId_Event_Leave
;
}
};
class
Event_GameClosed
:
public
GameEvent
{
Q_OBJECT
...
...
@@ -394,6 +427,7 @@ private:
public:
Event_GameClosed
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Event_GameClosed
;
}
int
getItemId
()
const
{
return
ItemId_Event_GameClosed
;
}
};
class
Event_ReadyStart
:
public
GameEvent
{
Q_OBJECT
...
...
@@ -401,6 +435,7 @@ private:
public:
Event_ReadyStart
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Event_ReadyStart
;
}
int
getItemId
()
const
{
return
ItemId_Event_ReadyStart
;
}
};
class
Event_SetupZones
:
public
GameEvent
{
Q_OBJECT
...
...
@@ -412,6 +447,7 @@ public:
int
getDeckSize
()
const
{
return
deckSize
;
}
int
getSbSize
()
const
{
return
sbSize
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_SetupZones
;
}
int
getItemId
()
const
{
return
ItemId_Event_SetupZones
;
}
protected:
void
extractParameters
();
};
...
...
@@ -421,6 +457,7 @@ private:
public:
Event_GameStart
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Event_GameStart
;
}
int
getItemId
()
const
{
return
ItemId_Event_GameStart
;
}
};
class
Event_Shuffle
:
public
GameEvent
{
Q_OBJECT
...
...
@@ -428,6 +465,7 @@ private:
public:
Event_Shuffle
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
);
static
ProtocolItem
*
newItem
()
{
return
new
Event_Shuffle
;
}
int
getItemId
()
const
{
return
ItemId_Event_Shuffle
;
}
};
class
Event_RollDie
:
public
GameEvent
{
Q_OBJECT
...
...
@@ -439,6 +477,7 @@ public:
int
getSides
()
const
{
return
sides
;
}
int
getValue
()
const
{
return
value
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_RollDie
;
}
int
getItemId
()
const
{
return
ItemId_Event_RollDie
;
}
protected:
void
extractParameters
();
};
...
...
@@ -464,6 +503,7 @@ public:
int
getY
()
const
{
return
y
;
}
bool
getFaceDown
()
const
{
return
faceDown
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_MoveCard
;
}
int
getItemId
()
const
{
return
ItemId_Event_MoveCard
;
}
protected:
void
extractParameters
();
};
...
...
@@ -485,6 +525,7 @@ public:
int
getX
()
const
{
return
x
;
}
int
getY
()
const
{
return
y
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_CreateToken
;
}
int
getItemId
()
const
{
return
ItemId_Event_CreateToken
;
}
protected:
void
extractParameters
();
};
...
...
@@ -510,6 +551,7 @@ public:
int
getTargetCardId
()
const
{
return
targetCardId
;
}
int
getColor
()
const
{
return
color
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_CreateArrow
;
}
int
getItemId
()
const
{
return
ItemId_Event_CreateArrow
;
}
protected:
void
extractParameters
();
};
...
...
@@ -521,6 +563,7 @@ public:
Event_DeleteArrow
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
,
int
_arrowId
=
-
1
);
int
getArrowId
()
const
{
return
arrowId
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_DeleteArrow
;
}
int
getItemId
()
const
{
return
ItemId_Event_DeleteArrow
;
}
protected:
void
extractParameters
();
};
...
...
@@ -538,6 +581,7 @@ public:
QString
getAttrName
()
const
{
return
attrName
;
}
QString
getAttrValue
()
const
{
return
attrValue
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_SetCardAttr
;
}
int
getItemId
()
const
{
return
ItemId_Event_SetCardAttr
;
}
protected:
void
extractParameters
();
};
...
...
@@ -557,6 +601,7 @@ public:
int
getRadius
()
const
{
return
radius
;
}
int
getValue
()
const
{
return
value
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_AddCounter
;
}
int
getItemId
()
const
{
return
ItemId_Event_AddCounter
;
}
protected:
void
extractParameters
();
};
...
...
@@ -570,6 +615,7 @@ public:
int
getCounterId
()
const
{
return
counterId
;
}
int
getValue
()
const
{
return
value
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_SetCounter
;
}
int
getItemId
()
const
{
return
ItemId_Event_SetCounter
;
}
protected:
void
extractParameters
();
};
...
...
@@ -581,6 +627,7 @@ public:
Event_DelCounter
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
,
int
_counterId
=
-
1
);
int
getCounterId
()
const
{
return
counterId
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_DelCounter
;
}
int
getItemId
()
const
{
return
ItemId_Event_DelCounter
;
}
protected:
void
extractParameters
();
};
...
...
@@ -592,6 +639,7 @@ public:
Event_SetActivePlayer
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
,
int
_activePlayerId
=
-
1
);
int
getActivePlayerId
()
const
{
return
activePlayerId
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_SetActivePlayer
;
}
int
getItemId
()
const
{
return
ItemId_Event_SetActivePlayer
;
}
protected:
void
extractParameters
();
};
...
...
@@ -603,6 +651,7 @@ public:
Event_SetActivePhase
(
int
_gameId
=
-
1
,
int
_playerId
=
-
1
,
int
_phase
=
-
1
);
int
getPhase
()
const
{
return
phase
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_SetActivePhase
;
}
int
getItemId
()
const
{
return
ItemId_Event_SetActivePhase
;
}
protected:
void
extractParameters
();
};
...
...
@@ -618,6 +667,7 @@ public:
QString
getZone
()
const
{
return
zone
;
}
int
getNumberCards
()
const
{
return
numberCards
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_DumpZone
;
}
int
getItemId
()
const
{
return
ItemId_Event_DumpZone
;
}
protected:
void
extractParameters
();
};
...
...
@@ -631,6 +681,7 @@ public:
int
getZoneOwnerId
()
const
{
return
zoneOwnerId
;
}
QString
getZone
()
const
{
return
zone
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_StopDumpZone
;
}
int
getItemId
()
const
{
return
ItemId_Event_StopDumpZone
;
}
protected:
void
extractParameters
();
};
...
...
@@ -642,6 +693,7 @@ public:
Event_Welcome
(
const
QString
&
_message
=
QString
());
QString
getMessage
()
const
{
return
message
;
}
static
ProtocolItem
*
newItem
()
{
return
new
Event_Welcome
;
}
int
getItemId
()
const
{
return
ItemId_Event_Welcome
;
}
protected:
void
extractParameters
();
};
...
...
common/protocol_mc.pl
View file @
29bf3d37
#!/usr/bin/perl
$initializeHash
=
'';
$itemId
=
1000
;
$headerfileBuffer
=
'';
open
(
idfile
,
"
>protocol_item_ids.h
");
open
(
headerfile
,
"
>protocol_items.h
");
print
headerfile
"
#ifndef PROTOCOL_ITEMS_H
\n
"
...
...
@@ -56,7 +61,8 @@ while (<file>) {
$constructorParamsCpp
=
"";
}
$className
=
$namePrefix
.
'
_
'
.
$name2
;
print
headerfile
"
class
$className
: public
$baseClass
{
\n
"
$itemEnum
.=
"
ItemId_
$className
=
"
.
++
$itemId
.
"
,
\n
";
$headerfileBuffer
.=
"
class
$className
: public
$baseClass
{
\n
"
.
"
\t
Q_OBJECT
\n
"
.
"
private:
\n
";
$paramStr2
=
'';
...
...
@@ -92,12 +98,13 @@ while (<file>) {
}
(
$prettyVarName2
=
$prettyVarName
)
=~
s/^(.)/\U$1\E/
;
$paramStr4
.=
"
\t
$dataType
get
$prettyVarName2
() const { return
$prettyVarName
; }
\n
";
print
headerfile
"
\t
$dataType
$prettyVarName
;
\n
";
$
headerfile
Buffer
.=
"
\t
$dataType
$prettyVarName
;
\n
";
}
print
headerfile
"
public:
\n
"
$
headerfile
Buffer
.=
"
public:
\n
"
.
"
\t
$className
(
$constructorParamsH
);
\n
"
.
$paramStr4
.
"
\t
static ProtocolItem *newItem() { return new
$className
; }
\n
"
.
"
\t
int getItemId() const { return ItemId_
$className
; }
\n
"
.
(
$paramStr5
eq
''
?
''
:
"
protected:
\n\t
void extractParameters();
\n
")
.
"
};
\n
";
print
cppfile
$className
.
"
::
$className
(
$constructorParamsCpp
)
\n
"
...
...
@@ -116,7 +123,14 @@ while (<file>) {
}
close
(
file
);
print
headerfile
"
\n
#endif
\n
";
print
idfile
"
enum AutoItemId {
\n
"
.
$itemEnum
.
"
ItemId_Other =
"
.
++
$itemId
.
"
\n
"
.
"
};
\n
";
close
(
idfile
);
print
headerfile
$headerfileBuffer
.
"
\n
#endif
\n
";
close
(
headerfile
);
print
cppfile
"
void ProtocolItem::initializeHashAuto()
\n
"
...
...
common/server_game.cpp
View file @
29bf3d37
...
...
@@ -101,17 +101,17 @@ void Server_Game::startGameIfReady()
setActivePlayer
(
0
);
}
ReturnMessage
::
Return
Code
Server_Game
::
checkJoin
(
const
QString
&
_password
,
bool
spectator
)
ProtocolResponse
::
Response
Code
Server_Game
::
checkJoin
(
const
QString
&
_password
,
bool
spectator
)
{
if
(
_password
!=
password
)
return
ReturnMessage
::
Return
Password
Wrong
;
return
ProtocolResponse
::
RespWrong
Password
;
if
(
spectator
)
{
if
(
!
spectatorsAllowed
)
return
ReturnMessag
e
::
Re
turn
SpectatorsNotAllowed
;
return
ProtocolRespons
e
::
Re
sp
SpectatorsNotAllowed
;
}
else
if
(
gameStarted
||
(
getPlayerCount
()
>=
getMaxPlayers
()))
return
ReturnMessag
e
::
Re
turn
ContextError
;
return
ProtocolRespons
e
::
Re
sp
ContextError
;
return
ReturnMessag
e
::
Re
turn
Ok
;
return
ProtocolRespons
e
::
Re
sp
Ok
;
}
Server_Player
*
Server_Game
::
addPlayer
(
const
QString
&
playerName
,
bool
spectator
)
...
...
common/server_game.h
View file @
29bf3d37
...
...
@@ -24,7 +24,7 @@
#include
<QPointer>
#include
<QObject>
#include
"server_player.h"
#include
"
returnmessage
.h"
#include
"
protocol
.h"
class
Server_Game
:
public
QObject
{
Q_OBJECT
...
...
@@ -55,7 +55,7 @@ public:
int
getMaxPlayers
()
const
{
return
maxPlayers
;
}
bool
getSpectatorsAllowed
()
const
{
return
spectatorsAllowed
;
}
QString
getGameListLine
()
const
;
ReturnMessage
::
Return
Code
checkJoin
(
const
QString
&
_password
,
bool
spectator
);
ProtocolResponse
::
Response
Code
checkJoin
(
const
QString
&
_password
,
bool
spectator
);
Server_Player
*
addPlayer
(
const
QString
&
playerName
,
bool
spectator
);
void
removePlayer
(
Server_Player
*
player
);
void
startGameIfReady
();
...
...
common/server_protocolhandler.cpp
View file @
29bf3d37
This diff is collapsed.
Click to expand it.
common/server_protocolhandler.h
View file @
29bf3d37
...
...
@@ -4,10 +4,10 @@
#include
<QObject>
#include
<QPair>
#include
"server.h"
#include
"protocol.h"
#include
"protocol_items.h"
class
Server_Player
;
class
Command
;
class
ProtocolItem
;
class
Server_ProtocolHandler
:
public
QObject
{
Q_OBJECT
...
...
@@ -23,6 +23,40 @@ private:
AuthenticationResult
authState
;
bool
acceptsGameListChanges
;
bool
acceptsChatChannelListChanges
;
ProtocolResponse
::
ResponseCode
cmdPing
(
Command_Ping
*
cmd
);
ProtocolResponse
::
ResponseCode
cmdLogin
(
Command_Login
*
cmd
);
ProtocolResponse
::
ResponseCode
cmdChatListChannels
(
Command_ChatListChannels
*
cmd
);
ProtocolResponse
::
ResponseCode
cmdChatJoinChannel
(
Command_ChatJoinChannel
*
cmd
);
ProtocolResponse
::
ResponseCode
cmdChatLeaveChannel
(
Command_ChatLeaveChannel
*
cmd
,
Server_ChatChannel
*
channel
);
ProtocolResponse
::
ResponseCode
cmdChatSay
(
Command_ChatSay
*
cmd
,
Server_ChatChannel
*
channel
);
ProtocolResponse
::
ResponseCode
cmdListGames
(
Command_ListGames
*
cmd
);
ProtocolResponse
::
ResponseCode
cmdCreateGame
(
Command_CreateGame
*
cmd
);
ProtocolResponse
::
ResponseCode
cmdJoinGame
(
Command_JoinGame
*
cmd
);
ProtocolResponse
::
ResponseCode
cmdLeaveGame
(
Command_LeaveGame
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdSay
(
Command_Say
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdShuffle
(
Command_Shuffle
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdRollDie
(
Command_RollDie
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdDrawCards
(
Command_DrawCards
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdMoveCard
(
Command_MoveCard
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdCreateToken
(
Command_CreateToken
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdCreateArrow
(
Command_CreateArrow
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdDeleteArrow
(
Command_DeleteArrow
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdSetCardAttr
(
Command_SetCardAttr
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdReadyStart
(
Command_ReadyStart
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdIncCounter
(
Command_IncCounter
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdAddCounter
(
Command_AddCounter
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdSetCounter
(
Command_SetCounter
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdDelCounter
(
Command_DelCounter
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdNextTurn
(
Command_NextTurn
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdSetActivePhase
(
Command_SetActivePhase
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdDumpZone
(
Command_DumpZone
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdStopDumpZone
(
Command_StopDumpZone
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdDumpAll
(
Command_DumpAll
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
ProtocolResponse
::
ResponseCode
cmdSubmitDeck
(
Command_SubmitDeck
*
cmd
,
Server_Game
*
game
,
Server_Player
*
player
);
QList
<
ProtocolItem
*>
itemQueue
;
void
enqueueProtocolItem
(
ProtocolItem
*
item
);
public:
Server_ProtocolHandler
(
Server
*
_server
,
QObject
*
parent
=
0
);
~
Server_ProtocolHandler
();
...
...
servatrice/servatrice.pro
View file @
29bf3d37
...
...
@@ -15,7 +15,6 @@ QT -= gui
HEADERS
+=
src
/
servatrice
.
h
\
src
/
serversocketinterface
.
h
\
src
/
version
.
h
\
..
/
common
/
protocol
.
h
\
..
/
common
/
protocol_items
.
h
\
..
/
common
/
rng_abstract
.
h
\
...
...
servatrice/src/returnmessage.cpp
deleted
100644 → 0
View file @
6923c98d
#include
"returnmessage.h"
#include
"serversocket.h"
bool
ReturnMessage
::
send
(
ReturnCode
code
)
{
ServerSocket
*
s
=
qobject_cast
<
ServerSocket
*>
(
parent
());
if
(
!
s
)
return
false
;
QString
returnCodeString
;
switch
(
code
)
{
case
ReturnNothing
:
return
true
;
case
ReturnOk
:
returnCodeString
=
"ok"
;
break
;
case
ReturnNameNotFound
:
returnCodeString
=
"name_not_found"
;
break
;
case
ReturnLoginNeeded
:
returnCodeString
=
"login_needed"
;
break
;
case
ReturnSyntaxError
:
returnCodeString
=
"syntax"
;
break
;
case
ReturnContextError
:
returnCodeString
=
"context"
;
break
;
case
ReturnPasswordWrong
:
returnCodeString
=
"password"
;
break
;
case
ReturnSpectatorsNotAllowed
:
returnCodeString
=
"spectators_not_allowed"
;
break
;
}
s
->
msg
(
QString
(
"resp|%1|%2"
).
arg
(
msg_id
)
.
arg
(
returnCodeString
));
return
(
code
==
ReturnOk
);
}
bool
ReturnMessage
::
sendList
(
const
QStringList
&
args
,
const
QString
&
prefix
)
{
ServerSocket
*
s
=
qobject_cast
<
ServerSocket
*>
(
parent
());
if
(
!
s
)
return
false
;
QString
arg1
=
prefix
.
isEmpty
()
?
cmd
:
prefix
;
for
(
int
i
=
0
;
i
<
args
.
size
();
i
++
)
s
->
msg
(
QString
(
"%1|%2|%3"
).
arg
(
arg1
)
.
arg
(
msg_id
)
.
arg
(
args
[
i
]));
return
true
;
}
servatrice/src/returnmessage.h
deleted
100644 → 0
View file @
6923c98d
#ifndef RETURNMESSAGE_H
#define RETURNMESSAGE_H
#include
<QStringList>
class
ReturnMessage
:
public
QObject
{
Q_OBJECT
private:
unsigned
int
msg_id
;
QString
cmd
;
public:
enum
ReturnCode
{
ReturnNothing
,
ReturnOk
,
ReturnNameNotFound
,
ReturnLoginNeeded
,
ReturnSyntaxError
,
ReturnContextError
,
ReturnPasswordWrong
,
ReturnSpectatorsNotAllowed
};
ReturnMessage
(
QObject
*
parent
=
0
)
:
QObject
(
parent
),
msg_id
(
0
)
{
}
unsigned
int
getMsgId
()
const
{
return
msg_id
;
}
void
setMsgId
(
unsigned
int
_msg_id
)
{
msg_id
=
_msg_id
;
}
void
setCmd
(
const
QString
&
_cmd
)
{
cmd
=
_cmd
;
}
bool
send
(
ReturnCode
code
);
bool
sendList
(
const
QStringList
&
args
,
const
QString
&
prefix
=
QString
());
};
#endif
servatrice/src/servatrice.cpp
View file @
29bf3d37
...
...
@@ -22,10 +22,13 @@
#include
"servatrice.h"
#include
"server_chatchannel.h"
#include
"serversocketinterface.h"
#include
"protocol.h"
Servatrice
::
Servatrice
(
QObject
*
parent
)
:
Server
(
parent
)
{
ProtocolItem
::
initializeHash
();
tcpServer
=
new
QTcpServer
(
this
);
connect
(
tcpServer
,
SIGNAL
(
newConnection
()),
this
,
SLOT
(
newConnection
()));
tcpServer
->
listen
(
QHostAddress
::
Any
,
4747
);
// XXX make customizable
...
...
servatrice/src/serversocketinterface.cpp
View file @
29bf3d37
...
...
@@ -26,7 +26,7 @@
#include
"protocol_items.h"
ServerSocketInterface
::
ServerSocketInterface
(
Server
*
_server
,
QTcpSocket
*
_socket
,
QObject
*
parent
)
:
Server_ProtocolHandler
(
_server
,
parent
),
socket
(
_socket
)
:
Server_ProtocolHandler
(
_server
,
parent
),
socket
(
_socket
)
,
currentItem
(
0
)
{
xmlWriter
=
new
QXmlStreamWriter
;
xmlWriter
->
setDevice
(
socket
);
...
...
@@ -39,7 +39,7 @@ ServerSocketInterface::ServerSocketInterface(Server *_server, QTcpSocket *_socke
connect
(
socket
,
SIGNAL
(
error
(
QAbstractSocket
::
SocketError
)),
this
,
SLOT
(
catchSocketError
(
QAbstractSocket
::
SocketError
)));
xmlWriter
->
writeStartDocument
();
xmlWriter
->
writeStartElement
(
"cockatrice_
communication
"
);
xmlWriter
->
writeStartElement
(
"cockatrice_
server_stream
"
);
xmlWriter
->
writeAttribute
(
"version"
,
QString
::
number
(
ProtocolItem
::
protocolVersion
));
sendProtocolItem
(
new
Event_Welcome
(
Servatrice
::
versionString
));
...
...
@@ -64,32 +64,38 @@ ServerSocketInterface::~ServerSocketInterface()
void
ServerSocketInterface
::
readClient
()
{
qDebug
()
<<
"readClient"
;
xmlReader
->
addData
(
socket
->
readAll
());
while
(
canReadLine
())
{
QString
line
=
QString
(
readLine
()).
trimmed
();
if
(
line
.
isNull
())
break
;
qDebug
(
QString
(
"<<< %1"
).
arg
(
line
).
toLatin1
());
/* switch (PlayerStatus) {
case StatusNormal:
case StatusReadyStart:
case StatusPlaying:
parseCommand(line);
break;
case StatusSubmitDeck:
QString card = line;
if (card == ".") {
PlayerStatus = StatusNormal;
remsg->send(ReturnMessage::ReturnOk);
} else if (card.startsWith("SB:"))
SideboardList << card.mid(3);
if
(
currentItem
)
{
if
(
!
currentItem
->
read
(
xmlReader
))
return
;
currentItem
=
0
;
}
while
(
!
xmlReader
->
atEnd
())
{
xmlReader
->
readNext
();
if
(
xmlReader
->
isStartElement
())
{
QString
itemType
=
xmlReader
->
name
().
toString
();
if
(
itemType
==
"cockatrice_client_stream"
)
continue
;
QString
itemName
=
xmlReader
->
attributes
().
value
(
"name"
).
toString
();
qDebug
()
<<
"parseXml: startElement: "
<<
"type ="
<<
itemType
<<
", name ="
<<
itemName
;
currentItem
=
ProtocolItem
::
getNewItem
(
itemType
+
itemName
);
if
(
!
currentItem
)
currentItem
=
new
InvalidCommand
;
if
(
!
currentItem
->
read
(
xmlReader
))
return
;
else
{
Command
*
command
=
qobject_cast
<
Command
*>
(
currentItem
);
if
(
qobject_cast
<
InvalidCommand
*>
(
command
))
sendProtocolItem
(
new
ProtocolResponse
(
command
->
getCmdId
(),
ProtocolResponse
::
RespInvalidCommand
));
else
DeckList << card;
processCommand
(
command
);
currentItem
=
0
;
}
}
}
*/
}
}
void
ServerSocketInterface
::
catchSocketError
(
QAbstractSocket
::
SocketError
socketError
)
{
...
...
servatrice/src/serversocketinterface.h
View file @
29bf3d37
...
...
@@ -21,7 +21,7 @@
#define SERVERSOCKETINTERFACE_H
#include
<QTcpSocket>
#include
<
server_protocolhandler.h
>
#include
"
server_protocolhandler.h
"
class
QTcpSocket
;
class
Server
;
...
...
@@ -38,6 +38,7 @@ private:
QTcpSocket
*
socket
;
QXmlStreamWriter
*
xmlWriter
;
QXmlStreamReader
*
xmlReader
;
ProtocolItem
*
currentItem
;
public:
ServerSocketInterface
(
Server
*
_server
,
QTcpSocket
*
_socket
,
QObject
*
parent
=
0
);
~
ServerSocketInterface
();
...
...
servatrice/src/version.h
deleted
100644 → 0
View file @
6923c98d
/***************************************************************************
* Copyright (C) 2008 by Max-Wilhelm Bruker *
* brukie@laptop *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
static
const
int
PROTOCOL_VERSION
=
2
;
static
const
char
*
VERSION_STRING
=
"Servatrice 0.20091017"
;
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