Since unreal engine already has netcode and stuff, replication can be done in engine, all i need to do is to connect to its headless server, which can be done by sending an ip address after matchmaking.
players click a button and it invokes rtClient->addMatchmaker
and once a match has been found it simply logs that a match has been found and then joins the match using rtClient->joinMatchByToken
is it possible to start an real time authoritative match without nakama auto closing the session since we aren’t replicating data through nakama.
I have written a simple .ts file, shown below
let InitModule: nkruntime.InitModule = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer) {
initializer.registerMatchmakerMatched(getServerIp);
logger.info('RPC Registered');
}
let getServerIp: nkruntime.MatchmakerMatchedFunction = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama) : string{
logger.info('Matched With server IP 127.0.0.1')
return JSON.stringify({"serverIP":"127.0.0.1"})
}
i have compiled the code and added the runtime file to the server
it should return a string with the server ip, but how does the client access the data sent by the server?
@SnappierSoap318 The server does not auto-close a session (a socket connection) when an authoritatve match is stopped. The presences in the multiplayer match (if they had joined) will no longer receive messages from the stream which is created to power the authoritative match when it runs. What sort of error do you get which indicates that the socket connections are closed?
@novabyte am working on a third person shooter, and since unreal already has its own netcode and stuff, all i need to do is matchmake and send the ip address to the players and they can connect through that ip. how can i do this in the backend, going through the documentation i found the code which i showed before but how can the player access that data?
@SnappierSoap318 You can attach any data properties you want to your match maker requests. Is there a reason you can’t just put the connectivity information into the matchmaker data properties when the user submits themselves to the matchmaker?
@novabyte isn’t the server supposed to send the ip to the clients upon fulfilling the matchmaking requests?
shouldn’t the flow go like this:
client gets added to matchmaker → match found → server sends ip to clients from available pool of servers → client connects to server using given ip.
isn’t the server supposed to send the ip to the clients upon fulfilling the matchmaking requests?
@SnappierSoap318 Nakama does not need IP addresses for users to play in matches hosted on the multiplayer engine in the server. The use case you described is to use the netcode implementation in Unreal engine and therefore only use Nakama to matchmake players together. This is why I suggested the approach above.
client gets added to matchmaker → match found → server sends ip to clients from available pool of servers → client connects to server using given ip.
This flow you describe is not for P2P-based multiplayer but for authoritative multiplayer probably with headless Unreal instances hosted in some kind of fleet manager. Sure, you can of course select a server instance from a pool of servers and return its IP for all users to connect against. This could be done within the matchmaker matched hook in Nakama.
Your code flow could look like:
- User enters the matchmaker either as a solo player or as part of a party. They submit the matchmaker criteria for the type of opponents they want to be matched against.
- You write a small amount of server logic in the matchmaker matched hook.
- When users are matched together the hook will be called on the server. You can make requests to obtain an instance from the server instance pool however you talk to the fleet manager.
- The response you receive back with the IP address of the instance can be attached as data to the matchmaker matched response that will be returned by the hook. Alternatively you could push to each user the IP address of the server to join over a non-persistent for in-app notifications.
Let me know if you have more questions.
2 Likes
@novabyte
so which mode should I query the matchmaker? I’m guessing authoritative, but when i give mode: authoritative in string properties, the server auto closes the match
after receiving the match id and joining the match using the token/id i should make another query to get the ip’s? or can the hook return values to the client?