Beispiel #1
0
		// CONSTRUCTOR
		public Server(NetworkingInfo netinfo)
		{
			networkingInfo = netinfo;
			if(networkingInfo.port == -1) networkingInfo.port = NetworkingInfo.defaultPort;
			if(networkingInfo.address == "") networkingInfo.address = NetworkingInfo.defaultAddress;
			// TODO: Add some kind of DNS pre check for IP?

			connectedPlayers = new List<ServerPlayer>();
			whiteList = new Dictionary<string, DateTime>();
			pendingConnections = new Queue<NetworkConnection>();

			config = new ConnectionConfig();
			Channels.priority = config.AddChannel(QosType.AllCostDelivery);
			Channels.reliable = config.AddChannel(QosType.ReliableSequenced);
			Channels.unreliable = config.AddChannel(QosType.UnreliableSequenced);
			Channels.fragmented = config.AddChannel(QosType.ReliableFragmented);
			Channels.update = config.AddChannel(QosType.StateUpdate);
			hostconfig = new HostTopology(config, maxConcurrentConnectedUsers);

			NetworkServer.Configure(hostconfig);
			NetworkServer.Listen(networkingInfo.port);
			NetworkServer.RegisterHandler(MsgType.Connect, OnClientConnected);
			common.printConsole (tag, "Setup complete", true);
			networkingInfo.address = NetworkingCommon.localServer;
		}
 public ConnectionConfig(ConnectionConfig config)
 {
     this.m_Channels = new List<ChannelQOS>();
     if (config == null)
     {
         throw new NullReferenceException("config is not defined");
     }
     this.m_PacketSize = config.m_PacketSize;
     this.m_FragmentSize = config.m_FragmentSize;
     this.m_ResendTimeout = config.m_ResendTimeout;
     this.m_DisconnectTimeout = config.m_DisconnectTimeout;
     this.m_ConnectTimeout = config.m_ConnectTimeout;
     this.m_MinUpdateTimeout = config.m_MinUpdateTimeout;
     this.m_PingTimeout = config.m_PingTimeout;
     this.m_ReducedPingTimeout = config.m_ReducedPingTimeout;
     this.m_AllCostTimeout = config.m_AllCostTimeout;
     this.m_NetworkDropThreshold = config.m_NetworkDropThreshold;
     this.m_OverflowDropThreshold = config.m_OverflowDropThreshold;
     this.m_MaxConnectionAttempt = config.m_MaxConnectionAttempt;
     this.m_AckDelay = config.m_AckDelay;
     this.m_MaxCombinedReliableMessageSize = config.MaxCombinedReliableMessageSize;
     this.m_MaxCombinedReliableMessageCount = config.m_MaxCombinedReliableMessageCount;
     this.m_MaxSentMessageQueueSize = config.m_MaxSentMessageQueueSize;
     this.m_IsAcksLong = config.m_IsAcksLong;
     foreach (ChannelQOS lqos in config.m_Channels)
     {
         this.m_Channels.Add(new ChannelQOS(lqos));
     }
 }
 public ConnectionConfigInternal(ConnectionConfig config)
 {
   if (config == null)
     throw new NullReferenceException("config is not defined");
   this.InitWrapper();
   this.InitPacketSize(config.PacketSize);
   this.InitFragmentSize(config.FragmentSize);
   this.InitResendTimeout(config.ResendTimeout);
   this.InitDisconnectTimeout(config.DisconnectTimeout);
   this.InitConnectTimeout(config.ConnectTimeout);
   this.InitMinUpdateTimeout(config.MinUpdateTimeout);
   this.InitPingTimeout(config.PingTimeout);
   this.InitReducedPingTimeout(config.ReducedPingTimeout);
   this.InitAllCostTimeout(config.AllCostTimeout);
   this.InitNetworkDropThreshold(config.NetworkDropThreshold);
   this.InitOverflowDropThreshold(config.OverflowDropThreshold);
   this.InitMaxConnectionAttempt(config.MaxConnectionAttempt);
   this.InitAckDelay(config.AckDelay);
   this.InitMaxCombinedReliableMessageSize(config.MaxCombinedReliableMessageSize);
   this.InitMaxCombinedReliableMessageCount(config.MaxCombinedReliableMessageCount);
   this.InitMaxSentMessageQueueSize(config.MaxSentMessageQueueSize);
   this.InitIsAcksLong(config.IsAcksLong);
   this.InitUsePlatformSpecificProtocols(config.UsePlatformSpecificProtocols);
   this.InitWebSocketReceiveBufferMaxSize(config.WebSocketReceiveBufferMaxSize);
   for (byte idx = 0; (int) idx < config.ChannelCount; ++idx)
   {
     int num = (int) this.AddChannel(config.GetChannel(idx));
   }
 }
 public ConnectionConfigInternal(ConnectionConfig config)
 {
     if (config == null)
     {
         throw new NullReferenceException("config is not defined");
     }
     this.InitWrapper();
     this.InitPacketSize(config.PacketSize);
     this.InitFragmentSize(config.FragmentSize);
     this.InitResendTimeout(config.ResendTimeout);
     this.InitDisconnectTimeout(config.DisconnectTimeout);
     this.InitConnectTimeout(config.ConnectTimeout);
     this.InitMinUpdateTimeout(config.MinUpdateTimeout);
     this.InitPingTimeout(config.PingTimeout);
     this.InitReducedPingTimeout(config.ReducedPingTimeout);
     this.InitAllCostTimeout(config.AllCostTimeout);
     this.InitNetworkDropThreshold(config.NetworkDropThreshold);
     this.InitOverflowDropThreshold(config.OverflowDropThreshold);
     this.InitMaxConnectionAttempt(config.MaxConnectionAttempt);
     this.InitAckDelay(config.AckDelay);
     this.InitMaxCombinedReliableMessageSize(config.MaxCombinedReliableMessageSize);
     this.InitMaxCombinedReliableMessageCount(config.MaxCombinedReliableMessageCount);
     this.InitMaxSentMessageQueueSize(config.MaxSentMessageQueueSize);
     this.InitIsAcksLong(config.IsAcksLong);
     for (byte i = 0; i < config.ChannelCount; i = (byte) (i + 1))
     {
         this.AddChannel(config.GetChannel(i));
     }
 }
Beispiel #5
0
        public void Connect(string ip)
        {
            NetworkTransport.Init();

            // Config must be identical with the server
            var config = new ConnectionConfig();
            config.PacketSize = 1000;
            infoChannel = config.AddChannel(QosType.ReliableSequenced);
            gameChannel = config.AddChannel(QosType.ReliableSequenced);

            // Setup the host socket (yes also for clients)
            // Using port 0 to let the system assign a random available port
            var topology = new HostTopology(config, 200);
            server.host = NetworkTransport.AddHost(topology, 0);

            byte error;
            server.conn = NetworkTransport.Connect(server.host, ip, port, 0, out error);

            Log.TestError(error, "Failed to connect to the server!");

            // Setup the data buffer:
            data = new byte[config.PacketSize];
            // And setup a reader and writer for easy data manipulation
            stream = new MemoryStream(data);
            reader = new BinaryReader(stream);
            writer = new BinaryWriter(stream);
        }
 private HostTopology()
 {
     this.m_DefConfig = null;
     this.m_MaxDefConnections = 0;
     this.m_SpecialConnections = new List<ConnectionConfig>();
     this.m_ReceivedMessagePoolSize = 0x80;
     this.m_SentMessagePoolSize = 0x80;
     this.m_MessagePoolSizeGrowthFactor = 0.75f;
 }
        public static void Setup(string port)
        {
            NetworkTransport.Init();

            ConnectionConfig config = new ConnectionConfig();
            channelSetupId = config.AddChannel(QosType.Reliable); // for lobby
            channelActionId = config.AddChannel(QosType.Reliable); // action in game
            channelConfirmationId = config.AddChannel(QosType.Reliable); // confirmation in game

            HostTopology topology = new HostTopology(config, maxConnection);
            hostId = NetworkTransport.AddHost(topology, Convert.ToInt32(port));

            self.enabled = true;
        }
 private void InitUnetBroadcastDiscovery()
 {
     byte num;
     if (!NetworkTransport.IsStarted)
     {
         NetworkTransport.Init();
     }
     ConnectionConfig defaultConfig = new ConnectionConfig();
     defaultConfig.AddChannel(QosType.Unreliable);
     HostTopology topology = new HostTopology(defaultConfig, 1);
     this.hostId = NetworkTransport.AddHost(topology, 0xbaa1);
     if (this.hostId == -1)
     {
         Debug.LogError("Network Discovery addHost failed!");
     }
     NetworkTransport.SetBroadcastCredentials(this.hostId, 0x3e8, 1, 1, out num);
 }
