Exemplo n.º 1
0
        ///
        /// Decription: Call back method to handle incoming data.
        ///
        /// <param name="ar">Status of an asynchronous operation.</param>
        protected void ReadCallback(IAsyncResult ar)
        {
            //String content = String.Empty;
            // Retrieve the state object and the handler socket
            // from the async state object.
            StateObject state   = (StateObject)ar.AsyncState;
            Socket      handler = state.workSocket;

            try
            {
                // Read data from the client socket.
                int bytesRead = handler.EndReceive(ar);

                if (bytesRead > 0)
                {
                    Monitor.Enter(state);
                    for (int i = 0; i < bytesRead; i++)
                    {
                        state.Received(state.buffer[i]);
                    }
                    Monitor.Exit(state);
                    //content = state.sb.ToString();
                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(this.ReadCallback), state);
                }
                else
                { //Disconnected
                    RemoveSocket(state);
                }
            }
            catch (System.Net.Sockets.SocketException es)
            {
                RemoveSocket(state);
                OnDisconnect(state);
                if (es.ErrorCode == 10057 || es.NativeErrorCode == 10054)
                {
                    LoggingAPI.SysLogEntry(state.RemoteAddress + ": Socket Disconnected");
                }
                else
                {
                    if (es.ErrorCode != 64)
                    {
                        LoggingAPI.Error(es);
                    }
                }
            }
            catch (Exception e)
            {
                RemoveSocket(state);
                OnDisconnect(state);
                if (e.GetType() != typeof(System.ObjectDisposedException))
                {
                    LoggingAPI.Error(e);
                }
            }
        }
Exemplo n.º 2
0
Arquivo: BBS.cs Projeto: ch0mik/SixNet
        //private readonly bool _slackEnabled;
        //private readonly SlackIntegration _slackIntegration;

        public BBS(IBBSHost bbsHost, StateObject stateObject, string ConnectionString)
        {
            connectionTimestamp        = DateTime.Now;
            _bbsDataCore               = new BBSDataCore(ConnectionString);
            _bbsHost                   = bbsHost;
            base._stateObject          = stateObject;
            messageQueueTimer.Enabled  = false;
            messageQueueTimer.Interval = 100;
            messageQueueTimer.Elapsed += new System.Timers.ElapsedEventHandler(MessageQueueTimer_Elapsed);
            _remoteAddress             = stateObject.RemoteAddress;
            //_slackEnabled = (_dataInterface.GetUserDefinedField(0, "SLACKENABLED") == "1");
            //if (_slackEnabled) _slackIntegration = new SlackIntegration(_dataInterface);

            LoggingAPI.SysLogEntry(_remoteAddress + ": User Connected");
        }
Exemplo n.º 3
0
        public BBS(IBBSHost host_system, StateObject so, string ConnectionString)
        {
            ConnectionTimeStamp        = DateTime.Now;
            _dataInterface             = new DataInterface(ConnectionString);
            Host_System                = host_system;
            State_Object               = so;
            MessageQueueTimer.Enabled  = false;
            MessageQueueTimer.Interval = 100;
            MessageQueueTimer.Elapsed += new System.Timers.ElapsedEventHandler(MessageQueueTimer_Elapsed);
            _remoteAddress             = so.workSocket.RemoteEndPoint.ToString();
            _slackEnabled              = (_dataInterface.GetUserDefinedField(0, "SLACKENABLED") == "1");
            if (_slackEnabled)
            {
                _slackIntegration = new SlackIntegration(_dataInterface);
            }

            LoggingAPI.SysLogEntry(_remoteAddress + ": User Connected");
        }
Exemplo n.º 4
0
        public bool Go()
        {
            if (State_Object != null)
            {
                DoNotDisturb = true;
                DND_Override = false;
                MessageQueue = new List <string>();
                State_Object.AddDisconnectHandler(Disconnect);
                State_Object.AddReceiver(Receive);
                Currentchar = 0x00;
                try
                {
                    Sysop_Identified = false;
                    //Terminal Detection
                    TerminalType = new TermType_Default();
                    TermDetect td = new TermDetect(this);
                    TerminalType = td.Detect();
                    LoggingAPI.SysLogEntry(_remoteAddress + ": " + TerminalType.TerminalTypeName() + " terminal was detected");
                    Write("~s1");
                    //Welcome Screen
                    SendFileForTermType("Welcome", false);
                    if (TerminalType.C64_Color())
                    {
                        AnyKey(true, false);
                        Write("~s2");
                    }
                    else
                    {
                        AnyKey(true, true);
                    }

                    //Login
                    Login li = new Login(this, _dataInterface);
                    CurrentUser = li.LogIn();
                    if (CurrentUser != null)
                    {
                        SlackLogMessage(CurrentUser.Username + " logged on.");
                        LoggingAPI.SysLogEntry(_remoteAddress + ": " + CurrentUser.Username + "(" + CurrentUser.UserId.ToString() + ")" + " logged in.");
                        int CallLogId = _dataInterface.RecordConnection(CurrentUser.UserId);

                        LastTen lt = new LastTen(this, _dataInterface);
                        lt.ShowLast10();
                        AnyKey(true, false);

                        Gw = new GraffitiWall(this, _dataInterface);
                        Gw.DisplayWall();
                        AnyKey(true, false);

                        News ne = new News(this, _dataInterface);
                        ne.DisplayNews();
                        AnyKey(true, false);

                        Main main = new Main(this, _dataInterface);
                        try
                        {
                            MessageQueueTimer.Enabled = true;
                            Thread.Sleep(100);
                            main.MainPrompt();
                            MessageQueueTimer.Enabled = false;
                            Thread.Sleep(100);
                        }
                        catch (Exception e)
                        {
                            //Log this?
                            LoggingAPI.Error(e);
                        }
                        _dataInterface.RecordDisconnection(CallLogId);
                    }
                    //Close Out
                    WriteLine("~l1~c1Logging out~c2...");
                    LoggingAPI.SysLogEntry(_remoteAddress + ": " + CurrentUser.Username + "(" + CurrentUser.UserId.ToString() + ")" + " logged out.");
                    CurrentArea = "Logging out";
                    //Send end screen
                    SendFileForTermType("Goodbye", true);
                    Sysop_Identified = false;
                    //Thread.Sleep(1000 * 3);
                    CurrentArea = "Disconnected.";
                    SlackLogMessage(CurrentUser.Username + " logged off.");
                    HangUp();
                }
                catch (Exception e)
                {
                    LoggingAPI.Error(e);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }