Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void func_start(int sockfd)
- {
- string user = usernames[sockfd];
- if (sockets.find(user) == sockets.end())
- {
- writeline(sockfd,"Nao esta feito o login.");
- //func_logout(sockfd);
- return;
- }
- if(verifica_admin(sockfd)==1) //e admin
- {
- initDB();
- int total, total_anterior, velocidade, forma, horse_id;
- PGresult* corrida = executeSQL("SELECT * FROM corrida ORDER BY cod DESC");
- int race_cod = atoi(PQgetvalue(corrida, 0, 0)); //ver a corrida ativa, a mais recente
- PGresult* cavalos = executeSQL("SELECT * FROM inscricao WHERE cod='"+intToString(race_cod)+"'");
- PGresult* res;
- for (int row = 0; row < PQntuples(cavalos); row++) //poe pontuacao a zero
- {
- total=0;
- executeSQL("INSERT INTO cavalo (pontuacao) VALUES '"+intToString(total)+"'");
- }
- int race_laps = atoi(PQgetvalue(corrida, 0, 2));
- srand (time(NULL));
- for (int lap = 0; lap < race_laps; lap++)
- {
- for (int row = 0; row < PQntuples(cavalos); row++)
- {
- forma=atoi(PQgetvalue(cavalos, row, 3));
- horse_id=atoi(PQgetvalue(cavalos, row, 1));
- res=executeSQL("SELECT * FROM cavalo");
- velocidade=atoi(PQgetvalue(res, row, 2));
- total_anterior=atoi(PQgetvalue(res, row, 3));
- total=total_anterior+(forma/100)*velocidade*((rand()%130+70)/100);
- executeSQL("UPDATE cavalo SET pontuacao ='"+intToString(total)+"' WHERE id = '"+intToString(horse_id)+"'");
- }
- //mostrar ordem dos cavalos em cada volta
- res=executeSQL("SELECT nome FROM cavalo JOIN inscricao USING (id) WHERE cod='"+intToString(race_cod)+"' ORDER BY pontuacao DESC");
- writeline(sockfd, "\nVolta '"+intToString(lap+1)+"'");
- for (int n=1; n < PQntuples(cavalos)+1; n++)
- {
- string cav = PQgetvalue(res, n-1, 0);
- writeline(sockfd, "'"+intToString(n)+"'-'"+cav+"'");
- broadcast(sockfd, "'"+intToString(n)+"'-'"+cav+"'");
- }
- }
- //dizer o cavalo vencedor e pagar a quem ganhou a aposta
- }
- else //quando não é admin
- {
- writeline(sockfd,"Nao tem autorizacao.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement