• Welcome to Valhalla Legends Archive.
 
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - brew

#1
Quote from: option on May 04, 2011, 02:24 PM
Also, anytime I've needed to cast something, I've now realized that I was doing it c-style? I.e.
struct Arg *arg = (struct Arg *) malloc(sizeof(struct Arg));
void *ptr;
ptr = (struct Arg *) arg;

That's not C style.  C implicitly casts void * types and C++ does not.
In C++, you must explicitly cast the return of malloc, for example.  This is the single language quirk that prevents C from being a true subset of C++.

Quote from: option on May 04, 2011, 02:24 PM
const char *c = "text";
char *str = const_cast<char *> (c);
cout << str << '\n';

This is a bad example of casting.  Couldn't you come up with anything else?
Because of your novice status, I'm concerned you might actually try to cast immutable strings to char *, and end up having your program crash and burn at runtime instead of giving an informative error at compile time.  Just don't do it.  Always practice const correctness.


Have you considered reading a book on C++ yet?  All of these questions would have been answered and more.  Asking on a forum should be reserved for problems a bit less trivial.
#2
Quote from: Ocdized on May 07, 2011, 05:00 AM
- I am not here to live up to your expectations, and I don't expect you to live up to mine.

What are our expectations?
#3
Kare wa Okotte Iru Toki, Ore no Joe ga Konna ni Kawaii Wake ga Nai

Quote from: Joex86] link=topic=18271.msg185150#msg185150 date=1303784707]
Best you could come up with to not look like an idiot? Too bad you still look like an idiot.
O.K., I'll entertain you. Detail how I "look like an idiot" when you're the one attending CC.
#4
He's so cute when he's mad!
#5
http://nyan.cat/

By the way, that toast cat isn't the original. The song itself was a meme on nicovideo for quite some time.

Quote from: Joex86] link=topic=18271.msg185123#msg185123 date=1303505066]
Nyan nyan, nyan nyan, ni hao nyan! Gojasu derishashu dekaruchaa!
Joe no aho.
I believe "ni hao" is Chinese, and somehow you misspelled the romanization of "goyasu". Even then, your phrase makes no sense. "Ease your loveliness magical teaa"? Way to go.
#6
Quote from: Invert on May 25, 2010, 03:54 PM
These bots can be used for gorilla marketing purposes.

Uhhhhh... no offense, but who's going to buy a gorilla?..
#7
Just an interjection while you're on this topic, you should make sure you do things right with endianness the first time around to avoid lots of problems. I never properly did a packet buffer/debuffer, and I used all kinds of hacks in my bots, such as appending a character to a string by doing something like *(unsigned short *)(str + strlen(str)) = '\', which turned it into a disaster when I went to compile for SPARC.
#8
/WHOAMI -- Introductions / Re: SoupDoGG
May 03, 2010, 10:12 AM
because he's a mothafukkin' Dee Oh Double G, you see?

Showin' much flex when it's time to wreck a mic
Pimpin' hoes and clockin' a grip like my name was Dolomite
Yeah, and it don't quit, I think they in the mood
For some motherfuckin' G shit
#9
Quote from: Hdx on March 29, 2010, 03:22 AM
btw, I was waiting for brew to correct himself, but the Length in the packet Header INCLUDES the fucking header!

Yes. Wow... I screwed up twice in the same post. I've forgotten a bunch about the BNCS protocol over the years. It makes me feel pretty bad that I'm giving this guy bad advice, thanks for pointing that out though, Hdx.

Oh well, who cares? Bnet2 is where it's at! :P
This guy is just probably trying to make a D2-run "clientless" bot in order to sell items, like the thousands of others....
#10
Quote from: Trunning on March 28, 2010, 11:02 PM
@Brew
Removed the break, that was there from earlier experimentation, the if statement was in a while loop. And I'm still not receving anything with your code.

Ooops, my mistake!
Remove the -4 from the third parameter of the second send(). That should do it.
#11
This thread just went full retard.

It's mostly rabbit's fault for egging xpeh on, though, as any vL regular should know xpeh has done pretty much nothing but troll since he's been here. I get a mild squeak-y vibe from him (also note his use of python), but it's obvious he's not, because squeak would never use a 4chan meme in a post.
#12
#pragma comment(lib, "Ws2_32.lib")
#include <windows.h>
#include <winsock.h>
#include <string>
#include <iostream>
using namespace std;

