How to let clients see each other?

Hi,



I just started to learn jmonkey network few days ago and have lots of problems:

  1. How to let clients see each other?

    For example, client#1 connects to server and then client#2 connects. How does client#1 see client#2 ? Iv used rootNode.attachChild(// code for adding my new hero) to let client#1 see client#2. It works but after adding client#2, client#1 cannot control his own hero, it controls the new hero. (hope i describe this clearly…)



    2.How to get the existing information?

    For example, when the client#2 connects, how does it know the position of client#1 (and maybe the healthPoint of client#1’s hero)? Use something like logger to save information and server to read and broadcast to client#2 when he connects?



    3.How to share information?

    I just show an example to describe this question:

    In my game, there is a building which will be destroyed by heroes. When the client#1 hits/beats this building once, the building’s healthPoint would reduce 1, assume the initial HP of building is 100, then now it should be 99 and 99 should be shown on all clients’ screen. After that, client#2 hits the building, then it reduces 1 again. Now the building’s HP should be 98. (Not 100-1=99 on client#2’s screen). How to achieve that? Use a global class to hold all data?





    Many many thanks, experts!

@garlicbread

I did it like so:



Make a PlayerServer class that represents the players on the server (all it contains is player location, rotation, weapon or whatever else data you need)

Add to your player class an ArrayList

Make a PlayerMessage class, which sends a PlayerServer over the server

if the array list contains the PlayerServer instance sent, just update the code in it. If not, add the new one to the array

if a PlayerServer hasn’t been updated in a while, remove it from the array list.



later, in the update method:

call a for(PlayerServer player : playerArrayList) and for each player in the scene attach them to the node at the given position and rotation.



that’s the best way i could do it.