ReadGameMsg.cpp
上传用户:garry_shen
上传日期:2015-04-15
资源大小:45647k
文件大小:2k
- #include "stdafx.h"
- #include "socket.h"
- #include "..XMudClient.h"
- #include "..InterNetMsg.h"
- extern SOCKET hLCltForRSvrSock;
- extern char g_szReceive[];
- extern BOOL ExplainSvrMsg(char *szBuf);
- extern void SrvSendMsg(char *szBuf);
- extern int nRecTimes;
- extern int g_nReceiveMsgState;
- int CheckCharOnString(char *lpstr,char c);
- BOOL ReadServerMsg(void)
- {
- long len,i,times,hr;
- static long ptr=0,entry=0;
- char *szTemple=NULL;
- static char *szBuffer=NULL;
- entry++;
- if(entry>1) {
- return TRUE;
- }
- for(times=0;times<8;times++) {
- if(ptr) {
- szBuffer=(char *)realloc(szBuffer,ptr+INPUT_SIZE);
- } else {
- szBuffer=(char *)malloc(INPUT_SIZE);
- }
- len=recv(hLCltForRSvrSock,szBuffer+ptr,INPUT_SIZE,0);
- if(len==SOCKET_ERROR) {
- if((hr=WSAGetLastError())==WSAEWOULDBLOCK) {
- break;
- } else {
- entry--;
- return FALSE;
- }
- }
- while(len>0) {
- for(i=ptr;i<ptr+len;i++) if(*(szBuffer+i)=='27') break;
- if(i>=ptr+len) {
- ptr+=len;
- len=0;
- if ((g_nReceiveMsgState == SVRMSG_CREATENEW) ||
- (g_nReceiveMsgState == SVRMSG_LOADOLD) ||
- (g_nReceiveMsgState == SVRMSG_CHANGEMAP)) nRecTimes++;
- }else {
- if(ptr+len>i+1){
- szTemple=(char *)malloc(ptr+len-i-1);
- memcpy(szTemple,szBuffer+i+1,ptr+len-i-1);
- }else {
- szTemple=NULL;
- }
- memset(g_szReceive,0,INPUT_SIZE);
- memcpy(g_szReceive,szBuffer,i>INPUT_SIZE?INPUT_SIZE:i);
- szBuffer[i]=0;
- if(i>0 && !ExplainSvrMsg(szBuffer)) SrvSendMsg(szBuffer);
- free(szBuffer);
- szBuffer=szTemple;
- len-=i+1-ptr;
- ptr=0;
- }
- }
- }
- entry--;
- return TRUE;
- }