Пример #1
0
    public bool JoinGame(string address, string name)
    {
        if (address.Empty() || name.Empty())
        {
            EmitSignal(nameof(ErrorSignal), "Please enter a name and an address!");
            return(false);
        }
        GD.Print($"Joining game with address {address}");

        PlayerName    = name;
        ServerAddress = address;

        var clientPeer = new NetworkedMultiplayerENet();
        var result     = clientPeer.CreateClient(address, default_port);

        if (result != 0)
        {
            EmitSignal(nameof(ErrorSignal), $"Connection failed! ({result.ToString()})");
            return(false);
        }

        GetTree().NetworkPeer = clientPeer;
        EmitSignal(nameof(SuccessSignal), "Connecting...");

        return(true);
    }
Пример #2
0
    public void onClickJoin()
    {
        //get data
        string ip = lineIP.GetText();

        if (!int.TryParse(linePort.GetText(), out port))
        {
            port = 8920;
        }

        string name = lineName.GetText();

        if (name.Empty())
        {
            name = "NoName";
        }

        myData       = new DataPlayer(0, name); //data model example
        myData.color = new Random().Next(0, 3); //de 0,1,2

        //view
        panelStart.SetVisible(false);
        panelChat.SelfModulate = new Color(.2f, .2f, 0.5f);//blue style
        back.SetVisible(true);
        chat.BbcodeText = ("[color=purple]Connecting to " + ip + " : " + port + " ...[/color]");

        //CONNECTION
        var peer = new NetworkedMultiplayerENet();

        peer.CreateClient(ip, port);
        GetTree().SetNetworkPeer(peer);

        myData.id = GetTree().GetNetworkUniqueId();//get ID
    }
Пример #3
0
    public void ServerDisconnected()
    {
        Players.Clear();
        GetTree().NetworkPeer = null;

        var   clientPeer = new NetworkedMultiplayerENet();
        Error result     = 0;

        for (int i = 0; i < 10; i++)
        {
            result = clientPeer.CreateClient(ServerAddress, default_port);

            if (result != 0)
            {
                EmitSignal(nameof(ErrorSignal), $"Connection failed! ({result.ToString()})");
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                break;
            }
        }

        if (result == 0)
        {
            GetTree().NetworkPeer = clientPeer;
            EmitSignal(nameof(SuccessSignal), "Connecting...");
            return;
        }

        EmitSignal(nameof(ErrorSignal), "Disconnected from the server");
    }
Пример #4
0
    public void Connect(string IpString, string NickString)
    {
        if (IpString.Length == 0)
        {
            IpString = "127.0.0.1";
        }

        char[] NickArray = NickString.ToCharArray();
        NickArray  = Array.FindAll(NickArray, car => char.IsLetter(car) || car == '_');
        NickString = new string(NickArray);
        if (NickString.Length > 0)
        {
            Nickname = NickString;
        }

        var Peer = new NetworkedMultiplayerENet();

        Peer.CreateClient(IpString, Port);
        GetTree().NetworkPeer = Peer;

        RuntimeRoot.AddChild(WorldScene.Instance());

        DeathScreen = (Node)DeathScreenScene.Instance();
        RuntimeRoot.AddChild(DeathScreen);
    }
Пример #5
0
    private void onConnectPressed()
    {
        players = new List <Node>();
        peer    = new NetworkedMultiplayerENet();
        int    port    = System.Convert.ToInt32(panel.GetNode <TextEdit>("Port").Text);
        String address = panel.GetNode <TextEdit>("Address").Text;

        if (panel.GetNode <OptionButton>("OptionButton").GetSelectedId() == 0)
        {
            peer.CreateServer(port, maxPlayers);
            GetTree().SetNetworkPeer(peer);

            panel.changeToRed();
            players.Add(myself);
            myself = playerScene.Instance();
            myself.GetNode <RigidBody2D>("Ridiculous").Position = new Vector2(random.Next(20, 380), random.Next(100, 335));
            myself.SetNetworkMaster(GetTree().GetNetworkUniqueId());
            myself.SetName(GetTree().GetNetworkUniqueId().ToString());
            GetNode <Panel>("Panel").AddChild(myself);
        }
        else
        {
            peer.CreateClient(address, port);
            GetTree().SetNetworkPeer(peer);
            panel.changeToBlue();

            myself = playerScene.Instance();
            myself.GetNode <RigidBody2D>("Ridiculous").Position = new Vector2(random.Next(20, 380), random.Next(100, 335));
            myself.SetNetworkMaster(GetTree().GetNetworkUniqueId());
            myself.SetName(GetTree().GetNetworkUniqueId().ToString());
            GetNode <Panel>("Panel").AddChild(myself);
        }
    }
Пример #6
0
    public override void _Ready()
    {
        GetTree().Connect("network_peer_connected", this, "NetworkPeerConnected");
        GetTree().Connect("connected_to_server", this, "ConnectedServer");

        NetworkedMultiplayerENet peer = new NetworkedMultiplayerENet();

        _players = new Dictionary <int, Player>();

        Error err = peer.CreateServer(port, 2);

        GD.Print(err);

        if (err != 0)
        {
            GD.Print("Cliente");
            Error rr = peer.CreateClient(host, port);
            GetTree().SetNetworkPeer(peer);
            return;
        }

        GetTree().SetNetworkPeer(peer);

        int    unique = GetTree().GetNetworkUniqueId();
        string name   = GetTree().GetNetworkUniqueId().ToString();

        SpawnPlayer(unique, name);
    }
Пример #7
0
    public void ConnectTo(string InIp, int port)
    {
        //Set static string Ip
        NetworkedMultiplayerENet Peer = new NetworkedMultiplayerENet();

        Peer.CreateClient(InIp, port);
        GetTree().NetworkPeer = Peer;
    }
    //creates a peer and attempts to connect a server
    public void ConnectClient(string address, int port)
    {
        NetworkedMultiplayerENet peer = new NetworkedMultiplayerENet();

        peer.CompressionMode = NetworkedMultiplayerENet.CompressionModeEnum.Zlib;
        peer.CreateClient(address, port);
        GetTree().NetworkPeer = peer;
        GD.Print($"connecting to server {address}:{port}");
    }
Пример #9
0
 public void InitClient(string address, Godot.Object obj, string success, string fail)
 {
     GetTree().Connect("connected_to_server", obj, success);
     GetTree().Connect("connection_failed", obj, fail);
     peer = new Godot.NetworkedMultiplayerENet();
     peer.CreateClient(address, DefaultPort);
     this.GetTree().SetNetworkPeer(peer);
     selfPeerId = this.GetTree().GetNetworkUniqueId();
 }
Пример #10
0
        private void ConnectToServer()
        {
            _network = new NetworkedMultiplayerENet();
            _network.CreateClient(_ip, _port);
            GetTree().NetworkPeer = _network;

            _network.Connect("connection_failed", this, "_OnConnectionFailed");
            _network.Connect("connection_succeeded", this, "_OnConnectionSucceeded");
        }
Пример #11
0
    public static void ConnectTo(string InIp)
    {
        Ip = InIp;

        NetworkedMultiplayerENet Peer = new NetworkedMultiplayerENet();

        Peer.CreateClient(Ip, Port);
        Self.GetTree().SetNetworkPeer(Peer);
        Self.GetTree().SetMeta("network_peer", Peer);
    }
Пример #12
0
    public void joinGame(String IPAddress, String newName)
    {
        // Assign new data
        playerName = newName;

        // Create client
        NetworkedMultiplayerENet host = new NetworkedMultiplayerENet();

        host.CreateClient(IPAddress, PORT);
        GetTree().NetworkPeer = host;
    }
Пример #13
0
    public void JoinGame()
    {
        var address = AddressText.Text;

        GD.Print($"Joining game with address {address}");

        var clientPeer = new NetworkedMultiplayerENet();
        var result     = clientPeer.CreateClient(address, default_port);

        GetTree().NetworkPeer = clientPeer;
    }
Пример #14
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;
        }
    }
Пример #15
0
    private void JoinGame()
    {
        GD.Print("Joining network");
        HideAll();
        label.Text = "Joining Game";

        NetworkedMultiplayerENet host = new NetworkedMultiplayerENet();

        host.CreateClient(hostip.Text, PORT_NUM);
        GetTree().SetNetworkPeer(host);
    }
Пример #16
0
        /// <summary>
        /// Creates a client.
        /// Will silently replace any pre-existing peer without performing any shutdown/cleanup logic.
        /// </summary>
        /// <returns>
        /// The return value from CreateClient().
        /// `Error.Ok` signifies that the client was created and bounded.
        /// </returns>
        public static Error StartClient(this SceneTree tree, string host, int port)
        {
            var peer = new NetworkedMultiplayerENet();
            var err  = peer.CreateClient(host, port);

            if (err != Error.Ok)
            {
                return(err);
            }
            tree.NetworkPeer = peer;
            return(Error.Ok);
        }
