Bug #866850

fcdb-enabled server crashes on /take

Added by Louis Moureaux 2 months ago. Updated 23 days ago.

Scripting API
Target version:
Start date:
Due date:
% Done:


Estimated time:


This happened on a 2.6 server with patches but 3.0 and master appear to have the same code. When /taking a nation, the first time one gets a lua error and the second time the server segfaults.

The root cause is that fcdb tries to pass a Nation object to user_take, but Nation is part of the game API which is not imported into the fcdb context. For the first call, tolua fails to set the correct metatable, and afterwards it gets confused and tries to access non existing lua objects/bad indices on the lua stack.

An obvious workaround is to expose the game API to fcdb. That's what I did for the 2.6 longturn branch (attached).

0001-Add-tolua_game-to-the-fcdb-lua-context.patch (1.05 KB) 0001-Add-tolua_game-to-the-fcdb-lua-context.patch 2.6 patch used on Louis Moureaux, 2020-03-29 10:09 PM


#1 Updated by Marko Lindqvist 26 days ago

  • Target version set to 3.0.0

#2 Updated by Marko Lindqvist 25 days ago

  • Status changed from New to Resolved

Louis Moureaux wrote:

The root cause is that fcdb tries to pass a Nation object to user_take

Actually it passes Player, but Nation should then be accessible through it. I think that makes your approach the correct one, and not just an ugly hack. There's a lot of game API stuff behind Player, and custom user_take could sensibly rely on many of those properties. Also, in the future there's likely to be more than just user_take relying on game API.

#3 Updated by Marko Lindqvist 25 days ago

  • Assignee set to Marko Lindqvist

#4 Updated by Marko Lindqvist 23 days ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF