Skip to content

Commit

Permalink
Alliance: add max length of name/description
Browse files Browse the repository at this point in the history
Use HTML5 to prevent users from entering in an alliance name/description
that will result in a database error.
  • Loading branch information
hemberger committed Oct 3, 2024
1 parent 4af9439 commit 4970d1b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/lib/Smr/Alliance.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Alliance {
public const RECRUIT_CLOSED = 'closed';
public const RECRUIT_PASSWORD = 'password';

// Database constraints
public const MAXLENGTH_NAME = 36; // varchar(36)
public const MAXLENGTH_DESCRIPTION = 255; // varchar(255)

public static function clearCache(): void {
self::$CACHE_ALLIANCES = [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/templates/Default/engine/Default/alliance_create.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<table class="standard">
<tr>
<td class="top">Name:</td>
<td><input required type="text" name="name" size="30"></td>
<td><input required type="text" name="name" maxlength="<?php echo Alliance::MAXLENGTH_NAME; ?>" size="30"></td>
</tr>
<tr>
<td class="top">Description:</td>
<td><textarea spellcheck="true" name="description"></textarea></td>
<td><textarea spellcheck="true" name="description" maxlength="<?php echo Alliance::MAXLENGTH_DESCRIPTION; ?>"></textarea></td>
</tr>
<tr>
<td class="top">Members start with:&nbsp;&nbsp;&nbsp;</td>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/Default/engine/Default/alliance_stat.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

if ($CanChangeDescription) { ?>
<tr>
<td class="top">Description:&nbsp;</td><td><textarea spellcheck="true" name="description"><?php echo $Alliance->getDescription(); ?></textarea></td>
<td class="top">Description:&nbsp;</td><td><textarea spellcheck="true" name="description" maxlength="<?php echo Alliance::MAXLENGTH_DESCRIPTION; ?>"><?php echo $Alliance->getDescription(); ?></textarea></td>
</tr><?php
}

Expand Down

0 comments on commit 4970d1b

Please sign in to comment.