示例#1
0
文件: Server.cs 项目: zod331/pcsx2
        /// <summary>
        /// Thread function that actually run the server socket work.
        /// </summary>
        private void MainThread()
        {
            try
            {
                while (Enabled == true)
                {
                    TcpClient client = _socket.AcceptTcpClient();

                    CancelArgs args = new CancelArgs(false);
                    ClientS    cl   = CreateClient(client);
                    if (OnClientBeforeConnect != null)
                    {
                        OnClientBeforeConnect(this, cl, args);
                    }

                    if (args.Cancel != true)
                    {
                        lock (_clients)
                        {
                            _clients.Add(cl);
                        }

                        ASCIIEncoding ae  = new ASCIIEncoding();
                        byte[]        arr = ae.GetBytes("CONNECTEDTCPSERVER");

                        cl.Send(new Data(arr));

                        if (OnClientAfterConnect != null)
                        {
                            OnClientAfterConnect(this, cl);
                        }
                        cl.Start();
                    }
                    else
                    {
                        client.GetStream().Close();
                        client.Close();
                    }
                }
            }
            catch (SocketException)
            {
                Enabled = false;
            }
        }
示例#2
0
文件: Server.cs 项目: tsiru/pcsx2
        /// <summary>
        /// Thread function that actually run the server socket work.
        /// </summary>
        private void MainThread()
        {
            try
            {
                while (Enabled == true)
                {
                    TcpClient client = _socket.AcceptTcpClient();

                    CancelArgs args = new CancelArgs(false);
                    ClientS cl = CreateClient(client);
                    if (OnClientBeforeConnect != null)
                        OnClientBeforeConnect(this, cl, args);

                    if (args.Cancel != true)
                    {
                        lock (_clients)
                        {
                            _clients.Add(cl);
                        }

                        ASCIIEncoding ae = new ASCIIEncoding();
                        byte[] arr = ae.GetBytes("CONNECTEDTCPSERVER");

                        cl.Send(new Data(arr));

                        if (OnClientAfterConnect != null)
                            OnClientAfterConnect(this, cl);
                        cl.Start();
                    }
                    else
                    {
                        client.GetStream().Close();
                        client.Close();
                    }
                }
            }
            catch (SocketException)
            {
                Enabled = false;
            }
        }
示例#3
0
        /// <summary>
        /// Kick the client if the server reached the maximum allowed number of clients.
        /// </summary>
        /// <param name="server">Server raising the event.</param>
        /// <param name="client">Client connecting to the server.</param>
        /// <param name="args">Specify if the client should be accepted into the server.</param>
        void BaseMessageServer_OnClientBeforeConnect(Server server, ClientS client, CancelArgs args)
        {
            if ((Clients.Count >= UserLimit) && (UserLimit != 0))
            {
                TCPMessage msg = new TCPMessage();
                msg.MessageType = MessageType.MaxUsers;
                ((BaseMessageClientS)client).Send(msg);

                args.Cancel = true;
            }
        }