/*
 
 
NetL2Pri.h : level 2 private declarations
 
 
*/
 
#if !defined(__NETL2PRI_TYPES__)
#define __NETL2PRI_TYPES__
 
#if !defined(ONLY_TYPES)
#define NETL2PRI_UNDEF
#define ONLY_TYPES
#endif /* !ONLY_TYPES */
 
 /* 
 //////////////////////////////////////////////////////////////////////
 INCLUDE FILES 
 //////////////////////////////////////////////////////////////////////
 */
#include <NET\macros.h>
#include "PrivNetDef.h"
#include "PrivNetSer.h"
 
#if defined(NETL2PRI_UNDEF)
#undef ONLY_TYPES
#undef NETL2PRI_UNDEF
#endif /* !NETL2PRI_UNDEF */
 
 /* 
 //////////////////////////////////////////////////////////////////////
 DEFINITION OF TYPES :
 //////////////////////////////////////////////////////////////////////
 */
 
/* Describe the listening mode */
M_BeginDeclareEnumerate(tdeNetListeningMode)
E_Net_LisMod_OFF,
E_Net_LisMod_ON,
E_Net_LisMod_INVALID
M_EndDeclareEnumerate(tdeNetListeningMode, unsigned char)
 
/* Describe the status of a player currently asking to join the session */
M_BeginDeclareEnumerate(tdeNetConnectReceptionStatus)
 E_Net_ConRecSta_NONE,
 E_Net_ConRecSta_DOING,
 E_Net_ConRecSta_DONE
M_EndDeclareEnumerate(tdeNetConnectReceptionStatus, unsigned char)
 
/* Describe the status of a player to which a connection request is done or todo*/
M_BeginDeclareEnumerate(tdeNetConnectRequestStatus)
 E_Net_ConReqSta_Invalid,
 E_Net_ConReqSta_Todo,
 E_Net_ConReqSta_Done,
 E_Net_ConReqSta_Listened,
 E_Net_ConReqSta_Refused,
 E_Net_ConReqSta_SessionChanged,
 E_Net_ConReqSta_WaitBusy
M_EndDeclareEnumerate(tdeNetConnectRequestStatus, unsigned char)
 
typedef struct tdstNetGetActiveLoopDesc_
{
  unsigned short *m_p_uwNumberOfSessionWaited;
  NetLib_tdstSessionInfo **m_pd_stSessionInfoFound;
}tdstNetGetActiveLoopDesc;
 
typedef struct tdstNetConnectLoopDesc_
{
  unsigned short m_uwOldIndexValue;
  unsigned long m_ulPrevTimeInfo;
  unsigned long m_ulFreq;
}tdstNetConnectLoopDesc;
 
typedef struct tdstNetDescriptionMsgDesc_
{
  NetLib_tduxPlayerId m_ulPlayerId;
  tdpPointer m_pBuffer;
  NetLib_tduxDescriptionLength m_uxBufferLength;
  tdeNetMessageType m_eMessage;
}tdstNetDescriptionMsgDesc;
 
typedef int (_NET_CALLING_CONV_ *tdfn_vNetEngineFunc)(void);
 
/* internal structure for handling read-receipt event*/
typedef struct tdstNetInternalReadReceiptDesc_
{
  tdstNetMessage *m_p_stMessage;/* pointer to a message*/
  NetLib_tdulTimeInfo m_ulPreviousSending;
  NetLib_tdulTimeInfo m_ulFirstSending;
  NetLib_tdstReadReceiptDesc m_stReadReceiptDesc;
}tdstNetInternalReadReceiptDesc;
 
#endif /* !__NETL2PRI_TYPES__ */
 
#if !defined(ONLY_TYPES)
 
#if !defined(__NETL2PRI_VARS__)
#define __NETL2PRI_VARS__
 
#undef EXTERN
#undef extern
#if !defined(GLOBALS)
#define EXTERN extern
#else /* !GLOBALS */
#define EXTERN
#endif /* !GLOBALS */
 
#undef extern
 
#endif /* !__NETL2PRI_VARS__ */
 
#if !defined (__NETL2PRI_PROTOS__)
#define __NETL2PRI_PROTOS__
 
 /* 
 //////////////////////////////////////////////////////////////////////
 DEFINITION OF MACROS :
 //////////////////////////////////////////////////////////////////////
 */
#define M_vNetFreeIOSystemCell(p_stIOSystCell) \
 if (p_stIOSystCell) \
 { \
  if ((p_stIOSystCell)->p_stMessage) \
   vFree((tdpPointer)((p_stIOSystCell)->p_stMessage)); \
  vFree((tdpPointer)p_stIOSystCell); \
  p_stIOSystCell = (tdstNetIOSystemCell*) C_pNull; \
 }
 
#define M_vNetAddMessageMapEntry(p_fn_MessageMap,eSysMsg,fn_SysMsgHandle) \
 p_fn_MessageMap[eSysMsg] = fn_SysMsgHandle;
 
 
 /* 
 //////////////////////////////////////////////////////////////////////
 DEFINITION OF FUNCTIONS :
 //////////////////////////////////////////////////////////////////////
 */
 
  #ifndef _NO_USE_DEFAULT_NET_FUNCTIONS_
  /* Default functions :*/
  unsigned long _NET_CALLING_CONV_ fn_ulDefaultNetRandom(void);
  NetLib_tdulTimeInfo _NET_CALLING_CONV_ fn_ulDefaultNetGetTimeInfo(void);
  #endif
 
  NetLib_tduxPlayerId ulNetGetNewPlayerId();
 
 
  /* Handler of System messages :*/
  NetLib_tdeErrorStatus eNetBuildMessageMap(void);
  NetLib_tdeErrorStatus eNetClearMessageMap(void);
  NetLib_tdeErrorStatus eNetBuildMessageSwapLittleBigEndianMap(void);
  NetLib_tdeErrorStatus eNetClearMessageSwapLittleBigEndianMap(void);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgUnknownSender(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgUnknownRecipient(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgFullBuffer(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgPlayerDescriptorChanged(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgPlayerDescriptorChanged(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgRequestSessionReply(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgRequestSessionReply(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgRequestSession(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgConnectRequest(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgConnectCancel(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgConnectAcknowledgement(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgConnectAgreement(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgConnectAgreement(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgConnectDeny(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgConnectDeny(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgSessionDescriptorChanged(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgWaitFollow(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgWaitBusy(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgDisconnection(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgConnectListened(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgTimeDeltaRequest(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgTimeDeltaRequest(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgTimeDeltaReply(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgDisconnectRemotePlayer(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgDisconnectRemotePlayer(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgReadReceipt(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgReadReceipt(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgMaxNbrOfPlayers(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eSwapLittleBigEndianSysMsgMaxNbrOfPlayers(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
 
  /* NetEngine functions :*/
  NetLib_tdeErrorStatus eNetBuildEngineFunctionsList(void);
  NetLib_tdeErrorStatus eNetAddEngineFunction(tdfn_vNetEngineFunc);
  NetLib_tdeErrorStatus eNetRemoveEngineFunction(tdfn_vNetEngineFunc);
  NetLib_tdeErrorStatus eNetEmptyEngineFunctionList(void);
  int _NET_CALLING_CONV_ iNetEngineSysMsg(void);
  int _NET_CALLING_CONV_ iNetEngineGetActiveSession(void);
  int _NET_CALLING_CONV_ iNetEngineInternetSimulation(void);
  int _NET_CALLING_CONV_ iNetEngineReadReceipt(void);
 
  /* Setting parameters :*/
  void vNetSetOwnPlayerId(NetLib_tduxPlayerId);
  void vNetSetSessionId(NetLib_tduxSessionId);
 
  
  /* Others functions :*/
  NetLib_tdeErrorStatus eNetSendReadReceiptMessage(tdstNetMessage *);
  NetLib_tdeErrorStatus eNetSendReadReceiptSysMessage(tdstNetIOSystemCell *);
  
  void vNetClearSessionInfo(NetLib_tdstSessionInfo *);
  NetLib_tdeErrorStatus eNetCheckTimeOutOfPlayerConnected(unsigned char);
  NetLib_tdeErrorStatus eNetCancelConnection(void);
  NetLib_tdeErrorStatus eNetSendAcknowledgementMessage(void);
 
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetIsMessageType(tdstNetMessage *,void *);
 
  NetLib_tdeErrorStatus NetLib_eCopystPlayerInfo(NetLib_tdstPlayerInfo*,NetLib_tdstPlayerInfo*);
 
  unsigned long ulTimeInfoToLagUnits(NetLib_tdulTimeInfo,unsigned long);
  NetLib_tdulTimeInfo ulLagUnitsToTimeInfo(unsigned long,unsigned long);
  
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetDenyPlayerAccess(NetLib_tdstPlayerInfo*,long*);
 
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetBuildAndAddReadReceipt(NetLib_tduxPlayerId,long);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetReadCompleted(long);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetSendCompleted(long);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetListenCompleted(long);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetFlushCompleted(long);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetGetActiveSessionsCompleted(long);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetConnectionCompleted(long);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetListeningCompleted(long);
 
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetDisconnectPlayer(NetLib_tduxPlayerId,long);
  NetLib_tdeErrorStatus eNetInternalChangeMaxNbrOfPlayers(unsigned short);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetInternalSendMessage(NetLib_tdstSendDesc *,tdeNetMessageType);
  
  unsigned short _NET_CALLING_CONV_ uwNetGetPlayerIndex(NetLib_tduxPlayerId);
  NetLib_tdstPlayerInfo * _NET_CALLING_CONV_ pstNetGetPlayerSlot(NetLib_tduxPlayerId);
  NetLib_tdstPlayerInfo * _NET_CALLING_CONV_ pstNetGetOwnPlayerSlot(void);
  
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eNetRemoveRemotePlayer(NetLib_tduxPlayerId);
 
  NetLib_tdeErrorStatus eInternetSimuSendMessage(NetLib_tduxPlayerId,tdstNetMessage*);
  NetLib_tdeErrorStatus eNetManageInternetDelay(void);
 
  NetLib_tdeErrorStatus eNetBuildInternalReadReceiptDesc(tdstNetInternalReadReceiptDesc*,tdstNetMessage*,NetLib_tdstReadReceiptDesc*);
  NetLib_tdeErrorStatus eNetEraseInternalReadReceiptDesc(tdstNetInternalReadReceiptDesc*);
 
  NetLib_tdeErrorStatus eNetSendTCPAddress(void);
  NetLib_tdeErrorStatus eNetSendTCPIsMe(tduwNetChannel uwChannel,char First);
  NetLib_tdeErrorStatus eNetSendTCPSupRoute(NetLib_tduxPlayerId IdSource,NetLib_tduxPlayerId IdDest);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgTCPAddress(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgTCPIsMe(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  NetLib_tdeErrorStatus _NET_CALLING_CONV_ eHandleNetSysMsgTCPSupRoute(tdstNetMessage *pstMes,tdeNetProtocol eProt,tduwNetChannel uwChannel);
  int _NET_CALLING_CONV_ iNetEngineTCPReconect(void);
 
#endif /* !__NETL2PRI_PROTOS__ */
 
#endif /* !ONLY_TYPES */
