public bool ServerDisconnect(int connectionId) { if (LogFilter.Debug || debug) { Debug.Log("ServerDisconnect SteamworksNetworkTransport on ID " + connectionId); } if (connectionId == 0) { //this is the ID used for internal connections - ignore this return(true); } if (!ServerActive()) { return(false); } try { if (LogFilter.Debug || debug) { Debug.Log("Attempting to disconnect SteamID:" + connectionId); } SteamClient steamClient = steamConnectionMap.fromConnectionID[connectionId]; //remove the connection from our list steamConnectionMap.Remove(steamClient); if (steamClient.state == SteamClient.ConnectionState.CONNECTED || steamClient.state == SteamClient.ConnectionState.CONNECTING) { internalDisconnect(steamClient); if (LogFilter.Debug || debug) { Debug.Log("Server Disconnected"); } return(true); } } catch (KeyNotFoundException) { //we have no idea who this connection is Debug.LogError("Trying to disconnect a client thats not known " + connectionId); } return(false); }
/* * Check for messages and also deal with new connections and disconnects etc */ private bool ReceiveAndProcessEvents(out int connectionId, out TransportEvent transportEvent, out byte[] data, int chan) { data = null; //first check if we have received any new connections and return them as an event if (steamNewConnections.Count > 0) { if (LogFilter.Debug) { Debug.Log("Handling a new connection from queue"); } connectionId = steamNewConnections.Dequeue(); try { SteamClient steamClient = steamConnectionMap.fromConnectionID[connectionId]; if (steamClient.state == SteamClient.ConnectionState.CONNECTING) { Debug.Log("Set connection state to connected"); steamClient.state = SteamClient.ConnectionState.CONNECTED; } } catch (KeyNotFoundException) { //shouldnt happen - ignore } transportEvent = TransportEvent.Connected; return(true); } //first check if we have received any new disconnects and return them as an event if (steamDisconnectedConnections.Count > 0) { if (LogFilter.Debug) { Debug.Log("Handling a disconnect from queue"); } SteamClient steamClient = steamDisconnectedConnections.Dequeue(); connectionId = steamClient.connectionID; transportEvent = TransportEvent.Disconnected; //remove the connection from our list steamConnectionMap.Remove(steamClient); return(true); } //this is a buffer that may have been received at the same time as a new connection if (serverReceiveBufferPending != null) { if (LogFilter.Debug) { Debug.Log("Handling a postponed message"); } //we have a packet received and already in the buffer waiting to be returned connectionId = serverReceiveBufferPendingConnectionID; transportEvent = TransportEvent.Data; data = serverReceiveBufferPending; //clear our buffered variables serverReceiveBufferPendingConnectionID = -1; serverReceiveBufferPending = null; return(true); } //finally look for new packets return(Receive(out connectionId, out transportEvent, out data, chan)); }