private void Awake() { CSharp = EditorPrefs.GetString("cache_protocol_path_c#"); CPP = EditorPrefs.GetString("cache_protocol_path_c++"); Erlang = EditorPrefs.GetString("cache_protocol_path_erlang"); Go = EditorPrefs.GetString("cache_protocol_path_go"); Java = EditorPrefs.GetString("cache_protocol_path_java"); if (string.IsNullOrEmpty(CSharp)) { CSharp = Application.dataPath + "/Protocols/"; } if (string.IsNullOrEmpty(CPP)) { CPP = ProtocolGenerator.LanguageImplemented("C++") ? EditorUtil.GetProjectName(true) + "Protocols/CPP/" : "Language not supported"; } if (string.IsNullOrEmpty(Erlang)) { Erlang = ProtocolGenerator.LanguageImplemented("Erlang") ? EditorUtil.GetProjectName(true) + "Protocols/Erlang/" : "Language not supported"; } if (string.IsNullOrEmpty(Go)) { Go = ProtocolGenerator.LanguageImplemented("Go") ? EditorUtil.GetProjectName(true) + "Protocols/Go/" : "Language not supported"; } if (string.IsNullOrEmpty(Java)) { Java = ProtocolGenerator.LanguageImplemented("Java") ? EditorUtil.GetProjectName(true) + "Protocols/Java/" : "Language not supported"; } }
private void Save() { EditorPrefs.SetString("cache_protocol_path_c#", CSharp); EditorPrefs.SetString("cache_protocol_path_c++", ProtocolGenerator.LanguageImplemented("C++") ? CPP : ""); EditorPrefs.SetString("cache_protocol_path_erlang", ProtocolGenerator.LanguageImplemented("Erlang") ? Erlang : ""); EditorPrefs.SetString("cache_protocol_path_go", ProtocolGenerator.LanguageImplemented("Go") ? Go : ""); EditorPrefs.SetString("cache_protocol_path_java", ProtocolGenerator.LanguageImplemented("Java") ? Java : ""); }
public string[] Generate(PacketDef pkt, ProtocolGenerator g) { var code = ParseComment(pkt.comment); var pn = ParsePacketName(pkt.name); //code += string.Format("[PacketInfo(group = {0}, ID = {1}, early = {2})]\r\npublic class {3} : PacketObject<{3}>\r\n{{\r\n", pkt.group, pkt.id, pkt.earlySend ? "true" : "false", ParsePacketName(pkt.name)); code += string.Format("[PacketInfo(group = {0}, ID = {1})]\r\npublic class {2} : PacketObject<{2}>\r\n{{\r\n", pkt.group, pkt.id, ParsePacketName(pkt.name)); string rc = "", wc = "", dc0 = "", dc1 = "", cc0 = "", cc1 = ""; var fs = pkt.fields; foreach (var f in fs) { code += string.IsNullOrEmpty(f.comment) ? "" : " /// <summary>\r\n /// " + f.comment + "\r\n /// </summary>\r\n"; code += string.Format(" public {0} {1};\r\n", f.custom ? ParsePacketName(f.type) : ParseType(f.type), f.name); rc += string.Format(" {0, -" + (pkt.fl[1] + 2) + "} = p.Read{1}();\r\n", f.name, ParseReadName(f)); wc += " p.Write(" + f.name + ");\r\n"; if (f.custom || f.array) { dc0 += f.custom && f.array ? string.Format(" BackArray({0});\r\n", f.name) : ""; dc1 += string.Format(" {0, -" + (pkt.fl[2] + 2) + "} = null;\r\n", f.name); } if (!f.custom) { cc0 += string.Format(" dst.{0, -" + (pkt.fl[1] + 2) + "} = {0};\r\n", f.name); } else { cc1 += string.Format(" if ({0, -" + (pkt.fl[2] + 1) + "} != null) {0}.CopyTo(ref dst.{0});\r\n", f.name); } } var dc = dc0 + (string.IsNullOrEmpty(dc0) || string.IsNullOrEmpty(dc1) ? "" : "\r\n") + dc1; var cc = cc0 + (string.IsNullOrEmpty(cc0) || string.IsNullOrEmpty(cc1) ? "" : "\r\n") + cc1; if (!string.IsNullOrEmpty(cc)) { cc = "\r\n" + cc; } code += (fs.Length > 0 ? "\r\n" : "") + " private " + pn + "() { }\r\n"; code += string.IsNullOrEmpty(rc) ? "" : "\r\n public override void ReadFromPacket(Packet p)\r\n {\r\n" + rc + " }\r\n"; code += string.IsNullOrEmpty(wc) ? "" : "\r\n public override void WriteToPacket(Packet p)\r\n {\r\n" + wc + " }\r\n"; code += string.IsNullOrEmpty(cc) ? "" : "\r\n public override void CopyTo(ref " + pn + " dst)\r\n {\r\n base.CopyTo(ref dst);\r\n" + cc + " }\r\n"; code += string.IsNullOrEmpty(dc) ? "" : "\r\n public override void Clear()\r\n {\r\n" + dc + " }\r\n"; code += "}\r\n"; return(new string[] { code }); }
public string[] Generate(PacketDef pkt, ProtocolGenerator g) { var code = ParseComment(pkt.comment); code += string.Format("message {0}[id={1}{2}]\r\n{{\r\n", pkt.name, pkt.id, string.IsNullOrEmpty(pkt.router) ? "" : ", route=" + pkt.router); var fs = pkt.fields; for (var i = 0; i < fs.Length; ++i) { var f = fs[i]; code += string.Format(" {0} {1,-" + (pkt.fl[0] + 2) + "} {2,-" + (pkt.fl[1] + 2) + "} = " + (string.IsNullOrEmpty(f.comment) ? "{3}" : "{3, -8}// ") + "{4}\r\n", f.array ? "repeated" : "required", f.custom? f.typeName: ParseType(f.type), f.name, (i + 1) + ";", f.comment); } code += "}\r\n"; return(new string[] { code }); }
public string[] ParseDesc(string desc, ProtocolGenerator g) { var lines = Util.ParseString <string>(desc, true, '\n'); var d = "/*************************************************************************************************************\r\n * \r\n"; for (var i = 0; i < lines.Length; ++i) { var line = lines[i]; line = line.StartsWith(" ") ? line.Substring(1) : line; if (i == 0) { line = string.Format(line, GetType().Name); } d += " * " + line + "\r\n"; } d += " * \r\n *************************************************************************************************************/\r\n\r\n"; return(new string[] { d }); }
public string[] ParseDesc(string desc, ProtocolGenerator g) { var lines = Util.ParseString <string>(desc, true, '\n'); var d = "/*************************************************************************************************************\r\n * \r\n"; for (var i = 0; i < lines.Length; ++i) { var line = lines[i]; line = line.StartsWith(" ") ? line.Substring(1) : line; if (i == 0) { line = string.Format(line, GetType().Name); } d += " * " + line + "\r\n"; } d += " * \r\n *************************************************************************************************************/\r\n\r\n"; var dh = d + string.Format("#ifndef {0}\r\n#define {0}\r\n\r\n#include \"Packet.h\"\r\n{{0}}\r\nnamespace Packets::{1}\r\n{{{{\r\n", "_CM_GAME_CLASS_PACKETS_" + g.name.ToUpper() + "_H_", g.name); var dc = d + string.Format("#include <CMLog.h>\r\n#include \"WorldSession.h\"\r\n#include \"{0}.h\"{{0}}\r\n\r\n", GetFileName(g.group, g.name)); return(new string[] { dh, dc, "" }); // class defines / handlers / external include protocol groups }
public string[] ParseDesc(string desc, ProtocolGenerator g) { var lines = Util.ParseString <string>(desc, true, '\n'); var d = "//*************************************************************************************************************\r\n//\r\n"; for (var i = 0; i < lines.Length; ++i) { var line = lines[i]; line = line.StartsWith(" ") ? line.Substring(1) : line; if (i == 0) { line = string.Format(line, GetType().Name); } d += "// " + line + "\r\n"; } d += "//\r\n//*************************************************************************************************************\r\n\r\n"; // Add group info for erlang d += "// global route info\r\n"; d += string.Format("group: {0}\r\nname : {1}\r\n\r\n", g.group, g.name.ToLower()); return(new string[] { d }); }
public void OnComplete(string[] code, PacketDef[] gps, ProtocolGenerator g) { code[0] += "}}\r\n\r\nusing namespace Packets::" + g.name + ";\r\n\r\n#endif"; var refs = Util.ParseString <string>(code[2].Replace("\r\n", "\n").Replace("\n\n", "\n"), false, '\n'); string def = "", inc = ""; for (var i = 0; i < refs.Length; ++i) { var r = Util.ParseString <string>(refs[i], false, ':'); def += "\r\nclass Packets::" + r[0] + "::" + r[1] + ";"; inc += inc.Contains(GetFileName(0, r[0]) + ".h") ? "" : "\r\n#include \"" + GetFileName(0, r[0]) + ".h\""; } if (!string.IsNullOrEmpty(def)) { def += "\r\n"; } code[0] = string.Format(code[0], def); code[1] = string.Format(code[1], inc); }
public List <Record> GenerateRecords(int numberOfRecords) { #region Generator's Parameters Initialization _uniqueIpList = _kernel.Get <UniqueIpListGenerator>(); _uniqueIpListGeneratorParameters = new UniqueIpListGeneratorParameters { NumberOfUniqueIp = NumberOfUniqueIp }; UniqueIpList = _uniqueIpList.Generate(_uniqueIpListGeneratorParameters).UniqueIpList; _ipGeneratorParameters = new IpGeneratorParameters { UniqueIpList = UniqueIpList }; _queryTimeGeneratorParameters = new QueryTimeGeneratorParameters { MinInterval = MinIntervalInMilliseconds, MaxInterval = MaxIntervalInMilliseconds, StartTime = DateTime.Now }; _queryMethodGeneratorParameters = new QueryMethodGeneratorParameters { Values = Methods, ValuesWithWeights = Settings }; _fileNameGeneratorParameters = new FileNameGeneratorParameters { MinNumberOfCharacters = MinNumberOfCharacters, MaxNumberOfCharacters = MaxNumberOfCharacters, MinNumberOfFolders = MinNumberOfFolders, MaxNumberOfFolders = MaxNumberOfFolders }; _extensionGeneratorParameters = new ExtensionGeneratorParameters { Values = Extensions, ValuesWithWeights = Settings }; _protocolGeneratorParameters = new ProtocolGeneratorParameters { Values = Protocols }; _serverResponseCodeGeneratorParameters = new ServerResponseCodeGeneratorParameters { Values = ServerResponseCodes, ValuesWithWeights = Settings }; _sizeOfResponseGeneratorParameters = new SizeOfResponseGeneratorParameters { MinSize = MinSizeOfResponse, MaxSize = MaxSizeOfResponse }; #endregion #region Creation of generators _ip = _kernel.Get <IpGenerator>(); _queryTime = _kernel.Get <QueryTimeGenerator>(); _queryMethod = _kernel.Get <QueryMethodGenerator>(); _fileName = _kernel.Get <FileNameGenerator>(); _extension = _kernel.Get <ExtensionGenerator>(); _protocol = _kernel.Get <ProtocolGenerator>(); _serverResponseCode = _kernel.Get <ServerResponseCodeGenerator>(); _sizeOfTheResponse = _kernel.Get <SizeOfResponseGenerator>(); #endregion var listOfRecords = new List <Record>(); for (var i = 0; i < numberOfRecords; i++) { listOfRecords.Add(GenerateRecord()); } return(listOfRecords); }
public List<Record> GenerateRecords(int numberOfRecords) { #region Generator's Parameters Initialization _uniqueIpList = _kernel.Get<UniqueIpListGenerator>(); _uniqueIpListGeneratorParameters = new UniqueIpListGeneratorParameters { NumberOfUniqueIp = NumberOfUniqueIp }; UniqueIpList = _uniqueIpList.Generate(_uniqueIpListGeneratorParameters).UniqueIpList; _ipGeneratorParameters = new IpGeneratorParameters { UniqueIpList = UniqueIpList }; _queryTimeGeneratorParameters = new QueryTimeGeneratorParameters { MinInterval = MinIntervalInMilliseconds, MaxInterval = MaxIntervalInMilliseconds, StartTime = DateTime.Now }; _queryMethodGeneratorParameters = new QueryMethodGeneratorParameters { Values = Methods, ValuesWithWeights = Settings }; _fileNameGeneratorParameters = new FileNameGeneratorParameters { MinNumberOfCharacters = MinNumberOfCharacters, MaxNumberOfCharacters = MaxNumberOfCharacters, MinNumberOfFolders = MinNumberOfFolders, MaxNumberOfFolders = MaxNumberOfFolders }; _extensionGeneratorParameters = new ExtensionGeneratorParameters { Values = Extensions, ValuesWithWeights = Settings }; _protocolGeneratorParameters = new ProtocolGeneratorParameters { Values = Protocols }; _serverResponseCodeGeneratorParameters = new ServerResponseCodeGeneratorParameters { Values = ServerResponseCodes, ValuesWithWeights = Settings }; _sizeOfResponseGeneratorParameters = new SizeOfResponseGeneratorParameters { MinSize = MinSizeOfResponse, MaxSize = MaxSizeOfResponse }; #endregion #region Creation of generators _ip = _kernel.Get<IpGenerator>(); _queryTime = _kernel.Get<QueryTimeGenerator>(); _queryMethod = _kernel.Get< QueryMethodGenerator>(); _fileName = _kernel.Get<FileNameGenerator>(); _extension = _kernel.Get<ExtensionGenerator>(); _protocol = _kernel.Get<ProtocolGenerator>(); _serverResponseCode = _kernel.Get<ServerResponseCodeGenerator>(); _sizeOfTheResponse = _kernel.Get<SizeOfResponseGenerator>(); #endregion var listOfRecords = new List<Record>(); for (var i = 0; i < numberOfRecords; i++) listOfRecords.Add(GenerateRecord()); return listOfRecords; }
public void OnComplete(string[] code, PacketDef[] gps, ProtocolGenerator g) { }
public string[] Generate(PacketDef pkt, ProtocolGenerator g) { var code = ParseComment(pkt.comment).Replace("{", "{{").Replace("}", "}}");; var pn = ParsePacketName(pkt.name); var sp = pn.StartsWith("Sc"); var cpp = sp ? "" : string.Format("void WorldSession::Handle{0}({1} &packet)\r\n{{{{\r\n}}}}\r\n", pn.Replace("Cs", ""), pn); var refs = ""; code += string.Format(" class {0} final : public {1}\r\n {{{{\r\n", pn, sp ? "ServerPacket" : "ClientPacket"); string rc = "", wc = "", dc = ""; var fs = pkt.fields; var nl = pkt.fl[0]; var i = 0; var ct = -1; var custom = false; foreach (var f in fs) { var fieldType = f.custom ? f.array ? "std::vector<" + ParsePacketName(f.typeName, pkt.groupName, f.groupName) + "*>" : ParsePacketName(f.typeName, pkt.groupName, f.groupName) + "*" : ParseType(f.type); if (fieldType.Length > nl) { nl = fieldType.Length; } if (f.custom && f.groupName != pkt.groupName) { var mk = f.groupName + ":" + ParsePacketName(f.typeName); if (!refs.Contains(mk)) { refs += mk + "\r\n"; } } if (!custom && f.custom) { custom = true; } } foreach (var f in fs) { if (i == 0) { code += " public:\r\n"; } var fieldType = f.custom ? f.array ? "std::vector<" + ParsePacketName(f.typeName, pkt.groupName, f.groupName) + "*>" : ParsePacketName(f.typeName, pkt.groupName, f.groupName) + "*" : ParseType(f.type); code += string.Format(" {0,-" + (nl + 4) + "} {1, -" + (pkt.fl[1] + 4) + "}{2}\r\n", fieldType, f.name + ";", string.IsNullOrEmpty(f.comment) ? "" : "// " + f.comment); var t = f.custom ? 1 : 0; if (t == 1 && ct == 0 || ct < 0) { rc += string.Format("{0}{1} ", i == 0 ? " " : ";\r\n ", "w"); wc += string.Format("{0}{1} ", i == 0 ? " " : ";\r\n ", "w"); } ct = t; rc += string.Format(">> {0}{1}{2}", f.custom && !f.array ? "&" : "", f.name, i == fs.Length - 1 ? ";\r\n" : " "); wc += string.Format("<< {0}{1}", f.name, i == fs.Length - 1 ? ";\r\n" : " "); if (f.custom || f.array) { dc += string.Format(" {0}({1});\r\n", f.custom ? f.array ? "VECTOR_DELETE" : "SAFE_DELETE" : "VECTOR_CLEAR", f.name); } ++i; } code += string.Format("{0} public:\r\n {1}() : {2}({3}) {{{{ }}}}\r\n", fs.Length > 0 ? "\r\n" : "", pn, sp ? "ServerPacket" : "ClientPacket", pkt.id); code += string.Format(" {0}{1}\r\n", string.IsNullOrEmpty(dc) ? "" : "~" + pn + "()", string.IsNullOrEmpty(dc) ? "" : custom ? ";\r\n" : "\r\n {{\r\n" + dc.Replace(" ", " ") + " }}\r\n"); code += " void Read(WorldPacket &w) override" + (string.IsNullOrEmpty(rc) ? " {{ }}\r\n\r\n" : "\r\n {{\r\n" + rc + " }}\r\n\r\n"); code += " void Write(WorldPacket &w) const override" + (string.IsNullOrEmpty(wc) ? " {{ }}\r\n" : "\r\n {{\r\n" + wc + " }}\r\n"); des += !custom || string.IsNullOrEmpty(dc) ? "" : pn + "::~" + pn + "()\r\n{\r\n" + dc + "}\r\n\r\n"; code += " }};\r\n"; return(new string[] { code, cpp, refs }); }
static void Main(string[] args) { ProtocolGenerator.Generate(); }