public MultiplexConnectionOutputPump(BufferRead bufferRead, BufferWrite bufferWrite, int connectionId)
 {
     this.bufferRead = bufferRead;
     this.bufferWrite = bufferWrite;
     this.inputBuffer = new byte[65536];
     this.connectionId = connectionId;
 }
Exemplo n.º 2
0
 public MultiplexConnectionOutputPump(BufferRead bufferRead, BufferWrite bufferWrite, int connectionId)
 {
     this.bufferRead   = bufferRead;
     this.bufferWrite  = bufferWrite;
     inputBuffer       = new byte[65536];
     this.connectionId = connectionId;
 }
Exemplo n.º 3
0
 public BaseServer(Socket serverSocket)
 {
     Socket = serverSocket;
     _serverQueryChallenges = new List <NetChallenge>();
     Clients      = new List <GameClient>();
     Signon       = new BufferWrite();
     TickInterval = 0.03f;
 }
Exemplo n.º 4
0
        public override bool WriteToBuffer(BufferWrite buffer)
        {
            buffer.WriteInt(Tick);
            buffer.WriteULong(Utils.Clamp <ulong>((ulong)(HostFrameTime * Networking.NetTickScaleUp), 0, 65535));
            buffer.WriteULong(Utils.Clamp <ulong>((ulong)(HostFrameTimeStdDeviation * Networking.NetTickScaleUp), 0, 65535));

            return(true);
        }
Exemplo n.º 5
0
 public FramingOutputPump(BufferRead bufferRead, BufferWrite bufferWrite, int pingFrequency, EventTraceActivity activity, Uri uri)
 {
     this.bufferRead    = bufferRead;
     this.bufferWrite   = bufferWrite;
     this.inputBuffer   = new byte[65536];
     this.pingFrequency = pingFrequency;
     this.activity      = activity;
     this.uri           = uri;
 }
Exemplo n.º 6
0
        public static void OutOfBandPrintf(Socket socket, EndPoint addr, string format, params object[] args)
        {
            var msg = new BufferWrite();

            msg.WriteBytes(NetProtocol.ConnectionlessHeader);
            msg.WriteString(string.Format(format, args));

            SendPacket(null, socket, addr, msg.GetData());
        }
Exemplo n.º 7
0
 public FramingInputPump(BufferRead bufferRead, BufferWrite bufferWrite, Action bufferDone, EventTraceActivity activity, Uri uri)
 {
     this.bufferRead     = bufferRead;
     this.bufferWrite    = bufferWrite;
     this.bufferDone     = bufferDone;
     this.inputBuffer    = new byte[65536];
     this.preambleBuffer = new byte[2];
     this.Activity       = activity;
     this.uri            = uri;
 }
Exemplo n.º 8
0
        public bool SendData(BufferWrite msg, bool reliable = false)
        {
            if (_remoteAddress == null)
            {
                return(true);
            }

            var buf = reliable ? StreamReliable : StreamUnreliable;

            return(buf.WriteBytes(msg.GetData()));
        }
Exemplo n.º 9
0
        public NetChannel()
        {
            _netMesages = new List <NetMessage>();

            StreamReliable   = new BufferWrite();
            StreamUnreliable = new BufferWrite();

            _timeout = Networking.SignonTimeout;
            _rate    = Networking.DefaultRate;

            _inReliableState  = 0;
            _outReliableState = 0;
        }
Exemplo n.º 10
0
        private void ReplyChallenge(EndPoint clientEp)
        {
            var msg = new BufferWrite();

            // get a free challenge number
            var challengeNr = GetChallengeNr(clientEp);

            msg.WriteBytes(NetProtocol.ConnectionlessHeader);

            msg.WriteChar((char)EConnectionType.ServerChallenge);
            msg.WriteInt(challengeNr);
            msg.WriteInt(1); // auth protocol
            msg.WriteString("EE00");

            Networking.SendPacket(null, Socket, clientEp, msg.GetData());
        }
