feat: add player Names Throughout the Game UI

This commit is contained in:
2026-08-30 01:02:34 +03:00
parent 4d9d0db02d
commit dfc6b023f7
12 changed files with 307 additions and 34 deletions
+7 -2
View File
@@ -14,11 +14,16 @@ static bool valid_utf8_scalar(const unsigned char *text, size_t remaining, size_
static bool sanitize_name(const char *name, char output[kDisplayNameBytes + 1]) {
if (name == NULL) return false;
size_t input = 0;
while (name[input] == ' ') ++input;
const size_t start = input;
size_t end = start;
while (name[end] != '\0') ++end;
while (end > start && name[end - 1U] == ' ') --end;
size_t written = 0;
uint8_t scalars = 0;
while (name[input] != '\0') {
while (input < end) {
size_t bytes = 0;
if (!valid_utf8_scalar((const unsigned char *)&name[input], strlen(&name[input]), &bytes)) return false;
if (!valid_utf8_scalar((const unsigned char *)&name[input], end - input, &bytes) || name[input] == '"' || name[input] == '\\') return false;
if (written + bytes > kDisplayNameBytes || ++scalars > 20U) return false;
memcpy(&output[written], &name[input], bytes);
input += bytes;