Пример #1
0
        private void SendClientState()
        {
            //Sanity check
            var clientId = _session.LocalId;

            if (Log.AssertAndLogError(clientId.HasValue, "EBC361ED-780A-4DE0-944D-3D4D983B785D", "Attempting to send local client state before assigned an ID by the server"))
            {
                return;
            }

            //Send the local state
            var writer = new PacketWriter(_sender.GetSendBuffer());

            writer.WriteClientState(_session.SessionId, _playerName, clientId.Value, _codecSettings, _localRooms);
            _sender.EnqueueReliable(writer.Written);
            Log.Debug("Sent local client state");

            //begin watching for changes in rooms
            _localRooms.JoinedRoom -= SendJoinRoom;
            _localRooms.JoinedRoom += SendJoinRoom;
            _localRooms.LeftRoom   -= SendLeaveRoom;
            _localRooms.LeftRoom   += SendLeaveRoom;
        }
Пример #2
0
        /// <summary>
        /// Begin negotiating a connection with the server by sending a handshake.
        /// </summary>
        /// <remarks>It is safe to call this several times, even once negotiation has finished</remarks>
        private void SendHandshake(DateTime utcNow)
        {
            //Sanity check. We can't do *anything* with a disconnected client, definitely not restart negotiation!
            Log.AssertAndThrowPossibleBug(
                State != ConnectionState.Disconnected,
                "39533F23-2DAC-4340-9A7D-960904464E23",
                "Attempted to begin connection negotiation with a client which is disconnected");

            _lastHandshakeRequest = utcNow;

            //Send the handshake request to the server (when the server replies with a response, we know we're connected)
            _sender.EnqueueReliable(
                new PacketWriter(new ArraySegment <byte>(_sender.SendBufferPool.Get()))
                .WriteHandshakeRequest(_playerName, _codecSettings)
                .Written
                );
            Log.Trace("Sent HandshakeRequest");

            //Set the state to negotiating only if the state was previously none
            Interlocked.CompareExchange(ref _connectionStateValue, (int)ConnectionState.Negotiating, (int)ConnectionState.None);
        }