Пример #17
0
    public void joinServer(String ip, int port)
    {
        hostType = "Client";
        NetworkedMultiplayerENet peer = new NetworkedMultiplayerENet();

        if (peer.CreateClient(ip, port) != Error.Ok)
        {
            EmitSignal(nameof(JoinFailSignal));
            return;
        }
        GetTree().NetworkPeer = peer;
    }
Пример #18
0
    public static void ConnectTo(string InIp)
    {
        //Set static string Ip
        Ip = InIp;

        NetworkedMultiplayerENet Peer = new NetworkedMultiplayerENet();

        Peer.CreateClient(Ip, Port);
        Self.GetTree().SetNetworkPeer(Peer);

        IsWaitingForServer = true;
    }
Пример #19
0
        public void StartClient(string host = "127.0.0.1")
        {
            peer = new NetworkedMultiplayerENet();
            peer.CreateClient(host, port);
            tree.NetworkPeer = peer;

            main = this;

            //Intialize signal connects
            tree.Connect("connected_to_server", this, "ConnectedToServer");
            tree.Connect("connection_failed", this, "ConnectionFailed");
            tree.Connect("server_disconnected", this, "ServerDisconnected");
        }
Пример #20
0
    // Join a server
    public void JoinGame(string name, string ip_address)
    {
        ClientMessageManager cmm = new ClientMessageManager();

        // Store own player name
        self_data[0] = name;

        // Initializing the network as server
        var host = new NetworkedMultiplayerENet();

        host.CreateClient(ip_address, SERVER_PORT);
        GetTree().NetworkPeer = host;
    }
Пример #21
0
    public void joinServer(String ip, int port)
    {
        hostType = "Client";
        NetworkedMultiplayerENet peer = new NetworkedMultiplayerENet();

        peer.CompressionMode = NetworkedMultiplayerENet.CompressionModeEnum.Zstd;

        if (peer.CreateClient(ip, port) != Error.Ok)
        {
            EmitSignal(nameof(JoinFailSignal), "JOIN SERVER AT " + ip + ":" + port + " FAIL. PLEASE CHECK DETAIL AND TRY AGAIN.");
            return;
        }

        GetTree().NetworkPeer = peer;
    }
Пример #22
0
    private void OnJoinPressed()
    {
        string ip = _address.Text;

        if (!ip.IsValidIPAddress())
        {
            SetStatus("IP address is invalid", false);
            return;
        }

        _peer = new NetworkedMultiplayerENet();
        _peer.CompressionMode = NetworkedMultiplayerENet.CompressionModeEnum.RangeCoder;
        _peer.CreateClient(ip, DefaultPort);
        GetTree().NetworkPeer = _peer;
        SetStatus("Connecting...", true);
    }
Пример #23
0
    private void OnJoinPressed()
    {
        string IP = Address.Text;

        if (!IP.IsValidIPAddress())
        {
            SetStatus("IP Address is invalid", false);
            return;
        }

        NetworkedMultiplayerENet Host = new NetworkedMultiplayerENet();

        Host.CompressionMode = NetworkedMultiplayerENet.CompressionModeEnum.RangeCoder;
        Host.CreateClient(IP, Port);
        GetTree().NetworkPeer = Host;

        SetStatus("Connecting...", true);
    }
        public async Task Test()
        {
            var server          = new NetworkedMultiplayerENet();
            var boolEvent       = AwaitResponse(LanBoolEvent, (bool payload) => payload);
            var stringEvent     = AwaitResponse(LanStringEvent, (string payload) => payload == "true");
            var intEvent        = AwaitResponse(LanIntEvent, (int payload) => payload == 1);
            var floatEvent      = AwaitResponse(LanFloatEvent, (float payload) => payload == 1.0f);
            var serializedEvent =
                AwaitResponse(LanSerializedEvent, (SerializedClass payload) => payload.Field == "true");
            var error = server.CreateClient("127.0.0.1", ServerPort);

            Assertions.AssertTrue(error == Error.Ok, "Connection without errors");
            GetTree().NetworkPeer = server;
            var results = await Task.WhenAll(
                boolEvent, stringEvent, intEvent, floatEvent, serializedEvent);

            Assertions.AssertTrue(results.All(result => result), "All Lan events done");
        }
Пример #25
0
    /// <summary>
    /// Join an existing game by address and port
    /// </summary>
    /// <param name="address"></param>
    /// <param name="port"></param>
    public void JoinGame(String address, int port)
    {
        // hook up to client specific network events
        GetTree().Connect("server_disconnected", this, nameof(OnServerDisconnected));
        GetTree().Connect("connected_to_server", this, nameof(OnConnectedToServer));
        GetTree().Connect("connection_failed", this, nameof(OnConnectionFailed));

        var peer  = new NetworkedMultiplayerENet();
        var error = peer.CreateClient(address, port);

        if (error != Error.Ok)
        {
            GD.PrintErr($"Failed to connect to server: {address}:{port} Error: {error.ToString()}");
            return;
        }
        GetTree().NetworkPeer = peer;

        GD.Print($"Joined game at {address}:{port}");
    }
