Esempio n. 1
0
    public void OnConnectPressed()
    {
        ClientVariables.SaveMainMenu();
        NetworkedMultiplayerENet peer = new NetworkedMultiplayerENet();
        Error result = peer.CreateClient(ClientVariables.NetworkOptions.IPAddress, ClientVariables.NetworkOptions.Port);

        if (result == Error.Ok)
        {
            GetTree().NetworkPeer = peer;
        }
    }
Esempio n. 2
0
    // Main menu network controls:
    public void OnHostPressed()
    {
        ClientVariables.SaveMainMenu();
        if (ClientVariables.NetworkOptions.UseUPNP)
        {
            UPNP            upnp     = new UPNP();
            UPNP.UPNPResult resultV4 = (UPNP.UPNPResult)upnp.Discover(2000, 2, "InternetGatewayDevice");
            if (resultV4 == UPNP.UPNPResult.Success)
            {
                GD.Print("Will attempt to add port-forward with upnp ip v4");
                upnp.AddPortMapping(ClientVariables.NetworkOptions.Port);
            }
            else
            {
                upnp.DiscoverIpv6 = true;
                UPNP.UPNPResult resultV6 = (UPNP.UPNPResult)upnp.Discover(2000, 2, "InternetGatewayDevice");
                if (resultV6 == UPNP.UPNPResult.Success)
                {
                    GD.Print("Will attemt to add port-forward with upnp ip v6");
                    upnp.AddPortMapping(ClientVariables.NetworkOptions.Port);
                }
            }
        }
        var   peer   = new NetworkedMultiplayerENet();
        Error result = peer.CreateServer(ClientVariables.NetworkOptions.Port);

        if (result == Error.Ok)
        {
            GetTree().NetworkPeer = peer;
            Global.GotoScene("res://Session/Session.tscn");
        }
        else
        {
            GD.Print(result);
            GD.Print("On port:" + ClientVariables.NetworkOptions.Port);
        }
    }