Program.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Linq;
  9. using Newtonsoft.Json.Serialization;
  10. using ServerLib;
  11. // using HttpServer;
  12. using SLua;
  13. namespace GameLogic
  14. {
  15. class Program
  16. {
  17. private static BattleServer server;
  18. private static LaunchConfig launchConfig;
  19. static void Main(string[] args)
  20. {
  21. string configPath = new DirectoryInfo(Directory.GetCurrentDirectory() + "/Config.json").FullName;
  22. if (File.Exists(configPath))
  23. {
  24. string json = File.ReadAllText(configPath);
  25. launchConfig = JsonConvert.DeserializeObject<LaunchConfig>(json);
  26. }
  27. else
  28. {
  29. Console.WriteLine("找不到配置文件:" + configPath);
  30. return;
  31. }
  32. //
  33. // launchConfig.luaRoot = new DirectoryInfo(Directory.GetCurrentDirectory()).FullName +
  34. // launchConfig.luaRoot;
  35. Console.WriteLine("luaRootPath->" + new DirectoryInfo(launchConfig.luaRoot).FullName);
  36. LuaState.loaderDelegate = LoadFile;
  37. // LuaState.errorDelegate = (msg) => { Console.WriteLine("error:" + msg); };
  38. // LuaState.logDelegate = (msg) => { Console.WriteLine("log:" + msg); };
  39. server = new BattleServer(launchConfig.ip, launchConfig.port);
  40. // server.SetRoot(file_Path);
  41. server.Logger = new ConsoleLogger();
  42. LuaSvr svr = new LuaSvr();
  43. svr.init((process) => { }, () =>
  44. {
  45. svr.luaState.doFile("battle/server.lua");
  46. // svr.luaState.getFunction("serverPreloadAllConfig").call();
  47. //启动监听
  48. server.Start();
  49. }, LuaSvrFlag.LSF_BASIC);
  50. }
  51. private const string LUA_SUBFIX = ".lua";
  52. private static byte[] LoadFile(string fn)
  53. {
  54. if (!fn.EndsWith(LUA_SUBFIX))
  55. {
  56. fn = fn + LUA_SUBFIX;
  57. }
  58. // server.Logger.Log("加载:" + server.GetRoot() + fn);
  59. return File.ReadAllBytes(launchConfig.luaRoot + fn);
  60. }
  61. }
  62. }