// -------------------------------------------

        /*
         * OnReceivedMatchPresence
         */
        private void OnReceivedMatchPresence(IMatchPresenceEvent _matchPresenceEvent)
        {
            if (DEBUG)
            {
                Debug.LogError("NakamaController::IMatchPresenceEvent::JOINS[" + _matchPresenceEvent.Joins.ToList().Count + "]");
            }

            // For each new user that joins, spawn a player for them.
            foreach (var user in _matchPresenceEvent.Joins)
            {
                RegisterPlayer(_matchPresenceEvent.MatchId, user);
            }

            // For each player that leaves, despawn their player.
            foreach (var user in _matchPresenceEvent.Leaves)
            {
                for (int i = 0; i < m_players.Count; i++)
                {
                    NakamaPlayer player = m_players[i];
                    if (player.UserPresence.SessionId == user.SessionId)
                    {
                        m_players.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
 /// <summary>
 /// Method fired when any user leaves or joins the match
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnMatchPresence(IMatchPresenceEvent e)
 {
     foreach (IUserPresence user in e.Joins)
     {
         if (Players.FindIndex(x => x.UserId == user.UserId) == -1)
         {
             Debug.Log("User " + user.Username + " joined match");
             Players.Add(user);
             if (user.UserId != NakamaSessionManager.Instance.Session.UserId)
             {
                 OpponentId = user.UserId;
             }
             if (AllPlayersJoined == true)
             {
                 _allPlayersAdded = true;
                 StartGame();
             }
         }
     }
     if (e.Leaves.Count() > 0)
     {
         Debug.LogWarning("User left the game. Exiting");
         UnityMainThreadDispatcher.Instance().Enqueue(LeaveGame);
     }
 }
 /// <summary>
 /// Method fired when any user leaves or joins the match
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnMatchPresence(IMatchPresenceEvent e)
 {
     if (e.Leaves.Count() > 0)
     {
         Debug.LogWarning($"OnMatchPresence() User(s) left the game");
         LeaveGame();
     }
 }
Esempio n. 4
0
 private void OnMatchPresence(object s, IMatchPresenceEvent presenceChange)
 {
     _connectedUsers.AddRange(presenceChange.Joins);
     foreach (var leave in presenceChange.Leaves)
     {
         _connectedUsers.RemoveAll(item => item.SessionId.Equals(leave.SessionId));
     }
     ;
 }
 /**
  * Eventhandler is called when the composition of the players in
  * the match has changed either by joining of new player or
  * of player left the match.
  */
 private void OnMatchPresence(object sender, IMatchPresenceEvent e)
 {
     Debug.Log("OnMatchPresence");
     _connectedUsers.AddRange(e.Joins);
     foreach (var leave in e.Leaves)
     {
         _connectedUsers.RemoveAll(item => item.SessionId.Equals(leave.SessionId));
     }
     ;
 }
Esempio n. 6
0
 private void OnMatchPresence(IMatchPresenceEvent presenceEvent)
 {
     foreach (var player in presenceEvent.Joins)
     {
         if (!HasPlayerAlreadyJoined(player))
         {
             NewPlayerJoined(player);
         }
     }
 }
Esempio n. 7
0
    private void _socket_OnMatchPresence(object sender, IMatchPresenceEvent e)
    {
        this.OnDebugMessage("Presences in match have changed!");

        foreach (var p in e.Joins)
        {
            this.OnDebugMessage(string.Format("Player {0} joins", p.UserId));
            AddActivePlayer(p);
        }
        List_Players(_presences);
        CheckPlayerLimitReached();
    }
Esempio n. 8
0
        private void HandleOtherPlayerJoin(IMatchPresenceEvent obj)
        {
            if (!obj.Joins.Any())
            {
                return;
            }

            string opponentId = obj.Joins.Select(join => join.UserId).First(id => id != _connection.Session.UserId);

            _connection.BattleConnection.OpponentId   = opponentId;
            _connection.Socket.ReceivedMatchPresence -= HandleOtherPlayerJoin;
            SetInitialPlayerState();
        }
Esempio n. 9
0
        private void NakamaServerOnMatchPresenceReceived(IMatchPresenceEvent presences)
        {
            foreach (var join in presences.Joins)
            {
                CreateEnemyInstance(join.UserId);
                GD.Print(join.Username, " Joined !");
            }

            foreach (var leave in presences.Leaves)
            {
                RemoveEnemyInstance(leave.UserId);
                GD.Print(leave.Username, " Left !");
            }
        }
        private void HandleOtherPlayerJoin(IMatchPresenceEvent obj)
        {
            Func <IUserPresence, bool> findOtherPlayer = join => join.UserId != _connection.Session.UserId;

            if (!obj.Joins.Any(findOtherPlayer))
            {
                return;
            }

            string opponentId = obj.Joins.First(findOtherPlayer).UserId;

            _connection.BattleConnection.OpponentId   = opponentId;
            _connection.Socket.ReceivedMatchPresence -= HandleOtherPlayerJoin;
            SetInitialPlayerState();
        }
    private void _socket_ReceivedMatchPresence(IMatchPresenceEvent presenceEvent)
    {
        foreach (IUserPresence presence in presenceEvent.Leaves)
        {
            _joinUsers.Remove(presence);
            commands.Add($"{presence.UserId} - <b><color=#ff0000ff>desconectado</color></b>");
        }

        foreach (IUserPresence presence in presenceEvent.Joins)
        {
            commands.Add($"{presence.UserId} - <b>conectado</b>");
        }

        _joinUsers.AddRange(presenceEvent.Joins);
        refreshJoinList = true;
    }
        private void OnMatchPresence(IMatchPresenceEvent e)
        {
            foreach (IUserPresence user in e.Joins)
            {
                if (Players.FindIndex(x => x.UserId == user.UserId) == -1)
                {
                    Debug.Log("User " + user.Username + " joined match");
                    Players.Add(user);

                    if (AllPlayersJoined)
                    {
                        StartGame();
                    }
                }
                else
                {
                    Debug.Log("Already found this player");
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Method fired when any user leaves or joins the match
        /// </summary>
        /// <param name="e"></param>
        private void OnMatchPresence(IMatchPresenceEvent e)
        {
            foreach (var user in e.Joins)
            {
                if (Sm.instance.Session.UserId == user.UserId)
                {
                    self = user;                                                // Set myself
                }
                // If user is not already in the list
                if (players.FindIndex(x => x.UserId == user.UserId) == -1)
                {
                    players.Add(user);
                    Debug.Log($"User {user.UserId} joined match {e.MatchId}");
                }
                else
                {
                    // User is already present in the game
                    // Two devices use the same account, this is not allowed
                    Debug.LogError("Two devices uses the same account, this is not allowed");
                    // TODO: kick him ?
                }
            }

            foreach (var user in e.Leaves)
            {
                if (players.FindIndex(x => x.UserId == user.UserId) != -1)
                {
                    Debug.Log($"User {user.UserId} left match");
                    players.Remove(user);
                }
                else
                {
                    // User is already present in the game
                    // Two devices use the same account, this is not allowed
                    Debug.LogError($"New user {user.UserId} tried to leave the game ? WTF ?");
                }
            }
        }
Esempio n. 14
0
    private void MatchPresence(IMatchPresenceEvent @event)
    {
        bool   consent;
        string users;

        lock (_users)
        {
            _users.RemoveAll(_ => @event.Leaves.Any(_1 => _.UserId.Equals(_1.UserId)));
            _users.AddRange(@event.Joins);

            // log
            users   = string.Join(", ", _users.Select(_ => _.Username));
            consent = IsConsent;
        }

        var joined = string.Join(", ", @event.Joins.Select(_ => _.Username));
        var leaved = string.Join(", ", @event.Leaves.Select(_ => _.Username));

        // TODO: network state switch

        Debug.Log($">> match diff-joins: [{joined}], leaves: [{leaved}]");
        Debug.Log($"users: {users}");
        Debug.Log(consent ? ">> start match" : ">> awaiting for players");
    }
 private void ActionReceivedMatchPresence(IMatchPresenceEvent m)
 {
     m_mainThread.Enqueue(() => OnReceivedMatchPresence(m));
 }