# How to make MatchHandler work?

**URL:** <https://forum.heroiclabs.com/t/how-to-make-matchhandler-work/2861>\
**Category:** Runtime Framework\
**Tags:** server-framework, typescript\
**Created:** [July 23, 2022, 3:37pm UTC](https://forum.heroiclabs.com/t/how-to-make-matchhandler-work/2861 "2022-07-23T15:37:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/bodin/32/1260_2.png) [@bodin](https://forum.heroiclabs.com/u/bodin)\
**Post date:** [July 23, 2022, 3:37pm UTC](https://forum.heroiclabs.com/t/how-to-make-matchhandler-work/2861/1 "2022-07-23T15:37:53Z")

</div>

Hi,

sorry for the newbie question. I’m trying to setup a server-authoritative on Windows 10 machine.  
after I finished installing CockroachDB & Nakama. My game can now connect to server, start matchmaking, play against other player without any problem.

but my TypeScript runtime seem not to work.

When Nakama server start, I can see log text from InitModule.  
but other match handler function didn’t show log text at all.

Could anyone point out what I have done wrong in my code below?  
Thanks in advance for any help!

```auto
let InitModule : nkruntime.InitModule = function(ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer) {
	logger.info('My Custom Module initialized.');
	initializer.registerMatch('lobby', {
			matchInit,
			matchJoinAttempt,
			matchJoin,
			matchLoop,
			matchLeave,
			matchTerminate,
			matchSignal
	});
}

const matchInit = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, params: {[key: string]: string}) : {state: nkruntime.MatchState, tickRate: number, label: string} => {
	logger.info('My Custom Match initialized.');
	return {
			state: { },
			tickRate: 1,
			label: ''
	};
};

const matchJoinAttempt = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, presences: nkruntime.Presence, metadata : {[key : string]: any}) : {state: nkruntime.MatchState, accept: boolean, rejectMessage?: string | undefined} | null => {
	logger.info('My Custom Match JoinAttempt');
	return {
			state,
			accept: true
	};
};

const matchJoin = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, presences: nkruntime.Presence[]) : {state: nkruntime.MatchState} | null => {
	logger.info('My Custom Match Join');
	return {state};
};

const matchLeave = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, presences: nkruntime.Presence[]) : {state: nkruntime.MatchState} | null => {
	logger.info('My Custom Match Leave');
	return {state};
};

const matchLoop = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, messages: nkruntime.MatchMessage[]) : {state: nkruntime.MatchState} | null => {
	return {state};
};

const matchTerminate = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, graceSeconds: number) : {state: nkruntime.MatchState} | null => {
	return {state};
};

const matchSignal = (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: nkruntime.MatchState, data: string) : {state: nkruntime.MatchState, data?: string} | null => {
	logger.debug('Lobby match signal recieved: ' + data);
	return {state, data};
};

```

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)\
**Post date:** [July 25, 2022, 10:34am UTC](https://forum.heroiclabs.com/t/how-to-make-matchhandler-work/2861/2 "2022-07-25T10:34:43Z")

</div>

Hi @bodin,

Please can you share where you’re creating the authoritative match?

If you’re using the matchmaker you should be [using a hook to create the `"lobby"` match when a matchmaker matched event occurs](https://heroiclabs.com/docs/nakama/concepts/multiplayer/authoritative/#matchmaker).

Alternatively, you can [manually create a match and expose it via an RPC](https://heroiclabs.com/docs/nakama/concepts/multiplayer/authoritative/#manually).

If you’re doing either of the above and you’re still not seeing the log entries when the match is running please let me know.

---

<div class="post-metadata">

**Author:** ![bodin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/bodin/32/1260_2.png) [@bodin](https://forum.heroiclabs.com/u/bodin)\
**Post date:** [July 26, 2022, 6:27am UTC](https://forum.heroiclabs.com/t/how-to-make-matchhandler-work/2861/3 "2022-07-26T06:27:33Z")

</div>

Hi tom,

I created match with CreateMatchAsync(MatchName);  
after registered new RPC function for creating match instead, it’s now working as expected.  
Thank you very much for your guide!

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)\
**Post date:** [July 26, 2022, 8:07am UTC](https://forum.heroiclabs.com/t/how-to-make-matchhandler-work/2861/4 "2022-07-26T08:07:42Z")

</div>

Hi @bodin, I’m glad you got it working. Just for reference, calling `CreateMatchAsync` from the client will create a server relayed (or client authoritative) match, which is why your server authoritative match handler won’t have been invoked. 🙂

---

<div class="post-metadata">

**Author:** ![bodin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/bodin/32/1260_2.png) [@bodin](https://forum.heroiclabs.com/u/bodin)\
**Post date:** [July 27, 2022, 3:45am UTC](https://forum.heroiclabs.com/t/how-to-make-matchhandler-work/2861/5 "2022-07-27T03:45:54Z")

</div>

thank you.  
at first, I thought that match handler event also working on client authoritative.  
now I know I was wrong. 😅
