コード例 #1
0
ファイル: ServerArchitecture.java プロジェクト: Auzzy/school
  /**
   * Launch server app.
   *
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    // Determine the XML schema we are going to use
    if (!Configure.configure()) {
      System.err.println("Unable to configure Message XML");
      return;
    }
    // MockDatabaseManager.replaceDatabaseManager();
    MockDatabaseManager.revertDatabaseManager();
    // the authorization object. This is where login-handling code lives.
    // pretty much all of these are more or less wrapper functions for other
    // code, usually DatabaseManager code.
    IAuthorization auth =
        new IAuthorization() {
          int ctr = 1000000;

          // try logging in this player
          public boolean authorize(String who, String pwd) {
            return DatabaseManager.getInstance().loginPlayer(who, pwd);
          }

          // (not-so) random accounts
          public String selfRegister(String pwd) {
            DatabaseManager.getInstance().registerPlayer(pwd);
            ctr = DatabaseManager.getInstance().findMaxPlayerId();
            return "" + ctr;
          }

          // a player's logging in, but everything important is handled elsewhere
          public void login(Communicator com, Message m) {
            System.out.println(m.getOriginator() + " has logged in");
          }

          // a player's logging out; tell our managers about it
          public void logout(Communicator com, Message m) {
            DBPlayer p = DatabaseManager.getInstance().getPlayer(m.getOriginator());
            DatabaseManager.getInstance().logoutPlayer(m);
            TableManager.getInstance().PlayerIsLoggingOff(p);

            new TablesController().process(com, m); // broadcast the (updated) table list
            new PlayersController().process(com, m); // broadcast the (updated) player list
            System.out.println(m.getOriginator() + " has logged out");
          }
        };

    srv = new Server(auth);

    // here is where you can augment the chain of server-side controllers
    ServerControllerChain head = ServerProcessor.head();

    head.append(new SampleServerExtension());
    head.append(new ServerExtension());
    head.append(new DefaultServerChain());

    srv.activate();
  }
コード例 #2
0
ファイル: TestDatabaseManager.java プロジェクト: Auzzy/school
  protected void setUp() throws Exception {
    super.setUp();
    // we test the database manager on live! We're testing against a real database! Scary!
    MockDatabaseManager.revertDatabaseManager();
    // MockDatabaseManager.replaceDatabaseManager();
    currHighest = DatabaseManager.getInstance().findMaxPlayerId();
    DBPlayer temp = DatabaseManager.getInstance().getPlayer(currHighest + "");

    // some convoluted logic so we don't spam that many people into the db
    if (temp != null
        && (temp.getPassword().equalsIgnoreCase("hello")
            || temp.getPassword().equalsIgnoreCase("goodbye")
            || temp.getName().equalsIgnoreCase("test"))) playerId = currHighest;
    else playerId = currHighest + 1;

    DatabaseManager.getInstance().registerPlayer("hello");
    try {
      Message.unconfigure();
      assertTrue(Configure.configure());
    } catch (Exception e) {
      fail("Unable to setup Message tests.");
    }
  }