Source/NetSprocketSupport.h

//¥ ------------------------------------------------------------------------------------------  ¥
//¥
//¥ Copyright © 1996 Apple Computer, Inc., All Rights Reserved
//¥
//¥
//¥     You may incorporate this sample code into your applications without
//¥     restriction, though the sample code has been provided "AS IS" and the
//¥     responsibility for its operation is 100% yours.  However, what you are
//¥     not permitted to do is to redistribute the source as "DSC Sample Code"
//¥     after having made changes. If you're going to re-distribute the source,
//¥     we require that you make it clear in the source that the code was
//¥     descended from Apple Sample Code, but that you've made changes.
//¥
//¥     Authors:
//¥         Jamie Osborne
//¥
//¥ ------------------------------------------------------------------------------------------  ¥
 
#ifndef __NETSPROCKETSUPPORT__
#define __NETSPROCKETSUPPORT__
 
//¥ ------------------------------  Includes
 
#include <NetSprocket.h>
 
//¥ ------------------------------  Public Definitions
//¥ ------------------------------  Public Types
 
typedef struct WelcomeMessage
{
    NSpMessageHeader    h;
    UInt32              gameID;
} WelcomeMessage;
 
typedef struct ChatTextMessage
{
    NSpMessageHeader    h;
    Str255              text;
} ChatTextMessage;
 
typedef struct StartGameMessage
{
    NSpMessageHeader    h;
    SInt32              seed;
} StartGameMessage;
 
typedef struct PlayerInputMessage
{
    NSpMessageHeader    h;
    Boolean             left;
    Boolean             right;
    Boolean             fire;
} PlayerInputMessage;
 
//  Constants used for NetSprocket
enum
{
    kStandardMessageSize = 500,
    kBufferSize = 100000,
    kQElements = 40,
    kGameID = 'Invd',
    kTimeout = 5000,
    kMaxPlayers = 2
};
 
typedef enum
{
        kSlacking,
        kHosting,
        kJoining,
        kWaiting,
        kStarting,
        kRunning,
        kDenoument
} NetworkState;
 
enum
{
    kChatTextMessage = 10000,
    kStartGameMessage = 10001,
    kInputMessage = 10002,
    kEndGameMessage = 10003
};
 
//¥ ------------------------------  Public Variables
 
extern NSpGameReference gNetGame;
extern Boolean gIAmHost;
extern NetworkState gNetState;
extern Boolean gGotEndGameMessage;
extern Boolean gNetSprocketPresent;
extern Boolean gReceivedInput;
 
extern Str31 kNetworkGameName;
extern Str31 kJoinDialogLabel;
extern Str31 kNBPType;      // This should be the same as kGameID
 
//¥ ------------------------------  Public Functions
 
#ifdef __cplusplus
extern "C" {
#endif
 
extern Boolean InitNetworking(void);
extern Boolean NetSprocketPresent(void);
extern Boolean DoHostGame(void);
extern Boolean DoJoinGame(void);
extern void ShutdownNetworking(void);
extern void HandleNetworking(void);
extern void SendInputState(Boolean left, Boolean right, Boolean fire);
extern void SendEndGame();
extern Boolean WaitForAllPlayers(void);
extern void SendStartGame(void);
 
#ifdef __cplusplus
}
#endif
 
#endif