void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.LoopbackIpv4; // Set an endpoint to AnyIpv4 (Grab the IP of the machine which is running on)

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort); // If it doesn't bind, Log it
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent); // Initialize a connection list, create a list of 16 end systems.

        StartCoroutine(SendHandshakeToAllClient());
    }
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);

        otherPlayers = new Dictionary <string, GameObject>();

        // Init player
        playerUpdateMsg = new PlayerUpdateMsg();
        playerUpdateMsg.player.cubeColor = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
        yourCharacter = Instantiate(playerPrefab);

        yourCharacter.GetComponent <Renderer>().material.color = playerUpdateMsg.player.cubeColor;
        yourCharacter.AddComponent <CharacterMovement>();
        playerUpdateMsg.player.cubPos = yourCharacter.transform.position;
    }
Ejemplo n.º 3
0
        // these are all 7 message type events. Every Message Type has its own event that it listens to.
        // e.g. the setname message type is ServerCallbacks[(int)MessageHeader.MessageType.SetName)]. I can add functions to this event that need to be
        // invoked when I receive a message of the setname type.
        #endregion

        public void ServerStart(string ipAdress)
        {
            // Create network connection
            networkDriver = NetworkDriver.Create();
            var endpoint = NetworkEndPoint.LoopbackIpv4;

            endpoint.Port = 9000;

            // override if playing online
            if (ipAdress != "")
            {
                endpoint = NetworkEndPoint.Parse(ipAdress, 9000);
            }


            if (networkDriver.Bind(endpoint) != 0)
            {
                Debug.Log("Failed to bind port");
            }
            else
            {
                networkDriver.Listen();
            }

            connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

            // Initialize MessageQueue and All ServerCallback Events
            messagesQueue = new Queue <MessageConnection>();
            for (int i = 0; i < ServerCallbacks.Length; i++)
            {
                ServerCallbacks[i] = new MessageEvent(); // Instantiate all Message Type events.
            }

            // Add event listeners
            #region Lobby Event Listeners
            ServerCallbacks[(int)MessageHeader.MessageType.SetName].AddListener(HandleSetName); // this is how we would add a function to the Setname event.
            ServerCallbacks[(int)MessageHeader.MessageType.PlayerLeft].AddListener(HandlePlayerLeft);
            ServerCallbacks[(int)MessageHeader.MessageType.StartGame].AddListener(HandleStartGame);
            ServerCallbacks[(int)MessageHeader.MessageType.None].AddListener(HandleNone); // the optional one to keep the connection going in inactivity
            #endregion
            doneInitializing = true;
        }
    void Start()
    {
        dataHolder        = GetComponent <DataHolder>();
        dataHolder.client = this;

        networkDriver = NetworkDriver.Create();
        connection    = default;

        if (Tools.LOCAL)
        {
            var endpoint = NetworkEndPoint.LoopbackIpv4;
            endpoint.Port = 9000;
            connection    = networkDriver.Connect(endpoint);
        }
        else
        {
            var endpoint = NetworkEndPoint.Parse(Tools.IP, 9000);
            connection = networkDriver.Connect(endpoint);
        }
    }
Ejemplo n.º 5
0
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections      = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        m_connectedClients = new Dictionary <string, NetworkObjects.NetworkPlayer>();

        StartCoroutine(SendPositionsToClients(0.2f));
    }
    private Dictionary <string, NetworkObjects.NetworkPlayer> PlayersConnected = new Dictionary <string, NetworkObjects.NetworkPlayer>(); //Dictionary for all clients

    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }
        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        //Easier than Ienumerator. From Assignment 1.
        //Send updates to clients
        InvokeRepeating("UpdateAllClients", 0.1f, 0.1f);
    }
Ejemplo n.º 7
0
    void Start()
    {
        //***
        N_Player = new List <NewPlayer>();

        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
    }
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("[Server] Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        m_ClientIds   = new Dictionary <NetworkConnection, string>();

        UnitBase.IsRunOnServer = true;
    }
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        //StartCoroutine(SendHandshakeToAllClient());
        StartCoroutine(SendUpdateToAllClient());
    }
    void Start()  //done
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        InvokeRepeating("SendAllClientStats", 0.1f, 0.008f);
        InvokeRepeating("ChangeColors", 2.0f, 1.0f);
    }
    private float maxDistance = 45; // the furthest the player could be from a mine

    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }
        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        allMinePositions = mineManager.minePositions;
        InvokeRepeating("SendAllInfo", 0.1f, 0.166f);
        InvokeRepeating("ChangeCubeColours", 0.1f, 0.166f);
    }
