Example #1
0
 /**
  * Provede odhlaseni uzivatele Odesle informaci o odhlaseni ostatnim uzivatelum
  *
  * @param serverThread Vlakno serveru
  */
 public synchronized void logout(ServerThread serverThread) {
   if (serverThread.getLogin() != null) {
     clients.remove(serverThread.getLogin().toLowerCase());
     Enumeration<ServerThread> e = getClients().elements();
     while (e.hasMoreElements()) {
       e.nextElement().userLogout(serverThread.getLogin());
     }
   }
 }
Example #2
0
 /**
  * Odesle informaci ostatnim hracum, ze je tento hrac uz neni ve hre
  *
  * @param login Login hrace
  */
 public synchronized void userOutGame(String login) {
   Enumeration<ServerThread> e = getClients().elements();
   while (e.hasMoreElements()) {
     ServerThread serverThread = e.nextElement();
     if (!serverThread.getLogin().toLowerCase().equals(login.toLowerCase())) {
       serverThread.userOutGame(login);
     }
   }
 }
Example #3
0
  /**
   * Provede prihlaseni uzivatele Odesle mu seznam aktualnich uzivatelu a r ozesle informaci o
   * prihlaseni ostatnim uzivatelum
   *
   * @param serverThread Vlakno serveru
   */
  public synchronized boolean login(ServerThread serverThread) {
    if (clients.containsKey(serverThread.getLogin().toLowerCase())) {
      return false;
    }

    // Send login info to other clients
    Enumeration<ServerThread> e = getClients().elements();
    while (e.hasMoreElements()) {
      e.nextElement().userLogin(serverThread.getLogin());
    }

    // Send users list to client
    Enumeration<ServerThread> e2 = getClients().elements();
    while (e2.hasMoreElements()) {
      ServerThread serverThread2 = e2.nextElement();
      serverThread.userLogin(serverThread2.getLogin());
      if (serverThread2.getServerGame() != null) {
        serverThread.userInGame(serverThread2.getLogin());
      }
    }

    // Append client to list
    clients.put(serverThread.getLogin().toLowerCase(), serverThread);

    return true;
  }