Mac OS 9
NetSprocket.h
Go to the documentation of this file.
1 
19 #ifndef __NETSPROCKET__
20 #define __NETSPROCKET__
21 
22 #ifndef __CONDITIONALMACROS__
23 #include <ConditionalMacros.h>
24 #endif
25 
26 #ifndef __MACTYPES__
27 #include <MacTypes.h>
28 #endif
29 
30 #ifndef __EVENTS__
31 #include <Events.h>
32 #endif
33 
34 #ifndef __OPENTRANSPORT__
35 #include <OpenTransport.h>
36 #endif
37 
38 #ifndef __OPENTRANSPORTPROVIDERS__
39 #include <OpenTransportProviders.h>
40 #endif
41 
42 #ifndef __MACERRORS__
43 #include <MacErrors.h>
44 #endif
45 
46 #if PRAGMA_ONCE
47 #pragma once
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54 
55 #if PRAGMA_IMPORT
56 #pragma import on
57 #endif
58 
59 #if PRAGMA_STRUCT_ALIGN
60 #pragma options align = power
61 #elif PRAGMA_STRUCT_PACKPUSH
62 #pragma pack(push, 2)
63 #elif PRAGMA_STRUCT_PACK
64 #pragma pack(2)
65 #endif
66 
67 #if TARGET_OS_MAC
68  enum
69  {
70  kNSpMaxPlayerNameLen = 31,
71  kNSpMaxGroupNameLen = 31,
72  kNSpMaxPasswordLen = 31,
73  kNSpMaxGameNameLen = 31,
74  kNSpMaxDefinitionStringLen = 255
75  };
76 
78  typedef struct OpaqueNSpGameReference *NSpGameReference;
79  typedef struct OpaqueNSpProtocolReference *NSpProtocolReference;
80  typedef struct OpaqueNSpProtocolListReference *NSpProtocolListReference;
81  typedef struct OpaqueNSpAddressReference *NSpAddressReference;
82  typedef SInt32 NSpEventCode;
83  typedef SInt32 NSpGameID;
84  typedef SInt32 NSpPlayerID;
85  typedef NSpPlayerID NSpGroupID;
86  typedef UInt32 NSpPlayerType;
87  typedef SInt32 NSpFlags;
88  typedef Str31 NSpPlayerName;
91  struct NSpPlayerInfo
92  {
93  NSpPlayerID id;
94  NSpPlayerType type;
95  Str31 name;
96  UInt32 groupCount;
97  NSpGroupID groups[1];
98  };
99  typedef struct NSpPlayerInfo NSpPlayerInfo;
100 
101  typedef NSpPlayerInfo *NSpPlayerInfoPtr;
103  struct NSpPlayerEnumeration
104  {
105  UInt32 count;
106  NSpPlayerInfoPtr playerInfo[1];
107  };
108  typedef struct NSpPlayerEnumeration NSpPlayerEnumeration;
109  typedef NSpPlayerEnumeration *NSpPlayerEnumerationPtr;
111  struct NSpGroupInfo
112  {
113  NSpGroupID id;
114  UInt32 playerCount;
115  NSpPlayerID players[1];
116  };
117  typedef struct NSpGroupInfo NSpGroupInfo;
118  typedef NSpGroupInfo *NSpGroupInfoPtr;
120  struct NSpGroupEnumeration
121  {
122  UInt32 count;
123  NSpGroupInfoPtr groups[1];
124  };
125  typedef struct NSpGroupEnumeration NSpGroupEnumeration;
126  typedef NSpGroupEnumeration *NSpGroupEnumerationPtr;
128  typedef UInt32 NSpTopology;
129  enum
130  {
131  kNSpClientServer = 0x00000001
132  };
133 
135  struct NSpGameInfo
136  {
137  UInt32 maxPlayers;
138  UInt32 currentPlayers;
139  UInt32 currentGroups;
140  NSpTopology topology;
141  UInt32 reserved;
142  Str31 name;
143  Str31 password;
144  };
145  typedef struct NSpGameInfo NSpGameInfo;
147  struct NSpMessageHeader
148  {
149  UInt32 version;
150  SInt32 what;
151  NSpPlayerID from;
152  NSpPlayerID to;
153  UInt32 id;
154  UInt32 when;
155  UInt32 messageLen;
157  };
158  typedef struct NSpMessageHeader NSpMessageHeader;
160  struct NSpErrorMessage
161  {
162  NSpMessageHeader header;
163  OSStatus error;
164  };
165  typedef struct NSpErrorMessage NSpErrorMessage;
166  struct NSpJoinRequestMessage
167  {
168  NSpMessageHeader header;
169  Str31 name;
170  Str31 password;
171  UInt32 theType;
172  UInt32 customDataLen;
173  UInt8 customData[1];
174  };
175  typedef struct NSpJoinRequestMessage NSpJoinRequestMessage;
176  struct NSpJoinApprovedMessage
177  {
178  NSpMessageHeader header;
179  };
180  typedef struct NSpJoinApprovedMessage NSpJoinApprovedMessage;
181  struct NSpJoinDeniedMessage
182  {
183  NSpMessageHeader header;
184  Str255 reason;
185  };
186  typedef struct NSpJoinDeniedMessage NSpJoinDeniedMessage;
187  struct NSpPlayerJoinedMessage
188  {
189  NSpMessageHeader header;
190  UInt32 playerCount;
191  NSpPlayerInfo playerInfo;
192  };
193  typedef struct NSpPlayerJoinedMessage NSpPlayerJoinedMessage;
194  struct NSpPlayerLeftMessage
195  {
196  NSpMessageHeader header;
197  UInt32 playerCount;
198  NSpPlayerID playerID;
199  NSpPlayerName playerName;
200  };
201  typedef struct NSpPlayerLeftMessage NSpPlayerLeftMessage;
202  struct NSpHostChangedMessage
203  {
204  NSpMessageHeader header;
205  NSpPlayerID newHost;
206  };
207  typedef struct NSpHostChangedMessage NSpHostChangedMessage;
208  struct NSpGameTerminatedMessage
209  {
210  NSpMessageHeader header;
211  };
212  typedef struct NSpGameTerminatedMessage NSpGameTerminatedMessage;
213  struct NSpCreateGroupMessage
214  {
215  NSpMessageHeader header;
216  NSpGroupID groupID;
217  NSpPlayerID requestingPlayer;
218  };
219  typedef struct NSpCreateGroupMessage NSpCreateGroupMessage;
220  struct NSpDeleteGroupMessage
221  {
222  NSpMessageHeader header;
223  NSpGroupID groupID;
224  NSpPlayerID requestingPlayer;
225  };
226  typedef struct NSpDeleteGroupMessage NSpDeleteGroupMessage;
227  struct NSpAddPlayerToGroupMessage
228  {
229  NSpMessageHeader header;
230  NSpGroupID group;
231  NSpPlayerID player;
232  };
233  typedef struct NSpAddPlayerToGroupMessage NSpAddPlayerToGroupMessage;
234  struct NSpRemovePlayerFromGroupMessage
235  {
236  NSpMessageHeader header;
237  NSpGroupID group;
238  NSpPlayerID player;
239  };
240  typedef struct NSpRemovePlayerFromGroupMessage NSpRemovePlayerFromGroupMessage;
241  struct NSpPlayerTypeChangedMessage
242  {
243  NSpMessageHeader header;
244  NSpPlayerID player;
245  NSpPlayerType newType;
246  };
247  typedef struct NSpPlayerTypeChangedMessage NSpPlayerTypeChangedMessage;
249  enum
250  {
251  kNSpSendFlag_Junk = 0x00100000,
253  kNSpSendFlag_Normal = 0x00200000,
254  kNSpSendFlag_Registered =
255  0x00400000
256  };
257 
260  enum
261  {
262  kNSpSendFlag_FailIfPipeFull = 0x00000001,
263  kNSpSendFlag_SelfSend = 0x00000002,
264  kNSpSendFlag_Blocking = 0x00000004
265  };
266 
268  enum
269  {
270  kNSpGameFlag_DontAdvertise = 0x00000001,
271  kNSpGameFlag_ForceTerminateGame = 0x00000002
272  };
273 
276  enum
277  {
278  kNSpSystemMessagePrefix = (long)0x80000000,
279  kNSpError = kNSpSystemMessagePrefix | 0x7FFFFFFF,
280  kNSpJoinRequest = kNSpSystemMessagePrefix | 0x00000001,
281  kNSpJoinApproved = kNSpSystemMessagePrefix | 0x00000002,
282  kNSpJoinDenied = kNSpSystemMessagePrefix | 0x00000003,
283  kNSpPlayerJoined = kNSpSystemMessagePrefix | 0x00000004,
284  kNSpPlayerLeft = kNSpSystemMessagePrefix | 0x00000005,
285  kNSpHostChanged = kNSpSystemMessagePrefix | 0x00000006,
286  kNSpGameTerminated = kNSpSystemMessagePrefix | 0x00000007,
287  kNSpGroupCreated = kNSpSystemMessagePrefix | 0x00000008,
288  kNSpGroupDeleted = kNSpSystemMessagePrefix | 0x00000009,
289  kNSpPlayerAddedToGroup = kNSpSystemMessagePrefix | 0x0000000A,
290  kNSpPlayerRemovedFromGroup = kNSpSystemMessagePrefix | 0x0000000B,
291  kNSpPlayerTypeChanged = kNSpSystemMessagePrefix | 0x0000000C
292  };
293 
295  enum
296  {
297  kNSpAllPlayers = 0x00000000,
298  kNSpHostOnly = (long)0xFFFFFFFF
299  };
300 
301  /************************* Initialization ************************/
311  OSStatus
312  NSpInitialize(UInt32 inStandardMessageSize, UInt32 inBufferSize,
313  UInt32 inQElements, NSpGameID inGameID, UInt32 inTimeout);
314 
315  /*************************** Protocols **************************/
326  OSStatus
327  NSpProtocol_New(const char *inDefinitionString,
328  NSpProtocolReference *outReference);
329 
339  void
340  NSpProtocol_Dispose(NSpProtocolReference inProtocolRef);
341 
351  OSStatus
352  NSpProtocol_ExtractDefinitionString(NSpProtocolReference inProtocolRef,
353  char *outDefinitionString);
354 
365  OSStatus
366  NSpProtocolList_New(NSpProtocolReference inProtocolRef,
367  NSpProtocolListReference *outList);
368 
378  void
379  NSpProtocolList_Dispose(NSpProtocolListReference inProtocolList);
380 
390  OSStatus
391  NSpProtocolList_Append(NSpProtocolListReference inProtocolList,
392  NSpProtocolReference inProtocolRef);
393 
403  OSStatus
404  NSpProtocolList_Remove(NSpProtocolListReference inProtocolList,
405  NSpProtocolReference inProtocolRef);
406 
416  OSStatus
417  NSpProtocolList_RemoveIndexed(NSpProtocolListReference inProtocolList,
418  UInt32 inIndex);
419 
429  UInt32
430  NSpProtocolList_GetCount(NSpProtocolListReference inProtocolList);
431 
441  NSpProtocolReference
442  NSpProtocolList_GetIndexedRef(NSpProtocolListReference inProtocolList,
443  UInt32 inIndex);
444 
455  NSpProtocolReference
456  NSpProtocol_CreateAppleTalk(ConstStr31Param inNBPName,
457  ConstStr31Param inNBPType, UInt32 inMaxRTT,
458  UInt32 inMinThruput);
459 
469  NSpProtocolReference
470  NSpProtocol_CreateIP(InetPort inPort, UInt32 inMaxRTT, UInt32 inMinThruput);
471 
472  /************************ Human Interface ************************/
473  typedef CALLBACK_API(Boolean, NSpEventProcPtr)(EventRecord *inEvent);
483  NSpAddressReference
484  NSpDoModalJoinDialog(ConstStr31Param inGameType,
485  ConstStr255Param inEntityListLabel, Str31 ioName,
486  Str31 ioPassword, NSpEventProcPtr inEventProcPtr);
487 
497  Boolean
498  NSpDoModalHostDialog(NSpProtocolListReference ioProtocolList, Str31 ioGameName,
499  Str31 ioPlayerName, Str31 ioPassword,
500  NSpEventProcPtr inEventProcPtr);
501 
502  /********************** Hosting and Joining **********************/
512  OSStatus
513  NSpGame_Host(NSpGameReference *outGame, NSpProtocolListReference inProtocolList,
514  UInt32 inMaxPlayers, ConstStr31Param inGameName,
515  ConstStr31Param inPassword, ConstStr31Param inPlayerName,
516  NSpPlayerType inPlayerType, NSpTopology inTopology,
517  NSpFlags inFlags);
518 
528  OSStatus
529  NSpGame_Join(NSpGameReference *outGame, NSpAddressReference inAddress,
530  ConstStr31Param inName, ConstStr31Param inPassword,
531  NSpPlayerType inType, void *inCustomData, UInt32 inCustomDataLen,
532  NSpFlags inFlags);
533 
543  OSStatus
544  NSpGame_EnableAdvertising(NSpGameReference inGame,
545  NSpProtocolReference inProtocol, Boolean inEnable);
546 
556  OSStatus
557  NSpGame_Dispose(NSpGameReference inGame, NSpFlags inFlags);
558 
568  OSStatus
569  NSpGame_GetInfo(NSpGameReference inGame, NSpGameInfo *ioInfo);
570 
571  /*************************** Messaging **************************/
581  OSStatus
582  NSpMessage_Send(NSpGameReference inGame, NSpMessageHeader *inMessage,
583  NSpFlags inFlags);
584 
594  NSpMessageHeader *
595  NSpMessage_Get(NSpGameReference inGame);
596 
606  void
607  NSpMessage_Release(NSpGameReference inGame, NSpMessageHeader *inMessage);
608 
619  OSStatus
620  NSpMessage_SendTo(NSpGameReference inGame, NSpPlayerID inTo, SInt32 inWhat,
621  void *inData, UInt32 inDataLen, NSpFlags inFlags);
622 
623  /********************** Player Information **********************/
633  OSStatus
634  NSpPlayer_ChangeType(NSpGameReference inGame, NSpPlayerID inPlayerID,
635  NSpPlayerType inNewType);
636 
646  OSStatus
647  NSpPlayer_Remove(NSpGameReference inGame, NSpPlayerID inPlayerID);
648 
658  OSStatus
659  NSpPlayer_GetAddress(NSpGameReference inGame, NSpPlayerID inPlayerID,
660  OTAddress **outAddress);
661 
671  NSpPlayerID
672  NSpPlayer_GetMyID(NSpGameReference inGame);
673 
683  OSStatus
684  NSpPlayer_GetInfo(NSpGameReference inGame, NSpPlayerID inPlayerID,
685  NSpPlayerInfoPtr *outInfo);
686 
696  void
697  NSpPlayer_ReleaseInfo(NSpGameReference inGame, NSpPlayerInfoPtr inInfo);
698 
708  OSStatus
709  NSpPlayer_GetEnumeration(NSpGameReference inGame,
710  NSpPlayerEnumerationPtr *outPlayers);
711 
721  void
722  NSpPlayer_ReleaseEnumeration(NSpGameReference inGame,
723  NSpPlayerEnumerationPtr inPlayers);
724 
734  UInt32
735  NSpPlayer_GetRoundTripTime(NSpGameReference inGame, NSpPlayerID inPlayer);
736 
746  UInt32
747  NSpPlayer_GetThruput(NSpGameReference inGame, NSpPlayerID inPlayer);
748 
749  /********************** Group Management **********************/
759  OSStatus
760  NSpGroup_New(NSpGameReference inGame, NSpGroupID *outGroupID);
761 
771  OSStatus
772  NSpGroup_Dispose(NSpGameReference inGame, NSpGroupID inGroupID);
773 
783  OSStatus
784  NSpGroup_AddPlayer(NSpGameReference inGame, NSpGroupID inGroupID,
785  NSpPlayerID inPlayerID);
786 
796  OSStatus
797  NSpGroup_RemovePlayer(NSpGameReference inGame, NSpGroupID inGroupID,
798  NSpPlayerID inPlayerID);
799 
809  OSStatus
810  NSpGroup_GetInfo(NSpGameReference inGame, NSpGroupID inGroupID,
811  NSpGroupInfoPtr *outInfo);
812 
822  void
823  NSpGroup_ReleaseInfo(NSpGameReference inGame, NSpGroupInfoPtr inInfo);
824 
834  OSStatus
835  NSpGroup_GetEnumeration(NSpGameReference inGame,
836  NSpGroupEnumerationPtr *outGroups);
837 
847  void
848  NSpGroup_ReleaseEnumeration(NSpGameReference inGame,
849  NSpGroupEnumerationPtr inGroups);
850 
851  /*************************** Utilities ***************************/
861  NumVersion
862  NSpGetVersion(void);
863 
873  void
874  NSpSetConnectTimeout(UInt32 inSeconds);
875 
885  void
886  NSpClearMessageHeader(NSpMessageHeader *inMessage);
887 
897  UInt32
898  NSpGetCurrentTimeStamp(NSpGameReference inGame);
899 
909  NSpAddressReference
910  NSpConvertOTAddrToAddressReference(OTAddress *inAddress);
911 
921  OTAddress *
922  NSpConvertAddressReferenceToOTAddr(NSpAddressReference inAddress);
923 
933  void
934  NSpReleaseAddressReference(NSpAddressReference inAddress);
935 
936  /************************* Advanced/Async routines ****************/
937  typedef CALLBACK_API(void,
938  NSpCallbackProcPtr)(NSpGameReference inGame,
939  void *inContext, NSpEventCode inCode,
940  OSStatus inStatus, void *inCookie);
950  OSStatus
951  NSpInstallCallbackHandler(NSpCallbackProcPtr inHandler, void *inContext);
952 
953  typedef CALLBACK_API(Boolean, NSpJoinRequestHandlerProcPtr)(
954  NSpGameReference inGame, NSpJoinRequestMessage *inMessage, void *inContext,
955  Str255 outReason);
965  OSStatus
966  NSpInstallJoinRequestHandler(NSpJoinRequestHandlerProcPtr inHandler,
967  void *inContext);
968 
969  typedef CALLBACK_API(Boolean,
970  NSpMessageHandlerProcPtr)(NSpGameReference inGame,
971  NSpMessageHeader *inMessage,
972  void *inContext);
982  OSStatus
983  NSpInstallAsyncMessageHandler(NSpMessageHandlerProcPtr inHandler,
984  void *inContext);
985 
986 #endif
988 #if PRAGMA_STRUCT_ALIGN
989 #pragma options align = reset
990 #elif PRAGMA_STRUCT_PACKPUSH
991 #pragma pack(pop)
992 #elif PRAGMA_STRUCT_PACK
993 #pragma pack()
994 #endif
995 
996 #ifdef PRAGMA_IMPORT_OFF
997 #pragma import off
998 #elif PRAGMA_IMPORT
999 #pragma import reset
1000 #endif
1001 
1002 #ifdef __cplusplus
1003 }
1004 #endif
1005 
1006 #endif
Set up for compiler independent conditionals.
Event Manager Interfaces.
OSErr codes.
Basic Macintosh data types.
unsigned char Boolean
Definition: MacTypes.h:318
This file contains provider-specific definitions for various built-in providers.
UInt16 InetPort
Definition: OpenTransportProviders.h:58
Open Transport client interface file. This contains all the client APIs.
Definition: Components.h:266
Definition: Events.h:224
Definition: MacTypes.h:638
Definition: OpenTransport.h:545