Esempio n. 1
0
        /// <summary>
        /// Goes through ready players, async send them dynamic data and then returns their IDs.
        /// Ready client means that they received static data and requested sending dynamicData.
        /// </summary>
        /// <returns>Commands representing newly connected players.</returns>
        public IEnumerable <int> ProcessReadyClients(ConnectingDynamicData dynamicData)
        {
            //Claim the queue
            var queue = readyClients;

            readyClients = ImmutableList <ReadyClient> .Empty;

            var dynDataBytes = ConnectingDynamicData.Encode(dynamicData);

            foreach (var c in queue)
            {
                ProcessReadyClient(c, dynDataBytes).Detach();
            }
            return(from c in queue select c.playerID);
        }
Esempio n. 2
0
        /// <summary>
        /// Begins to receive dynamic data from the server.
        /// </summary>
        /// <returns></returns>
        async Task <ConnectingDynamicData> ReceiveDynamicDataAsync()
        {
            if (StaticData == null)
            {
                throw new InvalidOperationException("Cannot start receiving dynamic data before receiving the static data.");
            }
            await StaticData;

            //Confirm that static part received and started listening for commands.
            await Communication.TCPSendACKAsync(serverConnection);

            Console.WriteLine("Sent server ACK.");
            var dynData = ConnectingDynamicData.Decode(await Communication.TCPReceiveMessageAsync(serverConnection));

            Console.WriteLine("Received dynamic data.");
            serverConnection.Shutdown(SocketShutdown.Send);
            Console.WriteLine("Successfully connected to the server.");
            serverConnection.Close();
            serverConnection = null;
            return(dynData);
        }