/// <summary>
        /// 加载邮件列表
        /// </summary>
        /// <param name="receiver_idx">收件人</param>
        /// <param name="callback"></param>
        public static void LoadMailList(long receiver_idx, ushort spid, Action <List <MailInfo> > callback)
        {
            string sql = "call SP_MAIL_LIST(" + receiver_idx + ", " + spid + ", " + Time.second_time + ")";

            DBManager.Instance.GetDB(eDBType.Game).Query(sql, (reader) =>
            {
                List <MailInfo> list = new List <MailInfo>();
                while (reader.HasRows && reader.Read())
                {
                    int idx          = 0;
                    MailInfo data    = CommonObjectPools.Spawn <MailInfo>();
                    data.mail_idx    = reader.GetInt64(idx++);
                    data.mail_type   = (eMailType)reader.GetByte(idx++);
                    data.spid        = reader.GetUInt16(idx++);
                    data.sender_idx  = reader.GetInt64(idx++);
                    data.sender_name = reader.GetString(idx++);
                    data.send_time   = reader.GetInt64(idx++);
                    data.expire_time = reader.GetInt32(idx++);
                    data.flags       = reader.GetUInt32(idx++);
                    data.subject     = reader.GetString(idx++);
                    //内容
                    long len     = reader.GetBytes(idx, 0, null, 0, int.MaxValue);
                    ByteArray by = DBUtils.AllocDBArray();
                    reader.GetBytes(idx, 0, by.Buffer, 0, (int)len);
                    by.WriteEmpty((int)len);//直接修改m_tail
                    data.bin_mail_content.Read(by);
                    list.Add(data);
                }
                callback(list);
            });
        }
示例#2
0
 /// <summary>
 /// 同步好友最新数据:玩家上线时触发
 /// </summary>
 public void SyncDataFromUnit()
 {
     foreach (var obj in m_relations)
     {
         RelationInfo info = obj.Value;
         Unit         unit = UnitManager.Instance.GetUnitByIdx(info.char_idx);
         if (unit == null)
         {//取db离线数据
             long            target_char_idx = info.char_idx;
             PlayerInfoForGL data            = CommonObjectPools.Spawn <PlayerInfoForGL>();
             SQLCharHandle.QueryCharacterInfo(target_char_idx, data, (ret) =>
             {
                 if (ret)
                 {
                     RelationInfo db_info;
                     if (m_relations.TryGetValue(target_char_idx, out db_info))
                     {
                         db_info.Copy(data);
                     }
                 }
                 CommonObjectPools.Despawn(data);
                 this.SyncRelation2SS(target_char_idx);
             });
         }
         else
         {
             info.Copy(unit.player_data);
             this.SyncRelation2SS(info.char_idx);
         }
     }
 }
示例#3
0
        private void ProcessWrite(MailWriteInfo info)
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }

            if (info.receiver.char_idx == 0)
            {
                Log.Warning("错误的收件人id:" + info.receiver.char_idx);
                return;
            }

            //存db
            MailInfo mail_info = CommonObjectPools.Spawn <MailInfo>();

            mail_info.mail_type     = eMailType.NORMAL;
            mail_info.spid          = 0;//普通邮件,不区分渠道id
            mail_info.receiver_idx  = info.receiver.char_idx;
            mail_info.sender_idx    = m_char_idx;
            mail_info.sender_name   = player.char_name;
            mail_info.send_time     = Time.second_time;
            mail_info.expire_time   = 0;
            mail_info.delivery_time = 0;
            mail_info.flags         = (uint)eMailFlags.NONE;
            mail_info.subject       = info.subject;
            mail_info.bin_mail_content.content_type = eMailContentType.NORMAL;
            mail_info.bin_mail_content.bin_normal_content.content = info.content;
            SQLMailHandle.CreateMail(mail_info, player.db_id);
            CommonObjectPools.Despawn(mail_info);
        }
