Beispiel #1
1
        /// <summary>
        /// Start the server
        /// </summary>
        public void StartServer()
        {
            Clients = new ClientCollection();

            // Server basic configuration
            var config = new NetPeerConfiguration(GameConfiguration.NetworkAppIdentifier)
            {
                MaximumConnections = ServerSettings.MaxConnection,
                Port = ServerSettings.Port,
                #if DEBUG
                //PingInterval = 1f, // send ping every 1 second
                //SimulatedLoss = 0.5f, // half packets lost
                //SimulatedMinimumLatency = 0.05f, // latency of 50 ms
                #endif
            };

            // To send ping to each player frequently
            config.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionLatencyUpdated, true);

            try
            {
                _server = new NetServer(config);
                _server.Start();

                _hostStarted = true;

                GameManager.Initialize();

                Program.Log.Info("[START]Game server has started");
                Program.Log.Info("[PORT]: " + config.Port);
            }
            catch (NetException ex)
            {
                Program.Log.Fatal(ex.Message);

                throw;
            }
        }
Beispiel #2
0
        internal ClientConnection(bool dummy)
        {
            if (!dummy)
             {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            NetPeerConfiguration peerConfig = new NetPeerConfiguration("Qbes");
            peerConfig.AutoFlushSendQueue = true;
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.DebugMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ErrorMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage, true);
            peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.WarningMessage, true);
            _Client = new NetClient(peerConfig);
            _Client.RegisterReceivedCallback(new SendOrPostCallback(ReceivedMessage));
             }
        }
Beispiel #3
0
        public Program()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = API.MasterServer.MasterServerPort;

            peer = new NetPeer(config);
            peer.Start();
        }
Beispiel #4
0
        static S_NetworkManager()
        {
            NetPeerConfiguration lidServerConfig = new NetPeerConfiguration("chat");
            lidServerConfig.Port = 2323;
            lidServerConfig.PingInterval = HEARTBEAT_S;
            lidServerConfig.ConnectionTimeout = TIMEOUT_S;
            lidServerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            myLidServer = new NetServer(lidServerConfig);
            myLidServer.Start();
        }
		static void Main(string[] args)
		{
			IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);

			NetPeerConfiguration config = new NetPeerConfiguration("game");
			config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
			config.Port = 14242;

			NetServer server = new NetServer(config);
			server.Start();

			Console.WriteLine("Server started; waiting 5 seconds...");
			System.Threading.Thread.Sleep(5000);

			var lastRegistered = -60.0f;

			while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
			{
				// (re-)register periodically with master server
				if (NetTime.Now > lastRegistered + 60)
				{
					// register with master server
					NetOutgoingMessage regMsg = server.CreateMessage();
					regMsg.Write((byte)MasterServerMessageType.RegisterHost);
					IPAddress mask;
					IPAddress adr = NetUtility.GetMyAddress(out mask);
					regMsg.Write(server.UniqueIdentifier);
					regMsg.Write(new IPEndPoint(adr, 14242));
					Console.WriteLine("Sending registration to master server");
					server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
					lastRegistered = (float)NetTime.Now;
				}

				NetIncomingMessage inc;
				while ((inc = server.ReadMessage()) != null)
				{
					switch (inc.MessageType)
					{
						case NetIncomingMessageType.VerboseDebugMessage:
						case NetIncomingMessageType.DebugMessage:
						case NetIncomingMessageType.WarningMessage:
						case NetIncomingMessageType.ErrorMessage:
							Console.WriteLine(inc.ReadString());
							break;
					}
				}

				System.Threading.Thread.Sleep(1);
			}

			Console.ReadKey();
		}
        public static void Run(NetPeer peer)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("Test");

            config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
            if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false)
                throw new NetException("setting enabled message types failed");

            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false);
            if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == true)
                throw new NetException("setting enabled message types failed");

            Console.WriteLine("Misc tests OK");

            Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[]{0xDE,0xAD,0xBE,0xEF}));
        }
Beispiel #7
0
        static ConnectionManager()
        {
            config = new NetPeerConfiguration("CWRUShare");
            config.AutoFlushSendQueue = true;
            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            config.EnableMessageType(NetIncomingMessageType.Data);
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            currentListView = new FileList();
            isListUpdated = false;

            config.Port = 14242;
            isConnected = false;

            server = new NetServer(config);
            server.Start();
        }
