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 Zendoth · Jun 13, 2021 at 05:18 PM · multiplayerdatabasemultiplayer-networking

MLAPI: Is it possible to obtain all connected client ids in the NetworkManager?

Seeing if there's anyone more experienced to help. I am just wondering if there is a way to obtain perhaps the ClientId of all connected clients in the NetworkManager.

My situation is that I have a sql server and database which the game interacts with via php scripting. I have a table inside said database with the column 'online' which is either a 0 or 1 to denote if the user is connected.

I intend to update this table when the user clicks the quit button to update the 'online' column in his player's row to 0 for false.

Clearly this is not perfect and the database wont be updated if the user exits without clicking the quit button like alt+f4 for instance. Hence I am writing a script on the server side to take care of it and try to poll for connected clients and update them in the database as accordingly.

Wondering if anyone knows if the NetworkManager from MLAPI has any attribute like a list of connected client ids?

Note: I am aware of the NetworkManager.Singleton.LocalClientId but this returns a single ulong of the local client not all the connected clients. I would like a list of all the client ids if such an attribut exists.

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 Zendoth · Jun 14, 2021 at 06:06 PM

I have found the answer to this after some research and a little help from the mlapi discord admin TwoTen.

There exists an event called OnClientDisconnectCallback located within the NetworkManager. This event is automatically invoked by both the disconnected client and the server (important bit). Hence I can call for this event to call an additional function which handles my database queries. The event mentioned returns a ufloat which is the client ID unique to that client. On the server, no 2 client ID are the same starting from 1 which makes this perfect for my implementation.

I had a table in my db called client ID which is updated when the user connects to the server as a client and is already given a client ID. Hence a single user might have different client ID depending on when he logs in throughout the day.

For a user to login, it will query the db and see if this client ID is 0 or !0. If !0 it means someone is logged into that account. If the column was 0, After logging in, the client ID will be updated in the db.

As for my issue, when the event is invoked automatically on client disconnected, the server calls for an event that passed the unique client ID of the disconnected client to the db and I find the client ID cell of the ufloat passed through the event in my db and set it back to 0. I have tested this and it works quite well. If anyone has issues with implementation, I will be glad to help.

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

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

208 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dedicated Server for 1v1 Gameplay 3 Answers

How do game devs go about making a user's multiplayer experience persistent? 2 Answers

How the games are storing Bulk data of players and how they are processing? 2 Answers

Photon players' usernames not syncing properly 0 Answers

my multiplayer game second player not active 0 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