Jump to content
DvLrepLay

vc++ putin ajutor

Recommended Posts

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 grafica

Am facut interfata cu un buton "Start" , problema e ca , cand e apasat butonul start serverul porneste dar interfata ramane blocata

private: 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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...