• Welcome to Valhalla Legends Archive.
 

Sample C/C++ BNLS Client

Started by Mephisto, October 04, 2004, 09:33 PM

Previous topic - Next topic

Mephisto

Does anyone know where I might attain a sample BNLS client coded in C/C++?  Or perhaps an open source bot which uses BNLS (C/C++; not VB, thanks).

Spht

Quote from: Mephisto on October 04, 2004, 09:33 PMDoes anyone know where I might attain a sample BNLS client coded in C/C++?

Skywing wrote SNLS with VC++ 7.  It's "a simple demonstration of using BNLS's SNLS functions to check NLS style logins."  Is that the kind of thing you were looking for?

Quote from: Mephisto on October 04, 2004, 09:33 PMOr perhaps an open source bot which uses BNLS (C/C++; not VB, thanks).

Not that I know of.  The protocol is fairly uncomplicated and well documented, so I doubt anyone bothered to publish their source code for it.

Mephisto

#2
Well, I began working on the connection to BNLS, but I ran into some problems after sending packet 0x01; BNLS wasn't responding.  I'm guessing it's some minor error, which is why I wanted to look through some source code.  SNLS would probably be good if I could view the source code to it, but I doubt the source will ever become avaliable.

drivehappy


Blaze

Quote from: drivehappy on October 04, 2004, 11:55 PM
I don't know if you saw this or not, but it might be the problem: http://forum.valhallalegends.com/phpbbs/index.php?topic=8988.0

That problem occured due to the bnls server he was connecting to was down.
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

UserLoser.

Quote from: Mephisto on October 04, 2004, 10:11 PM
Well, I began working on the connection to BNLS, but I ran into some problems after sending packet 0x01; BNLS wasn't responding.  I'm guessing it's some minor error, which is why I wanted to look through some source code.  SNLS would probably be good if I could view the source code to it, but I doubt the source will ever become avaliable.

Show some code, maybe you're doing recv wrong or your client was/is totally confused and BNLS was actually responding

Mephisto

while (connected)
{
int buflen = 0;
int recvlen = recv(s, buffer + buflen, sizeof(buffer) - buflen, 0);

if (!recvlen || recvlen == SOCKET_ERROR)
{
cout << "BNLS has closed the connected!" << endl;
cout << "Exiting..." << endl;
Sleep(1000);
}

buflen += recvlen;

while ((int)buflen >= 3 && connected)
{
packetid = buffer[2];
packetlen = *(unsigned short *)(buffer + 0);
memcpy(packetdata, buffer, packetlen);

switch(packetid)
{
case 0x01:
cout << "Received packet 0x01 from BNLS!" << endl;
break;
}
}
}


The Sleep() call was for debugging...And I know it's sending the packet to BNLS/connected because send works.

UserLoser.

#7
Is recvlen ever 0, or does it ever print "BNLS has closed the connected!"?  Btw, at the end of your while loop you should put a message loop so it doesn't eat up your cpu usage.  Instead of Sleep(1000), you could put getch(), which'll wait until the user hits a key

dxoigmn

#8
Looks like buflen is being reset to 0 each iteration of the first while loop thereby overwriting your buffer everytime you recv.

Mephisto

Quote from: dxoigmn on October 05, 2004, 04:49 PM
Looks like buflen is being reset to 0 each iteration of the first while loop thereby overwriting your buffer everytime you recv.

Isn't that the point?  You don't want to keep the old data when you receive new data.  If you wanted this you could always store it somewhere before the loop reiterates.

dxoigmn

#10
Quote from: Mephisto on October 05, 2004, 04:59 PM
Quote from: dxoigmn on October 05, 2004, 04:49 PM
Looks like buflen is being reset to 0 each iteration of the first while loop thereby overwriting your buffer everytime you recv.

Isn't that the point?  You don't want to keep the old data when you receive new data.  If you wanted this you could always store it somewhere before the loop reiterates.

Then what is the point of buflen?  It will always equal 0 or recvlen.  So basically you're code can be condensed into:


while (connected)
{
int recvlen = recv(s, buffer, sizeof(buffer), 0);

if (!recvlen || recvlen == SOCKET_ERROR)
{
cout << "BNLS has closed the connected!" << endl;
cout << "Exiting..." << endl;
Sleep(1000);
}

while ((int)recvlen >= 3 && connected)
{
packetid = buffer[2];
packetlen = *(unsigned short *)(buffer + 0);
memcpy(packetdata, buffer, packetlen);

switch(packetid)
{
case 0x01:
cout << "Received packet 0x01 from BNLS!" << endl;
break;
}
}
}


Do you see what I'm trying to get at now?  The above code doesn't seem useful at all yet that is exactly what you're orginal code is doing.  If you were to move int buflen = 0 out of the first while, then you're code should work.  However, you need to decrement buflen by the length of data you parse in your switch.

Edit: Also, make sure buflen >= packetlen in that second while loop before doing that memcpy.

Mephisto