Пример #1
0
        protected MyMultiplayerServerBase(MySyncLayer syncLayer, EndpointId localClientEndpoint) : base(syncLayer)
        {
            this.m_factory = new MyReplicableFactory();
            MyReplicationServer layer = new MyReplicationServer(this, localClientEndpoint, Thread.CurrentThread);

            base.SetReplicationLayer(layer);
            base.ClientLeft           += (steamId, e) => MySandboxGame.Static.Invoke(() => this.ReplicationLayer.OnClientLeft(new EndpointId(steamId)), "P2P Client left");
            base.ClientJoined         += steamId => this.ReplicationLayer.OnClientJoined(new EndpointId(steamId), base.CreateClientState());
            MyEntities.OnEntityCreate += new Action <MyEntity>(this.CreateReplicableForObject);
            MyEntityComponentBase.OnAfterAddedToContainer += new Action <MyEntityComponentBase>(this.CreateReplicableForObject);
            MyExternalReplicable.Destroyed += new Action <MyExternalReplicable>(this.DestroyReplicable);
            foreach (MyEntity entity in MyEntities.GetEntities())
            {
                this.CreateReplicableForObject(entity);
                MyEntityComponentContainer components = entity.Components;
                if (components != null)
                {
                    foreach (MyComponentBase base2 in components)
                    {
                        this.CreateReplicableForObject(base2);
                    }
                }
            }
            syncLayer.TransportLayer.Register(MyMessageId.RPC, 0xff, new Action <MyPacket>(this.ReplicationLayer.OnEvent));
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, 0xff, new Action <MyPacket>(this.ReplicationLayer.ReplicableReady));
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_REQUEST, 0xff, new Action <MyPacket>(this.ReplicationLayer.ReplicableRequest));
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, 0xff, new Action <MyPacket>(this.ReplicationLayer.OnClientUpdate));
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_ACKS, 0xff, new Action <MyPacket>(this.ReplicationLayer.OnClientAcks));
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, 0xff, new Action <MyPacket>(this.ClientReady));
        }
Пример #2
0
        public MyMultiplayerServerBase(MySyncLayer syncLayer)
            : base(syncLayer)
        {
            var replication = new MyReplicationServer(this, () => MySandboxGame.Static.UpdateTime);

            if (MyFakes.MULTIPLAYER_REPLICATION_TEST)
            {
                replication.MaxSleepTime = MyTimeSpan.FromSeconds(30);
            }
            SetReplicationLayer(replication);
            ClientLeft += (steamId, e) => ReplicationLayer.OnClientLeft(new EndpointId(steamId));

            MyEntities.OnEntityCreate      += CreateReplicableForObject;
            MyInventory.OnCreated          += CreateReplicableForObject;
            MyExternalReplicable.Destroyed += DestroyReplicable;

            foreach (var entity in MyEntities.GetEntities())
            {
                CreateReplicableForObject(entity);
            }

            syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, ReplicationLayer.ReplicableReady);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, ReplicationLayer.OnClientUpdate);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, (p) => ReplicationLayer.OnClientReady(p.Sender, new MyClientState()));
        }
Пример #3
0
 public ItemsStateGroup(MyInventory entity, IMyReplicable owner, int batch)
 {
     Inventory   = entity;
     Batch       = batch;
     _serverData = new Dictionary <Endpoint, InventoryClientData>();
     Inventory.ContentsChanged += InventoryChanged;
     Owner   = owner;
     _server = (MyReplicationServer)MyMultiplayer.Static.ReplicationLayer;
 }
Пример #4
0
        public static void ReplicateImmediatelly(IMyReplicable replicable, IMyReplicable dependency = null)
        {
            MyReplicationServer replicationServer = GetReplicationServer();

            if (replicationServer != null)
            {
                replicationServer.ForceReplicable(replicable, dependency);
            }
        }
Пример #5
0
        public static void RemoveForClientIfIncomplete(IMyEventProxy obj)
        {
            MyReplicationServer replicationServer = GetReplicationServer();

            if (replicationServer != null)
            {
                replicationServer.RemoveForClientIfIncomplete(obj);
            }
        }
Пример #6
0
        private static void OnVirtualClientAdded(int index)
        {
            Endpoint            endpoint         = new Endpoint(MyEventContext.Current.IsLocallyInvoked ? new EndpointId(Sync.MyId) : MyEventContext.Current.Sender, (byte)index);
            MyReplicationServer replicationLayer = MyMultiplayer.Static.ReplicationLayer as MyReplicationServer;

            replicationLayer.AddClient(endpoint, CreateClientState());
            ClientReadyDataMsg msg = new ClientReadyDataMsg {
                UsePlayoutDelayBufferForCharacter = true,
                UsePlayoutDelayBufferForJetpack   = true,
                UsePlayoutDelayBufferForGrids     = true
            };

            replicationLayer.OnClientReady(endpoint, ref msg);
        }
Пример #7
0
        public PropsStateGroup(InventoryReplicable owner, SyncType syncType, int batch)
        {
            Owner   = owner;
            Batch   = batch;
            _server = (MyReplicationServer)MyMultiplayer.Static.ReplicationLayer;
            syncType.PropertyChangedNotify += Notify;
            syncType.PropertyCountChanged  += OnPropertyCountChanged;
            m_properties         = syncType.Properties;
            m_propertyTimestamps = new List <MyTimeSpan>(m_properties.Count);

            for (var i = 0; i < m_properties.Count; i++)
            {
                m_propertyTimestamps.Add(_server.GetSimulationUpdateTime());
            }
        }
Пример #8
0
        public static void RemoveKnownSector(long planetId, long sectorId)
        {
            MyReplicationServer replicationServer = MyMultiplayer.GetReplicationServer();

            if (replicationServer != null)
            {
                HashSet <long> set;
                MyClientState  clientData = (MyClientState)replicationServer.GetClientData(new Endpoint(MyEventContext.Current.Sender, 0));
                if ((clientData != null) && clientData.KnownSectors.TryGetValue(planetId, out set))
                {
                    set.Remove(sectorId);
                    if (set.Count == 0)
                    {
                        clientData.KnownSectors.Remove(planetId);
                    }
                }
            }
        }
Пример #9
0
        public static void AddKnownSector(long planetId, long sectorId)
        {
            MyReplicationServer replicationServer = MyMultiplayer.GetReplicationServer();

            if (replicationServer != null)
            {
                MyClientState clientData = (MyClientState)replicationServer.GetClientData(new Endpoint(MyEventContext.Current.Sender, 0));
                if (clientData != null)
                {
                    HashSet <long> set;
                    if (!clientData.KnownSectors.TryGetValue(planetId, out set))
                    {
                        set = new HashSet <long>();
                        clientData.KnownSectors.Add(planetId, set);
                    }
                    set.Add(sectorId);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the MyMultiplayerServerBase class.
        /// </summary>
        /// <param name="localClientEndpoint">Local client endpoint (for single player or lobby host) or null (for dedicated server)</param>
        public MyMultiplayerServerBase(MySyncLayer syncLayer, EndpointId?localClientEndpoint)
            : base(syncLayer)
        {
            Debug.Assert(MyEntities.GetEntities().Count == 0, "Multiplayer server must be created before any entities are loaded!");

            var replication = new MyReplicationServer(this, localClientEndpoint, MyFakes.MULTIPLAYER_USE_PLAYOUT_DELAY_BUFFER);

            if (MyFakes.MULTIPLAYER_REPLICATION_TEST)
            {
                replication.MaxSleepTime = MyTimeSpan.FromSeconds(30);
            }
            SetReplicationLayer(replication);
            ClientLeft   += (steamId, e) => ReplicationLayer.OnClientLeft(new EndpointId(steamId));
            ClientJoined += (steamId) => ReplicationLayer.OnClientJoined(new EndpointId(steamId), CreateClientState());

            MyEntities.OnEntityCreate += CreateReplicableForObject;
            MyEntityComponentBase.OnAfterAddedToContainer += CreateReplicableForObject;
            MyExternalReplicable.Destroyed += DestroyReplicable;

            foreach (var entity in MyEntities.GetEntities())
            {
                CreateReplicableForObject(entity);
                var components = entity.Components;
                if (components != null)
                {
                    foreach (var comp in components)
                    {
                        CreateReplicableForObject(comp);
                    }
                }
            }

            syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_READY, ReplicationLayer.ReplicableReady);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_UPDATE, ReplicationLayer.OnClientUpdate);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_ACKS, ReplicationLayer.OnClientAcks);
            syncLayer.TransportLayer.Register(MyMessageId.CLIENT_READY, ClientReady);
        }
Пример #11
0
 public void Destroy()
 {
     Owner   = null;
     _server = null;
 }
Пример #12
0
 public void Destroy()
 {
     Inventory.ContentsChanged -= InventoryChanged;
     _server = null;
 }