void FireEvent(string eventName, NetConnection onConnection, RemoteFlag flags, NetDeliveryMethod deliveryMethod, NetBuffer data, ushort numArgs) { // Create the event packet NetOutboundPacket firePacket = new NetOutboundPacket(deliveryMethod); firePacket.Type = NetPacketType.RemoteEvent; // Handle the flags firePacket.Encrypt = flags.HasFlag(RemoteFlag.Encrypt); if (flags.HasFlag(RemoteFlag.DontCompress)) { firePacket.Compression = NetPacketCompression.None; } firePacket.SendImmediately = flags.HasFlag(RemoteFlag.SendImmediately); // Write the event header firePacket.Write((byte)Type); firePacket.Write(Id); firePacket.Write(eventName); firePacket.Write(numArgs); // Write the data for the event firePacket.WriteBytes(data.data, 0, data.Length); // Send the event packet onConnection.SendPacket(firePacket); }
public void FireEventForAllConnections(string eventName, RemoteFlag flags, NetDeliveryMethod deliveryMethod, NetBuffer data) { foreach (NetConnection connection in Messenger.Connections.Values) { FireEvent(eventName, connection, flags, deliveryMethod, data); } }
public void FireEventForAllConnections(string eventName, RemoteFlag flags, NetDeliveryMethod deliveryMethod, params object[] args) { foreach (NetConnection connection in Messenger.Connections.Values) { FireEvent(eventName, connection, flags, deliveryMethod, args); } }
/// <summary> /// Calls a function for a connection. /// </summary> /// <param name="functionName">The name of the function.</param> /// <param name="onConnection">The connection to call the function for.</param> /// <param name="callback">The callback for the return value, sent by the called connection.</param> /// <param name="flags">Flags for the packet settings.</param> /// <param name="deliveryMethod">The way this packet will reach the connection.</param> /// <param name="args">Any data associated with the function to be handled by the other application.</param> public bool CallFunction(string functionName, NetConnection onConnection, RemoteFunctionCallback callback, RemoteFlag flags, NetDeliveryMethod deliveryMethod, params object[] args) { NetBuffer data = new NetBuffer(); // Write the data for the function for (int i = 0; i < args.Length; i++) { data.WriteDynamic(args[i]); } return(CallFunc(functionName, onConnection, callback, flags, deliveryMethod, data, (ushort)args.Length)); }
/// <summary> /// Fires an event for a connection. /// </summary> /// <param name="eventName">The name of the event.</param> /// <param name="onConnection">The connection to fire the event for.</param> /// <param name="flags">Flags for the packet settings.</param> /// <param name="deliveryMethod">The way this packet will reach the connection.</param> /// <param name="args">Any data associated with the event to be handled by the other application.</param> public void FireEvent(string eventName, NetConnection onConnection, RemoteFlag flags, NetDeliveryMethod deliveryMethod, params object[] args) { NetBuffer data = new NetBuffer(); // Write the data for the event for (int i = 0; i < args.Length; i++) { data.WriteDynamic(args[i]); } FireEvent(eventName, onConnection, flags, deliveryMethod, data, (ushort)args.Length); }
bool CallFunc(string functionName, NetConnection onConnection, RemoteFunctionCallback callback, RemoteFlag flags, NetDeliveryMethod deliveryMethod, NetBuffer data, ushort numArgs) { // Allocate Id ushort callbackId = GetNextCallbackId(); // Create the function packet NetOutboundPacket funcPacket = new NetOutboundPacket(deliveryMethod); funcPacket.Type = NetPacketType.RemoteFunction; // Handle the flags funcPacket.Encrypt = flags.HasFlag(RemoteFlag.Encrypt); if (flags.HasFlag(RemoteFlag.DontCompress)) { funcPacket.Compression = NetPacketCompression.None; } funcPacket.SendImmediately = flags.HasFlag(RemoteFlag.SendImmediately); // Write the function header funcPacket.Write((byte)Type); funcPacket.Write(Id); funcPacket.Write(functionName); funcPacket.Write(callbackId); funcPacket.Write(numArgs); // Write the data for the function funcPacket.WriteBytes(data.data, 0, data.Length); // Add the waiting function for the return value callback if (WaitingFunctions.TryAdd(callbackId, callback)) { // Send the event packet onConnection.SendPacket(funcPacket); return(true); } else { NetLogger.LogError("Failed to call function {0}, this function is already in the middle of being called!", functionName); return(false); } }
/// <summary> /// Calls a function for a connection. /// </summary> /// <param name="functionName">The name of the function.</param> /// <param name="onConnection">The connection to call the function for.</param> /// <param name="callback">The callback for the return value, sent by the called connection.</param> /// <param name="flags">Flags for the packet settings.</param> /// <param name="deliveryMethod">The way this packet will reach the connection.</param> /// <param name="args">Any data associated with the function to be handled by the other application.</param> public bool CallFunction(string functionName, NetConnection onConnection, RemoteFunctionCallback callback, RemoteFlag flags, NetDeliveryMethod deliveryMethod, NetBuffer data) { return(CallFunc(functionName, onConnection, callback, flags, deliveryMethod, data, 0)); }
/// <summary> /// Calls a function for a connection. /// </summary> /// <param name="functionName">The name of the function.</param> /// <param name="onConnection">The connection to call the function for.</param> /// <param name="callback">The callback for the return value, sent by the called connection.</param> /// <param name="flags">Flags for the packet settings.</param> /// <param name="args">Any data associated with the function to be handled by the other application.</param> public bool CallFunction(string functionName, NetConnection onConnection, RemoteFunctionCallback callback, RemoteFlag flags, params object[] args) { return(CallFunction(functionName, onConnection, callback, flags, NetDeliveryMethod.Reliable, args)); }
/// <summary> /// Fires an event for a connection. /// </summary> /// <param name="eventName">The name of the event.</param> /// <param name="onConnection">The connection to fire the event for.</param> /// <param name="flags">Flags for the packet settings.</param> /// <param name="deliveryMethod">The way this packet will reach the connection.</param> /// <param name="data">Data to write to the event call.</param> public void FireEvent(string eventName, NetConnection onConnection, RemoteFlag flags, NetDeliveryMethod deliveryMethod, NetBuffer data) { FireEvent(eventName, onConnection, flags, deliveryMethod, data, 0); }
/// <summary> /// Fires an event for a connection. /// </summary> /// <param name="eventName">The name of the event.</param> /// <param name="onConnection">The connection to fire the event for.</param> /// <param name="flags">Flags for the packet settings.</param> /// <param name="args">Any data associated with the event to be handled by the other application.</param> public void FireEvent(string eventName, NetConnection onConnection, RemoteFlag flags, params object[] args) { FireEvent(eventName, onConnection, flags, NetDeliveryMethod.Reliable, args); }
public void FireEventForAllConnections(string eventName, RemoteFlag flags, NetBuffer data) { FireEventForAllConnections(eventName, flags, NetDeliveryMethod.Reliable, data); }
public void FireEventForAllConnections(string eventName, RemoteFlag flags, params object[] args) { FireEventForAllConnections(eventName, flags, NetDeliveryMethod.Reliable, args); }