int main(){
struct SID_AUTH_INFO {
BYTE   Header;
BYTE   MsgID;
WORD   wLen;
DWORD   ProtocolID;
DWORD   PlatformID;
DWORD   ProductID;
DWORD   VerByte;
DWORD   ProductLang;
DWORD   LocalIP;
DWORD   TimeZone;
DWORD   LocaleID;
DWORD   LangID;
char   CountryAbr[4];
char   Country[10];
} Packet;
 
Packet.Header      = 0xFF;
Packet.MsgID      = 0x50;
Packet.ProtocolID   = 0x0;
Packet.PlatformID   = 'IX86';
Packet.ProductID   = 'D2DV';
Packet.VerByte      = 0x0D;
Packet.ProductLang   = 0;
Packet.LocalIP      = inet_addr("192.168.1.100");
Packet.TimeZone      = 600;
Packet.LocaleID      = 0;
Packet.LangID      = (DWORD)GetUserDefaultLangID();
Packet.wLen         = sizeof(SID_AUTH_INFO) - 4;
strcpy(Packet.CountryAbr, "Aus");
strcpy(Packet.Country, "Australia");
/*int size = sizeof((Packet.MsgID) & (Packet.ProtocolID) & (Packet.PlatformID) & (Packet.ProductID) & (Packet.VerByte) & (Packet.ProductLang) & (Packet.LocalIP) & (Packet.TimeZone) & (Packet.LocaleID) & (Packet.LangID) );
DWORD Pre = 0x01;*/

BYTE PingPacket[8];

int con;
WSADATA wsaData;

WSAStartup(MAKEWORD(2,0), &wsaData);

LPHOSTENT host;

host = gethostbyname("useast.battle.net");

if (!host)
{
 MessageBox(NULL, "Host error", "", MB_OK);
 WSACleanup();
 return 0;
}

SOCKET theSocket;

theSocket = socket(AF_INET,
 SOCK_STREAM,
 IPPROTO_TCP);

if (theSocket == INVALID_SOCKET)
{
 MessageBox(NULL, "theSocket bad...", "", MB_OK);
 WSACleanup();
 return 0;
}

SOCKADDR_IN info;

info.sin_family = AF_INET;
info.sin_addr = *((LPIN_ADDR)*host->h_addr_list);
info.sin_port = htons(6112);

con = connect(theSocket, (LPSOCKADDR)&info, sizeof(info));

if (con == SOCKET_ERROR)
{
 MessageBox(NULL, (LPCSTR)WSAGetLastError(), "", MB_OK);
 WSACleanup();
 return 0;
}

cout << "Sending 0x01...\n";
con = send(theSocket, "\x01", 1, NULL); //look at this, you're sending _1_ byte. nothing more.
if (con > 0){
cout << con << " bytes sent\n";
} else {
cout << "Nothing sent!\n";
}

cout << "Sending 0x50...\n";
con = send(theSocket, (const char*)&Packet, sizeof(SID_AUTH_INFO) - 4, NULL);
if ( con > 0 ){
  cout << con << " bytes sent\n";
} else {
  cout << "Nothing sent!\n";
}

con = recv(theSocket, PingPacket, sizeof(PingPacket), NULL);
if (con > 0){
cout << "Ping cookie: " << *(unsigned __int32 *)(PingPacket + 4);
break; //what does break; do here, in an if statement?
}

// for testing purposes
char n;
cin >> n;
closesocket(theSocket);
return 0;
}


I feel that I have made myself more than perfectly clear in the previous posts. Even after observing the logon sequence for yourself via a packet capture device, it seems you've failed to grasp the concept of what is supposed to be sent and what is supposed to be received.
Are you entirely certain that you have a solid grasp on coding with C/++?

@rabbit: I don't see what's wrong with his method of packet construction. If he didn't include the header with the actual packet's struct, it would work out nicely. In fact, this is the way Blizzard coded the packet construction in their batle.snp (not with a packet buffer, *gasp*)
#13
Quote from: Trunning on March 28, 2010, 01:41 AM
I'm not new to computers or C++, just combining C++ and Battle.net.

And I've got Wireshark already. I checked what the client Diablo 2 sent, and then my program, the start is different. I was hoping someone would tell me what I'm doing wrong.

Well, in your latest rendition of your code, you seemed to have omitted the size field of the header entirely. The length is a 16 little-endian int which is equal to the length of the data you're sending, minus the size of the standard BNCS header, which is 4. In other words


Packet.wLen         = sizeof(SID_AUTH_INFO);


is wrong.

Why are you still doing that, you said you fixed it in your earlier post? You don't get any data because it's expecting 4 more bytes than you're sending it.


P.S.
You really don't that call to bind(). That socket is already 'bound' to that connection.
#14
Quote from: Trunning on March 27, 2010, 09:08 PM
Based on everything you said I changed as much as I could. I'm still not getting any data back.

