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();
    }
    public void RpcAddClientToZoneDone(bool added)
    {
        if (hasAuthority == false)
        {
            return;
        }

        Debug.LogFormat("EntityNetworkClient({0}).RpcAddClientToZoneDone({1})", _clientId, added);
        if (added)
        {
            CmdAddClientToZoneDone();
        }
        else
        {
            _clientId     = 0;
            _zone         = null;
            _zoneChannel  = null;
            LocalClientId = 0;
        }
    }
Exemple #3
0
    private IEnumerator ProcessConnectToServer()
    {
        WriteLine("Connect");

        // Create channel and connect to gateway

        var channelFactory = ChannelFactoryBuilder.Build <DomainProtobufSerializer>(
            endPoint: new IPEndPoint(IPAddress.Loopback, 5000),
            createChannelLogger: () => LogManager.GetLogger("Channel"));

        channelFactory.Type = ChannelType.Tcp;
        var channel = channelFactory.Create();

        var t0 = channel.ConnectAsync();

        yield return(t0.WaitHandle);

        if (t0.Exception != null)
        {
            WriteLine("Connection Failed: " + t0.Exception.Message);
            yield break;
        }

        G.Channel = channel;

        // get user

        var user = G.Channel.CreateRef <UserRef>();

        var t1 = user.GetId();

        yield return(t1.WaitHandle);

        ShowResult(t1, "GetId()");

        if (t1.Status != TaskStatus.RanToCompletion)
        {
            yield break;
        }

        _gameObserver = (GameObserver)G.Channel.CreateObserver <IGameObserver>(this, startPending: true);

        // enter game

        var t2 = user.EnterGame("Test", _gameObserver);

        yield return(t2.WaitHandle);

        ShowResult(t2, "EnterGame()");

        if (t2.Status != TaskStatus.RanToCompletion)
        {
            G.Channel.RemoveObserver(_gameObserver);
            _gameObserver = null;
            yield break;
        }

        _gameClient = (GameClientRef)t2.Result.Item1;

        _zone = new ClientZone(
            ClientEntityFactory.Default,
            new ProtobufChannelToServerZoneOutbound
        {
            TypeTable       = new TypeAliasTable(),
            TypeModel       = new DomainProtobufSerializer(),
            OutboundChannel = this
        });

        _zoneChannel = new ProtobufChannelToClientZoneInbound
        {
            TypeTable         = new TypeAliasTable(),
            TypeModel         = new DomainProtobufSerializer(),
            InboundClientZone = _zone
        };

        _gameObserver.GetEventDispatcher().Pending = false;
    }