• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

AAC myacc few spaces

Tubeshop

Member
Joined
Nov 23, 2023
Messages
173
Reaction score
19
I have a problem with myacc. when I create a character and put a lot of spaces, the website does not remove them. the created character looks good on the website. it has a lot of spaces in the game. how to fix it?

1705328779519.png
 
Solution
@Tubeshop Speaking of exiting entries in DB you could sanitize that with use of REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) but if there are some names that'd lead to UNIQUE constraint violation you'd need to handle that too. For example like that (It's ugly but should work):
SQL:
WITH normalizedMap AS (
    SELECT
        REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) AS normalized_name,
        COUNT(*) OVER (PARTITION BY REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)) AS cnt,
        id AS player_id
    FROM players
)
UPDATE players p
INNER JOIN normalizedMap n ON n.player_id = p.id
SET p.name = n.normalized_name
WHERE n.cnt = 1;

Speaking of the previous code snippet it's just a proposal code you could use while saving players to DB...
PHP:
function sanitzePlayerName($name) {
    return preg_replace('/\s+/', ' ', trim($name));
}

$name = "Jon    Jons";
$sanitizedName = sanitzePlayerName($name);  // "Jon Jons"
 
PHP:
function sanitzePlayerName($name) {
    return preg_replace('/\s+/', ' ', trim($name));
}

$name = "Jon    Jons";
$sanitizedName = sanitzePlayerName($name);  // "Jon Jons"
on the page it automatically removes spaces. however, I want to fix a bug in the game
 
Go into your database probably using phpMyAdmin and find table players, find the player you wanna change and change their name.
:)
Post automatically merged:

PHP:
function sanitzePlayerName($name) {
    return preg_replace('/\s+/', ' ', trim($name));
}

$name = "Jon    Jons";
$sanitizedName = sanitzePlayerName($name);  // "Jon Jons"
In which page file should I add it? I can't find the account php file
 
@Tubeshop Speaking of exiting entries in DB you could sanitize that with use of REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) but if there are some names that'd lead to UNIQUE constraint violation you'd need to handle that too. For example like that (It's ugly but should work):
SQL:
WITH normalizedMap AS (
    SELECT
        REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) AS normalized_name,
        COUNT(*) OVER (PARTITION BY REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)) AS cnt,
        id AS player_id
    FROM players
)
UPDATE players p
INNER JOIN normalizedMap n ON n.player_id = p.id
SET p.name = n.normalized_name
WHERE n.cnt = 1;

Speaking of the previous code snippet it's just a proposal code you could use while saving players to DB (find a save player method in your AAC or some method that validates/sanitizes player name and put the code there)

UPDATE:
From what I see MyAAC already has some validators for that purpouse:
 
Last edited:
Solution
@Tubeshop Speaking of exiting entries in DB you could sanitize that with use of REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) but if there are some names that'd lead to UNIQUE constraint violation you'd need to handle that too. For example like that (It's ugly but should work):
SQL:
WITH normalizedMap AS (
    SELECT
        REGEXP_REPLACE(name, '\\s+', ' ', 1, 0) AS normalized_name,
        COUNT(*) OVER (PARTITION BY REGEXP_REPLACE(name, '\\s+', ' ', 1, 0)) AS cnt,
        id AS player_id
    FROM players
)
UPDATE players p
INNER JOIN normalizedMap n ON n.player_id = p.id
SET p.name = n.normalized_name
WHERE n.cnt = 1;

Speaking of the previous code snippet it's just a proposal code you could use while saving players to DB (find a save player method in your AAC or some method that validates/sanitizes player name and put the code there)

UPDATE:
From what I see MyAAC already has some validators for that purpouse:
thanks for help
 
It is allowed for admin to create char with spaces and also some other rules are skipped.

Are you sure you are not logged on admin account while creating character?
 
Back
Top