Пример #1
0
        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");
            }

            TestContext.Out.WriteLine("Misc tests OK");

            TestContext.Out.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }));

            if (NetUtility.BitsToHoldUInt64((ulong)UInt32.MaxValue + 1ul) != 33)
            {
                throw new NetException("BitsToHoldUInt64 failed");
            }
        }
Пример #2
0
        public static void Run()
        {
            var config = new NetPeerConfiguration("Test");

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

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

            Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }));

            if (NetBitWriter.BitsForValue(uint.MaxValue + 1ul) != 33)
            {
                throw new LidgrenException("BitCountForValue failed");
            }

            Console.WriteLine("Misc tests OK");
        }
Пример #3
0
        internal void Init(int port)
        {
            InitMessageHandler();

            int           receiveBufferSize = 64;
            int           sendBufferSize    = 64;
            StringBuilder sb = new StringBuilder(256);

            if (CenterClientApi.GetConfig("ReceiveBufferSize", sb, 256))
            {
                receiveBufferSize = int.Parse(sb.ToString());
            }
            if (CenterClientApi.GetConfig("SendBufferSize", sb, 256))
            {
                sendBufferSize = int.Parse(sb.ToString());
            }

            m_Config = new NetPeerConfiguration("RoomServer");
            m_Config.MaximumConnections = 1024;
            m_Config.ConnectionTimeout  = 5.0f;
            m_Config.PingInterval       = 1.0f;
            m_Config.ReceiveBufferSize  = receiveBufferSize * 1024 * 1024;
            m_Config.SendBufferSize     = sendBufferSize * 1024 * 1024;
            m_Config.Port = port;
            m_Config.DisableMessageType(NetIncomingMessageType.DebugMessage);
            m_Config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage);
            //m_Config.EnableMessageType(NetIncomingMessageType.DebugMessage);
            //m_Config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
            m_Config.EnableMessageType(NetIncomingMessageType.ErrorMessage);
            m_Config.EnableMessageType(NetIncomingMessageType.WarningMessage);

            if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.DebugMessage))
            {
                LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.DebugMessage");
            }
            if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage))
            {
                LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.VerboseDebugMessage");
            }
            if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.ErrorMessage))
            {
                LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.ErrorMessage");
            }
            if (m_Config.IsMessageTypeEnabled(NetIncomingMessageType.WarningMessage))
            {
                LogSys.Log(LOG_TYPE.DEBUG, "Enable NetIncomingMessageType.WarningMessage");
            }

            m_NetServer = new NetServer(m_Config);
            m_NetServer.Start();
            m_IOThread              = new Thread(new ThreadStart(IOHandler));
            m_IOThread.Name         = "IOHandler";
            m_IOThread.IsBackground = true;
            m_Status = RoomSrvStatus.STATUS_RUNNING;
            m_IOThread.Start();
            RoomPeerMgr.Instance.Init();
            Console.WriteLine("Init IOManager OK!");
        }
Пример #4
0
        private NetPeerConfiguration SetupNetwork(NetPeerConfiguration configuration)
        {
            configuration.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            configuration.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);
            configuration.EnableMessageType(NetIncomingMessageType.Data);
            configuration.EnableMessageType(NetIncomingMessageType.DebugMessage);
            configuration.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            configuration.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
            configuration.EnableMessageType(NetIncomingMessageType.Error);
            configuration.EnableMessageType(NetIncomingMessageType.ErrorMessage);
            configuration.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
            configuration.EnableMessageType(NetIncomingMessageType.Receipt);
            configuration.EnableMessageType(NetIncomingMessageType.StatusChanged);
            configuration.EnableMessageType(NetIncomingMessageType.UnconnectedData);
            configuration.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
            configuration.EnableMessageType(NetIncomingMessageType.WarningMessage);

            foreach (var msgType in Enum.GetValues(typeof(NetIncomingMessageType)))
            {
                if (configuration.IsMessageTypeEnabled((NetIncomingMessageType)msgType))
                {
                    Logger.Trace($"[SERVER] Message type {Enum.GetName(typeof(NetIncomingMessageType), msgType)} enabled");
                }
            }

            return(configuration);
        }
Пример #5
0
        public void TestEnableMessageType()
        {
            var config = new NetPeerConfiguration("Test");

            config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
            Assert.IsTrue(config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData), "setting enabled message types failed");
        }
Пример #6
0
        public void TestSetMessageTypeEnabled()
        {
            var config = new NetPeerConfiguration("Test");

            config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false);
            Assert.IsFalse(config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData), "setting enabled message types failed");
        }
Пример #7
0
        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 }));
        }
Пример #8
0
        internal void SetStatus(NetConnectionStatus status, string reason)
        {
            // user or library thread

            m_status = status;
            if (reason == null)
            {
                reason = string.Empty;
            }

            if (m_status == NetConnectionStatus.Connected)
            {
                m_timeoutDeadline = NetTime.Now + m_peerConfiguration.m_connectionTimeout;
                m_peer.LogVerbose("Timeout deadline initialized to  " + m_timeoutDeadline);
            }

            if (m_peerConfiguration.IsMessageTypeEnabled(NetIncomingMessageType.StatusChanged))
            {
                if (m_outputtedStatus != status)
                {
                    NetIncomingMessage info = m_peer.CreateIncomingMessage(NetIncomingMessageType.StatusChanged, 4 + reason.Length + (reason.Length > 126 ? 2 : 1));
                    info.m_senderConnection = this;
                    info.m_senderEndPoint   = m_remoteEndPoint;
                    info.Write((byte)m_status);
                    info.Write(reason);
                    m_peer.ReleaseMessage(info);
                    m_outputtedStatus = status;
                }
            }
            else
            {
                // app dont want those messages, update visible status immediately
                m_outputtedStatus = m_status;
                m_visibleStatus   = m_status;
            }
        }