public SPAWNTIMER(SPAWNINFO si, DateTime dt) { SpawnLoc = si.SpawnLoc; ZoneSpawnLoc = si.ZoneSpawnLoc; zone = ""; X = si.X; Y = si.Y; Z = si.Z; SpawnTimeDT = dt; SpawnTimeStr = dt.ToLongTimeString() + " " + dt.ToShortDateString(); SpawnCount = 1; LastSpawnName = si.Name; AllNames = RegexHelper.TrimName(si.Name); }
public SPAWNTIMER(SPAWNINFO si, DateTime dt) { this.SpawnLoc = si.SpawnLoc; this.ZoneSpawnLoc = si.ZoneSpawnLoc; this.zone = ""; this.X = si.X; this.Y = si.Y; this.Z = si.Z; this.SpawnTimeDT = dt; this.SpawnTimeStr = dt.ToLongTimeString() + " " + dt.ToShortDateString(); this.SpawnCount = 1; this.LastSpawnName = si.Name; this.AllNames = Regex.Replace(si.Name.Replace("_", " "), "[0-9]", "").Trim(); }
// We're pretty positive that the mob has been processed before, here. // This updates KillTime and NextSpawn. public void Kill(SPAWNINFO mob) { try { if ((Settings.Instance.SaveSpawnLogs) || (mapName.Length > 0)) { LogSpawns(String.Format("[KILL] Loc: {0} Name: {1}", mob.SpawnLoc, mob.Name)); } if (mobsTimer.ContainsKey(mob.ZoneSpawnLoc)) { SPAWNTIMER stold = (SPAWNTIMER)mobsTimer[mob.ZoneSpawnLoc]; string log = stold.Kill(DateTime.Now); // update mobsTimer2 also with kill info if (mobsTimer2.ContainsKey(stold.ZoneSpawnLoc)) { SPAWNTIMER st2 = (SPAWNTIMER)mobsTimer2[stold.ZoneSpawnLoc]; st2.KillTimeDT = stold.KillTimeDT; st2.KillTimeStr = stold.KillTimeStr; st2.NextSpawnDT = stold.NextSpawnDT; st2.NextSpawnStr = stold.NextSpawnStr; } if (log != string.Empty && Settings.Instance.MaxLogLevel > 0) { SpawnTimerLog(String.Format("Updating Kill Time for Spawn: {0} Name: {1} Killed: {2}", mob.SpawnLoc, mob.Name, log)); } } } catch (Exception ex) { LogLib.WriteLine("Error updating the SPAWNTIMER for " + mob.Name + ": ", ex); } MustSave = true; }
private void ProcessPacket(byte[] packet, int bytes) { int offset = 0; const int SIZE_OF_PACKET = 100; //104 on new server try { if (bytes > 0) { // we have received some bytes, check if this is the beginning of a new packet or a chunk of an existing one. if (numPackets == 0) { // The first word in the data stream is the number of packets numPackets = BitConverter.ToInt32(packet, 0); offset = 4; f1.StartNewPackets(); } else { // We havent finished processing packets, so check if we have any extra bytes stored in our incomplete buffer. offset = -incompleteCount; } eq.BeginProcessPacket(); for (; (offset + SIZE_OF_PACKET) <= bytes; offset += SIZE_OF_PACKET) { SPAWNINFO si = new SPAWNINFO(); if (offset < 0) { // copy the missing chunk of the incomplete packet to the incomplete packet buffer try { if (incompleteCount > 0 && packet.Length > 0) { Array.Copy(packet, 0, incompletebuffer, incompleteCount, SIZE_OF_PACKET - incompleteCount); } } catch (Exception ex) { LogLib.WriteLine("Error in ProcessPacket() Copy Incomplete packet buffer: ", ex); } incompleteCount = 0; if (incompletebuffer.Length == 0) { numPackets = 0; break; } si.frombytes(incompletebuffer, 0); } else { si.frombytes(packet, offset); } numProcessed++; f1.ProcessPacket(si, update_hidden); } f1.ProcessSpawnList(); f1.ProcessGroundItemList(); } } catch (Exception ex) { LogLib.WriteLine("Error in ProcessPacket(): ", ex); } if (numProcessed < numPackets) { if (offset < bytes) { // Copy unprocessed bytes into the incomplete buffer incompleteCount = bytes - offset; try { Array.Copy(packet, offset, incompletebuffer, 0, incompleteCount); } catch (Exception ex) { LogLib.WriteLine("Error in ProcessPacket(): Copy to Incomplete Buffer: ", ex); LogLib.WriteLine($"Packet Size: {packet.Length} Offset: {offset}"); LogLib.WriteLine($"Buffer Size: {incompletebuffer.Length} Incomplete Size: {incompleteCount}"); } } } else { // Finished proceessing the request RequestPending = false; if (update_hidden) { update_hidden = false; } numPackets = numProcessed = 0; incompleteCount = 0; // Make sure that the incomplete buffer is actually empty if (incompletebuffer.Length > 0) { for (int pp = 0; pp < incompletebuffer.Length; pp++) { incompletebuffer[pp] = 0; } } f1.checkMobs(); f1.mapCon.Invalidate(); } }
// Add a new spawn, or do a re-spawn public void Spawn(SPAWNINFO si) { try { // ignore players boats boxes corpses and invis man races of level 1 if (si.IsPlayer() || (si.Race == 141) || (si.Race == 533) || (si.Race == 376) || (si.Type == 2 || si.Type == 3)) { return; } // ignore ldon objects, mounts, pets, mercs, and familiars if (si.isLDONObject || si.isEventController || si.isPet || si.isMerc || si.isFamiliar || si.isMount) { return; } // ignore any mobs where name starts with "_" if (si.Name.IndexOf("_") == 0) { return; } // If made it this far, then it is a mob that can perform alerts for proximity checks. si.alertMob = true; si.SpawnLoc = String.Format("{0:f3},{1:f3}", si.Y, si.X); si.ZoneSpawnLoc = String.Format("{0}{1:f3},{2:f3}", mapName.ToLower(), si.Y, si.X); if (!mobsTimer.ContainsKey(si.ZoneSpawnLoc)) { // First spawn ever SPAWNTIMER st = new SPAWNTIMER(si, DateTime.Now); st.zone = mapName; try { mobsTimer.Add(si.ZoneSpawnLoc, st); if (Settings.Instance.MaxLogLevel > 0) { SpawnTimerLog(String.Format("Added Spawn: {0} Name: {1}", si.SpawnLoc, si.Name)); } } catch (Exception ex) { LogLib.WriteLine("Error adding new SPAWNTIMER for " + si.Name + ": ", ex); } } else { // Process a true re-spawn LogSpawns(String.Format("[SPAWN] Loc: {0} Name: {1}", si.SpawnLoc, si.Name)); SPAWNTIMER st = (SPAWNTIMER)mobsTimer[si.ZoneSpawnLoc]; SPAWNTIMER st2 = null; if (mobsTimer2.ContainsKey(si.ZoneSpawnLoc)) { st2 = (SPAWNTIMER)mobsTimer2[si.ZoneSpawnLoc]; } int last_time = st.SpawnTimer; string log = ""; if (st2 != null) { log = st2.ReSpawn(si.Name); // since we updated from st2, update st values st.LastSpawnName = st2.LastSpawnName; st.SpawnCount = st2.SpawnCount; st.SpawnTimer = st2.SpawnTimer; st.NextSpawnDT = st2.NextSpawnDT; st.NextSpawnStr = st2.NextSpawnStr; st.SpawnTimeDT = st2.SpawnTimeDT; st.SpawnTimeStr = st2.SpawnTimeStr; st.allNames = st2.allNames; st.KillTimeDT = st2.KillTimeDT; st.KillTimeStr = st2.KillTimeStr; } else { log = st.ReSpawn(si.Name); } if (Settings.Instance.MaxLogLevel > 0) { SpawnTimerLog(String.Format("Found Spawn: {0} Name: {1}", si.SpawnLoc, si.Name)); if (log != string.Empty) { SpawnTimerLog(log); } } if (st.SpawnCount > 1 && st.SpawnTimer > 10) { // The mob was known to spawn once, and is now re-spawning for the first // time... so copy it to the other hash if (!mobsTimer2.ContainsKey(si.ZoneSpawnLoc)) { mobsTimer2.Add(si.ZoneSpawnLoc, st); } MustSave = true; } } } catch (Exception ex) { LogLib.WriteLine("Error creating new SPAWNTIMER for " + si.Name + ": ", ex); } }