private void Awake()
    {
        current = this;

        SNet_Network.RegisterHandler("Auth_H", OnAuth_H);
        SNet_Network.RegisterHandler("Auth_V", OnAuth_V);
        SNet_Network.RegisterHandler("Auth_All", OnAuth_All);
    }
Ejemplo n.º 2
0
    // Use this for initialization
    private void Awake()
    {
        gameStatus = new SNet_Network.Game_Status(); // Reset the game status

        if (instance != null)
        {
            SNet_Auth.Init();
            Destroy(gameObject);
            return;
        }

        gameObject.name = "SteamManager";

        // This will always remain.
        DontDestroyOnLoad(gameObject);

        panel_Loading.Open();
        instance         = this;
        nextMemberUpdate = Time.time + 1;

        ///Register the main handlers

        SNet_Network.RegisterHandler("Spawn", OnSpawn);
        SNet_Network.RegisterHandler("Spawn_Request", OnSpawn_Request);
        SNet_Network.RegisterHandler("Spawn_Player", OnSpawn_Player);
        SNet_Network.RegisterHandler("Spawn_Item", OnSpawn_Item);
        SNet_Network.RegisterHandler("Game_Status", OnGame_Status);
        SNet_Network.RegisterHandler("Destroyed", OnDestroyed);
        SNet_Network.RegisterHandler("Impact", OnImpact);
        SNet_Network.RegisterHandler("A_Bool", OnA_Bool);
        SNet_Network.RegisterHandler("A_Float", OnA_Float);
        SNet_Network.RegisterHandler("A_Trigger", OnA_Trigger);
        SNet_Network.RegisterHandler("A_Int", OnA_Int);
        SNet_Network.RegisterHandler("RB", OnRB);
        SNet_Network.RegisterHandler("Pos", OnPos);
        SNet_Network.RegisterHandler("Rot", OnRot);
        SNet_Network.RegisterHandler("IS", OnIS);
        SNet_Network.RegisterHandler("PlayerItem", OnPlayerItem);
        SNet_Network.RegisterHandler("EquipItem", OnEquipItem);
        SNet_Network.RegisterHandler("A", OnA);
        SNet_Network.RegisterHandler("St", OnSt);
        SNet_Network.RegisterHandler("Health", OnHealth);
        SNet_Network.RegisterHandler("UserHit", OnUserHit);
        SNet_Network.RegisterHandler("Exploded", OnExploded);
        SNet_Network.RegisterHandler("V", OnV);
        SNet_Network.RegisterHandler("Interact", OnInteract);
        SNet_Network.RegisterHandler("VI", OnVI);
        SNet_Network.RegisterHandler("VH", OnVH);
        SNet_Network.RegisterHandler("CSRequest", OnCSRequest);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Draw lobby screen.
    /// </summary>
    public void OnLobbyUpdate()
    {
        List <ulong> members = Client.Instance.Lobby.GetMemberIDs().ToList();

        Debug.Log("OnLobbyUpdate(): Member count " + Client.Instance.Lobby.GetMemberIDs().Length);

        foreach (Transform t in lobbyMemberHolder)
        {
            if (!members.Contains(ulong.Parse(t.name)))
            {
                if (memberCount > 0)
                {
                    /*
                     * DISCONNECTED USER
                     * */
                    Transform conn = Instantiate(panel_Connections.transform.GetChild(0), panel_Connections.transform);
                    conn.GetComponentInChildren <Text>().text = t.GetComponentInChildren <Text>().text + " disconnected.";
                    conn.GetComponentInChildren <UnityEngine.UI.Image>().color = new UnityEngine.Color(1, 0.5f, 0.5f);
                    conn.gameObject.GetComponent <UIVisibility>().Open();

                    /*
                     */
                }

                Destroy(t.gameObject);
            }
        }

        int i = 0;

        foreach (ulong id in members)
        {
            if (lobbyMemberHolder.Find(id.ToString()))
            {
                continue; // already has
            }
            string    alias = Client.Instance.Friends.GetName(id);
            Transform t     = Instantiate(UIConnectedPlayer, lobbyMemberHolder);
            t.name = id.ToString();
            t.Find("avatar").GetComponent <Facepunch_Avatar>().Fetch(id);
            t.Find("name").GetComponent <Text>().text = alias;
            i++;

            if (SNet_Auth.current.validatedIds.Contains(id))
            {
                SNet_Auth.Validate(id);
            }

            if (memberCount > 0)
            {
                /*
                 * CONNECTED USER
                 * */
                Transform conn = Instantiate(panel_Connections.transform.GetChild(0), panel_Connections.transform);
                conn.GetComponentInChildren <Text>().text = t.GetComponentInChildren <Text>().text + " connected.";
                conn.GetComponentInChildren <UnityEngine.UI.Image>().color = new UnityEngine.Color(0.5f, 1f, 0.5f);
                conn.gameObject.AddComponent <DestroyIn>();
                conn.gameObject.SetActive(true);

                /*
                 */
            }
        }
    }
Ejemplo n.º 4
0
    public SNet_Network(GameObject receiver)
    {
        instance = this;

        Receiver = receiver;

        // Init voice
        SNet_Voice.instance.Init();

        Client.Instance.Networking.SetListenChannel(0, true); // Default game data
        Client.Instance.Networking.SetListenChannel(1, true); // Voice

        Client.Instance.Networking.OnP2PData = (steamid, bytes, length, channel) =>
        {
            if (channel == 1)
            {
                // Raw voice message
                SNet_Voice.instance.OnVM(bytes, length, steamid);
            }
            else
            {
                Incoming_Message(bytes, length, steamid);
            }
        };

        Client.Instance.Networking.OnIncomingConnection = (steamid) =>
        {
            Debug.Log("Incoming p2p connection from: " + steamid);

            /*
             * Only players in my lobby is allowed;
             * */
            return(Client.Instance.Lobby.GetMemberIDs().ToList().FindIndex(x => x == steamid) != -1);
        };

        Client.Instance.Networking.OnConnectionFailed = (steamid, error) =>
        {
            Debug.Log("Connection Error: " + steamid + " - " + error);
        };

        Client.Instance.Lobby.OnLobbyDataUpdated = () =>
        {
            Receiver.SendMessage("MemberUpdate");
        };

        Client.Instance.LobbyList.OnLobbiesUpdated = () =>
        {
            Debug.Log("Lobby count: " + Client.Instance.LobbyList.Lobbies.Count);

            Receiver.SendMessage("OnLobbyList");
        };

        Client.Instance.Lobby.OnLobbyJoined = (bool val) =>
        {
            Client.Instance.Lobby.SetMemberData("host", "false");

            Receiver.SendMessage("OnLobbyJoined", val);
        };

        Client.Instance.Lobby.OnLobbyCreated = (bool val) =>
        {
            Client.Instance.Lobby.SetMemberData("host", "false");

            Receiver.SendMessage("OnLobbyCreated", val);
        };

        Client.Instance.Lobby.OnChatStringRecieved = (steamid, text) =>
        {
            Debug.Log(steamid + " " + text);
        };

        SNet_Auth.Init();
        SNet_Controller.list.Clear();
    }