662 lines
14 KiB
C++
662 lines
14 KiB
C++
![]() |
#include "../systeminc/version.h"
|
|||
|
#include "../systeminc/system.h"
|
|||
|
#include <winsock.h>
|
|||
|
#include "../systeminc/netmain.h"
|
|||
|
#include "../systeminc/lssproto_cli.h"
|
|||
|
#include "../wgs/message.h"
|
|||
|
#include "../systeminc/login.h"
|
|||
|
#include <time.h>
|
|||
|
#include "zlib.h"
|
|||
|
#pragma comment(lib,"zlib.lib")
|
|||
|
// Nuke 0615: Avoid 7's lock
|
|||
|
int isWGS7=0;
|
|||
|
|
|||
|
unsigned int sockfd; // SOCKET ? unsigned int?
|
|||
|
int init_net; // WSAStartup??????????????????server_choosed??????
|
|||
|
int server_choosed; // ?????<3F>k???????????????
|
|||
|
|
|||
|
char *net_writebuf = NULL;
|
|||
|
char *net_readbuf = NULL;
|
|||
|
int net_readbuflen;
|
|||
|
int net_writebuflen;
|
|||
|
|
|||
|
BOOL disconnectServerFlag = FALSE;
|
|||
|
BOOL oldDisconnectServerFlag = FALSE;
|
|||
|
|
|||
|
#ifdef _LOG_MSG
|
|||
|
char debugLogFileName[256] = "recvdata.txt"; // ???????<3F><><EFBFBD><EFBFBD>??????????
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
struct gameserver gmsv[MAX_GMSV];
|
|||
|
|
|||
|
// ????????<3F>ѩ<EFBFBD>?<3F>x??
|
|||
|
// ??: int index : <20>V?????<3F>k??0 ??getServerMax?<3F>k-1??????
|
|||
|
// char *hostname : IP?????
|
|||
|
// short *port : ???<3F>k?
|
|||
|
// ??<3F>k: 0 ... <20><>?
|
|||
|
// -1 ... <20><><EFBFBD><EFBFBD>
|
|||
|
//
|
|||
|
// ?????I/O????
|
|||
|
int getServerInfo( int index, char *hostname, short *port )
|
|||
|
{
|
|||
|
if( index < 0 || index >= sizeof( gmsv)/sizeof( gmsv[0] ) )
|
|||
|
return -1;
|
|||
|
|
|||
|
strcpy( hostname,gmsv[index].ipaddr );
|
|||
|
*port = atoi( gmsv[index].port );
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
??????<EFBFBD><EFBFBD>??????????????????????
|
|||
|
|
|||
|
??????????????????????
|
|||
|
|
|||
|
|
|||
|
?????I/O??????
|
|||
|
|
|||
|
*/
|
|||
|
char rpc_linebuffer[NETBUFSIZ]; // rpc?
|
|||
|
|
|||
|
extern int testCnt;
|
|||
|
|
|||
|
#ifdef _STONDEBUG_
|
|||
|
int CheckNetErrror( void )
|
|||
|
{
|
|||
|
int error = WSAGetLastError();
|
|||
|
// ??????<3F>R<EFBFBD>e
|
|||
|
switch ( error ){
|
|||
|
case WSANOTINITIALISED:
|
|||
|
return error;
|
|||
|
case WSAENETDOWN:
|
|||
|
return error;
|
|||
|
case WSAEACCES:
|
|||
|
return error;
|
|||
|
case WSAEINTR:
|
|||
|
return error;
|
|||
|
case WSAEINPROGRESS:
|
|||
|
return error;
|
|||
|
case WSAEFAULT:
|
|||
|
return error;
|
|||
|
case WSAENETRESET:
|
|||
|
return error;
|
|||
|
case WSAENOBUFS:
|
|||
|
return error;
|
|||
|
case WSAENOTCONN:
|
|||
|
return error;
|
|||
|
case WSAENOTSOCK:
|
|||
|
return error;
|
|||
|
case WSAEOPNOTSUPP:
|
|||
|
return error;
|
|||
|
case WSAESHUTDOWN:
|
|||
|
return error;
|
|||
|
case WSAEWOULDBLOCK:
|
|||
|
return error;
|
|||
|
case WSAEMSGSIZE:
|
|||
|
return error;
|
|||
|
case WSAEINVAL:
|
|||
|
return error;
|
|||
|
case WSAECONNABORTED:
|
|||
|
return error;
|
|||
|
case WSAECONNRESET:
|
|||
|
return error;
|
|||
|
case WSAETIMEDOUT:
|
|||
|
return error;
|
|||
|
default:
|
|||
|
return error;
|
|||
|
}
|
|||
|
return error;
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
#ifdef _STONDEBUG_
|
|||
|
|
|||
|
/*
|
|||
|
???Web???????????
|
|||
|
|
|||
|
do_http_request_forever()
|
|||
|
|
|||
|
static ?<EFBFBD><EFBFBD>?????????????<EFBFBD>u????????
|
|||
|
|
|||
|
char *ip : IP????(???<EFBFBD><EFBFBD>???????<EFBFBD><EFBFBD><EFBFBD>q?<EFBFBD>w????????)
|
|||
|
unsigned short port : ???<EFBFBD>k??????80?
|
|||
|
char *obj : ??????????????
|
|||
|
int sec : ?<EFBFBD><EFBFBD>??????
|
|||
|
|
|||
|
????<EFBFBD><EFBFBD> 0?<EFBFBD><EFBFBD>??<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>???????????
|
|||
|
*/
|
|||
|
static int http_sock;
|
|||
|
static int http_call_counter = 0;
|
|||
|
static time_t http_call_last_time;
|
|||
|
static int http_connecting = 0;
|
|||
|
static int http_sent_request = 0;
|
|||
|
|
|||
|
int
|
|||
|
do_http_request_forever( char *ip, unsigned short port,
|
|||
|
char *obj, int sec )
|
|||
|
{
|
|||
|
fd_set rfds,wfds;
|
|||
|
int r;
|
|||
|
struct timeval tm;
|
|||
|
|
|||
|
/* ??????????????????
|
|||
|
1<EFBFBD><EFBFBD>?1?????????? */
|
|||
|
if( http_call_last_time != time(NULL )){
|
|||
|
http_call_last_time = time(NULL);
|
|||
|
} else {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
//fprintf(stderr,".");
|
|||
|
|
|||
|
if( http_call_counter == 0 ){
|
|||
|
struct sockaddr_in sin;
|
|||
|
|
|||
|
/* sec<65><63>?1?connect?? */
|
|||
|
if( time(NULL) % sec != 0 )return 0;
|
|||
|
|
|||
|
http_sock = socket( AF_INET, SOCK_STREAM, 0 );
|
|||
|
if( http_sock < 0 )return -1;
|
|||
|
|
|||
|
unsigned long flg = 1;
|
|||
|
ioctlsocket( http_sock, FIONBIO, &flg );
|
|||
|
#if 0
|
|||
|
fprintf(stderr,"socket()\n" );
|
|||
|
flags = fcntl( http_sock, F_GETFL,0);
|
|||
|
if( fcntl( http_sock, F_SETFL, flags|O_NONBLOCK )< 0){
|
|||
|
close( http_sock );
|
|||
|
return -2;
|
|||
|
}
|
|||
|
#endif
|
|||
|
memset( &sin, 0 , sizeof( sin ));
|
|||
|
sin.sin_addr.s_addr = inet_addr( ip );
|
|||
|
sin.sin_port = htons( port );
|
|||
|
sin.sin_family = AF_INET;
|
|||
|
|
|||
|
if( connect( http_sock, (struct sockaddr*)&sin,
|
|||
|
sizeof(sin))== SOCKET_ERROR ){
|
|||
|
|
|||
|
if( WSAGetLastError() == WSAEWOULDBLOCK )
|
|||
|
{
|
|||
|
// <20>o?????????????????
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
closesocket( http_sock );
|
|||
|
return -5;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
http_call_counter ++;
|
|||
|
http_sent_request = 0;
|
|||
|
//fprintf(stderr,"connected\n" );
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
FD_ZERO( &rfds );
|
|||
|
FD_SET( http_sock, &rfds );
|
|||
|
FD_ZERO( &wfds );
|
|||
|
FD_SET( http_sock, &wfds );
|
|||
|
|
|||
|
tm.tv_usec = tm.tv_sec = 0;
|
|||
|
r = select( http_sock+1, &rfds, &wfds,(fd_set*)NULL,&tm);
|
|||
|
|
|||
|
if( r > 0 && FD_ISSET( http_sock, &rfds ) ){
|
|||
|
char buf[1000];
|
|||
|
r = recv( http_sock, buf,sizeof(buf), 0);
|
|||
|
if( r <= 0 ){
|
|||
|
closesocket( http_sock );
|
|||
|
/* ????????? */
|
|||
|
http_call_counter = 0;
|
|||
|
}
|
|||
|
//fprintf(stderr,"read %d\n",r );
|
|||
|
}
|
|||
|
|
|||
|
if( r > 0 && FD_ISSET( http_sock, &wfds ) && http_sent_request == 0 ){
|
|||
|
/* HTTP????MSS???<3F><><EFBFBD><EFBFBD>?<3F><>?????
|
|||
|
1??write????????<EFBFBD>e?????
|
|||
|
???????????????<EFBFBD>u?<EFBFBD><EFBFBD>???????????
|
|||
|
????? */
|
|||
|
int r;
|
|||
|
char fuck[1000];
|
|||
|
sprintf_s( fuck, "GET %s HTTP/1.0\r\n\r\n" , obj );
|
|||
|
|
|||
|
r = send( http_sock, fuck, strlen( fuck ), 0 );
|
|||
|
|
|||
|
if( r <= 0 ){
|
|||
|
closesocket(r );
|
|||
|
http_call_counter = 0;
|
|||
|
return -10;
|
|||
|
}
|
|||
|
//fprintf(stderr,"wrote %d\n",r );
|
|||
|
http_sent_request = 1;
|
|||
|
}
|
|||
|
return 0;
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
void networkLoop(void)
|
|||
|
{
|
|||
|
if( init_net == FALSE )
|
|||
|
return;
|
|||
|
|
|||
|
if( disconnectServerFlag && !oldDisconnectServerFlag){
|
|||
|
// ???????<3F><><EFBFBD>e???
|
|||
|
ChangeProc( PROC_DISCONNECT_SERVER );
|
|||
|
}
|
|||
|
oldDisconnectServerFlag = disconnectServerFlag;
|
|||
|
if( disconnectServerFlag)
|
|||
|
return;
|
|||
|
|
|||
|
if( server_choosed == 0)return;
|
|||
|
fd_set rfds , wfds, efds;
|
|||
|
|
|||
|
struct timeval tm;
|
|||
|
tm.tv_sec = 0;
|
|||
|
tm.tv_usec = 0;
|
|||
|
|
|||
|
FD_ZERO( &rfds );
|
|||
|
FD_ZERO( &wfds );
|
|||
|
FD_ZERO( &efds );
|
|||
|
|
|||
|
FD_SET( sockfd , &rfds );
|
|||
|
FD_SET( sockfd , &wfds );
|
|||
|
FD_SET( sockfd , &efds );
|
|||
|
|
|||
|
int a = select( 2 , &rfds , &wfds , (fd_set*)NULL, &tm );
|
|||
|
#if 0
|
|||
|
if( FD_ISSET( sockfd , &efds )){
|
|||
|
char buf[256];
|
|||
|
memset( buf , 0 , sizeof(buf));
|
|||
|
int len = recv( sockfd , buf , sizeof( buf ) -1 , 0 );
|
|||
|
if( len == SOCKET_ERROR ){
|
|||
|
#ifdef _STONDEBUG_
|
|||
|
CheckNetErrror();
|
|||
|
#endif
|
|||
|
closesocket( sockfd );
|
|||
|
dwServer = NULL;
|
|||
|
// ??????<3F><><EFBFBD>Q?<3F>N<EFBFBD><4E>?????<3F><><EFBFBD><EFBFBD>??
|
|||
|
disconnectServerFlag = TRUE;
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>???
|
|||
|
int len = SOCKET_ERROR;
|
|||
|
#ifdef __NEW_CLIENT_MEM
|
|||
|
BOOL ret;
|
|||
|
DWORD oldprotect;
|
|||
|
#ifndef __NEW_CLIENT_ONLY_WRITE
|
|||
|
ret = VirtualProtect( net_readbuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect);
|
|||
|
#endif
|
|||
|
#endif
|
|||
|
if( FD_ISSET( sockfd , &rfds) ){
|
|||
|
len = recv( sockfd , rpc_linebuffer , (NETBUFSIZ >> 1) - 1, 0 );
|
|||
|
if (isWGS7) {
|
|||
|
if ((len>1400)&&(len<=1460)) {
|
|||
|
Sleep(500);
|
|||
|
len += recv( sockfd , rpc_linebuffer+len , (NETBUFSIZ >> 1) - 1, 0 );
|
|||
|
}
|
|||
|
isWGS7=0;
|
|||
|
}
|
|||
|
if( len == SOCKET_ERROR ){
|
|||
|
if( WSAGetLastError() != WSAEWOULDBLOCK ){
|
|||
|
#ifdef _STONDEBUG_
|
|||
|
CheckNetErrror();
|
|||
|
#endif
|
|||
|
closesocket(sockfd);
|
|||
|
dwServer = NULL;
|
|||
|
// ??????<3F><><EFBFBD>Q?<3F>N<EFBFBD><4E>?????<3F><><EFBFBD><EFBFBD>??
|
|||
|
disconnectServerFlag = TRUE;
|
|||
|
}
|
|||
|
} else appendReadBuf( rpc_linebuffer , len );
|
|||
|
}
|
|||
|
int aaaaaaaa=0;
|
|||
|
while( len!=SOCKET_ERROR && net_readbuflen>0){
|
|||
|
// get line from read buffer
|
|||
|
if(GS==dwServer){
|
|||
|
if(!getLineFromReadBuf( rpc_linebuffer ,sizeof(rpc_linebuffer) )){
|
|||
|
|
|||
|
if( bNewServer)
|
|||
|
SaDispatchMessage( sockfd , rpc_linebuffer );
|
|||
|
else
|
|||
|
lssproto_ClientDispatchMessage( sockfd , rpc_linebuffer );
|
|||
|
}else break;
|
|||
|
}else ReadWGSMessage(net_readbuf,net_readbuflen);
|
|||
|
}
|
|||
|
#ifdef __NEW_CLIENT_MEM
|
|||
|
#ifndef __NEW_CLIENT_ONLY_WRITE
|
|||
|
ret = VirtualProtect( net_readbuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect);
|
|||
|
#endif
|
|||
|
#endif
|
|||
|
|
|||
|
static unsigned int writetime = TimeGetTime();
|
|||
|
|
|||
|
// ?<3F><>???
|
|||
|
if( FD_ISSET( sockfd , &wfds)){
|
|||
|
#ifdef __NEW_CLIENT_MEM
|
|||
|
ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect);
|
|||
|
#endif
|
|||
|
len = 0;
|
|||
|
if( net_writebuflen) len = send( sockfd, net_writebuf , net_writebuflen , 0 );
|
|||
|
/*???????*/
|
|||
|
if(len > 0) writetime = TimeGetTime();
|
|||
|
|
|||
|
if( len == SOCKET_ERROR ){
|
|||
|
if( WSAGetLastError() != WSAEWOULDBLOCK ){
|
|||
|
#ifdef _STONDEBUG_
|
|||
|
CheckNetErrror();
|
|||
|
#endif
|
|||
|
closesocket(sockfd);
|
|||
|
dwServer = NULL;
|
|||
|
// ??????<3F><><EFBFBD>Q?<3F>N<EFBFBD><4E>?????<3F><><EFBFBD><EFBFBD>??
|
|||
|
disconnectServerFlag = TRUE;
|
|||
|
}
|
|||
|
} else {
|
|||
|
if( len) shiftWriteBuf( len );
|
|||
|
}
|
|||
|
#ifdef __NEW_CLIENT_MEM
|
|||
|
ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect);
|
|||
|
#endif
|
|||
|
}
|
|||
|
if((GS==dwServer) && (writetime + 30*1000 <TimeGetTime())){
|
|||
|
if( init_net == TRUE){
|
|||
|
if( bNewServer)
|
|||
|
lssproto_Echo_send(sockfd, "hoge");
|
|||
|
else
|
|||
|
old_lssproto_Echo_send(sockfd, "hoge");
|
|||
|
testCnt++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
StoneAge??????????????<EFBFBD>o????
|
|||
|
|
|||
|
|
|||
|
<EFBFBD>V??<EFBFBD><EFBFBD>?????????<EFBFBD><EFBFBD><EFBFBD>i???????????????<EFBFBD><EFBFBD>?select<EFBFBD>V<EFBFBD><EFBFBD>?
|
|||
|
??????<EFBFBD><EFBFBD>?????????????????????????????
|
|||
|
????<EFBFBD><EFBFBD>???????????????????HTTP???????????
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>h??????
|
|||
|
|
|||
|
|
|||
|
???????<EFBFBD><EFBFBD>???????<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
1. ??????initNet()??
|
|||
|
2. ????networkLoop??????????<EFBFBD><EFBFBD>???
|
|||
|
3. cli.cpp ???? gmsv ?<EFBFBD>B<EFBFBD>l?<EFBFBD><EFBFBD>??????????<EFBFBD>ѩ<EFBFBD>??????
|
|||
|
4. ?<EFBFBD><EFBFBD>?????????<EFBFBD><EFBFBD>???????????
|
|||
|
|
|||
|
*/
|
|||
|
|
|||
|
|
|||
|
|
|||
|
//***************************************
|
|||
|
// ?????????
|
|||
|
//***************************************
|
|||
|
BOOL initNet( void )
|
|||
|
{
|
|||
|
int ret;
|
|||
|
WSADATA wsadata;
|
|||
|
|
|||
|
// winsock??????
|
|||
|
ret = WSAStartup( MAKEWORD( 1, 1 ), &wsadata );
|
|||
|
if( ret != 0 )
|
|||
|
return FALSE;
|
|||
|
|
|||
|
// lssproto????
|
|||
|
//cary test lssproto_InitClient( appendWriteBuf, 65536, sockfd );
|
|||
|
lssproto_InitClient( appendWriteBuf, NETBUFSIZ, sockfd );
|
|||
|
|
|||
|
#ifdef _LOG_MSG
|
|||
|
//??????
|
|||
|
{
|
|||
|
// ??????<3F><>??????
|
|||
|
FILE *fp;
|
|||
|
fp = fopen( debugLogFileName, "w" );
|
|||
|
fclose(fp);
|
|||
|
}
|
|||
|
lssproto_SetClientLogFiles( debugLogFileName , debugLogFileName );
|
|||
|
#endif
|
|||
|
|
|||
|
#ifdef _STONDEBUG_
|
|||
|
{ // <20><><EFBFBD><EFBFBD>??????????????<3F><>??<3F><>
|
|||
|
FILE *fp = fopen( "recvtime.txt", "w" );
|
|||
|
if( fp ) fclose( fp );
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
init_net = TRUE;
|
|||
|
disconnectServerFlag = FALSE;
|
|||
|
oldDisconnectServerFlag = FALSE;
|
|||
|
|
|||
|
return TRUE;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//***************************************
|
|||
|
// ??????<3F><>?????<3F><>??????
|
|||
|
//***************************************
|
|||
|
void cleanupNetwork( void )
|
|||
|
{
|
|||
|
if( init_net == FALSE )
|
|||
|
return;
|
|||
|
|
|||
|
init_net = FALSE;
|
|||
|
server_choosed = 0;
|
|||
|
|
|||
|
disconnectServerFlag = FALSE;
|
|||
|
oldDisconnectServerFlag = FALSE;
|
|||
|
|
|||
|
closesocket( sockfd );
|
|||
|
dwServer = NULL;
|
|||
|
WSACleanup();
|
|||
|
|
|||
|
// lsrpc???????????<3F><>??????????
|
|||
|
// ????????????????????????????
|
|||
|
lssproto_CleanupClient();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// ????????????<3F>D?
|
|||
|
//
|
|||
|
// ??<3F>k<EFBFBD><6B> 0 ... <20><>?
|
|||
|
// -1 ... ?????<3F>K???
|
|||
|
// -100 ... ????<3F>k<EFBFBD><6B>?????
|
|||
|
int appendReadBuf( char *buf, int size )
|
|||
|
{
|
|||
|
#ifdef _NEWSHOP_
|
|||
|
BOOL flg=TRUE;
|
|||
|
while(*(DWORD *)buf == 0xC7B3CCC9){ //buf[0]==0xFFFFFFC9 && buf[1]==0xFFFFFFCC && buf[2]==0xFFFFFFB3 && buf[3]==0xFFFFFFC7
|
|||
|
extern int <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD>( char *arr[], char *str, const char *del);
|
|||
|
extern void <EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(char * ·<EFBFBD><EFBFBD>,<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>_ *<EFBFBD>̳<EFBFBD>);
|
|||
|
extern <EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>_ <EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[5];
|
|||
|
char patch[256]={0};
|
|||
|
int id=-1;
|
|||
|
buf+=4;
|
|||
|
char *<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[4]={0};
|
|||
|
unsigned int <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>,(char*)buf,"|");
|
|||
|
<EFBFBD>ܴ<EFBFBD>С = atoi(<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[0]);
|
|||
|
ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С = atoi(<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[1]);
|
|||
|
id = atoi(<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[2]);
|
|||
|
memcpy(<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[id].MD5<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[3],32);
|
|||
|
sprintf_s(patch,"./data/shop%d.bin",id+1);
|
|||
|
if(<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[id].<EFBFBD>̳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!=NULL)
|
|||
|
free(<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[id].<EFBFBD>̳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>);
|
|||
|
<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[id].<EFBFBD>̳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = (char*)malloc(<EFBFBD>ܴ<EFBFBD>С+1);
|
|||
|
memset(<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[id].<EFBFBD>̳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0,<EFBFBD>ܴ<EFBFBD>С+1);
|
|||
|
uLongf lendata = <EFBFBD>ܴ<EFBFBD>С-1;
|
|||
|
uncompress((Bytef*)<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[id].<EFBFBD>̳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,&lendata,(Bytef*)(buf+51),(unsigned long)ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С);
|
|||
|
<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(patch,&<EFBFBD>̳<EFBFBD><EFBFBD>ļ<EFBFBD>[id]);
|
|||
|
memset(buf-4,0,ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С+55);
|
|||
|
size -=ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С+55;
|
|||
|
buf+=ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С+51;
|
|||
|
flg=FALSE;
|
|||
|
}
|
|||
|
if(!flg) return -1;
|
|||
|
#endif
|
|||
|
if( server_choosed == 0 )
|
|||
|
return -100;
|
|||
|
|
|||
|
if( (net_readbuflen + size) > NETBUFSIZ )
|
|||
|
return -1;
|
|||
|
|
|||
|
memcpy( net_readbuf + net_readbuflen, buf, size );
|
|||
|
net_readbuflen += size;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// ????????????<3F>D?
|
|||
|
//
|
|||
|
// ??<3F>k<EFBFBD><6B> 0 ... <20><>?
|
|||
|
// -1 ... ?????<3F>K???
|
|||
|
// -100 ... ????<3F>k<EFBFBD><6B>?????
|
|||
|
int appendWriteBuf( int index, char *buf, int size )
|
|||
|
{
|
|||
|
if( server_choosed == 0 )
|
|||
|
return -100;
|
|||
|
#ifndef __NEW_CLIENT_MEM
|
|||
|
if( (net_writebuflen + size) > NETBUFSIZ )
|
|||
|
return -1;
|
|||
|
memcpy( net_writebuf + net_writebuflen, buf, size );
|
|||
|
net_writebuflen += size;
|
|||
|
#else
|
|||
|
DWORD oldprotect;
|
|||
|
BOOL ret;
|
|||
|
ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_READWRITE, &oldprotect);
|
|||
|
|
|||
|
if( (net_writebuflen + size) > NETBUFSIZ )
|
|||
|
return -1;
|
|||
|
memcpy( net_writebuf + net_writebuflen, buf, size );
|
|||
|
net_writebuflen += size;
|
|||
|
|
|||
|
ret = VirtualProtect( net_writebuf, NETBUFSIZ, PAGE_NOACCESS, &oldprotect);
|
|||
|
#endif
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// ????????????size???<3F>ơq????
|
|||
|
// ?????size???<3F><>?????<3F><>????
|
|||
|
//
|
|||
|
// ??<3F>k<EFBFBD><6B> 0 ... <20><>?
|
|||
|
// -1 ... ?????<3F><>????
|
|||
|
// -100 ... ???<3F>k<EFBFBD><6B>?????
|
|||
|
int shiftReadBuf( int size )
|
|||
|
{
|
|||
|
int i;
|
|||
|
if( server_choosed == 0 )
|
|||
|
return -100;
|
|||
|
|
|||
|
if( size > net_readbuflen )
|
|||
|
return -1;
|
|||
|
for( i = size; i < net_readbuflen; i++ )
|
|||
|
{
|
|||
|
net_readbuf[i-size] = net_readbuf[i];
|
|||
|
}
|
|||
|
net_readbuflen -= size;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// ????????????size???<3F>ơq????
|
|||
|
// ?????size???<3F><>?????<3F><>????
|
|||
|
//
|
|||
|
// ??<3F>k<EFBFBD><6B> 0 ... <20><>?
|
|||
|
// -1 ... ?????<3F><>????
|
|||
|
// -100 ... ???<3F>k<EFBFBD><6B>?????
|
|||
|
int shiftWriteBuf( int size )
|
|||
|
{
|
|||
|
int i;
|
|||
|
|
|||
|
if( server_choosed == 0 )
|
|||
|
return -100;
|
|||
|
if( size > net_writebuflen )
|
|||
|
return -1;
|
|||
|
for( i = size; i < net_writebuflen; i++ )
|
|||
|
{
|
|||
|
net_writebuf[i-size] = net_writebuf[i];
|
|||
|
}
|
|||
|
net_writebuflen -= size;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// ??????????????<3F><>????<3F><>????<3F><>?<3F><>?
|
|||
|
//
|
|||
|
// ??<3F>k<EFBFBD><6B> 0 ... <20><>?
|
|||
|
// -1 ... ??<3F><>????<3F><>?
|
|||
|
// -100 ... ????<3F>k<EFBFBD><6B>?????
|
|||
|
int getLineFromReadBuf( char *output, int maxlen )
|
|||
|
{
|
|||
|
int i;
|
|||
|
|
|||
|
if( server_choosed == 0 )
|
|||
|
return -100;
|
|||
|
int j;
|
|||
|
for( i = 0; i < net_readbuflen && i < (maxlen-1); i++ )
|
|||
|
{
|
|||
|
if( net_readbuf[i] == '\n' )
|
|||
|
{
|
|||
|
memcpy( output, net_readbuf, i );
|
|||
|
output[i] = '\0';
|
|||
|
// <20><>??<3F><><EFBFBD><EFBFBD>?<3F><>??????????? 0x0d?????<3F><>?
|
|||
|
for( j = i+1; j >= 0; j-- )
|
|||
|
{
|
|||
|
if( output[j] == 0x0d )
|
|||
|
{
|
|||
|
output[j] = '\0';
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>??<3F><>?????
|
|||
|
shiftReadBuf( i+1 );
|
|||
|
|
|||
|
// ??????<3F>D????????<3F><>??????
|
|||
|
// ????????????????<3F><>????????<3F><>?????????
|
|||
|
net_readbuf[net_readbuflen] = '\0';
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// ??????<3F><>?len????<3F><>??
|
|||
|
//
|
|||
|
// ??<3F>k<EFBFBD><6B> 0?<3F><> ... ?<3F><>??????
|
|||
|
// -100 ... ????<3F>k<EFBFBD><6B>??????
|
|||
|
int sendn( SOCKET s, char *buffer, int len )
|
|||
|
{
|
|||
|
int total = 0;
|
|||
|
int r;
|
|||
|
|
|||
|
if( server_choosed == 0 )
|
|||
|
return -100;
|
|||
|
|
|||
|
while( 1 )
|
|||
|
{
|
|||
|
r = send( s, buffer, len, 0 );
|
|||
|
if( r == SOCKET_ERROR )
|
|||
|
return SOCKET_ERROR;
|
|||
|
total += r;
|
|||
|
if( total == len )
|
|||
|
return total;
|
|||
|
}
|
|||
|
}
|