Пример #1
0
        static void InitializeBigQ()
        {
            _BigQConfig = ClientConfiguration.Default();
            _BigQConfig.TcpServer.Enable = true;
            _BigQConfig.TcpServer.Port   = _Settings.MessageQueue.TcpPort;
            _BigQConfig.TcpServer.Debug  = false;

            _BigQConfig.ClientGUID    = Guid.NewGuid().ToString();
            _BigQConfig.Email         = _BigQConfig.ClientGUID + "@watsonfunction.local";
            _BigQConfig.Name          = _BigQConfig.ClientGUID;
            _BigQConfig.Password      = _BigQConfig.ClientGUID;
            _BigQConfig.ServerGUID    = "00000000-0000-0000-0000-000000000000";
            _BigQConfig.SyncTimeoutMs = 15000;

            _BigQClient = new Client(_BigQConfig);

            _BigQClient.Callbacks.AsyncMessageReceived    = AsyncMessageReceived;
            _BigQClient.Callbacks.ChannelCreated          = ChannelCreated;
            _BigQClient.Callbacks.ChannelDestroyed        = ChannelDestroyed;
            _BigQClient.Callbacks.ClientJoinedChannel     = ClientJoinedChannel;
            _BigQClient.Callbacks.ClientJoinedServer      = ClientJoinedServer;
            _BigQClient.Callbacks.ClientLeftChannel       = ClientLeftChannel;
            _BigQClient.Callbacks.ClientLeftServer        = ClientLeftServer;
            _BigQClient.Callbacks.ServerConnected         = ServerConnected;
            _BigQClient.Callbacks.ServerDisconnected      = ServerDisconnected;
            _BigQClient.Callbacks.SubscriberJoinedChannel = SubscriberJoinedChannel;
            _BigQClient.Callbacks.SubscriberLeftChannel   = SubscriberLeftChannel;
            _BigQClient.Callbacks.SyncMessageReceived     = SyncMessageReceived;
        }
Пример #2
0
    // common code whether we are connecting to a GameLift hosted server or
    // a local server
    private IEnumerator ConnectToServer(string ipAddr, int port, string tokenUID)
    {
        ClientLogger.LogHandler = (x) => Debug.Log(x);
        ConnectionToken token = new ConnectionToken(tokenUID, null);

        ClientConfiguration clientConfiguration = ClientConfiguration.Default();

        _client = new Aws.GameLift.Realtime.Client(clientConfiguration);
        _client.ConnectionOpen  += new EventHandler(OnOpenEvent);
        _client.ConnectionClose += new EventHandler(OnCloseEvent);
        _client.DataReceived    += new EventHandler <DataReceivedEventArgs>(OnDataReceived);
        _client.ConnectionError += new EventHandler <Aws.GameLift.Realtime.Event.ErrorEventArgs>(OnConnectionErrorEvent);

        int UDPListenPort = FindAvailableUDPPort(DEFAULT_UDP_PORT, DEFAULT_UDP_PORT + 20);

        if (UDPListenPort == -1)
        {
            Debug.Log("Unable to find an open UDP listen port");
            yield break;
        }
        else
        {
            Debug.Log($"UDP listening on port: {UDPListenPort}");
        }

        Debug.Log($"[client] Attempting to connect to server ip: {ipAddr} TCP port: {port} Player Session ID: {tokenUID}");
        _client.Connect(string.IsNullOrEmpty(ipAddr) ? DEFAULT_ENDPOINT : ipAddr, port, UDPListenPort, token);

        while (true)
        {
            if (_client.ConnectedAndReady)
            {
                IsConnectedToServer = true;
                Debug.Log("[client] Connected to server");
                break;
            }
            yield return(null);
        }
    }
Пример #3
0
        static void MaintainConnection()
        {
            bool firstRun = true;

            while (true)
            {
                try
                {
                    if (firstRun)
                    {
                    }
                    else
                    {
                        firstRun = false;
                        Thread.Sleep(5000);
                    }

                    if (config == null)
                    {
                        config               = ClientConfiguration.Default();
                        config.Name          = RandomName();
                        config.ClientGUID    = RandomString(8);
                        config.Email         = config.Name + "@" + config.ClientGUID + ".com";
                        config.ServerGUID    = "00000000-0000-0000-0000-000000000000";
                        config.SyncTimeoutMs = 30000;

                        config.TcpServer        = new ClientConfiguration.TcpServerSettings();
                        config.TcpServer.Debug  = debug;
                        config.TcpServer.Enable = true;
                        config.TcpServer.Ip     = "127.0.0.1";
                        config.TcpServer.Port   = 8000;
                    }

                    if (client == null || !client.Connected || !client.LoggedIn)
                    {
                        if (client != null)
                        {
                            client.Dispose();
                        }

                        client = new Client(config);

                        client.Callbacks.AsyncMessageReceived    = AsyncMessageReceived;
                        client.Callbacks.SyncMessageReceived     = SyncMessageReceived;
                        client.Callbacks.ServerDisconnected      = ServerDisconnected;
                        client.Callbacks.ServerConnected         = ServerConnected;
                        client.Callbacks.ClientJoinedServer      = ClientJoinedServer;
                        client.Callbacks.ClientLeftServer        = ClientLeftServer;
                        client.Callbacks.ClientJoinedChannel     = ClientJoinedChannel;
                        client.Callbacks.ClientLeftChannel       = ClientLeftChannel;
                        client.Callbacks.SubscriberJoinedChannel = SubscriberJoinedChannel;
                        client.Callbacks.SubscriberLeftChannel   = SubscriberLeftChannel;
                        client.Callbacks.ChannelCreated          = ChannelCreated;
                        client.Callbacks.ChannelDestroyed        = ChannelDestroyed;

                        Console.WriteLine("Logging in");
                        Message response;
                        if (!client.Login(out response))
                        {
                            Console.WriteLine("Unable to login, retrying");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    client = null;
                }
            }
        }