Exemplo n.º 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));
        }