Beispiel #8
0
    public void send()
    {
        Patient PAT = new Patient(name.text, family.text, suffix.text, Convert.ToInt32(gender.text), Convert.ToDateTime(birthDate.text), polis.text, Convert.ToInt32(SocialStatus.text), Convert.ToInt32(Privileges.text));
        string json = JsonConvert.SerializeObject(PAT);

        int ClientPort = 25000;
        string ClientIP = "95.31.16.180";

        NetPeerConfiguration config = new NetPeerConfiguration(" ");
        config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
        config.Port = 1212;
        NetClient client = new NetClient(config);
        NetOutgoingMessage msg = client.CreateMessage();
        msg.Write((byte)0);
        msg.Write(json);
        client.Start();
        client.SendUnconnectedMessage(msg, ClientIP, ClientPort);

        Debug.Log("ОК");
    }
Beispiel #9
0
    void Start()
    {
        try
        {
            Debug.Log("client try Start");
            config = new NetPeerConfiguration(" ");
            DontDestroyOnLoad(this);

            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = 1212;

            client = new NetClient(config);

            client.Start();
            Debug.Log("client Start");
        }
        catch (Exception e )
        {
            Debug.Log (e.Message);
        }
    }
Beispiel #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Server Started");
            
            Dictionary<IPEndPoint, AvailableGame> registeredHosts = new Dictionary<IPEndPoint, AvailableGame>();

            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = 6000;

            NetPeer peer = new NetPeer(config);
            peer.Start();

            // keep going until ESCAPE is pressed
            Console.WriteLine("Press ESC to quit");
            while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
            {
                System.Threading.Thread.Sleep(10);
                NetIncomingMessage msg;
                while ((msg = peer.ReadMessage()) != null)
                {
                    switch (msg.MessageType)
                    {
                        case NetIncomingMessageType.UnconnectedData:
                            //
                            // We've received a message from a client or a host
                            //

                            // by design, the first byte always indicates action
                            switch (msg.ReadByte())
                            {
                                case 0: // register a new game
                                    // currently only one game per host per router.
                                    if (!registeredHosts.ContainsKey(msg.SenderEndpoint))
                                    {
                                        AvailableGame game = new AvailableGame();
                                        game.Count = msg.ReadInt32();
                                        game.GamerTag = msg.ReadString();
                                        game.PrivateGamerSlots = msg.ReadInt32();
                                        game.MaxGamers = msg.ReadInt32();
                                        game.IsHost = msg.ReadBoolean();
                                        game.InternalIP = msg.ReadIPEndpoint();
                                        game.ExternalIP = msg.SenderEndpoint;
                                        game.Game = msg.ReadString();


                                        Console.WriteLine("Got registration for host " + game.ToString());
                                        registeredHosts.Add(game.ExternalIP, game);
                                    }
                                    break;

                                case 1:
                                    // It's a client wanting a list of registered hosts
                                    Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndpoint);
                                    string appid = msg.ReadString();
                                    foreach (AvailableGame g1 in registeredHosts.Values)
                                    {
                                        if (g1.Game == appid)
                                        {
                                            // send registered host to client
                                            NetOutgoingMessage om = peer.CreateMessage();
                                            om.Write(g1.Count);
                                            om.Write(g1.GamerTag);
                                            om.Write(g1.PrivateGamerSlots);
                                            om.Write(g1.MaxGamers);
                                            om.Write(g1.IsHost);
                                            om.Write(g1.InternalIP);
                                            om.Write(g1.ExternalIP);
                                            peer.SendUnconnectedMessage(om, msg.SenderEndpoint);
                                        }
                                    }

                                    break;
                                case 2:
                                    // It's a client wanting to connect to a specific (external) host
                                    IPEndPoint clientInternal = msg.ReadIPEndpoint();
                                    IPEndPoint hostExternal = msg.ReadIPEndpoint();
                                    string token = msg.ReadString();

                                    Console.WriteLine(msg.SenderEndpoint + " requesting introduction to " + hostExternal + " (token " + token + ")");

                                    // find in list
                                    foreach (AvailableGame elist in registeredHosts.Values)
                                    {
                                        if (elist.ExternalIP.Equals(hostExternal))
                                        {
                                            // found in list - introduce client and host to eachother
                                            Console.WriteLine("Sending introduction...");
                                            peer.Introduce(
                                                    elist.InternalIP, // host internal
                                                    elist.ExternalIP, // host external
                                                    clientInternal, // client internal
                                                    msg.SenderEndpoint, // client external
                                                    token // request token
                                            );
                                            break;
                                        }
                                    }
                                    break;
                                case 3:
                                    if (registeredHosts.ContainsKey(msg.SenderEndpoint))
                                    {
                                        AvailableGame game = registeredHosts[msg.SenderEndpoint];
                                        string tag = msg.ReadString();
                                        string gamename = msg.ReadString();
                                        if (game.GamerTag == tag)
                                        {
                                            Console.WriteLine("Remove for host " + game.ExternalIP.ToString());
                                            registeredHosts.Remove(game.ExternalIP);
                                        }
                                    }
                                    break;
                                case 4 :
                                    if (registeredHosts.ContainsKey(msg.SenderEndpoint))
                                    {
                                        AvailableGame game = registeredHosts[msg.SenderEndpoint];
                                        int count = msg.ReadInt32();
                                        string tag = msg.ReadString();                                        
                                        if (game.GamerTag == tag)
                                        {
                                            Console.WriteLine("Update for host " + game.ExternalIP.ToString());                                            
                                            game.Count = count;
	                                        game.PrivateGamerSlots = msg.ReadInt32();
	                                        game.MaxGamers = msg.ReadInt32();
	                                        game.IsHost = msg.ReadBoolean();
	                                        game.InternalIP = msg.ReadIPEndpoint();
	                                        game.Game = msg.ReadString();
                                        }
                                    }
                                    break;
                            }
                            break;

                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            // print diagnostics message
                            Console.WriteLine(msg.ReadString());
                            break;
                    }
                }
            }

            peer.Shutdown("shutting down");

        }
