public void load_cmds(utente u, string path_cmds) { this.list = new List <cmd>(); mwl.xml.xml_doc d = new mwl.xml.xml_doc(path_cmds); foreach (mwl.xml.xml_node ng in d.nodes("//cmds/cmd-group")) { cmd_group grp = new cmd_group(ng.get_attr("title"), ng.get_attr("view") , ng.get_attr("type") != "" ? (cmd.type_cmd)Enum.Parse(typeof(cmd.type_cmd), ng.get_attr("type")) : cmd.type_cmd.none); if (grp.type == cmd.type_cmd.admin && !u.is_admin) { continue; } foreach (mwl.xml.xml_node nc in ng.nodes("cmd")) { cmd c = new cmd(grp) { prefix = nc.get_attr("prefix"), only_active_view = nc.get_bool("only_active_view"), view = nc.get_attr("view", grp.view) , action = nc.get_attr("action"), des = nc.get_attr("des"), action_optional = nc.get_attr("action-opt") == "true" , obj = nc.get_attr("object"), subobj = nc.get_attr("subobj"), subobj2 = nc.get_attr("subobj2") , hidden = nc.get_attr("hidden") == "true" , type = nc.get_attr("type") != "" ? (cmd.type_cmd)Enum.Parse(typeof(cmd.type_cmd), nc.get_attr("type")) : cmd.type_cmd.none }; if (c.type == cmd.type_cmd.admin && !u.is_admin) { continue; } this.list.Add(c); } } }
public cmd(cmd from) { this.group = from.group; this.prefix = from.prefix; this.action = from.action; this.des = from.des; this.action_optional = from.action_optional; this.obj = from.obj; this.subobj = from.subobj; this.subobj2 = from.subobj2; this.type = from.type; this.view = from.view != "" ? from.view : this.group.view; this.only_active_view = from.only_active_view; this.hidden = from.hidden; }
public cmd check_cmd(string txt, string active_view) { free_cmd c = new free_cmd(txt), c2 = new free_cmd("[action] " + txt); foreach (cmd cc in this.list) { if (cc.has_view && cc.only_active_view && active_view != null && cc.view != active_view) { continue; } if (cc.has_prefix && txt.StartsWith(cc.prefix)) { cmd res = new cmd(cc); res.line_cmd = txt; return(res); } if (is_like_cmd(cc.action, c.action) && is_like_cmd(cc.obj, c.obj) && is_like_cmd(cc.subobj, c.sub_obj()) && is_like_cmd(cc.subobj2, c.sub_obj(1))) { cmd res = new cmd(cc); res.line_cmd = txt; res.obj = cc.obj.Contains("{") ? c.obj : cc.obj; res.subobj = cc.subobj.Contains("{") ? c.sub_obj() : cc.subobj; res.subobj2 = cc.subobj2.Contains("{") ? c.sub_obj(1) : cc.subobj2; return(res); } if (cc.action_optional) { if (is_like_cmd(cc.obj, c2.obj) && is_like_cmd(cc.subobj, c2.sub_obj())) { cmd res = new cmd(cc); res.line_cmd = txt; res.action = cc.action; res.obj = cc.obj.Contains("{") ? c.obj : cc.obj; res.subobj = cc.subobj.Contains("{") ? c.sub_obj() : cc.subobj; return(res); } } } return(null); }