コード例 #1
0
 /// <summary>
 /// 添加,删除,插入等操作;同步执行
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <returns>影响的行数</returns>
 public void Execute(string sql, List <MySqlParameter> param = null)
 {
     if (!IsOpen())
     {
         Log.Warning("连接已经关闭,执行语句:" + sql);
         return;
     }
     if (m_IsExecing)
     {
         m_SQLExecQueue.Enqueue(new sSQLExecInfo(eSQLExecType.Exec, sql, param, null));
         return;
     }
     //Log.Debug("[db]:execute:" + sql);
     try
     {
         if (param != null)
         {
             MySqlParameter[] arr_p = param.ToArray();
             MySqlHelper.ExecuteNonQuery(m_MysqlConn, sql, arr_p);
             param.ForEach((p) => { CommonObjectPools.Despawn(p); });
         }
         else
         {
             MySqlHelper.ExecuteNonQuery(m_MysqlConn, sql, null);
         }
     }
     catch (Exception e)
     {
         Log.Exception(e);
     }
     CheckSqlExec();
 }
コード例 #2
0
        /// <summary>
        /// 可能是下线,或是离开场景
        /// </summary>
        /// <param name="char_idx"></param>
        public void Remove(long char_idx)
        {
            AOIUnitInfo aoi_info = null;

            if (!m_aoi_units.TryGetValue(char_idx, out aoi_info))
            {
                return;
            }

            ///广播离开事件
            AOIUnitInfo info = null;

            for (int i = aoi_info.observer_units.Count - 1; i >= 0; i--)
            {
                long idx = aoi_info.observer_units[i];
                if (m_aoi_units.TryGetValue(idx, out info))
                {
                    info.observer_units.Remove(aoi_info.char_idx);//从对方列表删除
                    SendAOILeave(info.char_idx, aoi_info.char_idx);
                }
            }

            CommonObjectPools.Despawn(aoi_info);
            m_aoi_units.Remove(char_idx);
        }
コード例 #3
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);
         }
     }
 }
コード例 #4
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);
        }
コード例 #5
0
 public void Destroy()
 {
     foreach (var obj in m_mailboxs)
     {
         CommonObjectPools.Despawn(obj.Value);
     }
     m_mailboxs.Clear();
 }
コード例 #6
0
 public void Destroy()
 {
     foreach (var obj in m_relations)
     {
         CommonObjectPools.Despawn(obj.Value);
     }
     m_relations.Clear();
 }
コード例 #7
0
 public void Destroy()
 {
     foreach (var obj in m_aoi_units)
     {
         CommonObjectPools.Despawn(obj.Value);
     }
     m_aoi_units.Clear();
 }
コード例 #8
0
 private void RemoveItem(BaseItem prop)
 {
     if (prop == null)
     {
         return;
     }
     CommonObjectPools.Despawn(prop);
     m_all_props.Remove(prop.item_idx);
 }
コード例 #9
0
 public void Destroy()
 {
     foreach (var obj in m_cache_members)
     {
         CommonObjectPools.Despawn(obj.Value);
     }
     m_cache_members.Clear();
     m_cache_name_members.Clear();
 }
コード例 #10
0
 public void RemoveUnit(Unit unit)
 {
     if (unit == null)
     {
         return;
     }
     m_cache_units.Remove(unit.char_idx);
     m_name_units.Remove(unit.char_name);
     CommonObjectPools.Despawn(unit);
 }
コード例 #11
0
 public void Destroy()
 {
     this.UnRegisterEvent();
     foreach (var member in m_cache_members)
     {
         member.Value.Destroy();
         CommonObjectPools.Despawn(member);
     }
     m_cache_members.Clear();
 }
コード例 #12
0
 public void Destroy()
 {
     foreach (var obj in m_cache_units)
     {
         obj.Value.OnLeave();
         CommonObjectPools.Despawn(obj.Value);
     }
     m_cache_units.Clear();
     m_name_units.Clear();
 }
コード例 #13
0
 public void Destroy()
 {
     this.UnRegisterEvent();
     foreach (var obj in m_chache_account)
     {
         CommonObjectPools.Despawn(obj.Value);
     }
     m_chache_account.Clear();
     m_account_2_name.Clear();
 }
コード例 #14
0
 public void Destroy()
 {
     this.UnRegisterEvent();
     foreach (var obj in m_fight_players)
     {
         obj.Value.Destroy();
         CommonObjectPools.Despawn(obj.Value);
     }
     m_fight_players.Clear();
 }
コード例 #15
0
 public void RemoveAll()
 {
     foreach (var obj in m_units)
     {
         obj.Value.Destroy();
         CommonObjectPools.Despawn(obj.Value);
     }
     m_units.Clear();
     m_main_player = null;
 }