Beispiel #11
0
        /// <summary>
        /// Set up the server, bind to a socket. Use Start to fully start the server after running this
        /// </summary>
        /// <param name="configuration"></param>
        public static void InitializeServer(ServerConfiguration configuration)
        {
            Configuration = configuration;

            if (peer != null && peer.Status != NetPeerStatus.NotRunning)
            {
                Debug.LogError("cannot start server while already running");
                return;
            }

            _netPeerConfiguration = new NetPeerConfiguration(Configuration.AppIdentifier);
            _netPeerConfiguration.Port = Configuration.ListenPort;
            _netPeerConfiguration.MaximumConnections = Configuration.MaximumConnections;
            connections = new IntDictionary<NetConnection>(Configuration.MaximumConnections);

            _netPeerConfiguration.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            peer = new NetServer(_netPeerConfiguration);

            peer.Start();

            var serverId = connections.Add(null);
            var serverPlayer = new Player();
            serverPlayer.Id = (ushort)serverId;
            Player.Server = serverPlayer;

            GameState.update += Update;
        }
        static void Main(string[] args)
        {
            IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);

            NetPeerConfiguration config = new NetPeerConfiguration("game");
            config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
            config.Port = 14242;

            NetServer server = new NetServer(config);
            server.Start();

            Console.WriteLine("Server started; waiting 5 seconds...");
            System.Threading.Thread.Sleep(5000);

            var lastRegistered = -60.0f;

            while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
            {
                // (re-)register periodically with master server
                if (NetTime.Now > lastRegistered + 60)
                {
                    // register with master server
                    NetOutgoingMessage regMsg = server.CreateMessage();
                    regMsg.Write((byte)MasterServerMessageType.RegisterHost);
                    IPAddress mask;
                    IPAddress adr = NetUtility.GetMyAddress(out mask);
                    regMsg.Write(server.UniqueIdentifier);
                    regMsg.Write(new IPEndPoint(adr, 14242));
                    Console.WriteLine("Sending registration to master server");
                    server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
                    lastRegistered = (float)NetTime.Now;
                }

                NetIncomingMessage inc;
                while ((inc = server.ReadMessage()) != null)
                {
                    switch (inc.MessageType)
                    {
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            Console.WriteLine(inc.ReadString());
                            break;
                        case NetIncomingMessageType.Data:
                            // incoming chat message from a client
                            string chat = inc.ReadString();
                            Console.WriteLine(chat);
                            //Output("Broadcasting '" + chat + "'");

                            // broadcast this to all connections, except sender
                            List<NetConnection> all = server.Connections; // get copy
                            all.Remove(inc.SenderConnection);

                            if (all.Count > 0) {
                                NetOutgoingMessage om = server.CreateMessage();
                                om.Write(NetUtility.ToHexString(inc.SenderConnection.RemoteUniqueIdentifier) + " said: " + chat);
                                server.SendMessage(om, all, NetDeliveryMethod.ReliableOrdered, 0);
                            }
                            break;
                    }
                }

                System.Threading.Thread.Sleep(1);
            }

            Console.ReadKey();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Dictionary<long, ServerData> registeredHosts = new Dictionary<long, ServerData>();

            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = SharedConfiguration.MasterServerEndPoint.Port;

            NetPeer peer = new NetPeer(config);
            peer.Start();

            // keep going until ESCAPE is pressed
            Console.WriteLine("Press ESC to quit");
            while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape) {
                NetIncomingMessage msg;
                while ((msg = peer.ReadMessage()) != null) {
                    switch (msg.MessageType) {
                        case NetIncomingMessageType.UnconnectedData:
                            //
                            // We've received a message from a client or a host
                            //

                            // by design, the first byte always indicates action
                            switch ((MasterServerMessageType)msg.ReadByte()) {
                                case MasterServerMessageType.RegisterHost:

                                    // It's a host wanting to register its presence
                                    var id = msg.ReadInt64(); // server unique identifier
                                    Console.WriteLine("Got registration for host " + id);

                                    ServerData serverData = new ServerData();
                                    serverData.IPEndPoint[0] = msg.ReadIPEndPoint();
                                    serverData.IPEndPoint[1] = msg.SenderEndPoint;

                                    serverData.ServerName = msg.ReadString();
                                    serverData.ScriptName = msg.ReadString();
                                    serverData.Players = msg.ReadInt32();
                                    serverData.MaxPlayers = msg.ReadInt32();

                                    registeredHosts[id] = serverData;
                                    break;

                                case MasterServerMessageType.RequestHostList:
                                    // It's a client wanting a list of registered hosts
                                    Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndPoint);
                                    foreach (var kvp in registeredHosts) {
                                        // send registered host to client
                                        NetOutgoingMessage om = peer.CreateMessage();
                                        om.Write(kvp.Key);
                                        om.Write(kvp.Value.IPEndPoint[0]);
                                        om.Write(kvp.Value.IPEndPoint[1]);
                                        om.Write(kvp.Value.ServerName);
                                        om.Write(kvp.Value.ScriptName);
                                        om.Write(kvp.Value.Players);
                                        om.Write(kvp.Value.MaxPlayers);
                                        peer.SendUnconnectedMessage(om, msg.SenderEndPoint);
                                    }

                                    break;
                            }
                            break;

                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            // print diagnostics message
                            Console.WriteLine(msg.ReadString());
                            break;
                    }
                }
            }

            peer.Shutdown("shutting down");
        }
        /// <summary>
        /// Initialize the Lidgren NetServer.
        /// </summary>
        public S_LidgrenContainer(ServerWindow setServerWindow)  //Need to know an instance of ChatWindow so we can pass commands along to it in HandleCustomMessages.
        {
            NetPeerConfiguration lidServerConfig = new NetPeerConfiguration("chat");
            lidServerConfig.Port = 2323;
            lidServerConfig.PingInterval = HEARTBEAT_S;
            lidServerConfig.ConnectionTimeout = TIMEOUT_S;
            lidServerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            myLidServer = new NetServer(lidServerConfig);
            myLidServer.Start();
        }
        void StartServer()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("FPSMod");

            Debug.Log("Starting Server");

            m_isServer = true;

            config.Port = ServerSettings.Port;
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);

            m_server = new NetServer(config);
            m_server.Start();

            SpawnLocalPlayer();
            Debug.Log("wID: " + m_saveWorkshopID);
            Debug.Log("p: " + ServerSettings.Private);

            if (MultiplayerLoading.UseVehiclesAndCitizens)
            {
                m_vNetworkManager = gameObject.AddComponent<VehicleNetworkManager>();
                m_cNetworkManager = gameObject.AddComponent<CitizenNetworkManager>();
            }

            if (m_saveWorkshopID != UInt64.MaxValue && !ServerSettings.Private)
            {
                try
                {
                    using (var client = new WebClient())
                    {
                        var values = new NameValueCollection
                            {
                                {"name", ServerSettings.Name.IsNullOrWhiteSpace() ? "No name" : ServerSettings.Name},
                                {"port", ServerSettings.Port.ToString()},
                                {"mapId", m_saveWorkshopID.ToString()},
                                {"modVersion", Settings.ModVersion.ToString()}
                            };
                        var result = client.UploadValues(Settings.ServerUrl + "/create", "POST", values);
                        string responsebody = Encoding.UTF8.GetString(result);
                        Debug.Log("Sending to masterserver: " + responsebody);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Set up the server, and bind to a socket. Use Start to actually fully start the server
        /// </summary>
        /// <param name="maxConnections"></param>
        /// <param name="listenPort"></param>
        /// <param name="tickRate"></param>
        public static void InitializeServer(int maxConnections, int listenPort, int tickRate = 66)
        {
            if (peer != null && peer.Status != NetPeerStatus.NotRunning)
            {
                Debug.LogError("cannot start server while already running");
                return;
            }

            config = new NetPeerConfiguration("PNet");
            config.Port = listenPort;
            config.MaximumConnections = maxConnections;
            config.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            peer = new NetServer(config);

            peer.Start();

            var serverId = connections.Add(null);
            var serverPlayer = new Player();
            serverPlayer.Id = (ushort)serverId;
            Player.Server = serverPlayer;

            GameState.update += Update;
        }
Beispiel #17
0
        static void ClientServerStart()
        {
            NetPeerConfiguration config = new NetPeerConfiguration(" ");
            config.Port = ClientPort;
            config.LocalAddress = IPAddress.Parse(ClientIP);
            config.MaximumConnections = 10000;
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);

            MediatorServer = new NetServer(config);
            MediatorServer.Start();
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            List<IPEndPoint[]> registeredHosts = new List<IPEndPoint[]>();

            NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
            config.Port = CommonConstants.MasterServerPort;

            NetPeer peer = new NetPeer(config);
            peer.Start();

            // keep going until ESCAPE is pressed
            Console.WriteLine("Press ESC to quit");
            while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
            {
                NetIncomingMessage msg;
                while((msg = peer.ReadMessage()) != null)
                {
                    switch (msg.MessageType)
                    {
                        case NetIncomingMessageType.UnconnectedData:
                            //
                            // We've received a message from a client or a host
                            //

                            // by design, the first byte always indicates action
                            switch ((MasterServerMessageType)msg.ReadByte())
                            {
                                case MasterServerMessageType.RegisterHost:
                                    // It's a host wanting to register its presence
                                    IPEndPoint[] eps = new IPEndPoint[]
                                    {
                                        msg.ReadIPEndpoint(), // internal
                                        msg.SenderEndpoint // external
                                    };
                                    Console.WriteLine("Got registration for host " + eps[1]);
                                    registeredHosts.Add(eps);
                                    break;

                                case MasterServerMessageType.RequestHostList:
                                    // It's a client wanting a list of registered hosts
                                    Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndpoint);
                                    foreach (IPEndPoint[] ep in registeredHosts)
                                    {
                                        // send registered host to client
                                        NetOutgoingMessage om = peer.CreateMessage();
                                        om.Write(ep[0]);
                                        om.Write(ep[1]);
                                        peer.SendUnconnectedMessage(om, msg.SenderEndpoint);
                                    }

                                    break;
                                case MasterServerMessageType.RequestIntroduction:
                                    // It's a client wanting to connect to a specific (external) host
                                    IPEndPoint clientInternal = msg.ReadIPEndpoint();
                                    IPEndPoint hostExternal = msg.ReadIPEndpoint();
                                    string token = msg.ReadString();

                                    Console.WriteLine(msg.SenderEndpoint + " requesting introduction to " + hostExternal + " (token " + token + ")");

                                    // find in list
                                    foreach (IPEndPoint[] elist in registeredHosts)
                                    {
                                        if (elist[1].Equals(hostExternal))
                                        {
                                            // found in list - introduce client and host to eachother
                                            Console.WriteLine("Sending introduction...");
                                            peer.Introduce(
                                                elist[0], // host internal
                                                elist[1], // host external
                                                clientInternal, // client internal
                                                msg.SenderEndpoint, // client external
                                                token // request token
                                            );
                                            break;
                                        }
                                    }
                                    break;
                            }
                            break;

                        case NetIncomingMessageType.DebugMessage:
                        case NetIncomingMessageType.VerboseDebugMessage:
                        case NetIncomingMessageType.WarningMessage:
                        case NetIncomingMessageType.ErrorMessage:
                            // print diagnostics message
                            Console.WriteLine(msg.ReadString());
                            break;
                    }
                }
            }

            peer.Shutdown("shutting down");
        }
Beispiel #19
0
        static void startup()
        {
            ObjList = new List<GameObj>();
            Random r=new Random();
            for(int i=0;i<10;i++)
            {
                TestObj to = new TestObj();
                to.id = i;
                to.name = "testObj";
                to.tran.xy[0]=r.Next(500);
                to.tran.xy[1] = r.Next(500);
                to.Sprite = "test";
                ObjList.Add(to);
            }

            ClientList = new List<ConClient>();
            config = new NetPeerConfiguration("Litrpg");
            config.MaximumConnections = 32;
            config.Port = 5410;
            server = new NetServer(config);
            config.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);

            server.Start();
        }
        public override void Start()
        {
            this.backgroundSprite = "MenuPanel";
            this.color = new Color32(50, 50, 50, 255);
            this.width = 350;
            this.height = 185;
            this.isVisible = false;
            this.position += new Vector3(-this.width/2, this.height/2 + 50);

            UILabel ipLabel = this.AddUIComponent<UILabel>();
            ipLabel.text = "IP:";
            ipLabel.pivot = UIPivotPoint.BottomRight;
            ipLabel.relativePosition = new Vector2(10, 10);

            m_ipTextField = CreateTextField();
            m_ipTextField.width = 140;
            m_ipTextField.text = "127.0.0.1";
            m_ipTextField.pivot = UIPivotPoint.BottomRight;
            m_ipTextField.relativePosition = new Vector2(55, 10);

            UILabel portLabel = this.AddUIComponent<UILabel>();
            portLabel.text = "Port:";
            portLabel.pivot = UIPivotPoint.BottomRight;
            portLabel.relativePosition = new Vector2(10, 45);

            m_portTextField = CreateTextField();
            m_portTextField.numericalOnly = true;
            m_portTextField.text = "27015";
            m_portTextField.pivot = UIPivotPoint.BottomRight;
            m_portTextField.relativePosition = new Vector2(55, 45);

            UIButton connectButton = CreateButton();
            connectButton.text = "CONNECT";
            connectButton.width = 100;
            connectButton.height = 60;
            connectButton.pivot = UIPivotPoint.BottomRight;
            connectButton.relativePosition = new Vector2(this.width - connectButton.width - 110, this.height - connectButton.height - 5);
            connectButton.eventClick += OnClickConnect;

            UIButton closeButton = CreateButton();
            closeButton.text = "CANCEL";
            closeButton.width = 100;
            closeButton.height = 60;
            closeButton.pivot = UIPivotPoint.BottomRight;
            closeButton.relativePosition = new Vector2(this.width - closeButton.width - 5, this.height - closeButton.height - 5);
            closeButton.eventClick += OnClickCancel;

            m_connectionInfoLabel = this.AddUIComponent<UILabel>();
            m_connectionInfoLabel.text = "";
            m_connectionInfoLabel.pivot = UIPivotPoint.TopLeft;
            m_connectionInfoLabel.relativePosition = new Vector2(10, 80);
            m_connectionInfoLabel.textAlignment = UIHorizontalAlignment.Left;

            NetPeerConfiguration config = new NetPeerConfiguration("FPSMod");
            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);

            m_netClient = new NetClient(config);
            m_netClient.Start();
        }