Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

List informations about the game room

Discussion in 'Multiplayer' started by bittarello, Jan 16, 2015.

  1. bittarello

    bittarello

    Joined:
    Aug 8, 2013
    Posts:
    8
    Hello,

    I've made a online game that works fine. The player receives a list of game rooms and then can join. The problem is: I can't get information about what level was select by the host or any other, only the specifics about the connection.

    I'm using Unity 4.6 without any network plugin. The list above is an array of HostData objects. There is any way I can get those information?

    ps: I searched in here and the most similar thread was http://forum.unity3d.com/threads/pun-room-logic.290426/ . But they are using some kind of plugin.
     
  2. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    You can use rpcs to send data back and forth. Set up an rpc and send the info to the client about the rooms.
     
  3. bittarello

    bittarello

    Joined:
    Aug 8, 2013
    Posts:
    8
    Thanks for replying.

    As long as I know, to do that I would connect to all clients room, one by one. It gets worst when I need to refresh every second.
     
  4. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    Well... if you need them to refresh, just every second iterate through the rooms and send out the rpc calls. I don't know your specifics since I don't see exactly what you're doing but an rpc call should work.
     
  5. bittarello

    bittarello

    Joined:
    Aug 8, 2013
    Posts:
    8
    My code is like:
    Code (CSharp):
    1. MasterServer.RequestHostList(strGameName);
    2. HostData[] rooms = MasterServer.PollHostList()
    With array "rooms", I show on user interface a list of rooms that he can connect. The last thing in each row is a button "Connect". Until that moment, the player didn't connect with anyone, only got a list of rooms from the masterserver.

    If I make the player connect with each players host every refresh, it would make a lot of connections. Beside, the hosts will note that someone singed up in their rooms.
     
  6. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    You can have it refresh only when someone joins a room. You don't need to connect to each player every frame... But when a user connects to the host, the host sends out an rpc to all people that the room has an additional person in it.
     
  7. bittarello

    bittarello

    Joined:
    Aug 8, 2013
    Posts:
    8
    I found a way :D

    For everyone that want to update information about the room, without make connections, you just have to put the information in the prop "comment" when your code call the function "MasterServer.RegisterHost". I knew this property before, but I thought it couldn't be change after connection registered.

    It can be changed using the same function with the same "gameTypeName" and "gameName" parameters, only changing the third (each is the comment property). I did tests and the connections made previously stayed the same. Any player, even those not connect in the room, noted the room's comment changed.

    Now I can pass game mode, level and time limit selected by the host for everybody in the room browser.
    Thank you GambinoInd for your attention!