Beruflich Dokumente
Kultur Dokumente
GroupC
WNel
GScheepers
JPrinsloo
KCowdrey
KPitzer
CSwanepoel
u12097722
u12007227
u12023796
u12066754
u11198908
u11092743
1. Introduction
Thisdocumentwilldiscussthecommunicationprotocolusedtocommunicatebetweenthe
gamemasterandplayers.Allcommunicationwillgothroughthegamemastertothe
players.Therewillbenodirectcommunicationbetweenplayers.Communicationwill
consistofTCPsocketconnections.MessageswillbeencryptedusingQtencrypt
components.QtcomponentshasaXMLparserandthusmessageswillbeinaXML
format.
2. QTnetworkingcomponents
a. Servercode
tcpServer=newQTcpServer(this)
if(!tcpServer>listen()){
QMessageBox::critical(this,tr("FortuneServer"),
tr("Unabletostarttheserver:%1.")
.arg(tcpServer>errorString()))
close()
return
}
connect(tcpServer,SIGNAL(newConnection()),this,SLOT(sendFortune()))
b. Clientsetupcode
tcpSocket=newQTcpSocket(this)
connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(readFortune()))
connect(tcpSocket,SIGNAL(error(QAbstractSocket::SocketError)),
this,SLOT(displayError(QAbstractSocket::SocketError)))
c. Clientconnectioncode
tcpSocket>connectToHost(hostLineEdit>text(),
portLineEdit>text().toInt())
d. Datatransfer
QDataStreamin(tcpSocket)
in.setVersion(QDataStream::Qt_4_0)
if(blockSize==0){
if(tcpSocket>bytesAvailable()<(int)sizeof(quint16))
return
in>>blockSize
}
if(tcpSocket>bytesAvailable()<blockSize)
return
QStringnextFortune
in>>nextFortune
if(nextFortune==currentFortune){
QTimer::singleShot(0,this,SLOT(requestNewFortune()))
return
}
currentFortune=nextFortune
3. Communicationflowdiagrams
a. Playerstart
b. Gamemasterstart
c. Playeringame
d. Gamemasteringame
4. Messaging
Messagesthatwillbesenttocommunicatebetweenthedifferentobjects,willconformto
anXMLstandard.
Ageneralexampleisshownbelow:
<message>
<type>MessageTypeSent</type>
<data1>[yes|no]</data1>
<data2>DatainTag</data2>
</message>
LobbyList
<message>
<type>LOBBY</type>
<name>[Lobbynameongamemaster]</name>
<currentNumOfplayers>[0..4]</currentNumOfplayers>
<playerNames>[strArr[1..4]]</playerNames>
<address>[LobbyIPaddress]</address>
</message>
ThegamemastersthatareonthenetworkwillsendtheirlobbyinformationtotherequestedIPaddressof
theclient.
LobbySearchRequest
<message>
<type>SEARCH</type>
<name>[Uniqueplayername]</name>
<address>[ClientIPaddress]</address>
</message>
Theclientwillbroadcastamessageonthenetworktoaskforavailablelobbies.
Join
<message>
<type>JOIN</type>
<name>[Uniqueplayername]</name>
<address>[IPaddress]</address>
</message>
Theclientsendsamessagetoalobbyrequestingtojoin.
Acknowledgement
<message>
<type>ACK</type>
<confirm>[yes|no]</confirm>
</message>
Clientreceivesasuccessfulacknowledgemessageifthelobbyhasspacefortheclient.
Position
<message>
<type>POSITION</type>
<name>[Uniqueplayername]</name>
<address>[IPaddress]</address>
<position>[1..4]</position>
</message>
Theclientrequestsapositionontheboard.
Ready
<message>
<type>READY</type>
<name>[Uniqueplayername]</name>
<address>[ClientIPaddress]</address>
<status>[ready=1]</status>
</message>
Theclientsendsareadytoproceedmessagetothegamemaster.
Card
<message>
<type>CARD</type>
<cardsReceived>[Cards[1..4][1..13]]</cardsReceived>
</message>
Theclientreceives13randomcards.
Table
<message>
<type>TABLE</type>
<cardsPlayed>[Cards[1..4][1..13]]</cardsPlayed>
<dummieHand>[Cards[1..4][1..13]]</dummieHand>
<trumpSuite>[NoTrump|Spades|Hearts|Diamonds|Clovers]</trumpSuite>
<numOfTricksWon>[Trickswonbycontractteam]</numOfTricksWon>
<activePlayer>[playerName]</activePlayer>
</message>
Theclientreceivesthecurrenttablethatisshowntoalltheplayers.
Bid
<message>
<type>BID</type>
<suite>[Suite[0..4]]</suite>
<numberTricks>[TrickBid[1..7]]</numberTricks>
<contract>[Pass,Double,Call]</contract>
</message>
Theclientsendsthebidthatitcalls.
Token
<message>
<type>TOKEN</type>
<suite>[activeSuite[0..4]]</suite>
<activePlayer>[Uniqueplayername]</activePlayer>
</message>
Thegamemastersendsthetokentotheplayerthatcurrentlyhastoplay.
CardPlayed
<message>
<type>PLAYED</type>
<playCard>[Cards[1..4][1..13]]</playCard>
<returnToken>[activePlayer=null]</returnToken>
</message>
Theclientsendsthelastcardplayedaswellasreturningthetoken.
WinningTrick
<message>
<type>WINNINGT</type>
<activePlayer>[Uniqueplayername]</activePlayer>
</message>
Theplayerthatwonthelasttrickisbroadcastedtoalltheplayers.
Score
<message>
<type>SCORE</type>
<playerScore>[1..4]</playerScore>
<playerNames>[strArr[1..4]]</playerNames>
</message>
Afterthegamehasendedthescoreisbroadcastedtoalltheplayers.
Terminate
<message>
<type>TERMINATE</type>
<winningTeam>[Uniqueplayernames[2]]</winningTeam>
</message>
Amessageisbroadcastedtoalltheplayerstoinformthemthattheconnectionwillbeterminated.