Package userManagement

Examples of userManagement.Friend


      } else if (networkInput.startsWith(NAME_CHANGE_TOKEN)) {

        Iterator<Friend> iterator = super.getCurrentUser().getFriends().iterator();
        while (iterator.hasNext()) {
          Friend friend = iterator.next();

          String newAlias = networkInput.split(" ")[1];

          if (friend.getName().equals(fromName)) {
            Chat.getSingleton().getChatTabbedModel().editChatter(friend, friend.getAlias(), newAlias);
            friend.setAlias(newAlias);
          }
        }

        saveUser();
        fireStateChanged();

      } else if (networkInput.startsWith(FRIEND_REQUEST_TOKEN)) {
        Iterator<Friend> iterator = super.getCurrentUser().getFriends().iterator();
        boolean exists = false;

        String name = networkInput.split(" ")[1];
        String alias = networkInput.split(" ")[2];

        Friend friend = null;

        while (iterator.hasNext() && !exists) {
          friend = iterator.next();

          if (friend.getName().equals(fromName)) {
            exists = true;
          }
        }

        if (!exists) {  // maak vriend aan
          openAddFriendFrame(name, alias, fromIp, port);
        } else {
          NetworkAdapter.getSingleton().sendMessage(FRIEND_ACCEPT_TOKEN + " " + getCurrentUser().getName() + " " + getCurrentUser().getAlias(), fromIp, port);
          friend.setStatus(FriendStatus.IN_GATHERINGLOUNGE);
          Chat.getSingleton().addChatter(GATHERINGLOUNGE_NAME, friend);
          fireStateChanged();
        }

      } else if (networkInput.startsWith("LEFT:")) {

        for (Friend friend : getCurrentUser().getFriends()) {
          if (friend.getName().equals(fromName)) {
            Chat.getSingleton().removeChatter(GATHERINGLOUNGE_NAME, friend);
          }
        }

      } else if (networkInput.startsWith(GameLoungeModel.STATUS_CHANGE_TOKEN)) {

        for (Friend friend : getCurrentUser().getFriends()) {
          if (friend.getName().equals(fromName)) {

            FriendStatus friendStatus = friend.getStatus();

            if (friendStatus == FriendStatus.IN_GATHERINGLOUNGE) {
              Chat.getSingleton().addChatter(GATHERINGLOUNGE_NAME, friend);
            }
          }
        }

      } else if (networkInput.startsWith(FRIEND_ACCEPT_TOKEN)) {

        String name = networkInput.split(" ")[1];
        String alias = networkInput.split(" ")[2];
        String ip = fromIp;

        JOptionPane.showMessageDialog(null,
           name + " (IP: " + ip + ") has accepted your friend request.", "Friend request accepted",
           JOptionPane.INFORMATION_MESSAGE, null);

        try {
          Friend friend = new Friend(name, alias, Inet4Address.getByName(ip));
          Chat.getSingleton().addChatter(GATHERINGLOUNGE_NAME, friend);
          getCurrentUser().getFriends().add(friend);
          saveUser();

          friend.setStatus(FriendStatus.IN_GATHERINGLOUNGE);
          fireStateChanged();

        } catch (UnknownHostException ex) {
          System.out.println("Zou niet mogen gebeuren.");
        }
View Full Code Here


    int confirmed = JOptionPane.showConfirmDialog(null,
       name + " (IP: " + ip + ") tries to add you: accept? ", "Friend request",
       JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null);
    if (confirmed == JOptionPane.YES_OPTION) {
      try {
        Friend friend = new Friend(name, alias, Inet4Address.getByName(ip));

        getCurrentUser().getFriends().add(friend);

        saveUser();

        friend.setStatus(FriendStatus.IN_GATHERINGLOUNGE);

        Chat.getSingleton().addChatter(GATHERINGLOUNGE_NAME, friend);
        fireStateChanged();

        NetworkAdapter.getSingleton().sendMessage(FRIEND_ACCEPT_TOKEN + " " + getCurrentUser().getName() + " " + getCurrentUser().getAlias(), ip, port);
View Full Code Here

    }

  }

  void openEditFriendFrame() {
    Friend friend = (Friend) userList.getSelectedValue();

    editFriendFrame = new JFrame("Edit friend");
    JPanel panel = new EditFriendPanel(friend, this);
    editFriendFrame.setContentPane(panel);
    editFriendFrame.pack();
View Full Code Here

  }

  public void deleteFriend() {
    Object[] selectedFriends = userList.getSelectedValues();
    for (int i = 0; i < selectedFriends.length; i++) {
      Friend friend = (Friend) selectedFriends[i];
      if (friend.getStatus() != FriendStatus.OFFLINE) {
        NetworkAdapter.getSingleton().sendKillCommand(friend.getIp().getHostAddress(), friend.getName());
        NetworkAdapter.getSingleton().closeConnection(friend.getIp().getHostAddress(), friend.getName());
        Chat.getSingleton().removeChatter(GATHERINGLOUNGE_NAME, friend);
      }
      super.getCurrentUser().getFriends().remove(friend);
    }
View Full Code Here

           JOptionPane.INFORMATION_MESSAGE);

        // Sluit de connectie en heropent naar het andere IP-adres
        NetworkAdapter.getSingleton().closeConnection(backupIp, friend.getName());

        final Friend vriend = friend;
        executor.execute(new Runnable() {

          @Override
          public void run() {
            NetworkAdapter.getSingleton().openConnection(friendIp, vriend.getName());
          }
        });


      } catch (UnknownHostException ex) {
View Full Code Here

           friend.getIp().getHostAddress(), friend.getName());
      }
    }

    for (int i = 0; i < selectedFriends.length; i++) {
      Friend friend = (Friend) selectedFriends[i];

      for (int j = 0; j < selectedFriends.length; j++) {

        Friend vriend = (Friend) selectedFriends[j];

        if (friend != vriend) {
          NetworkAdapter.getSingleton().sendMessage(I_HAVE_INVITED_TOKEN + " " + friend.getName() + " " + friend.getAlias() + " " + friend.getIp().getHostAddress() + " " + friend.getStatus().toString(), vriend.getIp().getHostAddress(), vriend.getName());
        }

      }
    }

    for (int i = 0; i < selectedFriends.length; i++) {
      Friend friend = (Friend) selectedFriends[i];

      NetworkAdapter.getSingleton().sendMessage(INVITE_TOKEN + " " + super.getCurrentUser().getName(),
         friend.getIp().getHostAddress(), friend.getName());

      Player player = new Player(friend.getName(), friend.getAlias(), friend.getIp());
      player.setStatus(friend.getStatus());
      invitedPlayerList.add(player);

    }

    openGameLounge(true);
