Ejemplo n.º 1
0
 /// <summary>
 /// Sends the <see cref="ServerInfoMessage"/> structure to the connected client.
 /// </summary>
 /// <param name="info">The info message to send.</param>
 /// <returns>True on success.</returns>
 public bool SendServerInfo(ServerInfoMessage info)
 {
     _packet.Reset((ushort)RoutingID.ServerInfo, 0);
     if (info.Write(_packet))
     {
         _packet.FinalisePacket();
         return(Add(_packet) > 0);
     }
     return(false);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends the given <see cref="ServerInfoMessage"/> to the client.
        /// </summary>
        /// <param name="info">Details of the server to send to the client.</param>
        /// <remarks>
        /// Should always be send as the first message to the client.
        /// </remarks>
        public bool SendServerInfo(ServerInfoMessage info)
        {
            _serverInfo = info;
            const float secondsToMicroseconds = 1e6f;

            _secondsToTimeUnit = secondsToMicroseconds / (_serverInfo.TimeUnit != 0 ? _serverInfo.TimeUnit : 1.0f);

            if (Connected)
            {
                _packetLock.Lock();
                try
                {
                    _packet.Reset((ushort)RoutingID.ServerInfo, 0);
                    if (info.Write(_packet))
                    {
                        _packet.FinalisePacket();
                        _sendLock.Lock();
                        try
                        {
                            // Do not use collation buffer or compression for this message.
                            if (_client != null && _client.Connected)
                            {
                                _client.GetStream().Write(_packet.Data, _packet.Cursor, _packet.Count);
                            }
                            return(true);
                        }
                        catch (System.IO.IOException)
                        {
                            _client.Close();
                            _client = null;
                        }
                        finally
                        {
                            _sendLock.Unlock();
                        }
                    }
                }
                finally
                {
                    _packetLock.Unlock();
                }
            }

            return(false);
        }