- Home /
[UNET] Unable to run [Command]s on remote client
Update: Commands definitely are working on the host. Remote Clients, on the other hand simply aren't calling them.
Update: I seem to have been wrong. Whether or not they're set via a command, the Host never sees the synclist and most of the syncvars from the client. I can get the remote client to list both the host's cards and their own cards, but the host cannot see anything from the client. Notably, the User Unique Identity is synchronized across the host and client.
Original Post: I'm making a two player card game, and multiplayer is being implemented via the matchmaker. The PlayerPrefab has a NetworkID component, and it is set to have authority. I'm using a single UserHandler class to handle every bit of data for the user (deck info, unique identity, etc.). Basically, when a player connects, they're supposed to provide their deck lists (position, lineup and sideboard) and deck name to the server. If I remove the [Command] attribute on the functions that set all the SyncVars and SyncListInts, then the client has all data for both the client and the host players, but the host only has its own data. When I switch them back to [Command]s, the host has all data for both, but the client only has the Host's data (which is backwards from what I'd expect.
I've been fighting with Rpc/Command stuff for about a week now, and I'm just getting nowhere. I have no idea what I've done wrong, because if it's out of sync on one, it would make sense if it were completely out of sync on the other. Relevant Code Below:
public class UserHandler : NetworkBehaviour
{
[SyncVar]
public string UserUniqueIdentity;
NetworkInstanceId UserNetID;
Transform myTransform;
[SyncVar]
public string DeckName;
public SyncListInt UserDeckPositions = new SyncListInt();
public SyncListInt UserDeckLineup = new SyncListInt();
public SyncListInt UserDeckDugout = new SyncListInt();
public List<int> ClientUserDeckPositions = new List<int>();
public List<int> ClientUserDeckLineup = new List<int>();
public List<int> ClientUserDeckDugout = new List<int>();
public override void OnStartLocalPlayer () {
Debug.Log("Beginning Setup");
GetUserDeck();
CmdProvideUserDeckToServer();
NetworkLobbyUIHandler.LobbyUISingleton.ListUserCards (GameDataHandler.GameDataSingleton.User.CurrentDeck);
GetNetIdentity();
SetIdentity();
//Debug.Log("Done setting up");
CmdDoneSettingUp();
}
[Client]
void GetUserDeck()
{
Deck deck = GameDataHandler.GameDataSingleton.User.CurrentDeck;
for (int i = 0; i < deck.Positions.Length; i++)
{
ClientUserDeckPositions.Add(deck.positions[i]);
}
for (int i = 0; i < deck.StartingLineup.Count; i++)
{
ClientUserDeckLineup.Add(deck.StartingLineup[i]);
}
for (int i = 0; i < deck.Sideboard.Count; i++)
{
ClientUserDeckSideboard.Add(deck.Sideboard[i]);
}
CmdProvideDeckNameToServer(deck.DeckName);
Debug.Log(DeckName);
}
[Command]
void CmdProvideDeckNameToServer(string deckName)
{
Debug.Log(deckName);
DeckName = DeckName;
}
[Command]
void CmdProvideUserDeckToServer()
{
//UserData user = GameDataHandler.GameDataSingleton.User;
Debug.Log ("Number of UserDeckPositions on the Client:"+ClientUserDeckPositions.Count);
for (int i = 0; i < ClientUserDeckPositions.Count; i++)
{
UserDeckPositions.Add(ClientUserDeckPositions[i]);
}
for (int i = 0; i < ClientUserDeckLineup.Count; i++)
{
UserDeckLineup.Add(ClientUserDeckLineup[i]);
}
for (int i = 0; i < ClientUserDeckSideboard.Count; i++)
{
UserDeckSideboard.Add(ClientUserDeckSideboard[i]);
}
//RpcListDeckLineup();
}
[Client]
void GetNetIdentity()
{
//Debug.Log("Did I Crash before or after I got my NetIdentity?");
UserNetID = GetComponent<NetworkIdentity>().netId;
CmdProvideNetIDToServer(MakeUniqueIdentity());
}
string MakeUniqueIdentity()
{
string UserName = "Player " + UserNetID.ToString() + " " + DeckName;
Debug.Log ("Making Unique Identity: " + UserName);
CmdProvideNetIDToServer(UserName);
return UserName;
}
void SetIdentity()
{
Debug.Log("Setting Net Identity...");
if(!isLocalPlayer)
{
Debug.Log("Client set identity Reached");
transform.name = UserUniqueIdentity;
}
else
{
transform.name = MakeUniqueIdentity();
}
}
}
Answer by firestorm713q · Oct 14, 2015 at 01:13 AM
This is simply the wrong way to approach this problem. As far as I can tell, the HLAPI doesn't support this kind of peer-to-peer method of doing things, and so the best way to handle player-data is to find a way to load it in a server-authoritative way. If you need something more like this, then you'll likely have to delve into the LLAPI, which is not something I feel like doing. Shortest version, Commands can't be run on remote clients, only the local client and the server.
My overall solution is to load up everything on the NetworkHandler using WWW and php.
Your answer
Follow this Question
Related Questions
Synchronizing multiplayer car game 1 Answer
UNET SyncVar on a NetworkInstanceId SyncList structure not updating across network 1 Answer
Unet assigning local player Authority to a gameObject. 1 Answer
Help| Sync' boolean variable (Friendly Fire) 0 Answers
What does the Unity act as when you have a Client-Server system? What are you paying for? 0 Answers