Beispiel #1
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;
  }
Beispiel #2
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());
     }
   }
 }