Witam,
na razie mam taki kod
#include <iostream>
#include <winsock2.h>
#include <windows.h>
using namespace std;
struct gg_header {
int type; /* typ pakietu */
int length; /* dlugosc reszty */
}header;
#define GG_WELCOME 0x0001
struct gg_welcome {
int seed; /* klucz szyfrowania hasla */
}welcome;
#define GG_LOGIN60 0x0015
struct gg_login60 {
int uin; /* numer */
int hash; /* hash hasla */
int status; /* status na wjazd */
int version; /* wersja klienta */
char unknown1; /* 0x00 */
int local_ip; /* moje ip */
short local_port; /* port na ktorym slucham */
int external_ip; /* zew. ip */
short external_port; /* zew. port */
char image_size; /* maks. rozm. grafiki z kb */
char unknown2; /* 0xbe */
char description[]; /* opis / nie musi byc */
int time; /* czas / nie musi byc */
}login;
#define GG_NEW_STATUS 0x0002
struct gg_new_status {
int status; /* na jaki zmienic */
char description[]; /* opis / nie musi byc */
int time; /* czas / nie musi byc */
}nstatus;
int gg_login_hash(char *password, unsigned int seed)
{
unsigned int x, y, z;
y = seed;
for (x = 0; *password; password++) {
x = (x & 0xffffff00) | *password;
y ^= x;
y += x;
x <<= 8;
y ^= x;
x <<= 8;
y -= x;
x <<= 8;
y ^= x;
z = y & 0x1f;
y = (y << z) | (y >> (32 - z));
}
return y;
}
void clear(struct gg_header *header)
{
header->type = 0;
header->length = 0;
}
int main(int argc, char **argv[])
{
WSADATA wsd;
SOCKET sock;
struct sockaddr_in server;
int numer = 12345;
char *password = "jakies haslo";
if(WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
cout<<"Nie mozna utworzyc WinSocka\r\n";
cout.flush();
return 1;
}
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(sock == INVALID_SOCKET)
{
cout<<"Nie mozna utworzyc gniazda ( "<<WSAGetLastError()<<" )\r\n";
cout.flush();
return 2;
}
server.sin_family = AF_INET;
server.sin_port = htons((u_short)8074);
server.sin_addr.s_addr = inet_addr("91.214.237.11");
cout<<"ip: "<<inet_addr("91.214.237.11")<<"\r\n";
cout<<"port: "<<htons((u_short)8074)<<"\r\n";
cout.flush();
if(connect(sock, (sockaddr *)&server, sizeof(server)) == SOCKET_ERROR)
{
cout<<"Nie mozna sie polaczyc ( "<<WSAGetLastError()<<" )\r\n";
cout.flush();
return 3;
}
clear(&header);
/******* pobieranie seeda *******/
if(recv(sock, (char *)&header, sizeof(header), 0) > 0)
{
if(recv(sock, (char *)&welcome, header.length, 0) > 0)
{
cout<<"seed: "<<welcome.seed<<"\r\n";
cout.flush();
} else {
cout<<"seed failed\r\n";
cout.flush();
}
}
login.uin = numer;
login.hash = gg_login_hash(password, welcome.seed);
login.status = 0x0002;
login.version = 0x20;
login.unknown1 = 0x00;
login.local_ip = 0x00;
login.local_port = 1550;
login.external_ip = 0x00;
login.external_port = 1550;
login.unknown2 = 0xbe;
login.image_size = 256;
//login.description[]
//login.time
/****** logowanie *****/
#define GG_LOGIN_OK 0x0003
#define GG_LOGIN_FAILED 0x0009
clear(&header);
header.type = GG_LOGIN60;
header.length = sizeof(login);
if(send(sock, (char *)&header, sizeof(header), 0) > 0)
{
if(send(sock, (char *)&login, sizeof(login), 0) > 0)
{
clear(&header);
//if(recv(sock, (char *)&header, sizeof(header), 0) > 0)
//{
recv(sock, (char *)&header, sizeof(header), 0);
if(header.type == GG_LOGIN_OK)
{
cout<<"login ok\r\n";
cout.flush();
} else if (header.type == GG_LOGIN_FAILED)
{
cout<<"login failed\r\n";
cout.flush();
} else {
cout<<"wtf?!\r\n";
}
cout<<header.length<<"\r\n";
cout.flush();
printf("0x%x\r\n", header.type);
//}
}
}
closesocket(sock);
WSACleanup();
getchar();
return 0;
}
Mam problem z zalogowaniem się. Dostaję ciągle status 0 zamiast 3 (prawidłowe zalogowanie się) czy nawet 9 (nieprawidłowe zalogowanie). Czy ktoś wie gdzie jest problem ?