private static string BuildIndexTXTEntry(PeerCast peercast, Channel channel) { var endpoint = peercast.GetGlobalEndPoint(channel.NetworkAddressFamily, OutputStreamType.Play); var enc_channel_name = Uri.EscapeDataString(channel.ChannelInfo.Name); var uptime = (int)channel.Uptime.TotalMinutes; var columns = new string[] { channel.ChannelInfo.Name, //1 CHANNEL_NAME チャンネル名 channel.ChannelID.ToString("N").ToUpperInvariant(), //2 ID ID ユニーク値16進数32桁、制限チャンネルは全て0埋め endpoint.ToString(), //3 TIP TIP ポートも含む。Push配信時はブランク、制限チャンネルは127.0.0.1 channel.ChannelInfo.URL, //4 CONTACT_URL コンタクトURL 基本的にURL、任意の文字列も可 CONTACT_URL channel.ChannelInfo.Genre, //5 GENRE ジャンル channel.ChannelInfo.Desc, //6 DETAIL 詳細 channel.TotalDirects.ToString(), //7 LISTENER_NUM Listener数 -1は非表示、-1未満はサーバのメッセージ。ブランクもあるかも channel.TotalRelays.ToString(), //8 RELAY_NUM Relay数 同上 channel.ChannelInfo.Bitrate.ToString(), //9 BITRATE Bitrate 単位は kbps channel.ChannelInfo.ContentType, //10 TYPE Type たぶん大文字 channel.ChannelTrack.Creator, //11 TRACK_ARTIST トラック アーティスト channel.ChannelTrack.Album, //12 TRACK_ALBUM トラック アルバム channel.ChannelTrack.Name, //13 TRACK_TITLE トラック タイトル channel.ChannelTrack.URL, //14 TRACK_CONTACT_URL トラック コンタクトURL 基本的にURL、任意の文字列も可 enc_channel_name, //15 ENC_CHANNEL_NAME エンコード済みチャンネル名 URLエンコード(UTF-8) $"{uptime/60}:{uptime%60:D2}", //16 BROADCAST_TIME 配信時間 000〜99999 "", //17 STATUS ステータス 特殊なステータス disconnectしばらく情報の更新が無い、port0Push配信 又はアイコン channel.ChannelInfo.Comment, //18 COMMENT コメント "0", //19 DIRECT ダイレクトの有無 0固定 }.Select(str => { str = System.Text.RegularExpressions.Regex.Replace(str, "&", "&"); str = System.Text.RegularExpressions.Regex.Replace(str, "<", "<"); str = System.Text.RegularExpressions.Regex.Replace(str, ">", ">"); return(str); }); return(String.Join("<>", columns)); }
private JObject GetStatus() { var res = new JObject(); res["uptime"] = (int)PeerCast.Uptime.TotalSeconds; res["isFirewalled"] = PeerCast.IsFirewalled; var endpoint = PeerCast.GetGlobalEndPoint( System.Net.Sockets.AddressFamily.InterNetwork, Core.OutputStreamType.Relay); res["globalRelayEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null; endpoint = PeerCast.GetGlobalEndPoint( System.Net.Sockets.AddressFamily.InterNetwork, Core.OutputStreamType.Play); res["globalDirectEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null; endpoint = PeerCast.GetLocalEndPoint( System.Net.Sockets.AddressFamily.InterNetwork, Core.OutputStreamType.Relay); res["localRelayEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null; endpoint = PeerCast.GetLocalEndPoint( System.Net.Sockets.AddressFamily.InterNetwork, Core.OutputStreamType.Play); res["localDirectEndPoint"] = endpoint != null ? new JArray(endpoint.Address.ToString(), endpoint.Port) : null; return(res); }
/// <summary> /// 現在のチャンネルとPeerCastの状態からHostパケットを作ります /// </summary> /// <returns>作ったPCP_HOSTパケット</returns> public virtual Atom CreateHostPacket() { var host = new AtomCollection(); host.SetHostChannelID(Channel.ChannelID); host.SetHostSessionID(PeerCast.SessionID); var globalendpoint = PeerCast.GetGlobalEndPoint( RemoteEndPoint.AddressFamily, OutputStreamType.Relay); if (globalendpoint != null) { host.AddHostIP(globalendpoint.Address); host.AddHostPort(globalendpoint.Port); } var localendpoint = PeerCast.GetLocalEndPoint( RemoteEndPoint.AddressFamily, OutputStreamType.Relay); if (localendpoint != null) { host.AddHostIP(localendpoint.Address); host.AddHostPort(localendpoint.Port); } host.SetHostNumListeners(Channel.LocalDirects); host.SetHostNumRelays(Channel.LocalRelays); host.SetHostUptime(Channel.Uptime); if (Channel.Contents.Count > 0) { host.SetHostOldPos((uint)(Channel.Contents.Oldest.Position & 0xFFFFFFFFU)); host.SetHostNewPos((uint)(Channel.Contents.Newest.Position & 0xFFFFFFFFU)); } host.SetHostVersion(PCP_VERSION); host.SetHostVersionVP(PCP_VERSION_VP); host.SetHostFlags1( (PeerCast.AccessController.IsChannelRelayable(Channel) ? PCPHostFlags1.Relay : 0) | (PeerCast.AccessController.IsChannelPlayable(Channel) ? PCPHostFlags1.Direct : 0) | ((!PeerCast.IsFirewalled.HasValue || PeerCast.IsFirewalled.Value) ? PCPHostFlags1.Firewalled : 0) | (RecvRate > 0 ? PCPHostFlags1.Receiving : 0)); host.SetHostUphostIP(RemoteEndPoint.Address); host.SetHostUphostPort(RemoteEndPoint.Port); return(new Atom(Atom.PCP_HOST, host)); }
/// <summary> /// 現在のチャンネルとPeerCastの状態からHostパケットを作ります /// </summary> /// <returns>作ったPCP_HOSTパケット</returns> private Atom CreatePCPHOST() { var host = new AtomCollection(); host.SetHostChannelID(Channel.ChannelID); host.SetHostSessionID(PeerCast.SessionID); var globalendpoint = PeerCast.GetGlobalEndPoint( connection.RemoteEndPoint.AddressFamily, OutputStreamType.Relay); if (globalendpoint != null) { host.AddHostIP(globalendpoint.Address); host.AddHostPort(globalendpoint.Port); } var localendpoint = PeerCast.GetLocalEndPoint( connection.RemoteEndPoint.AddressFamily, OutputStreamType.Relay); if (localendpoint != null) { host.AddHostIP(localendpoint.Address); host.AddHostPort(localendpoint.Port); } host.SetHostNumListeners(Channel.LocalDirects); host.SetHostNumRelays(Channel.LocalRelays); host.SetHostUptime(Channel.Uptime); if (Channel.Contents.Count > 0) { host.SetHostOldPos((uint)(Channel.Contents.Oldest.Position & 0xFFFFFFFFU)); host.SetHostNewPos((uint)(Channel.Contents.Newest.Position & 0xFFFFFFFFU)); } PCPVersion.SetHostVersion(host); host.SetHostFlags1( (PeerCast.AccessController.IsChannelRelayable(Channel) ? PCPHostFlags1.Relay : 0) | (PeerCast.AccessController.IsChannelPlayable(Channel) ? PCPHostFlags1.Direct : 0) | ((PeerCast.GetPortStatus(connection.RemoteEndPoint.AddressFamily) != PortStatus.Open) ? PCPHostFlags1.Firewalled : 0) | (RecvRate > 0 ? PCPHostFlags1.Receiving : 0)); host.SetHostUphostIP(connection.RemoteEndPoint.Address); host.SetHostUphostPort(connection.RemoteEndPoint.Port); return(new Atom(Atom.PCP_HOST, host)); }
private void PostHostInfo(AtomCollection parent, Channel channel, bool playing) { var hostinfo = new AtomCollection(); hostinfo.SetHostChannelID(channel.ChannelID); hostinfo.SetHostSessionID(PeerCast.SessionID); var globalendpoint = PeerCast.GetGlobalEndPoint(AddressFamily.InterNetwork, OutputStreamType.Relay); if (globalendpoint != null) { hostinfo.AddHostIP(globalendpoint.Address); hostinfo.AddHostPort(globalendpoint.Port); } var localendpoint = PeerCast.GetLocalEndPoint(AddressFamily.InterNetwork, OutputStreamType.Relay); if (localendpoint != null) { hostinfo.AddHostIP(localendpoint.Address); hostinfo.AddHostPort(localendpoint.Port); } hostinfo.SetHostNumListeners(channel.TotalDirects); hostinfo.SetHostNumRelays(channel.TotalRelays); hostinfo.SetHostUptime(channel.Uptime); if (channel.Contents.Count > 0) { hostinfo.SetHostOldPos((uint)(channel.Contents.Oldest.Position & 0xFFFFFFFFU)); hostinfo.SetHostNewPos((uint)(channel.Contents.Newest.Position & 0xFFFFFFFFU)); } PCPVersion.SetHostVersion(hostinfo); var relayable = PeerCast.AccessController.IsChannelRelayable(channel); var playable = PeerCast.AccessController.IsChannelPlayable(channel) && PeerCast.FindListener(remoteEndPoint.Address, OutputStreamType.Play) != null; var firewalled = !PeerCast.IsFirewalled.HasValue || PeerCast.IsFirewalled.Value || PeerCast.FindListener(remoteEndPoint.Address, OutputStreamType.Relay) == null; var receiving = playing && channel.Status == SourceStreamStatus.Receiving; hostinfo.SetHostFlags1( (relayable ? PCPHostFlags1.Relay : 0) | (playable ? PCPHostFlags1.Direct : 0) | (firewalled ? PCPHostFlags1.Firewalled : 0) | PCPHostFlags1.Tracker | (receiving ? PCPHostFlags1.Receiving : PCPHostFlags1.None)); parent.SetHost(hostinfo); }