Advertisement
pcgod

Untitled

Mar 26th, 2011
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.IO.Pipes;
  4. using System.Net;
  5. using System.Net.Sockets;
  6. using System.Xml;
  7. #if __MonoCS__
  8. using Mono.Unix;
  9. #endif
  10.  
  11. namespace Mumble {
  12.     public class Mumble {
  13.         protected NamedPipeClientStream pipe;
  14.         protected StreamReader sr;
  15.         protected StreamWriter sw;
  16.  
  17.         public Mumble() {
  18. #if __MonoCS__
  19.             Socket s = new Socket(AddressFamily.Unix, SocketType.Stream, 0);
  20.             UnixEndPoint ue = new UnixEndPoint(Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/.MumbleSocket");
  21.             s.Connect(ue);
  22.             NetworkStream pipe = new NetworkStream(s);
  23. #else
  24.             pipe = new NamedPipeClientStream("Mumble");
  25.             pipe.Connect();
  26. #endif
  27.  
  28.             sr = new StreamReader(pipe);
  29.             sw = new StreamWriter(pipe);
  30.         }
  31.  
  32.         private bool OutputStringReply() {
  33.             String line;
  34.             while ((line = sr.ReadLine()) != "") {
  35.                 Console.WriteLine(line);
  36.             }
  37.             return true;
  38.         }
  39.  
  40.         private bool ReadReply() {
  41.             bool reply;
  42.             using (XmlReader xr = XmlReader.Create(sr)) {
  43.                 xr.MoveToContent();
  44.                 xr.ReadToDescendant("succeeded");
  45.                 reply = xr.ReadElementContentAsBoolean();
  46.             }
  47.             return reply;
  48.         }
  49.  
  50.         public bool Mute(bool state) {
  51.             sw.WriteLine("<self mute='{0}' />", state);
  52.             sw.Flush();
  53.  
  54.             return ReadReply();
  55.         }
  56.  
  57.         public bool Deaf(bool state) {
  58.             sw.WriteLine("<self deaf='{0}' />", state);
  59.             sw.Flush();
  60.  
  61.             return ReadReply();
  62.         }
  63.  
  64.         public bool Focus() {
  65.             sw.WriteLine("<focus />");
  66.             sw.Flush();
  67.  
  68.             return ReadReply();
  69.         }
  70.  
  71.         public bool OpenUrl(String url) {
  72.             Uri u;
  73.             Uri.TryCreate(url, UriKind.Absolute, out u);
  74.             sw.WriteLine("<url><href>{0}</href></url>", u);
  75.             sw.Flush();
  76.  
  77.             return ReadReply();
  78.         }
  79.  
  80.         public String QueryUrl() {
  81.             sw.WriteLine("<url />");
  82.             sw.Flush();
  83.  
  84.             String reply;
  85.             using (XmlReader xr = XmlReader.Create(sr)) {
  86.                 xr.MoveToContent();
  87.                 xr.ReadToDescendant("href");
  88.                 reply = xr.ReadString();
  89.             }
  90.             return reply;
  91.         }
  92.  
  93. /*
  94.         public static void Main(String[] args) {
  95.             Mumble m = new Mumble();
  96.             m.Deaf(true);
  97.         }
  98.  
  99. */
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement