private async void AsyncDisconnect() { await Task.Delay((int)Math.Abs(DISCONNECT_DELAY * 1000)); // peer.Disconnect(); FlowServer.clients.Remove(id); Logger.Debug($"Client ({id}) has disconnected"); DisconnectFlowServerAction action = FlowActions.GetActionByName("Disconnect") as DisconnectFlowServerAction; action.SendFrom(id); }
/// <summary> /// Connect this client to the passed peer /// </summary> /// <param name="_peer"></param> public FlowClientServer Connect(NetPeer _peer, bool wasConnected = false) { if (isConnected) { return(this); } peer = _peer; endPoint = $"{peer.EndPoint.Address}:{peer.EndPoint.Port}"; id = Flow.CreateClientId(peer); isConnected = true; ConnectFlowServerAction action = FlowActions.GetActionByName("Connect") as ConnectFlowServerAction; if (wasConnected) { Logger.Debug($"Client ({id}) has reconnected"); if (action != null) { action.SendFrom(id, "You reconnected succesfully."); } } else { if (FlowServer.clients.ContainsKey(id)) { FlowServer.clients.Remove(id); } Logger.Debug($"Client ({id}) has connected"); FlowServer.clients.Add(id, this); if (action != null) { action.SendFrom(id, "You connected succesfully."); } } return(this); }