Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate

Autor Topic: DataSend y DataRecv duda  (Visto 285 veces)

0 Miembros and 1 Guest are viewing this topic.

Offline Daniel@ Posteado: January 27, 2021, 02:24:28 PM | Modificado: January 27, 2021, 02:45:23 PM by Daniel@

  • 0 puntos por ventas
  • *
  • Rank: Puto amo
  • Posts: 353
  • Gracias recibida: 2866
  • ve
hola tengo una gran pregunta

en el datasend del launcher añadi lo siguiente

Code: [Select]
int Encrypt = 0;

size = buff[0+1];
buff[0+2] ^= Encrypt;
headcode = buff[0+2];

el coneccserver recibe perfectamente los datos

aqui el detalle es cuando le toca al coneectserver volver a reenviar

datasend del connectserver

Code: [Select]
pMsg.h.headcode = 0x04;
strcpy( pMsg.IpAddress, serverManager.http.Address );
strcpy( pMsg.FtpId, serverManager.http.ID );
strcpy( pMsg.FtpPass, serverManager.http.Password );
strcpy( pMsg.Folder, serverManager.http.Folder );
pMsg.Port = serverManager.http.Port;

BuxConvert(pMsg.IpAddress, 100);
BuxConvert(pMsg.FtpId,   20);
BuxConvert(pMsg.FtpPass, 20);
BuxConvert(pMsg.Folder,  20);

memcpy( serverManager.szHTTPFileServerInfoSendBuffer, (char*)&pMsg, sizeof(pMsg) );
serverManager.nHTTPFileServerInfoBufferLen = sizeof( pMsg );
memcpy( serverManager.szHTTPFileServerInfoSendBuffer, (char*)&pMsg, sizeof(pMsg) );
serverManager.nHTTPFileServerInfoBufferLen = sizeof( pMsg );

DataSend(aIndex, (LPBYTE)serverManager.szFileServerInfoSendBuffer, serverManager.nFileServerInfoBufferLen);


Code: [Select]
BOOL DataSend(int aIndex, unsigned char* lpMsg, DWORD dwSize)
{
int i = 0;
unsigned char changedProtocol = 0;
int aLen = sizeof(lpMsg);
unsigned long SendBytes;
_PER_SOCKET_CONTEXT * lpPerSocketContext;
unsigned char * SendBuf;
EnterCriticalSection(&criti);

if ( ((aIndex < 0)? FALSE : (aIndex > serverManager._MaxConnections-1)? FALSE : TRUE )  == FALSE )
{
LogAdd("error-L2 : Index(%d) %x %x %x ", dwSize, lpMsg[0], lpMsg[1], lpMsg[2]);
LeaveCriticalSection(&criti);
return false;
}

SendBuf = lpMsg;

if ( Obj[aIndex].Connected == false )
{
LeaveCriticalSection(&criti);
return FALSE;
}

lpPerSocketContext= Obj[aIndex].PerSocketContext;

if ( dwSize > sizeof(lpPerSocketContext->IOContext[0].Buffer))
{
LogAdd("Error : Max msg(%d) %s %d", dwSize, __FILE__, __LINE__);
CloseClient(aIndex);
LeaveCriticalSection(&criti);
return false;
}

_PER_IO_CONTEXT  * lpIoCtxt;

lpIoCtxt = &lpPerSocketContext->IOContext[1];

if ( lpIoCtxt->nWaitIO > 0 )
{
if ( ( lpIoCtxt->nSecondOfs + dwSize ) > MAX_IO_BUFFER_SIZE-1 )
{
LogAdd("(%d)error-L2 MAX BUFFER OVER %d %d %d", aIndex, lpIoCtxt->nTotalBytes, lpIoCtxt->nSecondOfs, dwSize);
lpIoCtxt->nWaitIO = 0;
CloseClient(aIndex);
LeaveCriticalSection(&criti);
return true;
}

memcpy( &lpIoCtxt->BufferSecond[lpIoCtxt->nSecondOfs], SendBuf, dwSize);
lpIoCtxt->nSecondOfs += dwSize;
LeaveCriticalSection(&criti);
return true;
}

lpIoCtxt->nTotalBytes = 0;

if ( lpIoCtxt->nSecondOfs > 0 )
{
memcpy(lpIoCtxt->Buffer, lpIoCtxt->BufferSecond, lpIoCtxt->nSecondOfs);
lpIoCtxt->nTotalBytes = lpIoCtxt->nSecondOfs;
lpIoCtxt->nSecondOfs = 0;
}

if ( (lpIoCtxt->nTotalBytes+dwSize) > MAX_IO_BUFFER_SIZE-1 )
{
LogAdd("(%d)error-L2 MAX BUFFER OVER %d %d", aIndex, lpIoCtxt->nTotalBytes, dwSize);
lpIoCtxt->nWaitIO = 0;
CloseClient(aIndex);
LeaveCriticalSection(&criti);
return FALSE;
}

memcpy( &lpIoCtxt->Buffer[lpIoCtxt->nTotalBytes], SendBuf, dwSize);
lpIoCtxt->nTotalBytes += dwSize;
lpIoCtxt->wsabuf.buf = (char*)&lpIoCtxt->Buffer;
lpIoCtxt->wsabuf.len = lpIoCtxt->nTotalBytes;
lpIoCtxt->nSentBytes = 0;
lpIoCtxt->IOOperation = 1;


if ( WSASend( Obj[aIndex].m_socket, &lpIoCtxt->wsabuf , 1, &SendBytes, 0, &lpIoCtxt->Overlapped, NULL) == -1 )
{

if ( WSAGetLastError() != WSA_IO_PENDING )
{
lpIoCtxt->nWaitIO = 0;


//if ( lpIoCtxt->wsabuf.buf[0] == 0xC1 )
//{
// LogAdd("(%d)WSASend(%d) failed with error [%x][%x] %d %s ", __LINE__, aIndex, (BYTE)lpIoCtxt->wsabuf.buf[0],
// (BYTE)lpIoCtxt->wsabuf.buf[2], WSAGetLastError(), Obj[aIndex].Ip_addr);
//}
//else if ( lpIoCtxt->wsabuf.buf[0] == 0xC2 )
//{
// LogAdd("(%d)WSASend(%d) failed with error [%x][%x] %d %s ", __LINE__, aIndex, (BYTE)lpIoCtxt->wsabuf.buf[0],
// (BYTE)lpIoCtxt->wsabuf.buf[3], WSAGetLastError(), Obj[aIndex].Ip_addr);
//}
CloseClient(aIndex);
LeaveCriticalSection(&criti);
return false;
}
}
else
{
lpPerSocketContext->dwIOCount ++;
}


lpIoCtxt->nWaitIO = 1;
LeaveCriticalSection(&criti);
return true;
}


