public void req_client_msg(int seq) { try { if (!end_point.connect_status) { return; } JObject obj = Msg_Parse.get_cmd_jsonobj(seq); uint msg_id = uint.Parse(obj["msg_id"].ToString()); if (msg_id < 5) { player_log("小于5的命令号是系统命令号"); return; } Bit_Buffer buffer = new Bit_Buffer(); Msg_Struct msg = Struct_Manager.instance.get_send_msg_struct((int)msg_id); msg.scan(buffer, obj); if (-1 == msg.scan(buffer, obj) || msg == null) { throw new Exception("命令参数错误"); } end_point_.send_to_server(msg_id, buffer); } catch (Exception ex) { Log.debug_log(ex.Message); } }
public int res_server_msg(uint msg_id, Bit_Buffer buffer) { Msg_Struct msg = Struct_Manager.instance.get_recv_msg_struct((int)msg_id); if (msg == null) { return(0); } player_log(msg.print_msg(buffer)); return(0); }
private int set_struct_buffer(Field_Info info, Bit_Buffer buffer, JObject jobject) { Msg_Struct msg = Struct_Manager.instance.get_msg_struct(info.field_type); if (msg == null) { return(-1); } set_msg_buffer(msg.field_list, buffer, jobject); return(0); }
public Msg_Struct get_msg_struct(string struct_name) { try { Msg_Struct msg = msg_name_map[struct_name]; return(msg); } catch (Exception ex) { Log.debug_log(ex.Message); Log.debug_log("msg_name_map 找不到关键字:" + struct_name); return(null); } }
public Msg_Struct get_recv_msg_struct(int msg_id) { try { Msg_Struct msg = recv_msg_id_map[msg_id]; return(msg); } catch (Exception ex) { Log.debug_log(ex.Message); Log.debug_log("recv_msg_id_map 找不到关键字:" + msg_id.ToString()); return(null); } }
static public void parse_cmd_and_send_buffer(string cmd) { Bit_Buffer buffer = new Bit_Buffer(); try { JObject jsonobj = null; Match match = Regex.Match(cmd, cmd_input_pattern_); string cmd_string = match.Groups[0].ToString(); if (cmd_string != "") { string[] cmd_str = cmd_string.Split('@'); int cmd_seq = int.Parse(cmd_str[1]); Log.debug_log("脚本命令序列:" + cmd_seq.ToString() + " => " + Msg_Parse.parse_cmd_string(cmd_list_[cmd_seq])); Game_Manager.instance.send_to_server(cmd_seq); return; } else if (Regex.IsMatch(cmd, cmd_input_pattern2)) { int cmd_seq = int.Parse(cmd); Log.debug_log("脚本命令序列:" + cmd_seq.ToString() + " => " + Msg_Parse.parse_cmd_string(cmd_list_[cmd_seq])); Game_Manager.instance.send_to_server(cmd_seq); return; } else { string real_cmd = Msg_Parse.parse_cmd_string(cmd); jsonobj = (JObject)JsonConvert.DeserializeObject(real_cmd); } uint msg_id = uint.Parse(jsonobj["msg_id"].ToString()); if (msg_id < 5) { Log.debug_log("小于5的命令号是系统命令号"); return; } Msg_Struct msg = Struct_Manager.instance.get_send_msg_struct((int)msg_id); if (-1 == msg.scan(buffer, jsonobj) || msg == null) { throw new Exception("命令参数错误"); } Game_Manager.instance.send_to_server(msg_id, buffer); } catch (Exception ex) { Log.debug_log(ex.Message); } }
public void load_config(string path, bool clear_map = true) { try { if (clear_map) { msg_name_map.Clear(); send_msg_id_map.Clear(); recv_msg_id_map.Clear(); } XmlDocument doc = new XmlDocument(); //加载xml配置时候忽略注释 XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; XmlReader reader = XmlReader.Create(path, settings); doc.Load(reader); XmlNode root_node = doc.SelectSingleNode(doc.DocumentElement.Name); if (root_node != null) { foreach (XmlNode node in root_node.ChildNodes) { Msg_Struct msg = new Msg_Struct(node); msg_name_map.Add(msg.struct_name, msg); if (msg.msg_id > 0) { if (msg.msg_name.IndexOf("RES") == 0) { recv_msg_id_map.Add(msg.msg_id, msg); } else if (msg.msg_name.IndexOf("REQ") == 0) { send_msg_id_map.Add(msg.msg_id, msg); } } } } } catch (Exception ex) { Log.debug_log(ex.Message); } }
private string get_struct_string(Field_Info info, Bit_Buffer buffer, bool from_vector = false) { string ret = "{"; if (!from_vector) { ret = (info.field_name + ":{"); } Msg_Struct msg = Struct_Manager.instance.get_msg_struct(info.field_type); string msg_str = msg.get_print_msg(msg.field_list, buffer); if (msg_str != "") { msg_str = msg_str.Substring(0, msg_str.Length - 2); } ret += msg_str; return(ret + "}, "); }