protected override void OnConnected(Client client) { //var comm = new GameDriver(new InteractivePlayer(Name), client); //var replay = new Queue<string>(File.ReadAllLines(FileName)); //while (true) //{ // var line = client.ReadLine(); // var handled = false; // if (line.StartsWith("?") && replay.Count > 0) // { // var answer = replay.Dequeue(); // if (!String.IsNullOrEmpty(answer)) // { // ConsoleHelper.NotImportant("AUTO: {0} -> {1}".F(line, answer)); // client.Send(answer); // handled = true; // } // } // if (!handled) // if (!comm.Dispatch(line)) // break; //} }
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; }
public Player(string name, Client client) { Name = name; Client = client; Client.Name = name; log = NLog.LogManager.GetLogger("P: " + Name); }
public void Execute() { InitializeParams(); var tcp = new TcpClient(); tcp.Connect(Address); Console.WriteLine("Connecting as " + Name); using (var stream = tcp.GetStream()) { var client = new Client(stream); client.Send("AUTH " + Password); OnConnected(client); } }
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; }
protected abstract void OnConnected(Client client);