public void BroadcastMessage(ITypedMessage typedMessage, ushort from, ushort except = 0xFFFF) { try { if (!typedMessage.GetMessageType().OnlyBroadcasted()) { throw new DnmpException("Message is not broadcastable"); } foreach (var client in realClient.ClientsById.Values.Where(x => x.ParentId == realClient.SelfClient.Id || x.Id == realClient.SelfClient.ParentId)) { if (client.Id == except) { continue; } if (typedMessage.GetMessageType() == MessageType.DataBroadcast) { client.DataBytesSent += typedMessage.GetBytes().Length; } SendReliableMessage(typedMessage, from, 0xFFFF, client.Id, client.EndPoint, MessageFlags.IsRedirected); } } catch (Exception) { if (realClient.CurrentStatus == DnmpClient.ClientStatus.Disconnecting || realClient.CurrentStatus == DnmpClient.ClientStatus.NotConnected) { return; } throw; } }
public void SendReliableMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId, ushort realDestinationId, IEndPoint to, MessageFlags messageFlags = MessageFlags.None) { try { if (!typedMessage.GetMessageType().IsReliable()) { throw new DnmpException("Message is not reliable"); } var id = Guid.NewGuid(); var message = new BaseMessage(typedMessage, sourceId, destinationId, realClient.SelfClient?.Id ?? 0xFFFF, realDestinationId, id, messageFlags); var messageInfo = new BaseMessagePair { Message = message, EndPoint = to }; reliableMessages.TryAdd(id, messageInfo); SendBaseMessage(message, to); EventQueue.AddEvent(ReliableCallback, new KeyValuePair <Guid, BaseMessagePair>(id, messageInfo), DateTime.Now.AddMilliseconds(500), id); } catch (Exception) { if (realClient.CurrentStatus == DnmpClient.ClientStatus.Disconnecting || realClient.CurrentStatus == DnmpClient.ClientStatus.NotConnected) { return; } throw; } }
public BaseMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId, ushort realSourceId, ushort realDestinationId, Guid id = new Guid(), MessageFlags messageFlags = MessageFlags.None) : this(typedMessage.GetBytes(), typedMessage.GetMessageType(), sourceId, destinationId, realSourceId, realDestinationId, id, messageFlags) { }