Exemplo n.º 1
0
        static void PingServer_OnAfterSet()
        {
            try
            {
                DateTime dt     = DateTime.Today;
                bool     result = false;
                if (dt.Year == Config.AppSetting.lastlogclear.year)
                {
                    if (dt.Month != Config.AppSetting.lastlogclear.month)
                    {
                        result = true;
                    }
                }
                else
                {
                    result = true;
                }

                if (result)
                {
                    NetTalk.BLL.Log api = new NetTalk.BLL.Log();
                    api.ClearLastMonthLog();

                    Config.AppSetting.lastlogclear.month = Convert.ToByte(dt.Month);
                    Config.AppSetting.lastlogclear.year  = Convert.ToUInt16(dt.Year);

                    Config.SaveXML();
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(null, ex, "PingServer_OnAfterSet");
            }
        }
Exemplo n.º 2
0
        public static void Messages(string sid, string username, Message msg)
        {
            string TextBody = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(msg.Body))
                {
                    TextBody = msg.Body;
                }

                if (msg.To != null)
                {
                    if (!string.IsNullOrEmpty(msg.To.User))
                    {
                        if (TextBody == "info")
                        {
                            XML.Messages.SendInfo(username, msg.To.User);
                        }
                        else
                        {
                            XML.Messages.SendMessage(username, msg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(sid, ex, "Proccess.Messages");
            }
        }
Exemplo n.º 3
0
        public static bool SaveFromBase64(string b64, out string name)
        {
            bool result = false;

            byte[] buffer = Convert.FromBase64String(b64);
            name = NetTalk.Common.Hash.NetTalkHash.HashData(buffer, "sha1");
            bool  IsImage = false;
            float kbyte   = Convert.ToSingle(buffer.Length) / 1024f;

            try
            {
                MemoryStream st = new MemoryStream();
                st.Write(buffer, 0, buffer.Length);
                Image img = Image.FromStream(st);
                st.Close();
                st.Dispose();
                IsImage = true;
                if (kbyte > 20)
                {
                    Image Thumb = NetTalk.Common.ImageTools.NetTalkCropImage.Thumbnail(img, true, 150);
                    st = new MemoryStream();
                    Thumb.Save(st, NetTalk.Common.ImageTools.NetTalkEncoder.JpegEncoderInfo, NetTalk.Common.ImageTools.NetTalkEncoder.EncoderParams(85));

                    buffer = st.ToArray();
                    b64    = Convert.ToBase64String(buffer);

                    st.Close();
                    st.Dispose();

                    Thumb.Dispose();
                    Thumb = null;

                    kbyte = 20;
                }

                img.Dispose();
                img = null;
            }
            catch (Exception ex)
            {
                LogTools.Write(null, ex, "ImageTools.SaveFromBase64");
            }

            if (IsImage && (kbyte <= 20))
            {
                object obj = new object();
                lock (obj)
                {
                    if (!File.Exists(Config.PictureFolder + name))
                    {
                        File.WriteAllText(Config.PictureFolder + name, b64);
                    }
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public static string ToBase64(string name)
        {
            string result = "";

            try
            {
                result = File.ReadAllText(Config.PictureFolder + name);
            }
            catch (Exception ex)
            {
                LogTools.Write(null, ex, "ImageTools.ToBase64");
            }
            return(result);
        }
Exemplo n.º 5
0
 public void Send(string data)
 {
     try
     {
         if (!string.IsNullOrEmpty(data))
         {
             byte[] byteData = Encoding.UTF8.GetBytes(data);
             ConnectionSocket.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), null);
             LogTools.Write(this.SessionId, data);
         }
     }
     catch (Exception ex)
     {
         LogTools.Write(this.SessionId, ex, "Connection.Send");
     }
 }
Exemplo n.º 6
0
 private void ReadCallback(IAsyncResult ar)
 {
     try
     {
         int bytesRead = ConnectionSocket.EndReceive(ar);
         if (bytesRead > 0)
         {
             streamParser.Push(buffer, 0, bytesRead);
             ConnectionSocket.BeginReceive(buffer, 0, BUFFERSIZE, 0, new AsyncCallback(ReadCallback), null);
         }
     }
     catch (Exception ex)
     {
         LogTools.Write(this.SessionId, ex, "Connection.ReadCallback");
     }
 }
Exemplo n.º 7
0
 private void streamParser_OnStreamElement(object sender, Node e)
 {
     LogTools.Write(this.SessionId, e.ToString());
     if (e.GetType() == typeof(Message))
     {
         XML.Proccess.Messages(this.SessionId, this.Username, e as Message);
     }
     else if (e.GetType() == typeof(Presence))
     {
         XML.Proccess.Presences(this.SessionId, this.Username, e as Presence);
     }
     else if (e.GetType() == typeof(IQ))
     {
         IQ iq = e as IQ;
         XML.Proccess.IQs(this.SessionId, this.Username, iq);
     }
 }
Exemplo n.º 8
0
        public static void Presences(string sid, string username, Presence pre)
        {
            try
            {
                if (pre.HasTag("x"))
                {
                    XML.Rosters.GetUserPicture(username, pre);
                }

                string StatusText = string.Empty;
                int    UserIndex;
                if (pre.HasAttribute("type"))
                {
                    XML.Rosters.PresenceProccessTypes(username, pre);
                }
                else
                {
                    ShowType show = ShowType.NONE;
                    if (pre.HasTag("show"))
                    {
                        show = pre.Show;
                    }
                    if (!string.IsNullOrEmpty(pre.Status))
                    {
                        StatusText = pre.Status;
                    }

                    ThreadTools.Users.Online.IsAuthenticated(username, out UserIndex);
                    if (UserIndex > -1)
                    {
                        ThreadTools.Users.Online[UserIndex].UserStatus     = show;
                        ThreadTools.Users.Online[UserIndex].UserStatusText = StatusText;
                    }
                    XML.Rosters.ChangeStatus(username, StatusText, show, (UserIndex > -1));
                    XML.Rosters.SendStatus(username);
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(sid, ex, "Proccess.Presences");
            }
        }
Exemplo n.º 9
0
        public static bool SaveXML(string URL)
        {
            bool          Result = false;
            XmlSerializer rd     = new XmlSerializer(typeof(XMLConfig.config));

            try
            {
                using (XmlWriter writer = XmlWriter.Create(URL))
                {
                    rd.Serialize(writer, AppSetting);
                    writer.Close();
                    Result = true;
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(null, ex, "Config.SaveXML");
            }
            return(Result);
        }
Exemplo n.º 10
0
        public static bool LoadXML(string URL)
        {
            bool          Result = false;
            XmlSerializer rd     = new XmlSerializer(typeof(XMLConfig.config));

            try
            {
                using (XmlReader reader = XmlReader.Create(URL))
                {
                    AppSetting     = (XMLConfig.config)rd.Deserialize(reader);
                    FileLoadedDate = System.IO.File.GetLastWriteTime(URL);
                    Result         = true;
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(null, ex, "Config.LoadXML");
            }
            return(Result);
        }
Exemplo n.º 11
0
        public static void IQs(string sid, string username, IQ iq)
        {
            try
            {
                string iqId = string.Empty;
                if (iq.HasAttribute("id"))
                {
                    iqId = iq.Id;
                }

                int UserSessionIndex;
                ThreadTools.Users.Online.IsSessionExists(sid, out UserSessionIndex);

                if (ThreadTools.Users.Online[UserSessionIndex].Authenticated)
                {
                    iq.From = new agsXMPP.Jid(username + "@" + Config.AppSetting.domain);
                }

                if (iq.HasTag("ping"))
                {
                    XML.IQs.PingPong(username, UserSessionIndex, iqId);
                }
                else if (iq.HasTag("vCard"))
                {
                    XML.IQs.ProccessVcard(username, UserSessionIndex, iq);
                }
                else if (iq.HasTag("pubsub"))
                {
                    //to do
                }
                else if (iq.Query != null)
                {
                    if (iq.Query.Namespace == "http://jabber.org/protocol/disco#info" && iq.Type == IqType.get)
                    {
                        ThreadTools.Users.Online[UserSessionIndex].Send(XML.Server.features(username, iq));
                    }
                    else if (iq.Query.GetType() == typeof(Auth))
                    {
                        Auth auth = iq.Query as Auth;
                        switch (iq.Type)
                        {
                        case IqType.get:
                            XML.IQs.ProccessAuthGet(username, UserSessionIndex, iq);
                            break;

                        case IqType.set:
                            XML.IQs.ProccessAuthSet(username, sid, UserSessionIndex, iq);
                            break;
                        }
                    }
                    else if (iq.Query.GetType() == typeof(Register))
                    {
                        XML.IQs.SubmitChangePassForm(username, iq);
                    }
                    else if (iq.Query.GetType() == typeof(Roster))
                    {
                        if (iq.Type == IqType.get)
                        {
                            XML.IQs.ProcessRosterIQGet(username, iq);
                        }
                        else
                        {
                            XML.IQs.ProcessRosterIQSet(username, iq);
                        }
                    }
                    else if (iq.Query.GetType() == typeof(Last))
                    {
                        if (iq.Type == IqType.get)
                        {
                            if (iq.To != null)
                            {
                                BLL.Users api = new BLL.Users();
                                iq.SwitchDirection();
                                iq.Type = IqType.result;
                                DateTime d    = api.LastActivity(iq.To.User);
                                TimeSpan diff = DateTime.Now - d;
                                Last     lt   = iq.Query as Last;
                                lt.Seconds = diff.Seconds;
                                ThreadTools.Users.Online[UserSessionIndex].Send(iq);
                            }
                        }
                    }
                    else if (iq.Query.GetType() == typeof(agsXMPP.protocol.iq.version.Version))
                    {
                        iq.SwitchDirection();
                        if (iq.From != null)
                        {
                            ThreadTools.Users.Online[UserSessionIndex].Send(iq);
                        }
                    }
                    else if (iq.Query.Namespace.IndexOf("avatar") > -1)
                    {
                        XML.IQs.Avatar(username, iq);
                    }
                }
            }
            catch (Exception ex)
            {
                LogTools.Write(sid, ex, "Proccess.IQs");
            }
        }