Beispiel #1
0
        /// <summary>
        /// This callback method is called when a name has been received from the connected client.
        /// </summary>
        private void NameReceived(string name, Exception e, object payload)
        {
            StringSocket ss = (StringSocket)payload;

            // Check that the received string starts with "PLAY " followed by at least one non-whitespace character.
            if (name.StartsWith("PLAY ") && name.Substring(5).Trim().Length > 0)
            {
                name = name.Substring(5);

                lock (players)
                {
                    // Add the player to the queue.
                    players.Enqueue(new Player(ss, name));

                    // If there are two players in the queue, start a new boggle game and dequeue them.
                    if (players.Count == 2)
                    {
                        BoggleGame game = new BoggleGame(players.Dequeue(), players.Dequeue(), time, letters, ref dictionary);
                    }
                }
            }
            // Otherwise, the client deviated from protocol. Send an IGNORING message.
            else
            {
                ss.BeginSend("IGNORING " + name + "\n", (ee, pp) => { }, ss);
            }
        }
Beispiel #2
0
        /// <summary>
        /// This callback method is called when a name has been received from the connected client.
        /// </summary>
        private void NameReceived(string name, Exception e, object payload)
        {
            StringSocket ss = (StringSocket)payload;
            
            // Check that the received string starts with "PLAY " followed by at least one non-whitespace character.
            if (name.StartsWith("PLAY ") && name.Substring(5).Trim().Length > 0)
            {
                name = name.Substring(5);

                lock (players)
                {
                    // Add the player to the queue.
                    players.Enqueue(new Player(ss, name));

                    // If there are two players in the queue, start a new boggle game and dequeue them.
                    if (players.Count == 2)
                    {
                        BoggleGame game = new BoggleGame(players.Dequeue(), players.Dequeue(), time, letters, ref dictionary);
                    }
                }
            }
            // Otherwise, the client deviated from protocol. Send an IGNORING message.
            else
            {
                ss.BeginSend("IGNORING " + name + "\n", (ee, pp) => { }, ss);
            }
        }