Exemple #1
0
		public static void SendAllClients(Packet p) {
			foreach (WorldObject obj in Objects.Account.Values) {
				if ((obj as Account).Netstate != null && (obj as Account).Netstate.Running == true) {
					(obj as Account).Netstate.Send(p);
				}
			}
		}
Exemple #2
0
		public static void Send(Packet p, WorldObject source, ESendTarget target) {
			if (target != ESendTarget.AllClients && target != ESendTarget.ChatMainchat) {
				if (source == null) {
					ServerConsole.ErrorLine("World.Send: WorldObject (source) cant be null on type " + target + "!");
					return;
				}
			}

			Rectangle2D area;
			switch (target) {
				case ESendTarget.Self:
					if (source is Character && (source as Character).Account.Netstate != null) {
						(source as Character).Account.Netstate.Send(p);
					}
					break;
				case ESendTarget.AllClients:
					World.SendAllClients(p);
					break;
				case ESendTarget.AllSameMap:
					// Source must have a map/is moveable
					if (source is WorldObjectUnit) {
						foreach (MapBlock block in (source as WorldObjectUnit).Map.Blocks) {
							foreach (WorldObject obj in block.Values) {
								if (obj is Character) {
									(obj as Character).Account.Netstate.Send(p);
								}
							}
						}
					}
					break;
				case ESendTarget.Area:
				case ESendTarget.AreaWithoutOwnChatrooms:
				case ESendTarget.AreaWithoutChatrooms:
				case ESendTarget.AreaWithoutSelf:
					//if (sd && bl->prev == NULL) //Otherwise source misses the packet
					// TODO: what means that? how exactly do they using ->prev and ->next pointer?
					if ((source is Character) && (target == ESendTarget.Area || target == ESendTarget.AreaWithoutOwnChatrooms)) {
						(source as Character).Account.Netstate.Send(p);
					}

					if (source is Character) {
						area = new Rectangle2D((source as Character).Location.X - Global.AREA_SIZE, (source as Character).Location.Y - Global.AREA_SIZE, (source as Character).Location.X + Global.AREA_SIZE, (source as Character).Location.Y + Global.AREA_SIZE, true);
						(source as Character).Map.ForeachInRange(area, mForeachInRangeCallback, new object[] { source, p, target });
					}
					break;
				case ESendTarget.HearableAreaWithoutChatrooms:
					if (source is Character) {
						area = new Rectangle2D((source as Character).Location.X - (Global.AREA_SIZE - 5), (source as Character).Location.Y - (Global.AREA_SIZE - 5), (source as Character).Location.X + (Global.AREA_SIZE - 5), (source as Character).Location.Y + (Global.AREA_SIZE - 5), true);
						(source as Character).Map.ForeachInRange(area, mForeachInRangeCallback, new object[] { source, p, ESendTarget.AreaWithoutChatrooms });
					}
					break;
			}

		}
Exemple #3
0
		/// <summary>
		/// Simplifies inventory/cart/storage packets by handling the packet section relevant to items
		/// </summary>
		/// <param name="p"></param>
		public void WriteItemData(Packet p, int equip) {
			if (Data.ViewID > 0) {
				p.Write((short)Data.ViewID);
			} else {
				p.Write((short)NameID);
			}
			p.Write((byte)(Data.Type == EItemType.PetEgg ? EItemType.Weapon : Data.Type));
			p.Write((byte)(Identify == true ? 1 : 0));
			if (equip >= 0) {
				// Equippable item 
				p.Write((short)equip);
				p.Write((short)Equip);
				p.Write((byte)Attribute);
				p.Write((byte)Refine);
			} else {
				// Stackable item.
				p.Write((short)Amount);
				if (equip == -2 && Equip == EItemEquipLocation.Ammo) {
					p.Write((ushort)EItemEquipLocation.Ammo);
				} else {
					p.Write((short)0);
				}
			}
		}
Exemple #4
0
		public void WriteItemCardData(Packet p) {
			// Blank data
			if (Cards == null) {
				for (int i = 0; i < Global.MAX_SLOTS; i++) {
					p.Write((short)0);
				}
				return;
			}

			// Pet eggs
			if (Cards[0] == Item.Card0Pet) {
				p.Write((short)0);
				p.Write((short)0);
				p.Write((short)0);
				p.Write((short)Cards[3]); // Pet renamed flag.
				return;
			}

			// Forged/created items
			if (Cards[0] == Item.Card0Create || Cards[0] == Item.Card0Forge) {
				for (int i = 0; i < Global.MAX_SLOTS; i++) {
					p.Write((short)Cards[i]);
				}
				return;
			}

			// Normal items
			for (int i = 0; i < Global.MAX_SLOTS; i++) {
				// Write viewID of cards
				ItemDatabaseData item = (Cards[i] > 0 ? (ItemDatabaseData)World.Database[EDatabaseType.Item, Cards[i]] : null);
				p.Write((ushort)(item != null && item.ViewID != EWeaponType.Fist ? (ushort)item.ViewID : Cards[i]));
			}

		}
Exemple #5
0
		public static void Release(Packet p) {
			if (p != null)
				p.Release();
		}
Exemple #6
0
		public static void Release(ref Packet p) {
			if (p != null)
				p.Release();

			p = null;
		}
Exemple #7
0
		public static Packet Acquire(Packet p) {
			p.Acquire();
			return p;
		}
Exemple #8
0
		public static Packet SetStatic(Packet p) {
			p.SetStatic();
			return p;
		}
Exemple #9
0
		public virtual void Send(Packet p) {
			if (mSocket == null || mBlockAllPackets) {
				ServerConsole.ErrorLine("{0}: Socket is null! Packet {1:X4} ({2} bytes) cant be send", this, p.PacketID, p.Length);
				// Wont send packet, but trigger OnSend to free data..
				p.OnSend(this);
				Dispose();
				return;
			}

			// Allow APIs to break sending
			if (p.OnBeforeSend(this) == false) {
				// Didnt send the packet, so let the APIs know that (2nd param, false)
				p.OnSend(this, false);
				return;
			}
			PacketSendProfile prof = PacketSendProfile.Acquire(p.GetType());

			int length = 0;
			byte[] buffer = p.Compile(out length);
			if (buffer == null) {
				ServerConsole.ErrorLine("{0}: null buffer send, disconnecting...", this);
				using (StreamWriter op = new StreamWriter("null_send.log", true)) {
					op.WriteLine("{0} Client", "{1}: null buffer send, disconnecting...", DateTime.Now, this);
					op.WriteLine(new System.Diagnostics.StackTrace());
				}
				Dispose();
				return;
			}

			if (buffer.Length <= 0 || length <= 0) {
				p.OnSend(this);
				return;
			}

			if (prof != null)
				prof.Start();

			if (mEncoder != null)
				mEncoder.EncodeOutgoingPacket(this, ref buffer, ref length);

			try {
				ServerConsole.DebugLine("{0}: sending Packet 0x{1:X4} ({2} bytes)", this, p.PacketID, length);
				mSocket.BeginSend(buffer, 0, length, SocketFlags.None, mOnSend, mSocket);
			} catch (Exception ex) {
				ExceptionHandler.Trace(ex);
				Dispose(false);
			}

			p.OnSend(this);

			if (prof != null)
				prof.Finish(length);
		}