/// <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; } }
//配置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); }
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; } } }
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); }
protected void LinkButtonSave_Click(object sender, EventArgs e) { if (!WebUtil.CheckPrivilege(TheAdminServer.GameServerManager.SecurityObject, OpType.WRITE, Session)) { LabelOpMsg.Text = StringDef.NotEnoughPrivilege; LabelOpMsg.Visible = true; return; } LabelSuccess.Text = ""; LabelOpMsg.Text = ""; ArrayList servers = new ArrayList(); //获得服务器组 ServerGroup group = ServerGroupDropDownList.SelectedServerGroup; //选中的服务器组为空的情况 if (group == null) { LabelOpMsg.Text = "没有选中的服务器组,添加终止"; LabelOpMsg.Visible = true; return; } //此服务器组中已有服务器,添加中止 //(只允许对一个空组做本页面添加一整组的操作) if (group.List.Count != 0) { LabelOpMsg.Text = "本服务器组中已有其他服务器,添加中止(只允许对空服务器组做此添加操作)"; LabelOpMsg.Visible = true; return; } //已有其他server使用输入的IP,添加终止 string groupIp = TextBoxGroupIpAddress.Text.Trim(); foreach (GameServer server in TheAdminServer.GameServerManager.Servers) { if (server.IpAddress == groupIp) { LabelOpMsg.Text = "已有服务器使用此IP: " + server.Name; LabelOpMsg.Visible = true; return; } } try { string strName = ""; string strComment = ""; string strDir = ""; string serverConfigFileName = ""; string serverConfigFile = ""; GameServer svr = null; //添加bishop strName = group.Name + "_网关服务器"; strComment = strName; strDir = "../bishop/"; serverConfigFileName = WebConfig.WebsiteRootPath + WebConfig.ConfigTemplateDir + ServerType2Module.Gateway; ServerConfigTextBox.getServerConfigTextBox(serverConfigFileName); serverConfigFile = GetServerConfigFile(ServerConfigTextBox.Text); TheAdminServer.GameServerManager.AddGameServer(strName, strComment, groupIp, strDir, group, GameServer.ConfigGuardState.Configuring, serverConfigFile, GameServer.ServerType.bishop, FtpDropDownList.SelectFtp); svr = getGameServerByName(strName); servers.Add(svr); //添加goddess strName = group.Name + "_角色管理服务器"; strComment = strName; strDir = "../goddess/"; serverConfigFileName = WebConfig.WebsiteRootPath + WebConfig.ConfigTemplateDir + ServerType2Module.RoleServer; ServerConfigTextBox.getServerConfigTextBox(serverConfigFileName); serverConfigFile = GetServerConfigFile(ServerConfigTextBox.Text); TheAdminServer.GameServerManager.AddGameServer(strName, strComment, groupIp, strDir, group, GameServer.ConfigGuardState.Configuring, serverConfigFile, GameServer.ServerType.goddess, FtpDropDownList.SelectFtp); svr = getGameServerByName(strName); servers.Add(svr); //添加gamecenter strName = group.Name + "_中心服务器"; strComment = strName; strDir = "../gamecenter/"; serverConfigFileName = WebConfig.WebsiteRootPath + WebConfig.ConfigTemplateDir + ServerType2Module.GameCenter; ServerConfigTextBox.getServerConfigTextBox(serverConfigFileName); serverConfigFile = GetServerConfigFile(ServerConfigTextBox.Text); TheAdminServer.GameServerManager.AddGameServer(strName, strComment, groupIp, strDir, group, GameServer.ConfigGuardState.Configuring, serverConfigFile, GameServer.ServerType.gamecenter, FtpDropDownList.SelectFtp); svr = getGameServerByName(strName); servers.Add(svr); //添加logserver strName = group.Name + "_日志服务器"; strComment = strName; strDir = "../logserver/"; serverConfigFileName = WebConfig.WebsiteRootPath + WebConfig.ConfigTemplateDir + ServerType2Module.LogServer; ServerConfigTextBox.getServerConfigTextBox(serverConfigFileName); serverConfigFile = GetServerConfigFile(ServerConfigTextBox.Text); TheAdminServer.GameServerManager.AddGameServer(strName, strComment, groupIp, strDir, group, GameServer.ConfigGuardState.Configuring, serverConfigFile, GameServer.ServerType.logserver, FtpDropDownList.SelectFtp); svr = getGameServerByName(strName); servers.Add(svr); //添加gameservers for (int i = 1; i <= 7; i++) { strName = group.Name + "_游戏服务器0" + i.ToString(); strComment = strName; strDir = "../gameserver0" + i.ToString() + "/"; serverConfigFileName = WebConfig.WebsiteRootPath + WebConfig.ConfigTemplateDir + ServerType2Module.GameServer; ServerConfigTextBox.getServerConfigTextBox(serverConfigFileName); serverConfigFile = GetServerConfigFile(ServerConfigTextBox.Text, i); TheAdminServer.GameServerManager.AddGameServer(strName, strComment, groupIp, strDir, group, GameServer.ConfigGuardState.Configuring, serverConfigFile, GameServer.ServerType.gameserver, FtpDropDownList.SelectFtp); GameServer server = getGameServerByName(strName); servers.Add(server); } if (servers.Count == 0) { //LabelOpMsg.Text = StringDef.AddServer + StringDef.Failure + StringDef.Colon + StringDef.ConfigFile + StringDef.NotExist; LabelOpMsg.Text = StringDef.AddServer + StringDef.Failure + StringDef.Colon + "未指定任何要添加的服务器"; LabelOpMsg.Visible = true; } else { foreach (GameServer server in servers) { LordConfig lordConfig = GuardCfg(server.IpAddress); server.LordConfig.ServerCount = lordConfig.ServerCount; server.LordConfig.ServerIDs = lordConfig.ServerIDs; server.LordConfig.BindIp = server.IpAddress; //只对GameCenter的LordConfig添加GMCIp和GMCAccount的信息 if (server.Type == GameServer.ServerType.gamecenter) { if (GMCIpTextBox.Text.Length > 0) { lordConfig.GMCIp = GMCIpTextBox.Text; } if (GMCAccountTextBox.Text.Length > 0) { lordConfig.GMCAccount = GMCAccountTextBox.Text; } } TheAdminServer.GameServerManager.ModifyGameServer(server, server.Name, server.Comment, server.IpAddress, server.GameDir, server.Group, lordConfig, GameServer.ConfigGuardState.Configuring, server.ConfigContent, server.Type, FtpDropDownList.SelectFtp); SendGuardCfg(svr); } LabelSuccess.Text = StringDef.AddServer + StringDef.Colon + StringDef.Ok; LabelSuccess.Visible = true; LinkButtonEdit.Enabled = false; SaveArgumentsAsDefaultValues(); } } catch (Exception ex) { foreach (GameServer svr in servers) { TheAdminServer.GameServerManager.DeleteGameServer(svr); } Util.DebugLog(ex.ToString()); LabelOpMsg.Text = StringDef.AddServer + StringDef.Failure + StringDef.Colon + ex.Message; LabelOpMsg.Visible = true; } }
protected void SetToDefaultLordConfig_Click(object sender, EventArgs e) { ShowLordConfig(LordConfig.LoadFromDefaultConfig()); }
private bool Save2DB() { try { //权限检查 if (_operation == Operation.Add) { if (!WebUtil.CheckPrivilege(TheAdminServer.GameServerManager.SecurityObject, OpType.WRITE, Session)) { LabelOpMsg.Text = StringDef.NotEnoughPrivilege; return(false); } } else if (_operation == Operation.Modify) { int id = int.Parse(TextBoxServerId.Text); GameServer server = TheAdminServer.GameServerManager.GetGameServer(id); if (server != null && !WebUtil.CheckPrivilege(TheAdminServer.GameServerManager.SecurityObject, OpType.WRITE, Session)) { LabelOpMsg.Text = StringDef.NotEnoughPrivilege; return(false); } } else { LabelOpMsg.Text = StringDef.NotEnoughPrivilege; return(false); } string name = TextBoxServerName.Text; string comment = TextBoxServerComment.Text; string ip = TextBoxServerIpAddress.Text; string gameDir = TextBoxGameDir.Text; string cfgContent = ServerConfig.Text; ////游戏目录最后一个“/”必须有 //if (gameDir != null && gameDir.Length > 0) // if (!gameDir.EndsWith(GameServer.FilePathDelimiter) && !gameDir.EndsWith(GameServer.FilePathWinDelimiter)) // { // if (gameDir.IndexOf(GameServer.FilePathWinDelimiter) >= 0) // { // gameDir = gameDir + GameServer.FilePathWinDelimiter; // } // else // { // gameDir = gameDir + GameServer.FilePathDelimiter; // } // TextBoxGameDir.Text = gameDir; // } ServerGroup group = ServerGroupDropDownList.SelectedServerGroup; LordConfig lordConfig = null; //GameServer.ConfigGuardState configState = CheckBoxHasBeenConfigGuard.Checked ? GameServer.ConfigGuardState.Configed : GameServer.ConfigGuardState.NotConfig; GameServer.ServerType serverType = (GameServer.ServerType) int.Parse(ListBoxServerType.SelectedValue); if (PanelLordConfig.Visible) { if (GuardCfg(ref lordConfig) == false) { return(false); } } if (_operation == Operation.Add) { int severtype = ListBoxServerType.SelectedIndex; string serverConfigFile = WebConfig.WebsiteRootPath + WebConfig.ConfigTemplateDir + GetServerConfigFileName(severtype); ServerConfig.getServerConfigTextBox(serverConfigFile); if (TheAdminServer.GameServerManager.AddGameServer(name, comment, ip, gameDir, group, GameServer.ConfigGuardState.None, ServerConfig.Text, serverType, FtpDropDownList.SelectFtp)) { LabelSuccess.Visible = true; LabelSuccess.Text = StringDef.AddGameServer + StringDef.Colon + StringDef.Success; } else { LabelOpMsg.Text = StringDef.AddGameServer + StringDef.Colon + StringDef.Failure; return(false); } } else if (_operation == Operation.Modify) { int id = int.Parse(TextBoxServerId.Text); GameServer server = TheAdminServer.GameServerManager.GetGameServer(id); if (TheAdminServer.GameServerManager.ModifyGameServer(server, name, comment, ip, gameDir, group, lordConfig, GameServer.ConfigGuardState.Configuring, ServerConfig.Text, serverType, FtpDropDownList.SelectFtp)) { LabelSuccess.Visible = true; LabelSuccess.Text = StringDef.ModifyServer + StringDef.Colon + StringDef.Success; if (_server.LordConfig.FSEyeIp == string.Empty || _server.LordConfig.FSEyePort == 0) { LabelLordIsConfig.Visible = true; } else { LabelLordIsConfig.Visible = false; } } else { LabelOpMsg.Text = StringDef.ModifyServer + StringDef.Colon + StringDef.Failure; return(false); } } } catch (Exception ex) { string operationText = string.Empty; if (_operation == Operation.Add) { operationText = StringDef.AddServer; } else if (_operation == Operation.Modify) { operationText = StringDef.ModifyServer; } LabelOpMsg.Text = operationText + StringDef.Colon + StringDef.Failure + StringDef.Colon + ex.Message; } return(true); }