public static void HandlePacket(WorldClient client, CMSG msgID, BinReader data) { DebugLogger.ILog("Handling CMSG packet: " + msgID); bool handled = false; try { IWorldClientPacketHandler handler = (IWorldClientPacketHandler)worldClientHandlers[msgID]; if (handler != null) { handler.HandlePacket(client, msgID, data); handled = true; } WorldClientPacketDelegate wcpd = (WorldClientPacketDelegate)worldClientDelegates[(int)msgID]; if (wcpd != null) { wcpd(client, msgID, data); handled = true; } } catch (Exception exp) { DebugLogger.Logger.Log("", exp); } if (handled == false) { DebugLogger.ILog("Unhandled CMSG: " + msgID.ToString()); } }
private static void mainThread() { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); try { m_running = true; int shutdownstage = 0; while (true) { if (!processConnection()) { // Todo handle this break; } EventManager.CheckEvents(); if (m_shutdown == true) { if (shutdownstage == 0) { // save and remove everything ArrayList clients = new ArrayList(m_clients.Values); IEnumerator e = clients.GetEnumerator(); while (e.MoveNext()) { WorldClient client = (WorldClient)e.Current; client.LeaveWorld(); } shutdownstage = 1; } if (shutdownstage == 1 && DBManager.CreateRequestsPending() == 0) { Send(new WorldPacket(WORLDMSG.WORLD_SHUTDOWN)); shutdownstage = 2; } if (shutdownstage == 2 && m_connection.PendingSendData == false) { break; } } Thread.Sleep(5); } } catch (ThreadAbortException) { } catch (Exception e) { Console.WriteLine("Unhandled worldserver exception!"); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); DebugLogger.ILog("", e); } ObjectManager.CheckBeforeShutdown(); DBManager.CheckBeforeShutdown(); m_connection.Close("Server shutting down."); m_running = false; }
internal static void RemoveClient(WorldClient client) { try { m_clients.Remove(client.CharacterID); } catch (Exception exp) { DebugLogger.ILog("", exp); } }
public static WorldClient GetClientByCharacterID(uint id) { try { return((WorldClient)m_clients[id]); } catch (Exception exp) { DebugLogger.ILog("", exp); } return(null); }
internal static void AddClient(WorldClient client) { DebugLogger.ILog("Added client: " + client.ToString()); try { m_clients[client.CharacterID] = client; } catch (Exception exp) { DebugLogger.ILog("", exp); } }
public static void Send(WorldPacket pkg) { DebugLogger.ILog("Sending packet " + pkg.ToString()); try { pkg.Set(0, (int)(pkg.BaseStream.Length - 4)); m_connection.Send(pkg.GetBuffer(), pkg.BaseStream.Length); } catch (Exception exp) { DebugLogger.ILog("", exp); } }
public static WorldClient GetClientByName(string name) { try { int numclient = m_clients.Count; System.Collections.IDictionaryEnumerator ienum = m_clients.GetEnumerator(); while (ienum.MoveNext()) { if (((WorldClient)ienum.Value).Player.Name == name) { return((WorldClient)ienum.Value); } } } catch (Exception exp) { DebugLogger.ILog("", exp); } return(null); }
private static void OnLoginServerData(ClientBase client, byte[] data) { try { BinReader read = new BinReader(data); read.BaseStream.Position += 4; // skip len WORLDMSG msgID = (WORLDMSG)read.ReadInt32(); if (msgID != WORLDMSG.DESERIALIZE_OBJ) { Console.WriteLine("OnLoginServerData read {0}", msgID); } if (msgID == WORLDMSG.CLIENT_MESSAGE) { uint charID = read.ReadUInt32(); CMSG cmsg = (CMSG)read.ReadInt32(); WorldClient world_client = GetClientByCharacterID(charID); if (client != null) { WorldPacketManager.HandlePacket(world_client, cmsg, read); } else { Console.WriteLine("Client(" + charID + ") was missing when " + cmsg.ToString() + " was received."); } } else if (msgID == WORLDMSG.SCRIPT_MESSAGE) { int msg = read.ReadInt32(); Console.WriteLine("Read SMSG: " + msg); Scripts.OnScriptMessage(msg, read); } else { WorldPacketManager.HandlePacket(msgID, read); } } catch (Exception exp) { DebugLogger.ILog("", exp); } }
public static void HandlePacket(WORLDMSG msgID, BinReader data) { if (msgID != WORLDMSG.DESERIALIZE_OBJ) { DebugLogger.ILog("Handling WORLDMSG packet: " + msgID); } try { IWorldServerPacketHandler handler = (IWorldServerPacketHandler)worldServerHandlers[msgID]; if (handler != null) { handler.HandlePacket(msgID, data); } WorldServerPacketDelegate wspd = (WorldServerPacketDelegate)worldServerDelegates[(int)msgID]; if (wspd != null) { wspd(msgID, data); } } catch (Exception exp) { DebugLogger.Logger.Log("", exp); } }