本文整理汇总了Java中com.jme3.network.HostedConnection类的典型用法代码示例。如果您正苦于以下问题:Java HostedConnection类的具体用法?Java HostedConnection怎么用?Java HostedConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostedConnection类属于com.jme3.network包,在下文中一共展示了HostedConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: messageReceived
import com.jme3.network.HostedConnection; //导入依赖的package包/类
public void messageReceived(HostedConnection source, Message m) {
if (m instanceof ChatMessage) {
// Keep track of the name just in case we
// want to know it for some other reason later and it's
// a good example of session data
source.setAttribute("name", ((ChatMessage) m).getName());
System.out.println("Broadcasting:" + m + " reliable:" + m.isReliable());
// Just rebroadcast... the reliable flag will stay the
// same so if it came in on UDP it will go out on that too
source.getServer().broadcast(m);
} else {
System.err.println("Received odd message:" + m);
}
}
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:TestChatServer.java
示例2: messageReceived
import com.jme3.network.HostedConnection; //导入依赖的package包/类
public void messageReceived(HostedConnection source, Message m) {
TestSerializationMessage cm = (TestSerializationMessage) m;
System.out.println(cm.z);
System.out.println(cm.b);
System.out.println(cm.c);
System.out.println(cm.s);
System.out.println(cm.i);
System.out.println(cm.f);
System.out.println(cm.l);
System.out.println(cm.d);
System.out.println(Arrays.toString(cm.ia));
System.out.println(cm.ls);
System.out.println(cm.mp);
System.out.println(cm.status1);
System.out.println(cm.status2);
System.out.println(cm.date);
}
开发者ID:mleoking,项目名称:PhET,代码行数:18,代码来源:TestSerialization.java
示例3: onConnection
import com.jme3.network.HostedConnection; //导入依赖的package包/类
private void onConnection(HostedConnection conn) {
if (localObjects.size() > 0){
// send a object definition message
ObjectDef[] defs = new ObjectDef[localObjects.size()];
int i = 0;
for (Entry<LocalObject> entry : localObjects){
defs[i] = makeObjectDef(entry.getValue());
i++;
}
RemoteObjectDefMessage defMsg = new RemoteObjectDefMessage();
defMsg.objects = defs;
if (this.client != null){
this.client.send(defMsg);
logger.log(Level.INFO, "Client: Sending {0}", defMsg);
} else{
conn.send(defMsg);
logger.log(Level.INFO, "Server: Sending {0}", defMsg);
}
}
}
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:ObjectStore.java
示例4: onSendGameData
import com.jme3.network.HostedConnection; //导入依赖的package包/类
/**
* 服务端向客户端发送游戏数据,当服务端接收到客户端连接或者客户端向服务端请求游戏数据时,
* 该方法会被自动调用,主要实现向客户端发送当前的游戏数据GameData。<br>
* 注:默认情况下,服务端只向客户端发送游戏基本数据,不发送场景实体数据,也不发送游戏逻辑。
* 因为客户端不应该执行来自服务端的游戏逻辑,另一个,游戏场景实体数据的不确定性,当场景实体非常多时,
* 如果一次性发送可能导致问题,因此这些数据应该在客户端和服务端连接和初始化完成后再从服务端获取。
* @param gameServer
* @param coon
*/
protected void onSendGameData(GameServer gameServer, HostedConnection coon) {
// 注1:这里向客户端发送的并不包含游戏逻辑数据及场景实体数据,
// 这些数据是在客户端状态初始化后再从服务端获取并载入,当服务端和客户端状态就绪之后,服务端可以依次有序的向
// 客户端一个一个发送所有实体数据。
// 注2:gameData必须克隆后,再清除逻辑和场景实体,否则会影响服务端的游戏数据。
GameData gameData = gameServer.getGameData();
GameData clone = (GameData) gameServer.getGameData().clone();
// 清理掉逻辑
clone.getGameLogicDatas().clear();
// 清理场景实体数据
if (clone.getSceneData() != null) {
clone.getSceneData().setEntityDatas(null);
}
// GUI场景不清理,这个必须是固定的
// if (clone.getGuiSceneData() != null) {
// clone.getGuiSceneData().setEntityDatas(null);
// }
gameServer.send(coon, new GameDataMess(clone));
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:34,代码来源:AbstractServerListener.java
示例5: messageReceived
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
public void messageReceived(final HostedConnection source, final Message m) {
// LOG.log(Level.INFO, "GameServer receive message={0}", m.getClass().getSimpleName());
if (listener == null)
return;
LuoYing.getApp().enqueue(new Callable() {
@Override
public Object call() {
try {
listener.messageReceived(GameServer.this, source, m);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Message error on server!", e);
}
return null;
}
});
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:20,代码来源:GameServer.java
示例6: createNewEntity
import com.jme3.network.HostedConnection; //导入依赖的package包/类
public void createNewEntity(Spatial spatial, Command command) {
ServerSender sender =
app.getStateManager().getState(ServerSender.class);
// PlayerEntityAwareness myAwareness = searchForAwareness(spatial);
for (Map.Entry<PlayerEntityAwareness, HostedConnection> entry
: awarenessConnectionMap.entrySet()) {
PlayerEntityAwareness awareness = entry.getKey();
awareness.addEntity(spatial);
if (awareness.testVisibility(spatial)) {
sender.addCommandForSingle(command, entry.getValue());
}
// This is at least temporarily disabled because it seems to cause problems and it's
// not clear what its benefits are
// if (awareness != myAwareness && myAwareness != null) {
// if (myAwareness.testVisibility(awareness.getOwnSpatial()) &&
// !myAwareness.isAwareOf(awareness.getOwnSpatial())) {
//// visibilityChanged(myAwareness, awareness.getOwnSpatial(), true);
// }
// }
}
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:25,代码来源:ServerFog.java
示例7: removeEntity
import com.jme3.network.HostedConnection; //导入依赖的package包/类
public void removeEntity(Spatial spatial, Command command) {
ServerSender sender =
app.getStateManager().getState(ServerSender.class);
for (Map.Entry<PlayerEntityAwareness, HostedConnection> entry
: awarenessConnectionMap.entrySet()) {
PlayerEntityAwareness awareness = entry.getKey();
if (awareness.removeEntity(spatial)) {
sender.addCommandForSingle(command, entry.getValue());
}
if (awareness.getOwnSpatial() == spatial) {
int entityId = spatial.getUserData(UserData.ENTITY_ID);
logger.log(Level.INFO,
"Character with id {0} belonged for player with id {1}."
+ " Nulling",
new Object[]{entityId, awareness.getPlayerId()});
awareness.setOwnSpatial(null);
}
}
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:22,代码来源:ServerFog.java
示例8: connectionAdded
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
public void connectionAdded(Server server, HostedConnection conn) {
final int clientId = conn.getId();
if (!ServerClientData.exists(clientId)) {
ServerClientData.add(clientId);
ServerSender sender = stateManager.getState(ServerSender.class);
sender.addConnection(conn);
stateManager.getState(Receiver.class).addConnection(conn);
CmdTopicOnly connectionEstablishendCommand
= new CmdTopicOnly(Topic.CONNECTION_ESTABLISHED);
sender.addCommand(connectionEstablishendCommand);
} else {
logger.log(Level.SEVERE, "Client ID exists!");
conn.close("ID exists already");
}
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:18,代码来源:ServerNetListener.java
示例9: readGuaranteed
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
public void readGuaranteed(Object source, Command command) {
ServerSender sender = stateManager.getState(ServerSender.class);
if (command instanceof CmdTopicOnly) {
handleTopicOnlyCommand((HostedConnection) source,
(CmdTopicOnly) command);
} else if (command instanceof ChatMessage) {
sender.addCommand(command);
} else if (command instanceof CmdClientLogin) {
handleClientLoginCommand((HostedConnection) source,
(CmdClientLogin) command);
} else if (command instanceof CmdSelectHero) {
handleClientSelectHeroCommand((HostedConnection) source,
(CmdSelectHero) command);
} else if (command instanceof CmdClientSettings) {
handleClientSettingsCommand((HostedConnection) source,
(CmdClientSettings) command);
}
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:22,代码来源:ServerNetListener.java
示例10: handleTopicOnlyCommand
import com.jme3.network.HostedConnection; //导入依赖的package包/类
private void handleTopicOnlyCommand(HostedConnection source,
CmdTopicOnly topicCommand) {
ServerSender sender = stateManager.getState(ServerSender.class);
switch (topicCommand.getTopicId()) {
case Topic.PLAYER_STATISTICS_REQUEST:
BattleStatisticsResponse response = BattleStatisticsResponse
.buildPlayerStatisticsResponse();
sender.addCommand(response);
break;
case Topic.UDP_HANDSHAKE_REQUEST:
sender.addCommandForSingle(new CmdTopicOnly(
Topic.UDP_HANDSHAKE_ACK, false), source);
break;
}
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:17,代码来源:ServerNetListener.java
示例11: serverHandleTopicOnly
import com.jme3.network.HostedConnection; //导入依赖的package包/类
private void serverHandleTopicOnly(HostedConnection source,
CmdTopicOnly command) {
ServerSender sender = stateManager.getState(ServerSender.class);
common.serverHandleTopicOnlyCommand(source, command);
switch (command.getTopicId()) {
case Topic.CLIENT_WORLD_CREATED:
List<String> teamOpts = new ArrayList<>(teamNameId.keySet());
sender.addCommandForSingle(
new CmdTeamOptions(teamOpts), source);
break;
case Topic.TEAM_STATISTICS_REQUEST:
sender.addCommand(BattleStatisticsResponse
.buildTeamStatisticsResponse());
break;
}
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:17,代码来源:TeamDeathmatch.java
示例12: getSource
import com.jme3.network.HostedConnection; //导入依赖的package包/类
public static HostedConnection getSource(int playerId) {
Collection<HostedConnection> connections = Globals.app.getStateManager()
.getState(ServerSender.class).getServer().getConnections();
for (HostedConnection hostedConnection : connections) {
// FIXME: NullPointerException may happen here when player joins!
if (hostedConnection.getAttribute(
ServerClientDataStrings.PLAYER_ID) == null) {
logger.log(Level.WARNING, "PlayerId of connection {0} is null!",
hostedConnection.getId());
continue;
}
if (hostedConnection.getAttribute(ServerClientDataStrings.PLAYER_ID)
.equals(playerId)) {
return hostedConnection;
}
}
return null;
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:21,代码来源:ConnectionHelper.java
示例13: serverHandleCommands
import com.jme3.network.HostedConnection; //导入依赖的package包/类
private void serverHandleCommands(HostedConnection source,
final Command command) {
if (!listening) {
return;
}
int player = ServerClientData.getPlayerId(source.getId());
final int syncId = PlayerData.getIntData(player, PlayerData.ENTITY_ID);
if (syncId != -1) {
app.enqueue(() -> {
doMessage(syncId, command);
return null;
});
} else {
System.out.println("Entity id for player " + player
+ " does not exist");
}
}
开发者ID:TripleSnail,项目名称:Arkhados,代码行数:19,代码来源:Sync.java
示例14: connectionAdded
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
public void connectionAdded(Server server, final HostedConnection conn) {
System.out.println("New connection from " + conn.getAddress());
app.enqueue(new Callable<Void>() {
@Override
public Void call() throws Exception {
connections.put(conn.getId(), conn);
conn.send(new PlayerSpeedMessage(world.getPlayerSpeed(), world.getSpawnPoint()));
for(Entity o : world.getEntitiesOfClass(Entity.class))
conn.send(new AddEntityMessage(o.getEntityID(), o, o.getLocation()));
conn.send(new AddEntityFinishMessage());
return null;
}
});
}
开发者ID:GSam,项目名称:Game-Project,代码行数:17,代码来源:GameServer.java
示例15: applyOnServer
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
public void applyOnServer(GameServer gameServer, HostedConnection source) {
super.applyOnServer(gameServer, source);
Entity sActor = playService.getEntity(sender);
Entity rActor = playService.getEntity(receiver);
if (sActor == null || rActor == null) {
return;
}
chatNetwork.chatSend(sActor, rActor, objectId, amount);
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:11,代码来源:ChatSendMess.java
示例16: applyOnServer
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
public void applyOnServer(GameServer gameServer, HostedConnection source) {
super.applyOnServer(gameServer, source);
Entity sellerActor = playService.getEntity(seller);
Entity buyerActor = playService.getEntity(buyer);
if (sellerActor == null || buyerActor == null) {
return;
}
chatNetwork.chatShop(sellerActor, buyerActor, objectId, count, discount);
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:11,代码来源:ChatShopMess.java
示例17: onReceiveMessRequestGameInit
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
protected void onReceiveMessRequestGameInit(GameServer gameServer, HostedConnection conn, RequestGameInitMess mess) {
int needInitEntities = scene.getData().getEntityDatas() != null ? scene.getData().getEntityDatas().size() : 0;
// 向客户端返回初始化OK的消息
RequestGameInitStartMess result = new RequestGameInitStartMess(needInitEntities);
gameServer.send(conn, result);
// 立即向客户端初始化当前场景中已经载入的实体。
List<Entity> initEntities = scene.getEntities();
for (Entity e : initEntities) {
playNetwork.addEntityToClient(conn, e);
}
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:16,代码来源:ServerNetworkRpgGame.java
示例18: onClientRemoved
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
protected void onClientRemoved(GameServer gameServer, HostedConnection conn) {
super.onClientRemoved(gameServer, conn);
ConnData cd = conn.getAttribute(ConnData.CONN_ATTRIBUTE_KEY);
if (cd == null)
return;
Entity clientPlayer = playService.getEntity(cd.getEntityId());
if (clientPlayer == null)
return;
// 1.将客户端角色的所有宠物移除出场景,注意是宠物,不要把非生命的(如防御塔)也一起移除
List<Entity> actors = playService.getEntities(Entity.class, null);
if (actors != null && !actors.isEmpty()) {
for (Entity actor : actors) {
if (gameService.getOwner(actor) == clientPlayer.getData().getUniqueId() && gameService.isBiology(actor)) {
playNetwork.removeEntity(actor);
}
}
}
// 2.将客户端角色移除出场景
playNetwork.removeEntity(clientPlayer);
// 3.通知所有客户端(不含主机)
String message = ResManager.get(ResConstants.LAN_CLIENT_EXISTS, new Object[] {gameService.getName(clientPlayer)});
MessageMess notice = new MessageMess();
notice.setMessage(message);
notice.setType(MessageType.notice);
gameServer.broadcast(notice);
// 4.通知主机
addMessage(message, MessageType.notice);
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:35,代码来源:ServerNetworkRpgGame.java
示例19: kickClient
import com.jme3.network.HostedConnection; //导入依赖的package包/类
@Override
public void kickClient(int connId) {
// 踢出之前先把玩家的资料保存起来
HostedConnection conn = gameServer.getServer().getConnection(connId);
if (conn != null) {
ConnData cd = conn.getAttribute(ConnData.CONN_ATTRIBUTE_KEY);
if (cd != null && cd.getClientId() != null && cd.getEntityId() > 0) {
storeClient(saveStory, scene.getEntities(Actor.class, null), cd.getClientId(), cd.getEntityId(), data.getId());
SaveHelper.saveStoryLast(saveStory);
}
}
super.kickClient(connId);
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:14,代码来源:StoryServerNetworkRpgGame.java
示例20: saveStory
import com.jme3.network.HostedConnection; //导入依赖的package包/类
/**
* 保存整个存档,当故事模式在退出时要保存整个存档,包含主角,其它客户端玩家资料,及所有玩家的宠物等。
*/
private void saveStory() {
String gameId = data.getId();
List<Actor> actors = scene.getEntities(Actor.class, null);
// 保存所有故事模式下的主角
Entity savePlayer = getPlayer();
savePlayer.updateDatas();
storeClient(saveStory, actors, configService.getClientId(), savePlayer.getEntityId(), gameId);
// 保存当前所有客户端的资料
Collection<HostedConnection> conns = gameServer.getServer().getConnections();
if (conns != null && conns.size() > 0) {
for (HostedConnection hc : conns) {
ConnData cd = hc.getAttribute(ConnData.CONN_ATTRIBUTE_KEY);
// 如果客户端刚刚连接或还没有选角色
if (cd.getClientId() == null || cd.getEntityId() <= 0)
continue;
storeClient(saveStory, actors, cd.getClientId(), cd.getEntityId(), gameId);
}
}
// 单独保存主角,这是为了兼容v2.4及之前的版本,后续可能会取消这个特殊的保存方式.
saveStory.setPlayer(savePlayer.getData());
// 保存快捷方式
saveStory.setShortcuts(ShortcutManager.getShortcutSaves());
// 存档到系统文件
SaveHelper.saveStoryLast(saveStory);
// 保存全局配置
gameService.saveConfig(LyConfig.getConfigData());
}
开发者ID:huliqing,项目名称:LuoYing,代码行数:37,代码来源:StoryServerNetworkRpgGame.java
注:本文中的com.jme3.network.HostedConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论