PageRenderTime 790ms CodeModel.GetById 235ms RepoModel.GetById 1ms app.codeStats 0ms

/.metadata/.plugins/org.eclipse.core.resources/.history/4b/f0368dc980a3001e1dff9ae635b3e1ee

https://bitbucket.org/fixpoint/connexion
#! | 67 lines | 56 code | 11 blank | 0 comment | 0 complexity | b0d0ce463f9708e19a7ad4592793677a MD5 | raw file
  1. package info.reflectionsofmind.connexion.platform.cli;
  2. import info.reflectionsofmind.connexion.platform.control.IRoot;
  3. import info.reflectionsofmind.connexion.platform.control.ServerInfo;
  4. import info.reflectionsofmind.connexion.platform.control.control.IConnectControl;
  5. import info.reflectionsofmind.connexion.platform.control.control.IJoinControl;
  6. import info.reflectionsofmind.connexion.platform.game.IGame;
  7. import info.reflectionsofmind.connexion.transport.AbstractTransport;
  8. import info.reflectionsofmind.connexion.transport.ITransport;
  9. import info.reflectionsofmind.connexion.transport.ITransport.INode;
  10. import java.util.concurrent.Future;
  11. public class ConnectInterpreter implements IConnectControl, IInterpreter
  12. {
  13. private final IGame game;
  14. private final IRoot root;
  15. public ConnectInterpreter(final IRoot root, final IGame game)
  16. {
  17. this.game = game;
  18. this.root = root;
  19. }
  20. public Future<IJoinControl> connect(final String name, final INode server)
  21. {
  22. return null;
  23. }
  24. public IGame getGame()
  25. {
  26. return this.game;
  27. }
  28. public IRoot getRoot()
  29. {
  30. return this.root;
  31. }
  32. public void interpret(final String command)
  33. {
  34. if (command.equals("connect"))
  35. {
  36. final ServerInfo info = this.root.getConfiguration().getServers().get(0);
  37. final ITransport transport = info.getFactory().createTransport(info.getParameters());
  38. final ITransport.IListener listener = new AbstractTransport.Listener()
  39. {
  40. @Override
  41. public void onTrace(final ITransport transport, final String trace)
  42. {
  43. System.out.println(trace);
  44. }
  45. };
  46. transport.addListener(listener);
  47. transport.start();
  48. transport.removeListener(listener);
  49. connect("Player", transport.createNode(info.getAddress()));
  50. }
  51. else if ("exit".equals(command))
  52. {
  53. getRoot().restart();
  54. }
  55. }
  56. }