Beispiel #9
0
		// CONSTRUCTOR
		public Client(NetworkingInfo netinfo)
		{
			networkingInfo = netinfo;
			if(networkingInfo.port == -1) networkingInfo.port = NetworkingInfo.defaultPort;
			if(networkingInfo.address == "") networkingInfo.address = NetworkingInfo.defaultAddress;
			// TODO: Add some kind of DNS pre check for IP?

			connectedPlayers = new List<Player>();

			config = new ConnectionConfig();
			Channels.priority = config.AddChannel(QosType.AllCostDelivery);
			Channels.reliable = config.AddChannel(QosType.ReliableSequenced);
			Channels.unreliable = config.AddChannel(QosType.UnreliableSequenced);
			Channels.fragmented = config.AddChannel(QosType.ReliableFragmented);
			Channels.update = config.AddChannel(QosType.StateUpdate);
			hostconfig = new HostTopology(config, maxConcurrentConnectedUsers);

			if(networkingInfo.isServer)
			{
				myClient = ClientScene.ConnectLocalServer();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);
			}
			else
			{
				myClient = new NetworkClient();
				myClient.Configure(hostconfig);

				myClient.RegisterHandler(MsgType.Connect, OnConnected);
				myClient.RegisterHandler(MsgType.Error, ConnectionError);
				myClient.RegisterHandler(MsgType.Disconnect, ConnectionFailed);
				registerAllCallbacks(myClient, cbClientHandler);

				common.printConsole (tag, "Setup complete", true);

				myClient.Connect(networkingInfo.address, networkingInfo.port);
				common.printConsole (tag, "Connecting to " + networkingInfo.address + ":" + networkingInfo.port, true);
			}
		}
Beispiel #10
0
        // Use this for initialization
        private void Start()
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            var config = new ConnectionConfig();
            state = config.AddChannel(QosType.Unreliable);
            reliable = config.AddChannel(QosType.ReliableSequenced);
            var topology = new HostTopology(config, 1);

            host = NetworkTransport.AddHost(topology);

            ms = new MemoryStream(data);
            reader = new BinaryReader(ms);
            writer = new BinaryWriter(ms);

            NetworkTransport.StartBroadcastDiscovery(host, port, 1, 1, 0, new byte[1], 1, 2000, out error);
            PhoneServer.TestError(error);

            Input.gyro.enabled = true;
            Input.compass.enabled = true;
        }
Beispiel #11
0
 public HostTopology(ConnectionConfig defaultConfig, int maxDefaultConnections)
 {
     this.m_SpecialConnections = new List<ConnectionConfig>();
     this.m_ReceivedMessagePoolSize = 0x80;
     this.m_SentMessagePoolSize = 0x80;
     this.m_MessagePoolSizeGrowthFactor = 0.75f;
     if (defaultConfig == null)
     {
         throw new NullReferenceException("config is not defined");
     }
     if (maxDefaultConnections <= 0)
     {
         throw new ArgumentOutOfRangeException("maxDefaultConnections", "count connection should be > 0");
     }
     if (maxDefaultConnections > 0xffff)
     {
         throw new ArgumentOutOfRangeException("maxDefaultConnections", "count connection should be < 65535");
     }
     ConnectionConfig.Validate(defaultConfig);
     this.m_DefConfig = new ConnectionConfig(defaultConfig);
     this.m_MaxDefConnections = maxDefaultConnections;
 }
Beispiel #12
0
 public bool Initialize()
 {
     if (this.m_BroadcastData.Length >= 0x400)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("NetworkDiscovery Initialize - data too large. max is " + 0x400);
         }
         return false;
     }
     if (!NetworkTransport.IsStarted)
     {
         NetworkTransport.Init();
     }
     if (this.m_UseNetworkManager && (NetworkManager.singleton != null))
     {
         object[] objArray1 = new object[] { "NetworkManager:", NetworkManager.singleton.networkAddress, ":", NetworkManager.singleton.networkPort };
         this.m_BroadcastData = string.Concat(objArray1);
         if (LogFilter.logInfo)
         {
             Debug.Log("NetwrokDiscovery set broadbast data to:" + this.m_BroadcastData);
         }
     }
     this.m_MsgOutBuffer = StringToBytes(this.m_BroadcastData);
     this.m_MsgInBuffer = new byte[0x400];
     this.m_BroadcastsReceived = new Dictionary<string, NetworkBroadcastResult>();
     ConnectionConfig defaultConfig = new ConnectionConfig();
     defaultConfig.AddChannel(QosType.Unreliable);
     this.m_DefaultTopology = new HostTopology(defaultConfig, 1);
     if (this.m_IsServer)
     {
         this.StartAsServer();
     }
     if (this.m_IsClient)
     {
         this.StartAsClient();
     }
     return true;
 }
 private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
 {
   this.InitializeSingleton();
   this.OnStartServer();
   if (this.m_RunInBackground)
     Application.runInBackground = true;
   NetworkCRC.scriptCRCCheck = this.scriptCRCCheck;
   NetworkServer.useWebSockets = this.m_UseWebSockets;
   if (this.m_GlobalConfig != null)
     NetworkTransport.Init(this.m_GlobalConfig);
   if (this.m_CustomConfig && this.m_ConnectionConfig != null && config == null)
   {
     this.m_ConnectionConfig.Channels.Clear();
     using (List<QosType>.Enumerator enumerator = this.m_Channels.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         int num = (int) this.m_ConnectionConfig.AddChannel(enumerator.Current);
       }
     }
     NetworkServer.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
   }
   if (config != null)
     NetworkServer.Configure(config, maxConnections);
   if (info != null)
   {
     if (!NetworkServer.Listen(info, this.m_NetworkPort))
     {
       if (LogFilter.logError)
         Debug.LogError((object) "StartServer listen failed.");
       return false;
     }
   }
   else if (this.m_ServerBindToIP && !string.IsNullOrEmpty(this.m_ServerBindAddress))
   {
     if (!NetworkServer.Listen(this.m_ServerBindAddress, this.m_NetworkPort))
     {
       if (LogFilter.logError)
         Debug.LogError((object) ("StartServer listen on " + this.m_ServerBindAddress + " failed."));
       return false;
     }
   }
   else if (!NetworkServer.Listen(this.m_NetworkPort))
   {
     if (LogFilter.logError)
       Debug.LogError((object) "StartServer listen failed.");
     return false;
   }
   this.RegisterServerMessages();
   if (LogFilter.logDebug)
     Debug.Log((object) ("NetworkManager StartServer port:" + (object) this.m_NetworkPort));
   this.isNetworkActive = true;
   string name = SceneManager.GetSceneAt(0).name;
   if (this.m_OnlineScene != string.Empty && this.m_OnlineScene != name && this.m_OnlineScene != this.m_OfflineScene)
     this.ServerChangeScene(this.m_OnlineScene);
   else
     NetworkServer.SpawnObjects();
   return true;
 }
        private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
        {
            this.OnStartServer();

              if (this.m_RunInBackground)
            Application.runInBackground = true;

              // Check if we have been given custom config info and configure server accordingly if so
              if (this.m_CustomConfig && this.m_ConnectionConfig != null && config == null)
              {
            this.m_ConnectionConfig.Channels.Clear();
            using (List<QosType>.Enumerator enumerator = this.m_Channels.GetEnumerator())
            {
              while (enumerator.MoveNext())
              {
            int num = (int) this.m_ConnectionConfig.AddChannel(enumerator.Current);
              }
            }
            NetworkServer.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
              }

              // register server handlers
              this.RegisterServerMessages();

              NetworkServer.sendPeerInfo = this.m_SendPeerInfo; // check if we are to send peer info also

              // if no custom config has been set and a config param was sent in then use that config
              if (config != null)
            NetworkServer.Configure(config, maxConnections);

              // check the MatchInfo param
              if (info != null)
              {
            if (!NetworkServer.Listen(info, this.m_NetworkPort))
            {
              if (LogFilter.logError)
            Debug.LogError((object) "StartServer listen failed.");
              return false;
            }
              }
              else if (!NetworkServer.Listen(this.m_NetworkPort))
              {
            if (LogFilter.logError)
              Debug.LogError((object) "StartServer listen failed.");
            return false;
              }

              if (LogFilter.logDebug)
            Debug.Log((object) ("NetworkManager StartServer port:" + (object) this.m_NetworkPort));

              this.isNetworkActive = true; // set the flag indicating this object is network active
              // transition to the online scene if its name has been set(must be included in build settings before being allowed to be set)
              if (this.m_OnlineScene != string.Empty && this.m_OnlineScene != Application.loadedLevelName && this.m_OnlineScene != this.m_OfflineScene)
            this.ServerChangeScene(this.m_OnlineScene);
              else
            NetworkServer.SpawnObjects();

              return true;
        }
        // Connections methods return a NetworkClient object, this method connects according to the endpoint being used
        public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
        {
            this.matchInfo = info;

              if (this.m_RunInBackground)
            Application.runInBackground = true;

              this.isNetworkActive = true;
              this.client = new NetworkClient();
              this.OnStartClient(this.client);

              // if not using a custom config
              if (config != null)
            this.client.Configure(config, 1);
              else if (this.m_CustomConfig && this.m_ConnectionConfig != null) // else using a custom config setup for our clients
              {
            this.m_ConnectionConfig.Channels.Clear();
            using (List<QosType>.Enumerator enumerator = this.m_Channels.GetEnumerator())
            {
              while (enumerator.MoveNext())
              {
            int num = (int) this.m_ConnectionConfig.AddChannel(enumerator.Current);
              }
            }
            this.client.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
              }

              this.RegisterClientMessages(this.client); // register client handlers

              // if a match was sent in then connect to that game
              if (this.matchInfo != null)
              {
            if (LogFilter.logDebug)
              Debug.Log((object) ("NetworkManager StartClient match: " + (object) this.matchInfo));
            this.client.Connect(this.matchInfo);
              }
              else if (this.m_EndPoint != null) // if we are connecting to an endpoint used by something like XboxOne, then connect there
              {
            if (LogFilter.logDebug)
              Debug.Log((object) "NetworkManager StartClient using provided SecureTunnel");
            this.client.Connect(this.m_EndPoint);
              }
              else // we are going to local connect otherwise if address has been set
              {
            if (string.IsNullOrEmpty(this.m_NetworkAddress))
            {
              if (LogFilter.logError)
            Debug.LogError((object) "Must set the Network Address field in the manager");
              return (NetworkClient) null;
            }
            if (LogFilter.logDebug)
            {
              object[] objArray = new object[4];
              int index1 = 0;
              string str1 = "NetworkManager StartClient address:";
              objArray[index1] = (object) str1;
              int index2 = 1;
              string str2 = this.m_NetworkAddress;
              objArray[index2] = (object) str2;
              int index3 = 2;
              string str3 = " port:";
              objArray[index3] = (object) str3;
              int index4 = 3;
              // ISSUE: variable of a boxed type
              __Boxed<int> local = (ValueType) this.m_NetworkPort;
              objArray[index4] = (object) local;
              Debug.Log((object) string.Concat(objArray));
            }

            // if using simulator connect that way, otherwise just complete the local network connect
            if (this.m_UseSimulator)
              this.client.ConnectWithSimulator(this.m_NetworkAddress, this.m_NetworkPort, this.m_SimulatedLatency, this.m_PacketLossPercentage);
            else
              this.client.Connect(this.m_NetworkAddress, this.m_NetworkPort);
              }

              NetworkManager.s_address = this.m_NetworkAddress;

              return this.client;
        }
Beispiel #16
0
 public static void Validate(ConnectionConfig config)
 {
     if (config.m_PacketSize < 0x80)
     {
         int num = 0x80;
         throw new ArgumentOutOfRangeException("PacketSize should be > " + num.ToString());
     }
     if (config.m_FragmentSize >= (config.m_PacketSize - 0x80))
     {
         int num2 = 0x80;
         throw new ArgumentOutOfRangeException("FragmentSize should be < PacketSize - " + num2.ToString());
     }
     if (config.m_Channels.Count > 0xff)
     {
         throw new ArgumentOutOfRangeException("Channels number should be less than 256");
     }
 }
Beispiel #17
0
        // Use this for initialization
        void Awake()
        {
            ScreenLog.Write("WebManager Awake!");

            var global = new GlobalConfig();

            Debug.Log("global recieve " + global.ReactorMaximumReceivedMessages);
            Debug.Log("global sent " + global.ReactorMaximumSentMessages);
            Debug.Log("global max " + global.MaxPacketSize);
            Debug.Log("global model " + global.ReactorModel);
            Debug.Log("global thread timeout " + global.ThreadAwakeTimeout);

            global.ReactorMaximumReceivedMessages = 50000;

            NetworkTransport.Init(global);

            var config = new ConnectionConfig();
            //config.PacketSize = PACKET_SIZE;
            config.Channels.Add(new ChannelQOS(QosType.ReliableFragmented));
            config.Channels.Add(new ChannelQOS(QosType.Unreliable));


            Debug.Log("AckDelay " + config.AckDelay);
            Debug.Log("AllCostTimeout " + config.AllCostTimeout);
            Debug.Log("ChannelCount " + config.ChannelCount);
            Debug.Log("ConnectTimeout " + config.ConnectTimeout);
            Debug.Log("DisconnectTimeout " + config.DisconnectTimeout);
            Debug.Log("FragmentSize " + config.FragmentSize);
            Debug.Log("IsAcksLong " + config.IsAcksLong);
            Debug.Log("MaxCombinedReliableMessageCount " + config.MaxCombinedReliableMessageCount);
            Debug.Log("MaxCombinedReliableMessageSize " + config.MaxCombinedReliableMessageSize);
            Debug.Log("MaxConnectionAttempt " + config.MaxConnectionAttempt);
            Debug.Log("MaxSentMessageQueueSize " + config.MaxSentMessageQueueSize);
            Debug.Log("MinUpdateTimeout " + config.MinUpdateTimeout);
            Debug.Log("NetworkDropThreshold " + config.NetworkDropThreshold);
            Debug.Log("OverflowDropThreshold " + config.OverflowDropThreshold);
            Debug.Log("PacketSize " + config.PacketSize);
            Debug.Log("PingTimeout " + config.PingTimeout);
            Debug.Log("ReducedPingTimeout " + config.ReducedPingTimeout);
            Debug.Log("ResendTimeout " + config.ResendTimeout);
            Debug.Log("UsePlatformSpecificProtocols " + config.UsePlatformSpecificProtocols);

            var topology = new HostTopology(config, 200);
            topology.ReceivedMessagePoolSize = 50000;
            //topology.SentMessagePoolSize = 50000;

            if (Application.platform != RuntimePlatform.WebGLPlayer &&
                (SystemInfo.graphicsDeviceID == 0 || forceServer))
            {
                ScreenLog.Write("Server starting!");
                IsServer = true;

                server = new WebServer(19219, 8123, topology);

                ChunkManager.Instance.LoadChunks("server.vox");
                server.RefreshMap();

            }
            else
            {
                ScreenLog.Write("Client starting!");
                client = new WebClient(topology);
#if UNITY_WEBGL
                //client.TryConnect("127.0.0.1", 8123);
                client.TryConnect("188.226.164.147", 8123);
#else
                //client.TryConnect("127.0.0.1", 19219);
                client.TryConnect("188.226.164.147", 19219);
#endif
            }
        }
Beispiel #18
0
        /// <summary>
        /// 
        /// </summary>
        private void Start()
        {
            // Multiplayer game, don't allow pausing
            Application.runInBackground = true;

            m_configuration = new ConnectionConfig();
            m_communicationChannel = m_configuration.AddChannel(QosType.Reliable);

            NetworkTransport.Init();

            var topology = new HostTopology(m_configuration, this.MaxConnections);
            m_genericHostId = NetworkTransport.AddHost(topology, 0);

            byte error;
            m_connectionId = NetworkTransport.Connect(m_genericHostId, this.ServerIP, this.ServerPort, 0, out error);
            if (error != 0 || m_connectionId == 0)
            {
                Debug.LogError(string.Format("Failed to connect to {0}:{1}", this.ServerIP, this.ServerPort));
            }

            m_packetHandlers[typeof(Server.Packet.PlayerHandshakePacket)] = OnPlayerHandshakePacket;
            m_packetHandlers[typeof(Server.Packet.PlayerJoinPacket)] = OnPlayerJoinPacket;
            m_packetHandlers[typeof(Server.Packet.PlayerMovePacket)] = OnPlayerMovePacket;
            m_packetHandlers[typeof(Server.Packet.PlayerDisconnectPacket)] = OnPlayerDisconnectPacket;
            m_packetHandlers[typeof(Server.Packet.PlayerChatPacket)] = OnPlayerChatPacket;

            m_packetHandlers[typeof(Server.Packet.MobSpawnPacket)] = OnMobSpawnPacket;
            m_packetHandlers[typeof(Server.Packet.MobMovePacket)] = OnMobMovePacket;
            m_packetHandlers[typeof(Server.Packet.MobDamagedPacket)] = OnMobDamagedPacket;
            m_packetHandlers[typeof(Server.Packet.MobDeathPacket)] = OnMobDeathPacket;

            SetupUsername();
            m_isSetup = true;
        }
 /// <summary>
 /// 
 /// <para>
 /// Will create default connection config or will copy them from another.
 /// </para>
 /// 
 /// </summary>
 /// <param name="config">Connection config.</param>
 public ConnectionConfig(ConnectionConfig config)
 {
     if (config == null)
     throw new NullReferenceException("config is not defined");
       this.m_PacketSize = config.m_PacketSize;
       this.m_FragmentSize = config.m_FragmentSize;
       this.m_ResendTimeout = config.m_ResendTimeout;
       this.m_DisconnectTimeout = config.m_DisconnectTimeout;
       this.m_ConnectTimeout = config.m_ConnectTimeout;
       this.m_MinUpdateTimeout = config.m_MinUpdateTimeout;
       this.m_PingTimeout = config.m_PingTimeout;
       this.m_ReducedPingTimeout = config.m_ReducedPingTimeout;
       this.m_AllCostTimeout = config.m_AllCostTimeout;
       this.m_NetworkDropThreshold = config.m_NetworkDropThreshold;
       this.m_OverflowDropThreshold = config.m_OverflowDropThreshold;
       this.m_MaxConnectionAttempt = config.m_MaxConnectionAttempt;
       this.m_AckDelay = config.m_AckDelay;
       this.m_MaxCombinedReliableMessageSize = config.MaxCombinedReliableMessageSize;
       this.m_MaxCombinedReliableMessageCount = config.m_MaxCombinedReliableMessageCount;
       this.m_MaxSentMessageQueueSize = config.m_MaxSentMessageQueueSize;
       this.m_IsAcksLong = config.m_IsAcksLong;
       using (List<ChannelQOS>.Enumerator enumerator = config.m_Channels.GetEnumerator())
       {
     while (enumerator.MoveNext())
       this.m_Channels.Add(new ChannelQOS(enumerator.Current));
       }
 }
 public NetworkClient StartClient(ConnectionConfig config)
 {
     return(StartClient(config, 0));
 }
        public NetworkClient StartClient(ConnectionConfig config, int hostPort)
        {
            InitializeSingleton();

            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            isNetworkActive = true;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            client          = new NetworkClient();
            client.hostPort = hostPort;

            if (config != null)
            {
                if ((config.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
                {
                    throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                }

                client.Configure(config, 1);
            }
            else
            {
                if (m_CustomConfig && m_ConnectionConfig != null)
                {
                    m_ConnectionConfig.Channels.Clear();
                    for (int i = 0; i < m_Channels.Count; i++)
                    {
                        m_ConnectionConfig.AddChannel(m_Channels[i]);
                    }
                    if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
                    {
                        throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                    }
                    client.Configure(m_ConnectionConfig, m_MaxConnections);
                }
            }

            RegisterClientMessages(client);
            if (m_EndPoint != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient using provided SecureTunnel");
                }
                client.Connect(m_EndPoint);
            }
            else
            {
                if (string.IsNullOrEmpty(m_NetworkAddress))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must set the Network Address field in the manager");
                    }
                    return(null);
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
                }

                client.Connect(m_NetworkAddress, m_NetworkPort);
            }

            OnStartClient(client);
            s_Address = m_NetworkAddress;
            return(client);
        }
Beispiel #22
0
 /// <summary>
 ///   <para>This configures the transport layer settings for a client.</para>
 /// </summary>
 /// <param name="config">Transport layer configuration object.</param>
 /// <param name="maxConnections">The maximum number of connections to allow.</param>
 /// <param name="topology">Transport layer topology object.</param>
 /// <returns>
 ///   <para>True if the configuration was successful.</para>
 /// </returns>
 public bool Configure(ConnectionConfig config, int maxConnections)
 {
     return(this.Configure(new HostTopology(config, maxConnections)));
 }
