Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Reflex\Database\Models\Player as Playerbot;
- use Reflex\Database\Models\Match as MatchBot;
- use App\ScorePlayer;
- use App\Statitems;
- use Config;
- use DB;
- use App\UserGame;
- use App\Match;
- use App\UserMatch;
- use App\GameServer;
- use App\ChallengeUser;
- class PopulateRankings extends Command {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'command:populateRanking';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Comando para extraer los resultados despues de cada mach de la plataforma ebot';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct() {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle() {
- $fileRemoteMatch = config('tg.fileRemoteMatch');
- $serversEbot = config('tg.serversEbot');
- foreach ($serversEbot as $server) {
- $file = file_get_contents($server . '/' . $fileRemoteMatch);
- $matchsResult = json_decode(str_replace("'", '"', trim(str_replace('},]', '}]', $file))), true);
- foreach ($matchsResult as $match) {
- if ($match["status"] == 13) {
- $this->retrieveStatsEbot($match["id"]);
- }
- }
- }
- }
- public function getServerStatus($getMatchIpServer) {
- Config::set('database.default', 'ebot');
- DB::connection('ebot');
- $matchBot = new MatchBot();
- $match = $matchBot->where('ip', '=', $getMatchIpServer)->where('enable', '=', 1)->get()->count();
- return $match;
- }
- public function retrieveStatsEbot($matchId) {
- $getEbotUsers = $this->getEbotUsers($matchId);
- $getMatchIpServer = $this->getMatchIpServer($matchId);
- $serverRunning = $this->getServerStatus($getMatchIpServer);
- Config::set('database.default', 'mysql');
- DB::connection('mysql');
- $ipExplode = explode(":", $getMatchIpServer);
- $gameServer = new GameServer();
- $getGameServerByIp = $gameServer->getGameServerByIp($ipExplode[0], $ipExplode[1]);
- $GameServerModel = GameServer::find($getGameServerByIp->id);
- if ($GameServerModel->status != 1) {
- if ($serverRunning == 0) {
- $GameServerModel->status = 0;
- $GameServerModel->users_count = 1;
- $GameServerModel->password = '';
- $GameServerModel->save();
- }
- }
- $localMatch = Match::where('ebot_match_id', $matchId)->first();
- if ($localMatch) {
- if ($serverRunning == 0) {
- $localMatch->status = 0;
- $localMatch->save();
- }
- }
- $Statitems = new Statitems();
- foreach ($getEbotUsers as $player) {
- $user = new UserGame();
- $steamId = explode(":", $player['steamid']);
- if (count($steamId) > 1) {
- $getByRemoreId = $user->getByRemoreId($steamId[2]);
- } else {
- $getByRemoreId = $user->getByRemoreId($steamId[1]);
- }
- // $getByRemoreId = $user->getByRemoreId($player['steamid']);
- $statsArray = array();
- if ($getByRemoreId) {
- $userMatchM = new UserMatch();
- $countMatchByUser = $userMatchM->countMatchByUserByStatus($matchId, $getByRemoreId->user_id);
- if (count($userMatch) == 0) {
- $userMatch->match_id = $matchId;
- $userMatch->user_id = $getByRemoreId->user_id;
- $userMatch->status = 1;
- $userMatch->save();
- $kills = 0;
- $deaths = 0;
- $hs = 0;
- $ds = 0;
- $bm = 0;
- $modifyKd = false;
- foreach ($player as $key => $attPlayer) {
- $getStatByName = $Statitems->getStatByName($key, 1);
- if ($getStatByName) {
- if ($attPlayer > 0) {
- $ScorePlayer = new ScorePlayer();
- $getScoreUserAndMatch = $ScorePlayer->getScoreUserAndMatch($getByRemoreId->user_id, $matchId, $getStatByName->id)->count();
- if ($getScoreUserAndMatch == 0) {
- if ($getStatByName->id == 40) {
- $kills = $attPlayer;
- $modifyKd = true;
- }
- if ($getStatByName->id == 42) {
- $deaths = $attPlayer;
- $modifyKd = true;
- }
- if ($getStatByName->id == 45) {
- $ds = $attPlayer;
- $modifyKd = true;
- }
- if ($getStatByName->id == 44) {
- $hs = $attPlayer;
- $modifyKd = true;
- }
- if ($getStatByName->id == 46) {
- $bm = $attPlayer;
- $modifyKd = true;
- }
- $ScorePlayer->statitem_id = $getStatByName->id;
- $ScorePlayer->value = $attPlayer;
- $ScorePlayer->user_id = $getByRemoreId->user_id;
- $ScorePlayer->match_id = $matchId;
- $ScorePlayer->save();
- $statsArray[] = array($getStatByName->id => $attPlayer);
- }
- }
- }
- }
- if ($modifyKd) {
- $scorKill = 0;
- $scoreDeath = 0;
- $scorHs = 0;
- $scoreDs = 0;
- $scorebm = 0;
- if ($kills != 0) {
- $scorKill = $kills * config('tg.coefficient.kill');
- }
- if ($deaths != 0) {
- $scoreDeath = $deaths * config('tg.coefficient.death');
- }
- if ($hs != 0) {
- $scorHs = $hs * config('tg.coefficient.heads');
- }
- if ($ds != 0) {
- $scoreDs = $ds * config('tg.coefficient.defuse');
- }
- if ($bm != 0) {
- $scorebm = $bm * config('tg.coefficient.bomb');
- }
- $score = ($scorKill + $scoreDeath + $scorHs + $scoreDs + $scoreDs + $scorebm) * 10;
- $userMatchModel = new UserMatch();
- $getMatchByUser = $userMatchModel->getMatchByUser($userMatch->match_id, $userMatch->user_id);
- if ($getMatchByUser->score == 0) {
- $getMatchByUser->score = $score;
- } else {
- $getMatchByUser->score = (($getByRemoreId->score + $score));
- }
- $getMatchByUser->game_id = 1;
- $getMatchByUser->save();
- $getByRemoreId->save();
- }
- $challengeUser = new ChallengeUser();
- $challengeUser->validateChallengeUser($getByRemoreId->user_id, $statsArray);
- }
- }
- }
- }
- public function getMatchIpServer($matchId) {
- Config::set('database.default', 'ebot');
- DB::connection('ebot');
- $matchBot = MatchBot::find($matchId);
- return $matchBot->ip;
- }
- public function getEbotUsers($matchId) {
- Config::set('database.default', 'ebot');
- DB::connection('ebot');
- $players = new Playerbot();
- $playersModel = $players->where('match_id', $matchId)->get();
- $ebotUsers = array();
- foreach ($playersModel as $player) {
- $ebotUsers[] = $player->toArray();
- }
- return $ebotUsers;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement