/// <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(); }
/// <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); }); }
/// <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); } } }
/// <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); }); }
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); }
/// <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); }
public void Destroy() { foreach (var obj in m_mailboxs) { CommonObjectPools.Despawn(obj.Value); } m_mailboxs.Clear(); }
public void Destroy() { foreach (var obj in m_aoi_units) { CommonObjectPools.Despawn(obj.Value); } m_aoi_units.Clear(); }
/// <summary> /// 创建-玩家重新登录 /// </summary> public BaseItem CreateItem(ItemInfo item_info) { BaseItem prop = CommonObjectPools.Spawn <BaseItem>(); prop.Init(item_info); this.AddItem(prop); return(prop); }
public void Destroy() { foreach (var obj in m_relations) { CommonObjectPools.Despawn(obj.Value); } m_relations.Clear(); }
private void RemoveItem(BaseItem prop) { if (prop == null) { return; } CommonObjectPools.Despawn(prop); m_all_props.Remove(prop.item_idx); }
/// <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); }
public void Destroy() { foreach (var obj in m_cache_members) { CommonObjectPools.Despawn(obj.Value); } m_cache_members.Clear(); m_cache_name_members.Clear(); }
/// <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); }
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); } }
/// <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); }
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(); }
public void RemoveAll() { foreach (var obj in m_units) { obj.Value.Destroy(); CommonObjectPools.Despawn(obj.Value); } m_units.Clear(); m_main_player = null; }
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(); }
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); }
public void CloseAllSession() { foreach (var obj in m_sessions) { obj.Value.Destroy(); CommonObjectPools.Despawn(obj.Value); } m_sessions.Clear(); m_account_sessions.Clear(); }
public void Destroy() { this.UnRegisterEvent(); foreach (var member in m_cache_members) { member.Value.Destroy(); CommonObjectPools.Despawn(member); } m_cache_members.Clear(); }
public void Destroy() { this.UnRegisterEvent(); foreach (var obj in m_fight_players) { obj.Value.Destroy(); CommonObjectPools.Despawn(obj.Value); } m_fight_players.Clear(); }
/// <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); }); } }
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); }
/// <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); }
/// <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); } }
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); }
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); }
/// <summary> /// 对象池信息 /// </summary> private void OnCommand_Pools(string[] param) { NetChannelPools.ToString(true); UserTokenPools.ToString(true); IOCPClientSocket.ToString(true); IOCPServerSocket.ToString(true); SendRecvBufferPools.ToString(true); PacketPools.ToString(true); ObjectPools.ToString(true); CommonObjectPools.ToString(true); }