Exemplo n.º 1
0
        public OnlineUserMessge getSingleMessage(int user_id)
        {
            OnlineUserMessge t_return = new OnlineUserMessge();
            MySqlCommand     cmd      = new MySqlCommand("SELECT id,content,from_id FROM drawtogether.systemmsg WHERE to_id=" + user_id + ";", conn);
            MySqlDataAdapter da       = new MySqlDataAdapter(cmd);
            DataSet          ds       = new DataSet();

            try
            {
                da.Fill(ds, "BLOBTest");
                int c = ds.Tables["BLOBTest"].Rows.Count;
                //for (int index = 0; index < c; ++index)
                int index = c - 1;
                {
                    Byte[] byteBLOBData = new Byte[0];
                    byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[index]["content"]);

                    t_return    = (OnlineUserMessge)btoo(byteBLOBData);
                    t_return.id = (int)ds.Tables["BLOBTest"].Rows[index]["id"];
                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("error in getMessageToUser,{0}", ex.Message);
            }
            finally
            {
                ds.Dispose();
                da.Dispose();
            }

            return(t_return);
        }
Exemplo n.º 2
0
        /// <summary>
        /// data[3]{请求人id,被请求人id,0或1(拒绝与否)},返回值表示请求人在线与否
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool dealToMakeFriend(int[] data)
        {
            bool result = false;

            if (data[2] == 1)//同意
            {
                Program.SqlManager.makeFriend(data);
            }

            List <object> re1 = new List <object>(2);

            re1.Add(Program.SqlManager.getUserById(data[1], true));
            re1.Add(data[2]);
            OnlineUserMessge re = new OnlineUserMessge(6, re1);

            if (user_list.ContainsKey(data[0]))//请求人在线
            {
                user_list[data[0]].ReciveMessage(data[1], re);
                result = true;
            }
            else //不在
            {
                List <pair <int, OnlineUserMessge> > ll = new List <pair <int, OnlineUserMessge> >();
                ll.Add(new pair <int, OnlineUserMessge>(data[1], re));
                Program.SqlManager.storeOnlineMessagesOfUser(data[0], ll);
            }
            return(result);
        }
Exemplo n.º 3
0
        public static OnlineUserMessge OOOOO()
        {
            OnlineUserMessge ss     = null;
            MySqlConnection  m_conn = new MySqlConnection("Data Source='127.0.0.1';UserId='Asher';Password='******';");

            m_conn.Open();
            //MySqlCommand cmd = new MySqlCommand("SELECT IMG,name FROM drawtogether.TESTTABLE WHERE id=18", m_conn);
            MySqlCommand cmd = new MySqlCommand("SELECT content,id FROM drawtogether.systemmsg WHERE id=41", m_conn);

            try
            {
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataSet          ds = new DataSet();
                da.Fill(ds, "BLOBTest");
                int c = ds.Tables["BLOBTest"].Rows.Count;
                if (c > 0)
                {
                    Byte[] byteBLOBData = new Byte[0];
                    byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[c - 1]["content"]);
                    ss           = (OnlineUserMessge)btoo(byteBLOBData);
                    string k = ds.Tables["BLOBTest"].Rows[c - 1]["id"].ToString();
                    Console.WriteLine(k);
                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("error in {0},{1}", ex.TargetSite, ex.Message);
            }
            m_conn.Close();
            return(ss);
        }
Exemplo n.º 4
0
        public void storeSingleOnlineMessage(int reciver_id, int sender_id, OnlineUserMessge msg)
        {
            byte[]       bytBLOBData = otob(msg);
            MySqlCommand cmd2        = new MySqlCommand();

            cmd2.CommandText = "INSERT INTO drawtogether.systemmsg (from_id,to_id,content) VALUES (" + sender_id + "," + reciver_id + ",?alfa)";
            MySqlParameter prm = new MySqlParameter("?alfa", MySqlDbType.Blob, bytBLOBData.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bytBLOBData);

            cmd2.Parameters.Add(prm);
            cmd2.Connection = conn;
            cmd2.ExecuteNonQuery();
            cmd2.Dispose();
        }
