//---------------------------------------------------------------------------------------------// //Public functions: //---------------------------------------------------------------------------------------------// /// <summary> /// Function starts all [NET] related threads and systems /// </summary> /// <returns> /// Returns (true) if all systems were started successfully / returns (false) if not /// </returns> public bool NET_Start() {//Start all NET systems NET_GetLocalIP(); if (localIP != null && state == NET_State.NET_Waiting) { //Start tcp systems if (isHost == true) { tcpServer = new NET_TcpServer(); tcpServer.TCP_Server_Start(); } else { tcpClient = new NET_TcpClient(); } //Start udp system udpSystem = new NET_Udp(isHost); udpSystem.UDP_Start(); //Start main system state = NET_State.NET_Running; mainThread = new Thread(NET_MainThread); mainThread.Name = "[NET_Main] system thread"; mainThread.Start(); return(true); } else { return(false); } }
/// <summary> /// Functions suspend all [NET] related threads and systems /// </summary> /// <returns> /// Returns (true) if all systems were suspended successfully / returns (false) if not /// </returns> public bool NET_Stop() {//Suspend all NET systems if (state == NET_State.NET_Running) { //Suspend main system state = NET_State.NET_Waiting; //Suspend udp system udpSystem.UDP_Stop(); //Suspend tcp system if (isHost == true) { tcpServer.TCP_Server_Stop(); } return(true); } else { return(false); } }
/// <summary> /// Function stops all [NET] related threads and systems (First call [NET_Stop] then [NET_Shutdown] on game quit) /// </summary> /// <returns> /// Returns (true) if all systems were stopped successfully / returns (false) if not /// </returns> public bool NET_Shutdown() { if (state == NET_State.NET_Waiting) { //Stop main system state = NET_State.NET_Shutdown; //Stop udp system udpSystem.UDP_Shutdown(); //Stop tcp system if (isHost == true) { tcpServer.TCP_Server_Shutdown(); } else { tcpClient.TCP_DisconnectFromServer(playerID); } return(true); } else { return(false); } }