[Kde-games-devel] KBattleship network protocol reveals ship types
Stephen McCamant
smcc at CSAIL.MIT.EDU
Wed Mar 22 00:37:30 CET 2006
>>>>> "AAC" == Albert Astals Cid <aacid at kde.org> writes:
AAC> A Dijous 16 Març 2006 00:05, Stephen McCamant va escriure:
SMcC> While looking at the protocol that KBattleship uses for network
SMcC> games, I noticed an unexpected feature: in the ANSWER_SHOOT
SMcC> message that tells the opponent whether their shot was a hit or
SMcC> a miss, the client actually reveals some extra
SMcC> information. Because the "fieldstate" field of the message is
SMcC> taken directly from the return value of the shipTypeAt() method,
SMcC> it also reveals the type of ship that the shot hit. [...]
AAC> It would be nice if you could provide that patch yes.
I've appended a patch against the latest 3.5-branch version from SVN
to the end of this message.
AAC> P.S: I hope you are not trying to donwload SVN trunk (that will
AAC> be KDE 4.0 but branches/3.5) so we can fix that for KDE 3.5.3 and
AAC> so on.
I actually did try the trunk first, but had some trouble compiling
because of the klistview -> k3listview transition. That's fixed now,
though, and kbattleship doesn't appear to have changed too much in the
trunk, so I could also supply a patch against that pretty easily as
well.
-- Stephen
Index: kbattleship/kbattleship/kbattleship.cpp
===================================================================
--- kbattleship/kbattleship/kbattleship.cpp (revision 521181)
+++ kbattleship/kbattleship/kbattleship.cpp (working copy)
@@ -922,7 +922,7 @@
void KBattleshipWindow::slotSendEnemyFieldState(int fieldx, int fieldy)
{
int data, showstate;
- bool xokay = false, yokay = false;
+ bool xokay = false, yokay = false, is_kill = false;
typedef QValueList<int> DeathValueList;
DeathValueList deathList;
@@ -987,12 +987,12 @@
msg->addField(QString("ystart"), QString::number(fieldy));
msg->addField(QString("ystop"), QString::number(fieldy));
msg->addField(QString("death"), QString("true"));
+ is_kill = true;
}
}
msg->addField(QString("fieldx"), QString::number(fieldx));
msg->addField(QString("fieldy"), QString::number(fieldy));
- msg->addField(QString("fieldstate"), QString::number(data));
if(xokay)
{
@@ -1001,6 +1001,7 @@
msg->addField(QString("ystart"), QString::number(fieldy));
msg->addField(QString("ystop"), QString::number(fieldy));
msg->addField(QString("death"), QString("true"));
+ is_kill = true;
}
else if(yokay)
{
@@ -1009,8 +1010,19 @@
msg->addField(QString("ystart"), QString::number(deathList.first()));
msg->addField(QString("ystop"), QString::number(deathList.last()));
msg->addField(QString("death"), QString("true"));
+ is_kill = true;
}
+ if(is_kill)
+ // If sunk, reveal ship type
+ msg->addField(QString("fieldstate"), QString::number(data));
+ else if(showstate == KBattleField::HIT)
+ // On non-fatal hit, keep ship type secret
+ msg->addField(QString("fieldstate"), QString::number(1));
+ else /* showstate == KBattleField::WATER */
+ // Miss
+ msg->addField(QString("fieldstate"), QString::number(99));
+
if(m_connection->type() == KonnectionHandling::SERVER)
m_kbserver->sendMessage(msg);
else
More information about the kde-games-devel
mailing list