示例#4
0
        /// <summary>
        /// 玩家所有物品
        /// </summary>
        public static void LoadItem(long char_idx, DBID db_id, Action <List <ItemInfo> > callback)
        {
            string sql = "call SP_ITEM_LIST(" + char_idx + ")";

            DBManager.Instance.GetDB(eDBType.Game, db_id.game_id).Query(sql, (reader) =>
            {
                List <ItemInfo> list = new List <ItemInfo>();
                while (reader.HasRows && reader.Read())
                {
                    int idx          = 0;
                    ItemInfo data    = CommonObjectPools.Spawn <ItemInfo>();
                    data.item_idx    = reader.GetInt64(idx++);
                    data.char_idx    = reader.GetInt64(idx++);
                    data.type        = (eItemSubType)reader.GetUInt32(idx++);
                    data.bag_type    = (eBagType)reader.GetUInt16(idx++);
                    data.ui_pos      = reader.GetUInt32(idx++);
                    data.number      = reader.GetUInt32(idx++);
                    data.create_time = reader.GetInt64(idx++);
                    //内容
                    long len     = reader.GetBytes(idx, 0, null, 0, int.MaxValue);
                    ByteArray by = DBUtils.AllocDBArray();
                    reader.GetBytes(idx, 0, by.Buffer, 0, (int)len);
                    by.WriteEmpty((int)len);
                    data.bin_content.Read(by);
                    list.Add(data);
                }
                callback(list);
            });
        }
示例#5
0
        /// <summary>
        /// 创建-玩家重新登录
        /// </summary>
        public BaseItem CreateItem(ItemInfo item_info)
        {
            BaseItem prop = CommonObjectPools.Spawn <BaseItem>();

            prop.Init(item_info);
            this.AddItem(prop);
            return(prop);
        }
示例#6
0
 public void Derialize(ByteArray by)
 {
     while (by.Available > 0 && by.Available >= RelationInfo.BaseSize)
     {
         RelationInfo info = CommonObjectPools.Spawn <RelationInfo>();
         info.Read(by);
         m_relations.Add(info.char_idx, info);
     }
 }
示例#7
0
        /// <summary>
        /// 创建-新道具
        /// </summary>
        public BaseItem CreateItem(uint template_idx, uint num)
        {
            long     item_idx = IdSharedManager.Instance.GetNextItemIdx();
            BaseItem prop     = CommonObjectPools.Spawn <BaseItem>();

            prop.Init(item_idx, new ItemTemplateInfo());
            this.AddItem(prop);
            return(prop);
        }
示例#8
0
        /// <summary>
        /// 登入处理
        /// </summary>
        private void OnPlayerLogin(long char_idx)
        {
            this.RemoveMember(char_idx);

            MemberRelation member = CommonObjectPools.Spawn <MemberRelation>();

            member.Setup(char_idx);
            m_cache_members.Add(char_idx, member);
        }
示例#9
0
        /// <summary>
        /// 构建mysql参数
        /// </summary>
        /// <param name="filed">字段</param>
        /// <param name="type">字段类型</param>
        /// <param name="by">内容</param>
        /// <param name="size">内容大小</param>
        /// <returns></returns>
        public static MySqlParameter MakeMysqlParam(string filed, MySqlDbType type, byte[] by, int size)
        {
            MySqlParameter p = CommonObjectPools.Spawn <MySqlParameter>();

            p.ParameterName = filed;
            p.MySqlDbType   = type;
            p.Value         = by;
            p.Size          = size;
            return(p);
        }
示例#10
0
        /// <summary>
        /// 进入游戏
        /// </summary>
        private void OnEnterGame(PacketBase packet)
        {
            gs2ss.EnterGame msg        = packet as gs2ss.EnterGame;
            ClientUID       client_uid = msg.client_uid;
            InterServerID   server_uid = msg.server_uid;

            UnitManager.Instance.AddSession(client_uid);

            if (!UnitManager.Instance.HasUnit(msg.char_idx))
            {
                DBID db_id = new DBID();
                db_id.game_id = ServerConfig.GetDBByAccountIdx(msg.account_idx, eDBType.Game);
                PlayerInfoForSS ss_data = CommonObjectPools.Spawn <PlayerInfoForSS>();
                SQLCharHandle.QueryCharacterInfo(msg.char_idx, db_id, ss_data, is_load =>
                {
                    if (is_load && UnitManager.Instance.HadSession(client_uid))
                    {//读取玩数据,有可能已经退出
                        //创建玩家
                        Player player     = new Player();
                        player.client_uid = client_uid;
                        player.LoadData(ss_data);
                        UnitManager.Instance.AddUnit(player);

                        //告诉gs成功进入游戏
                        ss2gs.EnterGame rep_gs_msg = PacketPools.Get(ss2gs.msg.ENTER_GAME) as ss2gs.EnterGame;
                        rep_gs_msg.server_uid      = server_uid;
                        rep_gs_msg.client_uid      = client_uid;
                        rep_gs_msg.char_idx        = ss_data.char_idx;
                        ServerNetManager.Instance.Send(server_uid.gs_uid, rep_gs_msg);

                        //告诉ws
                        ss2ws.LoginClient rep_ws_msg = PacketPools.Get(ss2ws.msg.LOGIN_CLIENT) as ss2ws.LoginClient;
                        rep_ws_msg.server_uid        = server_uid;
                        rep_ws_msg.client_uid        = client_uid;
                        rep_ws_msg.data.Copy(ss_data);
                        ServerNetManager.Instance.Send2WS(rep_ws_msg);

                        //告诉gl
                        ss2gl.LoginClient rep_gl_msg = PacketPools.Get(ss2gl.msg.LOGIN_CLIENT) as ss2gl.LoginClient;
                        rep_gl_msg.server_uid        = server_uid;
                        rep_gl_msg.data.Copy(ss_data);
                        ServerNetManager.Instance.Send2GL(rep_gl_msg);

                        //告诉客户端角色基础信息
                        ss2c.CharacterInfo rep_msg = PacketPools.Get(ss2c.msg.CHARACTER_INFO) as ss2c.CharacterInfo;
                        rep_msg.data.Copy(ss_data);
                        ServerNetManager.Instance.SendProxy(client_uid, rep_msg, false);

                        //初始化内部逻辑
                        player.OnFirstEnter();
                    }
                    CommonObjectPools.Despawn(ss_data);
                });
            }
        }
