/// <summary> /// 修改游戏服务器 /// </summary> /// <param name="server">服务器</param> /// <param name="name">服务器名</param> /// <param name="comment">服务器描述</param> /// <param name="ipAddress">IP地址</param> /// <param name="macAddress">MAC地址</param> /// <param name="gameDir">游戏目录</param> /// <param name="newGroup">服务器组</param> /// <param name="lordConfig">Lord配置</param> public bool ModifyGameServer( GameServer server, string name, string comment, string ipAddress, string gameDir, ServerGroup newGroup, LordConfig lordConfig, GameServer.ConfigGuardState configState, string cfgContent, //bool hasBeenConfigGuard, GameServer.ServerType serverType, int ftpServer ) { if (server == null) throw new ArgumentNullException("server"); if (name == null) throw new ArgumentNullException("name"); if (comment == null) throw new ArgumentNullException("comment"); if (ipAddress == null) throw new ArgumentNullException("ipAddress"); if (gameDir == null) throw new ArgumentNullException("gameDir"); if (newGroup == null) throw new ArgumentNullException("newGroup"); if (cfgContent == null) throw new ArgumentNullException("cfgContent"); IBlazeDatabase db = null; try { SecurityManager sm = AdminServer.TheInstance.SecurityManager; db = DbFactory.GetDatabase(); db.BeginTrans(); FSEyeObject serverObject = server.SecurityObject; serverObject.Name = name; serverObject.Comment = comment; sm.Set(serverObject, db); //游戏服务器配置值 string[] gameServerFields = null; object[] gameServerValues = null; if (lordConfig == null) { gameServerFields = new string[] { TableString.GameServerFieldNetAddress, TableString.GameServerFieldGameDir, TableString.GameServerFieldHasBeenConfigGuard, TableString.GameServerFieldServerType, TableString.GameServerFieldCfgString, TableString.GameServerFieldFtpDownloadServer }; gameServerValues = new object[] { ipAddress, gameDir, (int)configState, (int)serverType, cfgContent, ftpServer }; } else { ArrayList gameServerFieldList = new ArrayList(); ArrayList gameServerValueList = new ArrayList(); //TODO: HUANGBIAO 2008-1-20 下面代码可能没用 //gameServerFieldList.Add(TableString.GameServerFieldNetAddress); //gameServerFieldList.Add(TableString.GameServerFieldGameDir); //gameServerFieldList.Add(TableString.GameServerFieldLordPort); //gameServerFieldList.Add(TableString.GameServerFieldMaxPlayer); //gameServerFieldList.Add(TableString.GameServerFieldIntranetMask); //gameServerFieldList.Add(TableString.GameServerFieldInternetMask); //gameServerValueList.Add(ipAddress); //gameServerValueList.Add(gameDir); //gameServerValueList.Add(lordConfig.ServerCount); //gameServerValueList.Add(lordConfig.MaxPlayer); //gameServerValueList.Add(lordConfig.IntranetMask); //gameServerValueList.Add(lordConfig.InternetMask); //Payasys是否配置 if (lordConfig.PaysysIp != null && lordConfig.PaysysIp.Length != 0) { gameServerFieldList.Add(TableString.GameServerFieldPaysysIp); gameServerFieldList.Add(TableString.GameServerFieldPaysysPort); gameServerFieldList.Add(TableString.GameServerFieldPaysysLoginName); gameServerFieldList.Add(TableString.GameServerFieldPaysysLoginPwd); gameServerValueList.Add(lordConfig.PaysysIp); gameServerValueList.Add(lordConfig.PaysysPort); gameServerValueList.Add(lordConfig.PaysysLoginName); gameServerValueList.Add(lordConfig.PaysysLoginPwd); } if (cfgContent.Length != 0) { gameServerFieldList.Add(TableString.GameServerFieldCfgString); gameServerValueList.Add(cfgContent); } //Db是否配置 if (lordConfig.DbHost != null && lordConfig.DbHost.Length != 0) { gameServerFieldList.Add(TableString.GameServerFieldDbHost); gameServerFieldList.Add(TableString.GameServerFieldDbName); gameServerFieldList.Add(TableString.GameServerFieldDbLoginName); gameServerFieldList.Add(TableString.GameServerFieldDbLoginPwd); gameServerFieldList.Add(TableString.GameServerFieldDbBackupDir); gameServerValueList.Add(lordConfig.DbHost); gameServerValueList.Add(lordConfig.DbName); gameServerValueList.Add(lordConfig.DbLoginName); gameServerValueList.Add(lordConfig.DbLoginPwd); gameServerValueList.Add(lordConfig.DbBackupPath); } //是否配置GMCIp和GMCAccount这两个字段 if (lordConfig.GMCIp != null && lordConfig.GMCIp.Length != 0) { gameServerFieldList.Add(TableString.GameServerFieldGmcIp); gameServerValueList.Add(lordConfig.GMCIp); } if (lordConfig.GMCAccount != null && lordConfig.GMCAccount.Length != 0) { gameServerFieldList.Add(TableString.GameServerFieldGmcAccount); gameServerValueList.Add(lordConfig.GMCAccount); } gameServerFieldList.Add(TableString.GameServerFieldFSEyeIp); gameServerFieldList.Add(TableString.GameServerFieldFSEyePort); gameServerFieldList.Add(TableString.GameServerFieldHasBeenConfigGuard); gameServerFieldList.Add(TableString.GameServerFieldServerType); gameServerValueList.Add(lordConfig.FSEyeIp); gameServerValueList.Add(lordConfig.FSEyePort); gameServerValueList.Add((int)configState); gameServerValueList.Add((int)serverType); gameServerFields = (string[])gameServerFieldList.ToArray(typeof(string)); gameServerValues = (object[])gameServerValueList.ToArray(); } IBlazeTable gameServerTable = db.GetTable(TableString.GameServerTableName); gameServerTable.Set(gameServerFields, gameServerValues, FilterFactory.CreateEqualFilter(TableString.GameServerFieldId, server.Id)); server.SecurityObject.Name = name; server.SecurityObject.Comment = comment; server.IpAddress = ipAddress; server.GameDir = gameDir; server.ConfigState = configState; server.Type = serverType; server.ConfigContent = cfgContent; server.FtpServer = ftpServer; if (lordConfig != null) { server.LordConfig.Copy(lordConfig); } ServerGroup oldGroup = server.Group; if (oldGroup != null && newGroup != null) { oldGroup.List.Remove(server); oldGroup.SecurityObject.RemoveChild(server.SecurityObject.Name); sm.Set(oldGroup.SecurityObject, db); newGroup.List.Add(server); newGroup.SecurityObject.AddChild(server.SecurityObject); sm.Set(newGroup.SecurityObject, db); server.Group = newGroup; } sm.Set(serverObject, db); db.CommitTrans(); return true; } catch (Exception) { if (db != null) db.RollbackTrans(); } finally { if (db != null) db.Close(); } return false; }
private bool GuardCfg(ref LordConfig lordConfig) { lordConfig = new LordConfig(); lordConfig.ServerCount = int.Parse(TextBoxLordPort.Text); lordConfig.ServerIDs = TextBoxMaxPlayer.Text; lordConfig.FSEyeIp = TextBoxFSEyeIp.Text; lordConfig.FSEyePort = int.Parse(TextBoxFSEyePort.Text); if (_server.Type == GameServer.ServerType.gamecenter) { if ((GMCIpTextBox.Text != null) && (GMCIpTextBox.Text.Length != 0)) lordConfig.GMCIp = GMCIpTextBox.Text; if ((GMCAccountTextBox.Text != null) && (GMCAccountTextBox.Text.Length != 0)) lordConfig.GMCAccount = GMCAccountTextBox.Text; } return true; }
/// <summary> /// 更新自动化配置的状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //protected void uploadconfigstate(object sender, eventargs e) //{ // createlordconfigautomation createlord = null; // if (session["auto"] != null) createlord = session["createlord"] as createlordconfigautomation; // if (createlord == null) // { // //uploadlordconfig.visible = false; // timer1.enabled = false; // return; // } // if (createlord.state == automationstate.done) // { // literalsavefile1.text = createlord.result.tostring(); // if(createlord.result == automationresult.success) // _server.appendmessage(stringdef.createlordconfigfile,gameserver.messageinfo.type.alert); // if (createlord.result == automationresult.failure) // { // literaluploadfile1.text = automationresult.failure.tostring(); // literalconfig1.text = automationresult.failure.tostring(); // literaldeletefile1.text = automationresult.failure.tostring(); // session.remove("createlord"); // } // else if (createlord.success.state == automationstate.done) // { // if(createlord.success.result == automationresult.success) // _server.appendmessage(stringdef.uploadlordconfigfile,gameserver.messageinfo.type.alert); // literaluploadfile1.text = createlord.success.result.tostring(); // if (createlord.success.result == automationresult.failure) // { // literalconfig1.text = automationresult.failure.tostring(); // literaldeletefile1.text = automationresult.failure.tostring(); // session.remove("createlord"); // } // else if(createlord.success.success.state == automationstate.done) // { // if(createlord.success.success.result == automationresult.success) // _server.appendmessage(stringdef.configlord,gameserver.messageinfo.type.alert); // literalconfig1.text = createlord.success.success.result.tostring(); // if (createlord.success.success.result == automationresult.failure) // { // literaldeletefile1.text = automationresult.failure.tostring(); // session.remove("createlord"); // } // else if(createlord.success.success.success.state == automationstate.done) // { // if(createlord.success.success.success.result == automationresult.success) // _server.appendmessage(stringdef.deletelocallordconfigfile,gameserver.messageinfo.type.alert); // literaldeletefile1.text = createlord.success.success.success.result.tostring(); // } // } // } // } //} protected void SaveAsDefaultLordConfig_Click(object sender, EventArgs e) { try { LordConfig lordConfig = new LordConfig(); lordConfig = new LordConfig(); lordConfig.ServerCount = int.Parse(TextBoxLordPort.Text); lordConfig.ServerIDs = TextBoxMaxPlayer.Text; lordConfig.FSEyeIp = TextBoxFSEyeIp.Text; lordConfig.FSEyePort = int.Parse(TextBoxFSEyePort.Text); if (!LordConfig.SaveAsDefaultConfig(lordConfig)) { LabelOpMsg.Text = StringDef.OperationFail; return; } else { LabelSuccess.Visible = true; LabelSuccess.Text = StringDef.OperationSucceed; } } catch (Exception ex) { LabelOpMsg.Text = ex.Message; } }
/// <summary> /// 构造 /// </summary> public GameServer() { _fileManageTaskList = ArrayList.Synchronized(new ArrayList()); _cpuInfos = ArrayList.Synchronized(new ArrayList()); _memoryInfoQueue = Queue.Synchronized(new Queue()); _diskInfos = ArrayList.Synchronized(new ArrayList()); _networkCards = ArrayList.Synchronized(new ArrayList()); _processInfoList = ArrayList.Synchronized(new ArrayList()); _plugInInfoList = ArrayList.Synchronized(new ArrayList()); _gameInfoQueue = Queue.Synchronized(new Queue()); _installedPlugInList = ArrayList.Synchronized(new ArrayList()); _installedPlugInMap = Hashtable.Synchronized(new Hashtable()); _serverState = ServerState.Unknown; _lordConfig = new LordConfig(); _updateMsg = ArrayList.Synchronized(new ArrayList()); _downloadMsg = new string[3] { "0", "1", "2" }; _gameSetting = new GameSetting(this); _recentMessageQueue = new Queue<MessageInfo>(RecentMessageQueueLength); _lastCheckResult = new CheckResult(); }
private void ShowLordConfig(LordConfig lordConfig) { int iServerCount = 0; string sServerIDs = ""; if (lordConfig != null) { foreach (GameServer server in AdminServer.TheInstance.GameServerManager.Servers) { if (server.IpAddress == TextBoxServerIpAddress.Text.Trim()) { if (iServerCount == 0) sServerIDs = server.Id.ToString(); else sServerIDs = sServerIDs + "," + server.Id.ToString(); iServerCount++; } } TextBoxLordPort.Text = iServerCount.ToString(); // lordConfig.ServerCount.ToString(); TextBoxLordPort.Enabled = false; TextBoxMaxPlayer.Text = sServerIDs; // lordConfig.ServerIDs.ToString(); TextBoxMaxPlayer.Enabled = false; TextBoxFSEyeIp.Text = lordConfig.FSEyeIp; TextBoxFSEyePort.Text = lordConfig.FSEyePort.ToString(); if (_server.Type == GameServer.ServerType.gamecenter) { if (lordConfig.GMCIp != null) GMCIpTextBox.Text = lordConfig.GMCIp; if (lordConfig.GMCAccount != null) GMCAccountTextBox.Text = lordConfig.GMCAccount; GMCIpTr.Visible = true; GMCAccountTr.Visible = true; } } }
/// <summary> /// 保存为默认设置,写入fseyesetting目录下DefaultGuardConfig.xml /// </summary> /// <returns></returns> public static bool SaveAsDefaultConfig(LordConfig lord) { FileStream fileStream = new FileStream(SystemConfig.Current.GameSettingDir + DefaultConfigFileName, FileMode.OpenOrCreate); XmlTextWriter writer = null; try { fileStream.SetLength(0); writer = new XmlTextWriter(fileStream, Encoding.Default); writer.WriteStartElement("DefaultLordConfig"); if (lord.PaysysIp != null && lord.PaysysIp.Length != 0) { writer.WriteAttributeString("PaysysIp", lord.PaysysIp); writer.WriteAttributeString("PaysysPort", lord.PaysysPort.ToString()); writer.WriteAttributeString("PaysysLoginName", lord.PaysysLoginName); if (lord.PaysysLoginPwd != null && lord.PaysysLoginPwd.Length != 0) writer.WriteAttributeString("PaysysLoginPwd", UtilDllWrap.DBEncrypt(lord.PaysysLoginPwd, SystemConfig.Current.DefaultEncoding)); } if (lord.DbHost != null && lord.DbHost.Length != 0) { writer.WriteAttributeString("DbHost", lord.DbHost); writer.WriteAttributeString("DbName", lord.DbName); writer.WriteAttributeString("DbBackupPath", lord.DbBackupPath); writer.WriteAttributeString("DbLoginName", lord.DbLoginName); if (lord.DbLoginPwd != null && lord.DbLoginPwd.Length != 0) writer.WriteAttributeString("DbLoginPwd", UtilDllWrap.DBEncrypt(lord.DbLoginPwd, SystemConfig.Current.DefaultEncoding)); } writer.WriteAttributeString("FSEyeIp", lord.FSEyeIp); writer.WriteAttributeString("FSEyePort", lord.FSEyePort.ToString()); writer.WriteEndElement(); return true; } catch (Exception) { return false; } finally { if (writer != null) writer.Close(); } }
/// <summary> /// 从配置文件中读取默认配置 /// </summary> /// <returns>从文件中读取配置的标识,为true则配置从文件中读取,为false则用LordConfig中的简单默认配置</returns> public static LordConfig LoadFromDefaultConfig() { if (File.Exists(SystemConfig.Current.GameSettingDir + DefaultConfigFileName)) { FileStream fileStream = new FileStream(SystemConfig.Current.GameSettingDir + DefaultConfigFileName, FileMode.OpenOrCreate); XmlTextReader reader = null; LordConfig lordConfig = new LordConfig(); try { reader = new XmlTextReader(fileStream); if (reader != null) { reader.Read(); lordConfig.FSEyeIp = reader.GetAttribute("FSEyeIp"); lordConfig.FSEyePort = int.Parse(reader.GetAttribute("FSEyePort")); try { lordConfig.PaysysIp = reader.GetAttribute("PaysysIp"); lordConfig.PaysysPort = int.Parse(reader.GetAttribute("PaysysPort")); lordConfig.PaysysLoginName = reader.GetAttribute("PaysysLoginName"); lordConfig.PaysysLoginPwd = UtilDllWrap.DBEncrypt(reader.GetAttribute("PaysysLoginPwd"), SystemConfig.Current.DefaultEncoding); } catch (Exception) { } try { lordConfig.DbHost = reader.GetAttribute("DbHost"); lordConfig.DbName = reader.GetAttribute("DbName"); lordConfig.DbBackupPath = reader.GetAttribute("DbBackupPath"); lordConfig.DbLoginName = reader.GetAttribute("DbLoginName"); lordConfig.DbLoginPwd = reader.GetAttribute("DbLoginPwd");// UtilDllWrap.DBEncrypt(reader.GetAttribute("DbLoginPwd"), SystemConfig.Current.DefaultEncoding); } catch (Exception) { } } } catch (Exception) { } finally { if (reader != null) reader.Close(); } return lordConfig; } else { //默认简单配置 LordConfig lordConfig = new LordConfig(); lordConfig.ServerCount = DefaultServerCount; lordConfig.PaysysIp = DefaultPaysysIp; lordConfig.PaysysPort = DefaultPaysysPort; lordConfig.PaysysLoginName = DefaultPaysysLoginName; lordConfig.PaysysLoginPwd = DefaultPaysysLoginPwd; lordConfig.DbHost = DefaultDbHost; lordConfig.DbName = DefaultDbName; lordConfig.DbLoginName = DefaultDbLoginName; lordConfig.DbLoginPwd = DefaultDbLoginPwd; lordConfig.DbBackupPath = DefaultDbBackupPath; lordConfig.FSEyeIp = SystemConfig.Current.AdminServerListenIP; lordConfig.FSEyePort = SystemConfig.Current.AdminServerListenPort; return lordConfig; } }
/// <summary> /// 这个Copy好象只是浅拷贝 /// </summary> /// <param name="config"></param> public void Copy(LordConfig config) { if (config.ServerCount >= 0) ServerCount = config.ServerCount; if (config.MaxPlayer >= 0) MaxPlayer = config.MaxPlayer; if (config.IntranetMask != null) IntranetMask = config.IntranetMask; if (config.InternetMask != null) InternetMask = config.InternetMask; if (config.ServerIDs != null) ServerIDs = config.ServerIDs; if (config.PaysysIp != null) PaysysIp = config.PaysysIp; if (config.PaysysPort>=0) PaysysPort = config.PaysysPort; if (config.PaysysLoginName != null) PaysysLoginName = config.PaysysLoginName; if (config.PaysysLoginPwd != null) PaysysLoginPwd = config.PaysysLoginPwd; if (config.DbHost != null) DbHost = config.DbHost; if (config.DbName != null) DbName = config.DbName; if (config.DbLoginName != null) DbLoginName = config.DbLoginName; if ((config.DbLoginPwd != null) && (config.DbLoginPwd.Length != 0)) DbLoginPwd = config.DbLoginPwd; if (config.DbBackupPath != null) DbBackupPath = config.DbBackupPath; if (config.FSEyeIp != null) FSEyeIp = config.FSEyeIp; if (config.FSEyePort >=0) FSEyePort = config.FSEyePort; if ((config.BindIp != null) && (config.BindIp.Length != 0)) BindIp = config.BindIp; if ((config.GMCIp != null) && (config.GMCIp.Length != 0)) GMCIp = config.GMCIp; if ((config.GMCAccount != null) && (config.GMCAccount.Length != 0)) GMCAccount = config.GMCAccount; //FSEyeLoginPwd = config.FSEyeLoginPwd; }
//配置fseye, 与DB数据库 private LordConfig GuardCfg(string ipAddr) { int iServerCount = 0; string sServerIDs = ""; LordConfig lordConfig = new LordConfig(); foreach (GameServer server in AdminServer.TheInstance.GameServerManager.Servers) { if (server.IpAddress == ipAddr) { if (iServerCount == 0) sServerIDs = server.Id.ToString(); else sServerIDs = sServerIDs + "," + server.Id.ToString(); iServerCount++; } } lordConfig.ServerCount = iServerCount; lordConfig.ServerIDs = sServerIDs; lordConfig.FSEyeIp = TextBoxFSEyeIp.Text; lordConfig.FSEyePort = int.Parse(TextBoxFSEyePort.Text); return lordConfig; }
protected Boolean modifyServer(GameServer server, string name, string comment, string ip, string gameDir, ServerGroup group, LordConfig lordConfig, GameServer.ConfigGuardState ConfigState, string serverConfigFile, GameServer.ServerType serverType, int ftpServerID) { if (TheAdminServer.GameServerManager.ModifyGameServer(server, name, comment, ip, gameDir, group, lordConfig, server.ConfigState, serverConfigFile, serverType, ftpServerID)) { LabelSuccess.Visible = true; LabelSuccess.Text = StringDef.ModifyServer + StringDef.Colon + StringDef.Success; return true; } return false; }