Exemple #1
0
        /// <summary>
        /// 接続をセッションに結びつけます。
        /// </summary>
        /// <param name="connection"></param>
        public void Attach(ConnectionBase connection)
        {
            lock (_connections)
                lock (_server.Sessions)
                {
                    _connections.Add(connection);
                    connection.ConnectionEnded += ConnectionEnded;
                    connection.MessageReceived += MessageReceived;
                    SendGatewayServerMessage("Connection Attached: " + connection.ToString());

                    // ニックネームを合わせる
                    if (String.IsNullOrEmpty(CurrentNick))
                    {
                        CurrentNick = connection.UserInfo.Nick;
                    }
                    else
                    {
                        connection.SendServer(new NickMessage()
                        {
                            NewNick = CurrentNick
                        });
                        connection.UserInfo.Nick = CurrentNick;
                    }

                    OnAttached(connection);
                    OnConnectionAttached(new ConnectionAttachEventArgs {
                        Connection = connection
                    });
                }
        }
Exemple #2
0
        /// <summary>
        /// 接続をセッションから切り離します。キープアライブが有効な場合を除き接続数が0となるとセッションは終了します。
        /// </summary>
        /// <param name="connection"></param>
        public void Detach(ConnectionBase connection)
        {
            lock (_connections)
                lock (_server.Sessions)
                {
                    connection.ConnectionEnded -= ConnectionEnded;
                    connection.MessageReceived -= MessageReceived;
                    _connections.Remove(connection);
                    SendGatewayServerMessage("Connection Detached: " + connection.ToString());

                    OnDetached(connection);
                    OnConnectionDetached(new ConnectionAttachEventArgs {
                        Connection = connection
                    });

                    // 接続が0になったらセッション終了
                    if (_connections.Count == 0 && !IsKeepAlive)
                    {
                        Close();
                    }
                }
        }