Package voxo.server.actions

Source Code of voxo.server.actions.UserLogoutAction

package voxo.server.actions;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.SQLException;
import java.util.ArrayList;

import voxo.common.entities.Packet;
import voxo.common.entities.User;
import voxo.common.enums.EnumPacket;
import voxo.server.Messages;
import voxo.server.exceptions.RequestException;
import voxo.server.managers.UserManager;
import voxo.server.services.NetworkService;

public class UserLogoutAction {
  public UserLogoutAction(String ip, String username) throws UnknownHostException, IOException, SQLException, RequestException {
    // Check Login
    ArrayList<User> alu = UserManager.searchUserAbsolute(new User(null, username, null, null, null, null, null));

    // Not found / logged
    if (alu.size() == 0) {
      throw new RequestException(Messages.getString("UserLogoutAction.ERR_UserNotFound")); //$NON-NLS-1$
    }

    // Set offline
    User u = alu.get(0);
    u.setOnline(false);
    u.setIp(""); //$NON-NLS-1$
    UserManager.updateUserById(u);

    // Update contact list to his online members
    ArrayList<User> alcu = UserManager.getUserContactsByUser(u);
    for (User iU : alcu) {
      if (iU.getOnline() && (iU.getIp() != null)) {
        new SendContactListAction(iU);
        NetworkService.sendPacket(iU.getIp(), new Packet(EnumPacket.SERVER_Notice, String.format(Messages.getString("UserLogoutAction.UserDisconnect"), u.getUsername()))); //$NON-NLS-1$
      }
    }
  }
}
TOP

Related Classes of voxo.server.actions.UserLogoutAction

TOP
Copyright © 2018 www.massapi.com. 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.