示例#11
0
        /// <summary>
        /// 给玩家创建邮箱
        /// </summary>
        private void OnPlayerLogin(long char_idx)
        {
            Mailbox mail_box;

            if (!m_mailboxs.TryGetValue(char_idx, out mail_box))
            {
                mail_box = CommonObjectPools.Spawn <Mailbox>();
                mail_box.Setup(char_idx);
                m_mailboxs.Add(char_idx, mail_box);
            }
        }
示例#12
0
        /// <summary>
        /// 添加aoi对象
        /// </summary>
        /// <param name="char_idx"></param>
        /// <param name="scene_idx"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        public void Add(long char_idx, long scene_idx, int row, int col)
        {
            AOIUnitInfo aoi_info = null;

            if (!m_aoi_units.TryGetValue(char_idx, out aoi_info))
            {
                aoi_info           = CommonObjectPools.Spawn <AOIUnitInfo>();
                aoi_info.char_idx  = char_idx;
                aoi_info.scene_idx = scene_idx;
                m_aoi_units.Add(char_idx, aoi_info);
            }
            UpdatePosition(char_idx, row, col, true);
        }
        public ClientSession AddSession(long conn_idx)
        {
            if (!m_accept_sessions.ContainsKey(conn_idx))
            {
                return(null);
            }

            ClientSession session = CommonObjectPools.Spawn <ClientSession>();

            session.Setup(conn_idx);
            m_sessions.Add(conn_idx, session);
            return(session);
        }
示例#14
0
        public bool AddAccountData(string account_name, AccountData account_data)
        {
            this.RemoveAccountData(account_data.account_idx);

            CacheAccountData cache_chars = CommonObjectPools.Spawn <CacheAccountData>();

            cache_chars.logout_time  = Time.second_time;
            cache_chars.account_data = account_data;
            m_chache_account.Add(account_name, cache_chars);
            m_account_2_name.Add(account_data.account_idx, account_name);

            return(true);
        }
示例#15
0
        public bool AddPlayer(long char_idx)
        {
            if (m_fight_players.ContainsKey(char_idx))
            {
                RemovePlayer(char_idx);
            }
            FightPlayer player = CommonObjectPools.Spawn <FightPlayer>();

            player.Setup(char_idx);
            m_fight_players.Add(char_idx, player);

            return(true);
        }
示例#16
0
        /// <summary>
        /// 登入处理
        /// </summary>
        public void HandleLogin(ushort ss_uid, PlayerInfoForGL data)
        {
            Unit unit = GetUnitByIdx(data.char_idx);

            if (unit != null)
            {
                this.RemoveUnit(unit);
            }
            //创建玩家
            unit = CommonObjectPools.Spawn <Unit>();
            unit.Setup(ss_uid, data);
            UnitManager.Instance.AddUnit(unit);
            unit.OnEnter();
        }
示例#17
0
        /// <summary>
        /// 登入处理
        /// </summary>
        public void HandleLogin(ClientUID client_uid, InterServerID srv_uid, PlayerInfoForFS data)
        {
            Unit unit = GetUnitByIdx(data.char_idx);

            if (unit != null)
            {//可能上次退出时,没有清除数据
                this.RemoveUnit(unit);
            }
            //创建玩家
            unit = CommonObjectPools.Spawn <Unit>();
            unit.Setup(client_uid, srv_uid, data);
            UnitManager.Instance.AddUnit(unit);
            unit.OnEnter();
        }
示例#18
0
        /// <summary>
        /// gl下发的关系列表
        /// </summary>
        public void RelationListGL(RelationInfo info)
        {
            RelationInfo relation_info;

            if (m_relations.TryGetValue(info.char_idx, out relation_info))
            {
                relation_info.Copy(info);
            }
            else
            {
                relation_info = CommonObjectPools.Spawn <RelationInfo>();
                relation_info.Copy(info);
                this.AddRelation(relation_info);
            }
        }
        /// <summary>
        /// 加载单个玩家数据
        /// </summary>
        /// <param name="char_idx"></param>
        public void LoadPlayer(long char_idx, Action <long> callback)
        {
            if (m_cache_members.ContainsKey(char_idx))
            {
                Log.Debug("玩家数据已经加载:" + char_idx);
                if (callback != null)
                {
                    callback(char_idx);
                }
                return;
            }

            Log.Debug("请求加载玩家数据:" + char_idx);
            PlayerCache member = CommonObjectPools.Spawn <PlayerCache>();

            member.Load(char_idx, is_load =>
            {
                if (is_load)
                {
                    m_cache_members.Add(char_idx, member);
                    if (m_cache_name_members.ContainsKey(member.ss_data.char_name))
                    {
                        Log.Warning("存在相同玩家名:" + member.ss_data.char_name);
                    }
                    else
                    {
                        m_cache_name_members.Add(member.ss_data.char_name, char_idx);
                    }
                    if (callback != null)
                    {
                        callback(char_idx);
                    }
                }
                else
                {
                    Log.Warning("玩家数据加载失败:" + char_idx);
                    CommonObjectPools.Despawn(member);
                    if (callback != null)
                    {
                        callback(0);
                    }
                }
            }
                        );
        }
示例#20
0
        /// <summary>
        /// 读取玩家邮箱
        /// </summary>
        /// <param name="char_idx"></param>
        public void LoadMailbox(long char_idx)
        {
            if (m_mailboxs.ContainsKey(char_idx))
            {
                return;
            }

            MailboxCache mail_box = CommonObjectPools.Spawn <MailboxCache>();

            if (mail_box.Setup(char_idx))
            {
                m_mailboxs.Add(char_idx, mail_box);
            }
            else
            {
                CommonObjectPools.Despawn(mail_box);
            }
        }
示例#21
0
        private void ProcessWrite(MailWriteInfo info)
        {
            Player player = UnitManager.Instance.GetUnitByIdx(m_char_idx) as Player;

            if (player == null)
            {
                return;
            }

            if (info.receiver.char_idx == 0)
            {
                Log.Debug("错误的收件人id:" + info.receiver.char_idx);
                return;
            }

            //存db
            MailInfo mail_info = CommonObjectPools.Spawn <MailInfo>();

            mail_info.mail_idx      = IdSharedManager.Instance.GetNextMailIdx();
            mail_info.mail_type     = eMailType.NORMAL;
            mail_info.spid          = 0;//普通邮件,不区分渠道id
            mail_info.receiver_idx  = info.receiver.char_idx;
            mail_info.sender_idx    = m_char_idx;
            mail_info.sender_name   = player.char_name;
            mail_info.send_time     = Time.second_time;
            mail_info.expire_time   = 0;
            mail_info.delivery_time = 0;
            mail_info.flags         = (uint)eMailFlags.NONE;
            mail_info.subject       = info.subject;
            mail_info.bin_mail_content.content_type = eMailContentType.NORMAL;
            mail_info.bin_mail_content.bin_normal_content.content = info.content;
            SQLMailHandle.CreateMail(mail_info, player.db_id);
            CommonObjectPools.Despawn(mail_info);

            //告诉客户端发送成功
            ss2c.MailCommand msg_client = PacketPools.Get(ss2c.msg.MAIL_COMMAND) as ss2c.MailCommand;
            msg_client.mail_idx     = 0;
            msg_client.command_type = eMailCommandType.WRITE_MAIL;
            msg_client.error_type   = eMailCommandError.NONE;
            ServerNetManager.Instance.SendProxy(player.client_uid, msg_client);
        }
