Skip to content

Commit

Permalink
Merge pull request #26 from Zlimon/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Simon Konglevoll Lønnestad authored Jan 9, 2020
2 parents 92e7782 + 261cee4 commit 4cf98db
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
75 changes: 53 additions & 22 deletions app/Console/Commands/UpdateAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use RuneManager\Helpers\Helper;

class UpdateAccounts extends Command
{
Expand Down Expand Up @@ -46,36 +47,66 @@ public function handle()
foreach ($getMembers as $member) {
$playerDataUrl = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player='.$member->username;

/* Get the $playerDataUrl file content. */
$getPlayerData = file_get_contents($playerDataUrl);
$getPlayerData = Helper::verifyUrl($playerDataUrl);

/* Fetch the content from $playerDataUrl. */
$playerStats = explode("\n", $getPlayerData);
if ($getPlayerData) {
/* Get the $playerDataUrl file content. */
//$getPlayerData = file_get_contents($playerDataUrl);

/* Convert the CSV file of player stats into an array */
$playerData = array();
foreach ($playerStats as $playerStat) {
$playerData[] = str_getcsv($playerStat);
}
/* Fetch the content from $playerDataUrl. */
$playerStats = explode("\n", $getPlayerData);

/* Convert the CSV file of player stats into an array */
$playerData = array();
foreach ($playerStats as $playerStat) {
$playerData[] = str_getcsv($playerStat);
}

if ($member->xp != $playerData[0][2]) {
if ($member->xp < $playerData[0][2]) {
print_r("Detected ".$member->username." in database with outdated data! Updating...\r\n");

$updatePlayerData = DB::table('accounts')->where('id', $member->id)
->update(
['rank' => $playerData[0][0], 'level' => $playerData[0][1], 'xp' => $playerData[0][2], 'updated_at' => Carbon::now()]
);

for ($skillCounter = 0; $skillCounter < count($skills); $skillCounter++) {
$updatePlayerSkill = DB::table($skills[$skillCounter])->where('account_id', $member->id)
->update(
['rank' => $playerData[$skillCounter+1][0], 'level' => $playerData[$skillCounter+1][1], 'xp' => $playerData[$skillCounter+1][2], 'updated_at' => Carbon::now()]
);
}

if ($member->xp != $playerData[0][2]) {
print_r("Detected ".$member->username." in database with outdated data! Updating...\r\n");
print_r("Updated ".$member->username."!\r\n");
} else {
print_r("".$member->username." has changed owner! Deleting player...\r\n");

$updatePlayerData = DB::table('accounts')->where('id', $member->id)
->update(
['rank' => $playerData[0][0], 'level' => $playerData[0][1], 'xp' => $playerData[0][2], 'updated_at' => Carbon::now()]
);
for ($skillCounter = 0; $skillCounter < count($skills); $skillCounter++) {
$deletePlayerSkill = DB::table($skills[$skillCounter])->where('account_id', $member->id)
->delete();
}

$deletePlayer = DB::table('accounts')->where('id', $member->id)
->delete();

print_r("".$member->username." deleted!\r\n");
}
} else {
print_r("No outdated data for ". $member->username."! Not updating...\r\n");
}
} else {
print_r("".$member->username." does not exist!\r\n");

for ($skillCounter = 0; $skillCounter < count($skills); $skillCounter++) {
$updatePlayerSkill = DB::table($skills[$skillCounter])->where('account_id', $member->id)
->update(
['rank' => $playerData[$skillCounter+1][0], 'level' => $playerData[$skillCounter+1][1], 'xp' => $playerData[$skillCounter+1][2], 'updated_at' => Carbon::now()]
);
$deletePlayerSkill = DB::table($skills[$skillCounter])->where('account_id', $member->id)
->delete();
}

print_r("Updated ".$member->username."!\r\n");
} else {
print_r("No outdated data for ". $member->username."! Not updating...\r\n");
$deletePlayer = DB::table('accounts')->where('id', $member->id)
->delete();

print_r("".$member->username." deleted!\r\n");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function verifyUrl($url) {

/* If the document has loaded successfully without any redirection or error */
if ($httpCode >= 200 && $httpCode < 300) {
return true;
return file_get_contents($url);
} else {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**NOTICE!** This project remains inacitve until the clan update arrives to OSRS!**

# RuneManager for Old School RuneScape
**Welcome to RuneManager!**

Expand Down

0 comments on commit 4cf98db

Please sign in to comment.