public static void Put(this NetDataWriter @this, JoinSecret value)
 {
     @this.Put(value.Version);
     H3MP.Networking.Extensions.NetDataWriterExtensions.Put(@this, value.EndPoint);
     @this.Put(value.Key);
     @this.Put(value.TickDeltaTime);
 }
Esempio n. 2
0
        private void OnJoin(string rawSecret)
        {
            const string errorPrefix = "Failed to handle join event: ";

            _discordLog.LogDebug($"Received Discord join secret \"{rawSecret}\"");

            byte[] data;
            try
            {
                data = Convert.FromBase64String(rawSecret);
            }
            catch
            {
                _discordLog.LogError(errorPrefix + "could not parse base 64 secret.");
                return;
            }

            bool success = JoinSecret.TryParse(data, out var secret, out var version);

            if (!_version.CompatibleWith(version))
            {
                _discordLog.LogError(errorPrefix + $"version incompatibility detected (you: {_version}; host: {version})");
                return;
            }

            if (!success)
            {
                _discordLog.LogError(errorPrefix + "join secret was malformed.");
                return;
            }

            ConnectRemote(secret);
        }
Esempio n. 3
0
 public InitMessage(Key32 id, JoinSecret secret, byte maxSize, LevelChangeMessage level, PlayerJoinMessage[] players)
 {
     ID      = id;
     Secret  = secret;
     MaxSize = maxSize;
     Level   = level;
     Players = players;
 }
Esempio n. 4
0
        private void ConnectLocal(IPEndPoint endPoint, JoinSecret secret, Key32 hostKey)
        {
            Connect(endPoint, hostKey, secret, info =>
            {
                _clientLog.LogError("Disconnected from local server. Something probably caused the frame to hang for more than 5s (debugging breakpoint?). Restarting host...");

                StartCoroutine(_Host());
            });
        }
Esempio n. 5
0
        private void Connect(IPEndPoint endPoint, Key32?hostKey, JoinSecret secret, OnH3ClientDisconnect onDisconnect)
        {
            _clientLog.LogInfo($"Connecting to {endPoint}...");

            float  ups = 1 / Time.fixedDeltaTime;
            double tps = 1 / secret.TickDeltaTime;

            _clientLog.LogDebug($"Fixed update rate: {ups:.00} u/s");
            _clientLog.LogDebug($"Tick rate: {tps:.00} t/s");

            var request = new ConnectionRequestMessage(secret.Key, hostKey);

            Client = new H3Client(_clientLog, _config.Client, Activity, _messages.Client, _messages.ChannelsCount, secret.TickDeltaTime, _version, endPoint, request, onDisconnect);
        }
Esempio n. 6
0
        internal H3Server(ManualLogSource log, HostConfig config, RandomNumberGenerator rng, PeerMessageList <H3Server> messages, byte channelsCount, Version version, double tickDeltaTime, IPEndPoint publicEndPoint)
            : base(log, messages, channelsCount, new Events(messages.Definitions[typeof(Timestamped <PingMessage>)]), version, config.Binding.IPv4.Value, config.Binding.IPv6.Value, config.Binding.Port.Value)
        {
            _log     = log;
            _config  = config;
            _partyID = Key32.FromRandom(rng);

            _tickTimer = new LoopTimer(tickDeltaTime);
            _peerIDs   = new Dictionary <Peer, byte>();
            _husks     = new Dictionary <byte, Husk>();

            _selfID = -1;

            Secret  = new JoinSecret(version, publicEndPoint, Key32.FromRandom(rng), tickDeltaTime);
            HostKey = Key32.FromRandom(rng);
        }
Esempio n. 7
0
        private void ConnectRemote(JoinSecret secret)
        {
            Client?.Dispose();

            Connect(secret.EndPoint, null, secret, info =>
            {
                _clientLog.LogError("Disconnected from remote server.");

                if (_config.AutoHost.Value)
                {
                    Logger.LogDebug("Autostarting host from client disconnection...");

                    StartCoroutine(_Host());
                }
            });
        }