[Help]Locator in C++/Packet 9C42
I'm working in my locator using C++, so i finish them but i don't know if will work, i copy the source of Hare and converte to C++ in my style, so the packet stuff to build the server list :
Code:
void Tokenize(const string& str,
vector<string>& tokens,
const string& delimiters = " ")
{
// Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
string ToLower( char* szString )
{
char szBuffer[256];
memcpy( szBuffer, szString, strlen( szString ) );
szBuffer[ strlen( szString ) ] = '\x00';
for( unsigned i = 0; i < strlen( szBuffer ); i++ )
{
if( szBuffer[i] > 64 && szBuffer[i] < 91 )
{
szBuffer[i] += 32;
}
}
string sReturn = szBuffer;
return sReturn;
}
Code:
void BuildServerList( void )
{
/* Build server List */
CPacket *pPacket = CPacket::CreatePacket( MPV_DECRYPT, 0x9C42 );
/* DO PACKTE STUFF */
int pCount = 1, pSize = 83;
int total = 91;
vector<string> tokens;
Tokenize( g_mConfig.sIP, tokens, "." );
BYTE ServerType;
string svtype = ToLower( (char*)g_mConfig.sServerType.c_str() );
if( !strcmp( svtype.c_str(), "match" ) )
{
ServerType = 1;
}
else if( !strcmp( svtype.c_str(), "clan" ) )
{
ServerType = 2;
}
else if( !strcmp( svtype.c_str(), "test" ) )
{
ServerType = 3;
}
else if( !strcmp( svtype.c_str(), "developer" ) )
{
ServerType = 4;
}
else
{
ServerType = 2;
}
pPacket->WriteInt( 91 );
pPacket->WriteInt( 83 );
pPacket->WriteInt( 1 );
pPacket->WriteByte( atoi( tokens[0].c_str() ) );
pPacket->WriteByte( atoi( tokens[1].c_str() ) );
pPacket->WriteByte( atoi( tokens[2].c_str() ) );
pPacket->WriteByte( atoi( tokens[3].c_str() ) );
pPacket->WriteByte( atoi( tokens[0].c_str() ) );
pPacket->WriteByte( atoi( tokens[1].c_str() ) );
pPacket->WriteByte( atoi( tokens[2].c_str() ) );
pPacket->WriteByte( atoi( tokens[3].c_str() ) );
pPacket->WriteInt( (int)g_mConfig.wPort );
pPacket->WriteByte( ServerType ); // sv type
pPacket->WriteShort( (short)g_mConfig.nServerCapacity ); // sv capacity
pPacket->WriteShort( (short)g_nPlayerCount ); // players count
pPacket->WriteByte( ServerType ); // sv type
pPacket->WriteByte( 1 ); // DON't TOUCH THIS
pPacket->WriteString( (char*)g_mConfig.sServerName.c_str(), false );
/* AE */
nPacketBuffer = pPacket->m_nIndex;
pPacketBuffer = new char[nPacketBuffer];
ZeroMemory( pPacketBuffer, nPacketBuffer );
pPacket->FinalizePacket( pPacketBuffer );
Log( "Montagem do packet principal finalizada, tamanho : %d", nPacketBuffer );
delete pPacket;
}
nPacketBuffer, pPacketBuffer its global var
atoi( tokens[0].c_str() ) is like string.Split in C#
i test and not work ... so anyone can help me ?
Re: [Help]Locator in C++/Packet 9C42
pPacket->WriteByte( atoi( tokens[0].c_str() ) );
pPacket->WriteByte( atoi( tokens[1].c_str() ) );
pPacket->WriteByte( atoi( tokens[2].c_str() ) );
pPacket->WriteByte( atoi( tokens[3].c_str() ) );
pPacket->WriteByte( atoi( tokens[0].c_str() ) );
pPacket->WriteByte( atoi( tokens[1].c_str() ) );
pPacket->WriteByte( atoi( tokens[2].c_str() ) );
pPacket->WriteByte( atoi( tokens[3].c_str() ) );
What is that adding to the packet, because that does not look right.
and what does this do?
pPacket->FinalizePacket( pPacketBuffer );
Re: [Help]Locator in C++/Packet 9C42
Quote:
Originally Posted by
Raven0123
pPacket->WriteByte( atoi( tokens[0].c_str() ) );
pPacket->WriteByte( atoi( tokens[1].c_str() ) );
pPacket->WriteByte( atoi( tokens[2].c_str() ) );
pPacket->WriteByte( atoi( tokens[3].c_str() ) );
pPacket->WriteByte( atoi( tokens[0].c_str() ) );
pPacket->WriteByte( atoi( tokens[1].c_str() ) );
pPacket->WriteByte( atoi( tokens[2].c_str() ) );
pPacket->WriteByte( atoi( tokens[3].c_str() ) );
What is that adding to the packet, because that does not look right.
and what does this do?
pPacket->FinalizePacket( pPacketBuffer );
I assume the WriteByte calls write the IP address to the packet, and the FinalizePacket call seems to fill a buffer with the finalized packet. That would probably involve calculating the checksum at that point, too.