...
DWORD Pre = 0x01;
...



Quote from: brew on March 27, 2010, 08:40 AM
note that a single identification byte of 0x01

Also, keep in mind that the response is an 0x25 packet with the standard BNCS header, that just happens to contain a single dword of the ping value.

I strongly suggest you generalize your code more.
#15
Quote from: Trunning on March 27, 2010, 03:25 AM
Basically I'm stuck at receiving, I'm not sure if I have to put the pingval in a struct with the header, msgid and length. Or if I'm even receiving correctly, but if I'm doing anything wrong help is appreciated.

So if you can steer me in the right direction, I'd appreciated that.

#pragma comment(lib, "Ws2_32.lib")
#include <windows.h>
#include <winsock.h>
#include <string>
#include <iostream>
using namespace std;

int main(){
  WSADATA wsaData;

  WSAStartup(MAKEWORD(2,0), &wsaData);

  LPHOSTENT host;

  host = gethostbyname("asia.battle.net");

  if (!host)
  {
     MessageBox(NULL, "Host error", "", MB_OK);
     WSACleanup();
     return 0;
  }

  SOCKET theSocket;
  SOCKET theBnet;

  theSocket = socket(AF_INET,
                 SOCK_STREAM,
                 IPPROTO_TCP);

  theBnet = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

  if (theSocket == INVALID_SOCKET)
  {
     MessageBox(NULL, "theSocket bad...", "", MB_OK);
     WSACleanup();
     return 0;
  }

  if (theBnet == INVALID_SOCKET)
  {
  MessageBox(NULL, "Bnet socket bad...", "", MB_OK);
  WSACleanup();
  return 0;
  }

  SOCKADDR_IN info;

  info.sin_family = AF_INET;
  info.sin_addr = *((LPIN_ADDR)*host->h_addr_list);
  info.sin_port = htons(6112);

  int con;
  con = connect(theSocket, (LPSOCKADDR)&info, sizeof(info));

  if (con == SOCKET_ERROR)
  {
     MessageBox(NULL, (LPCSTR)WSAGetLastError(), "", MB_OK);
     WSACleanup();
     return 0;
  }

  struct SID_AUTH_INFO {
     BYTE   Header;
     BYTE   MsgID;
     WORD   wLen;
     DWORD   ProtocolID;
     DWORD   PlatformID;
     DWORD   ProductID;
     DWORD   VerByte;
     DWORD   ProductLang;
     DWORD   LocalIP;
     DWORD   TimeZone;
     DWORD   LocaleID;
     DWORD   LangID;
     char   CountryAbr[4];
     char   Country[10];
  } Packet;
 
  Packet.Header      = 0xFF;
  Packet.MsgID      = 0x50;
  Packet.wLen         = sizeof(SID_AUTH_INFO);
  Packet.ProtocolID   = 0x0;
  Packet.PlatformID   = '68XI';
  Packet.ProductID   = 'DV2D';
  Packet.VerByte      = 0x0D;
  Packet.ProductLang   = 0;
  Packet.LocalIP      = inet_addr("192.168.1.100");
  Packet.TimeZone      = 600;
  Packet.LocaleID      = 0;
  Packet.LangID      = (DWORD)GetUserDefaultLangID();
  strcpy(Packet.CountryAbr, "Aus");
  strcpy(Packet.Country, "Australia");

  DWORD PingVal;

  bind(theBnet, (LPSOCKADDR)&info, sizeof(info));

  cout << "Sending 0x50... " << send(theSocket, (const char*)&Packet, sizeof(SID_AUTH_INFO), NULL) << " bytes sent\n\n";

  recv(theBnet, (char *)&PingVal, sizeof(PingVal), NULL);

  cout << PingVal;

  // for testing purposes
  char n;
  cin >> n;
  closesocket(theBnet);
  closesocket(theSocket);
  return 0;
}


Lots of problems here.
The first thing that jumped out at me was the fact that your packet IDs are backwards... why? 'VD2D', '68XI', etc. The ill-gotten advice to write IDs backwards originated from the fact that nearly all bot 'developers' used VB6, and inserted that data as a binary string. You obviously don't do this since it's stored in that struct little-endian (I assume you're using a little-endian platform).
The next problem - you don't ever send the data! Before doing that, however, note that a single identification byte of 0x01 with no header of any sort must be sent after connection and before all other battle.net traffic.
Also, your size parameter is wrong. It includes the length of the header (4), and the length of the strings are not usually constant. You're just getting away with it for this packet because there's no variation from logon to logon.
Why are you recving on a different socket? theBnet is not in the connected state.



You might want to look into a basic socket tutorial.