Author Topic: Required to Join Channel/Load New Scene to use RFC/See Other Players?  (Read 13096 times)

Eyeshock

  • Guest
Hi there. I'm trying to integrate TNET into my already existing networked game. In the past, I've simply handled everything up until the gameplay via the main menu scene (setup lobby, players lobby, then run game based on map/difficulty choices, etc.)

I'm having no luck making this work with TNET and I'm guessing this join channel thing is to blame. So I can't execute any RFC before joining channel between players and the only way to join channel is to load a new scene? (this may be blatantly simple, but to be fair: 3 pages of documentation...)

AND...if that's the case, and I have a Multiplayer Manager script keeping track of my players saved data (preserved profile data, similar to games like League of Legends, Starcraft 2), can I preserve that gameobject with a TNObject script from hosting/connection scene to lobby scene (the 'joined' channel)?

And finally, can I preserve a manager object (with TNObject) between levels using TNManager.Loadlevel once I'm in the channel lobby?

So to summarize: is it absolutely necessary to load a new scene after connecting?

To be perfectly honest, I'm starting to doubt my decision to pick up this asset. It's great for folks looking for a fast track to sync, especially for standalone servers, but I'm yet to find any advantage to the swap (not to discredit your development packages; I am very fond of NGUI). Maybe when I actually get to the game-play, my luck will change. Thanks in advance for your support.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You can pass 'null' for the scene name for JoinChannel.

You can have TNObjects travel from one scene to another (DontDestroyOnLoad their game objects).

Eyeshock

  • Guest
That seems to work just fine, and fixed the mass of issues I was encountering.

The big problem I'm having now is I can't execute any [RFC] calls.
  1.        
  2.  
  3. void OnNetworkJoinChannel(bool success, string message)
  4.         {
  5.                 Debug.Log("Joining Network Channel: Success? " + success + " Message:" + message);
  6.                
  7.                 // Let All Users Know I'm Here
  8.                 Debug.Log ("Calling Notify Network...");
  9.                 tno.Send("NotifyNetwork", Target.All);
  10.         }
  11.        
  12.         void OnNetworkPlayerJoin(Player newPlayer)
  13.         {
  14.                 Debug.Log("ID "+ newPlayer.id + ", " + newPlayer.name + " Joined Network.");
  15.         }
  16.        
  17.        
  18.         void AddPlayerToClientList(string newPlayerName, int playerID)
  19.         {
  20.                 MPPlayer tempPlayer = new MPPlayer();
  21.                 tempPlayer.playerName = newPlayerName;
  22. //              tempPlayer.playerNetwork = view ;
  23.                 playerList.Add(tempPlayer);
  24.         }
  25.        
  26.        
  27.         [RFC] void NotifyNetwork()
  28.         {
  29.                 Debug.Log ("Calling Notify Network!");
  30.         }
  31.        

I keep getting the error: "Unable to execute function 'NotifyNetwork'. Did you forget an [RFC] prefix, perhaps?"
I'm currently inheriting from TNBehavior.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Where is this script attached? Is it on some instantiated prefab?

Also -- not quite sure why you are sending NotifyNetwork when you already get the OnNetworkPlayerJoined notification?

Eyeshock

  • Guest
Where is this script attached? Is it on some instantiated prefab?

Also -- not quite sure why you are sending NotifyNetwork when you already get the OnNetworkPlayerJoined notification?



Script is attached to existing gameobject at game start. I'm calling NotifyNetwork simply for learning/testing purposes, to make sure RFC is working. I would normally be calling an updated version of AddPlayerToClientList (old ver is based on RPC/Unity.Network), however I haven't started updating all my RPCs yet because...well...I can't get NotifyNetwork() to execute.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Try simply doing that tno.Send inside Update() function when you press a specific key:
  1. void Update()
  2. {
  3.     if (Input.GetKeyDown(KeyCode.S)) tno.Send("NotifyNetwork", Target.All);
  4. }
Does that work?

Eyeshock

  • Guest


Same error. It's not like RFC is broken either; I'm using the chat gameobject from your example scene in the same scene as multiplayerManager and it's working fine.

If I absolutely have to, I'll prolly try seperating my Mplayer class (player data) from MultiplayerManager (connection functions), and detaching them both from the TNManager to see if that changes anything; maybe even try instantiating what I can after connection. But obviously, I'd really rather not do that - nor does it explain why the error reported suggests the [RFC] prefix is being ignored.

