(For sake of discussion; let's call the proposed server protocol "Banjo".)
Code: Select all
// Initialize the thread that forms the Banjo client interface.
// The parameter is the name of the local event receiving function.
// The receiver gets called with a new Banjo event whenever the interface
// has something to say.
Banjo *bptr = new Banjo(LocalBanjoEventReceiver);
// Identify self and log in to the server using pointers to the
// server identification and the client (engine) identification.
assert(bptr->PostEvent(new BanjoEvent(EkLogin, ServerID, ClientID)));
// Start a game
assert(bptr->PostEvent(new BanjoEvent(EkMatch, OpponentID, GameParameters)));
// Send a move
assert(bptr->PostEvent(new BanjoEvent(EkMove, SANMoveString)));
// Send a rep draw claim
assert(bptr->PostEvent(new BanjoEvent(EkRepDraw, SANMoveString)));
// Resign
assert(bptr->PostEvent(new BanjoEvent(EkResign)));
// Logout
assert(bptr->PostEvent(new BanjoEvent(EkLogout)));
// Conclude the Banjo interface.
delete bptr;
// Local event receiver code
void LocalBanjoEventReceiver(const BanjoEvent *beptr)
{
switch (beptr->Ek)
{
case EkMatch: HandleIncomingMatch(beptr->OpponentID); break;
case EkMove: HandleIncomingMove(beptr->SANMoveString); break;
case EkRepDraw: HandleIncomingRepDraw(beptr->SANMoveString); break;
case EkResign: HandleIncomingResign(); break;
...
};
}