#include "main.h" std::vector clients; short loginnetworkId=0; short gamenetworkId=0; unsigned long dataBet=0; GWLPLog gLog; void FileServerMonitor(unsigned char* pData, unsigned long dataSize); int main(int argc, char *argv[] ) { short lsPort=0; short gsPort=0; unsigned char serverIP[4]={192,168,1,109}; char ipAddr[30]; if(argc>=4) { //Extract the IP address strcpy(ipAddr,argv[2]); char temp[50]; strcpy(temp,ipAddr); char *p=strtok(temp,"."); for(int i=0; i<4; i++) { serverIP[i]=(char)atoi(p); p=strtok(0,"."); } //Extract the ports lsPort=atoi(argv[3]); gsPort=atoi(argv[4]); } else { cout << "INVALnetworkId ARGUMENTS!" << endl; return -5; } gLog.SetFileHeader("GWLP Proxy","1.0"); gLog.Open("proxy.rtf",LOG_ALL);//LOG_ERRORS | LOG_NOTICES gLog.SetSpecialDefaults(CATEGORY_OPT,SECTION_OPT,SECTION_OPT_OK,SECTION_OPT_FAIL); gLog.SetLevelDefaults(DEBUG_TEXT,WARNING_TEXT,NOTICE_TEXT,ERROR_TEXT,ALWAYS_TEXT); //Start up the server binds Server *loginBind=new Server(6112,"Login Bind",0,false,&gLog); SERVERCONFIG sc; sc.maxConnections=10; sc.notifyOnConnect=true; loginBind->UpdateServerConfig(sc); //Output the file for the login server proxy ip std::ofstream fout("GWLPBin/pip.txt"); char lip[100]; loginBind->GetIpString(lip); fout << lip; fout.close(); unsigned char ip[4]={127,0,0,1}; Server *gameServBind=new Server(6112,"Game Bind",ip,false,&gLog); gameServBind->UpdateServerConfig(sc); while(true) { std::vector::iterator itr; for(itr=clients.begin(); itr!=clients.end(); itr++) { (itr)->client->Update(); } loginBind->Update(); gameServBind->Update(); //Check for updates from the login server bind NetMessage d; while(loginBind->GetNextNetMessage(&d)==0) { if(d.dataSize==CLIENT_CONNECTED) { CLIENT c; c.bind=0; c.NetworknetworkId=d.networkId; loginnetworkId=d.networkId; c.client=new Server(lsPort,"login client",serverIP,true,&gLog); SERVERCONFIG sc2; sc2.maxConnections=10; c.client->UpdateServerConfig(sc2); if(c.client->Connect(serverIP)!=0) { gLog.error("Could not connect to login server!"); //system("pause"); //return -6; delete c.client; c.client=NULL; loginBind->Kick(d.networkId); break; } else { clients.push_back(c); } } else if(d.dataSize==CLIENT_DISCONNECTED) { std::vector::iterator itr; for(itr=clients.begin(); itr!=clients.end(); itr++) { if(itr->NetworknetworkId==d.networkId && itr->bind==0) { delete itr->client; clients.erase(itr); break; } } } else if(d.dataSize>0) { std::vector::iterator itr; for(itr=clients.begin(); itr!=clients.end(); itr++) { if(itr->NetworknetworkId==d.networkId && itr->bind==0) { d.networkId=itr->client->GetClientModeId(); BIT_SET(d.flags,NETMESS_BOOL_DEL); //gLog.debug("Clie Pck: %02X %02X - %u", d.pData[0], d.pData[1], Read_uLong(d.pData+4)); //Output all the requested hashes if (d.pData[1] == 3) { gLog.debug("Requested Hashes"); gLog.debug("----------------"); for(int i=0; iclient->SendData(&d); //log.debug("DB: %u", dataBet); dataBet=0; d.pData=NULL; } } } //---------------------------------------------------------------- //free the memory used by the NetMessage. Deletes the original data. //---------------------------------------------------------------- if(d.pData!=0) delete [] d.pData; } //Check for updates from the game server bind while(gameServBind->GetNextNetMessage(&d)==0) { if(d.dataSize==CLIENT_CONNECTED) { CLIENT c; c.NetworknetworkId=d.networkId; c.bind=1; gamenetworkId=d.networkId; c.client=new Server(gsPort,"game client",serverIP,true,&gLog); SERVERCONFIG sc2; sc2.maxConnections=10; c.client->UpdateServerConfig(sc2); if(c.client->Connect(serverIP)!=0) { gLog.error("Could not connect to game server!"); //system("pause"); //return -7; delete c.client; c.client=NULL; gameServBind->Kick(d.networkId); break; } else { clients.push_back(c); } } else if(d.dataSize==CLIENT_DISCONNECTED) { std::vector::iterator itr; for(itr=clients.begin(); itr!=clients.end(); itr++) { if(itr->NetworknetworkId==d.networkId && itr->bind==1) { delete itr->client; clients.erase(itr); break; } } } else if(d.dataSize>0) { std::vector::iterator itr; for(itr=clients.begin(); itr!=clients.end(); itr++) { if(itr->NetworknetworkId==d.networkId && itr->bind==1) { d.networkId=itr->client->GetClientModeId(); BIT_SET(d.flags,NETMESS_BOOL_DEL); itr->client->SendData(&d); d.pData=NULL; } } } //---------------------------------------------------------------- //free the memory used by the NetMessage. Deletes the original data. //---------------------------------------------------------------- if(d.pData!=0) delete [] d.pData; } for(itr=clients.begin(); itr!=clients.end(); itr++) { while(itr->client->GetNextNetMessage(&d)==0) { if(d.dataSize==CLIENT_DISCONNECTED) { if(itr->bind==0) { loginBind->Kick(itr->NetworknetworkId); } else { gameServBind->Kick(itr->NetworknetworkId); } } else { d.networkId=itr->NetworknetworkId; BIT_SET(d.flags,NETMESS_BOOL_DEL); if(itr->bind==0) { FileServerMonitor(d.pData, d.dataSize); loginBind->SendData(&d); } else { gameServBind->SendData(&d); } d.pData=NULL; } if(d.pData!=0){delete [] d.pData;} } } if(true) { Sleep(1); } } //Clean up delete loginBind; delete gameServBind; gLog.Close(); }