Beispiel #23
0
 public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
 {
     this.matchInfo = info;
     if (this.m_RunInBackground)
     {
         Application.runInBackground = true;
     }
     this.isNetworkActive = true;
     this.client          = new NetworkClient();
     if (config != null)
     {
         this.client.Configure(config, 1);
     }
     else if (this.m_CustomConfig && this.m_ConnectionConfig != null)
     {
         this.m_ConnectionConfig.Channels.Clear();
         foreach (QosType current in this.m_Channels)
         {
             this.m_ConnectionConfig.AddChannel(current);
         }
         this.client.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
     }
     this.RegisterClientMessages(this.client);
     if (this.matchInfo != null)
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkManager StartClient match: " + this.matchInfo);
         }
         this.client.Connect(this.matchInfo);
     }
     else if (this.m_EndPoint != null)
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkManager StartClient using provided SecureTunnel");
         }
         this.client.Connect(this.m_EndPoint);
     }
     else
     {
         if (string.IsNullOrEmpty(this.m_NetworkAddress))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("Must set the Network Address field in the manager");
             }
             return(null);
         }
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[]
             {
                 "NetworkManager StartClient address:",
                 this.m_NetworkAddress,
                 " port:",
                 this.m_NetworkPort
             }));
         }
         if (this.m_UseSimulator)
         {
             this.client.ConnectWithSimulator(this.m_NetworkAddress, this.m_NetworkPort, this.m_SimulatedLatency, this.m_PacketLossPercentage);
         }
         else
         {
             this.client.Connect(this.m_NetworkAddress, this.m_NetworkPort);
         }
     }
     this.OnStartClient(this.client);
     NetworkManager.s_Address = this.m_NetworkAddress;
     return(this.client);
 }
Beispiel #24
0
 private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
 {
     this.OnStartServer();
     if (this.m_RunInBackground)
     {
         Application.runInBackground = true;
     }
     NetworkCRC.scriptCRCCheck = this.scriptCRCCheck;
     if (this.m_CustomConfig && this.m_ConnectionConfig != null && config == null)
     {
         this.m_ConnectionConfig.Channels.Clear();
         foreach (QosType current in this.m_Channels)
         {
             this.m_ConnectionConfig.AddChannel(current);
         }
         NetworkServer.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
     }
     this.RegisterServerMessages();
     NetworkServer.sendPeerInfo  = this.m_SendPeerInfo;
     NetworkServer.useWebSockets = this.m_UseWebSockets;
     if (config != null)
     {
         NetworkServer.Configure(config, maxConnections);
     }
     if (info != null)
     {
         if (!NetworkServer.Listen(info, this.m_NetworkPort))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("StartServer listen failed.");
             }
             return(false);
         }
     }
     else if (this.m_ServerBindToIP && !string.IsNullOrEmpty(this.m_ServerBindAddress))
     {
         if (!NetworkServer.Listen(this.m_ServerBindAddress, this.m_NetworkPort))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("StartServer listen on " + this.m_ServerBindAddress + " failed.");
             }
             return(false);
         }
     }
     else if (!NetworkServer.Listen(this.m_NetworkPort))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("StartServer listen failed.");
         }
         return(false);
     }
     if (LogFilter.logDebug)
     {
         Debug.Log("NetworkManager StartServer port:" + this.m_NetworkPort);
     }
     this.isNetworkActive = true;
     if (this.m_OnlineScene != string.Empty && this.m_OnlineScene != Application.loadedLevelName && this.m_OnlineScene != this.m_OfflineScene)
     {
         this.ServerChangeScene(this.m_OnlineScene);
     }
     else
     {
         NetworkServer.SpawnObjects();
     }
     return(true);
 }
		public ConnectionConfigInternal(ConnectionConfig config)
		{
			if (config == null)
			{
				throw new NullReferenceException("config is not defined");
			}
			this.InitWrapper();
			this.InitPacketSize(config.PacketSize);
			this.InitFragmentSize(config.FragmentSize);
			this.InitResendTimeout(config.ResendTimeout);
			this.InitDisconnectTimeout(config.DisconnectTimeout);
			this.InitConnectTimeout(config.ConnectTimeout);
			this.InitMinUpdateTimeout(config.MinUpdateTimeout);
			this.InitPingTimeout(config.PingTimeout);
			this.InitReducedPingTimeout(config.ReducedPingTimeout);
			this.InitAllCostTimeout(config.AllCostTimeout);
			this.InitNetworkDropThreshold(config.NetworkDropThreshold);
			this.InitOverflowDropThreshold(config.OverflowDropThreshold);
			this.InitMaxConnectionAttempt(config.MaxConnectionAttempt);
			this.InitAckDelay(config.AckDelay);
			this.InitSendDelay(config.SendDelay);
			this.InitMaxCombinedReliableMessageSize(config.MaxCombinedReliableMessageSize);
			this.InitMaxCombinedReliableMessageCount(config.MaxCombinedReliableMessageCount);
			this.InitMaxSentMessageQueueSize(config.MaxSentMessageQueueSize);
			this.InitAcksType((int)config.AcksType);
			this.InitUsePlatformSpecificProtocols(config.UsePlatformSpecificProtocols);
			this.InitInitialBandwidth(config.InitialBandwidth);
			this.InitBandwidthPeakFactor(config.BandwidthPeakFactor);
			this.InitWebSocketReceiveBufferMaxSize(config.WebSocketReceiveBufferMaxSize);
			this.InitUdpSocketReceiveBufferMaxSize(config.UdpSocketReceiveBufferMaxSize);
			if (config.SSLCertFilePath != null)
			{
				int num = this.InitSSLCertFilePath(config.SSLCertFilePath);
				if (num != 0)
				{
					throw new ArgumentOutOfRangeException("SSLCertFilePath cannot be > than " + num.ToString());
				}
			}
			if (config.SSLPrivateKeyFilePath != null)
			{
				int num2 = this.InitSSLPrivateKeyFilePath(config.SSLPrivateKeyFilePath);
				if (num2 != 0)
				{
					throw new ArgumentOutOfRangeException("SSLPrivateKeyFilePath cannot be > than " + num2.ToString());
				}
			}
			if (config.SSLCAFilePath != null)
			{
				int num3 = this.InitSSLCAFilePath(config.SSLCAFilePath);
				if (num3 != 0)
				{
					throw new ArgumentOutOfRangeException("SSLCAFilePath cannot be > than " + num3.ToString());
				}
			}
			byte b = 0;
			while ((int)b < config.ChannelCount)
			{
				this.AddChannel(config.GetChannel(b));
				b += 1;
			}
		}
 public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnections)
 {
   this.OnStartHost();
   if (!this.StartServer(config, maxConnections))
     return (NetworkClient) null;
   NetworkClient client = this.ConnectLocalClient();
   this.OnServerConnect(client.connection);
   this.OnStartClient(client);
   return client;
 }
Beispiel #27
0
 public int AddSpecialConnectionConfig(ConnectionConfig config)
 {
     m_SpecialConnections.Add(new ConnectionConfig(config));
     return(m_SpecialConnections.Count - 1);
 }
Beispiel #28
0
        public bool Configure(ConnectionConfig config, int maxConnections)
        {
            HostTopology top = new HostTopology(config, maxConnections);

            return(Configure(top));
        }
 /// <summary>
 /// 
 /// <para>
 /// Validate parameters of connection config. Will throw exceptions if parameters are incorrect.
 /// </para>
 /// 
 /// </summary>
 /// <param name="config"/>
 public static void Validate(ConnectionConfig config)
 {
     if ((int) config.m_PacketSize < 128)
     throw new ArgumentOutOfRangeException("PacketSize should be > " + 128.ToString());
       if ((int) config.m_FragmentSize >= (int) config.m_PacketSize - 128)
     throw new ArgumentOutOfRangeException("FragmentSize should be < PacketSize - " + 128.ToString());
       if (config.m_Channels.Count > (int) byte.MaxValue)
     throw new ArgumentOutOfRangeException("Channels number should be less than 256");
 }
 /// <summary>
 ///   <para>Create topology.</para>
 /// </summary>
 /// <param name="defaultConfig">Default config.</param>
 /// <param name="maxDefaultConnections">Maximum default connections.</param>
 public HostTopology(ConnectionConfig defaultConfig, int maxDefaultConnections)
 {
   if (defaultConfig == null)
     throw new NullReferenceException("config is not defined");
   if (maxDefaultConnections <= 0)
     throw new ArgumentOutOfRangeException("maxDefaultConnections", "Number of connections should be > 0");
   if (maxDefaultConnections >= (int) ushort.MaxValue)
     throw new ArgumentOutOfRangeException("maxDefaultConnections", "Number of connections should be < 65535");
   ConnectionConfig.Validate(defaultConfig);
   this.m_DefConfig = new ConnectionConfig(defaultConfig);
   this.m_MaxDefConnections = maxDefaultConnections;
 }
