internal void Invoke(IEnumerable <Player> players, RPCResult result, string name, params object[] args) { Network.ByteOutStream stream = new Network.ByteOutStream(256); stream.WriteByte(HeaderBytes.RemoteProcedureCall); stream.WriteBool(true); stream.WriteString(name); if (result != null) { stream.WriteInt(result.ReturnIndex); results.Add(result.ReturnIndex, result); result.Name = name; } foreach (object arg in args) { Writer writer; if (!writers.TryGetValue(arg.GetType(), out writer)) { log.Error("No RPC argument writer for type '{0}', can't send RPC '{1}'", arg.GetTypeName(), name); return; } writer(stream, arg.GetType(), arg); } log.Info("Sending {0}", name); foreach (Player player in players) { player.Connection.Queue(stream, true); } }
public void Send(ByteOutStream header) { Assert.NotNull(header, "header"); Context.Peer.NetworkPeer.Send(this, header, reliable, true); Context.Peer.NetworkPeer.Send(this, header, unreliable, false); }
void Network.IStreamWriter.WriteToStream(Player player, Network.ByteOutStream stream) { stream.WriteByte(HeaderBytes.ActorStateStream); stream.WriteUShort(Id); stream.WriteByte(StateStreamer.Size); StateStreamer.Pack(stream); }
void Network.IStreamWriter.WriteToStream(Player player, Network.ByteOutStream stream) { // Write event id stream.WriteByte(EventId); // Write handler header Handler.WriteEventHeader(this, stream); // Write data Pack(stream); }
public void Pack(Network.ByteOutStream stream) { Vector3 p; Quaternion r; byte angle = 0; if (Actor.Context.IsServer) { p = position; r = rotation; if (yawOnly) { angle = (byte)(yaw * 0.71111f); } } else { p = Actor.Transform.Position; r = Actor.Transform.Rotation; if (yawOnly) { angle = (byte)(Vector3.SignedAngle(Vector3.Forward, Actor.Transform.Forward, Vector3.Up) * 0.71111f); } } if (compressPosition) { stream.WriteUShort(HalfUtilities.Pack(p.X)); stream.WriteUShort(HalfUtilities.Pack(p.Y)); stream.WriteUShort(HalfUtilities.Pack(p.Z)); } else { stream.WriteVector3(p); } if (yawOnly) { stream.WriteByte(angle); } else { p = r.Axis; stream.WriteUShort(HalfUtilities.Pack(p.X)); stream.WriteUShort(HalfUtilities.Pack(p.Y)); stream.WriteUShort(HalfUtilities.Pack(p.Z)); stream.WriteByte((byte)(r.Angle * SlimMath.Single.Rad2Deg * 0.71111f)); } }
void writePair(Network.ByteOutStream s, Type t, object v) { object first = t.GetProperty("First").GetValue(v, null); object second = t.GetProperty("Second").GetValue(v, null); Writer firstW; Writer secondW; if (!writers.TryGetTypeValue(first.GetType(), out firstW) || !writers.TryGetTypeValue(second.GetType(), out secondW)) { return; } firstW(s, first.GetType(), first); secondW(s, second.GetType(), second); }
public void Send(IConnection connection, Network.ByteOutStream header, Queue <Network.IStreamWriter> data, bool reliable) { if (data.Count == 0) { return; } int mtu = MTU; int headerSize = header.Size; int messageSize = mtu - headerSize; IStreamWriter writer = null; NetConnection netConnection = ((LidgrenConnection)connection).Connection; ByteOutStream stream = new ByteOutStream(messageSize); NetDeliveryMethod delivery = reliable ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.UnreliableSequenced; while (data.Count > 0) { writer = data.Dequeue(); if (writer == null) { log.Warn("A null value was queued on the outgoing message queue for {0}", connection); continue; } if (stream.Size + writer.Size > messageSize && stream.Size > 0) { sendStream(connection.Player, netConnection, delivery, stream, header, mtu); stream.Reset(); } writer.WriteToStream(connection.Player, stream); } if (stream.Size > 0) { sendStream(connection.Player, netConnection, delivery, stream, header, mtu); } }
public bool Send() { if (NetworkQueue.Count > 0) { Peer.ContextPlugin.BeforeSend(); // Copy dirty connections HashSet <Network.IConnection> connections = new HashSet <Network.IConnection>(NetworkQueue); NetworkQueue.Clear(); // Make sure we have an up-to-date time Time.Update(); // Scheduler.RunExpired(); // Create message header Network.ByteOutStream header = new Network.ByteOutStream(4); header.WriteSingle(Time.GameTime); // Send foreach (Network.IConnection connection in connections) { connection.Send(header); } foreach (Synchronizable sync in SynchronizationQueue) { sync.DirtyIndexes = 0; } SynchronizationQueue.Clear(); Peer.ContextPlugin.AfterSend(); return(true); } return(false); }
internal void PackSyncData(uint indexes, Network.ByteOutStream stream) { if (indexes == 0 || !IsActive) { return; } log.Debug("Sending data for {0}", Actor); stream.WriteByte(HeaderBytes.Synchronizable); stream.WriteActor(Actor); stream.WriteUShort((ushort)DataSize); stream.WriteUInt(indexes); for (int i = 0; i < Values.Length; ++i) { if ((indexes & ((uint)1 << i)) != 0) { Values[i].Pack(stream); } } return; }
public override void Pack(SlimNet.Network.ByteOutStream stream) { stream.WriteString(Message); }
public override void Pack(Network.ByteOutStream stream) { stream.WriteInt((int)(ValueType)Value); }
bool onCall(Network.ByteInStream stream) { string name = stream.ReadString(); Receiver receiver; if (!receivers.TryGetValue(name, out receiver)) { log.Error("No receiver for '{0}' found", name); return(false); } int returnIndex = 0; int length = receiver.Parameters.Length; if (receiver.ReturnsValue) { returnIndex = stream.ReadInt(); } if (receiver.RequiresInfoArgument) { length += 1; } object[] args = new object[length]; for (var i = 0; i < receiver.Parameters.Length; ++i) { Type t = receiver.Parameters[i]; Reader reader; if (!readers.TryGetTypeValue(t, out reader)) { return(false); } args[i] = reader(stream, t); if (args[i] is Player) { if (!ReferenceEquals(args[i], stream.Player)) { log.Error("RPC from {0} tried to use object for {1}", stream.Player, args[i]); return(false); } } } if (receiver.RequiresInfoArgument) { RPCInfo info = new RPCInfo(); info.Caller = stream.Player; info.Context = Context; info.RemoteGameTime = stream.RemoteGameTime; args[args.Length - 1] = info; } log.Info("Received {0}", receiver.Name); if (receiver.ReturnsValue) { object result = receiver.Method.Invoke(receiver.Instance, args); Network.ByteOutStream resultStream = new Network.ByteOutStream(128); resultStream.WriteByte(HeaderBytes.RemoteProcedureCall); resultStream.WriteBool(false); resultStream.WriteInt(returnIndex); if (result == null) { resultStream.WriteBool(false); } else { Writer writer; Type t = result.GetType(); resultStream.WriteBool(true); if (writers.TryGetTypeValue(t, out writer)) { writer(resultStream, t, result); } } stream.Player.Connection.Queue(resultStream, true); } else { receiver.Method.Invoke(receiver.Instance, args); } return(true); }
void sendStream(Player player, NetConnection connection, NetDeliveryMethod delivery, ByteOutStream data, ByteOutStream header, int mtu) { // Create message NetOutgoingMessage message = Peer.CreateMessage(Math.Max(mtu, data.Size + header.Size)); // Write header + data message.WriteRaw(header.Stream.Data, 0, header.Stream.Size); message.WriteRaw(data.Stream.Data, 0, data.Stream.Size); // Record status player.Stats.AddOutBytes(message.LengthBytes + 2); player.Context.Stats.AddOutBytes(message.LengthBytes + 2); // Send message Peer.SendMessage(message, connection, delivery); }
public void WriteToStream(Player player, Network.ByteOutStream stream) { PackSyncData(DirtyIndexes, stream); }
public abstract void Pack(Network.ByteOutStream stream);
public override void Pack(SlimNet.Network.ByteOutStream stream) { stream.WriteByte(State); }
public void WriteToStream(Player player, Network.ByteOutStream stream) { synchronizable.PackSyncData(UInt32.MaxValue, stream); }
internal abstract void WriteEventHeader(Event <T> ev, Network.ByteOutStream stream);