/*
文件名:仓库锁.nut
路径:MyProject/仓库锁.nut
创建日期:2025-12-20	02:19
文件用途:
*/
class WarehouseLockC {

    MysqlObject = null;

    //不允许使用仓库的UID 列表
    NoWarehouseList = null;

    constructor() {
        NoWarehouseList = {};
        MysqlObject = Mysql(Str_Ptr("127.0.0.1"), 3306, Str_Ptr("taiwan_cain"), Str_Ptr("game"), Str_Ptr("uu5!^%jg"));
        MysqlObject.Exec_Sql(format("SET NAMES %s", "latin1"));


        MysqlObject.Select("CREATE TABLE `zyk`.`warehouselock`  (  `uid` int NOT NULL, `passwd` varchar(255) NULL,  PRIMARY KEY (`uid`));", []);



        Cb_History_MileageSet_Func["WarehouseLockC"] <- function(SUser, Data) {
            local Uid = SUser.GetUID();
            //查询uid是否存在于数据库中
            local querySql = "SELECT passwd FROM zyk.warehouselock WHERE uid = " + Uid;
            local result = MysqlObject.Select(querySql, [""]);

            //说明有密码
            if (result && result.len() > 0) {
                NoWarehouseList.rawset(Uid, true);
            }
        }.bindenv(this);

        ClientSocketPackFuncMap.rawset(21008009, function(SUser, Jso) {
            local Uid = SUser.GetUID();
            //查询uid是否存在于数据库中
            local querySql = "SELECT passwd FROM zyk.warehouselock WHERE uid = " + Uid;
            local result = MysqlObject.Select(querySql, [""]);

            //说明有密码
            if (result && result.len() > 0) {
                SUser.SendJso({
                    op = 21008010
                });
            }
        }.bindenv(this));


        ClientSocketPackFuncMap.rawset(21008001, function(SUser, Jso) {
            local Uid = SUser.GetUID();
            //查询uid是否存在于数据库中
            local querySql = "SELECT passwd FROM zyk.warehouselock WHERE uid = " + Uid;
            local result = MysqlObject.Select(querySql, ["string"]);

            local passwd = Jso.passwd;
            //说明有密码
            if (result && result.len() > 0) {
                local sqlpasswd = result[0][0];
                if (passwd == sqlpasswd) {
                    SUser.SendJso({
                        op = 21008002
                    });
                    SUser.SendNotiBox("          验证成功             账号金库限制成功解除", 1);
                    NoWarehouseList.rawdelete(Uid);
                } else {
                    SUser.SendNotiBox("          验证失败             请重新登录游戏以重试", 1);
                }
            }
        }.bindenv(this));


        Cb_Cargo_IsOperatorable_Leave_Func["毁梦定制仓库锁"] <- function(args) {
            local CUser = NativePointer(args[0]).readPointer();
            local SUser = User(CUser);
            local Uid = SUser.GetUID();
            if (NoWarehouseList.rawin(Uid)) {
                return false;
            }
            return null;
        }.bindenv(this);
    }


}



Timer.SetTimeOut(function() {

    getroottable()._WarehouseLock_ <- WarehouseLockC();

    print("双端插件·仓库锁 - 已加载");
}, 1);