void client_OnPacket(object sender, InterPacketReceivedEventArgs e) { try { MethodInfo method = InterHandlerStore.GetHandler(e.Packet.OpCode); if (method != null) { Action action = InterHandlerStore.GetCallback(method, this, e.Packet); if (Worker.Instance == null) { action(); } else { Worker.Instance.AddCallback(action); } } else { Log.WriteLine(LogLevel.Debug, "Unhandled packet: {0}", e.Packet); } } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, ex.ToString()); } }
void WorldConnection_OnPacket(object sender, InterPacketReceivedEventArgs e) { if (e.Client.Assigned == false) { if (Program.Zones.Count >= 3) { Log.WriteLine(LogLevel.Warn, "We can't load more than 3 zones atm."); e.Client.Disconnect(); return; } if (e.Packet.OpCode == InterHeader.AUTH) { string pass; if (!e.Packet.TryReadString(out pass)) { e.Client.Disconnect(); return; } if (!pass.Equals(Settings.Instance.InterPassword)) { e.Client.Disconnect(); return; } else { try { e.Client.Assigned = true; ID = Program.GetFreeZoneID(); this.Port = (ushort)(Settings.Instance.ZoneBasePort + ID); var l = DataProvider.Instance.GetMapsForZone(ID); Maps = new List <MapInfo>(); foreach (var mapid in l) { MapInfo map; if (DataProvider.Instance.Maps.TryGetValue(mapid, out map)) { Maps.Add(map); } else { Log.WriteLine(LogLevel.Warn, "Zone is loading map {0} which could not be found.", mapid); } } if (Program.Zones.TryAdd(ID, this)) { IsAZone = true; SendData(); Log.WriteLine(LogLevel.Info, "Added zone {0} with {1} maps.", ID, Maps.Count); } else { Log.WriteLine(LogLevel.Error, "Failed to add zone. Terminating connection."); Disconnect(); } } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, ex.ToString()); Disconnect(); } } } else { Log.WriteLine(LogLevel.Info, "Not authenticated and no auth packet first."); e.Client.Disconnect(); return; } } else { MethodInfo method = InterHandlerStore.GetHandler(e.Packet.OpCode); if (method != null) { Action action = InterHandlerStore.GetCallback(method, this, e.Packet); if (Worker.Instance == null) { action(); } else { Worker.Instance.AddCallback(action); } } else { Log.WriteLine(LogLevel.Debug, "Unhandled interpacket: {0}", e.Packet); } } }