示例#22
0
        /// <summary>
        /// 单位进入
        /// </summary>
        private void OnUnitEnter(PacketBase packet)
        {
            ss2c.UnitEnterAOI msg = packet as ss2c.UnitEnterAOI;
            Log.Debug("OnUnitEnter:" + msg.unit_idx.obj_idx);

            Unit unit = null;

            switch (msg.unit_idx.type)
            {
            case eUnitType.PLAYER: unit = CommonObjectPools.Spawn <Player>(); break;
            }
            if (unit == null)
            {
                Log.Warning("未定义类型:" + msg.unit_idx.type);
                return;
            }
            unit.obj_idx = msg.unit_idx.obj_idx;
            unit.Setup();
            unit.LoadData(msg.unit_info);
            UnitManager.Instance.AddUnit(unit);
        }
示例#23
0
        /// <summary>
        /// 场景切换
        /// </summary>
        private void OnEnterScene(PacketBase packet)
        {
            ss2c.EnterScene msg = packet as ss2c.EnterScene;

            UnitManager.Instance.RemoveAll();
            //玩家信息
            PlayerInfoForClient char_info   = PlayerDataMgr.Instance.main_player_info;
            PlayerAOIInfo       player_info = CommonObjectPools.Spawn <PlayerAOIInfo>();

            player_info.char_name = char_info.char_name;
            player_info.char_type = char_info.char_type;
            player_info.pos_x     = msg.pos.x;
            player_info.pos_y     = msg.pos.y;
            player_info.flags     = char_info.flags;
            player_info.model_idx = char_info.model_idx;
            player_info.job       = char_info.job;
            player_info.level     = char_info.level;
            player_info.exp       = char_info.exp;
            player_info.energy    = char_info.energy;
            player_info.gold      = char_info.gold;
            player_info.coin      = char_info.coin;
            player_info.hp        = char_info.hp;
            player_info.hp_max    = char_info.hp_max;
            player_info.hurt      = char_info.hurt;
            player_info.range     = char_info.range;
            player_info.run_speed = char_info.run_speed;
            player_info.vip_grade = char_info.vip_grade;
            player_info.vip_flags = char_info.vip_flags;

            //创建玩家对象
            Player player = new Player();

            player.obj_idx = char_info.char_idx;
            player.Setup();
            player.LoadData(player_info);
            UnitManager.Instance.AddUnit(player);

            EventController.TriggerEvent(ClientEventID.SHOW_STATUS, eFormStatusType.Scene, "当前场景:" + msg.scene_type);
            EventController.TriggerEvent(ClientEventID.SHOW_STATUS, eFormStatusType.Log, "进入场景:" + msg.scene_type);
        }
        private void ProcessWrite(MailWriteInfo info)
        {
            PlayerCache player = PlayerCacheManager.Instance.GetMember(m_char_idx);

            if (player == null)
            {
                return;
            }

            if (info.receiver_idx <= 0)
            {
                Log.Warning("错误的收件人id:" + info.receiver_idx);
                return;
            }
            //存db
            MailInfo mail_info = CommonObjectPools.Spawn <MailInfo>();

            mail_info.mail_type     = eMailType.NORMAL;
            mail_info.spid          = 0;//普通邮件,不区分渠道id
            mail_info.receiver_idx  = info.receiver_idx;
            mail_info.sender_idx    = m_char_idx;
            mail_info.sender_name   = player.ss_data.char_name;
            mail_info.send_time     = Time.second_time;
            mail_info.expire_time   = 0;
            mail_info.delivery_time = 0;
            mail_info.flags         = (uint)eMailFlags.NONE;
            mail_info.subject       = info.subject;
            mail_info.bin_mail_content.content_type = eMailContentType.NORMAL;
            mail_info.bin_mail_content.bin_normal_content.content = info.content;
            SQLMailHandle.CreateMail(mail_info);
            CommonObjectPools.Despawn(mail_info);

            //返回结果给ss
            db2ss.MailCommand rep_msg = PacketPools.Get(db2ss.msg.MAIL_COMMAND) as db2ss.MailCommand;
            rep_msg.mail_idx     = 0;
            rep_msg.command_type = eMailCommandType.WRITE_MAIL;
            rep_msg.error_type   = eMailCommandError.NONE;
            ForServerNetManager.Instance.Send(player.ss_uid, rep_msg);
        }
示例#25
0
        /// <summary>
        /// 添加关系
        /// </summary>
        public void AddRelationCommand(RelationAddTarget target_id, eRelationFlag flag, string message)
        {
            //超过上限
            if (IsRelationFull(flag))
            {
                return;
            }

            //不在线了
            Unit player = UnitManager.Instance.GetUnitByIdx(m_char_idx);

            if (player == null)
            {
                return;
            }

            //判断是否已经存在关系,另外防止添加自己为好友
            if (target_id.type == eRelationAddType.Idx)
            {
                if (target_id.char_idx == m_char_idx)
                {
                    return;
                }
                RelationInfo relation_info;
                if (m_relations.TryGetValue(target_id.char_idx, out relation_info) && relation_info.flags == flag)
                {
                    return;
                }
            }
            else
            {
                if (target_id.char_name == player.char_name)
                {
                    return;
                }
                foreach (var relation_info in m_relations)
                {
                    if (relation_info.Value.char_name == target_id.char_name && relation_info.Value.flags == flag)
                    {
                        return;
                    }
                }
            }

            //如果是根据名称加好友,必须在缓存里面能查找到玩家数据
            Unit target_player = null;

            if (target_id.type == eRelationAddType.Idx)
            {
                target_player = UnitManager.Instance.GetUnitByIdx(target_id.char_idx);
            }
            else if (target_id.type == eRelationAddType.Name)
            {
                target_player = UnitManager.Instance.GetUnitByName(target_id.char_name);
                if (target_player == null)
                {
                    return;//TODO:后期如果有需求,可以查表
                }
                else
                {
                    target_id.char_idx = target_player.char_idx;
                }
            }

            //拉黑直接处理,如果有好友关系,需要先去掉好友
            if (flag == eRelationFlag.Block)
            {
                RelationInfo relation_info;
                if (m_relations.TryGetValue(target_id.char_idx, out relation_info))
                {
                    relation_info.flags = eRelationFlag.Block;
                    this.SyncRelation2SS(target_id.char_idx);
                }
                else
                {
                    if (target_player == null)
                    {
                        PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                        SQLCharHandle.QueryCharacterInfo(target_id.char_idx, data, (ret) =>
                        {
                            if (ret && m_char_idx > 0)
                            {
                                relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                relation_info.Copy(data);
                                relation_info.flags = flag;
                                this.AddRelation(relation_info);
                                this.SyncRelation2SS(target_id.char_idx);
                            }
                            CommonObjectPools.Despawn(data);
                        });
                    }
                    else
                    {
                        relation_info = CommonObjectPools.Spawn <RelationInfo>();
                        relation_info.Copy(target_player.player_data);
                        relation_info.flags = flag;
                        this.AddRelation(relation_info);
                        this.SyncRelation2SS(target_id.char_idx);
                    }
                }
            }

            //添加到db,需要先判断数据库是否已经有写入过,防止重复写入
            //注:如果赠送可以同时存在的话,这里需要屏蔽赠送类型
            SQLRelationHandle.QueryExistsRelationEvent(m_char_idx, target_id.char_idx, flag, (event_idx) =>
            {
                if (event_idx == 0 && m_char_idx > 0)
                {//保存事件
                    RelationEventInfo e_info = new RelationEventInfo();
                    e_info.target_char_idx   = target_id.char_idx;
                    e_info.source_char_idx   = m_char_idx;
                    e_info.event_type        = eRelationEvent.Add;
                    e_info.bin_content.bin_add_content.char_name = player.char_name;
                    e_info.bin_content.bin_add_content.message   = message;
                    e_info.bin_content.bin_add_content.flag      = flag;
                    SQLRelationHandle.InsertRelationEvent(e_info);

                    //立刻通知接受者
                    this.BroadcastEvent(e_info.target_char_idx, e_info.event_type);
                }
            });
        }
