/// <summary> /// Enqueue <see cref="NetworkObject"/> to be sent to the client. /// </summary> public void EnqueueMessage(ObjectOpcode opcode, NetworkObject message) { var packet = new NetworkObject(); packet.AddField(0, NetworkObjectField.CreateIntField((int)opcode)); packet.AddField(1, NetworkObjectField.CreateObjectField(message)); EnqueueMessage(packet); }
/// <summary> /// Broadcast <see cref="NetworkObject"/> to all members. /// </summary> public void BroadcastMessage(ObjectOpcode opcode, NetworkObject message) { foreach (CharacterObject character in members.Values) { Session session = NetworkManager.FindSessionByCharacter(character); session?.EnqueueMessage(opcode, message); } }
public ServerObjectPacket(ObjectOpcode opcode, NetworkObject networkObject, bool encrypt = true) { this.opcode = opcode; this.networkObject = networkObject; if (encrypt) { flags |= PacketFlag.Encrypted; } }
/// <summary> /// Enqueue <see cref="NetworkObject"/> to be sent to the client. /// </summary> public void EnqueueMessage(NetworkObject message) { var packet = new ServerPacket(message); outgoingPackets.Enqueue(packet); ObjectOpcode opcode = (ObjectOpcode)NetworkObjectField.ReadIntField(message.GetField(0)); log.Trace($"Sent object packet {opcode}(0x{opcode:X})."); }
/// <summary> /// Invoke message handler delegate for supplied <see cref="ObjectOpcode"/>. /// </summary> public static void InvokeObjectMessageHandler(NetworkSession session, ObjectOpcode opcode, NetworkObject networkObject) { if (!objectMessageHandlers.TryGetValue(opcode, out ObjectMessageHandler handler)) { log.Warn($"Received unhandled object opcode 0x{opcode:X}!"); return; } handler.Invoke(session, networkObject); }
/// <summary> /// Broadcast <see cref="NetworkObject"/> to all members that satisfy supplied predicate. /// </summary> public void BroadcastMessage(ObjectOpcode opcode, NetworkObject message, Func <CharacterObject, bool> func) { foreach (CharacterObject character in members.Values) { if (!func(character)) { continue; } Session session = NetworkManager.FindSessionByCharacter(character); session?.EnqueueMessage(opcode, message); } }
private void ProcessObjectPacket(byte[] payload) { NetworkObject networkObject = NetworkObject.UnPack(payload); ObjectOpcode opcode = (ObjectOpcode)NetworkObjectField.ReadIntField(networkObject.GetField(0)); log.Trace($"Received object packet {opcode}(0x{opcode:X})."); if (opcode == ObjectOpcode.Authenticate) { PacketManager.InvokeObjectMessageHandler(this, opcode, networkObject); } else { PacketManager.InvokeObjectMessageHandler(this, opcode, networkObject.GetField(1).ReadObject()); } }
/// <summary> /// /// </summary> private void ProcessObjectPacket(byte[] payload) { try { NetworkObject networkObject = NetworkObject.UnPack(payload); ObjectOpcode opcode = (ObjectOpcode)NetworkObjectField.ReadIntField(networkObject.GetField(0)); if (opcode == ObjectOpcode.Authenticate) { PacketManager.InvokeObjectPacketHandler(this, opcode, networkObject); } else { PacketManager.InvokeObjectPacketHandler(this, opcode, networkObject.GetField(1).ReadObject()); } } catch (OutOfMemoryException exception) { log.Fatal(exception); log.Fatal($"Payload Length: {payload.Length}"); throw; } }
public ObjectPacketHandlerAttribute(ObjectOpcode opcode) { Opcode = opcode; }