View Full Code Here

  public ChatTabbedPanel getChatPanel() {
    return chatPanel;
  }

  public void requestProfile() {
    Friend friend = (Friend) userList.getSelectedValue();

    if (friend.getStatus() != FriendStatus.OFFLINE) {
      NetworkAdapter.getSingleton().sendMessage(REQUEST_PROFILE_TOKEN, friend.getIp().getHostAddress(), friend.getName());
    }
  }
View Full Code Here

        boolean exists = false;

        Iterator<Player> it = playerList.iterator();
        while (it.hasNext() && !exists) {
          Friend friend = it.next();
          if (friend.getName().equals(fromName)) {
            exists = true;
          }
        }

        if (!exists) {

          Iterator<Player> ite = invitedPlayerList.iterator();
          while (ite.hasNext() && !exists) {

            Player invitedPlayer = ite.next();

            if (invitedPlayer.getName().equals(fromName)) {
              playerList.add(invitedPlayer);
              FriendStatus status = FriendStatus.valueOf(networkInput.split(" ")[2]);
              invitedPlayer.setStatus(status);

              Chat.getSingleton().addChatter(GAMELOUNGE_NAME, invitedPlayer);

              String message = GAME_CHANGED_TOKEN + "@@@";

              message += gameFileName + "@@@";
              message += gameName + "@@@";
              message += gamePlayers + "@@@";
              message += gameTeams + "@@@";
              message += gameDescription;

              NetworkAdapter.getSingleton().sendMessage(message, fromIp, port);

              NetworkAdapter.getSingleton().sendMessage(JOIN_TOKEN + " " + getCurrentUser().getName() + " " + getCurrentUser().getStatus(), fromIp, port);

              fireStateChanged();

              exists = true;
            }

          }

        }

      } else if (networkInput.startsWith(GatheringLoungeModel.I_HAVE_INVITED_TOKEN)) {

        String invitedPlayerName = networkInput.split(" ")[1];
        String invitedPlayerAlias = networkInput.split(" ")[2];
        InetAddress invitedPlayerIp = null;
        try {
          invitedPlayerIp = Inet4Address.getByName(networkInput.split(" ")[3]);
        } catch (UnknownHostException ex) {
          Logger.getLogger(GatheringLoungeModel.class.getName()).log(Level.SEVERE, null, ex);
        }
        int invitedPlayerPort = Integer.parseInt(networkInput.split(" ")[4]);
        FriendStatus invitedPlayerStatus = FriendStatus.valueOf(networkInput.split(" ")[5]);

        Player player = new Player(invitedPlayerName, invitedPlayerAlias, invitedPlayerIp);
        player.setStatus(invitedPlayerStatus);
        invitedPlayerList.add(player);

      } else if (networkInput.startsWith(GAME_STARTED_TOKEN)) {

        if (getCurrentUser().getStatus() == FriendStatus.IN_GAMELOUNGE) {

          leaveGameLounge();

        } else {
          receivingFase = true;

          Chat.getSingleton().addChatMessage(GAMELOUNGE_NAME, "GameInfo", "Teams set. All receive the game!");

          getCurrentUser().setStatus(FriendStatus.IN_GAMELOUNGE);

          for (Friend friend : getCurrentUser().getFriends()) {
            NetworkAdapter.getSingleton().sendMessage(AbstractLoungeModel.STATUS_CHANGE_TOKEN + " " + getCurrentUser().getStatus(),
               friend.getIp().getHostAddress(), friend.getName());
          }

          for (Player player : playerList) {
            if (player.getStatus() != FriendStatus.IS_HOSTING) {
              player.setStatus(FriendStatus.IN_GAMELOUNGE);
            }
          }

          amountReady = 1;

          fireStateChanged();

          requestGame();
        }

      } else if (networkInput.startsWith(KICK_TOKEN)) {

        leaveGameLounge();

      } else if (networkInput.startsWith(STATUS_CHANGE_TOKEN)) {

        String status = networkInput.split(" ")[1];
        FriendStatus newState = FriendStatus.valueOf(status);

        for (Friend friend : playerList) {

          if (friend.getName().equals(fromName)) {

            if (newState == FriendStatus.IN_GAMELOUNGE && !receivingFase) {
              amountReady--;
            } else if (newState == FriendStatus.READY || newState == FriendStatus.IS_HOSTING) {
              amountReady++;
            }

            friend.setStatus(newState);

          }
        }

        fireStateChanged();

        if (amountReady == gamePlayers && receivingFase && isHosting && newState == FriendStatus.READY) {
          for (Player player : playerList) {
            NetworkAdapter.getSingleton().sendMessage(GAME_REALLY_STARTED_TOKEN, player.getIp().getHostAddress(), player.getName());
          }

          startStartTimer();
        }

      } else if (networkInput.startsWith(GAME_REALLY_STARTED_TOKEN)) {

        startStartTimer();

      } else if (networkInput.startsWith(LEAVE_TOKEN)) {

        Iterator<Player> iterator = playerList.iterator();
        while (iterator.hasNext()) {
          Friend friend = iterator.next();
          if (friend.getName().equals(fromName)) {
            if (friend.getStatus() == FriendStatus.READY) {
              amountReady--;
            }
            friend.setStatus(FriendStatus.IN_GATHERINGLOUNGE);

            Chat.getSingleton().removeChatter(GAMELOUNGE_NAME, friend);
            iterator.remove();
          }
        }

        fireStateChanged();

      } else if (networkInput.startsWith("LEFT: ")) {

        Iterator<Player> iterator = playerList.iterator();
        while (iterator.hasNext()) {
          Friend friend = iterator.next();
          if (friend.getName().equals(fromName)) {
            if (friend.getStatus() == FriendStatus.READY) {
              amountReady--;
            }
            friend.setStatus(FriendStatus.OFFLINE);

            Chat.getSingleton().removeChatter(GAMELOUNGE_NAME, friend);
            iterator.remove();
          }
        }

        fireStateChanged();

      } else if (networkInput.startsWith(HOST_TOKEN)) {

        JOptionPane.showMessageDialog(null, "The host has left! You are the host now!",
           "You're hosting!",
           JOptionPane.INFORMATION_MESSAGE);

        if (getCurrentUser().getStatus() == FriendStatus.READY) {
          amountReady--; // Compensering voor de statuschange
        }

        getCurrentUser().setStatus(FriendStatus.IS_HOSTING);

        for (Friend friend : getCurrentUser().getFriends()) {
          NetworkAdapter.getSingleton().sendMessage(STATUS_CHANGE_TOKEN + " " + getCurrentUser().getStatus(),
             friend.getIp().getHostAddress(), friend.getName());
        }

        for (Player player : playerList) {
          NetworkAdapter.getSingleton().sendMessage(STATUS_CHANGE_TOKEN + " " + getCurrentUser().getStatus(),
             player.getIp().getHostAddress(), player.getName());
View Full Code Here

    inviteFrame.dispose();

    for (int i = 0; i < friends.length; i++) {

      Friend friend = (Friend) friends[i];

      for (Player player : invitedPlayerList) {

        if (!player.getName().equals(friend.getName())) {
          NetworkAdapter.getSingleton().sendMessage(GatheringLoungeModel.I_HAVE_INVITED_TOKEN + " " + friend.getName() + " " + friend.getAlias() + " " + friend.getIp().getHostAddress() + " " + friend.getStatus().toString(), player.getIp().getHostAddress(), player.getName());
        }
      }
    }

    for (int i = 0; i < friends.length; i++) {
      Friend friend = (Friend) friends[i];

      for (Player player : invitedPlayerList) {
        NetworkAdapter.getSingleton().sendMessage(GatheringLoungeModel.I_HAVE_INVITED_TOKEN + " " + player.getName() + " " + player.getAlias() + " " + player.getIp().getHostAddress() + " " + player.getStatus().toString(), friend.getIp().getHostAddress(), friend.getName());
      }

      NetworkAdapter.getSingleton().sendMessage(GatheringLoungeModel.INVITE_TOKEN + " " + super.getCurrentUser().getName(),
         friend.getIp().getHostAddress(), friend.getName());

      Player player = new Player(friend.getName(), friend.getAlias(), friend.getIp());
      player.setStatus(friend.getStatus());
      invitedPlayerList.add(player);
    }

  }
View Full Code Here

TOP

Related Classes of userManagement.Friend

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.