public static void Start() { try { Game.Scene.ModelScene = ETModel.Game.Scene; // 注册热更层回调 ETModel.Game.Hotfix.Update = () => { Update(); }; ETModel.Game.Hotfix.LateUpdate = () => { LateUpdate(); }; ETModel.Game.Hotfix.OnApplicationQuit = () => { OnApplicationQuit(); }; // 注册热更层消息回调 ClientDispatcher clientDispatcher = new ClientDispatcher { HotfixCallback = (s, p) => { HotfixMessageDispatcher.Run(s, p); } }; ETModel.Game.Scene.GetComponent <NetOuterComponent>().MessageDispatcher = clientDispatcher; Game.Scene.AddComponent <UIComponent>(); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatherComponent>(); // 加载热更配置 ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); Game.EventSystem.Run(EventIdType.InitSceneStart); } catch (Exception e) { Log.Error(e.ToStr()); } }
public static void Start() { try { Hotfix.Scene.ModelScene = Game.Scene; // 注册热更层回调 Model.Init.Instance.HotfixUpdate = () => { Update(); }; Model.Init.Instance.HotfixLateUpdate = () => { LateUpdate(); }; Model.Init.Instance.HotfixOnApplicationQuit = () => { OnApplicationQuit(); }; // 注册热更层消息回调 ClientDispatcher clientDispatcher = new ClientDispatcher { HotfixCallback = (s, p) => { HotfixMessageDispatcher.Run(s, p); } }; Game.Scene.GetComponent <NetOuterComponent>().MessageDispatcher = clientDispatcher; Hotfix.Scene.AddComponent <UIComponent>(); Hotfix.Scene.AddComponent <OpcodeTypeComponent>(); Hotfix.Scene.AddComponent <MessageDispatherComponent>(); Hotfix.EventSystem.Run(EventIdType.InitSceneStart); } catch (Exception e) { Log.Error(e.ToStr()); } }
/// <summary> /// 启动连接 /// </summary> /// <returns></returns> public static bool Start() { try { ClientDispatcher.SetLoger(new ServerLinkLoger()); //拷贝配置文件 DictClientLink.Clear(); foreach (var conf in Conf.SysServerList.Values) { //if (conf.ServerType == (int)EServerType.世界)//|| conf.ServerType == (int)EServerType.数据中心) //{ // var client = new ClientLink(); // client.Setup(ConstsBase.Ip本机, conf.Id, conf.ServerType); // DictClientLink.Add(client.LinkId, client); //} } AutoCheckLink(); } catch { return(false); } return(true); }
// 心跳循环内容 public static void HeartbeatExecute() { foreach (var session in BaseServerInfo.AllSessions.Values) { if (session != null && session.Connected) { while (session.ListReq.TryDequeue(out var msg)) { Dispatcher.ProcessMessage(session, msg); } } } foreach (var item in GateServerLinkManager.DictServerLinkLogin.Values) { //if(item!=null &&item.) while (item.ListReq.TryDequeue(out var msg)) { ClientDispatcher.ProcessMessage(msg); } } foreach (var item in GateServerLinkManager.DictServerLinkGame.Values) { //if(item!=null &&item.) while (item.ListReq.TryDequeue(out var msg)) { ClientDispatcher.ProcessMessage(msg); } } }
/// <summary> /// 启动连接 /// </summary> /// <returns></returns> public static bool Start() { try { ClientDispatcher.SetLoger(new ServerLinkLoger()); DictServerLinkGame.Clear(); DictServerLinkLogin.Clear(); foreach (var conf in Conf.SysServerList.Values) { if (conf.ServerType == (int)EServerType.游戏) { var client = new ClientLink(); client.Setup(ConstsBase.Ip本机, conf.Id, conf.ServerType, conf.Desc); DictServerLinkGame.Add(client.LinkId, client); } else if (conf.ServerType == (int)EServerType.登陆) { var client = new ClientLink(); client.Setup(ConstsBase.Ip本机, conf.Id, conf.ServerType, conf.Desc); DictServerLinkLogin.Add(client.LinkId, client); } } AutoCheckLink(); } catch { return(false); } return(true); }
/// <summary> /// 消息注册器 /// </summary> public static void RegisterEventHandler() { ClientDispatcher.EventHandler = GateEventHandler; ClientDispatcher.BindEventHandler(GateServerLinkManager.OnServerConnect, EProtocolId.S2C_SERVER_CONNECT); ClientDispatcher.BindEventHandler(GateServerLinkManager.OnLogin, EProtocolId.L2E_GAME_LOGINSERVER); ClientDispatcher.BindEventHandler(GateServerLinkManager.OnRegister, EProtocolId.L2E_GAME_REGISTER); ClientDispatcher.BindEventHandler(GateServerLinkManager.OnPlayerLoginOut, EProtocolId.G2E_GAME_LOGINOUT); }
internal GameClient(int id, ClientData data, ClientDispatcher dispatcher) { Id = id; Data = data; Dispatcher = dispatcher; StartState(new StateReadyClient(this)); }
private void FormMain_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; comboBox1.SelectedIndex = 0; ClientDispatcher.SetLoger(this); ClientDispatcher.BindEventHandler(OnLoginUserLogin, EProtocolId.L2E_GAME_LOGINSERVER); ClientDispatcher.BindEventHandler(OnLoginUserRegister, EProtocolId.L2E_GAME_REGISTER); ClientDispatcher.BindEventHandler(OnPlayerXY, EProtocolId.G2E_GAME_PLAYERXY); ClientDispatcher.BindEventHandler(OnPlayerXYOther, EProtocolId.G2E_GAME_PLAYERXYOTHER); ClientDispatcher.BindEventHandler(OnPlayerLoginOut, EProtocolId.G2E_GAME_LOGINOUT); ClientDispatcher.BindEventHandler(OnPlayerMapInOther, EProtocolId.G2E_GAME_MAPINOTHER); ClientDispatcher.BindEventHandler(OnPlayerMapIn, EProtocolId.G2E_GAME_MAPIN); tabControl1.SelectedIndex = 0; }
private void timer1_Tick_1(object sender, EventArgs e) { if (ClientNetSingle.LinkState) { if (ClientNetSingle.ListReq.Count > maxnum) { maxnum = ClientNetSingle.ListReq.Count; Debug($"{uidButton.Count}:{maxnum}"); } while (ClientNetSingle.ListReq.TryDequeue(out var msg)) { ClientDispatcher.ProcessMessage(msg); } //if (pCursorOffset.X == 0 && pCursorOffset.Y == 0) //{ // return; //} //var Req = new E2G_Game_PlayerXY() //{ // PlayerXY = new CLS_PlayerXY() { Top = BtnPlayer.Top, Left = BtnPlayer.Left } //}; //ClientNetSingle.Send(Req); } }
/// <summary> /// Interpret the specified msg. /// </summary> /// <param name="msg">Message.</param> public static void Interpret(ServerMessage msg) { try { Console.WriteLine($@"[{DateTime.Now}] Message received from {msg.GUID}: {msg.Name}"); foreach (var asmFile in Directory.GetFiles(Environment.CurrentDirectory)) { if (asmFile.EndsWith(".exe") || asmFile.EndsWith(".dll")) { try { var asm = Assembly.LoadFile(asmFile); foreach (var type in asm.GetTypes()) { foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { foreach (var attrib in method.GetCustomAttributes(false)) { if (attrib is MudRequestAttribute) { var mAttrib = attrib as MudRequestAttribute; if (mAttrib.RequestName == msg.Name) { new Thread(() => { try { object contents = null; if (mAttrib.ExpectedType == typeof(int)) { int result = 0; if (int.TryParse(msg.Contents, out result) == true) { contents = result; } else { throw new MudException($"Protocol error: {msg.Name} expects a 32-bit signed integer for the message contents."); } } else if (mAttrib.ExpectedType == typeof(long)) { long result = 0; if (long.TryParse(msg.Contents, out result) == true) { contents = result; } else { throw new MudException($"Protocol error: {msg.Name} expects a 64-bit signed integer for the message contents."); } } else if (mAttrib.ExpectedType == typeof(bool)) { if (msg.Contents.ToLower() == "true") { contents = true; } else if (msg.Contents.ToLower() == "false") { contents = false; } else { contents = null; throw new MudException("Protocol error: " + msg.Name + " expects a content type of 'boolean'. Please send either 'true' or 'false'."); } } else if (mAttrib.ExpectedType == null) { } else if (mAttrib.ExpectedType == typeof(string)) { contents = msg.Contents; } else { //object type object result = null; try { result = JsonConvert.DeserializeObject(msg.Contents, mAttrib.ExpectedType); } catch (Exception ex) { Console.WriteLine(ex); result = null; } if (result == null) { throw new MudException($"Protocol error: {msg.Name} expects an object of type {mAttrib.ExpectedType.FullName}. Please send a JSON string representing an object of this type."); } contents = result; } method?.Invoke(null, new[] { msg.GUID, contents }); } catch (Exception mEx) { Console.WriteLine(mEx); ClientDispatcher.DispatchTo("Error", msg.GUID, mEx); } return; }).Start(); return; } } } } } } catch (Exception ex) { //Console.WriteLine($"[{DateTime.Now}] Exception while handling request {msg.Name}: {ex}"); //return; } } } ClientDispatcher.DispatchTo("Error", msg.GUID, new MudRequestHandlerNotFoundException()); } catch (Exception ex) { Console.WriteLine("An error occurred with that one."); Console.WriteLine(ex); ClientDispatcher.DispatchTo("Error", msg.GUID, ex); } }