/// <summary>
 /// コメントをキューの最後に追加する
 /// </summary>
 /// <param name="comment"></param>
 public void EnqueueComment(BroadcastComment comment)
 {
     lock (lockObject)
     {
         comments.Enqueue(comment);
     }
 }
Пример #2
0
        public static void callback(BroadcastComment comment)
        {
            Console.WriteLine(new StringBuilder()
                .Append(comment.Number).Append(" ")
                .Append(comment.ElapsedTime.ToString()).Append(" ")
                .Append(comment.Premium ? "P" : "N").Append(" ")
                .Append(comment.UserId).Append(" ")
                .Append(comment.CommentValue).Append(" ")
            );

            if (comment.CommentValue.StartsWith("sm"))
            {
                //broadcast.SendComment("/play " + comment.CommentValue + " sub");
            }
            return;
        }
Пример #3
0
        public static void callback(BroadcastComment comment)
        {
            Console.WriteLine(new StringBuilder()
                .Append(comment.Number).Append(" ")
                .Append(comment.ElapsedTime.ToString()).Append(" ")
                .Append(comment.Premium ? "P" : "N" ).Append(" ")
                .Append(comment.UserId).Append(" ")
                .Append(comment.CommentValue).Append(" ")
            );
            return;

            StringBuilder sb = new StringBuilder();
            TcpClient tcp = new TcpClient("localhost", 9821);
            Stream s = tcp.GetStream();
            StreamWriter sw = new StreamWriter(s);
            StreamReader sr = new StreamReader(s);
            //sw.Write(sb);
            //sw.Flush();
            char[] c = new char[512];
            //sr.Read(c, 0, c.Length);
            //Console.WriteLine(c);
            //tcp.Close();

            //tcp = new TcpClient("localhost", 9821);
            //s = tcp.GetStream();
            //sw = new StreamWriter(s);
            //sr = new StreamReader(s);
            sb = new StringBuilder();
            sb.Append("SEND SSTP/1.1\r\n");
            sb.Append("Sender: MomeNicoLibrary\r\n");
            sb.Append("Script: \\0\\s0" + comment.CommentValue + "\\e\r\n");
            sb.Append("Option: nodescript,notranslate\r\n");
            sb.Append("Charset: UTF-8\r\n\r\n");
            sw.Write(sb);
            sw.Flush();
            sr.Read(c, 0, c.Length);
            Console.WriteLine(c);
            tcp.Close();
        }
 public void SendComment(BroadcastComment comment)
 {
     sender.Send(comment);
 }
 /// <summary>
 /// コメント受信イベントホルダー
 /// </summary>
 public static void OnReceiveEventHandler(BroadcastComment comment)
 {
 }
Пример #6
0
 public void callback(BroadcastComment comment)
 {
     this.comment = comment;
     Invoke(new MethodInvoker(ViewUpdate));
 }
 /// <summary>
 /// コメントパーサー
 /// </summary>
 /// <param name="chat"></param>
 public static BroadcastComment Parse(string chat)
 {
     BroadcastComment comment = new BroadcastComment(
         XmlParse(chat, new CommentItems()));
     return comment;
 }
Пример #8
0
        /// <summary>
        /// コメント投稿
        /// </summary>
        /// <param name="broadcast_id"></param>
        /// <param name="comment"></param>
        public void PostComment(BroadcastComment comment)
        {
            // コメントサーバに接続
            System.Net.Sockets.TcpClient tcp = new System.Net.Sockets.TcpClient(si.Address, si.Port);

            // コメントサーバに下記のコマンドを投げると情報がかえる
            Stream s = tcp.GetStream();
            StreamWriter sw = new StreamWriter(s);
            string cmd = "<thread thread=\"" + si.Thread + "\" res_from=\"-" + 0 + "\" version=\"20061206\" />\0";
            sw.Write(cmd);

            // last_resに書かれてるレス番を取得する
            System.Net.Sockets.TcpClient tcp2 = new System.Net.Sockets.TcpClient(si.Address, si.Port);

            Stream ts = tcp2.GetStream();
            string t = "<thread thread=\"" + si.Thread + "\" version=\"20061206\" res_from=\"-1\"/>\0";
            byte[] b = Encoding.ASCII.GetBytes(t);
            ts.Write(b, 0, b.Length);

            byte[] buf = new byte[512];
            int size = ts.Read(buf, 0, buf.Length);
            string line = Encoding.UTF8.GetString(buf).Trim('\0');
            ts.Close();

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(line);

            int last_res = 0;
            string ticket = "";

            foreach (XmlNode node in xml.GetElementsByTagName("thread"))
            {
                foreach (XmlNode attr in node.Attributes)
                {
                    switch (attr.Name)
                    {
                        case "last_res":
                            last_res = int.Parse(attr.Value);
                            break;
                        case "ticket":
                            ticket = attr.Value;
                            break;
                        default:
                            //System.Console.WriteLine(attr.Name);
                            //System.Console.WriteLine(attr.Value);
                            break;
                    }
                }
            }

            // 下記のURLに接続する
            string posturl = "http://live.nicovideo.jp/api/getpostkey?thread=" + si.Thread + "&block_no=" + last_res / 100;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(posturl);
            request.Method = "GET";
            request.CookieContainer = new CookieContainer();
            foreach (Cookie c in cookies)
            {
                request.CookieContainer.Add(c);
            }

            WebResponse response = request.GetResponse();
            Stream st = response.GetResponseStream();
            byte[] buf2 = new byte[512];
            st.Read(buf2, 0, buf2.Length);

            string postkey = Encoding.UTF8.GetString(buf2).Trim('\0').Split('=')[1];
            //				Console.WriteLine(postkey);

            // コメントサーバに下記のデータを送信
            long cur = UnixEpochTime.Now();

            //				int vpos = ((int)(cur / 1000) - (ps.bti.baseTime)) * 100;
            //				string postXMLTmpl = "<chat thread=\"" + si.Thread + "\" ticket=\"" + ticket + "\" vpos=\"" + vpos + "\" postkey=\"" + postkey + "\" mail=\"\" user_id=\"" + ps.csi.usrId + "\" premium=\"0\">" + comment + "</chat>\0";
            string postXMLTmpl = "<chat thread=\"" + si.Thread + "\" ticket=\"" + ticket + "\" vpos=\"0\" postkey=\"" + postkey + "\" mail=\"\" user_id=\"" + "" + "\" premium=\"0\">" + comment + "</chat>\0";
            sw.Write(postXMLTmpl);
            sw.Flush();
            sw.Close();
        }
Пример #9
0
 public void Send(BroadcastComment comment)
 {
     sendComments.EnqueueComment(comment);
 }