protected void TreeViewSystemObject_Expanded(Object sender, TreeNodeEventArgs e) { try { if (e.Node.ChildNodes.Count == 0) { FSEyeObject obj = AdminServer.TheInstance.SecurityManager.Get(int.Parse(e.Node.Value)); if (obj != null) { BuildObjectTree(e.Node, obj); SetCurrNodeExpandState(e.Node); } } //Nullable<bool> expandState = e.Node.Expanded; //if (expandState.HasValue && !expandState.Value) //{ // SetCurrNodeExpandState(e.Node); //} SetCurrNodeExpandState(e.Node); } catch (Exception ex) { FSEye.Util.DebugLog(ex.ToString()); } }
object GetSelectedObject() { try { string selectedText = TreeViewServerGroup.SelectedValue; if (selectedText.Length == 1) { FSEyeObject fsObject = TheAdminServer.SecurityManager.Get(SecurityObjectGameServerList); return(fsObject); } else if (selectedText.Length > 1) { if (selectedText[0] == 's') { int serverId = int.Parse(selectedText.Substring(1)); GameServer server = TheAdminServer.GameServerManager.GetGameServer(serverId); return(server); } else if (selectedText[0] == 'g') { int groupId = int.Parse(selectedText.Substring(1)); ServerGroup group = TheAdminServer.GameServerManager.GetGameServerGroup(groupId); return(group); } } } catch (Exception) { } return(null); }
/// <summary> /// 更新策略 /// </summary> public void Update(int strategyId, Strategy newStrategy, string name, string comment) { using (IBlazeDatabase db = DbFactory.GetDatabase()) { try { db.BeginTrans(); SecurityManager sm = AdminServer.TheInstance.SecurityManager; FSEyeObject strategyObject = sm.Get(strategyId); strategyObject.Name = name; strategyObject.Comment = comment; sm.Set(strategyObject, db); newStrategy.SecurityObject = strategyObject; IBlazeTable table = db.GetTable(TableString.StrategyTableName); DataSet strategyData = new DataSet(); table.Get(strategyData); DataTable strategyTable = strategyData.Tables[TableString.StrategyTableName]; AutomationManager am = AdminServer.TheInstance.AutomationManager; byte[] strategyBytes = am.Save(newStrategy.Automation); DataRow[] rows = strategyTable.Select(TableString.StrategyFieldId + "=" + strategyId); if (rows != null && rows.Length > 0) { DataRow row = rows[0]; row[TableString.StrategyFieldEvent] = (int)newStrategy.Event; row[TableString.StrategyFieldEnabled] = (newStrategy.Enabled ? 1 : 0); row[TableString.StrategyFieldAutomation] = strategyBytes; table.Set(strategyTable); } for (int i = 0; i < _strategyList.Count; i++) { Strategy strategy = _strategyList[i] as Strategy; if (strategy.SecurityObject.Id == strategyId) { _strategyList.RemoveAt(i); _strategyList.Add(newStrategy); break; } } db.CommitTrans(); } catch (Exception ex) { if (db != null) { db.RollbackTrans(); } throw ex; } } }
/// <summary> /// 更新计划任务 /// </summary> public void Update(int taskId, IScheduledTask newTask, string name, string comment) { using (IBlazeDatabase db = DbFactory.GetDatabase()) { try { db.BeginTrans(); SecurityManager sm = AdminServer.TheInstance.SecurityManager; FSEyeObject taskObject = sm.Get(taskId); taskObject.Name = name; taskObject.Comment = comment; sm.Set(taskObject, db); newTask.SecurityObject = taskObject; using (MemoryStream taskDataStream = new MemoryStream()) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(taskDataStream, newTask); byte[] taskData = taskDataStream.ToArray(); DataSet ds = new DataSet(); IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName); scheduledTaskTable.Get(ds); DataTable table = ds.Tables[TableString.ScheduledTaskTableName]; DataRow[] rows = table.Select(TableString.ScheduledTaskFieldId + "=" + newTask.SecurityObject.Id); if (rows.Length > 0) { DataRow row = rows[0]; row[TableString.ScheduledTaskFieldTaskData] = taskData; scheduledTaskTable.Set(table); } } foreach (ScheduledTaskUnit unit in _taskList) { if (unit.Task.SecurityObject.Id == taskId) { unit.AvoidCheckTimeout = 0; unit.Task = newTask; break; } } db.CommitTrans(); } catch (Exception ex) { if (db != null) { db.RollbackTrans(); } throw ex; } } }
/// <summary> /// 添加策略 /// </summary> public bool Add(Strategy strategy, string name, string comment) { using (IBlazeDatabase db = DbFactory.GetDatabase()) { try { db.BeginTrans(); SecurityManager sm = AdminServer.TheInstance.SecurityManager; FSEyeObject newObject = sm.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + name, db); byte[] strategyBytes = AdminServer.TheInstance.AutomationManager.Save(strategy.Automation); if (newObject != null && strategyBytes != null) { newObject.Comment = comment; sm.Set(newObject); strategy.SecurityObject = newObject; IBlazeTable table = db.GetTable(TableString.StrategyTableName); DataSet strategyData = new DataSet(); table.Get(strategyData); DataTable strategyTable = strategyData.Tables[TableString.StrategyTableName]; DataRow newRow = strategyTable.NewRow(); newRow[TableString.StrategyFieldId] = newObject.Id; newRow[TableString.StrategyFieldEvent] = (int)strategy.Event; newRow[TableString.StrategyFieldAutomation] = strategyBytes; newRow[TableString.StrategyFieldEnabled] = (strategy.Enabled ? 1 : 0); strategyTable.Rows.Add(newRow); table.Set(strategyTable); //设置权限 AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true); _strategyList.Add(strategy); db.CommitTrans(); return(true); } else { return(false); } } catch (Exception ex) { if (db != null) { db.RollbackTrans(); } throw ex; } } }
/// <summary> /// 开启服务 /// </summary> public void StartService(User user) { try { lock (this) { if (!_isRunning) { _gameServerManager.Startup(); _messageEngine.Startup(); _connectionManager.ClientConnect += new ClientConnectEventHandler(_gameServerManager.GameServerConnected); _connectionManager.ClientDisconnect += new ClientDisconnectEventHandler(_gameServerManager.GameServerDisconnected); try { _connectionManager.Startup(SystemConfig.Current.AdminServerListenPort, SystemConfig.Current.MaxConnectionCount); } catch (Exception ex) { throw (ex); } _FTPClient.Startup(); _gameServerMonitor.Start(); //从Initialize中移动到这里 _strategyManager.Load(); _scheduledTaskManager.Load(); _batchTaskManager.Load(); _automationManager.Working = true; _strategyManager.On = true; _scheduledTaskManager.On = true; //插件信息初始化 ServerPlugInFactory.Initialize(); if (SystemConfig.Current.EnablePaysys) { _paysysAgent.Start(); } if (user != null) { FSEyeObject serviceSwitch = SecurityManager.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + SecurityObjectServiceSwitch); LogSystem.TheInstance.WriteLog(user.SecurityObject.Id, OpType.WRITE, serviceSwitch.Id, string.Format(StringDef.LogMessageStartService, user.UserName)); } _isRunning = true; } } } catch (Exception e) { Util.DebugLog(e.Message); Util.DebugLog(e.StackTrace); } }
/// <summary> /// 权限检查 /// </summary> /// <param name="fullName">请求访问的对象的完整路径</param> /// <param name="opType">访问类型</param> /// <param name="session">会话</param> public static bool CheckPrivilege(string fullName, int opType, HttpSessionState session) { if (fullName == null) { throw new ArgumentNullException("fullName"); } FSEyeObject checkObj = AdminServer.TheInstance.SecurityManager.Get(fullName); return(CheckPrivilege(checkObj, opType, session)); }
protected void Page_Load(object sender, EventArgs e) { if (!WebUtil.CheckPrivilege(WebConfig.FunctionSecurityEditPrivilege, OpType.READ, Session)) { Response.Redirect(WebConfig.PageNotEnoughPrivilege, true); } if (Request.Params[WebConfig.ParamObjectId] != null) { try { int objectId = int.Parse(Request.Params[WebConfig.ParamObjectId]); _object = AdminServer.TheInstance.SecurityManager.Get(objectId); ////修改需要Write权限 //if (_object != null && !WebUtil.CheckPrivilege(_object, OpType.WRITE, Session)) //{ // Response.Redirect(WebConfig.PageNotEnoughPrivilege, true); //} if (_object != null) { LabelEditObject.Text = StringDef.EditObject + StringDef.Colon + _object.FullPath; } if (!IsPostBack) { LabelTitle.Text += "[" + _object.Name + "]"; } } catch (Exception) { //Response.Redirect("Security.aspx"); } } else { Response.Redirect("Security.aspx"); } SystemObjectTree1.SelectedObjectChanged += new EventHandler(SystemObjectTree1_SelectedObjectChanged); //System.Threading.Thread.Sleep(500); FSEyeObject selObj = SystemObjectTree1.SelectedObject; if (selObj != null) { LiteralSelectedNode.Text = selObj.FullPath; } else { LiteralSelectedNode.Text = StringDef.None; } }
/// <summary> /// 为新增UpdateServer设置权限时默认设置为其直接父亲的权限 /// </summary> /// <param name="srcObj">源</param> /// <param name="targetObj">目标</param> /// <param name="overWrite">是否覆盖(由AccessControlEntry的AddAce方法决定)</param> void AddFatherAce(FSEyeObject srcObj, FSEyeObject targetObj, bool overWrite) { foreach (AccessControlEntry ace in srcObj.Aces) { targetObj.AddAce(ace, true); } AdminServer.TheInstance.SecurityManager.Set(targetObj); foreach (FSEyeObject obj in targetObj.Children) { AddFatherAce(srcObj, obj, overWrite); } }
TreeNode CreateChildNode(FSEyeObject obj) { if (obj == null) throw new ArgumentNullException("obj"); TreeNode node = new TreeNode(obj.Name, obj.Id.ToString()); foreach (FSEyeObject child in obj.Children) { node.ChildNodes.Add(CreateChildNode(child)); } return node; }
/// <summary> /// 设置权限 /// </summary> /// <param name="fsObject">FSEyeObject</param> /// <param name="opType">操作</param> void SetAce(FSEyeObject fsObject, int opType, bool applyAll) { fsObject.AddAce(new AccessControlEntry(_object.Id, opType), true); //保存 AdminServer.TheInstance.SecurityManager.Set(fsObject); if (!applyAll || fsObject.Children == null) { return; } foreach (FSEyeObject child in fsObject.Children) { SetAce(child, opType, applyAll); } }
public bool Load() { this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectBatchTaskManager); this._batchTaskList.Clear(); using (IBlazeDatabase db = DbFactory.GetDatabase()) { IBlazeTable table = db.GetTable(TableString.BatchTaskTableName); DataSet batchTaskDataSet = new DataSet(); table.Get(batchTaskDataSet); DataTable batchTaskTable = batchTaskDataSet.Tables[TableString.BatchTaskTableName]; StrategyManager sm = AdminServer.TheInstance.StrategyManager; AutomationManager am = AdminServer.TheInstance.AutomationManager; foreach (DataRow row in batchTaskTable.Rows) { int batchTaskId = (int)row[TableString.BatchTaskId]; try { BatchTask batchTask = new BatchTask(); batchTask.Step = (int)row[TableString.BatchTaskStep]; batchTask.Automation = am.Load((byte[])row[TableString.BatchTaskAutomation]); string serverIds = SystemConfig.Current.DefaultEncoding.GetString((byte[])row[TableString.BatchTaskServerIds]); foreach (string serverIdText in serverIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { int serverId = int.Parse(serverIdText); GameServer server = AdminServer.TheInstance.GameServerManager.GetGameServer(serverId); if (server != null) { batchTask.AddServer(serverId); } } FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(batchTaskId); if (secObj != null) { batchTask.SecurityObject = secObj; _batchTaskList.Add(batchTask); } } catch (Exception e) { Util.DebugLog(e.StackTrace); continue; } } return(true); } }
private void CreateDataTable(DataTable table) { foreach (DataRow dataRow in table.Rows) { TableRow row = new TableRow(); TableCell cell; cell = new TableCell(); int fsObjectId0 = int.Parse(dataRow[1].ToString()); FSEyeObject fsObject0 = TheAdminServer.SecurityManager.Get(fsObjectId0); cell.Text = fsObject0 == null?string.Format("{0}(ID)", fsObjectId0) : fsObject0.Name; row.Cells.Add(cell); cell = new TableCell(); switch (int.Parse(dataRow[2].ToString())) { case OpType.READ: cell.Text = "READ"; break; case OpType.WRITE: cell.Text = "WRITE"; break; case OpType.EXECUTE: cell.Text = "EXECUTE"; break; } row.Cells.Add(cell); cell = new TableCell(); int fsObjectId = int.Parse(dataRow[3].ToString()); FSEyeObject fsObject = TheAdminServer.SecurityManager.Get(fsObjectId); cell.Text = fsObject == null?string.Format("{0}(ID)", fsObjectId) : fsObject.Name; row.Cells.Add(cell); cell = new TableCell(); cell.Text = Encoding.Default.GetString(dataRow[4] as byte[]); row.Cells.Add(cell); cell = new TableCell(); cell.Text = dataRow[5].ToString(); row.Cells.Add(cell); TableLog.Rows.Add(row); } }
TreeNode CreateChildNode(FSEyeObject obj) { if (obj == null) { throw new ArgumentNullException("obj"); } TreeNode node = new TreeNode(obj.Name, obj.Id.ToString()); foreach (FSEyeObject child in obj.Children) { node.ChildNodes.Add(CreateChildNode(child)); } return(node); }
void BuildObjectTree(TreeNode node, FSEyeObject root) { if (root.Children != null) { foreach (FSEyeObject child in root.Children) { TreeNode childNode = new TreeNode(child.Name, child.Id.ToString()); childNode.PopulateOnDemand = true; node.ChildNodes.Add(childNode); //BuildObjectTree(childNode, child); } } //TreeViewSystemObject.Nodes.Clear(); //TreeNode node = new TreeNode(root.Name, root.Id.ToString()); //TreeViewSystemObject.Nodes.Add(node); }
void BuildObjectTree(TreeNode node,FSEyeObject root) { if (root.Children != null) { foreach (FSEyeObject child in root.Children) { TreeNode childNode = new TreeNode(child.Name, child.Id.ToString()); childNode.PopulateOnDemand = true; node.ChildNodes.Add(childNode); //BuildObjectTree(childNode, child); } } //TreeViewSystemObject.Nodes.Clear(); //TreeNode node = new TreeNode(root.Name, root.Id.ToString()); //TreeViewSystemObject.Nodes.Add(node); }
protected void Page_Load(object sender, EventArgs e) { if (!WebUtil.CheckPrivilege(WebConfig.FunctionSecurityEditPrivilege, OpType.READ, Session)) { Response.Redirect(WebConfig.PageNotEnoughPrivilege, true); } if (Request.Params[WebConfig.ParamObjectId] != null) { try { int objectId = int.Parse(Request.Params[WebConfig.ParamObjectId]); _object = AdminServer.TheInstance.SecurityManager.Get(objectId); ////修改需要Write权限 //if (_object != null && !WebUtil.CheckPrivilege(_object, OpType.WRITE, Session)) //{ // Response.Redirect(WebConfig.PageNotEnoughPrivilege, true); //} if (_object != null) LabelEditObject.Text = StringDef.EditObject + StringDef.Colon + _object.FullPath; if (!IsPostBack) LabelTitle.Text += "["+_object.Name+"]"; } catch (Exception) { //Response.Redirect("Security.aspx"); } } else { Response.Redirect("Security.aspx"); } SystemObjectTree1.SelectedObjectChanged += new EventHandler(SystemObjectTree1_SelectedObjectChanged); //System.Threading.Thread.Sleep(500); FSEyeObject selObj = SystemObjectTree1.SelectedObject; if (selObj != null) { LiteralSelectedNode.Text = selObj.FullPath; } else { LiteralSelectedNode.Text = StringDef.None; } }
private string GetGroupFullName(ServerGroup group, string groupPath) { FSEyeObject groupParent = group.SecurityObject.Parent; while (groupParent.Parent != null) { ServerGroup parentGroup = TheAdminServer.GameServerManager.GetGameServerGroup(groupParent.Id); if (parentGroup == null) { break; } groupPath = parentGroup.Name + "/" + groupPath; groupParent = parentGroup.SecurityObject.Parent; } return(groupPath); }
protected void TreeViewSystemObject_NodePopulate(Object sender, TreeNodeEventArgs e) { try { if (e.Node.ChildNodes.Count == 0) { FSEyeObject obj = AdminServer.TheInstance.SecurityManager.Get(int.Parse(e.Node.Value)); if (obj != null) { BuildObjectTree(e.Node, obj); } } } catch (Exception ex) { FSEye.Util.DebugLog(ex.ToString()); } }
/// <summary> /// 载入计划任务 /// </summary> public void Load() { this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectScheduledTaskManager); _taskList.Clear(); using (IBlazeDatabase db = DbFactory.GetDatabase()) { IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName); DataSet ds = new DataSet(); scheduledTaskTable.Get(ds); DataTable table = ds.Tables[TableString.ScheduledTaskTableName]; foreach (DataRow row in table.Rows) { try { int id = (int)row[TableString.ScheduledTaskFieldId]; byte[] taskData = (byte[])row[TableString.ScheduledTaskFieldTaskData]; MemoryStream taskDataStream = new MemoryStream(taskData); IFormatter formatter = new BinaryFormatter(); IScheduledTask task = (IScheduledTask)formatter.Deserialize(taskDataStream); if (task != null) { FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(id); if (secObj != null) { task.SecurityObject = secObj; ScheduledTaskUnit unit = new ScheduledTaskUnit(); unit.Task = task; unit.AvoidCheckTimeout = 0; _taskList.Add(unit); } } } catch (Exception e) { Util.DebugLog(e.StackTrace); continue; } } } }
protected void ButtonSave_Click(object sender, EventArgs e) { //if (!WebUtil.CheckPrivilege(_object, OpType.WRITE, Session)) //{ // Response.Redirect(WebConfig.PageNotEnoughPrivilege, true); //} ButtonModify.Enabled = true; ButtonSave.Enabled = false; ButtonCancel.Enabled = false; RadioButtonListApplyAll.Enabled = false; FSEyeObject selectedObject = SystemObjectTree1.SelectedObject; if (selectedObject == null) { return; } int opType = 0; if (CheckBoxAllowRead.Checked) { opType |= OpType.READ; } if (CheckBoxAllowWrite.Checked) { opType |= OpType.WRITE; } if (CheckBoxAllowExecute.Checked) { opType |= OpType.EXECUTE; } if (!WebUtil.CheckPrivilege(_object.Id, OpType.WRITE, Session)) { Response.Redirect(WebConfig.PageNotEnoughPrivilege, true); } bool applyAll = RadioButtonListApplyAll.SelectedIndex == 0 ? true : false; SetAce(selectedObject, opType, applyAll); PanelAce.Enabled = false; }
/// <summary> /// 载入策略配置 /// </summary> public void Load() { this.SecurityObject = AdminServer.TheInstance.SecurityManager.Get(SecurityObjectStrategyManager); _strategyList.Clear(); using (IBlazeDatabase db = DbFactory.GetDatabase()) { IBlazeTable table = db.GetTable(TableString.StrategyTableName); DataSet strategyData = new DataSet(); table.Get(strategyData); DataTable strategyTable = strategyData.Tables[TableString.StrategyTableName]; StrategyManager sm = AdminServer.TheInstance.StrategyManager; AutomationManager am = AdminServer.TheInstance.AutomationManager; foreach (DataRow row in strategyTable.Rows) { int strategyId = (int)row[TableString.StrategyFieldId]; try { Strategy strategy = new Strategy(); strategy.Event = (FSEyeEvent)row[TableString.StrategyFieldEvent]; strategy.Automation = am.Load((byte[])row[TableString.StrategyFieldAutomation]); strategy.Enabled = ((int)row[TableString.StrategyFieldEnabled]) == 0 ? false : true; FSEyeObject secObj = AdminServer.TheInstance.SecurityManager.Get(strategyId); if (secObj != null) { strategy.SecurityObject = secObj; _strategyList.Add(strategy); } } catch (Exception e) { Util.DebugLog(e.StackTrace); continue; } } } }
/// <summary> /// 权限检查 /// </summary> /// <param name="checkObj">请求访问的对象</param> /// <param name="opType">访问类型</param> /// <param name="session">会话</param> public static bool CheckPrivilege(FSEyeObject checkObj, int opType, HttpSessionState session) { //加入异常处理 try { //return true; if (checkObj == null) { throw new ArgumentNullException("checkObj"); } if (session == null) { throw new ArgumentNullException("session"); } object obj = null; if ((obj = session["CurrentUser"]) != null) { int id = (obj as UserInfo).Id; User user = AdminServer.TheInstance.SecurityManager.GetLoginUser(id); if (user == null) { throw new Exception("login user with id=\"" + id + "\" can not be found"); } if (checkObj.CheckPrivilege(user, opType) == CheckPrivilegeResult.Allow) { return(true); } } } catch (Exception) { return(false); } return(false); }
/// <summary> /// 关闭服务 /// </summary> public void StopService(User user) { lock (this) { if (_isRunning) { _strategyManager.On = false; _gameServerMonitor.Stop(); _automationManager.Working = false; _connectionManager.Shutdown(); _connectionManager.ClientConnect -= new ClientConnectEventHandler(_gameServerManager.GameServerConnected); _connectionManager.ClientDisconnect -= new ClientDisconnectEventHandler(_gameServerManager.GameServerDisconnected); _messageEngine.Shutdown(); _gameServerManager.Shutdown(); _FTPClient.Shutdown(); _paysysAgent.Stop(); FSEyeObject serviceSwitch = SecurityManager.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + SecurityObjectServiceSwitch); LogSystem.TheInstance.WriteLog(user.SecurityObject.Id, OpType.WRITE, serviceSwitch.Id, string.Format(StringDef.LogMessageStopService, user.UserName)); _isRunning = false; } } }
void RefreshCurrentPrivilege() { FSEyeObject selectedObject = SystemObjectTree1.SelectedObject; if (selectedObject != null) { int objectId = _object.Id; AccessControlEntry[] aces = selectedObject.Aces; CheckBoxAllowRead.Checked = false; CheckBoxAllowWrite.Checked = false; CheckBoxAllowExecute.Checked = false; foreach (AccessControlEntry ace in aces) { if (ace.OperatorId == objectId) { CheckBoxAllowRead.Checked = (ace.Operation & OpType.READ) > 0; CheckBoxAllowWrite.Checked = (ace.Operation & OpType.WRITE) > 0; CheckBoxAllowExecute.Checked = (ace.Operation & OpType.EXECUTE) > 0; } } } }
public void Initialize() { InitializeDatabase(false); Util.DebugLog("AdminServer Initialize: Database Done."); _securityManager.Startup(); _securityObject = SecurityManager.Root; Util.DebugLog("AdminServer Initialize: SecurityManager Done."); InitAutomations(); Util.DebugLog("AdminServer Initialize: Automation Done."); InitStrategy(); Util.DebugLog("AdminServer Initialize: Strategy Done."); _paysysAgent = new OraclePaySysAgent(SystemConfig.Current.PaySysDbConnectionString); _paysysAgent.Error += new EventHandler(_paysysAgent_Error); Util.DebugLog("AdminServer Initialize: Paysys Done."); LogSystem.TheInstance.LogDeviceList.Add(new MySqlLogDevice(SystemConfig.Current.DbConnectionString)); Util.DebugLog("AdminServer Initialize: LogSystem Done."); try { FS2GameDataManager.TheInstance.Init(SystemConfig.Current.GameSettingDir, SystemConfig.Current.DefaultEncoding); if (SystemConfig.Current.PreloadGameData) { FS2GameDataManager.TheInstance.Load(); } Util.DebugLog("AdminServer Initialize: FS2GameDataManager Done."); } catch (Exception ex) { Util.DebugLog(ex.ToString()); } }
protected void ButtonCreateServerGroup_Click(object sender, EventArgs e) { //需要在GameServerManager上有Write的权限 if (!WebUtil.CheckPrivilege(TheAdminServer.GameServerManager.SecurityObject, OpType.WRITE, Session)) { LabelOpMsg.Text = StringDef.NotEnoughPrivilege; LabelOpMsg.Visible = true; return; } string serverGroupName = TextBoxServerGroupName.Text.Trim(); if (serverGroupName.Length == 0) { LabelOpMsg.Text = "服务器组名不能为空"; LabelOpMsg.Visible = true; return; } string serverGroupComment = TextBoxServerGroupComment.Text.Trim(); if (serverGroupComment == String.Empty) { serverGroupComment = "服务器组添加时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } string serverGroupCabinet; if (DropDownListCabinet.SelectedIndex == 0) { serverGroupCabinet = String.Empty; } else { serverGroupCabinet = DropDownListCabinet.SelectedItem.Text; } try { ServerGroup parentGroup = null; object selectedObj = GetSelectedObject(); if (selectedObj != null) { if (selectedObj.GetType() == typeof(ServerGroup)) { parentGroup = selectedObj as ServerGroup; TheAdminServer.GameServerManager.AddServerGroup( serverGroupName, serverGroupComment, ServerGroup.Type.Group, parentGroup, serverGroupCabinet); ServerGroupDropDownList.Refresh(); CreateServerGroupTree(); } else { FSEyeObject fsObject = selectedObj as FSEyeObject; if (fsObject != null && fsObject.FullPath.Equals(SecurityObjectGameServerList)) { TheAdminServer.GameServerManager.AddServerGroup( serverGroupName, serverGroupComment, ServerGroup.Type.Group, parentGroup, serverGroupCabinet); ServerGroupDropDownList.Refresh(); CreateServerGroupTree(); } } //if (TextBoxCabinet.Text.Trim() != string.Empty) //{ // if (!AdminServer.TheInstance.GameServerManager.CabinetList.Contains(TextBoxCabinet.Text.Trim())) // { // AdminServer.TheInstance.GameServerManager.CabinetList.Add(TextBoxCabinet.Text.Trim()); // } //} LabelSuccess.Text = StringDef.OperationSucceed + StringDef.Colon + "服务器组 " + serverGroupName + " 添加成功"; LabelSuccess.Visible = true; } } catch (Exception ex) { LabelOpMsg.Text = StringDef.OperationFail + StringDef.Colon + ex.Message; LabelOpMsg.Visible = true; return; } }
/// <summary> /// 修改任务 /// </summary> public bool EditTask(int taskId, int step, IAutomation automation, GameServer[] servers, string name, string comment) { using (IBlazeDatabase db = DbFactory.GetDatabase()) { try { BatchTask task = this.GetBatchTask(taskId); if (task == null) { return(false); } db.BeginTrans(); SecurityManager sm = AdminServer.TheInstance.SecurityManager; FSEyeObject taskObject = sm.Get(taskId); taskObject.Name = name; taskObject.Comment = comment; sm.Set(taskObject, db); StringBuilder serverIdText = new StringBuilder(); foreach (GameServer server in servers) { serverIdText.Append(server.Id); serverIdText.Append(','); } IBlazeTable batchTaskTable = db.GetTable(TableString.BatchTaskTableName); DataSet batchTaskDataSet = new DataSet(); batchTaskTable.Get(batchTaskDataSet); DataTable taskTable = batchTaskDataSet.Tables[TableString.BatchTaskTableName]; DataRow[] taskRows = taskTable.Select(string.Concat(TableString.BatchTaskId, "=", taskId)); if (taskRows != null && taskRows.Length > 0) { taskRows[0][TableString.BatchTaskStep] = step; taskRows[0][TableString.BatchTaskAutomation] = AdminServer.TheInstance.AutomationManager.Save(automation); taskRows[0][TableString.BatchTaskServerIds] = SystemConfig.Current.DefaultEncoding.GetBytes(serverIdText.Length == 0 ? string.Empty : serverIdText.ToString(0, serverIdText.Length - 1)); batchTaskTable.Set(taskTable); } //修改内存中数据 task.Step = step; task.Automation = automation; task.ClearServers(); foreach (GameServer server in servers) { task.AddServer(server.Id); } db.CommitTrans(); return(true); } catch (Exception) { if (db != null) { db.RollbackTrans(); } return(false); } } }
/// <summary> /// 权限检查 /// </summary> /// <param name="checkObj">请求访问的对象</param> /// <param name="opType">访问类型</param> /// <param name="session">会话</param> public static bool CheckPrivilege(FSEyeObject checkObj, int opType, HttpSessionState session) { //加入异常处理 try { //return true; if (checkObj == null) { throw new ArgumentNullException("checkObj"); } if (session == null) { throw new ArgumentNullException("session"); } object obj = null; if ((obj = session["CurrentUser"]) != null) { int id = (obj as UserInfo).Id; User user = AdminServer.TheInstance.SecurityManager.GetLoginUser(id); if (user == null) { throw new Exception("login user with id=\"" + id + "\" can not be found"); } if (checkObj.CheckPrivilege(user, opType) == CheckPrivilegeResult.Allow) { return true; } } } catch (Exception) { return false; } return false; }
/// <summary> /// 添加计划任务 /// </summary> public void Add(IScheduledTask task, string name, string comment) { if (task == null) { throw new ArgumentNullException("task"); } if (name == null) { throw new ArgumentNullException("name"); } if (comment == null) { throw new ArgumentNullException("comment"); } using (IBlazeDatabase db = DbFactory.GetDatabase()) { try { db.BeginTrans(); SecurityManager sm = AdminServer.TheInstance.SecurityManager; FSEyeObject newObject = sm.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + name, db); byte[] automationData = AdminServer.TheInstance.AutomationManager.Save(task.Automation); MemoryStream taskDataStream = new MemoryStream(); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(taskDataStream, task); byte[] taskData = taskDataStream.ToArray(); if (newObject != null && automationData != null && taskData != null) { newObject.Comment = comment; sm.Set(newObject); task.SecurityObject = newObject; IBlazeTable scheduledTaskTable = db.GetTable(TableString.ScheduledTaskTableName); DataSet ds = new DataSet(); scheduledTaskTable.Get(ds); DataTable table = ds.Tables[TableString.ScheduledTaskTableName]; DataRow row = table.NewRow(); row[TableString.ScheduledTaskFieldId] = newObject.Id; row[TableString.ScheduledTaskFieldTaskData] = taskData; table.Rows.Add(row); scheduledTaskTable.Set(table); ScheduledTaskUnit unit = new ScheduledTaskUnit(); unit.Task = task; unit.AvoidCheckTimeout = 0; _taskList.Add(unit); //设置权限 AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true); db.CommitTrans(); } } catch (Exception) { db.RollbackTrans(); } } }
/// <summary> /// 权限检查 /// </summary> /// <param name="objId">请求访问的对象的编号</param> /// <param name="opType">访问类型</param> /// <param name="session">会话</param> public static bool CheckPrivilege(int objId, int opType, HttpSessionState session) { FSEyeObject checkObj = AdminServer.TheInstance.SecurityManager.Get(objId); return(CheckPrivilege(checkObj, opType, session)); }
/// <summary> /// 添加任务 /// </summary> public bool AddTask(BatchTask task, string name, string comment) { if (!_batchTaskList.Contains(task)) { using (IBlazeDatabase db = DbFactory.GetDatabase()) { try { db.BeginTrans(); SecurityManager sm = AdminServer.TheInstance.SecurityManager; FSEyeObject newObject = sm.Get(SecurityObject.FullPath + SecurityManager.ObjectPathDelimiter + name, db); byte[] taskAutomationBytes = AdminServer.TheInstance.AutomationManager.Save(task.Automation); if (newObject != null && taskAutomationBytes != null) { IBlazeTable table = db.GetTable(TableString.BatchTaskTableName); DataSet taskDataSet = new DataSet(); table.Get(taskDataSet); DataTable taskTable = taskDataSet.Tables[TableString.BatchTaskTableName]; DataRow newRow = taskTable.NewRow(); newRow[TableString.BatchTaskId] = newObject.Id; newRow[TableString.BatchTaskAutomation] = taskAutomationBytes; newRow[TableString.BatchTaskStep] = task.Step; StringBuilder serverIdText = new StringBuilder(); foreach (int serverId in task.Servers) { serverIdText.Append(serverId); serverIdText.Append(','); } newRow[TableString.BatchTaskServerIds] = SystemConfig.Current.DefaultEncoding.GetBytes(serverIdText.Length == 0 ? string.Empty : serverIdText.ToString(0, serverIdText.Length - 1)); taskTable.Rows.Add(newRow); table.Set(taskTable); //设置权限并更新SecurityObject AdminServer.TheInstance.SecurityManager.CopyAce(newObject.Parent, newObject, true); newObject.Comment = comment; sm.Set(newObject); task.SecurityObject = newObject; _batchTaskList.Add(task); db.CommitTrans(); return(true); } } catch (Exception) { if (db != null) { db.RollbackTrans(); } return(false); } } } return(false); }
public bool AddUpdateServer(FTPServer server) { IBlazeDatabase db = null; try { db = DbFactory.GetDatabase(); db.BeginTrans(); SecurityManager sm = AdminServer.TheInstance.SecurityManager; //构造相关安全对象 string newUpdateServerObjPath = sm.Root.FullName + SecurityManager.ObjectPathDelimiter + SecurityObjectSystem + SecurityManager.ObjectPathDelimiter + SecurityObjectUpdateManagement + SecurityManager.ObjectPathDelimiter + SecurityObjectUpdateServer + SecurityManager.ObjectPathDelimiter + server.Literal; FSEyeObject newUpdateServerObj = sm.Get(newUpdateServerObjPath, db); sm.Set(newUpdateServerObj); AddFatherAce(newUpdateServerObj.Parent, newUpdateServerObj, true); //IBlazeTable table = db.GetTable(TableString.UpdateServerTableName); //DataSet taskData = new DataSet(); //table.Get(taskData); //DataTable taskTable = taskData.Tables[TableString.UpdateServerTableName]; //DataRow addRow = taskTable.Rows.Add(newUpdateServerObj.Id, // server.Address, // server.Port, // server.UserName, // server.Password, // server.Literal); //table.Set(taskTable); //插入数据到服务器表 string[] fields = new string[] { TableString.UpdateServerFieldId, TableString.UpdateServerFieldAddress, TableString.UpdateServerFieldPort, TableString.UpdateServerFieldUsername, TableString.UpdateServerFieldPassword, TableString.UpdateServerFieldLiteral, TableString.UpdateServerFieldUpdateServerType }; object[] values = new object[] { newUpdateServerObj.Id, server.Address, server.Port, server.UserName, server.Password, server.Literal, (Int16)server.FtpServerType }; IBlazeTable serverTable = db.GetTable(TableString.UpdateServerTableName); serverTable.Add(fields, values); db.CommitTrans(); server.SecurityObject = newUpdateServerObj; this._FTPServerList.Add(server); return(true); } catch (Exception ex) { Util.DebugLog(ex.ToString()); if (db != null) { db.RollbackTrans(); } } finally { if (db != null) { db.Close(); } } return(false); }
public void Startup() { lock (this) { if (!_running) { _securityObject = AdminServer.TheInstance.SecurityManager.Get("/FSEye/System/GameServerManager"); _configGuardServerList.Clear(); _authenticationList.Clear(); //载入游戏服务器 LoadGameServers(); //载入服务器组 LoadServerGroups(); //排序 SortServerGroupByGroupId(); _systemTickTimer.Enabled = true; _isConfigingGuard = true; //载入ServerMap _serverMap.LoadServerMap(); _running = true; _maxPlayerTimer.Enabled = true; _GroupPlayerCountTimer.Enabled = true; //载入区域数据 RootRegion = new ServerRegion(); DirectUnderRegion = new ServerRegion(); LoadServerRegions(); LoadCabinet(); } } }
/// <summary> /// 设置权限 /// </summary> /// <param name="fsObject">FSEyeObject</param> /// <param name="opType">操作</param> void SetAce(FSEyeObject fsObject,int opType,bool applyAll) { fsObject.AddAce(new AccessControlEntry(_object.Id, opType),true); //保存 AdminServer.TheInstance.SecurityManager.Set(fsObject); if (!applyAll||fsObject.Children == null) return; foreach (FSEyeObject child in fsObject.Children) { SetAce(child, opType,applyAll); } }