Advertisement
Guest User

Untitled

a guest
May 31st, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. void func_start(int sockfd)
  2. {
  3. string user = usernames[sockfd];
  4.  
  5. if (sockets.find(user) == sockets.end())
  6. {
  7. writeline(sockfd,"Nao esta feito o login.");
  8. //func_logout(sockfd);
  9. return;
  10. }
  11.  
  12. if(verifica_admin(sockfd)==1) //e admin
  13. {
  14. initDB();
  15. int total, total_anterior, velocidade, forma, horse_id;
  16. PGresult* corrida = executeSQL("SELECT * FROM corrida ORDER BY cod DESC");
  17. int race_cod = atoi(PQgetvalue(corrida, 0, 0)); //ver a corrida ativa, a mais recente
  18. PGresult* cavalos = executeSQL("SELECT * FROM inscricao WHERE cod='"+intToString(race_cod)+"'");
  19. PGresult* res;
  20.  
  21. for (int row = 0; row < PQntuples(cavalos); row++) //poe pontuacao a zero
  22. {
  23. total=0;
  24. executeSQL("INSERT INTO cavalo (pontuacao) VALUES '"+intToString(total)+"'");
  25. }
  26.  
  27. int race_laps = atoi(PQgetvalue(corrida, 0, 2));
  28. srand (time(NULL));
  29. for (int lap = 0; lap < race_laps; lap++)
  30. {
  31. for (int row = 0; row < PQntuples(cavalos); row++)
  32. {
  33. forma=atoi(PQgetvalue(cavalos, row, 3));
  34. horse_id=atoi(PQgetvalue(cavalos, row, 1));
  35. res=executeSQL("SELECT * FROM cavalo");
  36. velocidade=atoi(PQgetvalue(res, row, 2));
  37. total_anterior=atoi(PQgetvalue(res, row, 3));
  38. total=total_anterior+(forma/100)*velocidade*((rand()%130+70)/100);
  39. executeSQL("UPDATE cavalo SET pontuacao ='"+intToString(total)+"' WHERE id = '"+intToString(horse_id)+"'");
  40. }
  41. //mostrar ordem dos cavalos em cada volta
  42. res=executeSQL("SELECT nome FROM cavalo JOIN inscricao USING (id) WHERE cod='"+intToString(race_cod)+"' ORDER BY pontuacao DESC");
  43.  
  44. writeline(sockfd, "\nVolta '"+intToString(lap+1)+"'");
  45. for (int n=1; n < PQntuples(cavalos)+1; n++)
  46. {
  47. string cav = PQgetvalue(res, n-1, 0);
  48. writeline(sockfd, "'"+intToString(n)+"'-'"+cav+"'");
  49. broadcast(sockfd, "'"+intToString(n)+"'-'"+cav+"'");
  50. }
  51.  
  52. }
  53.  
  54. //dizer o cavalo vencedor e pagar a quem ganhou a aposta
  55.  
  56. }
  57. else //quando não é admin
  58. {
  59. writeline(sockfd,"Nao tem autorizacao.");
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement