本文整理汇总了Java中com.jme3.network.HostedConnection类的典型用法代码示例。如果您正苦于以下问题:Java HostedConnection类的具体用法?Java HostedConnection怎么用?Java HostedConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostedConnection类属于com.jme3.network包,在下文中一共展示了HostedConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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);
}
示例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);
}
}
}
示例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));
}
示例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;
}
});
}
示例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);
// }
// }
}
}
示例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);
}
}
}
示例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");
}
}
示例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);
}
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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");
}
}
示例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;
}
});
}
示例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);
}