From 30e802179b229a9ec32b892b33266f53723afd50 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 31 Mar 2023 17:44:29 -0700 Subject: [PATCH] Added more things to the language system --- lang/english.ini | 42 ++++++++++ lang/spanish.ini | 46 ++++++++++- src/pc/chat_commands.c | 87 +++++++++------------ src/pc/djui/djui_chat_box.c | 2 +- src/pc/djui/djui_language.c | 34 ++++++++ src/pc/djui/djui_language.h | 2 + src/pc/network/discord/discord.c | 4 +- src/pc/network/network_player.c | 43 +++++----- src/pc/network/network_player.h | 1 + src/pc/network/packets/packet_command_mod.c | 3 +- src/pc/network/packets/packet_kick.c | 10 +-- src/pc/network/packets/packet_mod_list.c | 2 +- src/pc/network/packets/packet_player.c | 15 +--- 13 files changed, 196 insertions(+), 95 deletions(-) diff --git a/lang/english.ini b/lang/english.ini index 0b52ae6aa..76e9072e3 100644 --- a/lang/english.ini +++ b/lang/english.ini @@ -1,3 +1,45 @@ +[NOTIF] +CONNECTED = "@ connected" +DISCONNECTED = "@ disconnected" +LEFT_THIS_LEVEL = "@ left this level" +ENTERED_THIS_LEVEL = "@ entered this level" +ENTERED = "@ entered\n#" +SERVER_CLOSED = "\\#ffa0a0\\Disconnected:\\#dcdcdc\\ server closed" +DISCORD_ERROR = "Discord threw an error.\nTo fix, try: \n1. Close the game.\n2. Restart Discord.\n3. Start the game." +DISCORD_DETECT = "\\#ffa0a0\\Error:\\#c8c8c8\\ Could not detect Discord.\n\\#a0a0a0\\Try closing the game, restarting Discord, and opening the game again." +DISCONNECT_FULL = "\\#ffa0a0\\Disconnected:\\#c8c8c8\\ The party is full." +DISCONNECT_KICK = "\\#ffa0a0\\Disconnected:\\#c8c8c8\\ The server kicked you." +DISCONNECT_BAN = "\\#ffa0a0\\Disconnected:\\#c8c8c8\\ The server banned you." +DISCONNECT_REJOIN = "\\#ffa0a0\\Disconnected:\\#c8c8c8\\ Rejoining..." +DISCONNECT_CLOSED = "\\#ffa0a0\\Disconnected:\\#c8c8c8\\ Host has closed the connection." +DISCONNECT_BIG_MOD = "Server had too large of a mod.\nQuitting." +DIED = "@ died" +DEBUG_FLY = "@ entered the debug free fly state" + +[CHAT] +KICKING = "Kicking '@'!" +BANNING = "Banning '@'!" +SERVER_ONLY = "Only the server can use this command." +PERM_BANNING = "Permanently banning '@'!" +ADD_MODERATOR = "Adding '@' as a Moderator!" +PLAYERS = "Players" +NO_PERMS = "You do not have permission to use this command." +PLAYER_NOT_FOUND = "Could not find player." +SELF_KICK = "You can not kick yourself." +SELF_BAN = "You can not ban yourself." +SELF_MOD = "You can not make yourself a moderator." +KICK_CONFIRM = "Are you sure you want to kick '@'?\nType '\\#a0ffa0\\/confirm\\#fff982\\' to kick." +BAN_CONFIRM = "Are you sure you want to ban '@'?\nType '\\#a0ffa0\\/confirm\\#fff982\\' to ban." +PERM_BAN_CONFIRM = "Are you sure you want to permanently ban '@'?\nType '\\#a0ffa0\\/confirm\\#fff982\\' to ban." +MOD_CONFIRM = "Are you sure you want to make '@' a moderator?\nType '\\#a0ffa0\\/confirm\\#fff982\\'." +PLAYERS_DESC = "/players - List all players and their IDs" +KICK_DESC = "/kick [NAME|ID] - Kick this player from the current game" +BAN_DESC = "/ban [NAME|ID] - Ban this player from the current game" +PERM_BAN_DESC = "/permban [NAME|ID] - Ban this player from any game you host" +MOD_DESC = "/moderator [NAME|ID] - Make this player able to use commands like /kick, /ban, /permban on any game you host" +UNRECOGNIZED = "Unrecognized chat command." +MOD_GRANTED = "\\#fff982\\You are now a Moderator." + [MENU] BACK = "Back" CANCEL = "Cancel" diff --git a/lang/spanish.ini b/lang/spanish.ini index ae3e6a3aa..df8709ff3 100644 --- a/lang/spanish.ini +++ b/lang/spanish.ini @@ -1,3 +1,45 @@ +[NOTIF] +CONNECTED = "@ conectado" +DISCONNECTED = "@ desconectado" +LEFT_THIS_LEVEL = "@ salió de este nivel" +ENTERED_THIS_LEVEL = "@ entró en este nivel" +ENTERED = "@ ingresado\n#" +SERVER_CLOSED = "\\#ffa0a0\\Desconectado:\\#dcdcdc\\ servidor cerrado" +DISCORD_ERROR = "Discord lanzó un error.\nPara solucionarlo, intente: \n1. Cierre el juego.\n2. Reinicie Discord.\n3. Inicie el juego". +DISCORD_DETECT = "\\#ffa0a0\\Error:\\#c8c8c8\\ No se pudo detectar Discord.\n\\#a0a0a0\\Intente cerrar el juego, reiniciar Discord y volver a abrir el juego". +DISCONNECT_FULL = "\\#ffa0a0\\Desconectado:\\#c8c8c8\\ La fiesta está llena." +DISCONNECT_KICK = "\\#ffa0a0\\Desconectado:\\#c8c8c8\\ El servidor te expulsó". +DISCONNECT_BAN = "\\#ffa0a0\\Desconectado:\\#c8c8c8\\ El servidor te prohibió." +DISCONNECT_REJOIN = "\\#ffa0a0\\Desconectado:\\#c8c8c8\\ Reuniéndose..." +DISCONNECT_CLOSED = "\\#ffa0a0\\Desconectado:\\#c8c8c8\\ Host ha cerrado la conexión". +DISCONNECT_BIG_MOD = "El servidor tenía un mod demasiado grande.\nSaliendo". +DIED = "@ murió" +DEBUG_FLY = "@ entró en el estado de vuelo libre de depuración" + +[CHAT] +KICKING = "¡Patadas a '@'!" +BANNING = "¡Prohibición de '@'!" +SERVER_ONLY = "Solo el servidor puede usar este comando". +PERM_BANNING = "¡Prohibición permanente de '@'!" +ADD_MODERATOR = "¡Añadiendo '@' como moderador!" +PLAYERS = "Jugadores" +NO_PERMS = "No tiene permiso para usar este comando". +PLAYER_NOT_FOUND = "No se pudo encontrar el jugador". +SELF_KICK = "No puedes patearte a ti mismo". +SELF_BAN = "No puedes banearte a ti mismo". +SELF_MOD = "No puedes convertirte en moderador". +KICK_CONFIRM = "¿Estás seguro de que quieres patear a '@'?\nEscribe '\\#a0ffa0\\/confirm\\#fff982\\' para patear." +BAN_CONFIRM = "¿Está seguro de que desea prohibir a '@'?\nEscriba '\\#a0ffa0\\/confirm\\#fff982\\' para prohibir". +PERM_BAN_CONFIRM = "¿Está seguro de que desea prohibir permanentemente a '@'?\nEscriba '\\#a0ffa0\\/confirm\\#fff982\\' para prohibir". +MOD_CONFIRM = "¿Está seguro de que desea convertir a '@' en moderador?\nEscriba '\\#a0ffa0\\/confirm\\#fff982\\'". +PLAYERS_DESC = "/players - Lista de todos los jugadores y sus ID" +KICK_DESC = "/kick [NOMBRE|ID] - Expulsa a este jugador del juego actual" +BAN_DESC = "/ban [NOMBRE|ID] - Prohibir a este jugador del juego actual" +PERM_BAN_DESC = "/permban [NOMBRE|ID] - Bloquea a este jugador de cualquier juego que organices" +MOD_DESC = "/moderator [NOMBRE|ID] - Haz que este jugador pueda usar comandos como /kick, /ban, /permban en cualquier juego que organices" +UNRECOGNIZED = "Comando de chat no reconocido". +MOD_GRANTED = "\\#fff982\\Ahora eres moderador". + [MENU] BACK = "Atrás" CANCEL = "Cancelar" @@ -97,7 +139,7 @@ HOST = "Anfitrión" [HOST_MODS] ROMHACKS = "ROMHACKS" -MODS = "MODIFICACIONES" +MODS = "MODS" [HOST_SAVE] SAVE_TITLE = "AHORRAR" @@ -177,7 +219,7 @@ MENU_OPTIONS = "Opciones de menú" DEBUG = "Depurar" [MODLIST] -MODS = "MODIFICACIONES" +MODS = "MODS" [OPTIONS] OPTIONS = "OPCIONES" diff --git a/src/pc/chat_commands.c b/src/pc/chat_commands.c index f843f5b0e..a6d361f3e 100644 --- a/src/pc/chat_commands.c +++ b/src/pc/chat_commands.c @@ -1,6 +1,7 @@ #include "pc/network/network.h" #include "pc/network/socket/socket.h" #include "pc/lua/smlua_hooks.h" +#include "pc/djui/djui_language.h" #include "pc/djui/djui_chat_message.h" #include "chat_commands.h" #include "pc/network/ban_list.h" @@ -41,6 +42,16 @@ static bool str_starts_with(const char* pre, char* str) { return strncmp(pre, str, strlen(pre)) == 0; } +static void chat_construct_player_message(struct NetworkPlayer* np, char* msg) { + char built[256] = { 0 }; + snprintf(built, 256, "\\#fff982\\"); + + char player[128] = { 0 }; + snprintf(player, 128, "%s%s\\#fff982\\", network_get_player_text_color_string(np->localIndex), np->name); + djui_language_replace(msg, &built[9], 256 - 9, '@', player); + djui_chat_message_create(built); +} + bool exec_chat_command(char* command) { enum ChatConfirmCommand ccc = sConfirming; sConfirming = CCC_NONE; @@ -50,9 +61,7 @@ bool exec_chat_command(char* command) { if (ccc == CCC_KICK) { struct NetworkPlayer* np = &gNetworkPlayers[sConfirmPlayerIndex]; if (!np->connected) { return true; } - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Kicking '%s%s\\#fff982\\'!", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); + chat_construct_player_message(np, DLANG(CHAT, KICKING)); if (gNetworkType == NT_SERVER) { network_send_kick(np->localIndex, EKT_KICKED); network_player_disconnected(np->localIndex); @@ -66,9 +75,7 @@ bool exec_chat_command(char* command) { if (ccc == CCC_BAN) { struct NetworkPlayer* np = &gNetworkPlayers[sConfirmPlayerIndex]; if (!np->connected) { return true; } - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Banning '%s%s\\#fff982\\'!", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); + chat_construct_player_message(np, DLANG(CHAT, BANNING)); if (gNetworkType == NT_SERVER) { network_send_kick(np->localIndex, EKT_BANNED); ban_list_add(gNetworkSystem->get_id_str(np->localIndex), false); @@ -82,9 +89,7 @@ bool exec_chat_command(char* command) { if (gNetworkType == NT_SERVER && ccc == CCC_PERMBAN) { struct NetworkPlayer* np = &gNetworkPlayers[sConfirmPlayerIndex]; if (!np->connected) { return true; } - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Permanently banning '%s%s\\#fff982\\'!", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); + chat_construct_player_message(np, DLANG(CHAT, PERM_BANNING)); network_send_kick(np->localIndex, EKT_BANNED); ban_list_add(gNetworkSystem->get_id_str(np->localIndex), true); network_player_disconnected(np->localIndex); @@ -93,9 +98,7 @@ bool exec_chat_command(char* command) { if (gNetworkType == NT_SERVER && ccc == CCC_MODERATOR) { struct NetworkPlayer* np = &gNetworkPlayers[sConfirmPlayerIndex]; if (!np->connected) { return true; } - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Adding '%s%s\\#fff982\\' as a Moderator!", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); + chat_construct_player_message(np, DLANG(CHAT, ADD_MODERATOR)); network_send_moderator(np->localIndex); moderator_list_add(gNetworkSystem->get_id_str(np->localIndex), true); return true; @@ -104,7 +107,7 @@ bool exec_chat_command(char* command) { if (strcmp("/players", command) == 0) { char line[128] = { 0 }; - strncat(line, "\\#fff982\\Players:\n", 127); + snprintf(line, 127, "\\#fff982\\%s:\n", DLANG(CHAT, PLAYERS)); djui_chat_message_create(line); for (s32 i = 0; i < MAX_PLAYERS; i++) { struct NetworkPlayer* np = &gNetworkPlayers[i]; @@ -121,25 +124,21 @@ bool exec_chat_command(char* command) { if (str_starts_with("/kick ", command)) { if (gNetworkType != NT_SERVER && !gIsModerator) { - djui_chat_message_create("You do not have permission to use this command."); + djui_chat_message_create(DLANG(CHAT, NO_PERMS)); return true; } struct NetworkPlayer* np = chat_get_network_player(&command[6]); if (np == NULL) { - djui_chat_message_create("Could not find player."); + djui_chat_message_create(DLANG(CHAT, PLAYER_NOT_FOUND)); return true; } if (np->localIndex == 0) { - djui_chat_message_create("Can not kick yourself."); + djui_chat_message_create(DLANG(CHAT, SELF_KICK)); return true; } - - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Are you sure you want to kick '%s%s\\#fff982\\'?\nType '\\#a0ffa0\\/confirm\\#fff982\\' to kick.", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); - + chat_construct_player_message(np, DLANG(CHAT, KICK_CONFIRM)); sConfirming = CCC_KICK; sConfirmPlayerIndex = np->localIndex; @@ -148,25 +147,21 @@ bool exec_chat_command(char* command) { if (str_starts_with("/ban ", command)) { if (gNetworkType != NT_SERVER && !gIsModerator) { - djui_chat_message_create("You do not have permission to use this command."); + djui_chat_message_create(DLANG(CHAT, NO_PERMS)); return true; } struct NetworkPlayer* np = chat_get_network_player(&command[5]); if (np == NULL) { - djui_chat_message_create("Could not find player."); + djui_chat_message_create(DLANG(CHAT, PLAYER_NOT_FOUND)); return true; } if (np->localIndex == 0) { - djui_chat_message_create("Can not ban yourself."); + djui_chat_message_create(DLANG(CHAT, SELF_BAN)); return true; } - - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Are you sure you want to ban '%s%s\\#fff982\\'?\nType '\\#a0ffa0\\/confirm\\#fff982\\' to ban.", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); - + chat_construct_player_message(np, DLANG(CHAT, BAN_CONFIRM)); sConfirming = CCC_BAN; sConfirmPlayerIndex = np->localIndex; @@ -175,25 +170,21 @@ bool exec_chat_command(char* command) { if (str_starts_with("/permban ", command)) { if (gNetworkType != NT_SERVER && !gIsModerator) { - djui_chat_message_create("You do not have permission to use this command."); + djui_chat_message_create(DLANG(CHAT, NO_PERMS)); return true; } struct NetworkPlayer* np = chat_get_network_player(&command[9]); if (np == NULL) { - djui_chat_message_create("Could not find player."); + djui_chat_message_create(DLANG(CHAT, PLAYER_NOT_FOUND)); return true; } if (np->localIndex == 0) { - djui_chat_message_create("Can not permanently ban yourself."); + djui_chat_message_create(DLANG(CHAT, SELF_BAN)); return true; } - - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Are you sure you want to permanently ban '%s%s\\#fff982\\'?\nType '\\#a0ffa0\\/confirm\\#fff982\\' to permanently ban.", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); - + chat_construct_player_message(np, DLANG(CHAT, PERM_BAN_CONFIRM)); sConfirming = CCC_PERMBAN; sConfirmPlayerIndex = np->localIndex; @@ -202,25 +193,21 @@ bool exec_chat_command(char* command) { if (str_starts_with("/moderator ", command)) { if (gNetworkType != NT_SERVER) { - djui_chat_message_create("Only the server can use this command."); + djui_chat_message_create(DLANG(CHAT, SERVER_ONLY)); return true; } struct NetworkPlayer* np = chat_get_network_player(&command[11]); if (np == NULL) { - djui_chat_message_create("Could not find player."); + djui_chat_message_create(DLANG(CHAT, PLAYER_NOT_FOUND)); return true; } if (np->localIndex == 0) { - djui_chat_message_create("Can not make yourself a moderator."); + djui_chat_message_create(DLANG(CHAT, SELF_MOD)); return true; } - - char message[256] = { 0 }; - snprintf(message, 256, "\\#fff982\\Are you sure you want to make '%s%s\\#fff982\\' a moderator?\nType '\\#a0ffa0\\/confirm\\#fff982\\' to moderate.", network_get_player_text_color_string(np->localIndex), np->name); - djui_chat_message_create(message); - + chat_construct_player_message(np, DLANG(CHAT, MOD_CONFIRM)); sConfirming = CCC_MODERATOR; sConfirmPlayerIndex = np->localIndex; @@ -328,12 +315,12 @@ bool exec_chat_command(char* command) { } void display_chat_commands(void) { - djui_chat_message_create("/players - List all players and their IDs"); + djui_chat_message_create(DLANG(CHAT, PLAYERS_DESC)); if (gNetworkType == NT_SERVER || gIsModerator) { - djui_chat_message_create("/kick [NAME|ID] - Kick this player from the current game"); - djui_chat_message_create("/ban [NAME|ID] - Ban this player from the current game"); - djui_chat_message_create("/permban [NAME|ID] - Ban this player from any game you host"); - djui_chat_message_create("/moderator [NAME|ID] - Make this player able to use commands like /kick, /ban, /permban on any game you host"); + djui_chat_message_create(DLANG(CHAT, KICK_DESC)); + djui_chat_message_create(DLANG(CHAT, BAN_DESC)); + djui_chat_message_create(DLANG(CHAT, PERM_BAN_DESC)); + djui_chat_message_create(DLANG(CHAT, MOD_DESC)); } #if defined(DEVELOPMENT) djui_chat_message_create("/warp [LEVEL] [AREA] [ACT] - Level can be either a numeric value or a shorthand name"); diff --git a/src/pc/djui/djui_chat_box.c b/src/pc/djui/djui_chat_box.c index 03400eddc..e21bc6d54 100644 --- a/src/pc/djui/djui_chat_box.c +++ b/src/pc/djui/djui_chat_box.c @@ -41,7 +41,7 @@ static void djui_chat_box_input_enter(struct DjuiInputbox* chatInput) { if (strlen(chatInput->buffer) != 0) { if (chatInput->buffer[0] == '/') { if (!exec_chat_command(chatInput->buffer)) { - djui_chat_message_create("Unrecognized chat command."); + djui_chat_message_create(DLANG(CHAT, UNRECOGNIZED)); display_chat_commands(); } } else { diff --git a/src/pc/djui/djui_language.c b/src/pc/djui/djui_language.c index 090b408f7..07fe6b1fb 100644 --- a/src/pc/djui/djui_language.c +++ b/src/pc/djui/djui_language.c @@ -16,4 +16,38 @@ char* djui_language_get(const char *section, const char *key) { char* value = (char*)ini_get(sLang, section, key); if (!value) { return "???"; } return value; +} + +void djui_language_replace(char* src, char* dst, int size, char key, char* value) { + char tmpChar[10] = { 0 }; + char* c = src; + char* o = dst; + while (*c != '\0') { + if (*c == key) { + snprintf(o, size - (o - dst), "%s", value); + } else { + djui_unicode_get_char(c, tmpChar); + snprintf(o, size - (o - dst), "%s", tmpChar); + } + o = &dst[strlen(dst)]; + c = djui_unicode_next_char(c); + } +} + +void djui_language_replace2(char* src, char* dst, int size, char key1, char* value1, char key2, char* value2) { + char tmpChar[10] = { 0 }; + char* c = src; + char* o = dst; + while (*c != '\0') { + if (*c == key1) { + snprintf(o, size - (o - dst), "%s", value1); + } else if (*c == key2) { + snprintf(o, size - (o - dst), "%s", value2); + } else { + djui_unicode_get_char(c, tmpChar); + snprintf(o, size - (o - dst), "%s", tmpChar); + } + o = &dst[strlen(dst)]; + c = djui_unicode_next_char(c); + } } \ No newline at end of file diff --git a/src/pc/djui/djui_language.h b/src/pc/djui/djui_language.h index bab35965b..63622927f 100644 --- a/src/pc/djui/djui_language.h +++ b/src/pc/djui/djui_language.h @@ -3,3 +3,5 @@ void djui_language_init(char* filename); char* djui_language_get(const char *section, const char *key); +void djui_language_replace(char* src, char* dst, int size, char key, char* value); +void djui_language_replace2(char* src, char* dst, int size, char key1, char* value1, char key2, char* value2); diff --git a/src/pc/network/discord/discord.c b/src/pc/network/discord/discord.c index fe89bf246..b7c3a0c3c 100644 --- a/src/pc/network/discord/discord.c +++ b/src/pc/network/discord/discord.c @@ -30,7 +30,7 @@ static void discord_sdk_log_callback(UNUSED void* hook_data, enum EDiscordLogLev void discord_fatal_message(int rc) { // Discord usually does this because of loss of connection to Discord char errorMessage[132] = { 0 }; - snprintf(errorMessage, 132, "Discord threw an error.\nTo fix, try: \n1. Close the game.\n2. Restart Discord.\n3. Start the game.\nRC: %d", rc); + snprintf(errorMessage, 132, "%s\nRC: %d", DLANG(NOTIF, DISCORD_ERROR), rc); djui_popup_create(errorMessage, 6); } @@ -142,7 +142,7 @@ static bool ns_discord_initialize(enum NetworkType networkType) { DISCORD_REQUIRE(rc); } else if (rc) { LOGFILE_ERROR(LFT_DISCORD, "DiscordCreate failed: %d", rc); - djui_popup_create("\\#ffa0a0\\Error:\\#c8c8c8\\ Could not detect Discord.\n\\#a0a0a0\\Try closing the game, restarting Discord, and opening the game again.", 3); + djui_popup_create(DLANG(NOTIF, DISCORD_DETECT), 3); gDiscordFailed = true; return false; } diff --git a/src/pc/network/network_player.c b/src/pc/network/network_player.c index 088425cd8..5fc1906da 100644 --- a/src/pc/network/network_player.c +++ b/src/pc/network/network_player.c @@ -300,10 +300,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode // display connected popup if (!gCurrentlyJoining && type != NPT_SERVER && (gNetworkType != NT_SERVER || type != NPT_LOCAL)) { - char *playerColorString = network_get_player_text_color_string(np->localIndex); - char popupMsg[128] = { 0 }; - snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ connected", playerColorString, np->name); - djui_popup_create(popupMsg, 1); + construct_player_popup(np, DLANG(NOTIF, CONNECTED), NULL); } LOG_INFO("player connected, local %d, global %d", localIndex, np->globalIndex); @@ -350,10 +347,7 @@ u8 network_player_disconnected(u8 globalIndex) { LOG_INFO("player disconnected, local %d, global %d", i, globalIndex); // display popup - char *playerColorString = network_get_player_text_color_string(np->localIndex); - char popupMsg[128] = { 0 }; - snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ disconnected", playerColorString, np->name); - djui_popup_create(popupMsg, 1); + construct_player_popup(np, DLANG(NOTIF, DISCONNECTED), NULL); packet_ordered_clear(globalIndex); @@ -366,6 +360,20 @@ u8 network_player_disconnected(u8 globalIndex) { return UNKNOWN_GLOBAL_INDEX; } +void construct_player_popup(struct NetworkPlayer* np, char* msg, const char* level) { + char built[256] = { 0 }; + snprintf(built, 256, "\\#dcdcdc\\"); + + char player[128] = { 0 }; + snprintf(player, 128, "%s%s\\#dcdcdc\\", network_get_player_text_color_string(np->localIndex), np->name); + if (level) { + djui_language_replace2(msg, &built[9], 256 - 9, '@', player, '#', (char*)level); + } else { + djui_language_replace(msg, &built[9], 256 - 9, '@', player); + } + djui_popup_create(built, 1); +} + void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { // prevent sync valid packets from corrupting areaIndex if (areaIndex == -1) { @@ -374,23 +382,16 @@ void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum, // display popup bool inCredits = (np->currActNum == 99); - + if (np->currCourseNum != courseNum && np->localIndex != 0 && !inCredits) { - char *playerColorString = network_get_player_text_color_string(np->localIndex); - char popupMsg[128] = { 0 }; bool matchingLocal = (np->currCourseNum == gNetworkPlayerLocal->currCourseNum) && (np->currActNum == gNetworkPlayerLocal->currActNum); - + if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) { - snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ left this level", playerColorString, np->name); + construct_player_popup(np, DLANG(NOTIF, LEFT_THIS_LEVEL), NULL); } else if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) { - snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ entered this level", playerColorString, np->name); + construct_player_popup(np, DLANG(NOTIF, ENTERED_THIS_LEVEL), NULL); } else { - snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ entered\n%s", playerColorString, np->name, get_level_name(courseNum, levelNum, areaIndex)); - } - - // display popup - if (configDisablePopups == 0) { - djui_popup_create(popupMsg, 1); + construct_player_popup(np, DLANG(NOTIF, ENTERED), get_level_name(courseNum, levelNum, areaIndex)); } } @@ -446,6 +447,6 @@ void network_player_shutdown(bool popup) { gNetworkSystem->clear_id(i); } - if (popup) { djui_popup_create("\\#ffa0a0\\Disconnected:\\#dcdcdc\\ server closed", 1); } + if (popup) { djui_popup_create(DLANG(NOTIF, SERVER_CLOSED), 1); } LOG_INFO("cleared all network players"); } diff --git a/src/pc/network/network_player.h b/src/pc/network/network_player.h index 5539725df..3a365054f 100644 --- a/src/pc/network/network_player.h +++ b/src/pc/network/network_player.h @@ -83,6 +83,7 @@ void network_player_update(void); u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, const struct PlayerPalette* playerPalette, char* name); u8 network_player_disconnected(u8 globalIndex); +void construct_player_popup(struct NetworkPlayer* np, char* msg, const char* level); void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex); void network_player_shutdown(bool popup); diff --git a/src/pc/network/packets/packet_command_mod.c b/src/pc/network/packets/packet_command_mod.c index 2f933c350..c612b5531 100644 --- a/src/pc/network/packets/packet_command_mod.c +++ b/src/pc/network/packets/packet_command_mod.c @@ -1,5 +1,6 @@ #include #include "../network.h" +#include "pc/djui/djui_language.h" #include "pc/djui/djui_chat_message.h" #include "pc/network/ban_list.h" #include "pc/network/moderator_list.h" @@ -64,5 +65,5 @@ void network_recieve_moderator(struct Packet *p) { } gIsModerator = true; - djui_chat_message_create("\\#fff982\\You are now a Moderator."); + djui_chat_message_create(DLANG(CHAT, MOD_GRANTED)); } \ No newline at end of file diff --git a/src/pc/network/packets/packet_kick.c b/src/pc/network/packets/packet_kick.c index c69106ac9..7279f2369 100644 --- a/src/pc/network/packets/packet_kick.c +++ b/src/pc/network/packets/packet_kick.c @@ -31,11 +31,11 @@ void network_receive_kick(struct Packet* p) { enum KickReasonType kickReason = kickReasonType; switch (kickReason) { - case EKT_FULL_PARTY: djui_popup_create("\\#ffa0a0\\Disconnected:\\#c8c8c8\\ The party is full.", 1); break; - case EKT_KICKED: djui_popup_create("\\#ffa0a0\\Disconnected:\\#c8c8c8\\ The server kicked you.", 1); break; - case EKT_BANNED: djui_popup_create("\\#ffa0a0\\Disconnected:\\#c8c8c8\\ The server banned you.", 1); break; - case EKT_REJOIN: djui_popup_create("\\#ffa0a0\\Disconnected:\\#c8c8c8\\ Rejoining...", 1); break; - default: djui_popup_create("\\#ffa0a0\\Disconnected:\\#c8c8c8\\ Host has closed the connection.", 1); break; + case EKT_FULL_PARTY: djui_popup_create(DLANG(NOTIF, DISCONNECT_FULL), 1); break; + case EKT_KICKED: djui_popup_create(DLANG(NOTIF, DISCONNECT_KICK), 1); break; + case EKT_BANNED: djui_popup_create(DLANG(NOTIF, DISCONNECT_BAN), 1); break; + case EKT_REJOIN: djui_popup_create(DLANG(NOTIF, DISCONNECT_REJOIN), 1); break; + default: djui_popup_create(DLANG(NOTIF, DISCONNECT_CLOSED), 1); break; } if (kickReason == EKT_REJOIN) { diff --git a/src/pc/network/packets/packet_mod_list.c b/src/pc/network/packets/packet_mod_list.c index 8d343aeac..897914e59 100644 --- a/src/pc/network/packets/packet_mod_list.c +++ b/src/pc/network/packets/packet_mod_list.c @@ -236,7 +236,7 @@ void network_receive_mod_list_entry(struct Packet* p) { // sanity check mod size if (mod->size >= MAX_MOD_SIZE) { - djui_popup_create("Server had too large of a mod.\nQuitting.", 4); + djui_popup_create(DLANG(NOTIF, DISCONNECT_BIG_MOD), 4); network_shutdown(false, false, false); return; } diff --git a/src/pc/network/packets/packet_player.c b/src/pc/network/packets/packet_player.c index c93671eb1..2495ff52d 100644 --- a/src/pc/network/packets/packet_player.c +++ b/src/pc/network/packets/packet_player.c @@ -13,6 +13,7 @@ #include "game/mario_misc.h" #include "pc/configfile.h" #include "pc/djui/djui.h" +#include "pc/djui/djui_language.h" #include "pc/debuglog.h" #pragma pack(1) @@ -362,13 +363,7 @@ void network_receive_player(struct Packet* p) { // inform of player death if (oldData.action != ACT_BUBBLED && data.action == ACT_BUBBLED) { - // display popup - char* playerColorString = network_get_player_text_color_string(np->localIndex); - char popupMsg[128] = { 0 }; - snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ died", playerColorString, np->name); - if (configDisablePopups == 0) { - djui_popup_create(popupMsg, 1); - } + construct_player_popup(np, DLANG(NOTIF, DIED), NULL); } // action changed, reset timer @@ -395,11 +390,7 @@ void network_receive_player(struct Packet* p) { } #else if (m->action == ACT_DEBUG_FREE_MOVE && oldData.action != ACT_DEBUG_FREE_MOVE) { - char *playerColorString = network_get_player_text_color_string(np->localIndex); - char message[256]; - snprintf(message, 256, "%s%s\\#dcdcdc\\ entered the debug free fly state", playerColorString, np->name); - djui_popup_create(message, 1); - LOG_INFO("%s entered the debug free fly state", np->name); + construct_player_popup(np, DLANG(NOTIF, DEBUG_FLY), NULL); } #endif