![]() Up |
Enemy TerritoryDevelopment/Intro |
The first thing, a Client has to do, is to send a login message:
// Create a BMessage:
// The command-type of the BMessage must be 0x87654321.
BMessage theMessage ( 0x87654321 );
// Add the login fields to that message:
theMessage . AddString ( "Type", "login" );
theMessage . AddString ( "ClientName", "flintstone" );
theMessage . AddString ( "Password", "pentagon" );
theMessage . AddInt32 ( "Version", 1 );
// Create a BMessenger:
status_t theStatus;
BMessenger theMessenger ( "application/x-vnd.EnemyTerritory.Server",
-1, &theStatus );
// Send the message:
// the second parameter is the reply-handler.
// Every message from the Server will be sent to this BHandler.
theMessenger . SendMessage ( & theMessage, be_app );
Then, your client will receive a welcome message from the server:
// In your MessageReceived ( BMessage * theMessage ) function
// you should test the command-type:
if ( theMessage -> what == 0x87654321 )
{
Then, your client will receive status messages:
// In your MessageReceived ( BMessage * theMessage ) function
// you should test the command-type
// and check, if this message is a status message:
if ( theMessage -> what == 0x87654321 )
if ( Equal ( theMessage -> FindString ( "Type" ), "status" ) )
{
// Get the map-fields from the message:
int theIndex = 0;
while ( theMessage -> FindMessage ( "Field", theIndex, & includedMessage
) >= B_NO_ERROR )
{
// Get the objects from the message:
theIndex = 0;
while ( theMessage -> FindMessage ( "Object", theIndex, & includedMessage
) >= B_NO_ERROR )
{
Your Client can make a move by sending the following BMessage:
// Create the BMessage:
BMessage theMessage ( 0x87654321 );
// Add the turn fields to that message:
theMessage . AddString ( "Type", "turn" );
theMessage . AddString ( "ClientName", "flintstone" );
theMessage . AddString ( "Password", "pentagon" );
theMessage . AddInt32 ( "ID", 17 ); // replace the 17 by the
objects ID!
theMessage . AddString ( "Action", "move" );
theMessage . AddInt32 ( "MoveToX", 17 ); // replace the 17 by
the new x-coordinate
theMessage . AddInt32 ( "MoveToY", 17 ); // replace the 17 by
the new y-coordinate
// Create a BMessenger:
status_t theStatus;
BMessenger theMessenger ( "application/x-vnd.EnemyTerritory.Server",
-1, &theStatus );
// Send the message:
theMessenger . SendMessage ( & theMessage );