OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
natneg.h
1
2/******
3GameSpy NAT Negotiation SDK
4
5Copyright 2002 GameSpy Industries, Inc
6
7devsupport@gamespy.com
8
9******
10
11 Please see the GameSpy NAT Negotiation SDK documentation for more
12 information
13
14******/
15
16
17#ifndef _NATNEG_H_
18#define _NATNEG_H_
19#include "../common/gsCommon.h"
20#include "NATify.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/*
27NAT Negotiation Packet Magic Bytes
28These bytes will start each incoming packet that is part of the NAT Negotiation SDK.
29If you are sharing a game socket with the SDK, you can use these bytes to determine when to
30pass a packet to NNProcessData
31*/
32#define NATNEG_MAGIC_LEN 6
33#define NN_MAGIC_0 0xFD
34#define NN_MAGIC_1 0xFC
35#define NN_MAGIC_2 0x1E
36#define NN_MAGIC_3 0x66
37#define NN_MAGIC_4 0x6A
38#define NN_MAGIC_5 0xB2
39
40// This external array contains all 6 magic bytes - you can use it with memcmp to quickly check incoming packets for the bytes
41extern unsigned char NNMagicData[];
42
43/*
44Possible states for the SDK. The two you will be notified for are:
45ns_initack - when the NAT Negotiation server acknowledges your connection request
46ns_connectping - when direct negotiation with the other client has started
47*/
48typedef enum {ns_initsent, ns_initack, ns_connectping, ns_finished, ns_canceled, ns_reportsent, ns_reportack } NegotiateState;
49
50/*
51Possible reslts of the negotiation.
52nr_success: Successful negotiation, other parameters can be used to continue communications with the client
53nr_deadbeatpartner: Partner did not register with the NAT Negotiation Server
54nr_inittimeout: Unable to communicate with NAT Negotiation Server
55nr_unknownerror: NAT Negotiation server indicated an unknown error condition
56*/
57typedef enum {nr_success, nr_deadbeatpartner, nr_inittimeout, nr_pingtimeout, nr_unknownerror, nr_noresult } NegotiateResult;
58
59/*
60Possible errors that can be returned when starting a negotiation
61ne_noerror: No error
62ne_allocerror: Memory allocation failed
63ne_socketerror: Socket allocation failed
64ne_dnserror: DNS lookup failed
65*/
66typedef enum {ne_noerror, ne_allocerror, ne_socketerror, ne_dnserror} NegotiateError;
67
68
69//Callback prototype for your progress function
70typedef void (*NegotiateProgressFunc)(NegotiateState state, void *userdata);
71
72//Callback prototype for your negotiation completed function
73typedef void (*NegotiateCompletedFunc)(NegotiateResult result, SOCKET gamesocket, struct sockaddr_in *remoteaddr, void *userdata);
74
75//Callback prototype for your NAT detection results function
76typedef void (*NatDetectionResultsFunc)(gsi_bool success, NAT nat);
77
78
79/*
80NNBeginNegotiation
81-------------------
82Starts the negotiation process.
83cookie: Shared cookie value that both players will use so that the NAT Negotiation Server can match them up.
84clientindex: One client must use clientindex 0, the other must use clientindex 1.
85progresscallback: Callback function that will be called as the state changes
86completedcallback: Callback function that will be called when negotiation is complete.
87userdata: Pointer for your own use that will be passed into the callback functions.
88*/
89NegotiateError NNBeginNegotiation(int cookie, int clientindex, NegotiateProgressFunc progresscallback, NegotiateCompletedFunc completedcallback, void *userdata);
90
91
92/*
93NNBeginNegotiationWithSocket
94-------------------
95Starts the negotiation process using the socket provided, which will be shared with the game.
96Incoming traffic is not processed automatically - you will need to read the data off the socket and pass NN packets to NNProcessData
97*/
98NegotiateError NNBeginNegotiationWithSocket(SOCKET gamesocket, int cookie, int clientindex, NegotiateProgressFunc progresscallback, NegotiateCompletedFunc completedcallback, void *userdata);
99
100
101/*
102NNThink
103-------------------
104Processes any negotiation requests that are in progress
105*/
106void NNThink();
107
108
109/*
110NNProcessData
111-------------------
112When sharing a socket with the NAT Negotiation SDK, you must read incoming data and pass packets that start the the NN magic bytes
113to this function for processing, along with the address they came from.
114*/
115void NNProcessData(char *data, int len, struct sockaddr_in *fromaddr);
116
117
118/*
119NNCancel
120-------------------
121Cancels a NAT Negotiation request in progress
122*/
123void NNCancel(int cookie);
124
125
126/*
127NNFreeNegotiateList
128-------------------
129De-allocates the memory used by for the negotiate list when you are done with NAT Negotiation.
130The list will be re-allocated at a later time if you start additional negotiations.
131If any negotiations are outstanding this will cancel them.
132*/
133void NNFreeNegotiateList();
134
135
136/*
137NNStartNatDetection
138-------------------
139Detects if there is network address translation going on between the machine and the Internet.
140*/
141NegotiateError NNStartNatDetection(NatDetectionResultsFunc resultscallback);
142
143
144//Used for over-riding the default negotiation hostnames. Should not be used normally.
145extern char *Matchup2Hostname;
146extern char *Matchup1Hostname;
147
148#ifdef __cplusplus
149}
150#endif
151
152#endif
Definition puff.c:88