Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.86 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use Illuminate\Console\Command;
  6. use Reflex\Database\Models\Player as Playerbot;
  7. use Reflex\Database\Models\Match as MatchBot;
  8. use App\ScorePlayer;
  9. use App\Statitems;
  10. use Config;
  11. use DB;
  12. use App\UserGame;
  13. use App\Match;
  14. use App\UserMatch;
  15. use App\GameServer;
  16. use App\ChallengeUser;
  17.  
  18. class PopulateRankings extends Command {
  19.  
  20. /**
  21. * The name and signature of the console command.
  22. *
  23. * @var string
  24. */
  25. protected $signature = 'command:populateRanking';
  26.  
  27. /**
  28. * The console command description.
  29. *
  30. * @var string
  31. */
  32. protected $description = 'Comando para extraer los resultados despues de cada mach de la plataforma ebot';
  33.  
  34. /**
  35. * Create a new command instance.
  36. *
  37. * @return void
  38. */
  39. public function __construct() {
  40. parent::__construct();
  41. }
  42.  
  43. /**
  44. * Execute the console command.
  45. *
  46. * @return mixed
  47. */
  48. public function handle() {
  49.  
  50. $fileRemoteMatch = config('tg.fileRemoteMatch');
  51. $serversEbot = config('tg.serversEbot');
  52.  
  53. foreach ($serversEbot as $server) {
  54. $file = file_get_contents($server . '/' . $fileRemoteMatch);
  55.  
  56. $matchsResult = json_decode(str_replace("'", '"', trim(str_replace('},]', '}]', $file))), true);
  57.  
  58.  
  59. foreach ($matchsResult as $match) {
  60. if ($match["status"] == 13) {
  61. $this->retrieveStatsEbot($match["id"]);
  62. }
  63. }
  64. }
  65. }
  66.  
  67. public function getServerStatus($getMatchIpServer) {
  68. Config::set('database.default', 'ebot');
  69. DB::connection('ebot');
  70. $matchBot = new MatchBot();
  71. $match = $matchBot->where('ip', '=', $getMatchIpServer)->where('enable', '=', 1)->get()->count();
  72. return $match;
  73. }
  74.  
  75. public function retrieveStatsEbot($matchId) {
  76. $getEbotUsers = $this->getEbotUsers($matchId);
  77. $getMatchIpServer = $this->getMatchIpServer($matchId);
  78. $serverRunning = $this->getServerStatus($getMatchIpServer);
  79.  
  80. Config::set('database.default', 'mysql');
  81. DB::connection('mysql');
  82.  
  83.  
  84. $ipExplode = explode(":", $getMatchIpServer);
  85.  
  86. $gameServer = new GameServer();
  87. $getGameServerByIp = $gameServer->getGameServerByIp($ipExplode[0], $ipExplode[1]);
  88.  
  89. $GameServerModel = GameServer::find($getGameServerByIp->id);
  90. if ($GameServerModel->status != 1) {
  91. if ($serverRunning == 0) {
  92. $GameServerModel->status = 0;
  93. $GameServerModel->users_count = 1;
  94. $GameServerModel->password = '';
  95. $GameServerModel->save();
  96. }
  97. }
  98.  
  99. $localMatch = Match::where('ebot_match_id', $matchId)->first();
  100. if ($localMatch) {
  101. if ($serverRunning == 0) {
  102. $localMatch->status = 0;
  103. $localMatch->save();
  104. }
  105. }
  106.  
  107. $Statitems = new Statitems();
  108.  
  109. foreach ($getEbotUsers as $player) {
  110. $user = new UserGame();
  111.  
  112. $steamId = explode(":", $player['steamid']);
  113. if (count($steamId) > 1) {
  114. $getByRemoreId = $user->getByRemoreId($steamId[2]);
  115. } else {
  116. $getByRemoreId = $user->getByRemoreId($steamId[1]);
  117. }
  118.  
  119. // $getByRemoreId = $user->getByRemoreId($player['steamid']);
  120.  
  121. $statsArray = array();
  122. if ($getByRemoreId) {
  123.  
  124.  
  125. $userMatchM = new UserMatch();
  126. $countMatchByUser = $userMatchM->countMatchByUserByStatus($matchId, $getByRemoreId->user_id);
  127. if (count($userMatch) == 0) {
  128. $userMatch->match_id = $matchId;
  129. $userMatch->user_id = $getByRemoreId->user_id;
  130. $userMatch->status = 1;
  131. $userMatch->save();
  132.  
  133.  
  134.  
  135.  
  136. $kills = 0;
  137. $deaths = 0;
  138. $hs = 0;
  139. $ds = 0;
  140. $bm = 0;
  141. $modifyKd = false;
  142. foreach ($player as $key => $attPlayer) {
  143. $getStatByName = $Statitems->getStatByName($key, 1);
  144. if ($getStatByName) {
  145. if ($attPlayer > 0) {
  146. $ScorePlayer = new ScorePlayer();
  147.  
  148. $getScoreUserAndMatch = $ScorePlayer->getScoreUserAndMatch($getByRemoreId->user_id, $matchId, $getStatByName->id)->count();
  149.  
  150. if ($getScoreUserAndMatch == 0) {
  151. if ($getStatByName->id == 40) {
  152. $kills = $attPlayer;
  153. $modifyKd = true;
  154. }
  155. if ($getStatByName->id == 42) {
  156. $deaths = $attPlayer;
  157. $modifyKd = true;
  158. }
  159. if ($getStatByName->id == 45) {
  160. $ds = $attPlayer;
  161. $modifyKd = true;
  162. }
  163.  
  164. if ($getStatByName->id == 44) {
  165. $hs = $attPlayer;
  166. $modifyKd = true;
  167. }
  168. if ($getStatByName->id == 46) {
  169. $bm = $attPlayer;
  170. $modifyKd = true;
  171. }
  172. $ScorePlayer->statitem_id = $getStatByName->id;
  173. $ScorePlayer->value = $attPlayer;
  174. $ScorePlayer->user_id = $getByRemoreId->user_id;
  175. $ScorePlayer->match_id = $matchId;
  176. $ScorePlayer->save();
  177. $statsArray[] = array($getStatByName->id => $attPlayer);
  178. }
  179. }
  180. }
  181. }
  182. if ($modifyKd) {
  183. $scorKill = 0;
  184. $scoreDeath = 0;
  185. $scorHs = 0;
  186. $scoreDs = 0;
  187. $scorebm = 0;
  188. if ($kills != 0) {
  189. $scorKill = $kills * config('tg.coefficient.kill');
  190. }
  191.  
  192. if ($deaths != 0) {
  193. $scoreDeath = $deaths * config('tg.coefficient.death');
  194. }
  195.  
  196. if ($hs != 0) {
  197. $scorHs = $hs * config('tg.coefficient.heads');
  198. }
  199.  
  200.  
  201. if ($ds != 0) {
  202. $scoreDs = $ds * config('tg.coefficient.defuse');
  203. }
  204.  
  205.  
  206. if ($bm != 0) {
  207. $scorebm = $bm * config('tg.coefficient.bomb');
  208. }
  209.  
  210. $score = ($scorKill + $scoreDeath + $scorHs + $scoreDs + $scoreDs + $scorebm) * 10;
  211. $userMatchModel = new UserMatch();
  212.  
  213.  
  214. $getMatchByUser = $userMatchModel->getMatchByUser($userMatch->match_id, $userMatch->user_id);
  215. if ($getMatchByUser->score == 0) {
  216. $getMatchByUser->score = $score;
  217. } else {
  218. $getMatchByUser->score = (($getByRemoreId->score + $score));
  219. }
  220. $getMatchByUser->game_id = 1;
  221. $getMatchByUser->save();
  222.  
  223.  
  224. $getByRemoreId->save();
  225. }
  226. $challengeUser = new ChallengeUser();
  227. $challengeUser->validateChallengeUser($getByRemoreId->user_id, $statsArray);
  228. }
  229. }
  230. }
  231. }
  232.  
  233. public function getMatchIpServer($matchId) {
  234. Config::set('database.default', 'ebot');
  235. DB::connection('ebot');
  236. $matchBot = MatchBot::find($matchId);
  237. return $matchBot->ip;
  238. }
  239.  
  240. public function getEbotUsers($matchId) {
  241.  
  242.  
  243. Config::set('database.default', 'ebot');
  244. DB::connection('ebot');
  245. $players = new Playerbot();
  246. $playersModel = $players->where('match_id', $matchId)->get();
  247.  
  248. $ebotUsers = array();
  249. foreach ($playersModel as $player) {
  250. $ebotUsers[] = $player->toArray();
  251. }
  252.  
  253. return $ebotUsers;
  254. }
  255.  
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement