Commit ee01247
committed
Make trade commit atomic instead of dropping undeliverable items
trade_tradecommit() transferred each staged item independently: it called
pc_additem() per item and, on failure, handed that one item back to the
giver and carried on, still completing the trade. The staging path
(trade_tradeadditem) validates the receiver's weight and free slots but
never the per-item MAX_AMOUNT stack cap, so a deal that pushes a stack
past 30000 was accepted into the window, then silently lost that item at
commit while the rest of the trade went through.
Pre-validate both directions before touching any inventory: mirror the
npc_buylist() checks (per-item pc_checkadditem for the stack cap, plus
cumulative weight and free-slot counts) and cancel the entire trade if
either side cannot receive everything the other staged. Nothing transfers
unless all of it can, so partners keep exactly what they had on a failed
deal rather than losing items to a partial commit.
Tell both players why the trade was canceled: the client ignores the fail
field on the trade-complete packet (0x00f0), so send the reason as a plain
message before cancelling. The blocked player is told they can't hold
everything offered; their partner is told by name.
The per-item give-back branch in the commit loop is now unreachable on the
cap path but is left in place as a defensive fallback.1 parent 54ff3dc commit ee01247
1 file changed
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
354 | 396 | | |
355 | 397 | | |
356 | 398 | | |
| |||
389 | 431 | | |
390 | 432 | | |
391 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
392 | 457 | | |
393 | 458 | | |
394 | 459 | | |
| |||
0 commit comments