// generate MPBanEntry from a PlayerLobbyData
 public MPBanEntry(PlayerLobbyData p)
 {
     if (p != null)
     {
         Set(p.m_name, p.m_id, p.m_player_id);
     }
 }
        // Find the best match for a player
        // Search the active players in the lobby
        // May return null if no match can be found
        public PlayerLobbyData FindPlayerInLobby(string pattern)
        {
            if (String.IsNullOrEmpty(pattern))
            {
                return(null);
            }

            int             bestScore  = -1000000000;
            PlayerLobbyData bestPlayer = null;

            pattern = pattern.ToUpper();

            foreach (KeyValuePair <int, PlayerLobbyData> p in NetworkMatch.m_players)
            {
                int score = MatchPlayerName(p.Value.m_name.ToUpper(), pattern);
                if (score > 0)
                {
                    return(p.Value);
                }
                if (score < 0 && score > bestScore)
                {
                    bestScore  = score;
                    bestPlayer = p.Value;
                }
            }
            if (bestPlayer == null)
            {
                Debug.LogFormat("CHATCMD: did not find a player matching {0}", pattern);
            }
            return(bestPlayer);
        }
 // Kicks an Player in Lobby State
 public static void KickPlayer(PlayerLobbyData p, bool banned = false)
 {
     if (p != null)
     {
         KickPlayer(p.m_id, p.m_name, banned);
     }
 }
    private void OnPlayerRemoved(PlayerLobbyData playerData)
    {
        Debug.LogFormat("P{0} Dropped", playerData.m_PlayerIndex + 1);

        UILobbyPlayerLabel label = m_PlayerLabels[playerData.m_PlayerIndex];

        label.AnimateShow(false);
    }
    private void OnPlayerAdded(PlayerLobbyData playerData)
    {
        Debug.LogFormat("P{0} Joined", playerData.m_PlayerIndex + 1);

        UILobbyPlayerLabel label = m_PlayerLabels[playerData.m_PlayerIndex];

        label.Init(playerData);
        label.AnimateShow(true);
    }
Beispiel #6
0
    private void AddPlayer(PlayerLobbyData data)
    {
        SetPlayerData(data);

        // notify UI
        if (OnPlayerAdded != null)
        {
            OnPlayerAdded(data);
        }
    }
Beispiel #7
0
    private void RemovePlayer(PlayerLobbyData data)
    {
        // notify UI
        if (OnPlayerRemoved != null)
        {
            OnPlayerRemoved(data);
        }

        ClearPlayerData(data);
    }
Beispiel #8
0
    public void RequestAddPlayer(int playerId, CharacterProgress progress)
    {
        // TODO
        // when the networking stuff goes in...
        // when the player (client) requests to join, acknowledge from server, then client sends player display data.
        // server gets it, sends it out to all clients

        // for local multiplayer, will need to load all existing player saves and allow them to pick one. That will get populated below.

        string          playerName = progress.m_Stats.PlayerName;
        int             saveSlot   = progress.m_SaveSlot;
        PlayerLobbyData data       = new PlayerLobbyData(playerId, saveSlot, playerName, m_TeleportTransforms[playerId], m_PlayerColors[playerId]);

        AddPlayer(data); // send me to everyone!
    }
Beispiel #9
0
    private void ClearPlayerData(PlayerLobbyData data)
    {
        int playerIndex = data.m_PlayerIndex;

        m_ConnectedPlayerCount -= 1;

        // TODO
        // remove character
        // some sort of cool particle or shader effect here
        // for networking, will need to disconnect a player
        Destroy(data.m_PlayerModelObj);

        m_PlayerRingMeshes[playerIndex].material.color = m_DefaultColor;
        m_PlayerData[playerIndex] = null;
    }
Beispiel #10
0
    private void SetPlayerData(PlayerLobbyData data)
    {
        int playerIndex = data.m_PlayerIndex;

        m_ConnectedPlayerCount += 1;

        // TODO
        // spawn character on pad
        // some sort of cool particle or shader effect here
        GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Capsule);

        temp.transform.position = data.m_PadTransform.position + Vector3.up;
        temp.layer            = LayerMask.NameToLayer("UI");
        data.m_PlayerModelObj = temp;

        // change pad color
        m_PlayerRingMeshes[playerIndex].material.color = data.m_PlayerColor;
        m_PlayerData[playerIndex] = data;
    }
 // Select a player by a pattern
 public bool SelectPlayer(string pattern)
 {
     selectedPlayerEntry        = null;
     selectedPlayer             = null;
     selectedPlayerLobbyData    = null;
     selectedPlayerConnectionId = -1;
     if (inLobby)
     {
         selectedPlayerLobbyData = FindPlayerInLobby(pattern);
         if (selectedPlayerLobbyData != null)
         {
             selectedPlayerEntry        = new MPBanEntry(selectedPlayerLobbyData);
             selectedPlayerConnectionId = selectedPlayerLobbyData.m_id;
             if (selectedPlayerConnectionId >= NetworkServer.connections.Count)
             {
                 selectedPlayerConnectionId = -1;
             }
             return(true);
         }
     }
     else
     {
         selectedPlayer = FindPlayer(pattern);
         if (selectedPlayer != null)
         {
             selectedPlayerEntry        = new MPBanEntry(selectedPlayer);
             selectedPlayerConnectionId = (selectedPlayer.connectionToClient != null)?selectedPlayer.connectionToClient.connectionId:-1;
             if (selectedPlayerConnectionId >= NetworkServer.connections.Count)
             {
                 selectedPlayerConnectionId = -1;
             }
             return(true);
         }
     }
     return(false);
 }
    public void Init(PlayerLobbyData data)
    {
        m_Label.text = data.m_PlayerName;

        this.gameObject.SetActive(true);
    }
Beispiel #13
0
    public void RequestRemovePlayer(int playerId)
    {
        PlayerLobbyData data = m_PlayerData[playerId];

        RemovePlayer(data);
    }
Beispiel #14
0
    protected override void OnInputUpdate(InputActionEventData data)
    {
        if (ScreenInputLocked())
        {
            return;                      // can be controller by any player
        }
        bool handled = false;

        // this is ugly
        if (m_CharacterSelectors[data.playerId].m_IsActive)
        {
            handled = m_CharacterSelectors[data.playerId].OnInputUpdate(data);
            if (handled)
            {
                return;
            }
        }

        switch (data.actionId)
        {
        case RewiredConsts.Action.Y_Action:
            if (data.GetButtonDown())
            {
                string     popupTitle   = string.Format("P{0}", data.playerId + 1);
                string     popupContent = "Would you like to create a new character?";
                ePopupType popupType    = ePopupType.YesNo;
                PopupManager.Instance.ShowPopup(popupType, popupTitle, popupContent, OnCharacterCreationPopupClosed);

                // save which player opened it
                m_CreatorPlayerID = data.playerId;

                handled = true;
            }
            break;

        case RewiredConsts.Action.Confirm:
            if (data.GetButtonDown())
            {
                if (data.playerId == 0 && LobbyManager.Instance.AllPlayersReady && !AnyCharacterSelectorOpen())     // TODO only server/host should be able to advance
                {
                    string     popupTitle   = "Continue";
                    string     popupContent = "Are you ready?";
                    ePopupType popupType    = ePopupType.YesNo;
                    PopupManager.Instance.ShowPopup(popupType, popupTitle, popupContent, OnContinuePopupClosed);
                }
                else
                {
                    int             playerId   = data.playerId;
                    PlayerLobbyData playerData = LobbyManager.Instance.GetLobbyDataForPlayer(playerId);
                    if (playerData != null)
                    {
                        if (!playerData.m_Confirmed)
                        {
                            // player data exists, ready up
                            LobbyManager.Instance.SetConfirmed(playerId, true);
                            Debug.LogFormat("P{0} Ready", playerId + 1);
                        }
                    }
                    else
                    {
                        // no player exists, open the character selector
                        if (!m_CharacterSelectors[data.playerId].m_IsActive)
                        {
                            m_CharacterSelectors[data.playerId].SetIsActive(true);
                        }
                    }
                }

                handled = true;
            }
            break;

        case RewiredConsts.Action.Cancel:
            if (data.GetButtonDown())
            {
                int             playerId   = data.playerId;
                PlayerLobbyData playerData = LobbyManager.Instance.GetLobbyDataForPlayer(playerId);
                if (playerData != null)
                {
                    if (playerData.m_Confirmed)
                    {
                        // player is ready, un-ready them
                        LobbyManager.Instance.SetConfirmed(playerId, false);
                        Debug.LogFormat("P{0} Un-ready", playerId + 1);
                    }
                    else
                    {
                        if (playerId == 0)     // need to change this to a host player id check
                        {
                            string     popupTitle   = "Exit";
                            string     popupContent = "Are you sure you want to leave the lobby?";
                            ePopupType popupType    = ePopupType.YesNo;
                            PopupManager.Instance.ShowPopup(popupType, popupTitle, popupContent, OnExitPopupClosed);
                        }
                        else
                        {
                            // player wants to drop out
                            LobbyManager.Instance.RequestRemovePlayer(playerId);

                            // need to add back in the character data from any player who backed out
                            ShowCharacterInList(m_CharacterList[playerId]);
                        }
                    }
                }

                handled = true;
            }
            break;
        }

        // pass to base
        if (!handled)
        {
            base.OnInputUpdate(data);
        }
    }