コード例 #16
0
 public void CloseAllSession()
 {
     foreach (var obj in m_sessions)
     {
         obj.Value.Destroy();
         CommonObjectPools.Despawn(obj.Value);
     }
     m_sessions.Clear();
     m_account_sessions.Clear();
 }
コード例 #17
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);
                });
            }
        }
コード例 #18
0
        /// <summary>
        /// 玩家登出
        /// </summary>
        public void HanldeLogoutClient(long char_idx)
        {
            MailboxCache mail_box;

            if (m_mailboxs.TryGetValue(char_idx, out mail_box))
            {
                mail_box.Destroy();
                CommonObjectPools.Despawn(char_idx);
            }
            m_mailboxs.Remove(char_idx);
        }
コード例 #19
0
        public void RemoveMember(long char_idx)
        {
            MemberRelation member;

            if (m_cache_members.TryGetValue(char_idx, out member))
            {
                member.Destroy();
                CommonObjectPools.Despawn(member);
            }
            m_cache_members.Remove(char_idx);
        }
コード例 #20
0
        public void RemovePlayer(long char_idx)
        {
            FightPlayer player = null;

            if (m_fight_players.TryGetValue(char_idx, out player))
            {
                player.Destroy();
                CommonObjectPools.Despawn(player);
            }
            m_fight_players.Remove(char_idx);
        }
コード例 #21
0
        /// <summary>
        /// 从集合中移除
        /// </summary>
        /// <param name="char_idx">角色id</param>
        public void RemoveMember(long char_idx)
        {
            PlayerCache member;

            if (m_cache_members.TryGetValue(char_idx, out member))
            {
                m_cache_name_members.Remove(member.ss_data.char_name);
                CommonObjectPools.Despawn(member);
            }
            m_cache_members.Remove(char_idx);
        }
コード例 #22
0
        /// <summary>
        /// 玩家登出
        /// </summary>
        private void OnPlayerLogout(long char_idx)
        {
            Mailbox mail_box;

            if (m_mailboxs.TryGetValue(char_idx, out mail_box))
            {
                mail_box.Destroy();
                CommonObjectPools.Despawn(mail_box);
            }
            m_mailboxs.Remove(char_idx);
        }
コード例 #23
0
 public void Destroy()
 {
     this.Save();
     foreach (var obj in m_relations)
     {
         CommonObjectPools.Despawn(obj.Value);
     }
     m_relation_events.Clear();
     m_relations.Clear();
     m_char_idx = 0;
 }
コード例 #24
0
        public void RemoveRelation(long char_idx)
        {
            RelationInfo info;

            if (!m_relations.TryGetValue(char_idx, out info))
            {
                return;
            }
            CommonObjectPools.Despawn(info);
            m_relations.Remove(char_idx);
        }
コード例 #25
0
 public void Destroy()
 {
     this.Save();
     foreach (var obj in m_all_mails)
     {
         CommonObjectPools.Despawn(obj.Value);
     }
     m_all_mails.Clear();
     m_save_mails.Clear();
     m_del_mails.Clear();
     m_char_idx = 0;
 }
コード例 #26
0
        public void RemoveAccountData(long account_idx)
        {
            string account_name;

            if (m_account_2_name.TryGetValue(account_idx, out account_name))
            {
                CacheAccountData cache_chars;
                if (m_chache_account.TryGetValue(account_name, out cache_chars))
                {
                    CommonObjectPools.Despawn(cache_chars);
                }
                m_chache_account.Remove(account_name);
            }
            m_account_2_name.Remove(account_idx);
        }
コード例 #27
0
        public bool CleanupSession(long conn_idx)
        {
            CleanupAcceptSession(conn_idx);

            ClientSession session;

            if (m_sessions.TryGetValue(conn_idx, out session))
            {
                m_account_sessions.Remove(session.account_idx);

                session.Destroy();
                CommonObjectPools.Despawn(session);
            }
            m_sessions.Remove(conn_idx);
            return(true);
        }
コード例 #28
0
        public void RemoveUnit(long unit_idx)
        {
            Unit unit = null;

            if (m_units.TryGetValue(unit_idx, out unit))
            {
                unit.Destroy();
                CommonObjectPools.Despawn(unit);
            }
            if (m_main_player != null && m_main_player.obj_idx == unit_idx)
            {
                m_main_player = null;
            }

            m_units.Remove(unit_idx);
        }
コード例 #29
0
        /// <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);
                    }
                }
            }
                        );
        }
コード例 #30
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);
            }
        }