/// <summary> /// Sends an event to a client. /// </summary> /// <param name="e">Event to send.</param> /// <param name="connectionId">Target client's connection id</param> /// <param name="reliable">Is it reliable event</param> /// <param name="internalResend">If <c>false</c> this event will be added to reliable events queue as a new event</param> /// <returns><c>true</c> if the target client is connected</returns> public bool Send(EventBase e, int connectionId, bool reliable = false, bool internalResend = false) { ByteStreamWriter stream = new ByteStreamWriter(); stream.WriteByte(reliable ? ( byte )MsgFlags.ReliableEvent : ( byte )MsgFlags.UnreliableEvent); stream.WriteByte(e.GetId()); e.Serialize(stream); Connection c = m_server.GetConnectionById(connectionId); if (c != null) { c.Send(stream.GetBytes()); if (reliable && !internalResend && e is ReliableEventBase) { ReliableEventBase reb = e as ReliableEventBase; m_reliablesToRepeat[reb.m_reliableEventId] = new REventIdPair(connectionId, reb); } return(true); } else { return(false); } }
/// <summary> /// Sends an event to a server. /// </summary> /// <param name="e">Event to send.</param> /// <param name="reliable">Is it reliable event</param> /// <param name="internalResend">If <c>false</c> this event will be added to reliable events queue as a new event</param> /// <returns><c>true</c> if the target client is connected</returns> public void Send(EventBase e, bool reliable = false, bool internalResend = false) { ByteStreamWriter stream = new ByteStreamWriter(); stream.WriteByte(reliable ? (byte)MsgFlags.ReliableEvent : (byte)MsgFlags.UnreliableEvent); stream.WriteByte(e.GetId()); e.Serialize(stream); m_client.Send(stream.GetBytes()); if (reliable && !internalResend && e is ReliableEventBase) { ReliableEventBase reb = e as ReliableEventBase; m_reliablesToRepeat[reb.m_reliableEventId] = reb; } }