private IEnumerator AddClientToZone()
    {
        // By OnStartClient's note
        yield return(null);

        if (hasAuthority == false)
        {
            yield break;
        }

        var channel = new ProtobufChannelToServerZoneOutbound
        {
            OutboundChannel = new EntityNetworkChannelToServerZone {
                NetworkClient = this
            },
            TypeTable = EntityNetworkManager.Instance.GetTypeAliasTable(),
            TypeModel = EntityNetworkManager.Instance.GetTypeModel()
        };

        _clientId    = (int)netId.Value;
        _zone        = new ClientZone(EntityNetworkManager.Instance.GetClientEntityFactory(), channel);
        _zoneChannel = new ProtobufChannelToClientZoneInbound
        {
            TypeTable         = EntityNetworkManager.Instance.GetTypeAliasTable(),
            TypeModel         = EntityNetworkManager.Instance.GetTypeModel(),
            InboundClientZone = _zone
        };

        LocalClientId   = _clientId;
        LocalClientZone = _zone;

        CmdAddClientToZone();
    }
Example #2
0
        public KeyValuePair <int, TestClientZone> AddClient()
        {
            var clientId = ++_lastClientId;

            var channelUp = new ProtobufChannelToServerZoneOutbound
            {
                TypeTable       = _typeTable,
                TypeModel       = _typeModel,
                OutboundChannel = new DummyChannelToServerZoneInbound
                {
                    Channel = new ProtobufChannelToServerZoneInbound
                    {
                        TypeTable         = _typeTable,
                        TypeModel         = _typeModel,
                        ClientId          = clientId,
                        InboundServerZone = ServerZone,
                    }
                }
            };

            var clientZone = new TestClientZone(EntityFactory.Default, channelUp);

            ((EntityTimerProvider)clientZone.TimerProvider).ActionScheduled = OnActionSchedule;

            var channelDown = new ProtobufChannelToClientZoneOutbound
            {
                TypeTable       = _typeTable,
                TypeModel       = _typeModel,
                OutboundChannel = new ProtobufChannelToClientZoneInbound()
                {
                    TypeTable         = _typeTable,
                    TypeModel         = _typeModel,
                    InboundClientZone = clientZone,
                }
            };

            ServerZone.AddClient(clientId, channelDown);

            ClientZoneMap.Add(clientId, clientZone);
            ClientZones = ClientZoneMap.Values.ToArray();

            return(new KeyValuePair <int, TestClientZone>(clientId, clientZone));
        }
Example #3
0
        private static void Main(string[] args)
        {
            var typeTable = new TypeAliasTable();

            var typeModel = TypeModel.Create();

            typeModel.Add(typeof(TrackablePocoTracker <ISpaceShipData>), false)
            .SetSurrogate(typeof(TrackableSpaceShipDataTrackerSurrogate));

            var serverZone = new ServerZone(EntityFactory.Default);

            var clientZones = Enumerable.Range(0, 2).Select(i =>
            {
                var channelUp = new ProtobufChannelToServerZoneOutbound
                {
                    TypeTable       = typeTable,
                    TypeModel       = typeModel,
                    OutboundChannel = new DummyChannelToServerZoneInbound
                    {
                        Channel = new ProtobufChannelToServerZoneInbound
                        {
                            TypeTable         = typeTable,
                            TypeModel         = typeModel,
                            ClientId          = i + 1,
                            InboundServerZone = serverZone,
                        }
                    }
                };
                var clientZone = new ClientZone(EntityFactory.Default, channelUp);
                var channel    = new ProtobufChannelToClientZoneOutbound
                {
                    TypeTable       = typeTable,
                    TypeModel       = typeModel,
                    OutboundChannel = new ProtobufChannelToClientZoneInbound()
                    {
                        TypeTable         = typeTable,
                        TypeModel         = typeModel,
                        InboundClientZone = clientZone,
                    }
                };
                serverZone.AddClient(i + 1, channel);
                return(clientZone);
            }).ToArray();

            serverZone.RunAction(zone =>
            {
                zone.Spawn(typeof(ISpaceShip), 0, EntityFlags.AnyoneCanControl);
            });

            var cship1A = (ClientSpaceShip)clientZones[0].GetEntity(1);
            var cship1B = (ClientSpaceShip)clientZones[1].GetEntity(1);

            Console.WriteLine($"cship1A.Score = {cship1A.Data.Score}");
            clientZones[0].RunAction(_ => cship1A.Say("Hello"));
            Console.WriteLine($"cship1A.Score = {cship1A.Data.Score}");
            clientZones[0].RunAction(_ => cship1A.Stop(1, 2));
            clientZones[1].RunAction(_ =>
            {
                cship1B.Say("World");
                cship1B.Shoot(1, 2, 3, 4);
            });
        }
Example #4
0
 public TestClientZone(IClientEntityFactory entityFactory, ProtobufChannelToServerZoneOutbound serverChannel)
     : base(entityFactory, serverChannel)
 {
     EntitySpawned   = OnSpawn;
     EntityDespawned = OnDespawn;
 }