summaryrefslogtreecommitdiff
path: root/src/map/script-fun.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-05-17Mages Quality Of Life, part 2:Hello=)1-2/+2
This commit lands fix for infamous AFK-kill summons exploit. Its what essentially caused summoner spells in cities to be disabled. This is not free lunch: it comes at expense of little fun where mob would bite bad master hitting it. But its been minor fun or cosmetics while spells restriction in cities and so on is annoying setback for mages. So if choosing between evil and even more evil, guess... Technically, server's bug is: it too eager to reattach some things to wrong RID or something like this. Its what causes aggroed mob to lock on really wrong random targets and AFK-kill them.
2024-05-15bugfix for previous commit. Need to wrap MobMode in bool()asuratva1-1/+1
2024-05-15fix issummon function signature. Thanks @HoraK-FDF for catching the typo.asuratva1-1/+1
2024-05-15updated itenplz fix to use mob flag instead of string comparison. More ↵asuratva1-2/+2
efficient. Credit to @Hello for figuring this out :)
2024-05-15Add function to check for summoned creature in scriptsasuratva1-0/+18
2024-04-29npc_destroy: Defer NPC destruction via timerFreeyorp1-2/+13
055-1 _nodes.txt will call `destroy;` from within OnInit, that is during an iteration of the global `ev_db`. Previously, concurrent modification invalidated this iteration, resulting in a crash. This still nullifes `oid`, dequeues all timers, and effectively calls `builtin_end`. `npc_data::deletion_pending` is extended to include a third state. In addition to no deletion happening, and indicating when `npc_free` is currently on the stack, it now also tracks whether the NPC is about to be deleted by a timer. This means that an NPC which is about to be deleted is still blocked from triggering new events, much like an NPC actively being deleted would. Starting or continuing an NPC dialog with an NPC that does not, or is about to no longer exist, is now also blocked.
2024-04-22script-fun: Convert string literals to LStringFreeyorp1-83/+83
This is some rather impressive type safety, albeit safety that has evidently desensitized people to warnings for rather serious problems.
2024-04-22script_nullpo_end: Change error printf fmt -> argFreeyorp1-4/+4
PR !270 is an ongoing investigation into outstanding compiler warnings. One such warning is `warning: format '%s' expects a matching 'char*' argument` from `script_nullpo_end(nd, STRPRINTF("no such npc: '%s'"_fmt, name));` in `src/map/script-fun.cpp`. No such warning is emitted from a similar line in `src/map/atcommand.cpp`: `AString output = STRPRINTF("Jump to %s"_fmt, npc);`. `script_nullpo_end` is a macro, rather than a function. `error` is passed in verbatim by the preprocessor. The macro definition of `script_nullpo_end` includes lines such as the following: ```cpp PRINTF("script:%s: " #error " @ %s\n"_fmt, BUILTIN_NAME(), nullpo_nd->name); ``` `#<variable>` instructs the preprocessor to transform `<variable>` into a literal string. In this case, the string literal: ```cpp "STRPRINTF(\"no such npc: '%s'\"_fmt, name)" ``` So the entire line partly resolves to something like: ```cpp printf("script:%s: STRPRINTF(\"no such npc: '%s'\"_fmt, name) @ %s\n"_fmt, BUILTIN_NAME(), nullpo_nd->name); ``` Once the compiler sees this, it throws out the warning seen here, because printf is seeing three placeholders in the formatter, but is only given two value arguments. Checking with `gcc -E`, the full expansion is as follows: ```cpp if (nullpo_chk("script-fun.cpp", 4885, __PRETTY_FUNCTION__, nd)) { if (st->oid) { dumb_ptr<npc_data> nullpo_nd = map_id_is_npc(st->oid); if (nullpo_nd && nullpo_nd->name) { ({ struct format_impl { constexpr static FormatString print_format() __asm__("_print_format") { return "script:%s: " "STRPRINTF(\"no such npc: '%s'\"_fmt, npc)" " @ %s\n"_fmt; } }; cxxstdio::PrintFormatter<format_impl>::print(( # 4885 "script-fun.cpp" 3 4 stdout # 4885 "script-fun.cpp" ), (builtin_functions[st->stack->stack_datav[st->start].get_if<ScriptDataFuncRef>()->numi].name), nullpo_nd->name); }); } else if (nullpo_nd) { ({ struct format_impl { constexpr static FormatString print_format() __asm__("_print_format") { return "script:%s: " "STRPRINTF(\"no such npc: '%s'\"_fmt, npc)" " (unnamed npc)\n"_fmt; } }; cxxstdio::PrintFormatter<format_impl>::print(( # 4885 "script-fun.cpp" 3 4 stdout # 4885 "script-fun.cpp" ), (builtin_functions[st->stack->stack_datav[st->start].get_if<ScriptDataFuncRef>()->numi].name)); }); } else { ({ struct format_impl { constexpr static FormatString print_format() __asm__("_print_format") { return "script:%s: " "STRPRINTF(\"no such npc: '%s'\"_fmt, npc)" " (no npc)\n"_fmt; } }; cxxstdio::PrintFormatter<format_impl>::print(( # 4885 "script-fun.cpp" 3 4 stdout # 4885 "script-fun.cpp" ), (builtin_functions[st->stack->stack_datav[st->start].get_if<ScriptDataFuncRef>()->numi].name)); }); } } else { ({ struct format_impl { constexpr static FormatString print_format() __asm__("_print_format") { return "script:%s: " "STRPRINTF(\"no such npc: '%s'\"_fmt, npc)" " (no npc)\n"_fmt; } }; cxxstdio::PrintFormatter<format_impl>::print(( # 4885 "script-fun.cpp" 3 4 stdout # 4885 "script-fun.cpp" ), (builtin_functions[st->stack->stack_datav[st->start].get_if<ScriptDataFuncRef>()->numi].name)); }); } st->state = ScriptEndState::END; return; }; ``` Note the string literal: `"STRPRINTF(\"no such npc: '%s'\"_fmt, npc)"`. `script_nullpo_end` currently can't take as its argument for `error` any expression which, when stringified, contains something which `printf` will interpret as its formatter expecting another argument. This appears to have been broken since it was first introduced in https://git.themanaworld.org/legacy/tmwa/-/commit/594eafd4f231a897cbefd since the first revision implicitly had these requirements, and also introduced usage which didn't meet them. This rewrites each PRINTF line in `script_nullpo_end` from the template ```cpp PRINTF("script:%s: " #error " @ %s\n"_fmt, BUILTIN_NAME(), nullpo_nd->name); ``` to something like ```cpp PRINTF("script:%s: %s @ %s\n"_fmt, BUILTIN_NAME(), error, nullpo_nd->name); ``` This means that instead of an expression being stringified, error is interpreted as an expression that resolves (or decays) to a string. This seems consistent with all current usage of `script_nullpo_end`.
2024-04-20getmapmaxx getmapmaxyHoraK-FDF1-0/+26
2023-11-27activity checks and status cleanupHoraK-FDF1-5/+16
2023-04-04SC_COOLDOWN_UPMARMUHoraK-FDF1-0/+1
2022-12-23mesn was missing, but now the three minimum functions are here!Jesusaves1-0/+18
2022-12-16mobs critical_def + 10 drops + storage 500HoraK-FDF1-0/+29
2022-12-08Introduce mesq() for compatibility with Evol2Jesusaves1-0/+15
2022-12-08Add l() function for compatibility with Evol2 scriptsJesusaves1-0/+14
2022-11-19summon fixHoraK-FDF1-1/+1
2022-11-17Keep getusers(0) disabledJesusaves1-1/+3
2022-11-17MobInfoHoraK-FDF1-8/+433
* includes @mobinfo ingame command aswell as mobinfo functions for scripts * enhanced summon script command to take a name to support spawn names * moved @summon to where other mob related commands are * added enchanter and koyntety cooldown symbols * some translations * some constants added for drops and mobs
2022-11-08Nerf the "Red Threshold" attack speed.Jesusaves1-2/+2
2022-11-08Remove getusers(0) because it is broken in TMWA (causes a SEGV)Jesusaves1-2/+2
2022-10-24Sc cooldown added frillyar and kaflosh status symbols and <1s fixHoraK-FDF1-8/+23
2022-10-23Added get all reg2, get single reg2, set/add reg2 and del reg2 to ↵HoraK-FDF1-63/+368
tmwa-admin. Fixed communication from char server to login server. Added translations and comments. Minor QoL.
2020-07-06ensure that returning builtins always return, else abortgumi1-6/+6
2020-07-06fix formatting of the script nullpo macrogumi1-12/+16
2020-07-06abort script execution when encountering a null pointergumi1-121/+106
2019-08-28Revert the changes from the last 2 releasesgumi1-0/+1
battle.cpp is very messy and full of bugs
2019-08-26fix mob slaves not attackinggumi1-1/+0
2019-04-15add gm automod toolgumi1-1/+3
2019-01-11drop support for gcc-5, gcc-6, clang-4, clang-5 in travis and fix some misc ↵gumi1-0/+2
issues
2018-03-23Fix NPC script softlockv18.3.22Freeyorp1-0/+11
When an NPC called destroy; from an attached script, npc_id, and associated state, was not properly cleared. This meant that the server considered the PC to still be in conversation, preventing many actions including walking, but with an invalid NPC. This clears state for the specific case of the a PC attached to the script instance that called destroy. It is still not safe to call destroy; if other players may be attached to it.
2018-03-08fix some out-of-memory reads in script builtinsgumi1-3/+3
2018-02-17remove unused variablesgumi1-1/+0
2018-01-29fix the nullpo check in builtin_getcharidv18.1.29.1gumi1-1/+4
2018-01-29cowardly abort script if sd is missingv18.1.29gumi1-77/+100
2018-01-28make the player stand while attacking with overridesgumi1-0/+3
2018-01-28allow to specify charges for magic overridegumi1-2/+2
2018-01-03remove mob timers, make areatimer only work on PCgumi1-10/+0
2018-01-01release v18.1.1v18.1.1gumi1-1/+4
2016-11-26Merge pull request #226 from mekolat/settilesv16.11.27mekolat1-0/+33
Implement SMSG_MAP_SET_TILES_TYPE
2016-05-13implement SMSG_MAP_SET_TILES_TYPE, add builtin sendcollisionmekolat1-0/+33
2016-05-12allow to use npctalk on non-script npcsmekolat1-3/+3
2016-05-01allow foreach to have a targetmekolat1-3/+12
2016-05-01allow addtimer to have a targetmekolat1-2/+14
2016-05-01revert attachrid modification for now, will be deprecated soon enoughmekolat1-11/+1
2016-05-01Merge pull request #216 from mekolat/aggravatemekolat1-26/+8
simplify `aggravate` builtin
2016-05-01Merge pull request #217 from mekolat/overridemekolat1-14/+24
override modifications
2016-05-01make builtin_overrideattack take no charge, allow to dischargemekolat1-14/+24
2016-04-30simplify `aggravate` builtinmekolat1-26/+8
2016-04-28Make getmap take target_idwushin1-2/+8
2016-04-25yay! another bug! (move assert in builtin_explode)v16.4.25.2mekolat1-1/+3