public static bool ReLoad() { try { m_lock.AcquireWriterLock(Timeout.Infinite); try { using (ServiceBussiness db = new ServiceBussiness()) { _RateInfo = db.GetExperienceRate(WorldMgr.ServerID); } if (_RateInfo == null) { _RateInfo = new ExperienceRateInfo(); _RateInfo.Rate = -1; } return true; } catch{ } finally { m_lock.ReleaseWriterLock(); } } catch (Exception e) { if (log.IsErrorEnabled) log.Error("ExperienceRateMgr", e); } return false; }
public static bool Init() { try { //_RateInfo = new ExperienceRateInfo(); //_RateInfo.Rate = 1; m_lock = new System.Threading.ReaderWriterLock(); using (ServiceBussiness db = new ServiceBussiness()) { _RateInfo = db.GetExperienceRate(WorldMgr.ServerID); } if (_RateInfo == null) { _RateInfo = new ExperienceRateInfo(); _RateInfo.Rate = -1; } return true; } catch (Exception e) { if (log.IsErrorEnabled) log.Error("ExperienceRateMgr", e); return false; } }
private static void Save(Type type) { using (ServiceBussiness sb = new ServiceBussiness()) { foreach (FieldInfo f in type.GetFields()) { if (!f.IsStatic) continue; object[] attribs = f.GetCustomAttributes(typeof(ConfigPropertyAttribute), false); if (attribs.Length == 0) continue; ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)attribs[0]; SaveProperty(attrib, sb, f.GetValue(null)); } } }
private static bool LoadFightRate(Dictionary<int, FightRateInfo> fighRate) { using (ServiceBussiness db = new ServiceBussiness()) { FightRateInfo[] infos = db.GetFightRate(GameServer.Instance.Configuration.ServerID); foreach (FightRateInfo info in infos) { if (!fighRate.ContainsKey(info.ID)) { fighRate.Add(info.ID, info); } } } return true; }
public static bool ReLoadServerList() { try { using (ServiceBussiness db = new ServiceBussiness()) { lock (_syncStop) { ServerInfo[] list = db.GetServerList(); foreach (ServerInfo s in list) { if (_list.ContainsKey(s.ID)) { _list[s.ID].IP = s.IP; _list[s.ID].Name = s.Name; _list[s.ID].Port = s.Port; _list[s.ID].Room = s.Room; _list[s.ID].Total = s.Total; _list[s.ID].MustLevel = s.MustLevel; _list[s.ID].LowestLevel = s.LowestLevel; _list[s.ID].Online = s.Online; _list[s.ID].State = s.State; } else { s.State = 1; s.Online = 0; _list.Add(s.ID, s); } } } } log.Info("ReLoad server list from db."); return true; } catch (Exception ex) { log.ErrorFormat("ReLoad server list from db failed:{0}", ex); return false; } }
public static bool Init(GameServerConfig config) { m_lock.AcquireWriterLock(Timeout.Infinite); try { using (ServiceBussiness db = new ServiceBussiness()) { m_RateInfos = db.GetRate(config.ServerID); } return true; } catch (Exception e) { if (log.IsErrorEnabled) log.Error("RateMgr", e); return false; } finally { m_lock.ReleaseWriterLock(); } }
public static bool Start() { try { using (ServiceBussiness db = new ServiceBussiness()) { ServerInfo[] list = db.GetServerList(); foreach (ServerInfo s in list) { s.State = 1; s.Online = 0; _list.Add(s.ID, s); } } log.Info("Load server list from db."); return true; } catch (Exception ex) { log.ErrorFormat("Load server list from db failed:{0}", ex); return false; } }
public static bool Init() { bool result = false; try { m_rsa = new RSACryptoServiceProvider(); m_rsa.FromXmlString(GameServer.Instance.Configuration.PrivateKey); m_players.Clear(); using (ServiceBussiness db = new ServiceBussiness()) { ServerInfo info = db.GetServiceSingle(GameServer.Instance.Configuration.ServerID); if (info != null) { _marryScene = new Scene(info); result = true; } } } catch (Exception e) { log.Error("WordMgr Init", e); } return result; }
private static object LoadProperty(ConfigPropertyAttribute attrib, ServiceBussiness sb) { String key = attrib.Key; ServerProperty property = sb.GetServerPropertyByKey(key); if (property == null) { property = new ServerProperty(); property.Key = key; property.Value = attrib.DefaultValue.ToString(); log.Error("Cannot find server property " + key + ",keep it default value!"); } log.Debug("Loading " + key + " Value is " + property.Value); try { return Convert.ChangeType(property.Value, attrib.DefaultValue.GetType()); } catch (Exception e) { log.Error("Exception in GameProperties Load: ", e); return null; } }
private static void SaveProperty(ConfigPropertyAttribute attrib, ServiceBussiness sb,object value) { try { sb.UpdateServerPropertyByKey(attrib.Key, value.ToString()); } catch (Exception ex) { log.Error("Exception in GameProperties Save: ", ex); } }
public static void Save() { if (!TxtRecord) return; //DateTime dt = DateTime.Now; int interval = SaveRecordSecond; //dt = dt.AddMinutes(5); dt = dt.AddSeconds(interval); //int totalM = 0 ; //注册人数(男) //int totalF = 0; //注册人数(女) //int onlineM = 0; //在线人数(男) //int onlineF = 0; //在线人数(女) //int paymenM = 0; //付费用户(男) //int paymenF = 0; //付费用户(女) //int activePaymenM = 0; //活跃付费用户(男) //int activePaymenF = 0; //活跃付费用户(女) //int activeCustomerM = 0; //活跃消费用户(男) //int activeCustomerF = 0; //活跃消费用户(女) // 新的User日志格式 //#格式:【用户记录】游戏类型,分区,服务器ID,[时间],注册人数(男),注册人数(女),在线人数(男),在线人数(女),登陆用户数(男), 登陆用户数(女),活跃充值用户(男),活跃充值用户(女),活跃消费用户(男),活跃消费用户(女),活跃在线用户(男)、活跃在线用户(女) using (ServiceBussiness db = new ServiceBussiness()) { try { RecordInfo info = db.GetRecordInfo(dt, SaveRecordSecond); int online = LoginMgr.GetOnlineCount(); //writer.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", dt, totalM, totalF, onlineM, onlineF, paymenM, paymenF, activePaymenM, activePaymenF, activeCustomerM, activeCustomerF)); if (info == null) { info = new RecordInfo(); } _saveLogCache.Add(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}", _headStr, dt, info.TotalBoy, info.TotalGirl, online, 0, info.ExpendBoy, info.ExpendGirl, info.ActviePayBoy, info.ActviePayGirl, info.ActiveExpendBoy, info.ActiveExpendGirl, info.ActiveOnlineBoy, info.ActiveOnlineGirl)); string file = string.Format("{0}\\user-{1:D2}{2:D2}{3:D2}-{4:yyyyMMdd}.log", _logPath, _gameType, _areaId, _serverId, dt); using (FileStream fs = File.Open(file, FileMode.Append)) { using (StreamWriter writer = new StreamWriter(fs)) { while (_saveLogCache.Count != 0) { writer.WriteLine(_saveLogCache[0]); _saveLogCache.RemoveAt(0); } } } } catch (Exception ex) { if (log.IsErrorEnabled) log.Error("Save log error", ex); } try { //1,1,2,2009-1-10 0:02:06,0, //游戏类型、代理商、频道、日期、在线用户、注册用户 Dictionary<int, int> lines = LoginMgr.GetOnlineForLine(); int online = LoginMgr.GetOnlineCount(); _onlineLogCache.Add(string.Format("{0},{1},{2},{3},{4},{5}", _gameType, _areaId, 0, dt, online, RegCount)); RegCount = 0; string file = string.Format("{0}\\online-{1:D2}{2:D2}{3:D2}-{4:yyyyMMdd}.log", _logPath, _gameType, _areaId, _serverId, dt); using (FileStream fs = File.Open(file, FileMode.Append)) { using (StreamWriter writer = new StreamWriter(fs)) { while (_onlineLogCache.Count != 0) { writer.WriteLine(_onlineLogCache[0]); _onlineLogCache.RemoveAt(0); } } } } catch (Exception ex) { if (log.IsErrorEnabled) log.Error("OnlineForLine log error", ex); } } //#格式:【用户记录】游戏类型,分区,时间,付费方式(ebank、SMS、Post),男人数,女人数,男付费金额,女付费金额 //using (PlayerBussiness db = new PlayerBussiness()) //{ // ChargeRecordInfo[] infos = db.GetChargeRecordInfo(dt, SaveRecordSecond); // string file = string.Format("{0}\\pay-{1:D2}{2:D2}{3:D2}-{4:yyyyMMdd}.log", _logPath, _gameType, _areaId, _serverId, dt); // using (FileStream fs = File.Open(file, FileMode.Append)) // { // using (StreamWriter writer = new StreamWriter(fs)) // { // foreach (ChargeRecordInfo info in infos) // { // writer.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6}", // _headStr, dt, info.PayWay, info.TotalBoy, info.TotalGirl, info.BoyTotalPay, info.GirlTotalPay)); // } // } // } //} }
public static void SaveToDatabase() { try { using (ServiceBussiness db = new ServiceBussiness()) { foreach (ServerInfo info in _list.Values) { //if (info.State != 1) //{ // info.State = GetState(info.Online, info.Total); //} db.UpdateService(info); } } } catch (Exception ex) { log.Error("Save server state", ex); } }
protected override void Load(Type type) { if (Assembly.GetEntryAssembly() != null) RootDirectory = new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName; else RootDirectory = new FileInfo(Assembly.GetAssembly(typeof(GameServer)).Location).DirectoryName; //load app.config base.Load(type); //load server config in db using (ServiceBussiness sb = new ServiceBussiness()) { ServerInfo info = sb.GetServiceSingle(ServerID); if (info == null) { log.ErrorFormat("Can't find server config,server id {0}", ServerID); } else { ServerName = info.Name; MaxRoomCount = info.Room; MaxPlayerCount = info.Total; } } }