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
1
Question by rednax20 · Dec 05, 2013 at 02:46 AM · playernetworkrpc

Disconnect a player from a network

I am very new to networking. I am working on a simple script that will stop players from joining it if the game has been started. Networking to me seems (at times) unreasonably difficult.

Maybe I'm just not good at google searching.

Before i post my code, i will tell you what i searched for, if any of these exist, they would be extremely helpful. I couldn't find a one.

A method, to stop any new clients from joining the network

A way to diconnect a player by ip address (this one would be especially helpful)

A way to make a client disconnect itself.

As far as i know Network.CloseConnection seems to be the only way to do this. Although, i don't really know what CloseConnections even does. I found the example script for it in the documentation really long and hard to understand. from my knowledge it seems to disconnect a target connection (whatever the heck that is). I assume that this is a player instance in the Network.connections Array. but then again i have no clue.

here's a sample of my code (not all of it). It doesn't work am i doing something wrong?

 @RPC
 function allowentry (){
 
          if(startgame == true){
               Network.CloseConnection(Network.connections[Network.connections.length], true); // this was supposed to get rid of the last player that connected
          }
 
 }
 
 //bunch of GUI buttons unnecessary to the explanation to my code stuff here 
 
  Network.Connect(words, connectionPort); // it connects fine
 networkView.RPC("allowentry", RPCMode.Server);
 
 //yes the network view is attached to my object

This results in nothing happening. all of my code runs ( i found this out through console statements) but I get no error, no nothing. just a client that was not kicked out of the server.

I even tried changing line 5 to

     Network.CloseConnection(Network.connections[1], true);

because i was currently testing this with only one client and one server, but i got this error message

IndexOutOfRangeException: Array index is out of range. Connect.allowentry () (at Assets/Connect.js:19)

so sorry this was so long, and that i am such an idiot. thanks a whopping bajillion for reading this.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Dec 05, 2013 at 07:54 AM

  • for being humble and polite ;) And you're no idiot - networking is the single hardest component to nail that I've ever encountered. The only obvious mistake I can see in the above code is that, since array indexes are zero-based, to disconnect the last player,

    Network.CloseConnection(Network.connections[Network.connections.length], true);

should be:

 Network.CloseConnection(Network.connections[Network.connections.length - 1], true);

If you manage to get Network.CloseConnection() working in the general sense, you should be able to target a particular player to disconnect by testing the ipAddress property of the NetworkPlayer: http://docs.unity3d.com/Documentation/ScriptReference/NetworkPlayer-ipAddress.html - I might be able to knock up a quick example this evening.

Comment
Add comment · Show 1 · 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 rednax20 · Dec 05, 2013 at 09:23 PM 0
Share

I remember reading something about that. couldn't remember quite what it was though.

anyway it works now that i made that fix. thanks!

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

17 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

Related Questions

Problem with identifying players in network 1 Answer

Methods Repeats for each New Player connected 0 Answers

Displaying players name above in multiplayer 1 Answer

raycast hit to player in network ,how?? 0 Answers

List clients connected? 2 Answers


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