public static bool SendToReady(NetworkIdentity identity, short msgType, MessageBase msg, int channelId = Channels.DefaultReliable) { if (LogFilter.Debug) { Debug.Log("Server.SendToReady msgType:" + msgType); } if (identity != null && identity.observers != null) { // pack message into byte[] once byte[] bytes = MessagePacker.PackMessage((ushort)msgType, msg); // send to all ready observers bool result = true; foreach (KeyValuePair <int, NetworkConnection> kvp in identity.observers) { if (kvp.Value.isReady) { result &= kvp.Value.SendBytes(bytes, channelId); } } return(result); } return(false); }
public static bool SendToAll(int msgType, MessageBase msg, int channelId = Channels.DefaultReliable) { if (LogFilter.Debug) Debug.Log("Server.SendToAll id:" + msgType); // pack message into byte[] once byte[] bytes = MessagePacker.PackMessage((ushort)msgType, msg); // send to all bool result = true; foreach (KeyValuePair<int, NetworkConnection> kvp in connections) { result &= kvp.Value.SendBytes(bytes, channelId); } return result; }
static bool SendToObservers(NetworkIdentity identity, short msgType, MessageBase msg) { if (LogFilter.Debug) Debug.Log("Server.SendToObservers id:" + msgType); if (identity != null && identity.observers != null) { // pack message into byte[] once byte[] bytes = MessagePacker.PackMessage((ushort)msgType, msg); // send to all observers bool result = true; foreach (KeyValuePair<int, NetworkConnection> kvp in identity.observers) { result &= kvp.Value.SendBytes(bytes); } return result; } return false; }
public bool Send(int msgType, MessageBase msg, int channelId = Channels.DefaultReliable) { // pack message and send byte[] message = MessagePacker.PackMessage(msgType, msg); return(Send(new ArraySegment <byte>(message), channelId)); }
public virtual bool Send(int msgType, MessageBase msg, int channelId = Channels.DefaultReliable) { // pack message and send byte[] message = MessagePacker.PackMessage(msgType, msg); return(SendBytes(message, channelId)); }
public virtual bool Send(int msgType, MessageBase msg, int channelId = Channels.DefaultReliable) { byte[] message = MessagePacker.PackMessage(msgType, msg); return(SendBytes(new ArraySegment <byte>(message), channelId)); }