Exemplo n.º 5
0
        /// <summary>
        /// 处理好友申请消息
        /// </summary>
        /// <param name="afd"></param>
        private static bool AskToBeFriend(AddFriendData afd)
        {
            bool result = false;

            if (isdebug)
            {
                Console.WriteLine("用户{0}要加用户{1}为好友", afd.id, afd.f_id);
            }
            try
            {
                OnlineUserManager.user_list[afd.id].VitalityRefresh();
                //用户afd.id请求加用户afd.f_id为好友,将给用户afd.f_id添加4号S-B消息
                lock (OnlineUserManager.user_list)
                {
                    Console.WriteLine("这里的在线人数{0}", OnlineUserManager.user_list.Count);
                    OnlineUserMessge afdMsg = new OnlineUserMessge(4, OnlineUserManager.user_list[afd.id].ToUser());
                    if (isOnline(afd.f_id))//在线就直接放到人家的消息列表,离线将消息串行化存入数据库
                    {
                        if (isdebug)
                        {
                            Console.WriteLine("用户{0}在线,Ta的消息容器", afd.f_id);
                        }
                        OnlineUserManager.user_list[afd.f_id].ReciveMessage(afd.id, afdMsg);
                    }
                    else
                    {
                        if (isdebug)
                        {
                            Console.WriteLine("用户{0}不在线,塞入数据库", afd.f_id);
                        }
                        List <pair <int, OnlineUserMessge> > ll = new List <pair <int, OnlineUserMessge> >();
                        ll.Add(new pair <int, OnlineUserMessge>(afd.id, afdMsg));
                        SqlManager.storeOnlineMessagesOfUser(afd.f_id, ll);
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("error in AskToBeFriend..{0}", e.Message);
                result = false;
            }
            return(result);
        }
Exemplo n.º 6
0
        public static void KKKKK(OnlineUserMessge image)
        {
            MySqlConnection m_conn = new MySqlConnection("Data Source='127.0.0.1';UserId='Asher';Password='******';");

            m_conn.Open();


            byte[] bytBLOBData = otob(image);

            MySqlCommand cmd2 = new MySqlCommand();

            //cmd2.CommandText = "INSERT INTO drawtogether.TESTTABLE (id,NAME,IMG) VALUES ('4','test',?alfa)";
            cmd2.CommandText = "INSERT INTO drawtogether.systemmsg (id,content) VALUES ('',?alfa)";

            MySqlParameter prm = new MySqlParameter("?alfa", MySqlDbType.Blob, bytBLOBData.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bytBLOBData);

            cmd2.Parameters.Add(prm);
            cmd2.Connection = m_conn;
            cmd2.ExecuteNonQuery();
            cmd2.Dispose();
            m_conn.Close();
        }
Exemplo n.º 7
0
        /// <summary>
        /// 从数据库中获取未处理的消息,可用
        /// </summary>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public List <pair <int, OnlineUserMessge> > getMessageToUser(int user_id)
        {
            List <pair <int, OnlineUserMessge> > List_return = new List <pair <int, OnlineUserMessge> >();
            MySqlCommand     cmd = new MySqlCommand("SELECT content,from_id FROM drawtogether.systemmsg WHERE to_id=" + user_id + ";", conn);
            MySqlDataAdapter da  = new MySqlDataAdapter(cmd);
            DataSet          ds  = new DataSet();
            int Msgindex         = 0;

            try
            {
                da.Fill(ds, "BLOBTest");
                int c = ds.Tables["BLOBTest"].Rows.Count;
                for (int index = 0; index < c; ++index)
                {
                    Byte[] byteBLOBData = new Byte[0];
                    byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[index]["content"]);

                    OnlineUserMessge ts = (OnlineUserMessge)btoo(byteBLOBData);
                    //ts.id = (int)ds.Tables["BLOBTest"].Rows[index]["id"];
                    ts.id = Msgindex;
                    ++Msgindex;
                    List_return.Add(new pair <int, OnlineUserMessge>((int)ds.Tables["BLOBTest"].Rows[index]["from_id"], ts));
                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("error in getMessageToUser,{0}", ex.Message);
            }
            finally
            {
                ds.Dispose();
                da.Dispose();
            }
            runSQL("delete from drawtogether.systemmsg WHERE to_id=" + user_id + ";");
            return(List_return);
        }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="userMessage"></param>
 internal void ReciveMessage(int sender_id, OnlineUserMessge userMessage)
 {
     msgList.Add(new pair <int, OnlineUserMessge>(sender_id, userMessage));
 }