Ejemplo n.º 12
0
    private Dictionary <string, NetworkObjects.NetworkPlayer> ConnectedPlayers = new Dictionary <string, NetworkObjects.NetworkPlayer>(); //Dictionary for all clients

    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        // updates every sec 10 times
        InvokeRepeating("UpdatePlayerInfo", 0.1f, 0.1f);
    }
Ejemplo n.º 13
0
    void Start()
    {
        DontDestroyOnLoad(this);

        allEvents.AssignIDs();
        driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 9000;
        if (driver.Bind(endpoint) != 0)
        {
            Debug.Log("Server | Failed to bind to port 9000");
        }
        else
        {
            driver.Listen();
        }

        connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
    }
Ejemplo n.º 14
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this);
        }

        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);

        var endpoint = NetworkEndPoint.Parse(IP, Port);

        m_Connection = m_Driver.Connect(endpoint);

        players = new Dictionary <string, GameObject>();
    }
Ejemplo n.º 15
0
    void Start()
    {
        ushort serverPort = 9000;

        // Create the server driver, bind it to a port and start listening for incoming connections
        m_ServerDriver = NetworkDriver.Create();
        var addr = NetworkEndPoint.AnyIpv4;

        addr.Port = serverPort;
        if (m_ServerDriver.Bind(addr) != 0)
        {
            Debug.Log($"Failed to bind to port {serverPort}");
        }
        else
        {
            m_ServerDriver.Listen();
        }

        m_connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
    }
Ejemplo n.º 16
0
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        m_Players     = new List <NetworkObjects.NetworkPlayer>(16);

        InvokeRepeating("serverUpdate", 0.1f, 0.1f);
    }
Ejemplo n.º 17
0
    void Start()
    {
        // Create the NetworkDriver.
        Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = 9000;
        if (Driver.Bind(endpoint) != 0)
        {
            Debug.LogWarning("failed to bind to port 9000");
        }
        else
        {
            Driver.Listen();
        }

        connections = new NativeList <NetworkConnection>(2, Allocator.Persistent);

        ServerNumber.SetText("Server number: " + Main.Instance.CurrentServer.ServerID);
        Main.Instance.ServerBuild = true;
    }
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        players = new List <NetworkObjects.NetworkPlayer>();

        StartCoroutine("SendToAllPlayer");
    }
Ejemplo n.º 19
0
    void Start()
    {
        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);

        otherPlayers = new Dictionary <string, GameObject>();


        playerUpdateMsg = new PlayerUpdateMsg();
        playerUpdateMsg.player.cubeColor = new Color(
            UnityEngine.Random.Range(0.0f, 1.0f),
            UnityEngine.Random.Range(0.0f, 1.0f),
            UnityEngine.Random.Range(0.0f, 1.0f));

        playerController = Instantiate(cube);
        playerController.AddComponent <PlayerControls>();
        playerUpdateMsg.player.cubPos = playerController.transform.position;
    }
Ejemplo n.º 20
0
    public void Start()
    {
        m_Connections  = new NativeList <SoakClientCtx>(1, Allocator.Persistent);
        m_ServerDriver = NetworkDriver.Create(new ReliableUtility.Parameters {
            WindowSize = 32
        });
        //m_Pipeline = m_ServerDriver.CreatePipeline(typeof(UnreliableSequencedPipelineStage));
        m_Pipeline        = m_ServerDriver.CreatePipeline(typeof(ReliableSequencedPipelineStage));
        m_ReliableStageId = NetworkPipelineStageCollection.GetStageId(typeof(ReliableSequencedPipelineStage));
        var addr = NetworkEndPoint.AnyIpv4;

        addr.Port = 9000;
        if (m_ServerDriver.Bind(addr) != 0)
        {
            Debug.Log("Failed to bind to port 9000");
        }
        else
        {
            m_ServerDriver.Listen();
        }
    }
Ejemplo n.º 21
0
        public void CreateServerDriver(World world, out NetworkDriver driver, out NetworkPipeline unreliablePipeline, out NetworkPipeline reliablePipeline)
        {
            var reliabilityParams = new ReliableUtility.Parameters {
                WindowSize = 32
            };

#if UNITY_EDITOR || DEVELOPMENT_BUILD
            var netParams = new NetworkConfigParameter
            {
                maxConnectAttempts  = NetworkParameterConstants.MaxConnectAttempts,
                connectTimeoutMS    = NetworkParameterConstants.ConnectTimeoutMS,
                disconnectTimeoutMS = NetworkParameterConstants.DisconnectTimeoutMS,
                maxFrameTimeMS      = 100
            };
            driver = NetworkDriver.Create(netParams, reliabilityParams);
#else
            driver = NetworkDriver.Create(reliabilityParams);
#endif

            unreliablePipeline = driver.CreatePipeline(typeof(NullPipelineStage));
            reliablePipeline   = driver.CreatePipeline(typeof(ReliableSequencedPipelineStage));
        }