Exemplo n.º 11
0
        public bool SendServerInfo()
        {
            var msg = new BufferWrite();

            _sendServerInfo = false;
            SignonState     = ESignonState.New;

            var signonMsg = new NetMessageSignonState(SignonState);

            signonMsg.WriteToBuffer(msg);

            if (!_netChannel.SendData(msg))
            {
                Disconnect("Server info data overflow");
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
0
        private void SendConnectPacket(int challengeNr, int authProtocol)
        {
            var serverEp = (EndPoint) new IPEndPoint(IPAddress.Any, 0);

            if (!Networking.StringToAddr(_retryAddress, ref serverEp))
            {
                Console.WriteLine("Bad server address ({0})!\n", serverEp);
                Disconnect();
                return;
            }

            var msg = new BufferWrite();

            msg.WriteBytes(NetProtocol.ConnectionlessHeader);
            msg.WriteChar((char)EConnectionType.PlayerConnect);
            msg.WriteInt(Program.ProtocolVersion);
            msg.WriteInt(authProtocol);
            msg.WriteInt(challengeNr);
            msg.WriteString(Program.ClientName);
            msg.WriteString(Program.ServerPassword);

            Networking.SendPacket(null, _socket, serverEp, msg.GetData());
        }
Exemplo n.º 13
0
 public abstract bool WriteToBuffer(BufferWrite buffer);
 public StreamOverWriteDelegate(BufferWrite bufferWrite)
 {
     this.bufferWrite = bufferWrite;
 }
Exemplo n.º 15
0
 public MultiplexedConnection(BufferWrite bufferWrite, int connectionId)
 {
     Id = connectionId;
     this.bufferWrite = bufferWrite;
     Trace.TraceInformation("Connection {0} created", connectionId);
 }
Exemplo n.º 16
0
 public MultiplexedConnection(BufferWrite bufferWrite)
 {
     Id = Interlocked.Increment(ref lastConnection);
     this.bufferWrite = bufferWrite;
     Trace.TraceInformation("Connection {0} created", Id);
 }
Exemplo n.º 17
0
        public override bool WriteToBuffer(BufferWrite buffer)
        {
            buffer.WriteByte((byte)_state);

            return(true);
        }
Exemplo n.º 18
0
 public BufferPump(BufferRead bufferRead, BufferWrite bufferWrite, int bufferSize)
 {
     this.bufferRead = bufferRead;
     this.bufferWrite = bufferWrite;
     this.inputBuffer = new byte[bufferSize];
 }
Exemplo n.º 19
0
 public StreamOverWriteDelegate(BufferWrite bufferWrite)
 {
     this.bufferWrite = bufferWrite;
 }
Exemplo n.º 20
0
 public BufferPump(BufferRead bufferRead, BufferWrite bufferWrite)
     : this(bufferRead, bufferWrite, 65536)
 {
 }
Exemplo n.º 21
0
 public BufferPump(BufferRead bufferRead, BufferWrite bufferWrite, int bufferSize)
 {
     this.bufferRead  = bufferRead;
     this.bufferWrite = bufferWrite;
     inputBuffer      = new byte[bufferSize];
 }
Exemplo n.º 22
0
 public BufferPump(BufferRead bufferRead, BufferWrite bufferWrite)
     : this(bufferRead, bufferWrite, 65536)
 {
 }
Exemplo n.º 23
0
        public virtual void SendSnapshot(ClientFrame frame)
        {
            // do not send same snapshot twice
            if (_lastSnapshot == frame.GetSnapshot())
            {
                NetChannel.Transmit();
                return;
            }

            // if we send a full snapshot (no delta-compression) before, wait until client
            // received and acknowledge that update. don't spam client with full updates
            if (_forceWaitForTick > 0)
            {
                NetChannel.Transmit();
                return;
            }

            var msg = new BufferWrite();

            var deltaFrame = GetDeltaFrame(_deltaTick);

            if (deltaFrame == null)
            {
                // We need to send a full update and reset the instanced baselines
                OnRequestFullUpdate();
            }

            var tickmsg = new NetMessageTick(frame.TickCount, Program.HostFrametimeUnbounded, Program.HostFrametimeStdDeviation);

            tickmsg.WriteToBuffer(msg);

            // send entity update, delta compressed if deltaFrame != NULL
            Server.WriteDeltaEntities(this, frame, deltaFrame, msg);

            var maxTempEnts = 255;

            Server.WriteTempEntities(this, frame.GetSnapshot(), _lastSnapshot, msg, maxTempEnts);

            _lastSnapshot = frame.GetSnapshot();

            if (NetChannel == null)
            {
                _deltaTick = frame.TickCount;
                return;
            }

            bool sendOk;

            if (deltaFrame == null)
            {
                sendOk = NetChannel.SendData(msg);
                sendOk = sendOk && NetChannel.Transmit();

                // remember this tickcount we send the reliable snapshot
                // so we can continue sending other updates if this has been acknowledged
                _forceWaitForTick = frame.TickCount;
            }
            else
            {
                sendOk = NetChannel.SendDatagram(msg) > 0;
            }

            if (!sendOk)
            {
                Disconnect("Error! Couldn't send snapshot");
            }
        }
Exemplo n.º 24
0
 public void WriteTempEntities(BaseClient baseClient, FrameSnapshot getSnapshot, FrameSnapshot lastSnapshot, BufferWrite msg, int maxTempEnts)
 {
     // CBaseServer::WriteTempEntities
 }
Exemplo n.º 25
0
        public int SendDatagram(BufferWrite datagram)
        {
            var send = new BufferWrite();

            send.WriteInt(_outSequenceNr);
            send.WriteInt(_inSequenceNr);

            send.WriteByte(_inReliableState);

            var flagsPos = send.Position;

            // write correct flags value later
            send.WriteByte(0);

            byte flags = 0;

            if (_chokedPackets > 0)
            {
                flags |= (byte)ENetPacketHeader.Choked;
                send.WriteByte((byte)(_chokedPackets & 0xFF));
            }

            if (datagram != null)
            {
                if (datagram.GetNumBitsWritten() > 0)
                {
                    send.WriteBytes(datagram.GetData());
                }
            }

            if (StreamUnreliable.GetNumBitsWritten() > 0)
            {
                send.WriteBytes(StreamUnreliable.GetData());
            }

            // clear unreliable data buffer
            StreamUnreliable.Reset();

            send.WriteByteAt((int)flagsPos, flags);

            var bytesSend = Networking.SendPacket(this, _socket, _remoteAddress, send.GetData());

            // TODO: Calc sended size with udp header, and retreive stats
            // TODO: Network throttling

            if (_clearTime < Networking.NetTime)
            {
                _clearTime = Networking.NetTime;
            }

            var addTime = bytesSend / _rate;

            _clearTime += addTime;

            if (Networking.NetMaxcleartime > 0.0f)
            {
                var latestClearTime = Networking.NetTime + Networking.NetMaxcleartime;
                if (_clearTime > latestClearTime)
                {
                    _clearTime = latestClearTime;
                }
            }

            _chokedPackets = 0;
            _outSequenceNr++;

            // return send sequence nr
            return(_outSequenceNr - 1);
        }
 public MultiplexedConnection(BufferWrite bufferWrite, int connectionId)
 {
     Id = connectionId;
     this.bufferWrite = bufferWrite ?? throw new ArgumentNullException(nameof(bufferWrite));
     Trace.TraceInformation("Connection {0} created", connectionId);
 }
 public MultiplexedConnection(BufferWrite bufferWrite)
     : this(bufferWrite, Interlocked.Increment(ref lastConnection))
 {
 }
Exemplo n.º 28
0
        public void WriteDeltaEntities(BaseClient client, ClientFrame to, ClientFrame from, BufferWrite buf)
        {
            var u = new EntityWriteInfo();

            u.Buf          = buf;
            u.To           = to;
            u.ToSnapshot   = to.GetSnapshot();
            u.Baseline     = client.Baseline;
            u.FullProps    = 0;
            u.Server       = this;
            u.ClientEntity = client.EntityIndex;
            u.CullProps    = true;

            if (from != null)
            {
                u.AsDelta      = true;
                u.From         = from;
                u.FromSnapshot = from.GetSnapshot();
            }
            else
            {
                u.AsDelta      = false;
                u.From         = null;
                u.FromSnapshot = null;
            }

            u.HeaderCount = 0;

            // set from_baseline pointer if this snapshot may become a baseline update
            if (client.BaselineUpdateTick == -1)
            {
                // TODO: Clear client baselines sent
                // TODO: Set 'to' from baseline to client.BaselinesSent
            }

            u.Buf.WriteUShort((ushort)ENetCommand.SvcPacketEntities);
            u.Buf.WriteInt(u.ToSnapshot.NumEntities);

            if (u.AsDelta)
            {
                u.Buf.WriteByte(1);
                u.Buf.WriteInt(u.From.TickCount);
            }
            else
            {
                u.Buf.WriteByte(0);
            }

            u.Buf.WriteInt(client.BaselineUsed);

            // Store off current position
            var savePos = u.Buf.Position;
        }
Exemplo n.º 29
0
 public MultiplexedConnection(BufferWrite bufferWrite)
 {
     this.connectionId = Interlocked.Increment(ref lastConnection);
     this.bufferWrite = bufferWrite;
     Trace.TraceInformation("Connection {0} created", connectionId);
 }
Exemplo n.º 30
0
 public StreamBufferWritePump(Stream stream, BufferWrite bufferWrite)
     : base(stream.Read, bufferWrite)
 {
     this.stream = stream;
 }
Exemplo n.º 31
0
 public MultiplexedConnection(BufferWrite bufferWrite, int connectionId)
 {
     this.connectionId = connectionId;
     this.bufferWrite = bufferWrite;
     Trace.TraceInformation("Connection {0} created", connectionId);
 }