#include "main.h" #include "../../Servers/src/CompiledPacket.h" #include "../../Servers/src/Utility.h" #include "../../Servers/src/NetServer.h" #include "../../Servers/src/GWLPLog.h" int expecting=0; //0=computer info packet for hashing unsigned char compHash[32]; unsigned char secretHash[32]; unsigned long loginAttempts=0; unsigned char owns[3]; CompiledPacket poData; void SendAuth(); int Authorization(DATA *d) { //Looking for the computer info so we can hash it if(expecting==0) { if(!d->encrypted) { Util::Hash(d->data,compHash,d->dataSize-20); expecting++; } } //Looking for an @ symbol so we know when the user is logged in else if(expecting==1) { if(!d->encrypted) { //check if the current data is the login packet char email[2]={'@',0x00}; for(int i=0; idataSize-2; i++) { if(memcmp(email,&d->data[i],2)==0 && (d->dataSize<300 && d->dataSize>39) && !d->encrypted) { expecting++; return 0; } } } } //Looking for the start of the character selection stream if(expecting==2 && d->encrypted) { //Make sure the user's login didn't fail if(d->dataSize<40 && Read_uShort(d->data)!=0) { expecting--; } char sig1[2]={0x07,0}; //Looking for the start of the character selection data for(int i=0; idataSize-4; i++) { if(memcmp(d->data+i,sig1,2)==0) { memcpy(&loginAttempts,d->data+i+2,4); expecting++; break; } } } if(expecting==3 && d->encrypted) { poData.Add(d->data,d->dataSize,false); } //Looking for the account permissions data =) if(expecting==3 && !d->encrypted) { //Check all data for the signature unsigned char sig2[6]={0x11,0,0,0,0,0}; memcpy(sig2+2,&loginAttempts,4); int ds=0; unsigned char *pdata=poData.GetString(&ds); for(int i=0; i=ds*0.5) { int key=5; //Extract needed data memcpy(owns,pdata+i+14,1);//Campaigns memcpy(owns+1,pdata+i+24,1);//EotN expansion //Compile our secret signature for hashing CompiledPacket pck(true); pck.AddByte(0x14^key); pck.Fill(0,13); pck.AddByte(owns[0]); pck.Fill(0,9); pck.AddByte(owns[1]); pck.Add(compHash,32,false); int ds=0; unsigned char *shData=pck.GetString(&ds); Util::Hash(shData,secretHash,ds); return -1; } } poData.Clear(); } //printf("%u\n",expecting); return 0; } void SendAuth() { //Compile the data block CompiledPacket pck(true); pck.Add(compHash,32,false); pck.AddByte(owns[0]^2); pck.AddByte(owns[1]^2); for(int i=0; i<32; i++) { pck.AddByte(compHash[i]^owns[1-(i%2)]); pck.AddByte(secretHash[i]^owns[0+(i%2)]); } //Open a log we won't really use GWLPLog log; log.Open(".txt",LOG_RELEASE);// //Compile the final packet we will send int ds=0; unsigned char *data=pck.GetString(&ds); CompiledPacket fp(true); fp.AddByte(0xFD); fp.AddByte(ds); fp.Add(data,ds,false); //Get the IP address of the server from either play or proxy char temp[200]; //Load the config files looking for the server IP std::ifstream fin("GWLPBin/play.ini"); if(fin.fail()) { printf("Could not find play.ini!\n"); system("pause"); return; } fin >> temp; fin.close(); if(strcmp(temp,"proxy")==0) { std::ifstream fin2("GWLPBin/proxy.ini"); if(fin2.fail()) { printf("Could not find proxy.ini!\n"); system("pause"); return; } fin2 >> temp; fin2.close(); } //Convert the string version of the IP to a byte array unsigned char serverIP[4]; char *p=strtok(temp,"."); for(int i=0; i<4; i++) { serverIP[i]=(char)atoi(p); p=strtok(0,"."); } //Start up our network client Server *client=new Server; if(client==NULL){return;} if(client->Init(7112,"authclient",serverIP,true,&log)==-1) { printf("Could not make client network system!\n"); system("pause"); return; } if(client->Connect(serverIP)!=0) { printf("Could not connect to remote server. =(\n"); system("pause"); return; } //Send our data to the server NetMessage s; s.networkId=client->GetClientModeId(); s.pData=fp.GetString(&s.dataSize); client->SendData(&s); client->Update(); client->Shutdown(true); delete client; //Message sent printf("Authorization sent!"); }