/// <summary> /// Callback when peer has disconnected /// </summary> /// <param name="peer"></param> /// <param name="disconnectInfo"></param> void INetEventListener.OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo) { string peerID = Flow.CreateClientId(peer); Logger.Debug($"Connection to {peer.EndPoint.Address}:{peer.EndPoint.Port} closed. ({disconnectInfo.Reason.ToString()})"); IterateConnectedClients((FlowClientServer client) => { if (peerID == client.id) { return(client.Disconnect()); } return(true); }); }
/// <summary> /// Callback when peer has connected /// </summary> /// <param name="peer"></param> void INetEventListener.OnPeerConnected(NetPeer peer) { string peerID = Flow.CreateClientId(peer); Logger.Debug($"Incomming connection from {peer.EndPoint.Address}:{peer.EndPoint.Port}"); if (clients.ContainsKey(peerID) && clients.TryGetValue(peerID, out FlowClientServer existingClient)) { existingClient.Connect(peer, true); return; } if (clients.Count >= settings.MAX_PLAYERS) { Logger.Log("Server is full"); return; } FlowClientServer client = new FlowClientServer(); client.Connect(peer); }
/// <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); }