/// <summary> /// Returns false if the packet should be sent to the loginserver /// </summary> /// <param name="client"></param> /// <param name="msgID"></param> /// <param name="data"></param> /// <returns></returns> public static bool HandlePacket(LoginClient client, CMSG msgID, BinReader data) { if (msgID >= CMSG.MAX) { return(true); } ILoginClientPacketHandler handler = (ILoginClientPacketHandler)loginClientHandlers[msgID]; bool wasHandled = false; try { if (handler != null) { wasHandled = handler.HandlePacket(client, msgID, data); } LoginClientPacketDelegate wcpd = (LoginClientPacketDelegate)loginClientDelegates[(int)msgID]; if (wcpd != null) { foreach (LoginClientPacketDelegate d in wcpd.GetInvocationList()) { if (d(client, msgID, data)) { wasHandled = true; } } } return(wasHandled); } catch (Exception exp) { DebugLogger.Log("", exp); } return(wasHandled); }
void SearchForClientPacketDelegates(Type type) { try { MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static); foreach (MethodInfo method in methods) { LoginPacketDelegate[] attribs = (LoginPacketDelegate[])method.GetCustomAttributes(typeof(LoginPacketDelegate), true); if (attribs.Length == 0) { continue; } if (method.IsStatic) { foreach (LoginPacketDelegate attrib in attribs) { if (attrib.ClientMessage) { LoginClientPacketDelegate wcpd = (LoginClientPacketDelegate)Delegate.CreateDelegate(typeof(LoginClientPacketDelegate), method); LoginPacketManager.RegisterPacketHandler((CMSG)attrib.MsgID, wcpd); if (m_clientPacketDelegates.Contains(attrib.MsgID)) { LoginClientPacketDelegate dele = (LoginClientPacketDelegate)m_clientPacketDelegates[attrib.MsgID]; m_clientPacketDelegates[attrib.MsgID] = dele + wcpd; } else { m_clientPacketDelegates[attrib.MsgID] = wcpd; } } } } else { object obj = GetHandlerObject(type); foreach (LoginPacketDelegate attrib in attribs) { if (attrib.ClientMessage) { LoginClientPacketDelegate wcpd = (LoginClientPacketDelegate)Delegate.CreateDelegate(typeof(LoginClientPacketDelegate), obj, method.Name); LoginPacketManager.RegisterPacketHandler((CMSG)attrib.MsgID, wcpd); if (m_clientPacketDelegates.Contains(attrib.MsgID)) { LoginClientPacketDelegate dele = (LoginClientPacketDelegate)m_clientPacketDelegates[attrib.MsgID]; m_clientPacketDelegates[attrib.MsgID] = dele + wcpd; } else { m_clientPacketDelegates[attrib.MsgID] = wcpd; } } } } } } catch (Exception exp) { DebugLogger.Log("", exp); } }
internal void OnScriptMessage(int msgID, BinReader data) { try { ScriptPacketDelegate handler = (ScriptPacketDelegate)m_scriptPacketHandlers[msgID]; if (handler != null) { handler(msgID, data); } } catch (Exception exp) { DebugLogger.Log("", exp); } }
public static void HandlePacket(WorldConnection connection, WORLDMSG msgID, BinReader data) { try { ILoginServerPacketHandler handler = (ILoginServerPacketHandler)loginServerHandlers[msgID]; if (handler != null) { handler.HandlePacket(connection, msgID, data); } LoginServerPacketDelegate wspd = (LoginServerPacketDelegate)loginServerDelegates[(int)msgID]; if (wspd != null) { wspd(connection, msgID, data); } } catch (Exception exp) { DebugLogger.Log("", exp); } }
public static void SearchAssemblyForHandlers(Assembly assembly) { try { foreach (Type type in assembly.GetTypes()) { if (type.IsClass == false) { continue; } LoginPacketHandler[] attribs = (LoginPacketHandler[])type.GetCustomAttributes(typeof(LoginPacketHandler), true); foreach (LoginPacketHandler attrib in attribs) { if (attrib.UseDelegates) { SearchForDelegates(type); } else { if (attrib.ClientMessage) { if (type.GetInterface(typeof(ILoginClientPacketHandler).ToString()) != null) { object obj = GetHandlerObject(type); RegisterPacketHandler((CMSG)attrib.MsgID, (ILoginClientPacketHandler)obj); } } else { if (type.GetInterface(typeof(ILoginServerPacketHandler).ToString()) != null) { object obj = GetHandlerObject(type); RegisterPacketHandler((WORLDMSG)attrib.MsgID, (ILoginServerPacketHandler)obj); } } } } } } catch (Exception exp) { DebugLogger.Log("", exp); } }
public override void OnClientLoopStop() { try { IEnumerator e = new ArrayList(m_worldServers).GetEnumerator(); while (e.MoveNext()) { WorldConnection connection = (WorldConnection)e.Current; if (!connection.processWorldServerData()) { if (m_shutdown == false) { Console.WriteLine("Lost connection to world server " + connection.ToString()); LoginServer.Shutdown(); } else { m_worldServers.Remove(connection); } DebugLogger.Log("Lost connection to world server " + connection.ToString() + " -- Server will be restarted!"); LoginServer.RestartServer = true; } } if (m_shutdown && m_worldServers.Count == 0) { base.Stop(); } Thread.Sleep(5); } catch (Exception exp) { if (exp.GetType() != typeof(ThreadAbortException)) { DebugLogger.Log("Will restart server!", exp); } LoginServer.RestartServer = true; } }
public override void OnClientLoopException(Exception exp) { DebugLogger.Log("Will restart server!", exp); LoginServer.RestartServer = true; }