Exemple #1
0
        public List<Player> AcceptPlayers(IEnumerable< KeyValuePair<string, string>> credentials)
        {
            var byPassword = credentials.ToDictionary(k => k.Value, k => k.Key);
            var retval = new List<Player>();

            if (log.IsDebugEnabled)
                log.Debug("Waiting for clients " + String.Join(",", byPassword.Values));

            while (byPassword.Count > 0)
            {
                var tcpClient = listener.AcceptTcpClient();
                var client = new Client(tcpClient);
                var password = client.Authenticate();

                string name;

                if (!byPassword.TryGetValue(password, out name))
                {
                    DumpProcessInfo(tcpClient);
                    throw new InvalidOperationException("Invalid password: " + password);
                }

                byPassword.Remove(password);
                retval.Add(new Player(name, client));
            }

            return retval;
        }
Exemple #2
0
        public Player Accept(string name, string password)
        {
            log.Debug("Waiting for client " + name);

            var t = listener.AcceptTcpClientAsync();
            t.Wait(ConnectTimeout);

            log.Info("Client {0} has connected (@{1})", name, t.Result.Client.LocalEndPoint);

            var client = new Client(t.Result);
            client.Authenticate(password);

            var retval = new Player(name, client);

            return retval;
        }