Пример #26
0
        public Client(SceneTree _tree, string host, int _port = 7777)
        {
            Name = "Network";
            if (tree == null)
            {
                tree = _tree;
            }
            port = _port;

            peer = new NetworkedMultiplayerENet();
            peer.CreateClient(host, port);
            tree.NetworkPeer = peer;

            main = this;

            //Intialize signal connects
            tree.Connect("connected_to_server", this, "ConnectedToServer");
            tree.Connect("connection_failed", this, "ConnectionFailed");
            tree.Connect("server_disconnected", this, "ServerDisconnected");
        }
Пример #27
0
        public override void _Ready()
        {
            LOG = new Logger(this.GetType().Name);
            PackedScene dispatcherPackedScene = GD.Load("res://src/network/PacketDispatcher.tscn") as PackedScene;

            dispatcher = (PacketDispatcher)dispatcherPackedScene.Instance();
            AddChild(dispatcher);

            PlayerName = GetNode <Godot.LineEdit>("/root/FeudalMP/UI/Control/HBoxContainer/CenterContainer/VBoxContainer/name/LineEdit").Text;
            string ip   = GetNode <Godot.LineEdit>("/root/FeudalMP/UI/Control/HBoxContainer/CenterContainer/VBoxContainer/ip/LineEdit").Text;
            int    port = System.Int32.Parse(GetNode <Godot.LineEdit>("/root/FeudalMP/UI/Control/HBoxContainer/CenterContainer/VBoxContainer/port/LineEdit").Text);

            RegisterClientCallbacks();
            ENetInstance = new NetworkedMultiplayerENet();
            ENetInstance.CreateClient(ip, port);
            GetTree().NetworkPeer = ENetInstance;

            ENetInstance.Connect("connection_failed", this, "receive_connection_failed");
            ENetInstance.Connect("connection_succeeded", this, "receive_connection_succeeded");
            ENetInstance.Connect("server_disconnected", this, "receive_server_disconnected");
        }
Пример #28
0
        public bool StartClient(string Address, int Port)
        {
            NetworkedMultiplayerENet peer = new NetworkedMultiplayerENet();

            peer.Connect("connection_succeeded", this, nameof(ClientOnConnected));
            peer.Connect("connection_failed", this, nameof(ClientOnFailedToConnect));
            peer.Connect("server_disconnected", this, nameof(ClientOnServerDisconnect));
            ConfigurePeer(peer);

            Error error   = peer.CreateClient(Address, Port);
            bool  Success = error == Error.Ok;

            MDLog.CLog(Success, LOG_CAT, MDLogLevel.Info, $"Connecting to server at {Address}:{Port}");
            MDLog.CLog(!Success, LOG_CAT, MDLogLevel.Error, $"Failed to connect to server at {Address}:{Port}");

            if (Success)
            {
                SetNetworkPeer(peer);
            }

            return(Success);
        }
Пример #29
0
    public void InitClient(string address, Godot.Object obj, string success, string peerJoin, string fail, string port = "")
    {
        isServer = false;
        GetTree().Connect("connected_to_server", obj, success);
        GetTree().Connect("connection_failed", obj, fail);
        GetTree().Connect("network_peer_connected", obj, peerJoin);

        int usedPort = DefaultPort;

        int customPort = 0;

        if (port != "" && Int32.TryParse(port, out customPort))
        {
            usedPort = customPort;
        }

        peer = new Godot.NetworkedMultiplayerENet();
        peer.CreateClient(address, usedPort);

        this.GetTree().SetNetworkPeer(peer);
        selfPeerId = this.GetTree().GetNetworkUniqueId();
    }
Пример #30
0
    public static void ConnectTo(string InIp)
    {
        if (Self.GetTree().NetworkPeer != null)
        {
            if (Self.GetTree().IsNetworkServer())
            {
                Console.Print("Error: Cannot connect when hosting");
            }
            else
            {
                Console.Print("Error: Cannot connect when already connected to a server");
            }
            return;
        }

        //Set static string Ip
        Ip = InIp;

        NetworkedMultiplayerENet Peer = new NetworkedMultiplayerENet();

        Peer.CreateClient(Ip, Port);
        Self.GetTree().SetNetworkPeer(Peer);
    }