/*
文件名:ServerControl.nut
路径:Dps_A/ProjectClass/ServerControl/ServerControl.nut
创建日期:2024-05-01	16:24
文件用途:服务端核心类
*/
function removeBackslashes(str) {
    local result = "";
    local index = 0;
    local backslashIndex = -1;

    while (true) {
        backslashIndex = str.find("\\", index);
        if (backslashIndex == null) {
            result += str.slice(index);
            break;
        }
        result += str.slice(index, backslashIndex);
        index = backslashIndex + 1;
    }

    return result;
}
class ServerControl {

    function Get_User_Item_Count(SUser, ItemId) {
        local InvenObj = SUser.GetInven();
        local SlotIdx = InvenObj.GetSlotById(ItemId);
        if (SlotIdx != -1) {
            local SlotItem = GetSlot(1, SlotIdx);
            if (SlotItem) {
                if (SlotItem.GetType() != "装备") {
                    return {
                        count = SlotItem.GetAdd_Info(),
                        soltidx = SlotIdx
                    };
                }
            }
        }
        return {
            count = 0,
            soltidx = 0
        };
    }

    constructor() {

        //分发来自网关的包
        GatewaySocketPackFuncMap.rawset(20240730, function(Jso) {
            local UserList = [];
            foreach(_index, Value in Jso.uidlist) {
                local SUser = World.GetUserByUid(Value);
                if (SUser) UserList.append(SUser);
                else UserList.append(null);
            }
            foreach(_Index, SUser in UserList) {
                if (SUser) {
                    Jso.uid <- SUser.GetUID();
                    Jso.cid <- SUser.GetCID();
                    Jso.op <- Jso.realop;
                    local Str = Json.Encode(Jso);
                    Str = removeBackslashes(Str);
                    local Pack = Packet();
                    Pack.Put_Header(1, 130);
                    Pack.Put_Byte(1);
                    Pack.Put_Int(Str.len());
                    Pack.Put_Binary(Str);
                    Pack.Finalize(true);
                    SUser.Send(Pack);
                    Pack.Delete();
                    // SUser.SendJso(Jso);
                } else {

                }
            }
        }.bindenv(this));

        //给频道所有玩家分发网关的包
        GatewaySocketPackFuncMap.rawset(20240806, function(Jso) {
            Jso.op <- Jso.realop;
            local Str = Json.Encode(Jso);
            Str = removeBackslashes(Str);
            local Pack = Packet();
            Pack.Put_Header(1, 130);
            Pack.Put_Byte(1);
            Pack.Put_Int(Str.len());
            Pack.Put_Binary(Str);
            Pack.Finalize(true);
            World.SendAll(Pack);
            Pack.Delete();
        }.bindenv(this));


        //给查询指定uid cid列表的玩家信息
        GatewaySocketPackFuncMap.rawset(2023101902, function(Jso) {
            local UserList = [];
            foreach(_index, Value in Jso.uidlist) {
                local SUser = World.GetUserByUid(Value);
                if (SUser) UserList.append(SUser);
                else UserList.append(null);
            }

            local UserInfo = [];
            foreach(_Index, SUser in UserList) {
                if (SUser) {
                    local growjob = SUser.GetCharacGrowType();
                    if (growjob >= 16) {
                        growjob = growjob - 16;
                    }
                    local T = {
                        uid = SUser.GetUID(),
                        cid = SUser.GetCID(),
                        //名字
                        name = SUser.GetCharacName(),
                        //基础职业
                        job = SUser.GetCharacJob(),
                        //转职职业
                        growjob = SUser.GetCharacGrowType(),
                        //觉醒职业
                        Secondjob = SUser.GetCharacSecondGrowType(),
                        //等级
                        level = SUser.GetCharacLevel(),
                        //使用了多少疲劳
                        fatigue = SUser.GetFatigue(),
                        //总疲劳
                        maxfatigue = SUser.GetMaxFatigue(),
                        //是否是GM
                        isgm = SUser.IsGmMode(),
                        //点券
                        cera = SUser.GetCera(),
                        //代币
                        cerapoint = SUser.GetCeraPoint(),
                        //胜点
                        winpoint = SUser.GetWinPoint(),
                        //时装信息
                        avatar = SUser.GetAva()

                    };
                    UserInfo.append(T);
                } else {
                    UserInfo.append(null);
                }
            }

            Jso.op = Jso.realop;
            Jso.userinfo <- UserInfo;
            Socket.SendGateway(Jso);
        });


        //根据名称查询玩家信息
        GatewaySocketPackFuncMap.rawset(20241124, function(Jso) {
            local SUser = World.GetUserByName(Jso.Name);

            if (SUser) {
                local T = {
                    uid = SUser.GetUID(),
                    cid = SUser.GetCID(),
                    //名字
                    name = SUser.GetCharacName(),
                    //基础职业
                    job = SUser.GetCharacJob(),
                    //转职职业
                    growjob = SUser.GetCharacSecondGrowType(),
                    //觉醒职业
                    Secondjob = SUser.GetCharaecondGrowType(),
                    //等级
                    level = SUser.GetCharacLevel(),
                    //使用了多少疲劳
                    fatigue = SUser.GetFatigue(),
                    //总疲劳
                    maxfatigue = SUser.GetMaxFatigue(),
                    //是否是GM
                    isgm = SUser.IsGmMode(),
                    //点券
                    cera = SUser.GetCera(),
                    //代币
                    cerapoint = SUser.GetCeraPoint(),
                    //胜点
                    winpoint = SUser.GetWinPoint(),
                    //时装信息
                    avatar = SUser.GetAva()

                };
                Jso.userinfo <- T;

            } else {
                Jso.userinfo <- null;
            }

            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });

        //将玩家移出副本
        GatewaySocketPackFuncMap.rawset(20240420, function(Jso) {
            local UserList = [];
            foreach(_index, Value in Jso.uidlist) {
                local SUser = World.GetUserByUid(Value);
                if (SUser) UserList.append(SUser);
                else UserList.append(null);
            }
            foreach(_Index, SUser in UserList) {
                if (SUser) {
                    SUser.GiveupDgn();
                }
            }
        });

        //设置服务器最大等级
        GatewaySocketPackFuncMap.rawset(2023110800, function(Jso) {
            Cb_user_setusermaxlevel_Level <- Jso.level;
        });

        //将玩家移出队伍
        GatewaySocketPackFuncMap.rawset(20240418, function(Jso) {
            local UserList = [];
            foreach(_index, Value in Jso.uidlist) {
                local SUser = World.GetUserByUid(Value);
                if (SUser) UserList.append(SUser);
                else UserList.append(null);
            }
            foreach(_Index, SUser in UserList) {
                if (SUser) {
                    SUser.LeaveParty();
                }
            }
        });


        //注册区域不可见hook
        GatewaySocketPackFuncMap.rawset(20241128, function(Jso) {
            local id = Jso.id;
            local Town = Jso.Town;
            local Area = Jso.Area;

            Cb_Insert_User_Func[id] <- function(C_Area, C_User) {
                local SUser = User(C_User);
                if (SUser.GetLocation().Town == Town && SUser.GetLocation().Area == Area) {
                    Sq_WriteAddress(C_Area, 0x68, 1);
                }
            }
        });

        //设置玩家可见
        GatewaySocketPackFuncMap.rawset(20241130, function(Jso) {
            local uids = Jso.uids;

            local RealList = [];
            foreach(uid in uids) {
                local SUser = World.GetUserByUid(uid);
                if (SUser && SUser.GetState() >= 3) RealList.append(SUser);
            }
            foreach(_Index, Value in RealList) {
                local SUser = Value;
                local Pack = Packet();
                Pack.Put_Header(0, 24);
                Pack.Put_Byte(SUser.GetLocation().Town); //城镇
                Pack.Put_Byte(SUser.GetArea(1)); //区域
                Pack.Put_Short((RealList.len() - 1)); //几个玩家  要减去自己
                foreach(__Index, MapObj in RealList) {
                    if (SUser.GetUID() == MapObj.GetUID()) continue;
                    Pack.Put_Short(MapObj.GetUniqueId());
                    Pack.Put_Short(MapObj.GetAreaPos().X);
                    Pack.Put_Short(MapObj.GetAreaPos().Y);
                    Pack.Put_Byte(MapObj.GetDirections()); //朝向
                    Pack.Put_Byte(MapObj.GetVisibleValues()); //是否可见
                }
                Pack.Put_Byte(1); //是否可见
                Pack.Finalize(true);
                SUser.Send(Pack);
                Pack.Delete();
            }
        });

        //退出可见列表
        GatewaySocketPackFuncMap.rawset(20241132, function(Jso) {
            local uids = Jso.uids;
            local uid = Jso.uid;
            local MUser = World.GetUserByUid(uid);

            foreach(_Index, Value in uids) {
                local SUser = World.GetUserByUid(Value);
                if (!SUser || !(SUser.GetState() >= 3) || !MUser || !(MUser.GetState() >= 3)) continue;
                if (SUser.GetUID() == MUser.GetUID()) continue;
                local Pack = Packet();
                Pack.Put_Header(0, 23);
                Pack.Put_Short(MUser.GetUniqueId()); //唯一id
                Pack.Put_Byte(MUser.GetLocation().Town); //城镇


                Pack.Put_Byte(99); //区域
                Pack.Put_Short(MUser.GetAreaPos().X);

                Pack.Put_Short(MUser.GetAreaPos().Y);
                Pack.Put_Byte(MUser.GetDirections()); //朝向
                Pack.Put_Byte(MUser.GetVisibleValues()); //是否可见
                Pack.Finalize(true);

                SUser.Send(Pack);
                Pack.Delete();
            }
        });


        //玩家移动回调
        GatewaySocketPackFuncMap.rawset(20241134, function(Jso) {

            local MoveSUser = World.GetUserByUid(Jso.uid);
            if (!MoveSUser) return;

            local uids = Jso.list;
            local RealList = [];
            foreach(uid in uids) {
                local SUser = World.GetUserByUid(uid);
                if (SUser && SUser.GetState() >= 3) RealList.append(SUser);
            }

            local Pack = Packet();
            Pack.Put_Header(0, 22);
            Pack.Put_Short(MoveSUser.GetUniqueId());
            Pack.Put_Short(Jso.XPos);
            Pack.Put_Short(Jso.YPos);
            Pack.Put_Byte(Jso.Direction);
            Pack.Put_Short(Jso.Code);
            Pack.Finalize(true);


            foreach(_Index, Value in RealList) {
                local SUser = Value;
                if (SUser.GetUniqueId() == MoveSUser.GetUniqueId()) continue;
                SUser.Send(Pack);
            }
            Pack.Delete();
        });

        //给注册玩家使用道具回调
        GatewaySocketPackFuncMap.rawset(2023110702, function(Jso) {
            local ItemId = Jso.ItemId;
            local RealOp = Jso.realop;

            Cb_Use_Item_Sp_Func[ItemId] <- function(SUser, ItemId) {
                local T = {
                    op = RealOp,
                    itemId = ItemId,
                    uid = SUser.GetUID(),
                    cid = SUser.GetCID()
                };
                Socket.SendGateway(T);
            }
        });

        //查询玩家背包里的某个道具
        GatewaySocketPackFuncMap.rawset(2023100802, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            local ItemId = Jso.itemid;
            local num = 0;
            if (SUser) {


                local InvenObj = SUser.GetInven();
                //获取背包对象
                if (ItemId == 0) {

                    num = InvenObj.GetMoney();


                } else {

                    local SlotIdx = InvenObj.GetSlotById(ItemId);

                    local SlotItem = InvenObj.GetSlot(1, SlotIdx);
                    if (SlotItem != null && SlotItem.GetIndex() == ItemId) {
                        local Count = 1;
                        if (SlotItem.GetType() != "装备") {
                            Count = SlotItem.GetAdd_Info();
                        }
                        Jso.Count <- Count;
                        Jso.op = Jso.realop;
                        Socket.SendGateway(Jso);
                        return;
                    }

                    for (local i = 0; i< 120; i++) {
                        local ItemObj = InvenObj.GetSlot(3, i);
                        if (ItemObj != null && ItemObj.GetIndex() == ItemId) {
                            num++;
                        }

                        ItemObj = InvenObj.GetSlot(2, i);
                        if (ItemObj != null && ItemObj.GetIndex() == ItemId) {
                            num++;
                        }
                    };
                }
            }

            Jso.Count <- num;
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });

        //给指定玩家下发道具
        GatewaySocketPackFuncMap.rawset(2023100804, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            if (SUser) {
                local GiveTable = [];
                foreach(_a, v in Jso.result) {

                    //点券
                    if (v.item == -1) {
                        SUser.RechargeCera(v.num);
                        SUser.SendItemSpace(0);
                        continue;
                    }
                    //代币券
                    else if (v.item == -2) {
                        SUser.RechargeCeraPoint(v.num);
                        SUser.SendItemSpace(0);
                        continue;
                    }
                    //金币
                    else if (v.item == 0) {
                        SUser.RechargeMoney(v.num);
                        SUser.SendItemSpace(0);
                        continue;
                    }

                    GiveTable.append({
                        id = v.item,
                        count = v.num
                    });
                }
                SUser.GiveItemEx(GiveTable);
            }
        });

        //给指定玩家下发邮件
        GatewaySocketPackFuncMap.rawset(20240928, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            User.SendItemMail(UID, CID, Jso.result, Jso.title, Jso.content);
        });


        //给指定队伍设置复活币数量
        GatewaySocketPackFuncMap.rawset(20240804, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            if (SUser) {
                local PartyObj = SUser.GetParty();
                if (PartyObj) {
                    PartyObj.SetPartyMemberCoinLimit(Jso.count);
                }
            }
        });


        //查询指定玩家所在队伍的队长cid
        GatewaySocketPackFuncMap.rawset(20240722, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                Jso.PartyPlayer <- [];
                for (local i = 0; i< 4; i++) {
                    local SUserB = PartyObj.GetUser(i);
                    if (SUserB) {
                        Jso.PartyPlayer.append(SUserB.GetCID());
                    }
                }

                local Master = PartyObj.GetMaster();
                if (Master) {
                    Jso.Master <- Master.GetCID();
                }
            }
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });

        //给指定玩家扣除道具
        GatewaySocketPackFuncMap.rawset(2023100806, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            if (SUser) {
                //获取背包对象
                local InvenObj = SUser.GetInven();
                InvenObj.DeleteItemCount(Jso.itemid, Jso.itemcount);
                Jso.op = Jso.realop;
                Socket.SendGateway(Jso);
            }
        });

        //给指定玩家扣除道具 并且会返回是否成功的
        GatewaySocketPackFuncMap.rawset(2023100810, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            if (SUser) {
                //获取背包对象
                local InvenObj = SUser.GetInven();
                Jso.DeleteFlag <- InvenObj.DeleteItemCount(Jso.itemid, Jso.itemcount);
            } else {
                Jso.DeleteFlag <- false;
            }
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });

        //给指定玩家列表扣除道具
        GatewaySocketPackFuncMap.rawset(2023100808, function(Jso) {
            local Flag = true;
            foreach(uid in Jso.uidlist) {
                local SUser = World.GetUserByUid(uid);
                if (SUser) {
                    //获取背包对象
                    local InvenObj = SUser.GetInven();
                    local FlagBuf = InvenObj.CheckArrItemCount([{
                        Id = Jso.itemid,
                        Count = Jso.itemcount,
                    }]);
                    if (!FlagBuf) Flag = false;
                    Jso.Loser <- uid;
                } else {
                    Flag = false;
                }
            }
            if (Flag) {
                foreach(uid in Jso.uidlist) {
                    local SUser = World.GetUserByUid(uid);
                    local InvenObj = SUser.GetInven();
                    InvenObj.DeleteItemCount(Jso.itemid, Jso.itemcount);
                    SUser.SendItemSpace(0);
                }
                Jso.DeleteFlag <- true;
            } else {
                Jso.DeleteFlag <- false;
            }
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });


        //给指定玩家扣除装备 并且会返回是否成功的
        GatewaySocketPackFuncMap.rawset(20250318, function(Jso) {
            local UID = Jso.uid;
            local SUser = World.GetUserByUid(UID);
            if (SUser) {
                local InvenObj = SUser.GetInven();
                local slot = InvenObj.GetSlotById(Jso.itemId);

                if (slot == -1) {
                    Jso.DeleteFlag <- false;
                } else {
                    local itemobj = InvenObj.GetSlot(Inven.INVENTORY_TYPE_ITEM, slot);
                    itemobj.Delete();
                    SUser.SendUpdateItemList(1, 0, slot);
                    Jso.DeleteFlag <- true;

                }
            } else {
                Jso.DeleteFlag <- false;
            }
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });


        //给一个玩家 批量扣除道具
        GatewaySocketPackFuncMap.rawset(20241122, function(Jso) {
            local Flag = true;

            local SUser = World.GetUserByUid(Jso.uid);
            local InvenObj = SUser.GetInven();

            if (SUser) {
                //获取背包对象
                local FlagBuf = InvenObj.CheckArrItemCountRindro(Jso.ItemS);
                if (!FlagBuf) Flag = false;
            } else {
                Flag = false;
            }
            if (Flag) {
                InvenObj.DeleteArrItemCountRindro(Jso.ItemS);
                SUser.SendItemSpace(0);
            }

            Jso.DeleteFlag <- Flag;
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });


        //给一个玩家 设置角色栏上限
        GatewaySocketPackFuncMap.rawset(20250227, function(Jso) {
            local Flag = true;

            local SUser = World.GetUserByUid(Jso.uid);
            if (SUser == null) {
                SUser = WebAddressUser;
            }
            Sq_CallFunc(S_Ptr("0x0869755C"), "int", ["pointer", "int"], SUser.C_Object, Jso.num);

        });



        //给一个玩家 设置当天交易额
        GatewaySocketPackFuncMap.rawset(20250228, function(Jso) {
            local SUser = World.GetUserByUid(Jso.uid);


            SUser.SetTradeGoldDaily(Jso.num);
            print(SUser.GetTradeGoldDaily());
        });

        //设置全服交易上限
        GatewaySocketPackFuncMap.rawset(20250229, function(Jso) {
            GameManager.FixGlodTradeDaily(Jso.num);
        });



        //给一个玩家 批量扣除道具 并且如果第一个道具是装备 就返回装备的强化信息
        GatewaySocketPackFuncMap.rawset(20241210, function(Jso) {
            local Flag = true;

            local SUser = World.GetUserByUid(Jso.uid);
            local InvenObj = SUser.GetInven();

            local ItemObj1 = InvenObj.GetSlot(1, Jso.pos);

            if (SUser) {
                //获取背包对象
                local FlagBuf = InvenObj.CheckArrItemCountRindro(Jso.ItemS);
                if (!FlagBuf) Flag = false;
            } else {
                Flag = false;
            }
            if (Flag) {
                if (!ItemObj1.IsEmpty && ItemObj1.GetType() == "装备") {
                    local forging = ItemObj1.GetForging(); //锻造
                    local upgrade = ItemObj1.GetUpgrade(); //强化
                    local amplification = ItemObj1.GetAmplification(); //增幅
                    local enchanting = ItemObj1.GetEnchanting(); //附魔
                    Jso.up <- [forging, upgrade, amplification, enchanting];
                }
                InvenObj.DeleteArrItemCountRindro(Jso.ItemS);
                SUser.SendItemSpace(0);
            }
            Jso.DeleteFlag <- Flag;
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });

        //给指定玩家下发道具 并且如果道具是装备 就给加上强化信息
        GatewaySocketPackFuncMap.rawset(20241212, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            local item = SUser.GiveItem(Jso.itemId, Jso.count);
            //最后获得的道具
            local reitem = InvenObj.GetSlot(1, item[1]);
            if (reitem.GetType() == "装备") {
                reitem.SetForging(Jso.up[0]);
                reitem.SetUpgrade(Jso.up[1]);
                reitem.SetAmplification(Jso.up[2]);
                reitem.SetEnchanting(Jso.up[3]);
                reitem.Flush();
            }
        });

        //公告包
        GatewaySocketPackFuncMap.rawset(2023082102, function(Jso) {
            World.SendNotiPacketMessage(Jso.str, Jso.type);
        });
        //单人公告包
        GatewaySocketPackFuncMap.rawset(2024012700, function(Jso) {
            local UID = Jso.uid;
            local CID = Jso.cid;
            local SUser = World.GetUserByUidCid(UID, CID);
            if (SUser) {
                if (Jso.type == -1) {
                    SUser.SendNotiBox(Jso.str, 1);
                } else {
                    SUser.SendNotiPacketMessage(Jso.str, Jso.type);
                }
            }
        });

        //获取玩家位置信息
        GatewaySocketPackFuncMap.rawset(20241126, function(Jso) {
            local SUser = World.GetUserByUid(Jso.uid);
            local Info = SUser.GetLocation();
            local list = [];
            list.append(Info.Town);
            list.append(Info.Area);
            list.append(Info.Pos.X);
            list.append(Info.Pos.Y);
            Jso.Location <- list;
            Jso.op = Jso.realop;
            Socket.SendGateway(Jso);
        });

        //玩家进入副本
        Cb_History_DungeonEnter_Func["RindroGoDgn"] <- function(SUser, Data) {
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                local Bfobj = PartyObj.GetBattleField();
                local DgnObj = Bfobj.GetDgn();
                if (DgnObj) {
                    local Dungeon_Id = DgnObj.GetId();
                    local Dungeon_Name = DgnObj.GetName();
                    local Dungeon_Level = DgnObj.GetMinLevel();
                    local Hell_Info = Bfobj.GetHellDifficulty();
                    local UserArr = [];
                    PartyObj.ForeachMember(function(SUser, Pos) {
                        UserArr.append({
                            PUID = SUser.GetUID(),
                            PCID = SUser.GetCID(),
                            PNAME = SUser.GetCharacName(),
                            PLEVEL = SUser.GetCharacLevel(),
                        });
                    })
                    local T = {
                        op = 25001039,
                        PDungeon_Id = Dungeon_Id,
                        PDungeon_Name = Dungeon_Name,
                        PDungeon_Level = Dungeon_Level,
                        PHell_Info = Hell_Info,
                        RESULT = UserArr
                    }
                    Socket.SendGateway(T);
                }
            }
        }



        //给注册玩家通关副本
        GatewaySocketPackFuncMap.rawset(2023110704, function(Jso) {
            local RealOp = Jso.realop;
            Cb_ClearDungeon_Enter_Func[RealOp] <- function(arg) {
                local PartyObj = Party(arg[0]);
                if (PartyObj) {
                    local Bfobj = PartyObj.GetBattleField();
                    local DgnObj = Bfobj.GetDgn();
                    if (DgnObj) {
                        local Dungeon_Id = DgnObj.GetId();
                        local Dungeon_Name = DgnObj.GetName();
                        local Dungeon_Level = DgnObj.GetMinLevel();
                        local UserArr = [];
                        PartyObj.ForeachMember(function(SUser, Pos) {
                            UserArr.append({
                                PUID = SUser.GetUID(),
                                PCID = SUser.GetCID(),
                                PNAME = SUser.GetCharacName(),
                                PLEVEL = SUser.GetCharacLevel(),
                            });
                        })
                        local T = {
                            op = RealOp,
                            PDungeon_Id = Dungeon_Id,
                            PDungeon_Name = Dungeon_Name,
                            PDungeon_Level = Dungeon_Level,
                            RESULT = UserArr
                        }
                        Socket.SendGateway(T);
                    }
                }
            }
        });

        //离开副本
        Cb_History_DungeonLeave_Func["Rindro_DungeonLeave"] <- function(SUser, Data) {
            local T = {
                op = 25001003,
                cid = SUser.GetCID(),
                uid = SUser.GetUID()
            };
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                local Bfobj = PartyObj.GetBattleField();
                local DgnObj = Bfobj.GetDgn();
                if (DgnObj) {
                    T.dgnid <- DgnObj.GetId();
                    T.dgnname <- DgnObj.GetName();
                    T.dgnminlevel <- DgnObj.GetMinLevel();
                }
                T.PartyPlayer <- [];
                for (local i = 0; i< 4; i++) {
                    local SUserB = PartyObj.GetUser(i);
                    if (SUserB) {
                        T.PartyPlayer.append(SUserB.GetCID());
                    }
                }
            }
            Socket.SendGateway(T);
        }


        //返回选择角色
        Cb_return_select_character_Func["Rindro_return_select_character"] <- function(SUser) {
            local T = {
                op = 25001005,
                cid = SUser.GetCID(),
                uid = SUser.GetUID()
            };
            Socket.SendGateway(T);
        }
        //下线
        Cb_player_exit_Func["Rindro_player_exit"] <- function(SUser) {
            local T = {
                op = 25001007,
                cid = SUser.GetCID(),
                uid = SUser.GetUID()
            };
            Socket.SendGateway(T);
        }
        //放弃副本
        Cb_giveup_dgn_Func["Rindro_player_exit"] <- function(SUser) {
            local T = {
                op = 25001009,
                cid = SUser.GetCID(),
                uid = SUser.GetUID()
            };
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                local Bfobj = PartyObj.GetBattleField();
                local DgnObj = Bfobj.GetDgn();
                if (DgnObj) {
                    T.dgnid <- DgnObj.GetId();
                    T.dgnname <- DgnObj.GetName();
                    T.dgnminlevel <- DgnObj.GetMinLevel();
                }
            }
            Socket.SendGateway(T);
        }
        //玩家上线
        Cb_reach_game_world_Func["Rindro_player_reach_game_world"] <- function(SUser) {
            local T = {
                op = 25001011,
                cid = SUser.GetCID(),
                uid = SUser.GetUID(),
                config = Sq_Game_GetConfig()
            };
            Socket.SendGateway(T);
        }

        //组队HOOK包 加入或者邀请
        Cb_User_Party_Create_Func["Rindro_player_User_Party_Create"] <- function(SUser) {
            local T = {
                op = 25001023,
                uid = SUser.GetUID(),
                cid = SUser.GetCID(),
            }
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                T.PartyPlayer <- [];
                for (local i = 0; i< 4; i++) {
                    local SUserB = PartyObj.GetUser(i);
                    if (SUserB) {
                        T.PartyPlayer.append(SUserB.GetCID());
                    }
                }
            }
            Socket.SendGateway(T);
            return true;
        }

        Cb_UseCoin_Enter_Func["Rindro_PCoinDown"] <- function(args) {
            local SUser = User(args[1]);
            if (SUser) {
                local T = {
                    op = 25001035,
                    uid = SUser.GetUID(),
                    cid = SUser.GetCID(),
                }
                Socket.SendGateway(T);
            }
        }

        //组队HOOK包 同意加入或者同意申请
        Cb_User_Party_Agree_Func["Rindro_player_User_Party_Agree"] <- function(SUser) {
            local T = {
                op = 25001025,
                uid = SUser.GetUID(),
                cid = SUser.GetCID(),
            }
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                T.PartyPlayer <- [];
                for (local i = 0; i< 4; i++) {
                    local SUserB = PartyObj.GetUser(i);
                    if (SUserB) {
                        T.PartyPlayer.append(SUserB.GetCID());
                    }
                }

                local Master = PartyObj.GetMaster();
                if (Master) {
                    T.Master <- Master.GetCID();
                }
            }
            Socket.SendGateway(T);
            return true;
        }

        //组队HOOK包 退出队伍
        Cb_User_Party_Exit_Func["Rindro_player_User_Party_Exit"] <- function(SUser) {
            local T = {
                op = 25001027,
                uid = SUser.GetUID(),
                cid = SUser.GetCID(),
            }
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                T.PartyPlayer <- [];
                for (local i = 0; i< 4; i++) {
                    local SUserB = PartyObj.GetUser(i);
                    if (SUserB) {
                        T.PartyPlayer.append(SUserB.GetCID());
                    }
                }

                local Master = PartyObj.GetMaster();
                if (Master) {
                    T.Master <- Master.GetCID();
                }
            }
            Socket.SendGateway(T);
            return true;
        }
        //组队HOOK包 委任队长
        Cb_User_Party_GiveMaster_Func["Rindro_player_User_Party_GiveMaster"] <- function(SUser) {
            local T = {
                op = 25001029,
                uid = SUser.GetUID(),
                cid = SUser.GetCID(),
            }
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                T.PartyPlayer <- [];
                for (local i = 0; i< 4; i++) {
                    local SUserB = PartyObj.GetUser(i);
                    if (SUserB) {
                        T.PartyPlayer.append(SUserB.GetCID());
                    }
                }

                local Master = PartyObj.GetMaster();
                if (Master) {
                    T.Master <- Master.GetCID();
                }
            }

            Socket.SendGateway(T);

            return true;
        }
        //组队HOOK包 踢出队伍
        Cb_User_Party_Kick_Func["Rindro_player_User_Party_GiveMaster"] <- function(SUser) {
            local T = {
                op = 25001031,
                uid = SUser.GetUID(),
                cid = SUser.GetCID(),
            }
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                T.PartyPlayer <- [];
                for (local i = 0; i< 4; i++) {
                    local SUserB = PartyObj.GetUser(i);
                    if (SUserB) {
                        T.PartyPlayer.append(SUserB.GetCID());
                    }
                }

                local Master = PartyObj.GetMaster();
                if (Master) {
                    T.Master <- Master.GetCID();
                }
            }
            Socket.SendGateway(T);
            return true;
        }

        //角色上线包

        //上线HOOK
        // Cb_History_IPUp_Func.ServerControl <- function(UID, CID, Data) {
        //     local T = {
        //         op = 25001017,
        //         cid = UID,
        //         uid = CID,
        //     };
        //     Socket.SendGateway(T);
        // };

        //副本清除
        Cb_History_DungeonClearInfo_Func.ServerControl <- function(SUser, Data) {
            local PartyObj = SUser.GetParty();
            if (PartyObj) {
                local T = {
                    op = 25001019,
                    cid = SUser.GetCID(),
                    uid = SUser.GetUID(),
                    state = PartyObj.Get_Dgn_Clear_State()
                };
                Socket.SendGateway(T);
            }
        };


        Cb_GetUserInfo_Leave_Func.ServerControl <- function(args) {
            if (args.pop() >= 0) {
                local SUser = User(args[1]);
                local Unid = NativePointer(args[2]).add(13).readShort();
                local OtherUser = World.GetUserBySession(Unid);
                if (OtherUser && SUser) {
                    local Jso = {
                        seeUid = SUser.GetUID(),
                        seeCid = SUser.GetCID(),
                        viewedUid = OtherUser.GetUID(),
                        viewedCid = OtherUser.GetCID(),
                        op = 20069009
                    }
                    Socket.SendGateway(Jso);
                }
            }
        }


        //任务完成
        Cb_fnStatQuestClear_Enter_Func.ServerControl <- function(args) {
            local SUser = User(args[0])
            local Jso = {
                uid = SUser.GetUID(),
                cid = SUser.GetCID(),
                queId = args[1],
                op = 25001041
            }
            print(Jso);
            Socket.SendGateway(Jso);
        };



        // 登录游戏时点击开始游戏的回调
        Cb_User_Set_WebAddress_Leave_Func.ServerControl <- function(args) {
            local SUser = User(args[0]);

            local Jso = {
                uid = SUser.GetUID(),
                cid = SUser.GetCID(),
                op = 25001043
            }
            Socket.SendGateway(Jso);
            WebAddressUser = SUser;
        }


    }
}
//刚登录游戏没办法从世界里找到这个角色 在这暂存下
WebAddressUser <- null;


ProjectInitFuncMap.P_ServerControl <- ServerControl();