diff options
author | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-08-03 15:38:55 +0000 |
---|---|---|
committer | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-08-03 15:38:55 +0000 |
commit | e8af4bb64be4594cf6ece1b9f05825240107dee1 (patch) | |
tree | 28cbc434df599d9a82a340e3b27cff45b5e52bcb /src/map/script.c | |
parent | 84c9b1b61fbb7c5b7c2d9fa4ba7984cdf80c7612 (diff) | |
download | hercules-e8af4bb64be4594cf6ece1b9f05825240107dee1.tar.gz hercules-e8af4bb64be4594cf6ece1b9f05825240107dee1.tar.bz2 hercules-e8af4bb64be4594cf6ece1b9f05825240107dee1.tar.xz hercules-e8af4bb64be4594cf6ece1b9f05825240107dee1.zip |
Fixed bugreport:6402 when a menu supersedes the client's maximum length it is truncated and a warning is displayed on console, special thanks to Vianna for providing us with the proper length.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16568 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/src/map/script.c b/src/map/script.c index 7d0d9df74..4b8afdb24 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4261,7 +4261,21 @@ BUILDIN_FUNC(menu) } st->state = RERUNLINE; sd->state.menu_or_input = 1; - clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); + + /** + * menus beyond this length crash the client (see bugreport:6402) + **/ + if( StringBuf_Length(&buf) >= 2047 ) { + struct npc_data * nd = map_id2nd(st->oid); + char* menu; + CREATE(menu, char, 2048); + safestrncpy(menu, StringBuf_Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + clif_scriptmenu(sd, st->oid, menu); + aFree(menu); + } else + clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); + StringBuf_Destroy(&buf); if( sd->npc_menu >= 0xff ) @@ -4331,44 +4345,51 @@ BUILDIN_FUNC(select) if( sd == NULL ) return 0; - if( sd->state.menu_or_input == 0 ) - { + if( sd->state.menu_or_input == 0 ) { struct StringBuf buf; StringBuf_Init(&buf); sd->npc_menu = 0; - for( i = 2; i <= script_lastdata(st); ++i ) - { + for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); + if( sd->npc_menu > 0 ) StringBuf_AppendStr(&buf, ":"); + StringBuf_AppendStr(&buf, text); sd->npc_menu += menu_countoptions(text, 0, NULL); } st->state = RERUNLINE; sd->state.menu_or_input = 1; - clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); + + /** + * menus beyond this length crash the client (see bugreport:6402) + **/ + if( StringBuf_Length(&buf) >= 2047 ) { + struct npc_data * nd = map_id2nd(st->oid); + char* menu; + CREATE(menu, char, 2048); + safestrncpy(menu, StringBuf_Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + clif_scriptmenu(sd, st->oid, menu); + aFree(menu); + } else + clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); StringBuf_Destroy(&buf); - if( sd->npc_menu >= 0xff ) - { + if( sd->npc_menu >= 0xff ) { ShowWarning("buildin_select: Too many options specified (current=%d, max=254).\n", sd->npc_menu); script_reportsrc(st); } - } - else if( sd->npc_menu == 0xff ) - {// Cancel was pressed + } else if( sd->npc_menu == 0xff ) {// Cancel was pressed sd->state.menu_or_input = 0; st->state = END; - } - else - {// return selected option + } else {// return selected option int menu = 0; sd->state.menu_or_input = 0; - for( i = 2; i <= script_lastdata(st); ++i ) - { + for( i = 2; i <= script_lastdata(st); ++i ) { text = script_getstr(st, i); sd->npc_menu -= menu_countoptions(text, sd->npc_menu, &menu); if( sd->npc_menu <= 0 ) @@ -4416,7 +4437,20 @@ BUILDIN_FUNC(prompt) st->state = RERUNLINE; sd->state.menu_or_input = 1; - clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); + + /** + * menus beyond this length crash the client (see bugreport:6402) + **/ + if( StringBuf_Length(&buf) >= 2047 ) { + struct npc_data * nd = map_id2nd(st->oid); + char* menu; + CREATE(menu, char, 2048); + safestrncpy(menu, StringBuf_Value(&buf), 2047); + ShowWarning("NPC Menu too long! (source:%s / length:%d)\n",nd?nd->name:"Unknown",StringBuf_Length(&buf)); + clif_scriptmenu(sd, st->oid, menu); + aFree(menu); + } else + clif_scriptmenu(sd, st->oid, StringBuf_Value(&buf)); StringBuf_Destroy(&buf); if( sd->npc_menu >= 0xff ) |