public void ProcessSaveRoleData_Attr(byte[] data) { GameBase.Network.Internal.SaveRoleData_Attr info = new GameBase.Network.Internal.SaveRoleData_Attr(); info.Create(data); //设置角色为离线状态 if (info.IsExit) { Data.SetOnlineState(info.accountid, -1); } if (!Data.SaveRoleData_Attr(info)) { Log.Instance().WriteLog("保存角色信息失败,角色id:" + info.accountid.ToString() + " 角色名称:" + info.name); } }
public static bool SaveRoleData_Attr(GameBase.Network.Internal.SaveRoleData_Attr info) { //加一个判断弥补之前的bug--负数 2016.1.25 if (info.gamegold < 0) { info.gamegold = 0; } if (info.gold < 0) { info.gold = 0; } MySqlCommand command = null; String name_latin1 = Coding.GB2312ToLatin1(info.name); String sql = ""; try { sql = String.Format(MysqlString.SAVEROLE_ATTR, name_latin1, info.lookface, info.hair, info.level, info.exp, info.life, info.mana, info.profession, info.pk, info.gold, info.gamegold, info.stronggold, info.mapid, info.x, info.y, info.hotkey, info.guanjue, info.godlevel, info.maxeudemon, info.accountid); String utf_sql = sql; command = new MySqlCommand(utf_sql, MysqlConn.GetConn()); MysqlConn.Conn_Open(); command.ExecuteNonQuery(); MysqlConn.Conn_Close(); command.Dispose(); } catch (System.Exception ex) { Log.Instance().WriteLog("SaveRoleData_Attr error!"); Log.Instance().WriteLog(ex.Message); Log.Instance().WriteLog(ex.StackTrace); Log.Instance().WriteLog("sql语句:" + sql); // if (MysqlConn.GetConn().State == ConnectionState.Open) // { // MysqlConn.GetConn().Close(); // } if (command != null) { command.Dispose(); } return(false); } return(true); }
//发送玩家数据信息到dbserver 保存到数据库 //play 玩家对象 //isExit 是否是退出游戏 - public void SaveRoleData(PlayerObject play,bool isExit = false) { if (!this.IsConnect()) { UserEngine.Instance().AddCachePlay(play); Log.Instance().WriteLog("保存玩家数据失败,dbserver未连接,已加入到数据库缓冲存储区"); return; } //人物基本属性 SaveRoleData_Attr data = new SaveRoleData_Attr(); GameStruct.PlayerAttribute attr = play.GetBaseAttr(); data.accountid = attr.account_id; data.IsExit = isExit; data.name = play.GetName(); data.lookface = attr.lookface; data.hair = attr.hair; data.level = (byte)attr.level; data.exp = attr.exp; data.life = attr.life; data.mana = attr.mana; data.profession = attr.profession; data.pk = attr.pk; data.gold = attr.gold; data.gamegold = attr.gamegold; data.stronggold = attr.stronggold; data.godlevel = attr.godlevel; data.maxeudemon = attr.maxeudemon; if (play.GetGameMap() == null) { data.mapid = 1000; data.x = 145; data.y = 413; } else { data.mapid = play.GetGameMap().GetMapInfo().id; data.x = play.GetCurrentX(); data.y = play.GetCurrentY(); } data.hotkey = play.GetHotKeyInfo(); data.guanjue = attr.guanjue; GetDBClient().SendData(data.GetBuffer()); //保存道具信息 play.GetItemSystem().DB_Save(); //保存技能信息 play.GetMagicSystem().DB_Save(); //保存幻兽信息 play.GetEudemonSystem().DB_Save(); //好友信息 play.GetFriendSystem().DB_Save(); }