public Client() { state = ClientState.Disconnected; pendingDisconnectState = ClientState.Disconnected; replayProtection = new NetcodeReplayProtection(); replayProtection.Reset(); }
public void Connect(byte[] connectToken, bool autoTick) { if (state != ClientState.Disconnected) { throw new InvalidOperationException(); } keepAliveTimer = 0.0; connectServers.Clear(); replayProtection.Reset(); if (connectToken.Length != Defines.NETCODE_CONNECT_TOKEN_PUBLIC_BYTES) { changeState(ClientState.InvalidConnectToken); return; } NetcodePublicConnectToken tokenData = new NetcodePublicConnectToken(); using (var reader = ByteArrayReaderWriter.Get(connectToken)) { if (!tokenData.Read(reader)) { changeState(ClientState.InvalidConnectToken); return; } } if (tokenData.CreateTimestamp >= tokenData.ExpireTimestamp) { changeState(ClientState.InvalidConnectToken); return; } clientToServerKey = tokenData.ClientToServerKey; serverToClientKey = tokenData.ServerToClientKey; foreach (var server in tokenData.ConnectServers) { connectServers.Enqueue(server.Endpoint); } this.connectToken = tokenData; this.state = ClientState.SendingConnectionRequest; // bind socket, spin up threads, and start trying to connect isRunning = true; currentServerEndpoint = connectServers.Dequeue(); createSocket(currentServerEndpoint); if (autoTick) { this.time = DateTime.Now.GetTotalSeconds(); ThreadPool.QueueUserWorkItem(clientTick); } }
internal Client(Func <EndPoint, ISocketContext> socketFactory) { state = ClientState.Disconnected; pendingDisconnectState = ClientState.Disconnected; replayProtection = new NetcodeReplayProtection(); replayProtection.Reset(); this.socketFactory = socketFactory; }
public Client() { state = ClientState.Disconnected; pendingDisconnectState = ClientState.Disconnected; replayProtection = new NetcodeReplayProtection(); replayProtection.Reset(); socketFactory = (endpoint) => { var socket = new UDPSocketContext(endpoint.AddressFamily); var socketEndpoint = new IPEndPoint(endpoint.AddressFamily == AddressFamily.InterNetwork ? IPAddress.Any : IPAddress.IPv6Any, 0); socket.Bind(socketEndpoint); return(socket); }; }