GetConnectionFromUserName() public static method

public static GetConnectionFromUserName ( string username ) : BoltConnection
username string
return BoltConnection
Ejemplo n.º 1
0
    public override void MoveTo(Vector3 position, Quaternion rotation)
    {
        //only the server is allowed to move other players
        if (!BoltNetwork.isServer)
        {
            Debug.LogError("Only the server is allowed to move other players!");
            throw new System.NotImplementedException();
        }
        //tell the other player to move!
        PlayerMoveEvent evnt = PlayerMoveEvent.Create(PlayerRegistry.GetConnectionFromUserName(Username), Bolt.ReliabilityModes.ReliableOrdered);

        evnt.NewPosition = position;
        evnt.NewRotation = rotation;
        evnt.Send();
    }
Ejemplo n.º 2
0
    public override void OnEvent(HurtEvent evnt)
    {
        if (BoltNetwork.isServer)
        {
            //TODO damage stats can be recorded here if needed, all HurtEvents pass through here exactly once

            //Direct damage events, either by consuming them here (if they were meant for the server player)
            //Or by redirecting them to the right player

            //if this HurtEvent is targeted at the server itself, apply it directly without forwarding it first
            if (evnt.Target == GameManager.instance.CurrentUserName)
            {
                GameManager.instance.CurrentPlayer.TakeDamage(evnt.Amount, evnt.Source, evnt.Direction, evnt.WeaponID);
            }
            else    //this event is not directed at the server player, it needs to be forwarded to the correct player
            {
                BoltConnection destination = PlayerRegistry.GetConnectionFromUserName(evnt.Target);
                if (destination == null)  //quick error check
                {
                    Debug.LogError("The destination connection for a HurtEvent could not be found! " + evnt);
                }
                else
                {
                    //forward the event to the player that was actually damaged
                    HurtEvent redir = HurtEvent.Create(destination, Bolt.ReliabilityModes.ReliableOrdered);
                    redir.Amount    = evnt.Amount;
                    redir.Target    = evnt.Target;
                    redir.Source    = evnt.Source;
                    redir.WeaponID  = evnt.WeaponID;
                    redir.Direction = evnt.Direction;
                    redir.Send();
                }
            }
        }
        else                                                         //this is a client
        {
            if (evnt.Target == GameManager.instance.CurrentUserName) //make sure that this hurtEvent is intended for this client
            {
                GameManager.instance.CurrentPlayer.TakeDamage(evnt.Amount, evnt.Source, evnt.Direction, evnt.WeaponID);
            }
            else
            {
                Debug.LogError("Recieved HurtEvent that is not directed to this player! " + evnt.ToString());
            }
        }
    }