DvLrepLay Posted February 24, 2012 Report Posted February 24, 2012 Salut , am gasit pe net sursa unui program care emuleaza un server virtual pentru jocul Counter Strike.Cand il fac in vc++ 2010 , console application merge fara nici o problema , dar vreau sa ii fac interfata graficaAm facut interfata cu un buton "Start" , problema e ca , cand e apasat butonul start serverul porneste dar interfata ramane blocataprivate: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { DeschideRedirect(); }void DeschideRedirect(void){ this->textBox4->Text = "Redirectele au fost deschise"; WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData); char msg[MAX_MSG]; char meseg[MAX_MSG]; int rc; int nNumRead; AnsverHDR = new a2shdr_t; fopen_s(&fp, "fakeserver.log", "w"); sprintf_s(hostname, "xxxxx"); // Seteaza hostname sprintf_s(map, "de_dust2"); // Seteaza harta sprintf_s(gamedir, "cstrike"); // Seteaza jocul sprintf_s(gamedescription, "www.xxxxx.ro"); // Seteaza gamename AnsverHDR->musor = '<'; AnsverHDR->hlam = NULL ; AnsverHDR->users = 27; AnsverHDR->maxusers = 32; AnsverHDR->bots = 0; AnsverHDR->type = 'd'; AnsverHDR->os = 'l'; AnsverHDR->password = 0; AnsverHDR->vac = 0; name_sock=socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); sockaddr_in dest_addr; dest_addr.sin_family=AF_INET; dest_addr.sin_port=htons ( PORT ); dest_addr.sin_addr.s_addr = htonl(INADDR_ANY); int server_addr_size=sizeof (server_addr); // defineste server_addr_size rc = bind (name_sock, (sockaddr *) &dest_addr,sizeof(dest_addr)); if(rc<0) { exit(1); } while(1) { memset(msg,0x0,MAX_MSG); memset(meseg,0x0,MAX_MSG); nNumRead = recvfrom(name_sock, msg, MAX_MSG, 0, (sockaddr *) &server_addr, &server_addr_size); if(nNumRead<0) { } for(int i = 4; i < nNumRead; i++) { sprintf_s(meseg, "%s%c",meseg, msg[i] ); } if (msg[4] == A2S_GETUSERS) { } if (strstr(meseg, A2S_INFO)) { } if (strstr(meseg, A2S_INFOOLD)) { } else if (strstr(meseg, A2S_GETCHALLENGE)) { } else if (strstr(meseg, A2S_CONNECT)) { } else { } } fclose(fp);}de la ce poate fi? Multumesc. Quote
TheTime Posted February 24, 2012 Report Posted February 24, 2012 Toate resursele alocate aplicatiei (interfata + cod) tale sunt 'mancate' de bucla infinita while(1), deci interfata ramane blocata pana se opreste codul din spate.Solutia este sa pui codul de sub buton intr-un nou thread, pentru a i se aloca resurse separate. Cum faci asta gasesti pe google. Eu iti recomand sa faci si un buton de stop Quote
R3AL Posted February 24, 2012 Report Posted February 24, 2012 Foloseste un backgroundWorkerCheama functia ta/muta continutul ei in backgroundworker_DoWork iar pentru a-l porni scrii backgroundworker->RunWorkerAsync() Quote