Player info for objects in Multiplayer

Hello,

I’m having a multiplayer project.

The Server itself is also a client (so no dedicated server).

When the server starts, I’m loading a map, and creating a palyer object with Network.Instantiate.

When a player joins, I’m also creating an object with Network.Instantiate.

These objects contain the player model, the camera, camera and control scripts and a name tag.

Now with the last there is the problem. The name tag. Everything else works fine.

The problem is: How to identify a player and how to save his name.

My test:

Calling an RPC from the client connecting (or the server on start) to the Server.

The server gets the IP and Port of the player and uses it as an unique identifier, adds this ID and the name into a hashmap.

After that it iterates through the hashmap and sends it all players.

In the name tags on the OnGUI function I’m using the key created form:

networkView.owner.ipAddress + ":" + networkView.owner.port

to get the name from the hashmap with all names sent from the server.

But all this names messes up.

First: The server dows not have an external ip set in this case so the key is “:0” that is set (The RPC uses NetworkMessageInfo to get the IP and Port).

Other clients get the external IP of the server and try to get the name of this key that doesn’t exist.

Second: Is there a client connecting over the local network in a match where some are connecting over the internet, the local client has the internal IP as key, from the external client this player has the IP of the server.

I hope someone understands my problem and has a solution for this problem.

Thanks for any answers!

Edit:

Did an additional test.

I’m now using the NetworkPlayer as String. (Player ID)

When the client model is created I’m sending an RPC call to the server with the Player ID and the Name.

The server saves it in a server player list.

Then it iterates through this list and sends it to all players (RPCMode.AllBuffered).

On the Clients I’m tanking the

transform.networkView.owner.ToString()

or

transform.gameObject.networkView.owner.ToString()

to get the owner of this object.

On the server side everything is perfect. All palyers have their matching name.

But on the client side (on every client) all other clients and the server have the name of the server.

Finally I got it with the solution I wrote in my edit.

Read on another question, that only the server knows the client and that the client has to ask the server for the owner of the networkView.

I made an RPC call to the server with the networkView.viewID.

On the server I got the owner from the NetwoekViewID, read out the name and made an RPC call abck to the client who asked for the name.