public void CreateServer() { RegisterHandlers(); var config = new ConnectionConfig(); config.AddChannel(QosType.Reliable); config.AddChannel(QosType.Unreliable); var ht = new HostTopology(config, _maxConnections); if (!NetworkServer.Configure(ht)) { Debug.Log("No server created error en configure"); return; } else { if (NetworkServer.Listen(_port)) { Debug.Log("Server created"); } else { Debug.Log("No server created, error en Listen"); } } Debug.Log("Port: " + _port); }
/// <summary> /// Initializes the lobby /// </summary> /// <param name="port">The port to listen to</param> /// <param name="maxPlayers">Maximum number of allowed players</param> public void Initialize(int port, int maxPlayers) { ConnectionConfig cc = new ConnectionConfig(); cc.AddChannel(QosType.Reliable); cc.AddChannel(QosType.ReliableFragmented); NetworkServer.Configure(cc, maxPlayers); NetworkServer.RegisterHandler(MsgType.Connect, netMsg => { if (OnClientConnected != null) { OnClientConnected(netMsg.conn); } }); NetworkServer.RegisterHandler(MsgType.Disconnect, netMsg => { if (OnClientConnected != null) { OnClientConnected(netMsg.conn); } }); if (NetworkServer.Listen(port)) { if (OnInitialized != null) { OnInitialized(); } } }
TimeSpan whiteListTimeOut = new TimeSpan(6,0,0); // 6 hours for the whitelist to time out // 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 void StartServer() { StopBroadcast(); Application.runInBackground = true; var config = new ConnectionConfig(); config.AddChannel(QosType.ReliableFragmented); config.AddChannel(QosType.UnreliableFragmented); var ht = new HostTopology(config, 30); if (!NetworkServer.Configure(ht)) { return; } if (EmptyPort()) { Initialize(); ServerInfo info = new ServerInfo(); info.name = nm.serverName; info.port = port; info.ip = ""; broadcastData = JsonUtility.ToJson(info); StartAsServer(); } }
public void OnMatchCreate(CreateMatchResponse matchResponse) { if (matchResponse.success) { Debug.Log("Create match succeeded"); Debug.Log(matchResponse.networkId); Debug.Log(Utility.GetSourceID().ToString()); ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableFragmented); config.AddChannel(QosType.UnreliableFragmented); NetworkServer.Configure(config, 3); NetworkServer.RegisterHandler(MsgType.Connect, OnPlayerConnected); NetworkServer.RegisterHandler(100, OnClientMessage); NetworkServer.Listen(new MatchInfo(matchResponse), 25000); Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString)); UnityMatchmaking.Instance.MasterServerConnection.matchMaker.JoinMatch(matchResponse.networkId, "", OnServerMatchJoined); UnityMatchmaking.Instance.LastGameId = matchResponse.networkId; } else { Debug.LogError("Create match failed"); } }
/// <summary> /// Start as server and if discovery not running, start broadcast. /// </summary> public void SetupServer() { if (!NetworkServer.active) { Debug.Log("SetupServer( )"); ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, 1000); NetworkServer.dontListen = false; NetworkServer.Listen(4444); // 注册回调绑定 NetworkServer.RegisterHandler(MsgType.Connect, OnConnected); NetworkServer.RegisterHandler(MsgType.Disconnect, OnDisconnected); NetworkServer.RegisterHandler(MyMsgType.UID, OnUID); NetworkServer.RegisterHandler(MyMsgType.Custom, OnCustomMessage); } if (!discovery.running) { discovery.Initialize(); discovery.StartAsServer(); } }
/// <summary> /// Setups the server and listen to an incomming connection. /// </summary> public void SetupServer() { ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); NetworkServer.Configure(config, 1); // register handler NetworkServer.RegisterHandler(MsgType.Connect, this.OnClientConnect); NetworkServer.RegisterHandler(MsgType.Disconnect, this.OnClientDisconnect); NetworkServer.RegisterHandler(MsgType.Error, this.OnServerError); // register application-specific handlers // buttons NetworkServer.RegisterHandler(InputMsgType.ButtonPress, this.OnReceiveButton); // mouse buttons NetworkServer.RegisterHandler(InputMsgType.MouseButtonPress, this.OnReceiveMouseButton); // keys NetworkServer.RegisterHandler(InputMsgType.KeyPress, this.OnReceiveKey); // axis NetworkServer.RegisterHandler(InputMsgType.Axis, this.OnReceiveAxis); // acceleration NetworkServer.RegisterHandler(InputMsgType.Acceleration, this.OnReceiveAcceleration); // compass NetworkServer.RegisterHandler(InputMsgType.Compass, this.OnReceiveCompass); // gyroscope NetworkServer.RegisterHandler(InputMsgType.Gyroscope, this.OnReceiveGyroscope); this.isStarted = NetworkServer.Listen(this.Port); #if UNITY_EDITOR Debug.LogFormat("Listening {0}@{1}", this.GetLocalIP(), this.Port); #endif }
private void InitializeNetwork() { Debug.Log("Began initializeNetwork"); ConnectionConfig myConfig = new ConnectionConfig(); myConfig.AddChannel(QosType.Reliable); myConfig.AddChannel(QosType.Unreliable); myConfig.AddChannel(QosType.StateUpdate); myConfig.AddChannel(QosType.AllCostDelivery); myConfig.NetworkDropThreshold = 95; //95% packets that need to be dropped before connection is dropped myConfig.OverflowDropThreshold = 30; //30% packets that need to be dropped before sendupdate timeout is increased myConfig.InitialBandwidth = 0; myConfig.MinUpdateTimeout = 10; myConfig.ConnectTimeout = 2000; // timeout before re-connect attempt will be made myConfig.PingTimeout = 1500; // should have more than 3 pings per disconnect timeout, and more than 5 messages per ping myConfig.DisconnectTimeout = 6000; // with a ping of 500 a disconnectimeout of 2000 is supposed to work well myConfig.PacketSize = 1470; myConfig.SendDelay = 2; myConfig.FragmentSize = 1300; myConfig.AcksType = ConnectionAcksType.Acks128; myConfig.MaxSentMessageQueueSize = 256; myConfig.AckDelay = 1; HostTopology myTopology = new HostTopology(myConfig, 4); //up to 4 connection allowed NetworkServer.Configure(myTopology); Debug.Log("Finished initializeNetwork"); }
private void CreateServer() { RegisterHandlers(); var config = new ConnectionConfig(); config.AddChannel(QosType.ReliableFragmented); config.AddChannel(QosType.UnreliableFragmented); var ht = new HostTopology(config, maxConnections); if (!NetworkServer.Configure(ht)) { Debug.Log("No server created, error on the configuration definition"); return; } else { if (NetworkServer.Listen(NetworkManager.Port)) { Debug.Log("Server created, listening on port: " + NetworkManager.Port); } else { Debug.Log("No server created, could not listen to the port: " + NetworkManager.Port); } } }
void CreateServer() { // Register handlers for the types of messages we can receive RegisterHandlers(); var config = new ConnectionConfig(); // There are different types of channels you can use, check the official documentation config.AddChannel(QosType.ReliableFragmented); config.AddChannel(QosType.UnreliableFragmented); var ht = new HostTopology(config, maxConnections); if (!NetworkServer.Configure(ht)) { Debug.Log("No server created, error on the configuration definition"); return; } else { // Start listening on the defined port if (NetworkServer.Listen(port)) { Debug.Log("Server created, listening on port: " + port); } else { Debug.Log("No server created, could not listen to the port: " + port); } } }
IEnumerator StartServerE() { ttimer = 0; ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.UnreliableSequenced); config.PacketSize = 1500; config.SendDelay = 0; config.AckDelay = 0; config.MinUpdateTimeout = 1; NetworkServer.Configure(config, 8); NetworkServer.Listen(port); NetworkServer.RegisterHandler(MsgType.Connect, OnSConnected); NetworkServer.RegisterHandler(MsgType.Disconnect, OnSDConnected); NetworkServer.RegisterHandler(MyMessageTypes.Ping, OnPingS); while (!NetworkServer.active) { Debug.Log("Still creating server"); ttimer += Time.deltaTime; if (ttimer > DCSeconds) { Debug.Log("Cant create server"); yield break; } yield return(new WaitForEndOfFrame()); } Debug.Log("Server created"); yield break; }
//Returns true if server created, false otherwise public bool CreateServer() { serverLog.Add("Attempting to create server"); // Register handlers for the types of messages we can receive RegisterHandlers(); ConnectionConfig config = new ConnectionConfig(); // There are different types of channels you can use, check the official documentation reliableChannelId = config.AddChannel(QosType.Reliable); HostTopology ht = new HostTopology(config, maxConnections); if (!NetworkServer.Configure(ht)) { serverLog.Add("No server created, error on the configuration definition"); return(false); } else { // Start listening on the defined port if (NetworkServer.Listen(port)) { serverLog.Add("Server created, listening on port: " + port); return(true); } else { serverLog.Add("No server created, could not listen to the port: " + port); return(false); } } }
public bool StartUNETServer() { if (SteamNetworkManager.Instance.LobbyConnectionState != SteamNetworkManager.SessionConnectionState.CONNECTED) { Debug.LogError("Not connected to lobby"); return(false); } Debug.Log("Starting UNET server"); // Listen for player spawn request messages NetworkServer.RegisterHandler(NetworkMessages.SpawnRequestMsg, OnSpawnRequested); // Start UNET server NetworkServer.Configure(SteamNetworkManager.hostTopology); NetworkServer.dontListen = true; NetworkServer.Listen(0); NetworkServer.SpawnObjects(); // Create a local client-to-server connection to the "server" // Connect to localhost to trick UNET's ConnectState state to "Connected", which allows data to pass through TransportSend myClient = ClientScene.ConnectLocalServer(); myClient.Configure(SteamNetworkManager.hostTopology); myClient.Connect("localhost", 0); myClient.connection.ForceInitialize(); // Add local client to server's list of connections // Here we get the connection from the NetworkServer because it represents the server-to-client connection var serverToClientConn = NetworkServer.connections[0]; AddConnection(serverToClientConn); // register networked prefabs SteamNetworkManager.Instance.RegisterNetworkPrefabs(); // Spawn self ClientScene.Ready(serverToClientConn); // Hack trick to find and respawn NetworkIdentity objects to enable rpc NetworkIdentity[] objectsToSpawn = GameObject.FindObjectsOfType <NetworkIdentity>(); foreach (NetworkIdentity uv in objectsToSpawn) { NetworkServer.UnSpawn(uv.gameObject); NetworkServer.Spawn(uv.gameObject); } NetworkServer.SetClientReady(serverToClientConn); if (inviteFriendOnStart) { // prompt to invite friend SteamNetworkManager.Instance.StartCoroutine(DoShowInviteDialogWhenReady()); } return(true); }
void Start() { ConnectionConfig config = new ConnectionConfig(); //50% of packets can be dropped before drop connection request - reconmended by unity for wireless connections config.NetworkDropThreshold = 60; config.OverflowDropThreshold = 15; NetworkServer.Configure(config, 6); }
private void Setup() { var config = new ConnectionConfig(); config.AddChannel(QosType.ReliableFragmented); config.AddChannel(QosType.UnreliableFragmented); NetworkServer.Configure(config, 2); Application.runInBackground = true; }
public void StartServer(int port) { HostTopology topology = new HostTopology(MasterClient.CreateConnectionConfig(), 3000); NetworkServer.Configure(topology); NetworkServer.SetNetworkConnectionClass <TPeer>(); NetworkServer.Listen(port); NetworkServer.RegisterHandler(MsgType.Connect, OnPeerConnectedMsg); NetworkServer.RegisterHandler(MsgType.Disconnect, OnPeerDisconnectedMsg); }
private bool LaunchServer(int port) { if (NetworkServer.active) { return(false); } Spawner = GetComponent <Spawner>(); ConnectionConfig Config = new ConnectionConfig(); NetworkChannelID.ReliableSequenced = Config.AddChannel(QosType.ReliableSequenced); NetworkChannelID.UnreliableSequenced = Config.AddChannel(QosType.UnreliableSequenced); NetworkChannelID.Unreliable = Config.AddChannel(QosType.Unreliable); NetworkServer.Configure(Config, 10); NetworkServer.Listen(port); Spawner.SyncDB.SetStaticObjectsIDs(); NetworkServer.RegisterHandler(PktType.TextMessage, HandlePacket); NetworkServer.RegisterHandler(PktType.MoveCreature, HandlePacket); NetworkServer.RegisterHandler(PktType.Interact, HandlePacket); NetworkServer.RegisterHandler(PktType.ClientSync, HandlePacket); NetworkServer.RegisterHandler(PktType.Disconnect, HandlePacket); NetworkServer.RegisterHandler(PktType.FailedChecksums, HandlePacket); NetworkServer.RegisterHandler(PktType.InventoryAction, HandlePacket); NetworkServer.RegisterHandler(MsgType.Connect, OnConnected); NetworkServer.RegisterHandler(MsgType.Disconnect, OnDisconnected); NetworkServer.RegisterHandler(MsgType.Error, OnError); Debug.Log("Server started on port " + port); Term.Println("Server started on port " + port); Term.AddCommand("send (message)", "Howl at the darkness of space. Does it echo though?", (args) => { Term.Println("You: " + args[0]); SendToAll(PktType.TextMessage, new TextMessagePkt("Server: " + args[0])); }); Term.AddCommand("unhost", "Shuts down the server, shut it all down!", (args) => { Term.Println("Unhosting the server."); Shutdown(); }); Syncer = gameObject.AddComponent <ServerSyncer>(); ServerSyncHandler = new ServerSyncHandler(Players); return(true); }
void Start() { Debug.Log("Starting server..."); NetworkTransport.Init(); ConnectionConfig config = new ConnectionConfig(); HostTopology topology = new HostTopology(config, 10); channelId = config.AddChannel(QosType.ReliableSequenced); NetworkServer.Configure(topology); hostId = NetworkTransport.AddHost(topology, port); Debug.Log("Host ID: " + hostId); }
public IEnumerator ClientCanConnectAfterFailureTest() { NetworkClient.ShutdownAll(); NetworkServer.Reset(); NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnected); config = new ConnectionConfig(); config.AddChannel(QosType.ReliableFragmented); if (!NetworkServer.Configure(config, 10)) { Assert.Fail("Server configure failed"); } // Mismatched channels between client 1 and server, so connect will fail with CRCMismatch error ConnectionConfig customConfig = new ConnectionConfig(); customConfig.AddChannel(QosType.UnreliableFragmented); client1 = new NetworkClient(); if (!client1.Configure(customConfig, 10)) { Assert.Fail("Client1 configure failed"); } client1.RegisterHandler(MsgType.Connect, OnClient1Connected); client1.RegisterHandler(MsgType.Disconnect, OnClient1Disconnected); int retries = 0; while (!NetworkServer.Listen("127.0.0.1", ++kListenPort)) { Assert.IsTrue(retries++ < 10, "Couldn't Listen for more than 10 retries"); } LogAssert.Expect(LogType.Error, "UNet Client Disconnect Error: CRCMismatch"); client1.Connect("127.0.0.1", kListenPort); while (!serverRecievedConnection || !isClientConnected) { yield return(null); } NetworkServer.DisconnectAll(); while (!isTestDone) { yield return(null); } }
public IEnumerator HavingManyLocalClientsSimultaneouslyWorksTest() { NetworkClient.ShutdownAll(); NetworkServer.Reset(); ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, maxConnections); NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnected); int retries = 0; while (!NetworkServer.Listen("127.0.0.1", ++kListenPort)) { Assert.IsTrue(retries++ < 10, "Couldn't Listen for more than 10 retries"); } for (int i = 0; i < numClients; ++i) { NetworkClient myClient = new NetworkClient(); if (!myClient.Configure(config, maxConnections)) { Assert.Fail("Client configure failed"); } myClient.RegisterHandler(MsgType.Connect, OnClientConnected); myClient.RegisterHandler(MsgType.Error, OnError); myClient.RegisterHandler(kMsgTest, OnClientTest); myClient.Connect("127.0.0.1", kListenPort); } while (serverConnections != numClients || clientsConnected != numClients) { yield return(null); } TestMessage testMsg = new TestMessage(); testMsg.number = 98756; testMsg.str = "teststring"; NetworkServer.SendToAll(kMsgTest, testMsg); while (msgCountClientRecieved != numClients) { yield return(null); } }
private void SetupServer(string ip) { if (ip == "") { StartAsServer(); } ConnectionConfig connConfig = new ConnectionConfig(); connConfig.AddChannel(QosType.ReliableSequenced); NetworkServer.Configure(connConfig, 1); RegisterHandler(MsgType.Error, ErrorHandler); RegisterHandler(MsgType.Connect, OnClientConnect); NetworkServer.Listen(PORT); }
public IEnumerator DisconnectAllWorksTest() { NetworkClient.ShutdownAll(); NetworkServer.Reset(); ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, maxConnections); NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnected); int retries = 0; while (!NetworkServer.Listen("127.0.0.1", ++kListenPort)) { Assert.IsTrue(retries++ < 10, "Couldn't Listen for more than 10 retries"); } for (int i = 0; i < numClients; ++i) { NetworkClient myClient = new NetworkClient(); if (!myClient.Configure(config, maxConnections)) { Assert.Fail("Client configure failed"); } myClient.RegisterHandler(MsgType.Connect, OnClientConnected); myClient.RegisterHandler(MsgType.Disconnect, OnClientDisconnected); myClient.Connect("127.0.0.1", kListenPort); } while (serverConnections != numClients || clientsConnected != numClients) { yield return(null); } NetworkServer.DisconnectAll(); while (clientsDisccnnected != numClients) { yield return(null); } Assert.IsTrue(NetworkServer.active, "NetworkServer should still be active after DisconnectAll()"); }
public void ServerStart() { if (SQL_sqlConnect.SqlUp) { if (!isAtStartup) { ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.Reliable); config.AddChannel(QosType.Unreliable); NetworkServer.useWebSockets = useWebSockets.isOn; //NetworkServer.Configure(config, MaxConnection); HostTopology host = new HostTopology(config, MaxConnection); NetworkServer.Configure(host); if (NetworkServer.Listen(Port)) { NetworkServer.RegisterHandler(MsgType.Connect, OnConn); NetworkServer.RegisterHandler(Networking_msgType_Sr.LoginSend, Networking_OnConnect.LoginGet); NetworkServer.RegisterHandler(Networking_msgType_Sr.PlayerMove, Networking_OnPlayerAction.OnPlMove); NetworkServer.RegisterHandler(Networking_msgType_Sr.JoinToRoom, Networking_OnPlayerSelect.HandlerJoinToRoom); NetworkServer.RegisterHandler(MsgType.Disconnect, OnDisconnect); NetworkServer.RegisterHandler(Networking_msgType_Sr.OnPlayerReady, RoomsManager.HandlerReady); NetworkServer.RegisterHandler(Networking_msgType_Sr.Registration, SQL_AccountRegistration.CreatNewAccount); NetworkServer.RegisterHandler(Networking_msgType_Sr.CharCreate, SQL_AccountRegistration.CreateChar); NetworkServer.RegisterHandler(Networking_msgType_Sr.RoomList, RoomsManager.GetRoomsList); NetworkServer.RegisterHandler(Networking_msgType_Sr.RoomCreate, Networking_OnPlayerSelect.HandlerCreateRoom); NetworkServer.RegisterHandler(Networking_msgType_Sr.Chat, Networking_Chat_Sr.ChatHandler); NetworkServer.RegisterHandler(Networking_msgType_Sr.PasswordRecovery, SQL_PasswordRecovery.PasswordRecovery); NetworkServer.RegisterHandler(Networking_msgType_Sr.MouseButton, Networking_OnPlayerAction.OnMouseButton); NetworkServer.RegisterHandler(Networking_msgType_Sr.Respawn, Networking_OnPlayerAction.HandleRespawn); NetworkServer.RegisterHandler(Networking_msgType_Sr.Reload, Networking_OnPlayerAction.HandleReload); NetworkServer.RegisterHandler(Networking_msgType_Sr.TopList, SQL_sqlConnect.SendTopList); NetworkServer.RegisterHandler(Networking_msgType_Sr.DropWeapon, Networking_OnPlayerAction.HandleDropWeapon); NetworkServer.RegisterHandler(Networking_msgType_Sr.PickUp, Networking_OnPlayerAction.HandlePickUpItem); NetworkServer.RegisterHandler(Networking_msgType_Sr.DisconnectAtRoom, RoomsManager.HandlerPlayerDisconnectAtRoom); isAtStartup = true; Debug.Log("Server start"); ErrorMsg("Server start"); } } } else { ErrorMsg("Please first connect to MySQL!"); } }
/// <summary> /// Unity's Start method. /// </summary> protected override void Start() { base.Start(); webGLServer.SetNetworkConnectionClass <MasterServerWebGLCustomNetworkConnection>(); webGLServer.useWebSockets = true; webGLServer.RegisterHandler(MsgType.Connect, OnWebGLConnected); webGLServer.RegisterHandler(MsgType.Disconnect, OnWebGLDisconnected); webGLServer.Listen(ip, port); webGLHostId = webGLServer.serverHostId; var config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, maxPlayers > 0 ? maxPlayers : 1024); NetworkServer.useWebSockets = false; NetworkServer.Listen(ip, port); }
// Use this for initialization void Start() { _chatText.text = ""; _sendTextInput.text = ""; Application.runInBackground = true; RegisterHandlers(); var config = new ConnectionConfig(); config.AddChannel(QosType.Reliable); config.AddChannel(QosType.Unreliable); var ht = new HostTopology(config, _maxConnections); if (!NetworkServer.Configure(ht) || !NetworkServer.Listen(_port)) { Debug.LogError("No server created"); return; } }
private void startServer() { ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.Reliable); config.AddChannel(QosType.Unreliable); HostTopology host = new HostTopology(config, maxConnenction); NetworkServer.Configure(host); if (NetworkServer.Listen(port)) { NetworkServer.RegisterHandler(MsgType.Connect, __onConn); NetworkServer.RegisterHandler(MsgType.Disconnect, __onDisconn); NetworkServer.RegisterHandler(MessageType.Join, __onJoin); NetworkServer.RegisterHandler(MessageType.Move, __onMove); } Log.Instance.Info("服务器已开启"); }
private void Awake() { if (_instance != null && _instance != this) { Destroy(this.gameObject); } else { _instance = this; } base.maxConnections = maxConnection; var config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, 20); }
public void SetupServer() { packetActions = new Dictionary <PacketIDs, Action <PacketBase> >(); AddPacketActions(); ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, maxPlayers); NetworkServer.Listen(8080); myClient = ClientScene.ConnectLocalServer(); _disconnect.SetActive(true); _hostButton.SetActive(false); ServerLogic.instance.SetAllToDisconected(); }
private bool LaunchClient(string ip, int port) { if (Running) { return(false); } ConnectionConfig Config = new ConnectionConfig(); NetworkChannelID.ReliableSequenced = Config.AddChannel(QosType.ReliableSequenced); NetworkChannelID.UnreliableSequenced = Config.AddChannel(QosType.UnreliableSequenced); NetworkChannelID.Unreliable = Config.AddChannel(QosType.Unreliable); NetworkServer.Configure(Config, 10); NetClient = new NetworkClient(); NetClient.Configure(Config, 10); Running = true; NetClient.RegisterHandler(PktType.TextMessage, HandlePacket); NetClient.RegisterHandler(PktType.Identity, HandlePacket); NetClient.RegisterHandler(PktType.MassIdentity, HandlePacket); NetClient.RegisterHandler(PktType.SpawnEntity, HandlePacket); NetClient.RegisterHandler(PktType.MoveCreature, HandlePacket); NetClient.RegisterHandler(PktType.Sync, HandlePacket); NetClient.RegisterHandler(PktType.Interact, HandlePacket); NetClient.RegisterHandler(PktType.StaticObjectIds, HandlePacket); NetClient.RegisterHandler(PktType.Disconnect, HandlePacket); NetClient.RegisterHandler(PktType.InventoryAction, HandlePacket); NetClient.RegisterHandler(MsgType.Connect, OnConnected); NetClient.RegisterHandler(MsgType.Disconnect, OnDisconnected); NetClient.RegisterHandler(MsgType.Error, OnError); NetClient.Connect(ip, port); Debug.Log("Connecting.."); Term.Println("Connecting.."); return(true); }
private void DisconnectOnClient() { bool youAreNewHost; if (FindNewHost(out newHost, out youAreNewHost)) // Check who is the new host { newHostAddress = newHost.address; if (youAreNewHost) // If you become host { waitingToBecomeNewHost = true; NetworkServer.Configure(networkManager.topo); BecomeNewHost(networkManager.networkPort); StartCoroutine(query.Match.Add(profile.userName, newHost.address, newHost.internalIP, newHost.externalIPv6, newHost.internalIPv6, newHost.guid.ToString())); } else // If you don't become host { waitingReconnectToNewHost = true; ReconnectToNewHost(); } } }