public void OnConnectionRequest(H3Server server, ConnectionRequest request, NetDataWriter rejectionContent) { var currentClients = server.ClientsCount; var maxClients = server._config.PlayerLimit.Value; if (currentClients >= maxClients) { server._log.LogWarning($"Rejecting join request from {request.RemoteEndPoint} because of full party ({currentClients} / {maxClients})."); rejectionContent.Put(JoinError.Full); request.Reject(rejectionContent); return; } var reader = request.Data; if (!reader.TryGet <ConnectionRequestMessage>(out var message)) { server._log.LogWarning($"Join request from {request.RemoteEndPoint} had a malformed request."); rejectionContent.Put(JoinError.MalformedMessage); request.Reject(rejectionContent); return; } if (message.AccessKey != server.Secret.Key) { server._log.LogWarning($"Join request {request.RemoteEndPoint} had an incorrect key."); rejectionContent.Put(JoinError.MismatchedKey); request.Reject(rejectionContent); return; } var peer = request.Accept(); if (message.HostKey == server.HostKey) { server._selfID = peer.Id; } using (WriterPool.Instance.Borrow(out var writer)) { _pong.Send(peer, writer, Timestamped <PingMessage> .Now(new PingMessage(message.ClientTime))); } }
internal static void OnClientPing(H3Server self, Peer peer, PingMessage message) { peer.Send(Timestamped <PingMessage> .Now(message)); }