示例#26
0
        /// <summary>
        /// 申请反馈
        /// </summary>
        public void ApplyRelationCommand(long event_idx, long target_char_idx, eRelationApplyCmd cmd)
        {
            //是否存在申请事件
            RelationEventInfo relation_evt;

            if (!m_relation_events.TryGetValue(event_idx, out relation_evt))
            {
                return;
            }

            switch (relation_evt.event_type)
            {
            case eRelationEvent.Add:
            {
                eRelationFlag flag = relation_evt.bin_content.bin_add_content.flag;
                if (cmd == eRelationApplyCmd.Agree)
                {
                    //超过上限
                    if (IsRelationFull(flag))
                    {
                        SQLRelationHandle.RemoveRelationEvent(event_idx);
                        m_relation_events.Remove(event_idx);
                        return;
                    }

                    //是否已经存在相同关系:是则返回;非相同关系先移除,再添加
                    RelationInfo relation_info;
                    if (m_relations.TryGetValue(target_char_idx, out relation_info))
                    {
                        if (relation_info.flags == flag)
                        {
                            SQLRelationHandle.RemoveRelationEvent(event_idx);
                            m_relation_events.Remove(event_idx);
                            return;
                        }
                        else
                        {
                            this.RemoveRelation(target_char_idx);
                        }
                    }

                    //如果对方在线,则取对方身上的数据;否则取数据库的数据
                    Unit target_player = UnitManager.Instance.GetUnitByIdx(target_char_idx);
                    if (target_player != null)
                    {
                        relation_info = CommonObjectPools.Spawn <RelationInfo>();
                        relation_info.Copy(target_player.player_data);
                        relation_info.flags = flag;
                        this.AddRelation(relation_info);
                        this.SyncRelation2SS(target_char_idx);
                    }
                    else
                    {
                        PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                        SQLCharHandle.QueryCharacterInfo(target_char_idx, data, (ret) =>
                            {
                                if (ret && m_char_idx > 0)
                                {
                                    relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                    relation_info.Copy(data);
                                    relation_info.flags = flag;
                                    this.AddRelation(relation_info);
                                    this.SyncRelation2SS(target_char_idx);
                                }
                                CommonObjectPools.Despawn(data);
                            });
                    }
                }
                else
                {
                    //undo
                }
                //写入事件
                RelationEventInfo e_info = new RelationEventInfo();
                e_info.target_char_idx = target_char_idx;
                e_info.source_char_idx = m_char_idx;
                e_info.event_type      = eRelationEvent.Agree;
                e_info.bin_content.bin_agree_content.flag = flag;
                e_info.bin_content.bin_agree_content.cmd  = cmd;
                SQLRelationHandle.InsertRelationEvent(e_info);
                //立刻通知接受者
                this.BroadcastEvent(e_info.target_char_idx, e_info.event_type);
            }
            break;
            }

            //清除处理过的事件
            SQLRelationHandle.RemoveRelationEvent(event_idx);

            //从事件列表移除
            m_relation_events.Remove(event_idx);
        }
