本文整理汇总了Java中net.sf.freecol.common.model.Game.LogoutReason类的典型用法代码示例。如果您正苦于以下问题:Java LogoutReason类的具体用法?Java LogoutReason怎么用?Java LogoutReason使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogoutReason类属于net.sf.freecol.common.model.Game包,在下文中一共展示了LogoutReason类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestLogout
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Request that this client log out from the server.
*
* @param reason The reason to logout from the server.
* @return True if the player is already logged out,
* or a logout request was sent.
*/
public boolean requestLogout(LogoutReason reason) {
final FreeColClient fcc = getFreeColClient();
final Player player = fcc.getMyPlayer();
if (!fcc.isLoggedIn()) return true;
// Save our active unit on reconnect.
if (reason == LogoutReason.RECONNECT) {
Unit active = getGUI().getActiveUnit();
if (active != null && player.owns(active)) {
FreeColServer fcs = fcc.getFreeColServer();
if (fcs != null) {
fcs.getGame().setInitialActiveUnitId(active.getId());
}
}
}
logger.info("Logout begin for client " + player.getName()
+ ": " + reason.toString());
return askServer().logout(player, reason);
}
示例2: startSinglePlayerGame
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Starts a new single player game by connecting to the server.
*
* FIXME: connect client/server directly (not using network-classes)
*
* @param spec The {@code Specification} for the game.
* @return True if the game starts successfully.
*/
public boolean startSinglePlayerGame(Specification spec) {
final FreeColClient fcc = getFreeColClient();
fcc.setMapEditor(false);
if (!fcc.unblockServer(FreeCol.getServerPort())) return false;
if (fcc.isLoggedIn()) { // Should not happen, warn and suppress
logger.warning("startSinglePlayer while logged in!");
requestLogout(LogoutReason.LOGIN);
}
// Load the player mods into the specification that is about to be
// used to initialize the server.
//
// ATM we only allow mods in single player games.
// FIXME: allow in stand alone server starts?
List<FreeColModFile> mods = getClientOptions().getActiveMods();
spec.loadMods(mods);
Messages.loadActiveModMessageBundle(mods, FreeCol.getLocale());
FreeColServer fcs = fcc.startServer(false, true, spec, -1);
return (fcs == null) ? false
: requestLogin(FreeCol.getName(),
fcs.getHost(), fcs.getPort());
}
示例3: startMultiplayerGame
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Starts a multiplayer server and connects to it.
*
* @param specification The {@code Specification} for the game.
* @param publicServer Whether to make the server public.
* @param port The port in which the server should listen for new clients.
* @return True if the game is started successfully.
*/
public boolean startMultiplayerGame(Specification specification,
boolean publicServer, int port) {
final FreeColClient fcc = getFreeColClient();
fcc.setMapEditor(false);
if (!fcc.unblockServer(port)) return false;
if (fcc.isLoggedIn()) { // Should not happen, warn and suppress
logger.warning("startMultiPlayer while logged in!");
requestLogout(LogoutReason.LOGIN);
}
FreeColServer fcs = fcc.startServer(publicServer, false,
specification, port);
if (fcs == null) return false;
fcc.setFreeColServer(fcs);
fcc.setSinglePlayer(false);
return requestLogin(FreeCol.getName(), fcs.getHost(), fcs.getPort());
}
示例4: mainTitle
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Reset to the MainPanel.
*
* Called from ShowMainAction.
*/
public void mainTitle() {
final FreeColClient fcc = getFreeColClient();
if (fcc.isMapEditor()) fcc.setMapEditor(false);
if (fcc.isLoggedIn()) {
if (getGUI().confirmStopGame()) {
requestLogout(LogoutReason.MAIN_TITLE);
}
return;
}
fcc.stopServer();
getGUI().removeInGameComponents();
getGUI().mainTitle();
}
示例5: newGame
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Reset to the NewPanel (except in the map editor).
*/
public void newGame() {
final FreeColClient fcc = getFreeColClient();
if (fcc.isMapEditor()) {
fcc.getMapEditorController().newMap();
return;
}
if (fcc.isLoggedIn()) {
if (getGUI().confirmStopGame()) {
requestLogout(LogoutReason.NEW_GAME);
}
return;
}
fcc.stopServer();
getGUI().removeInGameComponents();
getGUI().showNewPanel(null);
}
示例6: setDead
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* This player has died.
*/
public void setDead() {
final FreeColClient fcc = getFreeColClient();
final Player player = getMyPlayer();
FreeColDebugger.finishDebugRun(fcc, true);
if (fcc.getSinglePlayer()) {
if (player.getPlayerType() == Player.PlayerType.RETIRED) {
; // Do nothing, retire routine will quit
} else if (player.getPlayerType() != Player.PlayerType.UNDEAD) {
if (getGUI().confirm("defeatedSinglePlayer.text",
"defeatedSinglePlayer.yes", "quit")) {
askServer().enterRevengeMode();
}
} else {
fcc.getConnectController()
.requestLogout(LogoutReason.DEFEATED);
}
} else {
if (!getGUI().confirm("defeated.text", "defeated.yes", "quit")) {
fcc.getConnectController()
.requestLogout(LogoutReason.DEFEATED);
}
}
}
示例7: clientHandler
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void clientHandler(FreeColClient freeColClient) {
final Game game = freeColClient.getGame();
final Player player = getPlayer(game);
final LogoutReason reason = getReason();
if (player == null) return;
if (freeColClient.isInGame()) {
igc(freeColClient).logoutHandler(player, reason);
} else {
pgc(freeColClient).logoutHandler(player, reason);
}
}
示例8: logoutHandler
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Log out the current player.
*
* @param player The {@code Player} that is logging out.
* @param reason The reason for logging out.
*/
public void logoutHandler(Player player, LogoutReason reason) {
if (player == null) return;
final Game game = getGame();
if (game.getCurrentPlayer() == player) {
game.setCurrentPlayer(game.getNextPlayer());
}
if (getMyPlayer() == player) {
getFreeColClient().getConnectController().logout(reason);
}
}
示例9: reconnect
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Query whether the user wants to reconnect?
*
* Called from ReconnectAction.
*
* Returns no status, this game is going away.
*/
public void reconnect() {
final FreeColClient fcc = getFreeColClient();
final Player player = getMyPlayer();
if (getGUI().confirm("reconnect.text", "reconnect.no", "reconnect.yes")) {
logger.finest("Reconnect quit.");
fcc.getConnectController().requestLogout(LogoutReason.QUIT);
} else {
logger.finest("Reconnect accepted.");
fcc.getConnectController().requestLogout(LogoutReason.RECONNECT);
}
}
示例10: logoutHandler
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Handle a player logging out.
*
* @param player The {@code Player} that is logging out.
* @param reason The {@code LogoutReason} why the player left.
*/
public void logoutHandler(Player player, LogoutReason reason) {
final FreeColClient freeColClient = getFreeColClient();
getGame().removePlayer(player);
getGUI().refreshPlayersTable();
if (player == getMyPlayer()) {
freeColClient.getConnectController().logout(reason);
}
}
示例11: askToQuit
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Quits the application.
*/
public void askToQuit() {
if (gui.confirm("quitDialog.areYouSure.text", "ok", "cancel")) {
Player player = getMyPlayer();
if (player == null) { // If no player, must be already logged out
quit();
} else {
getConnectController().requestLogout(LogoutReason.QUIT);
}
}
}
示例12: endGame
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* The game is ending, tell all the non-admin players to quit.
*/
public void endGame() {
changeServerState(ServerState.END_GAME);
ChangeSet cs = new ChangeSet();
for (Player p : getGame().getLiveEuropeanPlayerList()) {
ServerPlayer sp = (ServerPlayer)p;
if (sp.isAdmin()) continue;
sp.send(new ChangeSet()
.add(See.only(sp),
new LogoutMessage(sp, LogoutReason.QUIT)));
}
}
示例13: logout
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Complete log out of this client from the server.
*
* @param reason The reason to logout from the server.
* @return True if the logout completes.
*/
public boolean logout(LogoutReason reason) {
final FreeColClient fcc = getFreeColClient();
final Player player = fcc.getMyPlayer();
logger.info("Logout end for client " + player.getName()
+ ": " + reason.toString());
askServer().disconnect();
switch (reason) {
case DEFEATED: case QUIT:
fcc.logout(false);
fcc.quit();
break;
case LOGIN: // FIXME: This should not happen, drop when convinced
FreeCol.trace(logger, "logout(LOGIN) detected");
fcc.logout(false);
break;
case MAIN_TITLE: // All the way back to the MainPanel
fcc.logout(false);
mainTitle();
break;
case NEW_GAME: // Back to the NewPanel
fcc.logout(false);
newGame();
break;
case RECONNECT:
fcc.logout(false);
final String name = player.getName();
try {
if (askServer().reconnect() != null
&& askServer().login(name, FreeCol.getVersion(),
fcc.getSinglePlayer(),
fcc.currentPlayerIsMyPlayer())) {
logger.info("Reconnected for client " + name);
} else {
logger.severe("Reconnect failed for client " + name);
fcc.askToQuit();
}
} catch (IOException ioe) {
logger.log(Level.SEVERE, "Reconnect exception for client "
+ name, ioe);
fcc.quit();
}
break;
}
return true;
}
示例14: joinMultiplayerGame
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* Join an existing multiplayer game.
*
* @param host The name of the machine running the server.
* @param port The port to use when connecting to the host.
* @return True if the game starts successfully.
*/
public boolean joinMultiplayerGame(String host, int port) {
final FreeColClient fcc = getFreeColClient();
fcc.setMapEditor(false);
if (fcc.isLoggedIn()) { // Should not happen, warn and suppress
logger.warning("joinMultiPlayer while logged in!");
requestLogout(LogoutReason.LOGIN);
}
// Connect and disconnect, allow GameState message to arrive
String name = FreeCol.getName();
StringTemplate err = connect(name, host, port);
if (err != null) {
getGUI().showErrorMessage(err);
return false;
}
while (fcc.getServerState() == null) Utils.delay(1000, null);
askServer().disconnect();
switch (fcc.getServerState()) {
case PRE_GAME: case LOAD_GAME:
// Name is good
break;
case IN_GAME:
/*
// Disable this check if you need to debug a multiplayer client.
if (FreeColDebugger.isInDebugMode(FreeColDebugger.DebugMode.MENUS)) {
getGUI().showErrorMessage(StringTemplate
.template("client.debugConnect"));
return false;
}
*/
// Find the players, choose one.
List<String> names = fcc.getVacantPlayerNames();
if (names.isEmpty()) return false;
if (names.contains(name)) break; // Already there, use it
String choice = getGUI().getChoice(null,
Messages.message("client.choicePlayer"), "cancel",
transform(names, alwaysTrue(), n ->
new ChoiceItem<>(Messages.message(StringTemplate
.template("countryName")
.add("%nation%", Messages.nameKey(n))), n)));
if (choice == null) return false; // User cancelled
name = Messages.getRulerName(choice);
break;
case END_GAME: default:
getGUI().showErrorMessage(StringTemplate.template("client.ending"));
return false;
}
return requestLogin(name, host, port);
}
示例15: doEndTurn
import net.sf.freecol.common.model.Game.LogoutReason; //导入依赖的package包/类
/**
* End the turn.
*
* @param showDialog Show the end turn dialog?
* @return True if the turn ended.
*/
private boolean doEndTurn(boolean showDialog) {
final Player player = getMyPlayer();
if (showDialog) {
List<Unit> units = transform(player.getUnits(), Unit::couldMove);
if (!units.isEmpty()) {
// Modal dialog takes over
getGUI().showEndTurnDialog(units,
(Boolean value) -> {
if (value != null && value) {
endTurn(false);
}
});
return false;
}
}
// Ensure end-turn mode sticks.
moveMode = moveMode.maximize(MoveMode.END_TURN);
// Make sure all goto orders are complete before ending turn, and
// that nothing (like a LCR exploration) has cancelled the end turn.
if (!doExecuteGotoOrders()
|| moveMode.ordinal() < MoveMode.END_TURN.ordinal()) return false;
// Check for desync as last thing!
if (FreeColDebugger.isInDebugMode(FreeColDebugger.DebugMode.DESYNC)
&& DebugUtils.checkDesyncAction(getFreeColClient())) {
logger.warning("Reconnecting on desync");
getFreeColClient().getConnectController()
.requestLogout(LogoutReason.RECONNECT);
return false;
}
// Clean up lingering menus.
getGUI().closeMenus();
// Clear active unit if any.
getGUI().setActiveUnit(null);
// Restart the selection cycle.
moveMode = MoveMode.NEXT_ACTIVE_UNIT;
// Clear outdated turn report messages.
turnReportMessages.clear();
// Inform the server of end of turn.
return askServer().endTurn();
}