diff --git a/src/initContractRouter.ts b/src/initContractRouter.ts index 1ae8506..dd55c1e 100644 --- a/src/initContractRouter.ts +++ b/src/initContractRouter.ts @@ -60,12 +60,24 @@ export function initContractRouter< } if (!(_rpc?.returns instanceof z.ZodVoid) || !(_rpc?.returns instanceof z.ZodUndefined)) { + let hasReturned = false; + _args.returnValue = (returnValue: typeof _rpc.returns) => { if (env === "server") { + if (hasReturned) { + throw new Error(`[alt-rpc] The rpc ${contract} already returned a value.`); + } + (opts.emit as EmitFn)(_args.player, rpcName, returnValue); + hasReturned = true; } else { + if (hasReturned) { + throw new Error(`[alt-rpc] The rpc ${contract} already returned a value.`); + } + (opts.emit as EmitFn)(rpcName, returnValue); + hasReturned = true; } }; }