示例#27
0
        /// <summary>
        /// 处理关系事件
        /// </summary>
        private void HandleRelationEvent(List <RelationEventInfo> list_event)
        {
            //查询过程中如果下线
            if (m_char_idx == 0)
            {
                return;
            }

            Unit player = UnitManager.Instance.GetUnitByIdx(m_char_idx);

            if (player == null)
            {
                return;
            }

            foreach (var relation_evt in list_event)
            {
                switch (relation_evt.event_type)
                {
                case eRelationEvent.Add:    //对方申请加你好友
                {
                    //超过上限
                    if (IsRelationFull(relation_evt.bin_content.bin_add_content.flag))
                    {
                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        continue;
                    }

                    //是否已经存在相同关系
                    RelationInfo relation_info = null;
                    if (m_relations.TryGetValue(relation_evt.source_char_idx, out relation_info) && relation_info.flags == relation_evt.bin_content.bin_add_content.flag)
                    {
                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        continue;
                    }

                    //拉黑不需要同意,所以不添加事件
                    if (relation_evt.bin_content.bin_add_content.flag == eRelationFlag.Block)
                    {
                        if (m_relations.TryGetValue(relation_evt.source_char_idx, out relation_info))
                        {        //已经存在其他关系,则用新关系覆盖旧关系
                            relation_info.flags = eRelationFlag.Block;
                            this.SyncRelation2SS(relation_evt.source_char_idx);
                        }
                        else
                        {
                            Unit target_player = UnitManager.Instance.GetUnitByIdx(relation_evt.source_char_idx);
                            if (target_player == null)
                            {
                                PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                                SQLCharHandle.QueryCharacterInfo(relation_evt.source_char_idx, data, (ret) =>
                                    {
                                        if (ret && m_char_idx > 0)
                                        {
                                            relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                            relation_info.Copy(data);
                                            relation_info.flags = eRelationFlag.Block;
                                            this.AddRelation(relation_info);
                                            this.SyncRelation2SS(relation_evt.source_char_idx);
                                        }
                                        CommonObjectPools.Despawn(data);
                                    });
                            }
                            else
                            {
                                relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                relation_info.Copy(target_player.player_data);
                                relation_info.flags = eRelationFlag.Block;
                                this.AddRelation(relation_info);
                                this.SyncRelation2SS(relation_evt.source_char_idx);
                            }
                        }

                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        m_relation_events.Remove(relation_evt.event_idx);
                    }
                    else
                    {
                        //添加关系事件
                        if (m_relation_events.ContainsKey(relation_evt.event_idx))
                        {
                            continue;
                        }
                        else
                        {
                            m_relation_events.Add(relation_evt.event_idx, relation_evt);
                        }

                        //通知逻辑服,由逻辑服转发给客户端
                        gl2ss.RelationAdd msg = PacketPools.Get(gl2ss.msg.RELATION_ADD) as gl2ss.RelationAdd;
                        msg.event_idx = relation_evt.event_idx;
                        msg.char_idx  = m_char_idx;
                        msg.player_id.Set(relation_evt.source_char_idx, relation_evt.bin_content.bin_add_content.char_name);
                        msg.message = relation_evt.bin_content.bin_add_content.message;
                        msg.flag    = relation_evt.bin_content.bin_add_content.flag;
                        ForServerNetManager.Instance.Send(player.ss_srv_uid, msg);
                    }
                    break;
                }

                case eRelationEvent.Delete:    //对方删除了你
                {
                    if (m_relations.ContainsKey(relation_evt.source_char_idx))
                    {
                        this.RemoveRelation(relation_evt.source_char_idx);

                        //通知逻辑服,由逻辑服转发给客户端
                        gl2ss.RelationRemove msg_remove = PacketPools.Get(gl2ss.msg.RELATION_REMOVE) as gl2ss.RelationRemove;
                        msg_remove.char_idx   = m_char_idx;
                        msg_remove.target_idx = relation_evt.source_char_idx;
                        ForServerNetManager.Instance.Send(player.ss_srv_uid, msg_remove);
                    }

                    //清除处理过的事件
                    SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                    m_relation_events.Remove(relation_evt.event_idx);
                    break;
                }

                case eRelationEvent.Agree:    //对方同意了你的申请
                {
                    if (relation_evt.bin_content.bin_agree_content.cmd == eRelationApplyCmd.Agree)
                    {
                        //如果对方在线,则取对方身上的数据;否则取数据库的数据
                        Unit target_player = UnitManager.Instance.GetUnitByIdx(relation_evt.source_char_idx);
                        if (target_player != null)
                        {
                            this.RemoveRelation(relation_evt.source_char_idx);

                            RelationInfo relation_info = CommonObjectPools.Spawn <RelationInfo>();
                            relation_info.Copy(target_player.player_data);
                            relation_info.flags = relation_evt.bin_content.bin_agree_content.flag;
                            this.AddRelation(relation_info);
                            this.SyncRelation2SS(relation_evt.source_char_idx);

                            //清除处理过的事件
                            SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                            m_relation_events.Remove(relation_evt.event_idx);
                        }
                        else
                        {
                            PlayerInfoForGL data = CommonObjectPools.Spawn <PlayerInfoForGL>();
                            SQLCharHandle.QueryCharacterInfo(relation_evt.source_char_idx, data, (ret) =>
                                {
                                    if (ret && m_char_idx > 0)
                                    {
                                        this.RemoveRelation(relation_evt.source_char_idx);

                                        RelationInfo relation_info = CommonObjectPools.Spawn <RelationInfo>();
                                        relation_info.Copy(data);
                                        relation_info.flags = relation_evt.bin_content.bin_agree_content.flag;
                                        this.AddRelation(relation_info);
                                        this.SyncRelation2SS(relation_evt.source_char_idx);
                                    }
                                    CommonObjectPools.Despawn(data);

                                    //清除处理过的事件
                                    SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                                    m_relation_events.Remove(relation_evt.event_idx);
                                });
                        }
                    }
                    else
                    {
                        //清除处理过的事件
                        SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                        m_relation_events.Remove(relation_evt.event_idx);
                    }

                    break;
                }

                case eRelationEvent.Give:
                {
                    Log.Info("赠送 src:" + relation_evt.source_char_idx + " dst:" + relation_evt.target_char_idx);
                    RelationEventContent.GiveContent give_info = relation_evt.bin_content.bin_give_content;
                    //发给ss处理
                    if (item.IsValidItem(give_info.item_id))
                    {
                        gl2ss.RelationGive msg_give = PacketPools.Get(gl2ss.msg.RELATION_GIVE) as gl2ss.RelationGive;
                        msg_give.char_idx = m_char_idx;
                        msg_give.src_player_id.Set(relation_evt.source_char_idx, give_info.char_name);
                        msg_give.item_id = give_info.item_id;
                        ForServerNetManager.Instance.Send(player.ss_srv_uid, msg_give);
                    }

                    //清除处理过的事件
                    SQLRelationHandle.RemoveRelationEvent(relation_evt.event_idx);
                    m_relation_events.Remove(relation_evt.event_idx);
                    break;
                }
                }
            }
        }
示例#28
0
 public PlayerCache()
 {
     m_ss_data = CommonObjectPools.Spawn <PlayerInfoForSS>();
 }