Пример #1
0
        public bool StartServer(int Port, int MaxPlayers = DEFAULT_MAX_PLAYERS)
        {
            NetworkedMultiplayerENet peer = new NetworkedMultiplayerENet();

            peer.Connect("peer_connected", this, nameof(ServerOnPeerConnected));
            peer.Connect("peer_disconnected", this, nameof(ServerOnPeerDisconnected));
            ConfigurePeer(peer);

            Error error   = peer.CreateServer(Port, MaxPlayers);
            bool  Success = error == Error.Ok;

            MDLog.CLog(Success, LOG_CAT, MDLogLevel.Info,
                       $"Starting server on port {Port} with {MaxPlayers} max players.");
            MDLog.CLog(!Success, LOG_CAT, MDLogLevel.Error, $"Failed to start server on port {Port}");

            if (Success)
            {
                UPNPPort = Port;
                SetNetworkPeer(peer);
                ServerOnStarted();
            }
            else
            {
                MDLog.Error(LOG_CAT, "Failed to start server");
                OnSessionFailedEvent();
            }

            return(Success);
        }
Пример #2
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");
        }
Пример #3
0
        private void StartServer()
        {
            _network.CreateServer(_port, _max_players);
            GetTree().NetworkPeer = _network;
            GD.Print("Server started");

            _network.Connect("peer_connected", this, "_OnPeerConnected");
            _network.Connect("peer_disconnected", this, "_OnPeerDisconnected");
        }
Пример #4
0
        public override void _Ready()
        {
            LOG = new Logger(this.GetType().Name);
            ConnectedClients = new System.Collections.Generic.Dictionary<int, ClientRepresentation>();
            PackedScene dispatcherPackedScene = GD.Load("res://src/network/PacketDispatcher.tscn") as PackedScene;
            dispatcher = (PacketDispatcher)dispatcherPackedScene.Instance();
            AddChild(dispatcher);

            RegisterServerCallbacks();
            port =(int)ProjectSettings.GetSetting("feudal_mp/server/port");
            ENetInstance = new NetworkedMultiplayerENet();
            ENetInstance.CreateServer(port);
            GetTree().NetworkPeer = ENetInstance;
            LOG.Info("Server started on port " + port);

            ENetInstance.Connect("peer_connected", this, "receive_peer_connected");
            ENetInstance.Connect("peer_disconnected", this, "receive_peer_disconnected");
        }
Пример #5
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");
        }
Пример #6
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);
        }