/// <summary>Disconnects the client and stops all network traffic.</summary> private void Disconnect() { Debug.Log($"{tcp.socket.Client.RemoteEndPoint} has disconnected."); ThreadManager.ExecuteOnMainThread(() => { Object.Destroy(player.gameObject); player = null; }); tcp.Disconnect(); udp.Disconnect(); ServerSend.PlayerDisconnected(id); }
/// <summary>Initializes the newly connected client's TCP-related info.</summary> /// <param name="_socket">The TcpClient instance of the newly connected client.</param> public void Connect(TcpClient _socket) { socket = _socket; socket.ReceiveBufferSize = dataBufferSize; socket.SendBufferSize = dataBufferSize; stream = socket.GetStream(); receivedData = new Packet(); receiveBuffer = new byte[dataBufferSize]; stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null); ServerSend.Welcome(id, "Welcome to the server!"); }
public void SpawnDestructibleBlock(Vector3 position) { DestructibleBlock _destructibleBlock = Instantiate(destructibleBlockPrefab, position, Quaternion.identity); ServerSend.Spawn(_destructibleBlock); }