Ejemplo n.º 22
0
    private void Start()
    {
        InitializePacketHandlers();

        driver = NetworkDriver.Create();
        var endPoint = NetworkEndPoint.AnyIpv4;

        endPoint.Port = 9000;

        if (driver.Bind(endPoint) != 0)
        {
            Debug.Log($"Failed to bind to port {endPoint}");
        }
        else
        {
            driver.Listen();
        }

        connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        ServerSend.Initialize(driver);
    }
    void Start()
    {
        d_Connections = new Dictionary <string, NetworkConnection>();
        m_Driver      = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        //StartCoroutine(SendLoginWebRequest("kevin2", "test1", 0));
        //StartCoroutine(SendRegisterWebRequest("kevin3", "test1", 0));
        //StartCoroutine(SendHandshakeToAllClient());
        //StartCoroutine(SendUpdateToAllClient());
    }
Ejemplo n.º 24
0
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        cubePrefab = (GameObject)Resources.Load("Prefabs/Cube");

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);
        Debug.Log("Server Started");

        StartCoroutine(SendHandshakeToAllClient());
    }
Ejemplo n.º 25
0
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);



        // repeat broadcast to all clients
        InvokeRepeating("SendToClient", 1, 1.0f / 60.0f);
    }
Ejemplo n.º 26
0
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        plMsg       = new PlayerListMsg();
        msgInterval = new List <float>();

        InvokeRepeating("SendPosition", 1, 0.033f);
    }
Ejemplo n.º 27
0
    void Start()
    {
        m_Driver = NetworkDriver.Create();
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        matchedRooms.Add(1111);
        matchedRooms.Add(2222);
        matchedRooms.Add(3333);
        matchedRooms.Add(4444);
    }
    float intervalOfChangeColorOfPlayers = 1f; //every 1 seconds change color of players

    void Start()
    {
        m_Driver = NetworkDriver.Create(); // just makes sure you are creating your driver without any parameters.
        var endpoint = NetworkEndPoint.AnyIpv4;

        endpoint.Port = serverPort;

        //Then we try to bind our driver to a specific network address and port, and if that does not fail, we call the Listen method.
        //Important: the call to the Listen method sets the NetworkDriver to the Listen state.This means that the NetworkDriver will now actively listen for incoming connections.
        if (m_Driver.Bind(endpoint) != 0)
        {
            Debug.Log("Failed to bind to port " + serverPort);
        }
        else
        {
            m_Driver.Listen();
        }

        //Finally we create a NativeList to hold all the connections.
        m_Connections = new NativeList <NetworkConnection>(16, Allocator.Persistent);

        //InvokeRepeating("SendAllPlayerInfoToClinet", 0, 1.0f);
    }
Ejemplo n.º 29
0
    void Start()
    {
        Debug.Log("Initialized.");
        loginInfo = GameObject.FindGameObjectWithTag("Login").GetComponent <Script_Login>();

        if (loginInfo.serverIP.Length > 5)
        {
            if (loginInfo.serverIP == "localhost")
            {
                serverIP = "127.0.0.1";
            }
            else
            {
                serverIP = loginInfo.serverIP;
            }
        }

        m_Driver     = NetworkDriver.Create();
        m_Connection = default(NetworkConnection);
        var endpoint = NetworkEndPoint.Parse(serverIP, serverPort);

        m_Connection = m_Driver.Connect(endpoint);
    }
Ejemplo n.º 30
0
    // -- lifecycle --
    private void Start()
    {
        mDriver = NetworkDriver.Create(new NetworkConfigParameter {
            connectTimeoutMS    = 1000,
            maxConnectAttempts  = 3,
            disconnectTimeoutMS = int.MaxValue,
            maxFrameTimeMS      = 0,
        });

        mConnection = new NativeArray <NetworkConnection>(1, Allocator.Persistent);
        mEvents     = new NativeList <AnyEvent>(10, Allocator.Persistent);

        var endpoint = NetworkEndPoint.Parse(mSession.HostIp, Config.kPort);

        if (endpoint == default)
        {
            endpoint      = NetworkEndPoint.LoopbackIpv4;
            endpoint.Port = Config.kPort;
        }

        mConnection[0] = mDriver.Connect(endpoint);
        Log.I($"Client - connecting to {endpoint.Address}");
    }