http://live.nicovideo.jp/api/getalertinfoを使って必要情報を収集(認証付きの方法だと、一手間増えます)
libAnkoにXMLSocketクラスがありますので、それをつかうことで簡単にアラートを作成できます。
private LibAnko.ClsNicoXMLClient Alert;
private string _Alert_user;
private string _Alert_userHash;
private string _Alert_server;
private int _Alert_port;
private int _Alert_thread;
//アラートAPIを呼び出して必要な情報を取得
bool getAlertInfo()
{
//テキストとして取得
string res = _host.GetHTTPResponse("http://live.nicovideo.jp/api/getalertinfo");
if(res=="ServiceUnavailable")
return false;
if (!string.IsNullOrEmpty(res))
{
try
{
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
//xmlをXmlDocumentに読み込んで扱いやすくする
xmldoc.LoadXml(res);
string status = LibAnko.Utility.SelectString(xmldoc, "getalertstatus/@status");
if (status != "ok") return false;
this._Alert_user = LibAnko.Utility.SelectString(xmldoc, "getalertstatus/user_id");
this._Alert_userHash = LibAnko.Utility.SelectString(xmldoc, "getalertstatus/user_hash");
this._Alert_server = LibAnko.Utility.SelectString(xmldoc, "getalertstatus/ms/addr");
this._Alert_port = LibAnko.Utility.SelectInt(xmldoc, "getalertstatus/ms/port", 0);
this._Alert_thread = LibAnko.Utility.SelectInt(xmldoc, "getalertstatus/ms/thread", 0);
return true;
}
catch { }
}
return false;
}
void StartAlert()
{
if(getAlertInfo())
{
Alert = new LibAnko.ClsNicoXMLClient();
Alert.ReceivedMessage += new LibAnko.ReceivedMessageEventHandler(Alert_ReceivedMessage);
Alert.DisConnect += new LibAnko.DisConnectEventHandler(Alert_DisConnect);
Alert.Connected += new EventHandler(Alert_Connected);
//Alert.Connect(サーバーのホスト名, ポート番号, スレッドID, 放送ID(コメビュとして使う時), ユーザID, プレミアム区分, 開始コメント番号);
Alert.Connect(this._Alert_server, this._Alert_port, this._Alert_thread, "", 0, 0, -1);
}
}
アラートがくるとAlert_ReceivedMessageが呼び出されるので、処理していけば出来上がり。
メッセージの中に 放送ID,コミュID,ユーザID って感じでカンマ区切りで入ってきます。