Skip to content

Commit 4a773e5

Browse files
alexp8Sneer-ra2TF338
authored
Develop to main (#462)
* add more logs and update secondsInQueue (#456) Co-authored-by: Sneer-ra2 <[email protected]> * set AutoSaveInterval to 0 * update secondsInQueue to use updated_at * fix secondsInQueue bug * update player name fix * account-settings updates * Fix: Cooldown should start on connect (#452) (#461) * Fix: Cooldown should start on connect (#452) * Fix: Cooldown should start on connect * Fix: Cooldown should start on connect * housekeeping --------- Co-authored-by: TF338 <[email protected]> --------- Co-authored-by: Sneer-ra2 <[email protected]> Co-authored-by: TF338 <[email protected]>
1 parent 67c6bbb commit 4a773e5

File tree

3 files changed

+66
-42
lines changed

3 files changed

+66
-42
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,9 @@ public function getUserBan(Request $request, $ladderId = null, $playerId = null,
12701270

12711271
$user = $player->user;
12721272

1273+
$startBan = ($banType >= \App\Models\Ban::START_NOW_BEGIN
1274+
&& $banType <= \App\Models\Ban::START_NOW_END);
1275+
12731276
return view(
12741277
"admin.edit-ban",
12751278
[
@@ -1281,7 +1284,7 @@ public function getUserBan(Request $request, $ladderId = null, $playerId = null,
12811284
"expires" => null,
12821285
"admin_id" => $mod->id,
12831286
"user_id" => $user->id,
1284-
"start_ban" => true, // new ban,
1287+
"start_ban" => $startBan,
12851288
"end_ban" => false,
12861289
"ban_type" => $banType,
12871290
"internal_note" => "",
@@ -1678,11 +1681,14 @@ public function editPlayerName(Request $request, $ladderId, $playerId)
16781681

16791682
$playerCaches = PlayerCache::where('player_id', $player->id)->get();
16801683

1681-
if ($playerCaches == null || $playerCaches->count() == 0)
1684+
if ($playerCaches != null)
16821685
{
1683-
Log::error("No player caches found with this player id: $player->id");
1684-
$request->session()->flash('error', "Error updating player");
1685-
return redirect()->back();
1686+
//update player name in player caches
1687+
foreach ($playerCaches as $playerCache)
1688+
{
1689+
$playerCache->player_name = $player->username;
1690+
$playerCache->save();
1691+
}
16861692
}
16871693

16881694
$newName = $request->player_name;
@@ -1703,13 +1709,6 @@ public function editPlayerName(Request $request, $ladderId, $playerId)
17031709
$player->username = $newName;
17041710
$player->save();
17051711

1706-
//update player name in player caches
1707-
foreach ($playerCaches as $playerCache)
1708-
{
1709-
$playerCache->player_name = $player->username;
1710-
$playerCache->save();
1711-
}
1712-
17131712
$url = URLHelper::getPlayerProfileUrl($history, $player->username);
17141713
$request->session()->flash('success', "Player name has been updated to " . $player->username);
17151714
Log::info("Successfully updated player '$oldName' to '$newName'");

cncnet-api/app/Models/Ban.php

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ public function getActivitylogOptions(): LogOptions
3434
'expires' => 'datetime',
3535
];
3636

37-
const START_ON_CONNECT_BEGIN = 0;
37+
const START_NOW_BEGIN = 0;
3838
const BAN_BEGIN = 0;
3939
const BAN48H = 0;
4040
const BAN1WEEK = 1;
4141
const BAN2WEEK = 2;
4242
const BAN_SHADOW = 3;
4343
const BAN_END = 99;
44-
const START_ON_CONNECT_END = 99;
44+
const START_NOW_END = 99;
4545

4646
const PERMBAN = 100;
4747

48-
const START_NOW_BEGIN = 140;
48+
const START_ON_CONNECT_BEGIN = 140;
4949
const COOLDOWN_BEGIN = 140;
5050
const COOLDOWN1H = 140;
5151
const COOLDOWN2H = 141;
5252
const COOLDOWN4H = 142;
5353
const COOLDOWN12H = 143;
5454
const COOLDOWN_END = 199;
55-
const START_NOW_END = 199;
55+
const START_ON_CONNECT_END = 199;
5656

5757
public function admin()
5858
{
@@ -69,11 +69,6 @@ public function ip()
6969
return $this->belongsTo(IpAddress::class, 'ip_address_id');
7070
}
7171

72-
public static function unstartedBanTime()
73-
{
74-
return Carbon::now();
75-
}
76-
7772
public function banHasExpired()
7873
{
7974
// Convert the timestamp to a Carbon instance
@@ -88,31 +83,72 @@ public function banHasExpired()
8883

8984
public function started()
9085
{
91-
if ($this->expires === null || $this->expires->eq(Ban::unstartedBanTime()))
92-
{
93-
return false;
94-
}
95-
return true;
86+
return $this->expires !== null;
9687
}
9788

89+
/**
90+
* Check if a ban is active and optionally start it if not already started.
91+
*
92+
* This method handles two types of bans:
93+
* - START_NOW bans (0-99): Regular bans that start immediately when created
94+
* - START_ON_CONNECT bans (140-199): Cooldown bans that start when user tries to queue
95+
*
96+
* Behavior depends on the $startBanStraightAway parameter:
97+
*
98+
* When $startBanStraightAway = false (checking existing bans):
99+
* - For cooldown bans: Returns message only if already started and not expired
100+
* - For regular bans: Returns message if ban is active
101+
* - Does NOT modify the ban record
102+
*
103+
* When $startBanStraightAway = true (creating new ban or user connecting):
104+
* - Sets the expiry time based on ban type if not already started
105+
* - Saves the ban record to database
106+
* - Returns appropriate ban/cooldown message
107+
*
108+
* @param bool $startBanStraightAway Whether to initialize the ban (set expiry time).
109+
* Pass true when creating a ban or when user attempts to queue.
110+
* Pass false when simply checking if a ban is active.
111+
*
112+
* @return string|null Returns a ban/cooldown message if the ban is active, null otherwise.
113+
* Message format varies by ban type (regular ban vs cooldown).
114+
*
115+
* @side-effects May update $this->expires and save to database when $startBanStraightAway = true
116+
*/
98117
public function checkStartBan($startBanStraightAway = false)
99118
{
100119
// Log::debug("checkStartBan: ban_id=" . $this->id . ", startBanStraightAway=" . $startBanStraightAway . ", ban_type=" . $this->ban_type . ", desc=" . Ban::typeToDescription($this->ban_type) . ", expires=" . $this->expires);
101120

102121
$banned = false;
103122
$cooldown = false;
104-
if (!$startBanStraightAway && !($this->ban_type >= Ban::START_NOW_BEGIN && $this->ban_type <= Ban::START_NOW_END))
123+
124+
// Check if this is a cooldown ban that hasn't been triggered yet
125+
$isCooldownBan = ($this->ban_type >= Ban::START_ON_CONNECT_BEGIN && $this->ban_type <= Ban::START_ON_CONNECT_END);
126+
127+
if (!$startBanStraightAway && $isCooldownBan)
105128
{
129+
// Cooldown ban hasn't been triggered yet, only show if already started
130+
if ($this->started() && $this->expires->gt(Carbon::now()))
131+
{
132+
$cooldown = true;
133+
}
134+
else
135+
{
136+
// Cooldown not started yet, don't block the user
137+
return null;
138+
}
139+
}
140+
else if (!$startBanStraightAway)
141+
{
142+
// Checking existing START_NOW bans (not actively starting them)
106143
if ($this->ban_type == Ban::PERMBAN)
107144
return "You are permanently banned!\n{$this->plubic_reason}";
108145

109-
if ($this->ban_type <= Ban::BAN_END && $this->ban_type >= Ban::BAN_BEGIN)
146+
if ($this->ban_type >= Ban::BAN_BEGIN && $this->ban_type <= Ban::BAN_END)
110147
$banned = true;
111-
else if ($this->ban_type <= Ban::COOLDOWN_END && $this->ban_type >= Ban::COOLDOWN_BEGIN)
112-
$cooldown = true;
113148
}
114149
else
115150
{
151+
// Starting a ban (either creation or user connecting for cooldowns)
116152
switch ($this->ban_type)
117153
{
118154
case Ban::BAN48H:

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,6 @@ function updateEmojiPreview() {
250250
</p><br />
251251
</div>
252252

253-
<div class="form-group">
254-
<h3>Match Yuri?</h3>
255-
<p>
256-
<label>
257-
<input id="do_not_match_yuri" type="checkbox" name="do_not_match_yuri"
258-
@if ($userSettings->do_not_match_yuri) checked @endif />
259-
You can disable matching with Yuri only if your rank is worse than 30 (rank 31 or lower). If your rank is 1-30, you cannot disable matching with Yuri
260-
</label>
261-
</p>
262-
</div>
263-
264253
<div class="form-group mt-5 mb-5">
265254
<div class="checkbox">
266255
@if (isset($userSettings))
@@ -324,7 +313,7 @@ function updateEmojiPreview() {
324313
</div>
325314

326315
<div class="form-group mt-2">
327-
<label for="discord">Discord username, <strong>E.g. user#9999</strong></label>
316+
<label for="discord">Discord username</label>
328317
<input id="discord" type="text" class="form-control" name="discord_profile" value="{{ $user->discord_profile }}"
329318
placeholder="Enter your Discord username only" style="max-width:300px;" />
330319
</div>

0 commit comments

Comments
 (0)