private static void ReadConfig(string path) { Debuger.Log(); string jsonStr = FileUtils.ReadString(path); List <object> obj = null; try { obj = Json.Deserialize(jsonStr) as List <object>; } catch (Exception e) { Debuger.LogError("文件加载失败:{0}", path); return; } for (int i = 0; i < obj.Count; i++) { var infoJson = obj[i] as Dictionary <string, object>; ServerModuleInfo info = new ServerModuleInfo(); info.id = (int)infoJson["id"]; info.name = (string)infoJson["name"]; info.assembly = (string)infoJson["assembly"]; info.ip = (string)infoJson["ip"]; info.port = (int)infoJson["port"]; info.auto = (bool)infoJson["auto"]; MapServerModuleInfo.Add(info.id, info); } }
public void StartServer(int id) { Debuger.Log(id); ServerModuleInfo info = ServerConfig.GetServerModuleInfo(id); string fullName = ServerConfig.Namespace + "." + info.name + "." + info.name; try { Type type = Type.GetType(fullName + "," + info.assembly); var module = Activator.CreateInstance(type) as ServerModule; if (module != null) { module.Create(info); m_mapModule.Add(module.id, module); module.Start(); } } catch (Exception e) { Debuger.LogError(e.Message); } }
public void StartServer(int id) { Debuger.Log(id); ServerModuleInfo info = ServerConfig.GetServerModuleInfo(id); StartServer(info); }
internal void Create(ServerModuleInfo info) { m_info = info; m_msgHandler = this; LOG_TAG = this.GetType().Name + "[" + info.id + "," + info.port + "]"; this.Log(); }
private static void ReadConfig() { Debuger.Log(); string jsonStr = FileUtils.ReadString(Path); var obj = MiniJSON.Json.Deserialize(jsonStr) as List <object>; for (int i = 0; i < obj.Count; i++) { var infoJson = obj[i] as Dictionary <string, object>; ServerModuleInfo info = new ServerModuleInfo(); info.id = (int)(long)infoJson["id"]; info.name = (string)infoJson["name"]; info.assembly = (string)infoJson["assembly"]; info.port = (int)(long)infoJson["port"]; MapServerModuleInfo.Add(info.id, info); } }
public bool StartServer(ServerModuleInfo info) { string fullName = ServerConfig.Namespace + "." + info.name + "." + info.name; Debuger.Log(fullName); try { Type type = Type.GetType(fullName + "," + info.assembly); var module = Activator.CreateInstance(type) as ServerModule; if (module != null) { module.Create(info); m_mapModule.Add(info.id, module); module.Start(); ServerConfig.SetServerModuleInfo(info); //处理缓存的消息 if (m_mapCacheMessage.ContainsKey(info.id)) { List <MessageObject> list = m_mapCacheMessage[info.id]; for (int i = 0; i < list.Count; i++) { MessageObject msgobj = list[i]; module.HandleMessage(msgobj.msg, msgobj.args); } m_mapCacheMessage.Remove(info.id); } return(true); } } catch (Exception e) { m_mapModule.Remove(info.id); Debuger.LogError("ServerModule[{0}] Create Or Start Error:{1}", info.name, e.Message + "\n" + e.StackTrace); } return(false); }
public static void SetServerModuleInfo(ServerModuleInfo info) { MapServerModuleInfo[info.id] = info; }