예제 #1
0
파일: OnlineUser.cs 프로젝트: olejeek/game
        //public static void Send(string str)
        //{
        //    if (!connection.Connected) Connect();
        //    connection.Send(Encoding.ASCII.GetBytes(str + "\0"));
        //}
        //public static void SendAndDisconnect(string str)
        //{
        //    if (connection.Connected)
        //    {
        //        connection.Send(Encoding.ASCII.GetBytes(str));
        //    }
        //    Disconnect(str);
        //}
        //public static void Disconnect(string str="You Disconnected!")
        //{
        //    timer.Stop();
        //    if (connection.Connected)
        //    {
        //        connection.Close();
        //        MessageBox.Show(str, "Disconnect", MessageBoxButtons.OK);
        //    }
        //    status = Status.Disconnect;
        //    ChangeStatus(status.ToString());
        //    //need add go to login Form

        //}

        private static void Disconnect(Block block)
        {
            CloseConnection();
            DisconnectType state = (DisconnectType)block.Type;

            switch (state)
            {
            case DisconnectType.Exit:
                MessageBox.Show("Exit!", state.ToString(),
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case DisconnectType.Error:
                MessageBox.Show("Wrong Command!", state.ToString(),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case DisconnectType.Timeout:
                MessageBox.Show("Timeout!", state.ToString(),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            default:
                MessageBox.Show("Command Error!", state.ToString(),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                break;
            }
        }
예제 #2
0
 /// <summary>
 /// 停止收发并关闭socket
 /// </summary>
 public void Close(DisconnectType e = DisconnectType.Manual)
 {
     lock (lockobj)
     {
         if (isRuning == true)
         {
             isRuning = false;
             try
             {
                 socket.Shutdown(SocketShutdown.Send);
             }
             catch (Exception) { }
             try
             {
                 socket.Shutdown(SocketShutdown.Receive);
             }
             catch (Exception) { }
             socket.Close();
             if (socketPool != null)
             {
                 if (readArgs != null)
                 {
                     readArgs.Completed -= readArgs_Completed;
                     socketPool.Push(readArgs);
                     readArgs.UserToken = null;
                 }
             }
             socket = null;
             OnSocketDisconnecting(new DisconnectEvent(e, this));
         }
         IsConnect = false;
     }
 }
예제 #3
0
        public void TriggerPeerDisconnected(DisconnectReason reason, DisconnectType disconnectType)
        {
            PeerDisconnected?.Invoke(this, new DisconnectEventArgs(reason, disconnectType));
            var task = Task.Delay(1000);

            task.Wait();
        }
예제 #4
0
 public static void DisconnectHandler(DisconnectType type, string message)
 {
     if (type == DisconnectType.NetworkTimeout)
     {
         Console.WriteLine("Network connection timed out, disconnected");
     }
     else if (type == DisconnectType.ServerInitiated)
     {
         Console.WriteLine("Server disconnected us: " + message);
     }
 }
예제 #5
0
 public static void DisconnectHandler(DisconnectType type, string message)
 {
     if (type == DisconnectType.NetworkTimeout)
     {
         Console.WriteLine("Network connection timed out, disconnected");
     }
     else if (type == DisconnectType.ServerInitiated)
     {
         Console.WriteLine("Server disconnected us: " + message);
     }
 }
예제 #6
0
    void Disconnected(DisconnectType dis, string msg)
    {
        Close();
        string protocal = dis == DisconnectType.System ?
                          SocketStatusCMD.Exception : SocketStatusCMD.Disconnect;

        NetByteBuffer buffer = new NetByteBuffer();

        buffer.WriteString(protocal);
        SocketClientManager.AddEvent(protocal, buffer);
        DebugConsole.LogError("Disconnected :>" + msg + " DisconnectType:>" + dis);
    }
예제 #7
0
        /// <summary>
        /// Shutdown will disconnect all the sims except for the current sim
        /// first, and then kill the connection to CurrentSim. This should only
        /// be called if the logout process times out on <code>RequestLogout</code>
        /// </summary>
        public void Shutdown(DisconnectType type)
        {
            Client.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info);

            // Send a CloseCircuit packet to simulators if we are initiating the disconnect
            bool sendCloseCircuit = (type == DisconnectType.ClientInitiated || type == DisconnectType.NetworkTimeout);

            lock (Simulators)
            {
                // Disconnect all simulators except the current one
                for (int i = 0; i < Simulators.Count; i++)
                {
                    if (Simulators[i] != null && Simulators[i] != CurrentSim)
                    {
                        Simulators[i].Disconnect(sendCloseCircuit);

                        // Fire the SimDisconnected event if a handler is registered
                        if (OnSimDisconnected != null)
                        {
                            try { OnSimDisconnected(Simulators[i], type); }
                            catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                        }
                    }
                }

                Simulators.Clear();
            }

            if (CurrentSim != null)
            {
                // Kill the connection to the curent simulator
                CurrentSim.Disconnect(sendCloseCircuit);

                // Fire the SimDisconnected event if a handler is registered
                if (OnSimDisconnected != null)
                {
                    try { OnSimDisconnected(CurrentSim, type); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }

            // Clear out all of the packets that never had time to process
            PacketInbox.Close();

            connected = false;

            // Fire the disconnected callback
            if (OnDisconnected != null)
            {
                try { OnDisconnected(DisconnectType.ClientInitiated, String.Empty); }
                catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }
        }
예제 #8
0
        public void AddNodeStatsDisconnectEvent(DisconnectType disconnectType, DisconnectReason disconnectReason)
        {
            _lastDisconnectTime = DateTime.UtcNow;
            if (disconnectType == DisconnectType.Local)
            {
                _lastLocalDisconnect = disconnectReason;
            }
            else
            {
                _lastRemoteDisconnect = disconnectReason;
            }

            Increment(NodeStatsEventType.Disconnect);
        }
예제 #9
0
    void OnDisconnect(DisconnectType dis, string msg)
    {
        if (dis != DisconnectType.ClientClosing)
        {
            CloseClient();
        }

        /*ushort protocal = dis == DisconnectType.Exception ? Protocal.Exception : Protocal.Disconnect;
         *
         * ByteBuffer buffer = new ByteBuffer();
         * buffer.WriteShort((ushort)protocal);
         * NetworkManager.PushPacket(protocal, buffer);*/
        Debug.Log("Connection closed. Distype: " + dis + ". Msg: " + msg);
    }
예제 #10
0
        void Close(Exception ex, DisconnectType dt)
        {
            if (IsClosed)
            {
                return;
            }

            IsClosed = true;

            TerminateThreads();

            notifyDisonnect(new NodeDisconnectInfo()
            {
                node = this, exception = ex, disconnectType = dt
            });
        }
예제 #11
0
        internal void DisconnectClient(Connection connection, DisconnectType disconnectType, byte[] packet)
        {
            if (!connection.UpdateState(Connection.ConnectionState.DISCONNECTED))
            {
                return;
            }

            if (disconnectType == DisconnectType.TIMEOUT)
            {
                Interlocked.Increment(ref Stats.StatTimeouts);
                if (this.OnTimeout != null)
                {
                    this.OnTimeout(connection, null);
                }
            }

            Interlocked.Increment(ref Stats.StatDisconnects);

            // send more than necessary so that the packet hopefully arrives
            for (int i = 0; i < 10; i++)
            {
                connection.SendHighLevelPacket(Packet.PacketDescriptor.DISCONNECT, packet);
            }

            // give the channel some time to process the packets
            Thread.Sleep(20);

            connection.StopRoutines();

            if (disconnectType != DisconnectType.SHUTDOWN)
            {
                uint hash = Util.AddrHash(connection.Addr);

                this.connectionsMutex.EnterWriteLock();
                this.connections.Remove(hash);
                this.connectionsMutex.ExitWriteLock();

                if (this.OnDisconnect != null)
                {
                    this.OnDisconnect(connection, packet);
                }
            }

            connection.Reset();
            this.connectionPool.Put(connection);
        }
 /// <summary>
 /// Shutdown will disconnect all the sims except for the current sim
 /// first, and then kill the connection to CurrentSim. This should only
 /// be called if the logout process times out on <code>RequestLogout</code>
 /// </summary>
 /// <param name="type">Type of shutdown</param>
 public void Shutdown(DisconnectType type)
 {
     Shutdown(type, type.ToString());
 }
예제 #13
0
        public void Close(DisconnectType Reason)
        {
            Send(new DisconnectMessage(Reason));

            Dispose();
        }
예제 #14
0
        /// <summary>
        /// Executes when some of current <see cref="MsSqlDataProvider"/> <see cref="MsSqlDataConnection"/> objects disconnects from database engine.
        /// </summary>
        /// <param name="connectionID">Disconnected <see cref="MsSqlDataConnection"/> unique id.</param>
        /// <param name="type">Disconnection type.</param>
        internal override void ConnectionDisconnected( byte connectionID, DisconnectType type )
        {
            if ( m_ActiveConnections.Contains(connectionID) )
            {
                Logger.WriteLine(Source.DataProvider, "Connection {0} was disconnected {1}.", connectionID, type);
                m_ActiveConnections.Remove(connectionID);

                if ( m_ActiveConnections.Count == 0 )
                {
                    Initialized = false;

                    if ( OnStopped != null )
                        OnStopped();
                }
            }
        }
예제 #15
0
        public static void Update(DisconnectType disconnectType, DisconnectReason disconnectReason)
        {
            if (disconnectType == DisconnectType.Remote)
            {
                switch (disconnectReason)
                {
                case DisconnectReason.BreachOfProtocol:
                    Metrics.BreachOfProtocolDisconnects++;
                    break;

                case DisconnectReason.UselessPeer:
                    Metrics.UselessPeerDisconnects++;
                    break;

                case DisconnectReason.TooManyPeers:
                    Metrics.TooManyPeersDisconnects++;
                    break;

                case DisconnectReason.AlreadyConnected:
                    Metrics.AlreadyConnectedDisconnects++;
                    break;

                case DisconnectReason.IncompatibleP2PVersion:
                    Metrics.IncompatibleP2PDisconnects++;
                    break;

                case DisconnectReason.NullNodeIdentityReceived:
                    Metrics.NullNodeIdentityDisconnects++;
                    break;

                case DisconnectReason.ClientQuitting:
                    Metrics.ClientQuittingDisconnects++;
                    break;

                case DisconnectReason.UnexpectedIdentity:
                    Metrics.UnexpectedIdentityDisconnects++;
                    break;

                case DisconnectReason.ReceiveMessageTimeout:
                    Metrics.ReceiveMessageTimeoutDisconnects++;
                    break;

                case DisconnectReason.DisconnectRequested:
                    Metrics.DisconnectRequestedDisconnects++;
                    break;

                case DisconnectReason.IdentitySameAsSelf:
                    Metrics.SameAsSelfDisconnects++;
                    break;

                case DisconnectReason.TcpSubSystemError:
                    Metrics.TcpSubsystemErrorDisconnects++;
                    break;

                default:
                    Metrics.OtherDisconnects++;
                    break;
                }
            }

            if (disconnectType == DisconnectType.Local)
            {
                switch (disconnectReason)
                {
                case DisconnectReason.BreachOfProtocol:
                    Metrics.LocalBreachOfProtocolDisconnects++;
                    break;

                case DisconnectReason.UselessPeer:
                    Metrics.LocalUselessPeerDisconnects++;
                    break;

                case DisconnectReason.TooManyPeers:
                    Metrics.LocalTooManyPeersDisconnects++;
                    break;

                case DisconnectReason.AlreadyConnected:
                    Metrics.LocalAlreadyConnectedDisconnects++;
                    break;

                case DisconnectReason.IncompatibleP2PVersion:
                    Metrics.LocalIncompatibleP2PDisconnects++;
                    break;

                case DisconnectReason.NullNodeIdentityReceived:
                    Metrics.LocalNullNodeIdentityDisconnects++;
                    break;

                case DisconnectReason.ClientQuitting:
                    Metrics.LocalClientQuittingDisconnects++;
                    break;

                case DisconnectReason.UnexpectedIdentity:
                    Metrics.LocalUnexpectedIdentityDisconnects++;
                    break;

                case DisconnectReason.ReceiveMessageTimeout:
                    Metrics.LocalReceiveMessageTimeoutDisconnects++;
                    break;

                case DisconnectReason.DisconnectRequested:
                    Metrics.LocalDisconnectRequestedDisconnects++;
                    break;

                case DisconnectReason.IdentitySameAsSelf:
                    Metrics.LocalSameAsSelfDisconnects++;
                    break;

                case DisconnectReason.TcpSubSystemError:
                    Metrics.LocalTcpSubsystemErrorDisconnects++;
                    break;

                default:
                    Metrics.LocalOtherDisconnects++;
                    break;
                }
            }
        }
예제 #16
0
 public override void Deserialise(Reader Reader)
 {
     Reason = (DisconnectType)Reader.ReadByte();
 }
예제 #17
0
 /// <summary>
 /// Executes when some of current <see cref="Provider"/> <see cref="Connection"/> objects disconnects from database engine.
 /// </summary>
 /// <param name="connectionID">Disconnected <see cref="Connection"/> unique id.</param>
 /// <param name="type">Disconnection type.</param>
 internal virtual void ConnectionDisconnected(byte connectionID, DisconnectType type)
 {
     Logger.WriteLine(Source.DataProvider, "Connection {0} disconnected {1}", connectionID, type);
 }
예제 #18
0
 public DisconnectedEventArgs(DisconnectType pDCType)
 {
     Reason = pDCType;
 }
예제 #19
0
 public DisconnectPacket(string message, DisconnectType type)
 {
     this.type           = PacketType.DISCONNECT;
     this.disconnectType = type;
     this.message        = message;
 }
예제 #20
0
 public DisconnectEvent(DisconnectType dt, YChannel channel)
 {
     this.DisconnectType = dt;
     this.Channel        = channel;
 }
 public DisconnectCategory(DisconnectReason reason, DisconnectType type)
 {
     Reason = reason;
     Type   = type;
 }
예제 #22
0
 public DisconnectMessage(DisconnectType Reason)
 {
     this.Reason = Reason;
 }
예제 #23
0
 public DisconnectEventArgs(DisconnectReason disconnectReason, DisconnectType disconnectType, string details)
 {
     DisconnectReason = disconnectReason;
     DisconnectType   = disconnectType;
     Details          = details;
 }
 internal ClientDisconnectedEventArgs(TCPClientInfo clientInfo, DisconnectType disconnectType)
 {
     ClientInfo     = clientInfo;
     DisconnectType = disconnectType;
 }
예제 #25
0
 public DisconnectEventArgs(DisconnectReason disconnectReason, DisconnectType disconnectType)
 {
     DisconnectReason = disconnectReason;
     DisconnectType   = disconnectType;
 }
예제 #26
0
 public Task DisconnectAsync(DisconnectReason disconnectReason, DisconnectType disconnectType)
 {
     return(Task.CompletedTask);
 }
예제 #27
0
 /// <summary>
 /// Executes when some of current <see cref="Provider"/> <see cref="Connection"/> objects disconnects from database engine.
 /// </summary>
 /// <param name="connectionID">Disconnected <see cref="Connection"/> unique id.</param>
 /// <param name="type">Disconnection type.</param>
 internal virtual void ConnectionDisconnected( byte connectionID, DisconnectType type )
 {
     Logger.WriteLine(Source.DataProvider, "Connection {0} disconnected {1}", connectionID, type);
 }
예제 #28
0
        public void ReportDisconnect(Node node, DisconnectType disconnectType, DisconnectReason disconnectReason)
        {
            INodeStats stats = GetOrAdd(node);

            stats.AddNodeStatsDisconnectEvent(disconnectType, disconnectReason);
        }
예제 #29
0
 public DisconnectEventArgs(DisconnectReason disconnectReason, DisconnectType disconnectType, string sessionId)
 {
     DisconnectReason = disconnectReason;
     DisconnectType   = disconnectType;
     SessionId        = sessionId;
 }
예제 #30
0
 internal ClientDisconnectedPacket(byte sender, byte disconnectedClientID, DisconnectType disconnectType)
 {
     Sender = sender;
     DisconnectedClientID = disconnectedClientID;
     DisconnectType       = disconnectType;
 }
예제 #31
0
        /// <summary>
        /// Shutdown will disconnect all the sims except for the current sim
        /// first, and then kill the connection to CurrentSim. This should only
        /// be called if the logout process times out on <code>RequestLogout</code>
        /// </summary>
        public void Shutdown(DisconnectType type)
        {
            Client.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info);

            // Send a CloseCircuit packet to simulators if we are initiating the disconnect
            bool sendCloseCircuit = (type == DisconnectType.ClientInitiated || type == DisconnectType.NetworkTimeout);

            lock (Simulators)
            {
                // Disconnect all simulators except the current one
                for (int i = 0; i < Simulators.Count; i++)
                {
                    if (Simulators[i] != null && Simulators[i] != CurrentSim)
                    {
                        Simulators[i].Disconnect(sendCloseCircuit);

                        // Fire the SimDisconnected event if a handler is registered
                        if (OnSimDisconnected != null)
                        {
                            try { OnSimDisconnected(Simulators[i], type); }
                            catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                        }
                    }
                }

                Simulators.Clear();
            }

            if (CurrentSim != null)
            {
                // Kill the connection to the curent simulator
                CurrentSim.Disconnect(sendCloseCircuit);

                // Fire the SimDisconnected event if a handler is registered
                if (OnSimDisconnected != null)
                {
                    try { OnSimDisconnected(CurrentSim, type); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }

            // Clear out all of the packets that never had time to process
            lock (PacketInbox) PacketInbox.Clear();

            connected = false;

            // Fire the disconnected callback
            if (OnDisconnected != null)
            {
                try { OnDisconnected(DisconnectType.ClientInitiated, String.Empty); }
                catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }
        }
        /// <summary>
        /// Shutdown will disconnect all the sims except for the current sim
        /// first, and then kill the connection to CurrentSim. This should only
        /// be called if the logout process times out on <code>RequestLogout</code>
        /// </summary>
        /// <param name="type">Type of shutdown</param>
        /// <param name="message">Shutdown message</param>
        public void Shutdown(DisconnectType type, string message)
        {
            Logger.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info, Client);

            // Send a CloseCircuit packet to simulators if we are initiating the disconnect
            bool sendCloseCircuit = (type == DisconnectType.ClientInitiated || type == DisconnectType.NetworkTimeout);

            lock (Simulators)
            {
                // Disconnect all simulators except the current one
                for (int i = 0; i < Simulators.Count; i++)
                {
                    if (Simulators[i] != null && Simulators[i] != CurrentSim)
                    {
                        Simulators[i].Disconnect(sendCloseCircuit);

                        // Fire the SimDisconnected event if a handler is registered
                        if (m_SimDisconnected != null)
                        {
                            OnSimDisconnected(new SimDisconnectedEventArgs(Simulators[i], type));
                        }
                    }
                }

                Simulators.Clear();
            }

            if (CurrentSim != null)
            {
                // Kill the connection to the curent simulator
                CurrentSim.Disconnect(sendCloseCircuit);

                // Fire the SimDisconnected event if a handler is registered
                if (m_SimDisconnected != null)
                {
                    OnSimDisconnected(new SimDisconnectedEventArgs(CurrentSim, type));
                }
            }

            // Clear out all of the packets that never had time to process
            PacketInbox.Close();
            PacketOutbox.Close();

            connected = false;

            // Fire the disconnected callback
            if (m_Disconnected != null)
            {
                OnDisconnected(new DisconnectedEventArgs(type, message));
            }
        }
예제 #33
0
 public override void Deserialise(Reader Reader)
 {
     Reason = (DisconnectType)Reader.ReadByte();
 }
예제 #34
0
 public DisconnectedEventArgs(DisconnectType disconnectReason)
 {
     DisconnectReason = disconnectReason;
 }
예제 #35
0
    void Disconnected(DisconnectType dis, string msg)
    {
        Close();
        string protocal = dis == DisconnectType.System ?
        SocketStatusCMD.Exception : SocketStatusCMD.Disconnect;

        NetBuffer buffer = new NetBuffer();
        buffer.WriteString(protocal);
        SocketClientManager.AddEvent(protocal, buffer);
        DebugConsole.LogError("Disconnected :>" + msg + " DisconnectType:>" + dis);
    }
예제 #36
0
파일: Connection.cs 프로젝트: hnefatl/RBS
        public void Close(DisconnectType Reason)
        {
            Send(new DisconnectMessage(Reason));

            Dispose();
        }
예제 #37
0
 public void TriggerPeerDisconnected(DisconnectReason reason, DisconnectType disconnectType)
 {
     PeerDisconnected?.Invoke(this, new DisconnectEventArgs(reason, disconnectType));
 }
예제 #38
0
 public void ReportDisconnect(DisconnectReason reason, DisconnectType type, string details)
 {
 }
예제 #39
0
        /// <summary>
        /// Shutdown will disconnect all the sims except for the current sim
        /// first, and then kill the connection to CurrentSim.
        /// </summary>
        private void Shutdown(DisconnectType type)
        {
            Client.Log("NetworkManager shutdown initiated", Helpers.LogLevel.Info);

            lock (Simulators)
            {
                // Disconnect all simulators except the current one
                for (int i = 0; i < Simulators.Count; i++)
                {
                    if (Simulators[i] != null && Simulators[i] != CurrentSim)
                    {
                        Simulators[i].Disconnect();

                        // Fire the SimDisconnected event if a handler is registered
                        // FIXME: This is a recipe for disaster, locking Simulators and
                        // firing a callback
                        if (OnSimDisconnected != null)
                        {
                            try { OnSimDisconnected(Simulators[i], type); }
                            catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                        }
                    }
                }

                Simulators.Clear();
            }

            if (CurrentSim != null)
            {
                // Kill the connection to the curent simulator
                CurrentSim.Disconnect();

                // Fire the SimDisconnected event if a handler is registered
                if (OnSimDisconnected != null)
                {
                    try { OnSimDisconnected(CurrentSim, type); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }

                // Destroy the CurrentSim object
                lock (Simulators) CurrentSim = null;
            }


            // Clear out all of the packets that never had time to process
            lock (PacketInbox) PacketInbox.Clear();

            connected = false;
        }
예제 #40
0
 public void OnDisconnect(DisconnectType disconnectType) => Disconnect();
예제 #41
0
 public DisconnectMessage(DisconnectType Reason)
 {
     this.Reason = Reason;
 }