secret sharing with 3 parties under constraint
This problem is known as conditional disclosure of secret in cryptography. There have been many nice recent works on the subject, I suggest having a quick look at this one for example.

In you exact scenario, can $r$ be of length $2n$? If so, here is a simple solution: call $(r_0,r_1)$ the left and right parts of $r$, each of length $n$.


Alice sends $s + r_0x - r_1$
Bob sends $r_1-r_0y$


Because of the mask $r_1$, these two values only leak $(s + r_0x - r_1) + (r_1-r_0y) = s + r_0(x-y)$. If $x=y$, this discloses $s$; otherwise, $r_0(x-y)$ perfectly hides $s$ (addition and multiplications are performed over $\mathbb{F}_{2^n}$).

Regarding your second questions, yes, there are results on conditional disclosure of secret for arbitrary functions. The best result we know of for arbitrary predicate $f:[N]\times[N] \mapsto \{0,1\}$ has communication $2^{O(\sqrt{\log N \log\log N})}$. For predicates represented by a boolean circuit, I think we can have communication linear in the circuit size, but I would need to check this.