BLAAHBLAHBLAHAAALL!H!H!H  :P

Eyeshock

  • Guest
SO WEIRD; I'm having no problems with the quick swapping out RPC for RFC on other instantiated prefabs, but this object continues to error out on RFC calls. Does it have anything to do with it being on the same object as TNManager?

I tried instantiated it as a prefab in an empty scene; same problem, so the issue is either in the script or something to do with the gameobject; I have included the entire script, though the mass of it is outdated RPC calls (comment shows the division).

Please lemme know if you see the problem. I've got TNET to function pretty well with my combat/collision stuff, so I'm convinced it's a good system; I bet I can find a work around for this issue (separating RFCs from the Abstract class), but obviously I'd rather now. Thanks again.

  1.  
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using TNet;
  6.  
  7. public class MultiplayerManager : TNBehaviour {
  8.        
  9.         public enum GameState
  10.         {
  11.                 Setup,
  12.                 GameLobby,
  13.                 CharacterSelect,
  14.                 Loading,
  15.                 Playing,
  16.                 BetweenLevels,
  17.                 EndGame
  18.         }
  19.        
  20.         public GameState matchState = GameState.Setup;
  21.         public bool playerReady = false;
  22.        
  23.         private string _matchName = "" ;
  24. //      private string _matchPassword = "" ;
  25.         private int _matchMaxUsers = 3 ;
  26.        
  27.         public static MultiplayerManager instance ;
  28.        
  29.        
  30.        
  31.         public System.Collections.Generic.List<MPPlayer> playerList = new System.Collections.Generic.List<MPPlayer>();
  32.         public System.Collections.Generic.List<GameObject> NetworkedPlayerPrefabs;
  33.         public System.Collections.Generic.List<SceneSettings> sceneList = new System.Collections.Generic.List<SceneSettings>();
  34.        
  35.         public GameObject playerCharacterPrefab;
  36.        
  37.        
  38.         public SceneSettings currentScene;
  39.         public int oldPrefix ;
  40.         public bool isMatchStarted = false;
  41.        
  42.        
  43.         // public TNObject tno;
  44.        
  45.         public int NumberOfConnectedPlayers;
  46.        
  47.        
  48.         void Start()
  49.         {
  50.                
  51.                 TNObject tno = gameObject.GetComponent<TNObject>();
  52.                
  53.                 GameReference.multiplayerManagerScript = this;
  54.                 DontDestroyOnLoad(gameObject);
  55.                 instance = this;
  56.                 // playerName = PlayerPrefs.GetString("PlayerName");
  57.                 currentScene = sceneList[0];
  58.         }
  59.        
  60.         void Update()
  61.         {
  62.                 NumberOfConnectedPlayers = TNManager.players.size;
  63.                
  64.                
  65.                  if (Input.GetKeyDown(KeyCode.S)) tno.Send("NotifyNetwork", Target.All);
  66.         }
  67.        
  68.         void FixedUpdate()
  69.         {
  70.                 instance = this;
  71.                
  72.         }
  73.        
  74.         // Starts local server using TNet Networking
  75.         public void StartServer(string serverName, string serverPassword, int maxUsers)
  76.         {
  77.                 _matchName = serverName ;
  78.                 _matchMaxUsers = maxUsers ;
  79.                
  80.                 TNServerInstance.Start(5127, 5128);
  81.                 TNManager.playerName = GameReference.gameSettingsScript.characterName;
  82.                 //AddPlayerToClientList(TNManager.playerName, TNManager.playerID);
  83.                 ConnectToServer("127.0.0.1");
  84.                
  85.         }
  86.        
  87.         // TNET Networking Setup; connects to server using provided IP
  88.         public void ConnectToServer(string IP2Connect)
  89.         {
  90.                 Debug.Log ("Attempting to Connect to Server at -" + IP2Connect + "-.");
  91.                 TNManager.Connect(IP2Connect);
  92.         }
  93.        
  94.         void OnNetworkError(string error)
  95.         {
  96.                 Debug.LogError("Network Error: " +  error);
  97.         }
  98.        
  99.         void OnNetworkConnect (bool success, string message)
  100.         {
  101.                 Debug.Log("Joining Network: Success? " + success + " Message:" + message);
  102.                
  103.                
  104.                 // Join Channel
  105.                 TNManager.JoinChannel(123, null);
  106.                
  107.                 // Add Player to List of Clients
  108.                 //TNManager.playerName = GameReference.gameSettingsScript.characterName;
  109.                 //AddPlayerToClientList(TNManager.playerName, TNManager.playerID);
  110.         }
  111.        
  112.        
  113.         void OnNetworkJoinChannel(bool success, string message)
  114.         {
  115.                 Debug.Log("Joining Network Channel: Success? " + success + " Message:" + message);
  116.                
  117.                 // Let All Users Know I'm Here
  118.                 Debug.Log ("Calling Notify Network...");
  119.                 tno.Send("NotifyNetwork", TNet.Target.All);
  120.         }
  121.        
  122.         void OnNetworkPlayerJoin(Player newPlayer)
  123.         {
  124.                 Debug.Log("ID "+ newPlayer.id + ", " + newPlayer.name + " Joined Network.");
  125.         }
  126.        
  127.        
  128.         void AddPlayerToClientList(string newPlayerName, int playerID)
  129.         {
  130.                 MPPlayer tempPlayer = new MPPlayer();
  131.                 tempPlayer.playerName = newPlayerName;
  132. //              tempPlayer.playerNetwork = view ;
  133.                 playerList.Add(tempPlayer);
  134.         }
  135.        
  136.         [RFC]
  137.         void NotifyNetwork()
  138.         {
  139.                 Debug.Log ("Calling Notify Network!");
  140.         }
  141.        
  142.        
  143.         // OLD NETWORKING FUNCTIONS BELOW
  144.        
  145.        
  146.         /*
  147.         void OnServerInitialized()
  148.         {
  149.                 Server_PlayerJoinRequest(GameReference.gameSettingsScript.characterName, Network.player);
  150.         }
  151.         */
  152.         void OnConnectedToServer()
  153.         {
  154.                 //networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, playerName, Network.player);
  155.                        
  156.         }
  157.        
  158.         void OnPlayerDisconnected(NetworkPlayer networkPlayerID)
  159.         {
  160.                 networkView.RPC("Client_RemovePlayer", RPCMode.All, networkPlayerID);
  161.         }
  162.        
  163.         void OnDisconnectedFromServer()
  164.         {
  165.                 playerList.Clear();
  166.         }
  167.        
  168.  
  169.        
  170.         void OnPlayerConnected(NetworkPlayer networkPlayerID)
  171.         {
  172.                 foreach(MPPlayer pl in playerList)
  173.                 {
  174. //                      networkView.RPC("Client_AddPlayerToList", networkPlayerID, pl.playerName, pl.playerNetwork);
  175.                 }
  176.                
  177.                 networkView.RPC("Client_GetMultiplayerMatchSettings", networkPlayerID, currentScene.sceneName, "", "");
  178.         }
  179.        
  180.        
  181.        
  182.  
  183.         void Client_RemovePlayer(NetworkPlayer view)
  184.         {
  185.                 MPPlayer temppl = null;
  186.                 foreach(MPPlayer pl in playerList)
  187.                 {
  188. //                      if(pl.playerNetwork == view)
  189. //                      {
  190. //                              temppl = pl;
  191. //                      }
  192.                 }
  193.                 if(temppl != null)
  194.                 {
  195.                         playerList.Remove(temppl);
  196.                 }
  197.         }
  198.        
  199.  
  200.         void Client_GetMultiplayerMatchSettings(string scene, string mode, string others)
  201.         {
  202.                 currentScene = GetScene(scene);
  203.         }
  204.        
  205.  
  206.         void Client_LoadMultiplayerScene(string scene, int prefix)
  207.         {
  208.                
  209.                 // Spawn Player
  210.                 // Client_SpawnPlayer();
  211.                
  212.                
  213.                 // So we only recieve messages for new prefix
  214.                 Network.SetLevelPrefix(prefix);
  215.                
  216.                
  217.                 Application.LoadLevel(scene);
  218.                
  219.         }
  220.        
  221.         public void Client_SpawnPlayer(Vector3 spawnPoint)
  222.         {
  223.                 Debug.Log ("Spawning Local Player");
  224.                
  225.                 // Create Player Prefab
  226.                 // GameReference.localPlayerObject = Network.Instantiate(playerCharacterPrefab, Vector3.zero, Quaternion.identity, 0) as GameObject;
  227.                 TNManager.Create(playerCharacterPrefab, spawnPoint, Quaternion.identity);
  228.                
  229.                 // GameReference.localPlayerObject.name = GameReference.playerCharacterScript.Name;
  230.                
  231.                 //GameReference.localPlayerObject.transform.localScale = new Vector3(1,1,1);
  232.         }
  233.        
  234.         public SceneSettings GetScene(string name)
  235.         {
  236.                 SceneSettings get = null;
  237.                
  238.                 foreach(SceneSettings st in sceneList)
  239.                 {
  240.                         if(st.sceneName == name)
  241.                         {
  242.                                 get = st;
  243.                                 break;
  244.                         }
  245.                 }
  246.                
  247.                 return get;
  248.         }
  249.        
  250.        
  251.        
  252.        
  253.        
  254. }
  255.  
  256.  [System.Serializable]
  257. public class MPPlayer
  258. {
  259.         public int playerID ;
  260.         public string playerName = "";
  261.        
  262. }
  263.  [System.Serializable]
  264. public class SceneSettings
  265. {
  266.         public string sceneName;
  267.         public string sceneLoadName;
  268.         public Texture sceneLoadTexture;
  269. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Interesting. In Starlink I have a TNObject on another game object that travels from scene to scene (not on the TNManager), but its ID is below 255 -- 10. Which game object it's on shouldn't matter though. Is it possible that you have more than one TNObject with the same ID? When instantiating new game objects it's important to make sure that they have unique IDs. Prefabs should have TNObject IDs set to 0.

Eyeshock

  • Guest
Yeah; it's got a unique ID both at run-time and instantiation. I tried changing the ID in different ways with no change.

Also in the case of prefabs, setting them to 0 has caused me issues already. I instantiate a number of monsters of the same prefab, and one of them always came out 0, so I've been setting prefabs at intervals of 1000.

I'm going to try making another script and attaching it to the object with a garbage RPC, then try it on a prefab that works with RFC and see if it's specifically something in MultiplayerManager.cs or the gameobject itself.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
« Reply #10 on: July 12, 2013, 02:37:03 PM »
How do you instantiate them? You need to use TNManager.Create to do that. If you don't, TNObject IDs won't be set correctly.

Eyeshock

  • Guest
Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
« Reply #11 on: July 22, 2013, 08:04:09 PM »
Yes, I am using TNManager.Create to create prefabs, and they are present in the objects list. I am having no problems with prefabs in the gameplay scene.

I've conducted a lot of trial and error, and even tried some workarounds:

I tried to separate the RFCs from the MultiplayerManager script and call them remotely. It turns out the RFCs aren't even being attempted; if the object in question doesn't exist or does exist, it doesn't matter: same error about 'missing RFC prefix'.

I tried joining a new scene via the JoinChannel and running the RFCs there, and that was a no-go as well.

I tried calling the RFCs in the gameplay scene where I have a lot of networking already; same error.

I tried calling the working RFCs from gameplay on the MultiplayerManager script; same error.

However, if I call RFCs on any other objects or script, it works fine.

Simply stated: It doesn't seem like TNObject will even attempt the call on a script attached to TNManager's gameobject. This does not seem to be the case in the example scenes? In any case, I've sorta hit a wall on this one; I'm not entirely sure what else I can try.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
« Reply #12 on: July 23, 2013, 04:28:43 AM »
If you can clean up your project to the bare minimum and send me the example of it not working correctly, I can look into what's wrong.

Jeremy Alessi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
« Reply #13 on: July 25, 2013, 11:32:21 AM »
I had the issue of [RFC] tags not working. The solution appears to have been to not use a prefabbed GameObject (I was modifying a previously existing script). I built the same GameObject from scratch (still using the same script) and all of a sudden my [RFC]'s began working. It's possible that it was something else but if so I cannot identify any other changes that made a difference.

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
« Reply #14 on: August 01, 2013, 01:46:00 PM »
Would having a TNObject ID of 1001 cause the problem Aren?  I remember reading that there is a limit to 255.  @Eyeshock change the ID from 1001 to 0 and see if that helps any.