- Port server core and libraries to Linux and 32-bit ARM (armhf): * Replace FreeBSD kqueue with Linux epoll in libthecore fdwatch * Fix unaligned float and 64-bit int memory stores in utils.h str_to_number to avoid ARM VFP alignment fault (SIGBUS) * Fix getopt loop variable type in main.cpp (char -> int) to eliminate infinite loop caused by default unsigned char on ARM * Add -fsigned-char and multi-architecture flags to Makefiles (x86_64 -m32, i386, and ARM armhf) * Update libsql for modern MariaDB client library (removed reconnect field) and C++20 concept/syntax compatibility * Replace Win32 xdirent with standard POSIX dirent on Unix/Linux * Include xmd5 in libthecore on non-FreeBSD platforms - AVA2 unlock features and tools: * Material stacking up to 2000 count, refine material resolution and test suites * AVA2 ticket shop and point drop configuration updates
52 lines
3.2 KiB
Python
52 lines
3.2 KiB
Python
"""Compile actual merge/split metadata helpers with an explicit attribute-lock DB boundary."""
|
|
from pathlib import Path
|
|
import subprocess,tempfile,unittest
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
class Identity(unittest.TestCase):
|
|
def test_actual_helpers_preserve_identity_and_fail_closed(self):
|
|
source=(ROOT/'src/server/game/src/item.cpp').read_bytes().decode('latin1')
|
|
actual=source[source.index('bool CItem::CanStackWith('):source.index('DWORD CItem::GetCount()')]
|
|
prefix=r'''
|
|
#include <cassert>
|
|
#include <cstring>
|
|
#include <cstdint>
|
|
struct Proto {unsigned dwVnum=30006,dwAntiFlags=0;};
|
|
constexpr unsigned ITEM_FLAG_STACKABLE=4,ITEM_ANTIFLAG_STACK=32768;
|
|
struct Extra {unsigned char bytes[69]={};};
|
|
struct CItem {Proto proto;const Proto* m_pProto=&proto;unsigned m_dwVnum=30006,m_dwMaskVnum=0,m_dwSIGVnum=0,m_lFlag=4;
|
|
bool m_bExchanging=false,m_isLocked=false,m_portAttrLockLoaded=false;unsigned m_portAttrLock=0,storedMask=0;
|
|
int32_t m_alSockets[3]={};unsigned char m_aAttr[21]={};Extra m_portExtra;
|
|
unsigned GetOriginalVnum(){return m_dwVnum;}const int32_t* GetSockets(){return m_alSockets;}
|
|
void SetSockets(const int32_t* s){memcpy(m_alSockets,s,sizeof(m_alSockets));}void CopyAttributeTo(CItem* x){memcpy(x->m_aAttr,m_aAttr,sizeof(m_aAttr));}
|
|
const Extra& GetPortExtra(){return m_portExtra;}void SetPortExtra(const Extra& x){m_portExtra=x;}
|
|
bool CanStackWith(const CItem*)const;bool CopyStackStateTo(CItem*);
|
|
};
|
|
static bool failRead=false,failWrite=false;
|
|
unsigned PortAttrLockGet(CItem* x){if(!x->m_portAttrLockLoaded&&!failRead){x->m_portAttrLock=x->storedMask;x->m_portAttrLockLoaded=true;}return x->m_portAttrLock;}
|
|
bool PortAttrLockSet(void*,CItem* x,unsigned m){if(failWrite)return false;x->storedMask=x->m_portAttrLock=m;return x->m_portAttrLockLoaded=true;}
|
|
'''
|
|
cases=r'''
|
|
int main(){CItem a,b;assert(a.CanStackWith(&b));
|
|
b.m_alSockets[0]=1;assert(!a.CanStackWith(&b));b.m_alSockets[0]=0;
|
|
b.m_aAttr[20]=1;assert(!a.CanStackWith(&b));b.m_aAttr[20]=0;
|
|
b.m_portExtra.bytes[68]=1;assert(!a.CanStackWith(&b));b.m_portExtra.bytes[68]=0;
|
|
b.storedMask=1;b.m_portAttrLockLoaded=false;assert(!a.CanStackWith(&b));assert(b.m_portAttrLockLoaded);
|
|
a.storedMask=1;a.m_portAttrLockLoaded=false;assert(a.CanStackWith(&b));
|
|
b.m_isLocked=true;assert(!a.CanStackWith(&b));b.m_isLocked=false;
|
|
b.m_bExchanging=true;assert(!a.CanStackWith(&b));b.m_bExchanging=false;
|
|
b.proto.dwAntiFlags=ITEM_ANTIFLAG_STACK;assert(!a.CanStackWith(&b));b.proto.dwAntiFlags=0;
|
|
b.m_dwVnum++;assert(!a.CanStackWith(&b));b.m_dwVnum--;
|
|
b.m_dwMaskVnum=99;assert(!a.CanStackWith(&b));b.m_dwMaskVnum=0;
|
|
b.m_dwSIGVnum=1;assert(!a.CanStackWith(&b));b.m_dwSIGVnum=0;
|
|
a.m_alSockets[2]=123;a.m_aAttr[20]=9;a.m_portExtra.bytes[68]=7;
|
|
CItem split;failWrite=true;assert(!a.CopyStackStateTo(&split));failWrite=false;assert(a.CopyStackStateTo(&split));
|
|
assert(split.storedMask==1&&a.CanStackWith(&split));
|
|
CItem unavailable;failRead=true;assert(!unavailable.CopyStackStateTo(&split)&&!unavailable.CanStackWith(&b));
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory() as td:
|
|
p=Path(td)/'probe.cpp';p.write_text(prefix+actual+cases);exe=Path(td)/'probe'
|
|
subprocess.run(['c++','-std=c++17','-fsanitize=address,undefined',str(p),'-o',str(exe)],check=True)
|
|
subprocess.run([str(exe)],check=True)
|
|
if __name__=='__main__':unittest.main()
|