02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The possible tags in this example are:<br />

Chapter 22: Multi-player games using sockets<br />

QUERYBOXES – used <strong>to</strong> find out which boxes are currently under remote user control.<br />

No parameters are passed. For each connection in the connection list the ID of the connection<br />

is s<strong>to</strong>red in the array ‘userids’. This array is initially set <strong>to</strong> eight zeros. If a connection is being<br />

used then the array for this index is set <strong>to</strong> one. Then we build a string using the XML tag<br />

QUERYBOXES and the value of each of the eight members of the ‘userid’ array is passed<br />

<strong>to</strong> it. This message is then sent back <strong>to</strong> the socket that asked for it.<br />

PICKBOX – used <strong>to</strong> tell the server which box this connection is controlling and the name<br />

<strong>to</strong> use.<br />

The name and ID are stripped out of the string that is passed. This information is then passed<br />

on <strong>to</strong> each connection in the server’s connection list.<br />

MOVEBOX – informs the server that the box has moved, which then passes the details on<strong>to</strong> each<br />

connection.<br />

The ID, XPOS and YPOS of the box are stripped from the passed message and passed on <strong>to</strong><br />

every connection.<br />

DROPBOX – a user has s<strong>to</strong>pped dragging the box. This information is passed <strong>to</strong> each connection.<br />

The ID of the dropped box is stripped from the string and passed on <strong>to</strong> each connection in<br />

the server’s connection list.<br />

1 void CSockListenerDlg::ProcessPendingRead(CClientSocket *pSocket)<br />

2 {<br />

3 char msg[1000], xmlmsg[1000], *cp;<br />

4 int id, xpos, ypos, usedids[]={0,0,0,0,0,0,0};<br />

5 POSITION pos = m_connectionList.GetHeadPosition();<br />

6 CClientSocket *socket;<br />

7<br />

8 memset(msg, 0, 1000);<br />

9 pSocket->Receive( msg, 1000);<br />

10<br />

11 if (strncmp(msg, "QUERYBOXES", 5)==0){<br />

12 while(pos){<br />

13 socket = (CClientSocket*)m_connectionList.GetNext(pos);<br />

14 if (socket->boxid) usedids[socket->boxid-1] = 1;<br />

15 }<br />

16<br />

17 sprintf(xmlmsg, "",<br />

19 usedids[0], usedids[1], usedids[2], usedids[3],<br />

20 usedids[4], usedids[5], usedids[6]);<br />

21<br />

22 pSocket->Send(xmlmsg, strlen(xmlmsg)+1);<br />

353

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!