Ejemplo n.º 1
0
        public void ListenerLoop()
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Bind(new IPEndPoint(IPAddress.Any, 12345));
            socket.Listen(4);

            while (true) {
                // Blocks until an incoming connection connects
                Socket transmitterSocket = socket.Accept();

                // Create new transmitter and assign socket
                Reader reader = new Reader(transmitterSocket, interpreter);
                reader.Start();
            }
        }
Ejemplo n.º 2
0
        public int JoinGame(Reader reader, string nick)
        {
            lock (theInterpreter) {
                // Save for later use
                //readers.Add(reader);
                //nicks.Add(nick);
                //ready.Add(false);

                players.Add(new Player(reader, nick));

                // New player's ID
                int n = players.Count - 1;

                players[n].Write((int)Command.JoinGameSuccess);
                players[n].Write(players.Count);

                // Sucess
                //reader.W.Write((int)Command.JoinGameSuccess);
                // Send player count to new player
                //reader.W.Write(readers.Count);

                for (int i = 0; i < players.Count; i++) {
                    // Send the new player all nicks (including their own)
                    //reader.W.Write(nicks[i]);

                    players[n].Write(players[i].Nick);
                    players[n].Write(players[i].IsReady);

                    if (players[n] != players[i]) {
                        players[i].Write((int)Command.PlayerJoin);
                        players[i].Write(players[n].Nick);
                    }

                    // And to all other players, skipping the new player...
                    //if (readers[i] != reader) {
                        // Tell them who the new player is
                        //readers[i].W.Write((int)Command.PlayerJoin);
                        //readers[i].W.Write(nick);
                    //}
                }

                return (players.Count - 1); // ID (index)
            }
        }
Ejemplo n.º 3
0
 public Player(Reader reader, string nick)
 {
     this.reader = reader;
     this.nick = nick;
 }