void SendStatePacketToClient(PlayerController inPlayerController)
        {
            int network_id = 0;

            do
            {
                //Log.Information($"SendStatePacketToClient");
                //build state packet
                var statePacket = GetServer().CreateMessage();

                //it's state!
                statePacket.Write((uint32_t)PacketType.kState, PacketTypeLengthBits);

                InFlightPacket ifp = inPlayerController.GetDeliveryNotificationManager().WriteState(statePacket);

                WriteLastMoveTimestampIfDirty(statePacket, inPlayerController);

                var rmtd = new ReplicationManagerTransmissionData(inPlayerController.GetReplicationManagerServer());
                network_id = inPlayerController.GetReplicationManagerServer().Write(statePacket, rmtd, network_id, inPlayerController.GetWorldId());
                ifp.SetTransmissionData((int)TransmissionDataType.kReplicationManager, rmtd);

                inPlayerController.SendMessage(statePacket, NetDeliveryMethod.Unreliable);


                //Debug.Log($"SendStatePacketToClient PlayerId:{inPlayerController.GetPlayerId()}, network_id:{network_id}");
            } while (network_id != 0);
        }
Ejemplo n.º 2
0
        public void Write(NetOutgoingMessage inOutputStream, ReplicationManagerTransmissionData ioTransmissinData)
        {
            //run through each replication command and do something...
            foreach (var pair in mNetworkIdToReplicationCommand)
            {
                ReplicationCommand replicationCommand = pair.Value;
                if (replicationCommand.HasDirtyState())
                {
                    int networkId = pair.Key;

                    //well, first write the network id...
                    inOutputStream.Write(networkId);

                    //only need 2 bits for action...
                    ReplicationAction action = replicationCommand.GetAction();
                    inOutputStream.Write(action);

                    uint32_t writtenState = 0;
                    uint32_t dirtyState   = replicationCommand.GetDirtyState();

                    //now do what?
                    switch (action)
                    {
                    case ReplicationAction.RA_Create:
                        writtenState = WriteCreateAction(inOutputStream, networkId, dirtyState);
                        break;

                    case ReplicationAction.RA_Update:
                        writtenState = WriteUpdateAction(inOutputStream, networkId, dirtyState);
                        break;

                    case ReplicationAction.RA_Destroy:
                        //don't need anything other than state!
                        writtenState = WriteDestroyAction(inOutputStream, networkId, dirtyState);
                        break;
                    }

                    ioTransmissinData.AddTransmission(networkId, action, writtenState);

                    //let's pretend everything was written- don't make this too hard
                    replicationCommand.ClearDirtyState(writtenState);
                }
            }
        }
Ejemplo n.º 3
0
        void SendStatePacketToClient(ClientProxy inClientProxy)
        {
            //build state packet
            var statePacket = GetServer().CreateMessage();

            //it's state!
            statePacket.Write((uint32_t)PacketType.kStateCC);

            InFlightPacket ifp = inClientProxy.GetDeliveryNotificationManager().WriteState(statePacket);

            WriteLastMoveTimestampIfDirty(statePacket, inClientProxy);

            AddScoreBoardStateToPacket(statePacket);

            var rmtd = new ReplicationManagerTransmissionData(inClientProxy.GetReplicationManagerServer());

            inClientProxy.GetReplicationManagerServer().Write(statePacket, rmtd);
            ifp.SetTransmissionData((int)TransmissionDataType.kReplicationManager, rmtd);

            var ret = GetServer().SendMessage(statePacket, inClientProxy.mConnection, NetDeliveryMethod.Unreliable);
            //log.InfoFormat("send {0}", ret);
        }
Ejemplo n.º 4
0
        void HandleUpdateStateDeliveryFailure(int inNetworkId, uint32_t inState, DeliveryNotificationManager inDeliveryNotificationManager)
        {
            //does the object still exist? it might be dead, in which case we don't resend an update
            if (NetworkManagerServer.sInstance.GetGameObject(inNetworkId) != null)
            {
                //look in all future in flight packets, in all transmissions
                //remove written state from dirty state
                foreach (var inFlightPacket in inDeliveryNotificationManager.GetInFlightPackets())
                {
                    ReplicationManagerTransmissionData rmtdp = (ReplicationManagerTransmissionData)(inFlightPacket.GetTransmissionData((int)TransmissionDataType.kReplicationManager));

                    foreach (var otherRT in rmtdp.mTransmissions)
                    {
                        inState &= ~otherRT.GetState();
                    }
                }

                //if there's still any dirty state, mark it
                if (inState != 0)
                {
                    mReplicationManagerServer.SetStateDirty(inNetworkId, inState);
                }
            }
        }
        public int Write(NetOutgoingMessage inOutputStream, ReplicationManagerTransmissionData ioTransmissinData, int inRestartedNetworkId, byte inWorldId)
        {
            int  count = 0;
            bool skip  = (inRestartedNetworkId != 0);
            //run through each replication command and do something...
            List <int> removeObject = null;

            foreach (var pair in mNetworkIdToReplicationCommand)
            {
                ReplicationCommand replicationCommand = pair.Value;
                if (replicationCommand.HasDirtyState())
                {
                    // 이전에 중단 되었던 network ID 부터 재개
                    if (skip)
                    {
                        if (inRestartedNetworkId == pair.Key)
                        {
                            skip = false;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    int networkId                = pair.Key;
                    ReplicationAction action     = replicationCommand.GetAction();
                    NetGameObject     gameObject = NetworkManagerServer.sInstance.GetGameObject(networkId, inWorldId);
                    if (gameObject == null && action != ReplicationAction.RA_Destroy)
                    {
                        if (removeObject == null)
                        {
                            removeObject = new List <int>();
                        }

                        removeObject.Add(networkId);
                        continue;
                    }

                    // 최대로 동기화 할수 있는 개수 초과시 중단
                    ++count;
                    if (count > max_replication_count)
                    {
                        return(pair.Key);
                    }



                    //well, first write the network id...
                    inOutputStream.Write((uint)networkId, NetGameObject.NetworkIdSize);
                    //Log.Information($"write networkId:{networkId}, classId:{gameObject?.GetClassId()}, action:{action}");

                    //only need 2 bits for action...
                    inOutputStream.Write(action);

                    uint32_t writtenState = 0;
                    uint32_t dirtyState   = replicationCommand.GetDirtyState();

                    //now do what?
                    switch (action)
                    {
                    case ReplicationAction.RA_Create:
                    {
                        inOutputStream.Write(gameObject.GetClassId());
                        writtenState = gameObject.Write(inOutputStream, dirtyState);
                    }
                    break;

                    case ReplicationAction.RA_Update:
                    {
                        writtenState = gameObject.Write(inOutputStream, dirtyState);
                    }
                    break;

                    case ReplicationAction.RA_Destroy:
                    {
                        //don't need anything other than state!
                        writtenState = dirtyState;
                    }
                    break;
                    }

                    ioTransmissinData.AddTransmission(networkId, action, writtenState, inWorldId);

                    //let's pretend everything was written- don't make this too hard
                    replicationCommand.ClearDirtyState(writtenState);
                }
            }

            if (removeObject != null)
            {
                foreach (var key in removeObject)
                {
                    mNetworkIdToReplicationCommand.Remove(key);
                }
            }
            return(0);
        }