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.SocketReceiveBufferSize = receiveBufferSize * 1024 * 1024;
              m_Config.SocketSendBufferSize = 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!");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientSocketManager"/> class.
        /// </summary>
        /// <param name="appIdentifier">The application identifier string.</param>
        public ClientSocketManager(string appIdentifier)
        {
            var config = new NetPeerConfiguration(appIdentifier) { AcceptIncomingConnections = false };

            // Disable some message types that will not be used by the client
            config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
            config.DisableMessageType(NetIncomingMessageType.Receipt);
            config.DisableMessageType(NetIncomingMessageType.UnconnectedData);
            config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest);
            config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse);

            // Custom configuration
            InitNetPeerConfig(config);

            // Start
            _local = new NetClient(config);
            _local.Start();
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServerSocketManager"/> class.
        /// </summary>
        /// <param name="appIdentifier">The application identifier string.</param>
        /// <param name="port">The port to listen on.</param>
        public ServerSocketManager(string appIdentifier, int port)
        {
            var config = new NetPeerConfiguration(appIdentifier)
            { AcceptIncomingConnections = true, Port = port, MaximumConnections = 50 };

            // Disable some message types that will not be used by the server
            config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
            config.DisableMessageType(NetIncomingMessageType.Receipt);
            config.DisableMessageType(NetIncomingMessageType.UnconnectedData);
            config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest);
            config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse);

            // Manually handle connection approval instead of just accepting everything
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            // Custom configuration
            InitNetPeerConfig(config);

            // Start
            _local = new NetServer(config);
            _local.Start();
        }
Beispiel #4
0
 public NetServiceImpl()
 {
     JObject constants = JObject.Parse(File.ReadAllText("Content/Json/config.json"));
     tag = constants.Value<String>("tag");
     port = constants.Value<int>("port");
     clientport = constants.Value<int>("clientport");
     discoveryWait = constants.Value<int>("discoverywait");
     config = new NetPeerConfiguration(tag);
     config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest);
     //config.Port = clientport;
     client = new NetClient(config);
     client.Start();
 }
Beispiel #5
0
 public MineWorldServer()
 {
     NetPeerConfiguration netConfig = new NetPeerConfiguration("MineWorld");
     netConfig.Port = Constants.MineworldPort;
     netConfig.MaximumConnections = 2;
     netConfig.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
     netConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
     netConfig.DisableMessageType(NetIncomingMessageType.UnconnectedData);
     Server = new NetServer(netConfig);
     GameWorld = new GameWorld(this);
     Console = new MineWorldConsole(this);
     ServerListener = new ServerListener(Server,this);
     ServerSender = new ServerSender(Server, this);
     Listener = new Thread(ServerListener.Start);
     MapManager = new MapManager();
     PlayerManager = new PlayerManager();
     Configloader = new ConfigFile("Data/Settings.ini");
 }
Beispiel #6
0
        public void Initialize(IServerConfiguration configuration)
        {
            var netPeerConfiguration = new NetPeerConfiguration("LidgrenConfig");
            netPeerConfiguration.Port = configuration.Port;
            netPeerConfiguration.DisableMessageType(NetIncomingMessageType.UnconnectedData);
            netPeerConfiguration.DisableMessageType(NetIncomingMessageType.DiscoveryRequest);
            netPeerConfiguration.DisableMessageType(NetIncomingMessageType.DiscoveryResponse);

            server = new NetServer(netPeerConfiguration);

            Reader = new LidgrenMessageReader(server);
            Writer = new LidgrenMessageWriter(server);

            connections.Clear();
        }
 public static NetPeerConfiguration GetStandardConfiguration(this NetPeerConfiguration self)
 {
     var config = new NetPeerConfiguration("NovaRat");
     // Disable all message types
     config.DisableMessageType(NetIncomingMessageType.ConnectionApproval);
     config.DisableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);
     config.DisableMessageType(NetIncomingMessageType.Data);
     config.DisableMessageType(NetIncomingMessageType.DebugMessage);
     config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest);
     config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse);
     config.DisableMessageType(NetIncomingMessageType.Error);
     config.DisableMessageType(NetIncomingMessageType.ErrorMessage);
     config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
     config.DisableMessageType(NetIncomingMessageType.Receipt);
     config.DisableMessageType(NetIncomingMessageType.UnconnectedData);
     config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     config.DisableMessageType(NetIncomingMessageType.WarningMessage);
     // Enable only what we need
     config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
     config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
     config.EnableMessageType(NetIncomingMessageType.StatusChanged);
     //config.EnableMessageType(NetIncomingMessageType.DebugMessage);
     //config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     //config.EnableMessageType(NetIncomingMessageType.WarningMessage);
     //config.EnableMessageType(NetIncomingMessageType.ErrorMessage);
     config.AcceptIncomingConnections = true;
     // No need to assign a port, as the OS will automatically assign an available port
     return config;
 }
 // Only for Introducer's NetworkServer
 public static NetPeerConfiguration GetStandardConfiguration(this NetPeerConfiguration self, int listeningPort)
 {
     var config = new NetPeerConfiguration("NovaRat");
     // Disable all message types
     config.DisableMessageType(NetIncomingMessageType.ConnectionApproval);
     config.DisableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);
     config.DisableMessageType(NetIncomingMessageType.Data);
     config.DisableMessageType(NetIncomingMessageType.DebugMessage);
     config.DisableMessageType(NetIncomingMessageType.DiscoveryRequest);
     config.DisableMessageType(NetIncomingMessageType.DiscoveryResponse);
     config.DisableMessageType(NetIncomingMessageType.Error);
     config.DisableMessageType(NetIncomingMessageType.ErrorMessage);
     config.DisableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
     config.DisableMessageType(NetIncomingMessageType.Receipt);
     config.DisableMessageType(NetIncomingMessageType.UnconnectedData);
     config.DisableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     config.DisableMessageType(NetIncomingMessageType.WarningMessage);
     // Enable only what we need
     config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
     config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess);
     config.EnableMessageType(NetIncomingMessageType.StatusChanged);
     //config.EnableMessageType(NetIncomingMessageType.DebugMessage);
     //config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     //config.EnableMessageType(NetIncomingMessageType.WarningMessage);
     //config.EnableMessageType(NetIncomingMessageType.ErrorMessage);
     config.Port = listeningPort;
     config.AcceptIncomingConnections = true;
     return config;
 }