Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to get the connection ID of the client that issued a Command

Discussion in 'Multiplayer' started by Joe-Censored, Jan 2, 2018.

  1. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Does anyone know how to get the connection ID of a client that issued an HLAPI Command?

    The purpose being that I want to make a request to the server via a Command, and have the server eventually respond to that request with a UNET Message to that client's connection ID. But I can't find any examples of capturing the connection ID of a client that runs a Command.
     
  2. Deleted User

    Deleted User

    Guest

    Kokowolo likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Deleted User likes this.
  4. Kokowolo

    Kokowolo

    Joined:
    Mar 26, 2020
    Posts:
    52
    Doesn't this (connectionToClient) only apply for objects that the client has authority over?

    I think in the event that you want to grab the connection of the client that called the Command for an object without authority, you need to manually pass a reference of client's network id. Not certain though.
     
    Last edited: Jan 14, 2021
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Unet generates an error instead of sending the Command if the client doesn't have authority over the object.
     
  6. Kokowolo

    Kokowolo

    Joined:
    Mar 26, 2020
    Posts:
    52
    Oh... that's a shame. Good to know though! In Mirror you can ignore authority and pass the client's connection through the method declaration, but perhaps that's yesterday's news.
     
    Nomis0042 likes this.
  7. T-Gamez

    T-Gamez

    Joined:
    Nov 2, 2019
    Posts:
    9
    I've an issue with this:

    `connectionToClient.connectionId` in the CMD method is not the same as `connectionToServer.connectionId` in the method that is calling the CMD method. It seems that the connectionId for a players connection on the server is different than the connectionId on the client? How can I identify, that the connection on the client is the same connection as the one that called the server?

    Thank you :)
     
    imek2 likes this.