本文整理汇总了Java中com.esotericsoftware.kryonet.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于com.esotericsoftware.kryonet包,在下文中一共展示了Connection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onNewConnection
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
private synchronized void onNewConnection(Connection con) {
Gdx.app.log("Server", "Client connected");
Player p = PlayerUtils.getRandomPlayer(players.values());
players.put(playersJoinedCount, p);
clients.put(playersJoinedCount, new ServerPlayer(p));
connections.put(playersJoinedCount, con);
// Inform the other clients
server.sendToAllExceptTCP(con.getID(), new PlayerJoinedMessage(
playersJoinedCount, players.get(playersJoinedCount)));
// Send the setup response
con.sendTCP(
new GameSetupMessage(players, playersJoinedCount, settings));
playersJoinedCount++;
}
示例2: getRandomGame
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
private GameResponse getRandomGame(Connection connection, Account account) {
Game randomGame = null;
// Go through the games
if (gamesMap != null) {
for (Game game : gamesMap.values()) {
// If there's a game currently waiting for more players, that's the one to return
if (!game.isInProgress() && game.getPlayerCount() < Config.MAX_PLAYERS) {
// Add the player to the game
game.addPlayer(account, connection.getID());
gamesMap.put(account.getUsername(), game);
randomGame = game;
}
}
}
return GameResponse.newInstance(randomGame);
}
示例3: LoginScreen
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
public LoginScreen(CatanGame pGame) {
aGame = pGame;
listener = new Listener() {
@Override
public void received(Connection connection, Object object) {
if (object instanceof LoginResponse) {
Gdx.app.postRunnable(() -> {
// Handle the login response from the server
if (((LoginResponse) object).success) {
// Cache the account used to login successfully
AccountManager.writeLocalAccount(account);
CatanGame.account = account;
// Move on to the main screen
aGame.switchScreen(ScreenKind.MAIN_MENU);
} else {
errorMessageLabel.setText(ERROR_USERNAME);
}
});
}
}
};
}
示例4: handleCreateMotorMessage
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
private void handleCreateMotorMessage(final Connection conn, final CreateMotorMessage msg) {
Thread createMotor = new Thread(){
@Override
public void run(){
LocalEV3.get().getLED().setPattern(9);
if(motorPorts.containsKey(msg.getPort())){
if(createMotorEndpoint( motorPorts.get(msg.getPort()),msg.getMotorType(),msg.getNetworkPort() )){
conn.sendTCP(BrickMessages.createEndpointCreatedMessage(true, msg.getPort(), "Motor endpoint created: "+msg.getPort(), false, true));
}else{
isBlocked = true;
System.out.println("System got blocked by handleCreateMotorMethod");
conn.sendTCP(BrickMessages.createEndpointCreatedMessage(false, msg.getPort(), "Motor endpoint not created: "+msg.getPort(), false, true));
}
}else{
conn.sendTCP(BrickMessages.createEndpointCreatedMessage(false, msg.getPort(), "Port not found!"+msg.getPort(), false, true));
}
}
};
creationThreads.add(createMotor);
//createMotor.start();
}
示例5: received
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void received(Connection connection, Object object){
/** Message if the Endpoint-creation was successful or not **/
System.out.println("Local-EV3MotorManager: received a message!");
if(object.getClass() == BrickMessages.EndpointCreatedMessage.class){
BrickMessages.EndpointCreatedMessage ecmsg = (BrickMessages.EndpointCreatedMessage)object;
System.out.println("Local-EV3MotorManager: Received a EndpointCreatedMessage! -> "+ecmsg.toString());
if(ecmsg.isMotor()){
if(ecmsg.isSuccess()){
System.out.println("Local-EV3MotorManager: isSuccess at port "+ecmsg.getPort()+"#");
if(motors.containsKey(EV3MotorPort.getPort(ecmsg.getPort()))){
System.out.println("Local-EV3MotorManager: Endpoint creation successfull - connect to endpoint!");
endpoints.get(EV3MotorPort.getPort(ecmsg.getPort())).connect();
}else{
System.out.println("Local-EV3MotorManager: Sensor does not exist");
}
}else{
//TODO Tell Sensor/Motor Manager that endpoint creation failed
}
}
}
}
示例6: received
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void received(Connection connection, Object object) {
System.out.println("Local-EV3Display: Received Message "+object.toString());
if(object.getClass() == BrickMessages.EndpointCreatedMessage.class){
BrickMessages.EndpointCreatedMessage msg = (EndpointCreatedMessage) object;
if(!msg.isMotor() && !msg.isSensor()){
if(msg.isSuccess() && msg.getMsg().equals("DISPLAY")){
connect();
System.out.println("EV3-Display: connecting to endpoint!");
}
}
return;
}
if(object.getClass() == DisplayMessages.HelloDisplay.class){
ready = true;
}
}
示例7: show
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void show() {
super.show();
entities = new HashMap<Integer, EntityPacket.EntityRender>();
game.getClient().sendTCP(new ViewShare("696969"));
game.getClient().addListener(new Listener() {
@Override
public void received(Connection connection, Object o) {
if(o instanceof EntityPacket)
Gdx.app.log("Entities", "Session" + ((EntityPacket) o).session);
}
});
}
示例8: addReceiver
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
/**
* Makes this chat client process and respond to audio sent from the server. If this message is not called, you will not hear anything
* from the server!
* @param client The client that audio data will be sent to from the server. Just use the normal client.
*/
public void addReceiver(Client client){
if(this.player == null)
this.createPlayer();
client.addListener(new Listener(){
public void received(Connection connection, Object object) {
// Only read objects of the correct type.
if(object instanceof VoiceNetData){
// Read data
VoiceNetData message = (VoiceNetData)object;
short[] data = message.getData();
// Play audio
processAudio(data, connection, message);
}
}
});
}
示例9: handle
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void handle(Connection connection, RetrieveItemRewardPacket packet)
{
Character character = gameDataRetreiver.getUserCharacterByConnectionId(connection.getID());
CharactersQuests quest = findSuiteQuest(character.getQuests(), packet.getQuestName());
CharactersQuestsItemReward itemReward = findSuiteItemReward(quest.getItemsReward(), packet.getItemIdentifier());
PlayerCharacter player = (PlayerCharacter) gameContainer.getObject(character.getId());
InventoryPosition inventoryPosition = new InventoryPosition(packet.getDesiredInventoryPage(),
packet.getDesiredInventoryX(), packet.getDesiredInventoryY());
Item gameItem;
if (itemReward.getNumberOfItems() == packet.getNumberOfItems())
gameItem = GameItemsFactory.produce(itemReward.getItemIdentifier(), itemReward.getNumberOfItems(),
IdSupplier.getId(), inventoryPosition);
else
throw new NotImplementedException("Not implemented yet");
player.addItemAllowStacking(gameItem);
connection.sendTCP(PacketsMaker.makeItemRewardRemovePacket(packet.getItemIdentifier(),
itemReward.getNumberOfItems()));
connection.sendTCP(PacketsMaker.makeItemPacket(gameItem));
}
示例10: handle
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void handle(Connection connection, RetrieveGoldRewardPacket packet)
{
Character character = gameDataRetriever.getUserCharacterByConnectionId(connection.getID());
CharactersQuests quest = findSuiteQuest(character.getQuests(), packet.getQuestName());
int goldReward = quest.getGoldReward();
if (goldReward > 0)
{
quest.setGoldReward(0);
character.setGold(character.getGold() + goldReward);
packetsSender.sendTo(connection.getID(), PacketsMaker.makeGoldReceivePacket(goldReward));
packetsSender.sendTo(connection.getID(),
PacketsMaker.makeQuestRewardGoldRemovalPacket(goldReward));
} else
packetsSender.sendTo(connection.getID(),
PacketsMaker.makeUnacceptableOperationPacket("There is no gold left!"));
}
示例11: clientBoardClickProperHandle
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
private void clientBoardClickProperHandle(Connection connection, GameObject target, PlayerCharacter source)
{
// TODO: refactor, implement collicion detection on clent side, so he
// can tell what he wants to do directly
if (target instanceof ShopNpc)
sendShopItemsInfo(connection, (ShopNpc) target);
else if (target instanceof QuestDialogNpc)
propagateQuestDialogEvent((QuestDialogNpc) target, source);
else if (target instanceof Monster)
tryToTargetMonster(connection, (Monster) target, source);
else if (target instanceof QuestBoard)
sendQuestBoardInfo(connection, (QuestBoard) target);
else if (target.getClass().getSimpleName().contains("NullGameObject"))
;//ignore
else
throw new NotImplementedException("Not implemented");
}
示例12: handle
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void handle(Connection connection, ItemUsagePacket packet)
{
int characterId = gameData.getCharacterIdByConnectionId(connection.getID());
PlayerCharacter itemUser = (PlayerCharacter)playState.getObject(characterId);
if(itemUser == null)
throw new PlayerUsingItemNotFoundException();
Monster target = (Monster)playState.getObject(packet.getTargetId());
try
{
itemUser.useItem(packet.getItemId(), target, (PacketsSender)playState);
connection.sendTCP(packet);
}
catch(OutOfStockException e)
{
connection.sendTCP(PacketsMaker.makeUnacceptableOperationPacket("Your item stack was depleted"));
}
}
示例13: handle
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void handle(Connection connection, TakingGoldFromContainerPacket packet)
{
long characterId = gameData.getCharacterIdByConnectionId(connection.getID());
PlayerCharacter player = (PlayerCharacter)playState.getObject(characterId);
GameContainer container = playState.getContainer(packet.getContainerId());
int gold = container.getGoldAmount();
if(gold > 0)
{
connection.sendTCP(PacketsMaker.makeGoldReceivePacket(gold));
server.sendToAllTCP(PacketsMaker.makeContainerGoldRemovalPacket(packet.getContainerId(), gold));
container.setGoldAmount(0);
player.addGold(gold);
}
else
connection.sendTCP(PacketsMaker.makeUnacceptableOperationPacket("There is no gold left in this container"));
}
示例14: handle
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void handle(Connection connection, ScriptCodePacket packet)
{
User user = authenticatedClientsKeyClientId.get(connection.getID());
if(!user.getRole().equals(UserRole.ADMIN))
{
connection.sendTCP(PacketsMaker.makeScriptExecutionErrorPacket("You must be admin to do that"));
return;
}
try
{
Object result = playState.executeCode(packet.getCode(), user.getId());
if(result != null)
connection.sendTCP(PacketsMaker.makeScriptResultInfoPacket(result.toString()));
}catch(ScriptException e)
{
connection.sendTCP(PacketsMaker.makeScriptExecutionErrorPacket(e.getMessage()));
}
}
示例15: handle
import com.esotericsoftware.kryonet.Connection; //导入依赖的package包/类
@Override
public void handle(Connection connection, ChatMessagePacket packet)
{
Field connectionsField = FieldUtils.getField(Server.class, "connections", true);
Connection[] connections;
try
{
connections = (Connection[])FieldUtils.readField(connectionsField, server, true);
} catch (IllegalAccessException e)
{
throw new RuntimeException(e);
}
ChatMessageReplyPacket newPacket = new ChatMessageReplyPacket();
Character sender = gameData.getUserCharacterByConnectionId(connection.getID());
String nickname = sender.getNickname();
newPacket.setMessage(packet.getMessage());
newPacket.setNickname(nickname);
Character character;
for(Connection client : connections)
if((character = gameData.getUserCharacterByConnectionId(client.getID())) != null)
{
newPacket.setSourceCharacterId(character.getId());
server.sendToTCP(client.getID(), newPacket);
}
}