summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorFilesLines
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-22Fix warning: 'T& tmwa::Slice<T>::operator[](size_t) is deprecatedFedja Beader2-9/+13
2024-04-22O(48logN) -> O(1logN) + reformat very long linesFedja Beader1-23/+50
2024-04-22Fix Wformat-zero-length warningsFedja Beader3-5/+0
Squash with: remove empty lines
2024-04-22Fix -Wformat warningsFedja Beader2-5/+5
2024-04-21DB/npc_free_internal: Use ancient approachFreeyorp2-7/+12
C++11 was a really long time ago, huh?
2024-04-21DB: Maybe fix concurrent modificationFreeyorp2-7/+7
2024-04-20getmapmaxx getmapmaxyHoraK-FDF1-0/+26
2024-04-20npc: Deregister events with `ev_db` on freeFreeyorp1-0/+12
In serverdata@c3b7fe59a, `magic-knuckles` made use of temporary copies of the spell NPC via `puppet`/`destroy` to provide additional functionality. This implementation was correct with respect to tmwa behaviour as documented. However, `puppet` and `destroy` doesn't quite return the server to a clean prior state. In `builtin_puppet`, events with the fresh new copy of NPC are registered into the global `ev_db` map to track named events, such as `OnDischarge`, which might be triggered later. However, these registrations are not reversed with `destroy`, leaving `ev_db` to retain references to now invalid and destroyed NPCs. serverdata@c3b7fe59a revealed this oversight through an intersection of rare conditions: - An NPC that is routinely cloned and destroyed - Having a variety of events - Including one that can be triggered during a search for the event over ALL NPCs when `#discharge` is cast. To reproduce, compile with `-fsanitize=address -fsanitize=undefined` to more reliably catch use of invalid memory, cast `magic-knuckles`, log out the character which cast `magic-knuckles` to destroy the NPC, log back in, then cast `#discharge`. The server will then crash. Special thanks to SystemError for testing out this theory. Currently lacking a test environment of my own, this would not have been possible without his patience and diligence.
2024-04-12Add battle_config.max_rate limit (500). GMs cannot go above thisFedja Beader1-28/+35
Blame Ledmitz (:
2024-04-10Add server-wide drop rates modifierFedja Beader2-3/+28
2024-04-10Split @exprate into @bexprate and @jexprateFedja Beader1-0/+44
Preserve @exprate as a shortcut for both & because scripts in serverdata call it
2024-04-10Report (hardcoded) drop rates on same line as base/job exp, reword messages.Fedja Beader1-6/+6
2024-02-22Update test cases for addition of Item Mode fieldFedja Beader1-8/+10
See "Item Mode" commit from Apr 3 2023
2024-02-01Fix bug whereby stat updates were not sent to client after equipping +1 stat ↵Fedja Beader1-1/+1
pt item when base stat is 1. What is funnier is that it sent updates for all other 5 (unchanged stats). Example, amethyst ring +1 dex: Sending update for stat 0: saved: 0+1, new: 0+0 (str?) Sending update for stat 1: saved: 0+1, new: 0+0 (agi?) Sending update for stat 2: saved: 0+1, new: 0+0 (vit?) Sending update for stat 3: saved: 0+1, new: 0+0 (int?) Sending update for stat 5: saved: 0+1, new: 0+0 (luk?)
2024-01-31Transfer something from local/ to live repository so there are less conflictsJesusaves1-2/+2
2023-11-27activity checks and status cleanupHoraK-FDF12-126/+318
2023-11-08SC_MATKPOTHoraK-FDF1-5/+7
2023-08-28Revert magic attack delay to original behaviourv23.10.22Led Mitz1-9/+9
2023-08-03weapon base attack delay standardizationHoraK-FDF9-44/+81
2023-06-10Backport MaxlvlHoraK-FDF1-16/+27
2023-04-04SC_COOLDOWN_UPMARMUHoraK-FDF3-0/+4
2023-04-03Merge branch 'item_mode' into 'master'Led Mitz9-1/+47
Item mode See merge request legacy/tmwa!246
2023-04-03Item modeHoraK-FDF9-1/+47
2023-02-09bAllStats, bAgiVit, bAgiDexStr, bDeadlyStrikeRate, bDeadlyStrikeAddRateHoraK-FDF5-126/+190
2023-01-22bSpeedCapHoraK-FDF3-1/+15
2022-12-23mesn was missing, but now the three minimum functions are here!Jesusaves1-0/+18
2022-12-22Fix a typoJesusaves1-0/+1
2022-12-16mobs critical_def + 10 drops + storage 500HoraK-FDF7-49/+98
2022-12-15Hello=). Someone said its up to GMs to deal with users exploiting their servers.Hello TMW1-0/+11
2022-12-15item bonus and showexprateHoraK-FDF7-227/+479
2022-12-08Merge branch 'equipment_stats' into 'master'HoraK-FDF2-0/+25
Equipment stats See merge request legacy/tmwa!238
2022-12-08Equipment statsHoraK-FDF2-0/+25
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) disabledv2022.11.19Jesusaves1-1/+3
2022-11-17Merge branch 'mobinfo' into 'master'Jesusalva Jesusalva10-55/+721
Mobinfo See merge request legacy/tmwa!237
2022-11-17MobInfoHoraK-FDF10-55/+721
* 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-15Revert the General ASPD Nerf. But retain mages capacity to use Conc Potion.Jesusaves1-2/+2
2022-11-09This is the patch for tomorrow. Have fun :3Jesusaves1-4/+10
- Fix the lighting machine gun bug - Fix upmarmu workings - Reduce nerf factor from 11 to 15
2022-11-09Revert previous commit, but upmarmu is strange and TMWA is not honoring its ↵Jesusaves1-3/+3
own limits. No wonder upmarmu is so powerful, it is easy to be if you ignore max_aspeed parameter. Also, smooth the aspd nerf.
2022-11-09Fix the promised machine gunJesusaves1-2/+3
2022-11-08Nerf the "Red Threshold" attack speed.v22.11.9Jesusaves2-2/+7
2022-11-08Slow down Setzer in 10ms - unnoticeable except in DPS calculations.Jesusaves1-1/+1
2022-11-08Break balance: Potions and Betsanc now affect mages speed (incl. upmarmu).Jesusaves1-2/+3
2022-11-08Remove getusers(0) because it is broken in TMWA (causes a SEGV)Jesusaves1-2/+2
2022-11-05Reduce scope of a variable to prevent possible exploits.Jesusaves1-1/+4
2022-10-26Reintroduce OnPCLogoutEvent labelv22.10.26Jesusaves1-0/+2