Skip to content

Commit df8ddbc

Browse files
committed
Check for active nicks each month
* Resolves #25 * Automatically assign active handles if they're not active when requesting matchups *
1 parent 7231bef commit df8ddbc

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

cncnet-api/app/Http/Controllers/AccountController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ public function toggleUsernameStatus(Request $request)
105105
}
106106

107107
$date = Carbon::now();
108+
$startOfMonth = $date->startOfMonth()->toDateTimeString();
108109
$endOfMonth = $date->endOfMonth()->toDateTimeString();
109110

110111
// Check if there are active handles within this month
111-
$hasActiveHandles = PlayerActiveHandle::getUserActiveHandleCount($user->id, $ladder->id, $endOfMonth);
112+
$hasActiveHandles = PlayerActiveHandle::getUserActiveHandleCount($user->id, $ladder->id, $startOfMonth, $endOfMonth);
112113

113114
// Allow TS players to have 3 nicks as opposed to just 1
114115
// Other games are still restricted to 1
@@ -124,12 +125,12 @@ public function toggleUsernameStatus(Request $request)
124125
{
125126
$request->session()->flash('error', 'You have a username active for this month and ladder already.
126127
If you are trying to make a username inactive, the month we are in has to complete first.');
127-
128+
128129
return redirect("/account");
129130
}
130131

131132
// Get the player thats being requested to change
132-
$activeHandle = PlayerActiveHandle::getPlayerActiveHandle($player->id, $ladder->id);
133+
$activeHandle = PlayerActiveHandle::getPlayerActiveHandle($player->id, $ladder->id, $startOfMonth, $endOfMonth);
133134

134135
// If it's not an active handle make it one
135136
if ($activeHandle == null)

cncnet-api/app/Http/Controllers/ApiQuickMatchController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use \App\Http\Services\PlayerService;
88
use \App\Http\Services\PointService;
99
use \App\Http\Services\AuthService;
10+
use \App\PlayerActiveHandle;
1011
use \Carbon\Carbon;
1112
use DB;
1213
use Log;
@@ -91,15 +92,25 @@ public function matchRequest(Request $request, $ladderAbbrev = null, $playerName
9192
{
9293
return $check;
9394
}
95+
9496
$player = $this->playerService->findPlayerByUsername($playerName, $ladder);
9597

9698
if ($player == null)
9799
{
98100
return array("type"=>"fail", "description" => "$playerName is not registered in $ladderAbbrev");
99101
}
100102

103+
$date = Carbon::now();
104+
$startOfMonth = $date->startOfMonth()->toDateTimeString();
105+
$endOfMonth = $date->endOfMonth()->toDateTimeString();
106+
101107
// Player checks - ensure nick is registered as an active handle
102-
108+
$hasActiveHandle = PlayerActiveHandle::getPlayerActiveHandle($player->id, $ladder->id, $startOfMonth, $endOfMonth);
109+
if ($hasActiveHandle == null)
110+
{
111+
PlayerActiveHandle::setPlayerActiveHandle($ladder->id, $player->id, $player->user->id);
112+
}
113+
103114

104115
$ban = $player->user->getBan(true);
105116
if ($ban !== null)

cncnet-api/app/Http/Controllers/ApiUserController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ public function getAccount(Request $request)
5858

5959
private function getActivePlayerList($userId)
6060
{
61-
$activeHandles = PlayerActiveHandle::where("user_id", $userId)->get();
61+
$date = Carbon::now();
62+
$startOfMonth = $date->startOfMonth()->toDateTimeString();
63+
$endOfMonth = $date->endOfMonth()->toDateTimeString();
64+
65+
$activeHandles = PlayerActiveHandle::getUserActiveHandles($userId, $startOfMonth, $endOfMonth);
6266

6367
$players = [];
6468
foreach($activeHandles as $activeHandle)

cncnet-api/app/PlayerActiveHandle.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,33 @@ public static function setPlayerActiveHandle($ladderId, $playerId, $userId)
2626
return $activeHandle;
2727
}
2828

29-
public static function getPlayerActiveHandle($playerId, $ladderId)
29+
public static function getPlayerActiveHandle($playerId, $ladderId, $dateStart, $dateEnd)
3030
{
3131
$activeHandle = PlayerActiveHandle::where("player_id", $playerId)
3232
->where("ladder_id", $ladderId)
33+
->where("created_at", ">=", $dateStart)
34+
->where("created_at", "<=", $dateEnd)
3335
->first();
3436

3537
return $activeHandle;
3638
}
39+
40+
public static function getUserActiveHandles($userId, $dateStart, $dateEnd)
41+
{
42+
$hasActiveHandles = PlayerActiveHandle::where("user_id", $userId)
43+
->where("created_at", ">=", $dateStart)
44+
->where("created_at", "<=", $dateEnd)
45+
->get();
46+
47+
return $hasActiveHandles;
48+
}
3749

3850
public static function getUserActiveHandleCount($userId, $ladderId,
39-
$dateEnd)
51+
$dateStart, $dateEnd)
4052
{
4153
$hasActiveHandles = PlayerActiveHandle::where("ladder_id", $ladderId)
4254
->where("user_id", $userId)
55+
->where("created_at", ">=", $dateStart)
4356
->where("created_at", "<=", $dateEnd)
4457
->count();
4558

cncnet-api/resources/views/auth/account.blade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@
135135
->where("ladder_id", $u->ladder_id)
136136
->first();
137137
138-
$activeHandle = \App\PlayerActiveHandle::where("ladder_id", $u->ladder_id)
139-
->where("player_id", $player->id)
140-
->first();
138+
$date = \Carbon\Carbon::now();
139+
$startOfMonth = $date->startOfMonth()->toDateTimeString();
140+
$endOfMonth = $date->endOfMonth()->toDateTimeString();
141+
142+
$activeHandle = \App\PlayerActiveHandle::getPlayerActiveHandle($player->id, $u->ladder_id,
143+
$startOfMonth, $endOfMonth);
141144
?>
142145

143146
<div class="username-status">

0 commit comments

Comments
 (0)