datarecv del launcher

PMSG_FILESERVERINFO* lpMsg = (PMSG_FILESERVERINFO*)lpRecv;
   lpMsg->FtpId <- Datos corruptos
   lpMsg->FtpPass <- Datos corruptos
   return;

Code: [Select]
bool CConnection::DataRecv() // OK
{
int count=0,size=0,result=0;
char tes[255];
if((result=recv(this->m_socket,(char*)&this->m_RecvBuff[this->m_RecvSize],(MAX_BUFF_SIZE-this->m_RecvSize),0)) == SOCKET_ERROR)
{
if(WSAGetLastError() == WSAEWOULDBLOCK)
{
return 1;
}
else
{
//gLog.Output(LOG_DEBUG,GetEncryptedString(4),WSAGetLastError());
this->Disconnect();
return 0;
}
}

this->m_RecvSize += result;

if(this->m_RecvSize < 4)
{
return 1;
}

BYTE header,head;

while(true)
{
if(this->m_RecvBuff[count] == 0xC1)
{
header = this->m_RecvBuff[count];
size = this->m_RecvBuff[count+1];
head = this->m_RecvBuff[count+2];
}
else if(this->m_RecvBuff[count] == 0xC2)
{
header = this->m_RecvBuff[count];
size = MAKEWORD(this->m_RecvBuff[count+2],this->m_RecvBuff[count+1]);
head = this->m_RecvBuff[count+3];
}
else
{
//gLog.Output(LOG_DEBUG,GetEncryptedString(5),this->m_RecvBuff[count]);
this->Disconnect();
return 0;
}

if(size < 4 || size > MAX_BUFF_SIZE)
{
//gLog.Output(LOG_DEBUG,GetEncryptedString(6),header,size,head);
this->Disconnect();
return 0;
}

if(size <= this->m_RecvSize)
{
if(header == 0xC1)
{
int Encrypt = 0;

size = m_RecvBuff[0+1];
m_RecvBuff[0+2] ^= Encrypt;
head = m_RecvBuff[0+2];
//PacketDecryptData(&this->m_RecvBuff[count+3],(size-3),this->m_RecvBuff[count+2]);
//head = this->m_RecvBuff[count+3];
}
else
{
//PacketDecryptData(&this->m_RecvBuff[count+4],(size-4),this->m_RecvBuff[count+3]);
//head = this->m_RecvBuff[count+4];
}

this->wsProtocolCore(head,&this->m_RecvBuff[count],size);

count += size;
this->m_RecvSize -= size;

if(this->m_RecvSize <= 0)
{
break;
}
}
else
{
if(count > 0 && this->m_RecvSize > 0 && this->m_RecvSize <= (MAX_BUFF_SIZE-count))
{
memmove(this->m_RecvBuff,&this->m_RecvBuff[count],this->m_RecvSize);
}

break;
}
}

return 1;
}

mi pregunta es el DataRecv ¿como deberia ir el codigo igual o diferente?
por que los datos me llegan de forma currupta


Solo usuarios registrados pueden comentar y agradecer, Logueate o Registrate


 

Related Topics

  Subject / Started by Replies Last post
3 Replies
1208 Views
Last post December 25, 2016, 12:49:58 PM
by ZabiinoOo
0 Replies
656 Views
Last post September 17, 2017, 06:49:43 PM
by Peluuca
3 Replies
1136 Views
Last post October 30, 2017, 11:46:17 PM
by keikurono
3 Replies
2206 Views
Last post September 26, 2019, 01:36:16 PM
by DaiveSN
0 Replies
263 Views
Last post January 26, 2021, 02:23:56 PM
by hamilton08