• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 0.X tfs 0.4 - server crash with the script why?

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
Hi, i'm using tfs 0.4 version 8.6.

I created an item that when equipped in the body, the player gains a storage ... and when this item is removed from the body, it loses the storage (everything works perfectly).
But there is a great bug and I tested it in tfs 0.4, I tested it otx and also has the same bug.

the bug occurs when the item is created directly for the body, for example when you use / i 2647 and the item falls on your head,(in my server this item is a helmeth) if you throw the item on the ground or look the item, the server crashes.
If it is created straight to the backpack, the server does not crash and everything works fine.

script in movements
Code:
function onEquip(cid, item, slot)
     setPlayerStorageValue(cid,1050,1)
     doPlayerSendTextMessage(cid, 22, "Storage added.")
return true
end


function onDeEquip(cid, item, slot)
     setPlayerStorageValue(cid,1050,-1)
     doPlayerSendTextMessage(cid, 22, "Storage Removed.")
return true
end

movements.xml
Code:
<movevent type="Equip" itemid="2647" slot="head" event="script" value="test.lua"/>
    <movevent type="DeEquip" itemid="2647" slot="head" event="script" value="test.lua"/>


GDB Log, when move a item:
Code:
Segmentation fault (core dumped)
root@proxy:/home/narutoBW# gdb theforgottenserver core.3
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from theforgottenserver...(no debugging symbols found)...done.
warning: core file may not match specified executable file.
[New LWP 5184]
[New LWP 5183]
[New LWP 5186]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./theforgottenserver'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00000000004bcbaf in Game::playerMoveThing(unsigned int, Position const&, unsigned short, short, Position const&, unsigned char) ()
[Current thread is 1 (Thread 0x7f0d2a83f700 (LWP 5184))]
(gdb) bt full
#0  0x00000000004bcbaf in Game::playerMoveThing(unsigned int, Position const&, unsigned short, short, Position const&, unsigned char) ()
No symbol table info available.
#1  0x00000000004c1385 in boost::detail::function::void_function_obj_invoker0<boost::_bi::bind_t<bool, boost::_mfi::mf6<bool, Game, unsigned int, Position const&, unsigned short, short, Position const&, unsigned char>, boost::_bi::list7<boost::_bi::value<Game*>, boost::_bi::value<unsigned int>, boost::_bi::value<Position>, boost::_bi::value<unsigned short>, boost::_bi::value<short>, boost::_bi::value<Position>, boost::_bi::value<unsigned char> > >, void>::invoke(boost::detail::function::function_buffer&) ()
No symbol table info available.
#2  0x000000000049ba1a in Dispatcher::dispatcherThread(void*) ()
No symbol table info available.
#3  0x00007f0d2e8095d5 in ?? ()
   from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0
No symbol table info available.
#4  0x00007f0d2d4ec6ba in start_thread (arg=0x7f0d2a83f700)
    at pthread_create.c:333
        __res = <optimized out>
        pd = 0x7f0d2a83f700
        now = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {139694524593920,
                -8886045072608894631, 0, 140737036462271, 139694524594624,
---Type <return> to continue, or q <return> to quit---


GDB log when look a item:

Code:
Reading symbols from theforgottenserver...(no debugging symbols found)...done.
warning: core file may not match specified executable file.
[New LWP 5172]
[New LWP 5171]
[New LWP 5173]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./theforgottenserver'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00000000004a4770 in Game::playerLookAt(unsigned int, Position const&, unsigned short, short) ()
[Current thread is 1 (Thread 0x7f9d42233700 (LWP 5172))]
(gdb) bf full
Undefined command: "bf".  Try "help".
(gdb) bt full
#0  0x00000000004a4770 in Game::playerLookAt(unsigned int, Position const&, unsigned short, short) ()
No symbol table info available.
#1  0x000000000049ba1a in Dispatcher::dispatcherThread(void*) ()
No symbol table info available.
#2  0x00007f9d461fd5d5 in ?? ()
   from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0
No symbol table info available.
#3  0x00007f9d44ee06ba in start_thread (arg=0x7f9d42233700)
    at pthread_create.c:333
        __res = <optimized out>
        pd = 0x7f9d42233700
        now = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {140313396197120,
                -4174413149968897944, 0, 140730417527599, 140313396197824,
                9382152, 4119391907147311208, 4119395661795321960},
              mask_was_saved = 0}}, priv = {pad = {0x0, 0x0, 0x0, 0x0},
            data = {prev = 0x0, cleanup = 0x0, canceltype = 0}}}
        not_first_call = <optimized out>
        pagesize_m1 = <optimized out>
        sp = <optimized out>
        freesize = <optimized out>
        __PRETTY_FUNCTION__ = "start_thread"
---Type <return> to continue, or q <return> to quit---
 
Last edited:
I just learned that you can compile with the -g flag and then run gdb ./tfs then you type run and when the system crashes it will tell you exactly where and what line the crash occurred on.
In the makefile look for something like this.
Code:
-D_THREAD_SAFE -D_REENTRANT -Wall -Wextra -Werror -Wno-strict-aliasing -Wno-unused-parameter
then you add the flag -g
Code:
-D_THREAD_SAFE -D_REENTRANT -Wall -g -Wextra -Werror -Wno-strict-aliasing -Wno-unused-parameter
If you have a CMakeList.txt then you look for something like this
Code:
add_compile_options(-Wall -Werror -pipe -fvisibility=hidden)
and add the flag -g
Code:
add_compile_options(-Wall -Werror -g -pipe -fvisibility=hidden)
Doesn't really matter where you add it in the list.

You will need to recompile everything I recommend deleting everything in the build directory before you recompile.
 
I have this problem too, i checked internalAddItem, moveItem etc. but crash is probably something with m_interface in bool MoveEvent::executeEquip function in movement.cpp
maybe someone more experienced can take a look at this?
 
To begin with, in 0.4 the onEquip and onDeEquip functions do not return a boolean value. They return callFunction(cid, item.uid, slot, boolean).
Your server crashes because the onEquip function in 0.4 does not handle equips properly when an item is equipped directly into it's designated slot by using "doPlayerAddItem(cid, itemid)".
If the item is dragged to the slot from elsewhere the function will not crash your server.

You'll have to either do as Villy said & rewrite some of your source code or make a workaround where the item is not directly inserted into it's designated slot via "doPlayerAddItem(cid, itemid)".

Edit: I just realized I did not read through properly, hence half my message is just repeating what's already been said. mb
 
Back
Top