chuyiwen_gmsv/include/net.h

311 lines
9.4 KiB
C
Raw Normal View History

2016-12-24 08:45:52 +08:00
#ifndef __NET_H__
#define __NET_H__
#include "common.h"
#include <sys/time.h>
#include <netinet/in.h>
// Nuke +1 0902: For queuing control
#include <signal.h>
#include <pthread.h>
#include "link.h"
#undef EXTERN
#ifdef __NET_C__
#define EXTERN
#else
#define EXTERN extern
#endif
/*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>У<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD> ƽ<EFBFBD>ҷ<EFBFBD><EFBFBD><EFBFBD>Ի
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ( <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ ) , <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ( ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> )
* N <EFBFBD><EFBFBD> NOT <EFBFBD><EFBFBD> W <EFBFBD><EFBFBD> WHILE , UL <EFBFBD><EFBFBD> UNLOCK <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
typedef enum
{
NOTLOGIN, /* <20><><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><CCBC>ƻ<EFBFBD><C6BB><EFBFBD>ئ<EFBFBD><D8A6> */
LOGIN, /* <20><><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD> */
WHILELOGIN, /* <20><><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><CCBC>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD> */
WHILECREATE, /* <20><><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD> */
WHILELOGOUTSAVE, /* <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ */
WHILECANNOTLOGIN, /* <20><><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD>ƥ<EFBFBD><C6A5>ئ<EFBFBD><D8A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
WHILECHARDELETE, /* ƽ<>ҷ´<D2B7><C2B4><EFBFBD> */
WHILEDOWNLOADCHARLIST, /* ƽ<>ҷ<EFBFBD><D2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
WHILECHANGEPASSWD, /* <20>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> */
WHILELOSTCHARSAVE, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥƽ<C6A5>ҷ±<D2B7><C2B1><EFBFBD>Ƥ<EFBFBD><C6A4> */
WHILELOSTCHARDELETE,/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥƽ<C6A5>ҷ<EFBFBD><D2B7><EFBFBD><EFBFBD><EFBFBD> */
WHILECLOSEALLSOCKETSSAVE, /* closeallsockets ƥƽ<C6A5>ҷ±<D2B7><C2B1><EFBFBD>Ƥ<EFBFBD><C6A4> */
WHILESAVEWAIT, /* <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󡼰<EFBFBD><F3A1BCB0> <20><><EFBFBD><EFBFBD> */
}LoginType;
/* <20>ƻ<EFBFBD><C6BB><EFBFBD>ئ<EFBFBD>У<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>ة */
typedef enum
{
NOTDETECTED,AC,CLI,ADM
}ConnectType;
/* <20>ӡ<EFBFBD><D3A1><EFBFBD><EFBBA5><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD>Ӯ<EFBFBD><D3AE> */
#define CDKEYLEN 16
#define PASSWDLEN 16
/* <20><>ľ<EFBFBD><C4BE> <20>ʷ<EFBFBD><CAB7>ص<EFBFBD>(<28><><EFBFBD><EFBFBD>ئ<EFBFBD><D8A6> Char <20><>STRING64 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><D8A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>³<EFBFBD><C2B3><EFBFBD>*/
#define CHARNAMELEN 32
#define CLITIMEOUT_SEC 120 /* <20>ͷ<EFBFBD><CDB7><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>read<61><64>ئ<EFBFBD><D8A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>գ<EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ةʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define NET_STRING_SUCCESSFULL "successful"
#define NET_STRING_FAILED "failed"
// <20>׹<EFBFBD><D7B9><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define RBSIZE (1024*64*8)
#define WBSIZE (1024*64*8)
// ʧ<><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//#define AC_RBSIZE (65536*48)
//#define AC_RBSIZE (65536*32)
#define AC_RBSIZE (1024*64*8)
//ttom modify because the second version had this
//#define AC_WBSIZE (65536*16)
extern int AC_WBSIZE;
EXTERN int bindedfd; /*<2A><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><CCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĩ<EFBFBD><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
EXTERN int acfd; /*ʧ<><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĩ<EFBFBD><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
EXTERN int ConnectLen; /*Ʊ<><C6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӯ<EFBFBD><D3AE>*/
#define CONNECT_WINDOWBUFSIZE 7
/* <20><> <20><><EFBFBD><EFBFBD> */
BOOL initConnect( int size );
void endConnect( void );
#define CONNECT_endOne( sockfd, lin) \
_CONNECT_endOne( __FILE__, __LINE__, sockfd, lin)
BOOL _CONNECT_endOne( char *file, int fromline, int sockfd , int lin);
#define CONNECT_attendOne( sockfd, lin) \
_CONNECT_attendOne( __FILE__, __LINE__, sockfd, lin)
BOOL _CONNECT_attendOne( char *file, int fromline, int sockfd , int lin);
BOOL netloop( void );
BOOL netloop_faster( void );
int lsrpcClientWriteFunc( int fd , char* buf , int size );
char* GetOneLine( int fd );
BOOL initConnectOne( int sockfd, struct sockaddr_in* sin ,int len );
#ifdef _CAX_LNS_NLSUOXU
void SetTimerLua( void );
BOOL DelTimer_net(int ID);
#endif
/* CA , CD */
void CAcheck( void );
void CAflush( int charaindex );
void CAsend( int fd );
void CDcheck( void );
void CDflush( int charaindex );
void CDsend( int fd );
BOOL CONNECT_appendCAbuf( int fd , char* data, int size );
BOOL CONNECT_appendCDbuf( int fd , char* data, int size );
/* Serverstate */
void SERVSTATE_decrementCloseallsocketnum(void);
int SERVSTATE_getCloseallsocketnum( void );
int SERVSTATE_SetAcceptMore( int nvalue );
int SERVSTATE_getShutdown(void);
void SERVSTATE_setShutdown(int a);
int SERVSTATE_getLimittime(void);
int SERVSTATE_getDsptime(void);
void SERVSTATE_setDsptime(int a);
void SERVSTATE_setLimittime(int a);
/* <20><><EFBFBD><EFBFBD><EFBFBD>þ<EFBFBD> */
void outputNetProcLog( int fd, int mode);
void chardatasavecheck( void );
void closeAllConnectionandSaveData( void );
BOOL SetShutdown( BOOL nvalue );
int GetShutdown( void );
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int getfdFromCdkey( char* cd );
int getfdFromCharaIndex( int charaindex );
int getcdkeyFromCharaIndex( int charaindex , char *out, int outlen );
int getCharindexFromFdid( int fdid );
int getFdidFromCharaIndex( int charind );
int getfdFromFdid( int fdid );
int getfdFromCdkeyWithLogin( char* cd );
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
INLINE int CONNECT_checkfd( int fd );
BOOL CONNECT_isCLI( int fd );
BOOL CONNECT_isAC( int fd );
BOOL CONNECT_isUnderLogin( int fd );
BOOL CONNECT_isWhileLogout( int fd );
BOOL CONNECT_isWhileLogin( int fd );
BOOL CONNECT_isNOTLOGIN( int fd );
BOOL CONNECT_isLOGIN( int fd );
int CONNECT_getUse( int fd );
int CONNECT_getUse_debug( int fd, int i );
void CONNECT_setCharaindex( int fd, int a );
int CONNECT_getCharaindex( int fd );
void CONNECT_getCdkey( int fd , char *out, int outlen );
void CONNECT_setCdkey( int fd , char *in);
void CONNECT_getPcid( int fd , char *out, int outlen );
void CONNECT_setPcid( int sockfd, char *pcid );
#ifdef _CAX_NEWMAC_LOGIN
void CONNECT_getMAC( int fd , char *out, int outlen );
void CONNECT_setMAC( int sockfd, char *mac );
#endif
void CONNECT_getOldPcid( int fd , char *out, int outlen );
void CONNECT_setOldPcid( int sockfd, char *pcid );
void CONNECT_getDefaultKey( int fd , char *out, int outlen );
void CONNECT_setDefaultKey( int sockfd, char *defaultkey );
void CONNECT_getPasswd( int fd , char *out, int outlen );
void CONNECT_setPasswd( int fd, char *in );
void CONNECT_getCharname( int fd , char *out, int outlen );
void CONNECT_setCharname( int fd, char *in );
int CONNECT_getFdid( int fd );
int CONNECT_getCtype( int fd );
void CONNECT_setCtype( int fd , int a );
void CONNECT_setDuelcharaindex( int fd, int i , int a );
int CONNECT_getDuelcharaindex( int fd, int i );
void CONNECT_setBattlecharaindex( int fd, int i , int a );
int CONNECT_getBattlecharaindex( int fd, int i );
void CONNECT_setJoinpartycharaindex( int fd, int i , int a);
int CONNECT_getJoinpartycharaindex( int fd, int i );
void CONNECT_setTradecardcharaindex( int fd, int i , int a );
int CONNECT_getTradecardcharaindex( int fd, int i );
/* MT<4D><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѩ<EFBFBD>ͷ<EFBFBD> */
#define CONNECT_endOne_debug(a) CONNECT_endOne( (a) , __LINE__ )
#define CONNECT_attendOne_debug(a) CONNECT_attendOne( (a) , __LINE__ )
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD><C9B1>) */
void CONNECT_setCDKEY( int sockfd, char *cd );
void CONNECT_getCDKEY( int sockfd , char *out, int outlen );
void CONNECT_setState( int fd, int s );
int CONNECT_getState( int fd );
void CONNECT_checkStatecount( int a );
int CONNECT_checkStateSomeOne( int a, int maxcount);
BOOL CONNECT_acfdInitRB( int fd );
BOOL CONNECT_acfdInitWB( int fd );
// Nuke +3
int checkWalkTime(int fd);
int setBtime(int fd);
#ifdef _BATTLE_TIMESPEED
//void setDefBTime( int fd, unsigned int times);
//unsigned int getDefBTime( int fd);
BOOL CheckDefBTime( int charaindex, int fd, unsigned int lowTime, unsigned int battletime, unsigned int addTime);
#endif
#ifdef _TYPE_TOXICATION
void setToxication( int fd, int flg);
int getToxication( int fd);
#endif
int checkBEOTime(int fd);
void sigusr1(int i);
void sigusr2(int i); // Arminius 6.26 signal
//ttom start
void CONNECT_set_watchmode(int fd, BOOL B_Watch);
BOOL CONNECT_get_watchmode(int fd);
void CONNECT_set_shutup(int fd,BOOL b_shut);//the avoid the user wash the screen
BOOL CONNECT_get_shutup(int fd);
unsigned long CONNECT_get_userip(int fd);
void CONNECT_set_pass(int fd,BOOL b_ps);
BOOL CONNECT_get_pass(int fd);
void CONNECT_set_state_trans(int fd,int a);
int CONNECT_get_state_trans(int fd);
//ttom end
// CoolFish: +9 2001/4/18
void CONNECT_setCloseRequest( int fd, int count);
void CONNECT_set_first_warp(int fd, BOOL b_ps);
BOOL CONNECT_get_first_warp(int fd);
int isDie(int fd);
void setDie(int fd);
// Arminius 6/22 encounter
int CONNECT_get_CEP(int fd);
void CONNECT_set_CEP(int fd, int cep);
// Arminius 7.12 login announce
int CONNECT_get_announced(int fd);
void CONNECT_set_announced(int fd, int a);
// shan trade(DoubleCheck) begin
int CONNECT_get_confirm(int fd);
void CONNECT_set_confirm(int fd, BOOL b);
// end
void CONNECT_setTradecharaindex( int fd, int i , int a);
void CONNECT_setLastrecvtime( int fd, struct timeval *a );
void CONNECT_getLastrecvtime( int fd, struct timeval *a );
void CONNECT_setLastrecvtime_D( int fd, struct timeval *a );
void CONNECT_getLastrecvtime_D( int fd, struct timeval *a );
void CONNECT_SetBattleRecvTime( int fd, struct timeval *a );
void CONNECT_GetBattleRecvTime( int fd, struct timeval *a );
void CONNECT_setTradeTmp(int fd, char* a);
void CONNECT_getTradeTmp(int fd, char *trademsg, int trademsglen);
int checkNu(int fd);
#ifdef _NO_WARP
// shan hjj add Begin
int CONNECT_get_seqno(int fd);
void CONNECT_set_seqno(int fd,int a);
int CONNECT_get_selectbutton(int fd);
void CONNECT_set_selectbutton(int fd, int a);
// shan End
#endif
// Arminius 7.2 Ra's amulet
void setNoenemy(int fd);
void clearNoenemy(int fd);
int getNoenemy(int fd);
void setEqNoenemy(int fd, int level);
void clearEqNoenemy(int fd);
int getEqNoenemy(int fd);
#ifdef _Item_MoonAct
void setEqRandenemy(int fd, int level);
void clearEqRandenemy(int fd);
int getEqRandenemy(int fd);
#endif
#ifdef _CHIKULA_STONE
void setChiStone(int fd, int nums);
int getChiStone(int fd);
#endif
// Arminius 7.31 cursed stone
void setStayEncount(int fd);
void clearStayEncount(int fd);
int getStayEncount(int fd);
void CONNECT_setBDTime( int fd, int nums);
int CONNECT_getBDTime( int fd);
// Arminius debug
void CONNECT_setUse( int fd , int a);
void CONNECT_setStarttime( int fd , int a);
#ifdef _ITEM_PILEFORTRADE
void CONNECT_setTradeList( int fd, int num);
int CONNECT_getTradeList(int fd);
#endif
#define QUEUE_LENGTH1 6
#define QUEUE_LENGTH2 7
BOOL MSBUF_CHECKbuflen( int size, float defp);
void SetTcpBuf( int sockfd);
#endif