using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; using ServerLib; // using HttpServer; using SLua; namespace GameLogic { class Program { private static BattleServer server; private static LaunchConfig launchConfig; static void Main(string[] args) { string configPath = new DirectoryInfo(Directory.GetCurrentDirectory() + "/Config.json").FullName; if (File.Exists(configPath)) { string json = File.ReadAllText(configPath); launchConfig = JsonConvert.DeserializeObject(json); } else { Console.WriteLine("找不到配置文件:" + configPath); return; } // // launchConfig.luaRoot = new DirectoryInfo(Directory.GetCurrentDirectory()).FullName + // launchConfig.luaRoot; Console.WriteLine("luaRootPath->" + new DirectoryInfo(launchConfig.luaRoot).FullName); LuaState.loaderDelegate = LoadFile; // LuaState.errorDelegate = (msg) => { Console.WriteLine("error:" + msg); }; // LuaState.logDelegate = (msg) => { Console.WriteLine("log:" + msg); }; server = new BattleServer(launchConfig.ip, launchConfig.port); // server.SetRoot(file_Path); server.Logger = new ConsoleLogger(); LuaSvr svr = new LuaSvr(); svr.init((process) => { }, () => { svr.luaState.doFile("battle/server.lua"); // svr.luaState.getFunction("serverPreloadAllConfig").call(); //启动监听 server.Start(); }, LuaSvrFlag.LSF_BASIC); } private const string LUA_SUBFIX = ".lua"; private static byte[] LoadFile(string fn) { if (!fn.EndsWith(LUA_SUBFIX)) { fn = fn + LUA_SUBFIX; } // server.Logger.Log("加载:" + server.GetRoot() + fn); return File.ReadAllBytes(launchConfig.luaRoot + fn); } } }