本文整理汇总了Java中net.sf.freecol.server.model.Session类的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于net.sf.freecol.server.model包,在下文中一共展示了Session类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: diplomacy
import net.sf.freecol.server.model.Session; //导入依赖的package包/类
/**
* Diplomacy.
*
* @param serverPlayer The {@code ServerPlayer} that is trading.
* @param ourColony Our {@code Colony}.
* @param otherUnit The other {@code Unit} that is trading.
* @param agreement The {@code DiplomaticTrade} to consider.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet diplomacy(ServerPlayer serverPlayer, Colony ourColony,
Unit otherUnit, DiplomaticTrade agreement) {
ChangeSet cs = new ChangeSet();
DiplomacySession session
= Session.lookup(DiplomacySession.class,
DiplomacySession.makeDiplomacySessionKey(otherUnit, ourColony));
if (session == null) {
return serverPlayer.clientError("Missing cu-diplomacy session for "
+ otherUnit.getId() + "/" + ourColony.getId()
+ " with " + agreement);
} else {
logger.info("Continuing diplomacy session: " + session
+ " from " + ourColony);
}
ServerPlayer otherPlayer = (ServerPlayer)otherUnit.getOwner();
serverPlayer.csDiplomacy(session, agreement, cs);
getGame().sendToOthers(serverPlayer, cs);
return cs;
}
示例2: monarchAction
import net.sf.freecol.server.model.Session; //导入依赖的package包/类
/**
* Respond to a monarch action.
*
* @param serverPlayer The {@code ServerPlayer} that is to respond.
* @param action The {@code MonarchAction} to respond to.
* @param result The player response.
* @return A {@code ChangeSet} containing the response.
*/
public ChangeSet monarchAction(ServerPlayer serverPlayer,
MonarchAction action, boolean result) {
MonarchSession session = Session.lookup(MonarchSession.class,
serverPlayer.getId(), "");
if (session == null) {
return serverPlayer.clientError("Bogus monarch action: " + action);
} else if (action != session.getAction()) {
return serverPlayer.clientError("Session action mismatch, "
+ session.getAction() + " expected: " + action);
}
ChangeSet cs = new ChangeSet();
session.complete(result, cs);
return cs;
}
示例3: FreeColServer
import net.sf.freecol.server.model.Session; //导入依赖的package包/类
/**
* Starts a new networked server, initializing from a saved game.
*
* The specification is usually null, which means it will be
* initialized by extracting it from the saved game. However
* MapConverter does call this with an overriding specification.
*
* @param savegame The file where the game data is located.
* @param specification An optional {@code Specification} to use.
* @param port The TCP port to use for the public socket.
* @param name An optional name for the server.
* @exception IOException If save game can not be found.
* @exception FreeColException If the savegame could not be loaded.
* @exception XMLStreamException If the server comms fail.
*/
public FreeColServer(final FreeColSavegameFile savegame,
Specification specification, int port, String name)
throws FreeColException, IOException, XMLStreamException {
this(name, port);
this.serverGame = loadGame(savegame, specification);
// NationOptions will be read from the saved game.
Session.clearAll();
// Replace the PRNG in the game if it is missing or a command line
// option was present.
long seed = FreeColSeed.getFreeColSeed(this.random == null);
if (seed != FreeColSeed.DEFAULT_SEED) {
this.random = new Random(seed);
}
this.inGameController.setRandom(random);
this.mapGenerator = null;
this.publicServer = registerWithMetaServer();
}
示例4: lootCargo
import net.sf.freecol.server.model.Session; //导入依赖的package包/类
/**
* Loot cargo.
*
* Note loser is passed by identifier, as by the time we get here
* the unit may have been sunk.
*
* @param serverPlayer The {@code ServerPlayer} that owns the winner.
* @param winner The {@code Unit} that looting.
* @param loserId The object identifier of the {@code Unit}
* that is looted.
* @param loot The {@code Goods} to loot.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet lootCargo(ServerPlayer serverPlayer, Unit winner,
String loserId, List<Goods> loot) {
LootSession session = Session.lookup(LootSession.class,
winner.getId(), loserId);
if (session == null) {
return serverPlayer.clientError("Bogus looting!");
}
if (!winner.hasSpaceLeft()) {
return serverPlayer.clientError("No space to loot to: "
+ winner.getId());
}
ChangeSet cs = new ChangeSet();
List<Goods> available = session.getCapture();
if (loot == null) { // Initial inquiry
cs.add(See.only(serverPlayer),
new LootCargoMessage(winner, loserId, available));
} else {
for (Goods g : loot) {
if (!available.contains(g)) {
return serverPlayer.clientError("Invalid loot: " + g);
}
available.remove(g);
if (!winner.canAdd(g)) {
return serverPlayer.clientError("Loot failed: " + g);
}
winner.add(g);
}
// Others can see cargo capacity change.
session.complete(cs);
cs.add(See.perhaps(), winner);
getGame().sendToOthers(serverPlayer, cs);
}
return cs;
}
示例5: deliverGiftToSettlement
import net.sf.freecol.server.model.Session; //导入依赖的package包/类
/**
* Deliver gift to settlement.
* Note that this includes both European and native gifts.
*
* @param serverPlayer The {@code ServerPlayer} that is delivering.
* @param unit The {@code Unit} that is delivering.
* @param settlement The {@code Settlement} to deliver to.
* @param goods The {@code Goods} to deliver.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet deliverGiftToSettlement(ServerPlayer serverPlayer,
Unit unit, Settlement settlement,
Goods goods) {
NativeTradeSession session
= Session.lookup(NativeTradeSession.class, unit, settlement);
if (session == null) {
return serverPlayer.clientError("Trying to deliver gift without opening a session");
}
NativeTrade nt = session.getNativeTrade();
if (!nt.getGift()) {
return serverPlayer.clientError("Trying to deliver gift in a session where gift giving is not allowed: " + unit + " " + settlement + " " + session);
}
ChangeSet cs = new ChangeSet();
Tile tile = settlement.getTile();
GoodsLocation.moveGoods(unit, goods.getType(), goods.getAmount(), settlement);
cs.add(See.perhaps(), unit);
if (settlement instanceof ServerIndianSettlement) {
ServerIndianSettlement sis = (ServerIndianSettlement)settlement;
final int alarmBonus = -Math.round(sis.getPriceToBuy(goods)
* 0.001f * getGame().getSpecification()
.getPercentage(GameOptions.ALARM_BONUS_GIFT));
csVisit(serverPlayer, sis, 0, cs);
sis.csModifyAlarm(serverPlayer, alarmBonus, true, cs);
sis.updateWantedGoods();
tile.updateIndianSettlement(serverPlayer);
cs.add(See.only(serverPlayer), tile);
}
nt.setGift(true);
// Inform the receiver of the gift.
ModelMessage m = new ModelMessage(MessageType.GIFT_GOODS,
"deliverGift.goods",
settlement, goods.getType())
.addStringTemplate("%player%", serverPlayer.getNationLabel())
.addNamed("%type%", goods)
.addAmount("%amount%", goods.getAmount())
.addName("%settlement%", settlement.getName());
cs.addMessage(serverPlayer, m);
ServerPlayer receiver = (ServerPlayer) settlement.getOwner();
if (receiver.isConnected() && settlement instanceof Colony) {
cs.add(See.only(receiver), unit);
cs.add(See.only(receiver), settlement);
cs.addMessage(receiver, m);
}
logger.info("Gift delivered by unit: " + unit.getId()
+ " to settlement: " + settlement.getName());
// Others can see unit capacity, receiver gets it own items.
getGame().sendToOthers(serverPlayer, cs);
return cs;
}