Advertisement
Guest User

Untitled

a guest
May 7th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. //
  2. // !rank
  3. //
  4.  
  5. if( Command == "rank" &&m_GHost->m_AllowRank)
  6. {
  7. string StatsUser = User;
  8.  
  9.  
  10.  
  11. if( !Payload.empty( ) )
  12. StatsUser = Payload;
  13.  
  14.  
  15.  
  16. MYSQL *mysql;
  17. MYSQL_ROW row;
  18. MYSQL_ROW row2;
  19. MYSQL_ROW row3;
  20.  
  21. //string test="";
  22.  
  23.  
  24. unsigned int num_fields;
  25. unsigned int num_rows;
  26. string nameTable[1000];
  27. int counter=0;
  28. int counter2=0;
  29. bool runAlways=true;
  30. string nrOfPlayers="";
  31.  
  32. string CFGFile = "ghost.cfg";
  33.  
  34. // read config file
  35.  
  36. CConfig *CFG=new CConfig();
  37. CFG->Read( CFGFile );
  38.  
  39. string serverName = CFG->GetString( "db_mysql_server", string( ) );
  40. string databaseName = CFG->GetString( "db_mysql_database", string());
  41. string userName = CFG->GetString( "db_mysql_user", string( ) );
  42. string password = CFG->GetString( "db_mysql_password", string( ) );
  43. int portNr = CFG->GetInt( "db_mysql_port", int() );
  44.  
  45. fprintf(stderr, "***%s***\n", serverName.c_str( ));
  46. fprintf(stderr, "***%s***\n", databaseName.c_str( ));
  47. fprintf(stderr, "***%s***\n", userName.c_str( ));
  48. fprintf(stderr, "***%d***\n", portNr);
  49.  
  50. m_GHost->m_CheckDbOn=true;
  51. mysql = mysql_init(NULL);
  52.  
  53. if (NULL == mysql_real_connect(mysql,serverName.c_str( ),userName.c_str( ),password.c_str( ),databaseName.c_str( ),0,NULL,0))
  54. {
  55. fprintf(stderr,"Problem encountered connecting to the database!");
  56. QueueChatCommand("Problem encountered connecting to the database!");
  57. m_GHost->m_CheckDbOn=false;
  58. mysql_close(mysql);
  59.  
  60.  
  61. }
  62.  
  63. if(m_GHost->m_CheckDbOn)
  64. {
  65.  
  66. string record="select score from scores where name='"+StatsUser+"'";
  67.  
  68. if(mysql_real_query(mysql,record.c_str(),record.size())!=0)
  69. {
  70. mysql_error(mysql);
  71.  
  72.  
  73. }
  74. else
  75. {
  76.  
  77. MYSQL_RES *result=mysql_store_result(mysql);
  78. if( result )
  79. {
  80. num_fields = mysql_num_fields(result);
  81.  
  82.  
  83. row = mysql_fetch_row( result );
  84. if(row!=NULL)
  85. m_GHost->m_Experience=row[0];
  86. else
  87. m_GHost->m_Experience="ERROR";
  88.  
  89.  
  90.  
  91. mysql_free_result( result );
  92. }
  93. else
  94. {
  95. if(mysql_field_count(mysql) == 0)
  96. {
  97. num_rows = mysql_affected_rows(mysql);
  98. }
  99. else
  100. {
  101. fprintf(stderr, "Error: %s\n", mysql_error(mysql));
  102.  
  103. }
  104.  
  105.  
  106. }
  107. }
  108.  
  109. string record2="select name,score from scores order by score desc";
  110. if(mysql_real_query(mysql,record2.c_str(),record2.size())!=0)
  111. {
  112. mysql_error(mysql);
  113.  
  114. }
  115. else
  116. {
  117. MYSQL_RES *result2=mysql_store_result(mysql);
  118. if( result2 )
  119. {
  120. num_fields = mysql_num_fields(result2);
  121.  
  122. while ((row2 = mysql_fetch_row(result2)))
  123. {
  124.  
  125.  
  126. nameTable[counter]=row2[0];
  127. counter++;
  128.  
  129.  
  130. }
  131.  
  132.  
  133. mysql_free_result( result2 );
  134. }
  135. else
  136. {
  137. mysql_error(mysql);
  138. }
  139. }
  140.  
  141. string record3="select count(name) from scores";
  142. if(mysql_real_query(mysql,record3.c_str(),record3.size())!=0)
  143. {
  144. mysql_error(mysql);
  145.  
  146. }
  147. else
  148. {
  149. MYSQL_RES *result3=mysql_store_result(mysql);
  150. if( result3 )
  151. {
  152. num_fields = mysql_num_fields(result3);
  153.  
  154. while ((row3 = mysql_fetch_row(result3)))
  155. {
  156.  
  157.  
  158. nrOfPlayers=row3[0];
  159.  
  160. }
  161.  
  162.  
  163. mysql_free_result( result3 );
  164. }
  165. else
  166. {
  167. mysql_error(mysql);
  168. }
  169. }
  170.  
  171. mysql_close(mysql);
  172. if(row!=NULL)
  173. {
  174. std::transform(StatsUser.begin(), StatsUser.end(), StatsUser.begin(), std::tolower);
  175.  
  176. while(runAlways)
  177. {
  178. if(StatsUser==nameTable[counter2])
  179. {
  180. runAlways=false;
  181. counter2=counter2+1;
  182. m_GHost->m_RankPos= UTIL_ToString(counter2);
  183. }
  184. else
  185. {
  186. counter2++;
  187. }
  188. }
  189.  
  190. m_GHost->m_TotalPlayersInDb=nrOfPlayers;
  191.  
  192. //QueueChatCommand("/w Guard /x ***"+StatsUser+"'s stats are: Experience: "+m_GHost->m_Experience.c_str()+".***");
  193. //display wins/losses/total games played
  194.  
  195. if( !StatsUser.empty( ) && StatsUser.size( ) < 16 && StatsUser[0] != '/' )
  196. {
  197. m_PairedDPSChecks.push_back( PairedDPSCheck( Whisper ? User : string( ), m_GHost->m_DB->ThreadedDotAPlayerSummaryCheck( StatsUser ) ) );
  198. runAlways=true;
  199. }
  200. }
  201. else
  202. QueueChatCommand("/w Guard /x "+StatsUser+" User not found in database!");
  203.  
  204. }
  205.  
  206. }
  207.  
  208. //
  209. //!best10
  210. //
  211. if( Command == "best10" &&m_GHost->m_AllowRank )
  212. {
  213. MYSQL *mysql;
  214. MYSQL_ROW row;
  215. string nameTable[1000];
  216. string scoreTable[1000];
  217. int num_fields;
  218. string finalResult="";
  219. int counter=0;
  220.  
  221. string CFGFile = "ghost.cfg";
  222.  
  223. // read config file
  224.  
  225. CConfig *CFG=new CConfig();
  226. CFG->Read( CFGFile );
  227.  
  228. string serverName = CFG->GetString( "db_mysql_server", string( ) );
  229. string databaseName = CFG->GetString( "db_mysql_database", string() );
  230. string userName = CFG->GetString( "db_mysql_user", string( ) );
  231. string password = CFG->GetString( "db_mysql_password", string( ) );
  232. int portNr = CFG->GetInt( "db_mysql_port", int() );
  233.  
  234. fprintf(stderr, "***%s***\n", serverName.c_str( ));
  235. fprintf(stderr, "***%s***\n", databaseName.c_str( ));
  236. fprintf(stderr, "***%s***\n", userName.c_str( ));
  237. fprintf(stderr, "***%d***\n", portNr);
  238.  
  239. m_GHost->m_CheckDbOn=true;
  240.  
  241. mysql = mysql_init(NULL);
  242. if (NULL == mysql_real_connect(mysql,serverName.c_str( ),userName.c_str( ),password.c_str( ),databaseName.c_str( ),0,NULL,0))
  243. {
  244. fprintf(stderr,"Problem encountered connecting to the database!");
  245. QueueChatCommand("Problem encountered connecting to the database!");
  246. m_GHost->m_CheckDbOn=false;
  247. mysql_close(mysql);
  248. }
  249.  
  250. if(m_GHost->m_CheckDbOn)
  251. {
  252.  
  253. string record="select name,score from scores order by score desc";
  254. if(mysql_real_query(mysql,record.c_str(),record.size())!=0)
  255. {
  256. mysql_error(mysql);
  257.  
  258. }
  259. else
  260. {
  261. MYSQL_RES *result=mysql_store_result(mysql);
  262. if( result )
  263. {
  264. num_fields = mysql_num_fields(result);
  265.  
  266. while ((row = mysql_fetch_row(result)))
  267. {
  268.  
  269.  
  270. nameTable[counter]=row[0];
  271. counter++;
  272.  
  273.  
  274. }
  275.  
  276.  
  277. mysql_free_result( result );
  278. }
  279. else
  280. {
  281. mysql_error(mysql);
  282. }
  283. }
  284.  
  285. mysql_close(mysql);
  286.  
  287.  
  288. for(int i=0;i<10;i++)
  289. {
  290. finalResult=finalResult+" "+nameTable[i]+"("+UTIL_ToString(i+1)+")"+"*";
  291. }
  292.  
  293. QueueChatCommand("/w Guard /x *"+finalResult);
  294. counter=0;
  295. }
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement