Beispiel #1
0
 /// <summary>
 /// 创建内置服务器
 /// </summary>
 /// <returns></returns>
 public static ClientFrame CreateServer(string ip, int port)
 {
     AideClientFrame = new ClientFrame(Tool.Sockets.SupportCode.TcpBufferSize.Default, 108, true);
     TcpFrame.ip     = ip;
     TcpFrame.port   = port;
     return(AideClientFrame);
 }
Beispiel #2
0
        public void DeleteClientFrames(int tick)
        {
            var         frame = _frames;
            ClientFrame prev  = null;

            while (frame != null)
            {
                if (tick < 0 || frame.TickCount < tick)
                {
                    // then remove frame

                    if (prev != null)
                    {
                        prev.NextFrame = frame.NextFrame;
                        frame          = prev.NextFrame;
                    }
                    else
                    {
                        _frames = frame.NextFrame;
                        frame   = _frames;
                    }
                }
                else
                {
                    prev  = frame;
                    frame = frame.NextFrame;
                }
            }
        }
        internal TServerDataFrameType HandleClientFrame(ClientFrame clientFrame)
        {
            if (this.sessionState == SessionState.Handshaking)
            {
                this.SetNewSessionState(SessionState.Connected);

                this.keepAlivePacketSenderTimer.Change(this.protocolruntimeSpecification.KeepAliveServerInterval, this.protocolruntimeSpecification.KeepAliveServerInterval);
                this.handshakeTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
            }

            this.dataReceiveTimer.Change(this.dataReceiveTimeout, this.dataReceiveTimeout);

            if (clientFrame is TClientDataFrameType)
            {
                var dataFrame = (TClientDataFrameType)clientFrame;
                this.frameBuffer.Add(dataFrame);
            }

            TServerDataFrameType toSend;

            if (this.queue.TryDequeue(out toSend))
            {
                return(this.SetSequenceNr(toSend));
            }

            return(null);
        }
Beispiel #4
0
        public GameClient(int slot, BaseServer server) : base(server)
        {
            Clear();

            EntityIndex = slot + 1;
            _frames     = null;
            Server      = server;
        }
Beispiel #5
0
        public void RemoveOldestFrame()
        {
            var frame = _frames;

            if (frame == null)
            {
                return;
            }

            _frames = frame.NextFrame;
        }
Beispiel #6
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;
        }
Beispiel #7
0
        public void SetupPackInfo(FrameSnapshot snapshot)
        {
            // TODO: Setup PVS visibility

            CurrentFrame = new ClientFrame();
            CurrentFrame.Init(snapshot);

            var maxFrames = ClientFrame.MaxClientFrames;

            if (maxFrames < AddClientFrame(CurrentFrame))
            {
                RemoveOldestFrame();
            }
        }
Beispiel #8
0
        public int AddClientFrame(ClientFrame frame)
        {
            if (_frames == null)
            {
                _frames = frame;
                return(1);
            }

            var count = 1;
            var f     = _frames;

            while (f.NextFrame != null)
            {
                f = f.NextFrame;
                ++count;
            }

            ++count;
            f.NextFrame = frame;

            return(count);
        }
Beispiel #9
0
        public void CopyFrame(ClientFrame frame)
        {
            TickCount = frame.TickCount;

            SetSnapshot(frame.GetSnapshot());
        }
Beispiel #10
0
 public ClientFrame()
 {
     TickCount = 0;
     _snapshot = null;
     NextFrame = null;
 }
Beispiel #11
0
 public ClientFrame(int tickcount)
 {
     TickCount = tickcount;
     _snapshot = null;
     NextFrame = null;
 }
Beispiel #12
0
        public override void SendSnapshot(ClientFrame frame)
        {
            WriteViewAngleUpdate();

            base.SendSnapshot(frame);
        }
Beispiel #13
0
 public static void AllocPacketEntities(ref ClientFrame Frame, uint NumEnts)
 {
 }
Beispiel #14
0
 public static void ClearPacketEntities(ref ClientFrame Frame, bool ForceFree)
 {
 }
Beispiel #15
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");
            }
        }