Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BlackPanda · Feb 17, 2015 at 05:43 AM · networkingconnectionmasterserverplayers

How to make host unavailable - Unity Networking

I'm creating a multiplayer turn based game in which 2 players will be playing against each other. One will be server and the other will connect to it. There will be multiple instances of the game running at the same time.

 connectionError = Network.InitializeServer (1, 25001, !Network.HavePublicAddress ());
 
 if (connectionError == NetworkConnectionError.TooManyConnectedPlayers) {
     DebugText.text += "/nToo many connected players";
 }
 else
 {
     MasterServer.RegisterHost (gameType, gameName, "helloo, this is a comment.");
 }

My problem is whenever 2 players are connected and are playing, when a third one tries to connect, it shows that host is available and so it waits for the server to accept. I don't want that. When the connection has got the maximum players, the host should be unavailable. How can I do that? I'm doing it using default Unity networking and Master Server (which I'll host on my own).

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image crodriguez · Feb 17, 2015 at 06:54 AM 0
Share

Do you use a list of HostData to display the available matches available or do you connect manually through IP and port number?

avatar image BlackPanda · Feb 17, 2015 at 06:58 AM 0
Share

I'm using hostdata

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by crodriguez · Feb 17, 2015 at 07:04 AM

I'm not entirely sure if it's the best way to go about it, but one way I 'disabled' a host, was by adding an if statement in the section where I display the match information and the Join button. That if statement would check if the number of connected players in the hostdata was less than the player limit.

Here's an example:

 if (hostData != null)
             {
                 for (int i = 0; i < hostData.Length; i++)
                 {
                     // If the game session is at max capacity, don't display it in the list of games.
                     if (hostData[i].connectedPlayers < hostData[i].playerLimit)
                     {
                         GUILayout.BeginHorizontal("box", GUILayout.Height(25));
 
                         if (GUILayout.Button("Join", GUILayout.Height(25), GUILayout.Width(50)))
                         {
                             // Ensure that the player can't join a game with an empty name. If the player left the name field
                             // empty, assign "Player 2" to the playerName variable.
                             
                             if(playerName == "")
                             {
                                 playerName = "Player 2";    
                             }    
                             
                             //If the player has a name that isn't empty then attempt to join 
                             //the server.
                             
                             if(playerName != "")
                             {
                                 // Connect to a server contained in the hostData[i].
 
                                 Network.Connect(hostData[i]);
                                 
                                 PlayerPrefs.SetString("playerName", playerName);
 
                                 // Call the function to apply the playerName across the Network and to other scripts.
                                 StartCoroutine(ChangePlayer2Name());
                             }
                         }
                         GUILayout.Space(10);
                         GUILayout.Label(hostData[i].gameName, GUILayout.Height(25));
                         GUILayout.EndHorizontal();
                     }
                 }
             }




Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BlackPanda · Feb 17, 2015 at 09:44 AM 0
Share

Thanks, but this is not what I'm looking for. I want multiple pairs of players to play at the same time. For example, a game like chess. One player will check for open servers, he won't find any. So he starts a server and waits for someone to join. Another player comes and searches for servers, and he finds one. They start playing. At the same time, if another player comes, he should be able to start a new server. That's what I want to achieve. :)

avatar image crodriguez · Feb 19, 2015 at 12:22 AM 0
Share

Just so you're aware, that piece of code only applies to players attempting to join a game. For players who desire to create one, it would not go through this code. If that still doesn't help, then show me more of your code to see better what you're trying to do.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Connecting to server through IP. ? tutorial thats not local trash? 0 Answers

server connecting issue 1 Answer

[Edited]How To establish a mmo game By using Bluetooth 1 Answer

are you sure the server can be connected to? 1 Answer

MasterServer with Unet ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges