예제 #1
0
        //public int PFile_ParentArea(int? area)
        //{
        //    int i = -1;
        //    try
        //    {

        //        PFileArea gfa = _bbsDataContext.PFileAreas.FirstOrDefault(p => p.ParentAreaId.Equals(area));
        //        if (gfa != null)
        //        {
        //            i = gfa.ParentAreaId;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        LoggingAPI.LogEntry("Exception in DataInterface.PFile_ParentArea: " + e.Message);
        //    }
        //    return i;
        //}
        public List <AreaListRow> PFileListArea(int?area, int userid)
        {
            //List all files and areas in the current area
            var response = new List <AreaListRow>();

            try
            {
                //User u = GetUserById(userid);
                //User must have at least one access group that matches the gfile area
                List <PFileArea>   pfileAreas   = _bbsDataContext.PFileAreas.Where(p => p.ParentAreaId == area).ToList();
                List <PFileDetail> pfileDetails = _bbsDataContext.PFileDetails.Where(p => p.PFileAreaId == area).ToList();
                int listId = 1;
                foreach (PFileArea pfileArea in pfileAreas)
                {
                    listId++;
                    response.Add(new AreaListRow(pfileArea, listId, AreaListRowType.Area));
                }
                foreach (PFileDetail pfileDetail in pfileDetails)
                {
                    listId++;
                    response.Add(new AreaListRow(pfileDetail, listId, AreaListRowType.Entry));
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
            }
            return(response);
        }
예제 #2
0
        public bool AddPFileDetail(int areaId, string filePath, string fileName, string title, string description)
        {
            //filename must include relative path from bbs
            //determines file size on its own
            //Will not allow re-add of the same filename to the same area
            bool b = false;

            try
            {
                if (!PFileExistsInArea(areaId, fileName))
                {
                    if (File.Exists(filePath + fileName))
                    {
                        PFileDetail pfd = new PFileDetail()
                        {
                            PFileAreaId = areaId,
                            Filename    = fileName,
                            FilePath    = filePath,
                            Title       = title,
                            Description = description
                        };
                        _bbsDataContext.PFileDetails.Add(pfd);
                        _bbsDataContext.SaveChanges();
                        b = true;
                    }
                }
            }
            catch (Exception e)
            {
                b = false;
                LoggingAPI.LogEntry("Exception in DataInterface.AddGFile: " + e);
            }
            return(b);
        }
예제 #3
0
        public IdAndKeys MessageBase_ParentArea(int area)
        {
            IdAndKeys idak = new IdAndKeys()
            {
                Id = -1
            };

            idak.Keys.Add("title", "Main");
            try
            {
                BBSDataDataContext bbs = GetDataContext();
                MessageBaseArea    gfa = bbs.MessageBaseAreas.FirstOrDefault(p => p.MessageBaseAreaId.Equals(area));
                if (gfa != null)
                {
                    idak.Id = gfa.ParentAreaId;
                    if (gfa.ParentAreaId == -1)
                    {
                        idak.Keys["title"] = "Main";
                    }
                    else
                    {
                        idak.Keys["title"] = gfa.Title;
                    }
                }
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.MessageBase_ParentArea: " + e.Message);
            }
            return(idak);
        }
예제 #4
0
        public User SaveNewUser(string userName, string password, string realName, string email, string computerType, string ip, string webPage)
        {
            User newUser = null;

            try
            {
                var u = new User()
                {
                    Username          = userName,
                    HashedPassword    = password,
                    RealName          = realName,
                    Email             = email,
                    ComputerType      = computerType,
                    WebPage           = webPage,
                    LastConnection    = DateTime.Now,
                    LastDisconnection = DateTime.Now,
                    LastConnectionIP  = ip
                };
                _bbsDataContext.Users.Add(u);
                _bbsDataContext.SaveChanges();
                newUser = GetUserByName(userName);
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                newUser = null;
            }
            return(newUser);
        }
예제 #5
0
        public List <Tuple <string, string> > GetLastTenCalls()
        {
            var glist = new List <Tuple <string, string> >();

            try
            {
                var callList = _bbsDataContext.CallLogs.OrderByDescending(p => p.Connected).Take(10).ToList();
                foreach (var call in callList)
                {
                    var connected = call.Connected.ToString("yyyy-MM-dd hh:mm");
                    var username  = "";
                    if (call.User == null)
                    {
                        var user = GetUserById(call.UserId);
                        username = user.Username;
                    }
                    else
                    {
                        username = call.User.Username;
                    }
                    glist.Add(new Tuple <string, string>(connected, username));
                    // = callList.Select(p => new Tuple<string, string>(p.Connected.ToString("yyyy-MM-dd hh:mm"), p.User.Username)).ToList();
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
            }
            return(glist);
        }
예제 #6
0
        public bool SaveNewUser(string un, string pw, string rn, string em, string co)
        {
            bool b = false;

            try
            {
                string Un = Utils.ToSQL(un);
                string Pw = Utils.ToSQL(pw);
                string Rn = Utils.ToSQL(rn);
                string Em = Utils.ToSQL(em);
                string Co = Utils.ToSQL(co);
                User   u  = new User()
                {
                    Username = Un, HashedPassword = Pw, RealName = Rn, Email = Em, ComputerType = Co, AccessLevel = 0
                };
                u.LastConnection    = DateTime.Now;
                u.LastDisconnection = DateTime.Now;
                BBSDataDataContext bbs = GetDataContext();
                bbs.Users.InsertOnSubmit(u);
                bbs.SubmitChanges();
                b = true;
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.SaveNewUser: " + e.ToString());
                b = false;
            }
            return(b);
        }
예제 #7
0
        public List <Tuple <string, string> > GetGraffiti()
        {
            var glist = new List <Tuple <string, string> >();

            try
            {
                var graffitis = _bbsDataContext.Graffiti.OrderByDescending(p => p.Posted).Take(10).ToList();
                foreach (var graffiti in graffitis)
                {
                    if (graffiti.User == null)
                    {
                        var user = GetUserById(graffiti.UserId);
                        if (user != null)
                        {
                            glist.Add(new Tuple <string, string>(user.Username, graffiti.Content));
                        }
                    }
                    else
                    {
                        glist.Add(new Tuple <string, string>(graffiti.User.Username, graffiti.Content));
                    }
                }
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.GetGraffiti: " + e.ToString());
            }
            return(glist);
        }
예제 #8
0
        public static int FirstUnread(int userid, List <int> messageids)
        {
            int i = -1;

            if (messageids != null)
            {
                if (messageids.Count > 0)
                {
                    try
                    {
                        BBSDataContext bbs = GetContext();
                        i = messageids.FirstOrDefault(q => !(
                                                          bbs.UserReads.Where(p => p.UserId.Equals(userid)).Select(r => r.MessageHeaderId).Contains(q))
                                                      );
                        if (i == null)
                        {
                            i = -1;
                        }
                    }
                    catch (Exception e)
                    {
                        LoggingAPI.LogEntry("Exception in DataInterface.FirstUnread(" + userid.ToString() + ",LIST):" + e.ToString());
                    }
                }
            }
            return(i);
        }
예제 #9
0
        public bool UpdateAccessGroup(AccessGroup accessGroup)
        {
            bool b = false;

            try
            {
                var dataContext    = GetDataContext();
                var oldAccessGroup = dataContext.AccessGroups.FirstOrDefault(p => p.AccessGroupId == accessGroup.AccessGroupId);
                if (oldAccessGroup != null)
                {
                    oldAccessGroup.AccessGroupNumber       = accessGroup.AccessGroupNumber;
                    oldAccessGroup.CallsPerDay             = accessGroup.CallsPerDay;
                    oldAccessGroup.Description             = accessGroup.Description;
                    oldAccessGroup.Flag_Remote_Maintenance = accessGroup.Flag_Remote_Maintenance;
                    oldAccessGroup.Is_SysOp       = accessGroup.Is_SysOp;
                    oldAccessGroup.MinutesPerCall = accessGroup.MinutesPerCall;
                    oldAccessGroup.Title          = accessGroup.Title;
                    dataContext.SubmitChanges();
                    b = true;
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", accessGroup, e);
            }
            return(b);
        }
예제 #10
0
        public void PostReply(int messagebase, string subject, bool anon, int userid, string message, int threadid)
        {
            try
            {
                BBSDataDataContext bbs = GetDataContext();

                MessageHeader header = new MessageHeader()
                {
                    MessageBaseId = messagebase, Anonymous = anon, Posted = DateTime.Now, Subject = subject, UserId = userid, MessageThreadId = threadid
                };
                bbs.MessageHeaders.InsertOnSubmit(header);
                bbs.SubmitChanges();

                MessageBody body = new MessageBody()
                {
                    Body = message, MessageHeaderId = header.MessageHeaderId
                };
                bbs.MessageBodies.InsertOnSubmit(body);

                bbs.SubmitChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.PostMessage: " + e.ToString());
            }
        }
예제 #11
0
        public List <Dictionary <string, string> > GetLast10()
        {
            List <Dictionary <string, string> > glist = new List <Dictionary <string, string> >();

            try
            {
                BBSDataDataContext bbs = GetDataContext();
                var gl2 = bbs.CallLogs.OrderByDescending(p => p.Connected).Take(10)
                          .Join(bbs.Users, g => g.UserId, u => u.UserId, (g, u) => new { connected = g.Connected, user = u.Username })
                          .ToList();

                foreach (var gl in gl2)
                {
                    Dictionary <string, string> d = new Dictionary <string, string>
                    {
                        { "when", gl.connected.ToString("yyyy-MM-dd hh:mm") },
                        { "user", gl.user }
                    };
                    glist.Add(d);
                }
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.GetLast10: " + e.ToString());
            }
            return(glist);
        }
예제 #12
0
        public List <AreaListRow> GFileListArea(int?area, int userid)
        {
            //List all files and areas in the current area
            var response = new List <AreaListRow>();

            try
            {
                //User u = GetUserById(userid);
                //User must have at least one access group that matches the gfile area
                List <GFileArea>   gfileAreas   = _bbsDataContext.GFileAreas.Where(p => p.ParentAreaId == area).ToList();
                List <GFileDetail> gfileDetails = _bbsDataContext.GFileDetails.Where(p => p.GFileAreaId == area).ToList();
                int listId = 1;
                foreach (GFileArea gfileArea in gfileAreas)
                {
                    listId++;
                    response.Add(new AreaListRow(gfileArea, listId, AreaListRowType.Area));
                }
                foreach (GFileDetail gfileDetail in gfileDetails)
                {
                    listId++;
                    response.Add(new AreaListRow(gfileDetail, listId, AreaListRowType.Entry));
                }
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.GFile_List_Area(" + area.ToString() + ") : " + e.Message);
            }
            return(response);
        }
예제 #13
0
        //Start new thread
        public void PostMessage(int messagebase, string subject, bool anon, int userid, string message)
        {
            try
            {
                //MessageThread thread = new MessageThread() { MessageBaseId = messagebase, MessageHeaderId = -1 };
                //_bbsDataContext.MessageThreads.Add(thread);
                //_bbsDataContext.SaveChanges();

                //MessageHeader header = new MessageHeader() { MessageBaseId = messagebase, Anonymous = anon, Posted = DateTime.Now, Subject = subject, UserId = userid, MessageThreadId = thread.MessageThreadId };
                //_bbsDataContext.MessageHeaders.Add(header);
                //_bbsDataContext.SaveChanges();

                //thread.MessageHeaderId = header.Id;
                //_bbsDataContext.SaveChanges();

                //MessageBody body = new MessageBody() { Body = message, MessageHeaderId = header.Id };
                //_bbsDataContext.MessageBodies.Add(body);

                //_bbsDataContext.SaveChanges();
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.PostMessage: " + e.ToString());
            }
        }
예제 #14
0
 private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             //which row is highlighted
             foreach (DataGridViewRow row in dataGridView1.SelectedRows)
             {
                 int         id = int.Parse(row.Cells[1].Value.ToString());
                 StateObject so = testserv.connectedSocks.FirstOrDefault(p => p.GetHashCode().Equals(id));
                 if (so != null)
                 {
                     testserv.Disconnect(so);
                 }
                 BBS bbs = bbs_instances.FirstOrDefault(p => p.GetHashCode().Equals(id));
                 bbs_instances.Remove(bbs);
             }
         }
     }
     catch (Exception ex)
     {
         LoggingAPI.LogEntry(ex.Message);
     }
 }
예제 #15
0
        public bool UpdateAccessGroup(AccessGroup accessGroup)
        {
            bool b = false;

            try
            {
                var oldAccessGroup = GetAccessGroupById(accessGroup.Id);
                if (oldAccessGroup != null)
                {
                    //oldAccessGroup.AccessGroupNumber = accessGroup.AccessGroupNumber;
                    oldAccessGroup.CallsPerDay            = accessGroup.CallsPerDay;
                    oldAccessGroup.Description            = accessGroup.Description;
                    oldAccessGroup.AllowRemoteMaintenance = accessGroup.AllowRemoteMaintenance;
                    oldAccessGroup.AllowSysOp             = accessGroup.AllowSysOp;
                    oldAccessGroup.MinutesPerCall         = accessGroup.MinutesPerCall;
                    oldAccessGroup.Title       = accessGroup.Title;
                    oldAccessGroup.Description = accessGroup.Description;
                    _bbsDataContext.SaveChanges();
                    b = true;
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", accessGroup, e);
            }
            return(b);
        }
예제 #16
0
 private void RefreshGrid()
 {
     if (this.dataGridView1.InvokeRequired)
     {
         GenericCallback d = new GenericCallback(RefreshGrid);
         this.Invoke(d);
     }
     else
     {
         try
         {
             dataGridView1.Rows.Clear();
             int i = 0;
             foreach (BBS bbs in bbs_instances)
             {
                 if (bbs.CurrentUser != null)
                 {
                     dataGridView1.Rows.Add(i, bbs.State_Object.GetHashCode(), bbs.State_Object.workSocket.RemoteEndPoint.ToString(), bbs.CurrentUser.Username, bbs.CurrentArea, (DateTime.Now.Subtract(bbs.ConnectionTimeStamp).ToString()));
                 }
                 else
                 {
                     dataGridView1.Rows.Add(i, bbs.State_Object.GetHashCode(), bbs.State_Object.workSocket.RemoteEndPoint.ToString(), "Pending Login", "Login", (DateTime.Now.Subtract(bbs.ConnectionTimeStamp).ToString()));
                 }
                 i++;
             }
             Application.DoEvents();
         }
         catch (Exception ex)
         {
             LoggingAPI.LogEntry(ex.Message);
         }
     }
 }
예제 #17
0
 private void CMD_OLM(string command)
 {
     try
     {
         //What userid and what message?
         int    messagebegins = command.IndexOf(' ', 4);
         string user          = command.Substring(3, messagebegins - 3);
         int    userid        = int.Parse(user);
         string message       = command.Substring(messagebegins, command.Length - messagebegins);
         foreach (BBS bbs2 in _bbs._bbsHost.GetAllNodes())
         {
             if (bbs2.CurrentUser.Id.Equals(userid))
             {
                 if (bbs2.doNotDisturb)
                 {
                     _bbs.WriteLine("~l1~d2That user is currently in DND mode.~d0");
                 }
                 else
                 {
                     bbs2._messageQueue.Add("~l1~c4OLM>~c7" + _bbs.CurrentUser.Username + "~c2:~c1" + message);
                     _bbs.WriteLine("~l1~c9Your message was delivered.");
                 }
             }
         }
     }
     catch (Exception e)
     {
         LoggingAPI.LogEntry("Exception in Main.CMD_OLM: " + e);
     }
 }
예제 #18
0
        ///
        /// Decription: Open a listener socket and wait for a connection.
        ///
        private void StartListening()
        {
            // Establish the local endpoint for the socket.
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, _portNumber);
            // Create a TCP/IP socket.
            Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            // Bind the socket to the local endpoint and listen for incoming connections.
            try
            {
                listener.Bind(localEndPoint);
                listener.Listen(1000);
                while (!ShuttingDown)
                {
                    // Set the event to nonsignaled state.
                    allDone.Reset();
                    // Start an asynchronous socket to listen for connections.

                    listener.BeginAccept(new AsyncCallback(this.AcceptCallback), listener);

                    // Wait until a connection is made before continuing.
                    allDone.WaitOne();
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                threadEnd[0].Set();
            }
        }
예제 #19
0
        public List <Dictionary <string, string> > GetGraffiti()
        {
            List <Dictionary <string, string> > glist = new List <Dictionary <string, string> >();

            try
            {
                BBSDataDataContext bbs = GetDataContext();
                var gl2 = bbs.Graffitis.OrderByDescending(p => p.Posted).Take(10)
                          .Join(bbs.Users, g => g.UserId, u => u.UserId, (g, u) => new { graf = g.Content, posted = g.Posted, user = u.Username })
                          .ToList();

                foreach (var gl in gl2)
                {
                    Dictionary <string, string> d = new Dictionary <string, string>
                    {
                        { "graf", gl.graf },
                        { "user", gl.user }
                    };
                    glist.Add(d);
                }
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in DataInterface.GetGraffiti: " + e.ToString());
            }
            return(glist);
        }
예제 #20
0
        public bool UpdateUser(User user)
        {
            bool b = false;

            try
            {
                var dataContext = GetDataContext();
                var oldUser     = GetUserById(user.UserId);
                if (oldUser != null)
                {
                    oldUser.AccessLevel    = user.AccessLevel;
                    oldUser.ComputerType   = user.ComputerType;
                    oldUser.Email          = user.Email;
                    oldUser.HashedPassword = user.HashedPassword;
                    oldUser.RealName       = user.RealName;
                    oldUser.Username       = user.Username;
                    dataContext.SubmitChanges();
                    b = true;
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error("Params, Exception: ", user, e);
            }
            return(b);
        }
예제 #21
0
파일: NewUser.cs 프로젝트: ch0mik/SixNet
        public bool Application()
        {
            var result = false;

            //var quitflag = false;
            try
            {
                //Show new user file
                _bbs.SendFileForTermType("NewUser", true);
                if (!GetUsername())
                {
                    return(false);
                }
                if (!GetPassword())
                {
                    return(false);
                }
                RealName = GetField("Real Name", "~l2~cbEnter your real name.", 0);
                if (RealName == null)
                {
                    return(false);
                }
                Email = GetField("Email", "~l2~cbEnter your email address.", 0);
                if (Email == null)
                {
                    return(false);
                }
                ComputerType = GetField("Computer", "~l2~cbEnter your computer model.", 0);
                if (ComputerType == null)
                {
                    return(false);
                }
                var user = _bbsDataCore.SaveNewUser(Username, Password, RealName, Email, ComputerType, _bbs._remoteAddress, "");
                if (user != null)
                {
                    _bbs.currentUser = user;
                }

                //New User feedback
                _bbs.Write("~l2~cbLeave an introduction message?");
                if (_bbs.YesNo(true, true))
                {
                    var lineEditor = new Line_Editor(_bbs);
                    if (lineEditor.Edit(null))
                    {
                        _bbsDataCore.NewFeedback("New User Feedback", lineEditor.GetMessage(), _bbs.currentUser.Id);
                    }
                }
                //And Done
                result = true;
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in NewUser.Application: " + e.ToString());
            }
            return(result);
        }
예제 #22
0
파일: TermDetect.cs 프로젝트: ch0mik/SixNet
        public ITerminalType Detect()
        {
            ITerminalType termtype = new TermType_Default();

            try
            {
                bool detected = false;
                while ((!detected) && Host_System.Connected)
                {
                    Host_System.Write("\x93\x0cHit Delete:");
                    char c = Host_System.GetChar();
                    if ((c == 8))
                    {
                        Host_System.WriteLine("ASCII/ANSI Detected");
                        Host_System.Write("ANSI Color? ");
                        bool b = Host_System.YesNo(true, true);
                        if (b)
                        {
                            termtype = new TermType_ANSI();
                            detected = true;
                        }
                        else
                        {
                            termtype = new TermType_Default();
                            detected = true;
                        }
                    }
                    else
                    {
                        if (c == '\x14')
                        {
                            termtype = new TermType_PETSCII40();
                            Host_System.WriteRaw("\x1cp" + "\x81" + "e\x9et" + "\x99s" + "\x9a" + "c\x9c" + "i\x1ci \x05" + "dETECTED\x02!\x05");
                            detected = true;
                        }
                        else
                        {
                            if (c == 127)
                            {
                                Host_System.WriteRaw("\x1b[1;31mA\x1b[1;32mN\x1b[1;33mS\x1b[1;34mI\x1b[1;37m Detected");
                                termtype = new TermType_ANSI();
                                detected = true;
                            }
                            else
                            {
                                Host_System.WriteLine(((int)c).ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in TermDetect.Detect: " + e.Message);
            }
            return(termtype);
        }
예제 #23
0
파일: IRC.cs 프로젝트: StuartSeeley/SixNet
        static void Go(string[] args)
        {
            NetworkStream stream;
            TcpClient     irc;
            string        inputLine;
            StreamReader  reader;

            //string nickname;
            try
            {
                irc    = new TcpClient(SERVER, PORT);
                stream = irc.GetStream();
                reader = new StreamReader(stream);
                writer = new StreamWriter(stream);
                // Start PingSender thread
                PingSender ping = new PingSender();
                ping.Start();
                writer.WriteLine(USER);
                writer.Flush();
                writer.WriteLine("NICK " + NICK);
                writer.Flush();
                writer.WriteLine("JOIN " + CHANNEL);
                writer.Flush();
                while (true)
                {
                    while ((inputLine = reader.ReadLine()) != null)
                    {
                        //if (inputLine.EndsWith("JOIN :" + CHANNEL))
                        //{
                        //    // Parse nickname of person who joined the channel
                        //    nickname = inputLine.Substring(1, inputLine.IndexOf("!") - 1);
                        //    // Welcome the nickname to channel by sending a notice
                        //    writer.WriteLine("NOTICE " + nickname + " :Hi " + nickname +
                        //    " and welcome to " + CHANNEL + " channel!");
                        //    writer.Flush();
                        //    // Sleep to prevent excess flood
                        //    Thread.Sleep(2000);
                        //}
                    }
                    // Close all streams
                    writer.Close();
                    reader.Close();
                    irc.Close();
                }
            }
            catch (Exception e)
            {
                LoggingAPI.LogEntry("Exception in Main.MainPrompt: " + e);
                // Show the exception, sleep for a while and try to establish a new connection to irc server
                //Console.WriteLine(e.ToString());
                //Thread.Sleep(5000);
                //string[] argv = { };
                //Main(argv);
            }
        }
예제 #24
0
파일: Server.cs 프로젝트: ch0mik/SixNet
        ///
        /// 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);
                }
            }
        }
예제 #25
0
파일: Program.cs 프로젝트: ch0mik/SixNet
        public static void Main(string[] args)
        {
            Console.Clear();
            Console.WriteLine("SixNet BBS, Starting up...");
            _bbsDatabaseConfiguration = BBSDatabaseConfiguration.LoadConfig("./");
            if (_bbsDatabaseConfiguration == null)
            {
                Console.WriteLine("Run setup utility first.");
                return;
            }
            _connectionString = BBSDatabaseConfiguration.BuildConnectionString(_bbsDatabaseConfiguration);
            LoggingAPI.Init("./Logs/");
            if (BBSDatabaseConfiguration.IsDatabaseSetup(_connectionString))
            {
                Console.WriteLine("Database configured.");
                _core = new BBSDataCore(_connectionString);
            }
            else
            {
                Console.WriteLine("Database not configured - run setup utility.");
                return;
            }
            var config = _core.GetBBSConfig();

            LoggingAPI.LogEntry("Software started.");
            try
            {
                quitFlag = false;
                BBSServer bbsServer = new BBSServer(_connectionString, config.BBSPort, "BBS Server");
                bbsServer.Start();
                while (!quitFlag)
                {
                    Thread.Sleep(100);
                    if (Console.KeyAvailable)
                    {
                        if (Console.ReadKey().Key == ConsoleKey.Q)
                        {
                            quitFlag = true;
                            bbsServer.Stop();
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
            }
            finally
            {
                LoggingAPI.LogEntry("Software shutdown.");
                LoggingAPI.FlushQueue();
            }
        }
예제 #26
0
        public static bool InitializeDatabase()
        {
            bool           b      = true;
            BBSDataContext bbs    = BBSDataContext.GetContext();
            SysConfig      config = null;

            try
            {
                config = bbs.SysConfigs.First(p => true);
            }
            catch (Exception e)
            {
                //nada
                LoggingAPI.LogEntry("Exception in DBUpdater.InitializeDatabase (Initial config check): " + e.Message);
            }
            if (config == null)
            {
                //Create base config
                config = new SysConfig()
                {
                    DatabaseVersion = 0
                };
                bbs.SysConfigs.Add(config);

                bbs.SaveChanges();

                //Create Sysop User
                User u = new User()
                {
                    Username          = "******",
                    HashedPassword    = "******",
                    LastConnection    = DateTime.Now,
                    LastConnectionIP  = "127.0.0.1",
                    LastDisconnection = DateTime.Now
                };
                bbs.Users.Add(u);
                bbs.SaveChanges();

                //Reload to get id in case it didn't autofill
                u = bbs.Users.FirstOrDefault(p => p.Username.Equals("Six"));

                //Create base bbsconfig
                BBSConfig bconfig = new BBSConfig()
                {
                    SysOpUserId = u.UserId,
                    BBS_Name    = "The Darkside BBS"
                };

                bbs.BBSConfigs.Add(bconfig);

                bbs.SaveChanges();
            }
            return(b);
        }
예제 #27
0
 public void AddConnection(StateObject so)
 {
     try
     {
         StartBBS(so);
     }
     catch (Exception e)
     {
         LoggingAPI.LogEntry("Exception in MainForm.AddConnection: " + e.Message);
     }
 }
예제 #28
0
 public User GetUserByName(string username)
 {
     try
     {
         return(_bbsDataContext.Users.FirstOrDefault(p => p.Username.ToUpper().Equals(username.ToUpper())));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + username + ")", e);
         return(null);
     }
 }
예제 #29
0
 public User GetUserById(int id)
 {
     try
     {
         return(_bbsDataContext.Users.FirstOrDefault(p => p.Id.Equals(id)));
     }
     catch (Exception e)
     {
         LoggingAPI.Error("(" + id + ")", e);
         return(null);
     }
 }
예제 #30
0
        //public AccessGroup GetAccessGroup(int level)
        //{
        //    try
        //    {
        //        return _bbsDataContext.AccessGroups.FirstOrDefault(p => p.AccessGroupNumber.Equals(level));
        //    }
        //    catch (Exception e)
        //    {
        //        LoggingAPI.Error("(" + level + "): " + e);
        //        return null;
        //    }
        //}

        public List <AccessGroup> ListAccessGroups()
        {
            try
            {
                return(_bbsDataContext.AccessGroups.ToList());
            }
            catch (Exception e)
            {
                LoggingAPI.Error(e);
                return(null);
            }
        }