Beispiel #31
0
        /// <summary>
        /// 
        /// </summary>
        private void Start()
        {
            // Multiplayer game, don't allow pausing
            Application.runInBackground = true;

            m_configuration = new ConnectionConfig();
            m_communicationChannel = m_configuration.AddChannel(QosType.Reliable);

            NetworkTransport.Init();

            var topology = new HostTopology(m_configuration, this.MaxConnections);
            m_webSocketHostId = NetworkTransport.AddWebsocketHost(topology, this.ServerPort, null);

            #if !UNITY_WEBGL
            m_genericHostId = NetworkTransport.AddHost(topology, this.ServerPort, null);
            #endif

            Debug.Log(string.Format("Server started.\nPort: {0}. Max Connections: {1}. WebSocketID: {2}.GenericHostID: {3}",
                this.ServerPort,
                this.MaxConnections,
                m_webSocketHostId,
                m_genericHostId)
            );

            m_packetHandlers[typeof(Client.Packet.PlayerConnectPacket)] = OnPlayerConnectPacket;
            m_packetHandlers[typeof(Client.Packet.PlayerMovePacket)] = OnPlayerMovePacket;
            m_packetHandlers[typeof(Client.Packet.PlayerChatSendPacket)] = OnPlayerChatSendPacket;
            m_packetHandlers[typeof(Client.Packet.PlayerAttackPacket)] = OnPlayerAttackPacket;
        }
 /// <summary>
 ///   <para>Add special connection to topology (for example if you need to keep connection to standalone chat server you will need to use this function). Returned id should be use as one of parameters (with ip and port) to establish connection to this server.</para>
 /// </summary>
 /// <param name="config">Connection config for special connection.</param>
 /// <returns>
 ///   <para>Id of this connection, user should use this id when he calls Networking.NetworkTransport.Connect.</para>
 /// </returns>
 public int AddSpecialConnectionConfig(ConnectionConfig config)
 {
   this.m_SpecialConnections.Add(new ConnectionConfig(config));
   return this.m_SpecialConnections.Count - 1;
 }
Beispiel #33
0
 public int AddSpecialConnectionConfig(ConnectionConfig config)
 {
     this.m_SpecialConnections.Add(new ConnectionConfig(config));
     return(this.m_SpecialConnections.Count);
 }
Beispiel #34
0
 public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
 {
     return(StartClient(info, config, 0));
 }
Beispiel #35
0
        public ConnectionConfigInternal(ConnectionConfig config)
        {
            bool flag = config == null;

            if (flag)
            {
                throw new NullReferenceException("config is not defined");
            }
            this.m_Ptr = ConnectionConfigInternal.InternalCreate();
            bool flag2 = !this.SetPacketSize(config.PacketSize);

            if (flag2)
            {
                throw new ArgumentOutOfRangeException("PacketSize is too small");
            }
            this.FragmentSize          = config.FragmentSize;
            this.ResendTimeout         = config.ResendTimeout;
            this.DisconnectTimeout     = config.DisconnectTimeout;
            this.ConnectTimeout        = config.ConnectTimeout;
            this.MinUpdateTimeout      = config.MinUpdateTimeout;
            this.PingTimeout           = config.PingTimeout;
            this.ReducedPingTimeout    = config.ReducedPingTimeout;
            this.AllCostTimeout        = config.AllCostTimeout;
            this.NetworkDropThreshold  = config.NetworkDropThreshold;
            this.OverflowDropThreshold = config.OverflowDropThreshold;
            this.MaxConnectionAttempt  = config.MaxConnectionAttempt;
            this.AckDelay  = config.AckDelay;
            this.SendDelay = config.SendDelay;
            this.MaxCombinedReliableMessageSize  = config.MaxCombinedReliableMessageSize;
            this.MaxCombinedReliableMessageCount = config.MaxCombinedReliableMessageCount;
            this.MaxSentMessageQueueSize         = config.MaxSentMessageQueueSize;
            this.AcksType = (byte)config.AcksType;
            this.UsePlatformSpecificProtocols  = config.UsePlatformSpecificProtocols;
            this.InitialBandwidth              = config.InitialBandwidth;
            this.BandwidthPeakFactor           = config.BandwidthPeakFactor;
            this.WebSocketReceiveBufferMaxSize = config.WebSocketReceiveBufferMaxSize;
            this.UdpSocketReceiveBufferMaxSize = config.UdpSocketReceiveBufferMaxSize;
            bool flag3 = config.SSLCertFilePath != null;

            if (flag3)
            {
                int  num   = this.SetSSLCertFilePath(config.SSLCertFilePath);
                bool flag4 = num != 0;
                if (flag4)
                {
                    throw new ArgumentOutOfRangeException("SSLCertFilePath cannot be > than " + num.ToString());
                }
            }
            bool flag5 = config.SSLPrivateKeyFilePath != null;

            if (flag5)
            {
                int  num2  = this.SetSSLPrivateKeyFilePath(config.SSLPrivateKeyFilePath);
                bool flag6 = num2 != 0;
                if (flag6)
                {
                    throw new ArgumentOutOfRangeException("SSLPrivateKeyFilePath cannot be > than " + num2.ToString());
                }
            }
            bool flag7 = config.SSLCAFilePath != null;

            if (flag7)
            {
                int  num3  = this.SetSSLCAFilePath(config.SSLCAFilePath);
                bool flag8 = num3 != 0;
                if (flag8)
                {
                    throw new ArgumentOutOfRangeException("SSLCAFilePath cannot be > than " + num3.ToString());
                }
            }
            byte b = 0;

            while ((int)b < config.ChannelCount)
            {
                this.AddChannel((int)((byte)config.GetChannel(b)));
                b += 1;
            }
            byte b2 = 0;

            while ((int)b2 < config.SharedOrderChannelCount)
            {
                IList <byte> sharedOrderChannels = config.GetSharedOrderChannels(b2);
                byte[]       array = new byte[sharedOrderChannels.Count];
                sharedOrderChannels.CopyTo(array, 0);
                this.MakeChannelsSharedOrder(array);
                b2 += 1;
            }
        }
Beispiel #36
0
        public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
        {
            InitializeSingleton();

            matchInfo = info;
            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            isNetworkActive = true;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            client = new NetworkClient();

            if (config != null)
            {
                if ((config.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                {
                    throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                }

                client.Configure(config, 1);
            }
            else
            {
                if (m_CustomConfig && m_ConnectionConfig != null)
                {
                    m_ConnectionConfig.Channels.Clear();
                    foreach (var c in m_Channels)
                    {
                        m_ConnectionConfig.AddChannel(c);
                    }
                    if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                    {
                        throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                    }
                    client.Configure(m_ConnectionConfig, m_MaxConnections);
                }
            }

            RegisterClientMessages(client);
            if (matchInfo != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient match: " + matchInfo);
                }
                client.Connect(matchInfo);
            }
            else if (m_EndPoint != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient using provided SecureTunnel");
                }
                client.Connect(m_EndPoint);
            }
            else
            {
                if (string.IsNullOrEmpty(m_NetworkAddress))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must set the Network Address field in the manager");
                    }
                    return(null);
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
                }

                if (m_UseSimulator)
                {
                    client.ConnectWithSimulator(m_NetworkAddress, m_NetworkPort, m_SimulatedLatency, m_PacketLossPercentage);
                }
                else
                {
                    client.Connect(m_NetworkAddress, m_NetworkPort);
                }
            }

#if ENABLE_UNET_HOST_MIGRATION
            if (m_MigrationManager != null)
            {
                m_MigrationManager.Initialize(client, matchInfo);
            }
#endif

            OnStartClient(client);
            s_Address = m_NetworkAddress;
            return(client);
        }
        public virtual NetworkClient StartHost(ConnectionConfig config, int maxConnections)
        {
            this.OnStartHost(); // this method is empty, just to be used to hook in

              if (!this.StartServer(config, maxConnections)) // start a server for the game and local client to connect to
            return (NetworkClient) null;

              NetworkClient client = this.ConnectLocalClient();
              //empty method, just to hook in and do anything with the NetworkClient before it is returned to the caller of StartHost
              this.OnStartClient(client);

              return client;
        }
Beispiel #38
0
        private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
        {
            InitializeSingleton();
            OnStartServer();
            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }
            NetworkCRC.scriptCRCCheck   = scriptCRCCheck;
            NetworkServer.useWebSockets = m_UseWebSockets;
            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }
            if (m_CustomConfig && m_ConnectionConfig != null && config == null)
            {
                m_ConnectionConfig.Channels.Clear();
                for (int i = 0; i < m_Channels.Count; i++)
                {
                    m_ConnectionConfig.AddChannel(m_Channels[i]);
                }
                NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
            }
            if (config != null)
            {
                NetworkServer.Configure(config, maxConnections);
            }
            if (info != null)
            {
                if (!NetworkServer.Listen(info, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen failed.");
                    }
                    return(false);
                }
            }
            else if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
            {
                if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed.");
                    }
                    return(false);
                }
            }
            else if (!NetworkServer.Listen(m_NetworkPort))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("StartServer listen failed.");
                }
                return(false);
            }
            RegisterServerMessages();
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkManager StartServer port:" + m_NetworkPort);
            }
            isNetworkActive = true;
            string name = SceneManager.GetSceneAt(0).name;

            if (!string.IsNullOrEmpty(m_OnlineScene) && m_OnlineScene != name && m_OnlineScene != m_OfflineScene)
            {
                ServerChangeScene(m_OnlineScene);
            }
            else
            {
                NetworkServer.SpawnObjects();
            }
            return(true);
        }
 public bool StartServer(ConnectionConfig config, int maxConnections)
 {
   return this.StartServer((MatchInfo) null, config, maxConnections);
 }
Beispiel #40
0
 public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
 {
     this.matchInfo = info;
     if (this.m_RunInBackground)
     {
         Application.runInBackground = true;
     }
     this.isNetworkActive = true;
     this.client = new NetworkClient();
     if (config != null)
     {
         this.client.Configure(config, 1);
     }
     else if (this.m_CustomConfig && (this.m_ConnectionConfig != null))
     {
         this.m_ConnectionConfig.Channels.Clear();
         foreach (QosType type in this.m_Channels)
         {
             this.m_ConnectionConfig.AddChannel(type);
         }
         this.client.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
     }
     this.RegisterClientMessages(this.client);
     if (this.matchInfo != null)
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkManager StartClient match: " + this.matchInfo);
         }
         this.client.Connect(this.matchInfo);
     }
     else if (this.m_EndPoint != null)
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("NetworkManager StartClient using provided SecureTunnel");
         }
         this.client.Connect(this.m_EndPoint);
     }
     else
     {
         if (string.IsNullOrEmpty(this.m_NetworkAddress))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("Must set the Network Address field in the manager");
             }
             return null;
         }
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "NetworkManager StartClient address:", this.m_NetworkAddress, " port:", this.m_NetworkPort }));
         }
         if (this.m_UseSimulator)
         {
             this.client.ConnectWithSimulator(this.m_NetworkAddress, this.m_NetworkPort, this.m_SimulatedLatency, this.m_PacketLossPercentage);
         }
         else
         {
             this.client.Connect(this.m_NetworkAddress, this.m_NetworkPort);
         }
     }
     this.OnStartClient(this.client);
     s_Address = this.m_NetworkAddress;
     return this.client;
 }
 public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
 {
   this.InitializeSingleton();
   this.matchInfo = info;
   if (this.m_RunInBackground)
     Application.runInBackground = true;
   this.isNetworkActive = true;
   if (this.m_GlobalConfig != null)
     NetworkTransport.Init(this.m_GlobalConfig);
   this.client = new NetworkClient();
   if (config != null)
   {
     if (config.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4)
       throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
     this.client.Configure(config, 1);
   }
   else if (this.m_CustomConfig && this.m_ConnectionConfig != null)
   {
     this.m_ConnectionConfig.Channels.Clear();
     using (List<QosType>.Enumerator enumerator = this.m_Channels.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         int num = (int) this.m_ConnectionConfig.AddChannel(enumerator.Current);
       }
     }
     if (this.m_ConnectionConfig.UsePlatformSpecificProtocols && Application.platform != RuntimePlatform.PS4)
       throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
     this.client.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
   }
   this.RegisterClientMessages(this.client);
   if (this.matchInfo != null)
   {
     if (LogFilter.logDebug)
       Debug.Log((object) ("NetworkManager StartClient match: " + (object) this.matchInfo));
     this.client.Connect(this.matchInfo);
   }
   else if (this.m_EndPoint != null)
   {
     if (LogFilter.logDebug)
       Debug.Log((object) "NetworkManager StartClient using provided SecureTunnel");
     this.client.Connect(this.m_EndPoint);
   }
   else
   {
     if (string.IsNullOrEmpty(this.m_NetworkAddress))
     {
       if (LogFilter.logError)
         Debug.LogError((object) "Must set the Network Address field in the manager");
       return (NetworkClient) null;
     }
     if (LogFilter.logDebug)
       Debug.Log((object) ("NetworkManager StartClient address:" + this.m_NetworkAddress + " port:" + (object) this.m_NetworkPort));
     if (this.m_UseSimulator)
       this.client.ConnectWithSimulator(this.m_NetworkAddress, this.m_NetworkPort, this.m_SimulatedLatency, this.m_PacketLossPercentage);
     else
       this.client.Connect(this.m_NetworkAddress, this.m_NetworkPort);
   }
   if ((UnityEngine.Object) this.m_MigrationManager != (UnityEngine.Object) null)
     this.m_MigrationManager.Initialize(this.client, this.matchInfo);
   this.OnStartClient(this.client);
   NetworkManager.s_Address = this.m_NetworkAddress;
   return this.client;
 }
