Skip to content

Commit

Permalink
Merge branch 'hotfix' into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlimon committed Dec 29, 2020
2 parents 01009b9 + 6086173 commit fe6b597
Show file tree
Hide file tree
Showing 41 changed files with 1,465 additions and 1,312 deletions.
3 changes: 1 addition & 2 deletions app/Events/AccountAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class AccountAll implements ShouldBroadcast
*/
public function __construct(Account $account, Notification $notification)
{
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderBy('id',
'DESC')->first();
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderByDesc('id')->first();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/Events/AccountKill.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class AccountKill implements ShouldBroadcast
*/
public function __construct(Account $account, Notification $notification)
{
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderBy('id',
'DESC')->first();
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderByDesc('id')->first();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/Events/AccountLevelUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class AccountLevelUp implements ShouldBroadcast
*/
public function __construct(Account $account, Notification $notification)
{
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderBy('id',
'DESC')->first();
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderByDesc('id')->first();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/Events/AccountNewUnique.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class AccountNewUnique implements ShouldBroadcast
*/
public function __construct(Account $account, Notification $notification)
{
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderBy('id',
'DESC')->first();
$this->notification = $notification::with('category')->where('account_id', $account->id)->orderByDesc('id')->first();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Events/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class All implements ShouldBroadcast
*/
public function __construct(Notification $notification)
{
$this->notification = $notification::with('category')->orderBy('id', 'DESC')->first();
$this->notification = $notification::with('category')->orderByDesc('id')->first();
}

/**
Expand Down
133 changes: 40 additions & 93 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace App\Helpers;

use App\Account;
use App\Collection;
use Carbon\Carbon;
use DateTime;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class Helper
{
Expand All @@ -26,14 +22,19 @@ public static function roundToNextHour()
return $nextHour;
}

public static function collectionAttribute($collection, $attribute)
{
return Collection::where('name', $collection)->value($attribute);
}

/**
* Generates a valid random item ID.
*
* @return
*/
public static function randomItemId($verify = false)
{
$randomItemId = rand(0, 25000);
$randomItemId = rand(0, 25317);

if ($verify) {
if (self::verifyItem($randomItemId)) {
Expand All @@ -55,15 +56,16 @@ public static function verifyItem($itemId)
{
$itemData = 'https://www.osrsbox.com/osrsbox-db/items-json/' . $itemId . '.json';

if (self::verifyUrl($itemData)) {
$itemData = file_get_contents($itemData);
$itemData = json_decode($itemData, true);
$itemData = @file_get_contents($itemData);

if (!$itemData['noted']) {
return true;
} else {
return false;
}
if ($itemData === false) {
return false;
}

$itemData = json_decode($itemData, true);

if (!$itemData['noted']) {
return true;
} else {
return false;
}
Expand All @@ -74,7 +76,7 @@ public static function verifyItem($itemId)
*
* @return
*/
public static function verifyUrl($url)
public static function getPlayerData($url)
{
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
Expand All @@ -88,7 +90,23 @@ public static function verifyUrl($url)

/* If the document has loaded successfully without any redirection or error */
if ($httpCode >= 200 && $httpCode < 300) {
return true;
$playerStats = explode("\n", $response);

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

if ($playerData[0][0]) {
return $playerData;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
Expand All @@ -110,75 +128,6 @@ public static function itemData($itemId, $attribute)
return $itemData[0][$attribute];
}

/**
* Returns the account ID for currently logged in user.
*
* @return
*/
public static function sessionAccountId()
{
return Auth::user()->member->first()->user_id;
}

public static function listClueScrollTiers()
{
return ["all", "beginner", "easy", "medium", "hard", "elite", "master"];
}

public static function listBosses()
{
return Collection::pluck('name')->toArray();
// return ["abyssal sire", "alchemical hydra", "barrows chests", "bryophyta", "callisto", "cerberus", "chambers of xeric", "chambers of xeric challenge mode", "chaos elemental", "chaos fanatic", "commander zilyana", "corporeal beast", "crazy archaeologist", "dagannoth kings", "dagannoth prime", "dagannoth rex", "dagannoth supreme", "deranged archaeologist", "general graardor", "giant mole","grotesque guardians", "hespori", "kalphite queen", "king black dragon", "kraken", "kreearra", "kril tsutsaroth", "mimic", "the nightmare", "obor", "sarachnis", "scorpia", "skotizo", "the gauntlet", "the corrupted gauntlet", "theatre of blood", "thermonuclear smoke devil", "tzkal zuk", "tztok jad", "venenatis", "vetion", "vorkath", "wintertodt", "zalcano", "zulrah"];
}

public static function collectionAttribute($collection, $attribute)
{
return Collection::where('name', $collection)->value($attribute);
}

public static function registerAccount($accountName)
{
$playerDataUrl = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=' . $accountName;

if (self::verifyUrl($playerDataUrl)) {
// Get the $playerDataUrl file content.
$getPlayerData = file_get_contents($playerDataUrl);

// Fetch the content from $playerDataUrl.
$playerStats = explode("\n", $getPlayerData);

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

$account = Account::create([
'username' => request('username'),
'rank' => $playerData[0][0],
'level' => $playerData[0][1],
'xp' => $playerData[0][2]
]);

$skills = self::listSkills();

foreach ($skills as $key => $skill) {
DB::table($skills[$key])->insert([
'account_id' => $account->id,
'rank' => $playerData[$key + 1][0],
'level' => $playerData[$key + 1][1],
'xp' => $playerData[$key + 1][2],
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
]);
}

return $account;
} else {
return false;
}
}

public static function listSkills()
{
return [
Expand Down Expand Up @@ -208,17 +157,15 @@ public static function listSkills()
];
}

public static function accountStats($accountId)
public static function listClueScrollTiers()
{
$accountSkills = [];

$skills = self::listSkills();

foreach ($skills as $skillName) {
array_push($accountSkills, DB::table($skillName)->where('account_id', $accountId)->get());
}
return ["all", "beginner", "easy", "medium", "hard", "elite", "master"];
}

return $accountSkills;
public static function listBosses()
{
return Collection::where('type', 'boss')->orWhere('type', 'raid')->pluck('name')->toArray();
// return dd(["abyssal sire", "alchemical hydra", "barrows chests", "bryophyta", "callisto", "cerberus", "chambers of xeric", "chambers of xeric challenge mode", "chaos elemental", "chaos fanatic", "commander zilyana", "corporeal beast", "crazy archaeologist", "dagannoth kings", "dagannoth prime", "dagannoth rex", "dagannoth supreme", "deranged archaeologist", "general graardor", "giant mole","grotesque guardians", "hespori", "kalphite queen", "king black dragon", "kraken", "kreearra", "kril tsutsaroth", "mimic", "the nightmare", "obor", "sarachnis", "scorpia", "skotizo", "the gauntlet", "the corrupted gauntlet", "theatre of blood", "thermonuclear smoke devil", "tzkal zuk", "tztok jad", "venenatis", "vetion", "vorkath", "wintertodt", "zalcano", "zulrah"]);
}

public static function listAccountTypes()
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/AccountAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function create()
} else {
$playerDataUrl = Helper::formatHiscoreUrl(request('account_type'), request('username'));

if (Helper::verifyUrl($playerDataUrl)) {
if (Helper::getPlayerData($playerDataUrl)) {
$authStatus = new AccountAuthStatus;

$authStatus->user_id = Auth::user()->id;
Expand Down Expand Up @@ -83,7 +83,7 @@ public function updateAccountType()
if ($authStatus->account_type != request('account_type')) {
$playerDataUrl = Helper::formatHiscoreUrl(request('account_type'), $authStatus->username);

if (Helper::verifyUrl($playerDataUrl)) {
if (Helper::getPlayerData($playerDataUrl)) {
$authStatus->account_type = request('account_type');

$authStatus->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function create()
if (Auth::check()) {
if (AccountAuthStatus::where('user_id', Auth::user()->id)->where('status', '!=', 'success')->first()) {
// TODO limit amount of account links setting
return redirect(route('show-account-auth'))->withErrors('You already have a pending status! You have to link this Old School RuneScape account to your RuneManager user before you can access this feature.');
return redirect(route('account-auth-show'))->withErrors('You already have a pending status! You have to link this Old School RuneScape account to your RuneManager user before you can access this feature.');
} else {
return view('account.create');
}
Expand Down
13 changes: 2 additions & 11 deletions app/Http/Controllers/Api/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,9 @@ public function store(Request $request)
'%20', request('username'));

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

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

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

if ($playerData[0][0]) {
if ($playerData) {
$account = Account::create([
'user_id' => $authStatus->user_id,
'account_type' => request('account_type'),
Expand Down
11 changes: 5 additions & 6 deletions app/Http/Controllers/Api/HiscoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public function skill($skillName)
{
if (Account::count() > 0) {
if ($skillName == "overall") {
$hiscores = Account::orderByRaw('CASE WHEN rank > 0 THEN 1 ELSE 2 END')->orderBy('rank',
'ASC')->orderBy('level', 'DESC')->orderBy('xp', 'DESC')->get();
$hiscores = Account::orderByRaw('CASE WHEN rank > 0 THEN 1 ELSE 2 END')->orderBy('rank')->orderByDesc('level')->orderByDesc('xp')->get();

$sumTotalXp = Account::sum('xp');

Expand Down Expand Up @@ -57,9 +56,9 @@ public function skill($skillName)
$skillName . '.rank', 'username')
->join('accounts', $skillName . '.account_id', '=', 'accounts.id')
->orderByRaw('CASE WHEN ' . $skillName . '.rank > 0 THEN 1 ELSE 2 END')
->orderBy('rank', 'ASC')
->orderBy('level', 'DESC')
->orderBy('xp', 'DESC')
->orderBy('rank')
->orderByDesc('level')
->orderByDesc('xp')
->get();
}

Expand All @@ -82,7 +81,7 @@ public function boss($bossName)
if (Account::count() > 0) {
$collection = Collection::findByName($bossName);

$boss = $collection->model::with('account')->orderBy('kill_count', 'DESC')->get();
$boss = $collection->model::with('account')->orderByDesc('kill_count')->get();

$sumKills = $collection->model::selectRaw('SUM(kill_count) AS total_kill_count')
->selectRaw('COUNT(*) AS total_kills')
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/Api/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NotificationController extends Controller
{
public function index()
{
$notifications = Notification::with('category')->orderBy('id', 'DESC')->limit(5)->get();
$notifications = Notification::with('category')->orderByDesc('id')->limit(5)->get();

return response()->json($notifications, 200);
}
Expand All @@ -19,8 +19,7 @@ public function show($accountUsername)
{
$account = Account::where('username', $accountUsername)->pluck('id')->first();

$notifications = Notification::with('category')->where('account_id', $account)->orderBy('id',
'DESC')->paginate(10);
$notifications = Notification::with('category')->where('account_id', $account)->orderByDesc('id')->paginate(10);

return response()->json($notifications, 200);
}
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class PageController extends Controller
{
public function index()
{
//$recentMembers = Account::orderBy('created_at', 'DESC')->limit(5)->get();
$recentPosts = NewsPost::with('user')->with('category')->with('image')->limit(5)->orderBy('created_at',
'DESC')->get();
$recentPosts = NewsPost::with('user')->with('category')->with('image')->limit(5)->orderByDesc('created_at')->get();

return view('index', compact('recentPosts'));
}
Expand All @@ -24,7 +22,7 @@ public function index()
*/
public function updateLog()
{
$updates = Account::orderBy('updated_at', 'DESC')->whereColumn('updated_at', '>', 'created_at')->get();
$updates = Account::orderByDesc('updated_at')->whereColumn('updated_at', '>', 'created_at')->get();

return view('update-log', compact('updates'));
}
Expand All @@ -34,7 +32,7 @@ public function updateLog()
*
* @return
*/
public function hiscore($hiscoreType, $hiscore)
public function hiscore($hiscoreType, $hiscoreName)
{
$hiscoreList = Helper::listSkills();

Expand All @@ -51,6 +49,6 @@ public function hiscore($hiscoreType, $hiscore)
$accountCount = Account::count();

return view('hiscore',
compact('hiscoreType', 'hiscore', 'hiscoreList', 'hiscoreListTop', 'hiscoreListBottom', 'accountCount'));
compact('hiscoreType', 'hiscoreName', 'hiscoreList', 'hiscoreListTop', 'hiscoreListBottom', 'accountCount'));
}
}
2 changes: 1 addition & 1 deletion database/seeds/CollectionSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function run()
// ["name" => "the fight caves", "alias" => "The Fight caves", "type" => "boss", "model" => "App\Boss\TheFightCaves"],
// ["name" => "the inferno", "alias" => "something", "type" => "boss", "model" => "App\Boss\TheInferno"],
["name" => "the nightmare", "alias" => "The Nightmare", "type" => "boss", "model" => "App\Boss\TheNightmare"],
["name" => "goblin", "alias" => "Goblin", "type" => "boss", "model" => "App\Boss\Goblin"], // TODO remove later
["name" => "goblin", "alias" => "Goblin", "type" => "npc", "model" => "App\Npc\Goblin"], // TODO remove later
]);
}
}
Loading

0 comments on commit fe6b597

Please sign in to comment.