Beispiel #42
0
 private bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
 {
     this.OnStartServer();
     if (this.m_RunInBackground)
     {
         Application.runInBackground = true;
     }
     NetworkCRC.scriptCRCCheck = this.scriptCRCCheck;
     if ((this.m_CustomConfig && (this.m_ConnectionConfig != null)) && (config == null))
     {
         this.m_ConnectionConfig.Channels.Clear();
         foreach (QosType type in this.m_Channels)
         {
             this.m_ConnectionConfig.AddChannel(type);
         }
         NetworkServer.Configure(this.m_ConnectionConfig, this.m_MaxConnections);
     }
     this.RegisterServerMessages();
     NetworkServer.sendPeerInfo = this.m_SendPeerInfo;
     if (config != null)
     {
         NetworkServer.Configure(config, maxConnections);
     }
     if (info != null)
     {
         if (!NetworkServer.Listen(info, this.m_NetworkPort))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("StartServer listen failed.");
             }
             return false;
         }
     }
     else if (this.m_ServerBindToIP && !string.IsNullOrEmpty(this.m_ServerBindAddress))
     {
         if (!NetworkServer.Listen(this.m_ServerBindAddress, this.m_NetworkPort))
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("StartServer listen on " + this.m_ServerBindAddress + " failed.");
             }
             return false;
         }
     }
     else if (!NetworkServer.Listen(this.m_NetworkPort))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("StartServer listen failed.");
         }
         return false;
     }
     if (LogFilter.logDebug)
     {
         Debug.Log("NetworkManager StartServer port:" + this.m_NetworkPort);
     }
     this.isNetworkActive = true;
     if (((this.m_OnlineScene != string.Empty) && (this.m_OnlineScene != Application.loadedLevelName)) && (this.m_OnlineScene != this.m_OfflineScene))
     {
         this.ServerChangeScene(this.m_OnlineScene);
     }
     else
     {
         NetworkServer.SpawnObjects();
     }
     return true;
 }
Beispiel #43
0
 public bool StartServer(ConnectionConfig config, int maxConnections)
 {
     return(StartServer(null, config, maxConnections));
 }
 public ConnectionConfigInternal(ConnectionConfig config)
 {
     if (config == null)
     {
         throw new NullReferenceException("config is not defined");
     }
     m_Ptr = InternalCreate();
     if (!SetPacketSize(config.PacketSize))
     {
         throw new ArgumentOutOfRangeException("PacketSize is too small");
     }
     this.FragmentSize          = config.FragmentSize;
     this.ResendTimeout         = config.ResendTimeout;
     this.DisconnectTimeout     = config.DisconnectTimeout;
     this.ConnectTimeout        = config.ConnectTimeout;
     this.MinUpdateTimeout      = config.MinUpdateTimeout;
     this.PingTimeout           = config.PingTimeout;
     this.ReducedPingTimeout    = config.ReducedPingTimeout;
     this.AllCostTimeout        = config.AllCostTimeout;
     this.NetworkDropThreshold  = config.NetworkDropThreshold;
     this.OverflowDropThreshold = config.OverflowDropThreshold;
     this.MaxConnectionAttempt  = config.MaxConnectionAttempt;
     this.AckDelay  = config.AckDelay;
     this.SendDelay = config.SendDelay;
     this.MaxCombinedReliableMessageSize  = config.MaxCombinedReliableMessageSize;
     this.MaxCombinedReliableMessageCount = config.MaxCombinedReliableMessageCount;
     this.MaxSentMessageQueueSize         = config.MaxSentMessageQueueSize;
     this.AcksType = (byte)config.AcksType;
     this.UsePlatformSpecificProtocols  = config.UsePlatformSpecificProtocols;
     this.InitialBandwidth              = config.InitialBandwidth;
     this.BandwidthPeakFactor           = config.BandwidthPeakFactor;
     this.WebSocketReceiveBufferMaxSize = config.WebSocketReceiveBufferMaxSize;
     this.UdpSocketReceiveBufferMaxSize = config.UdpSocketReceiveBufferMaxSize;
     if (config.SSLCertFilePath != null)
     {
         int len = SetSSLCertFilePath(config.SSLCertFilePath);
         if (len != 0)
         {
             throw new ArgumentOutOfRangeException("SSLCertFilePath cannot be > than " + len.ToString());
         }
     }
     if (config.SSLPrivateKeyFilePath != null)
     {
         int len = SetSSLPrivateKeyFilePath(config.SSLPrivateKeyFilePath);
         if (len != 0)
         {
             throw new ArgumentOutOfRangeException("SSLPrivateKeyFilePath cannot be > than " + len.ToString());
         }
     }
     if (config.SSLCAFilePath != null)
     {
         int len = SetSSLCAFilePath(config.SSLCAFilePath);
         if (len != 0)
         {
             throw new ArgumentOutOfRangeException("SSLCAFilePath cannot be > than " + len.ToString());
         }
     }
     for (byte i = 0; i < config.ChannelCount; ++i)
     {
         AddChannel((byte)config.GetChannel(i));
     }
     for (byte i = 0; i < config.SharedOrderChannelCount; ++i)
     {
         IList <byte> sharedOrderChannelsList  = config.GetSharedOrderChannels(i);
         byte[]       sharedOrderChannelsArray = new byte[sharedOrderChannelsList.Count];
         sharedOrderChannelsList.CopyTo(sharedOrderChannelsArray, 0);
         MakeChannelsSharedOrder(sharedOrderChannelsArray);
     }
 }
Beispiel #45
0
        // Use this for initialization
        private void Start()
        {
            var config = new ConnectionConfig();
            state = config.AddChannel(QosType.Unreliable);
            reliable = config.AddChannel(QosType.ReliableSequenced);
            var topology = new HostTopology(config, 10);

            host = NetworkTransport.AddHost(topology, port);
            NetworkTransport.SetBroadcastCredentials(host, 1, 1, 1, out error);

            TestError(error);

            ms = new MemoryStream(data);
            reader = new BinaryReader(ms);
            writer = new BinaryWriter(ms);
        }
Beispiel #46
0
        bool StartServer(MatchInfo info, ConnectionConfig config, int maxConnections)
        {
            InitializeSingleton();

            OnStartServer();

            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            NetworkCRC.scriptCRCCheck   = scriptCRCCheck;
            NetworkServer.useWebSockets = m_UseWebSockets;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            // passing a config overrides setting the connectionConfig property
            if (m_CustomConfig && m_ConnectionConfig != null && config == null)
            {
                m_ConnectionConfig.Channels.Clear();
                foreach (var c in m_Channels)
                {
                    m_ConnectionConfig.AddChannel(c);
                }
                NetworkServer.Configure(m_ConnectionConfig, m_MaxConnections);
            }

            if (config != null)
            {
                NetworkServer.Configure(config, maxConnections);
            }

            if (info != null)
            {
                if (!NetworkServer.Listen(info, m_NetworkPort))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("StartServer listen failed.");
                    }
                    return(false);
                }
            }
            else
            {
                if (m_ServerBindToIP && !string.IsNullOrEmpty(m_ServerBindAddress))
                {
                    if (!NetworkServer.Listen(m_ServerBindAddress, m_NetworkPort))
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("StartServer listen on " + m_ServerBindAddress + " failed.");
                        }
                        return(false);
                    }
                }
                else
                {
                    if (!NetworkServer.Listen(m_NetworkPort))
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("StartServer listen failed.");
                        }
                        return(false);
                    }
                }
            }

            // this must be after Listen(), since that registers the default message handlers
            RegisterServerMessages();

            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkManager StartServer port:" + m_NetworkPort);
            }
            isNetworkActive = true;

            // Only change scene if the requested online scene is not blank, and is not already loaded
            string loadedSceneName = SceneManager.GetSceneAt(0).name;

            if (m_OnlineScene != "" && m_OnlineScene != loadedSceneName && m_OnlineScene != m_OfflineScene)
            {
                ServerChangeScene(m_OnlineScene);
            }
            else
            {
                NetworkServer.SpawnObjects();
            }
            return(true);
        }