Ejemplo n.º 1
0
 private static void EndOpenChat(IAsyncResult res)
 {
     try
     {
         chatRoom = session.EndOpenChat(res);
         chatRoom.Client.MessageReceived += Room_Client_MessageReceived;
         chatRoom.Room.UserStateChanged += Room_UserStateChanged;
         Console.WriteLine("Write '" + "start bot" + "' in the Console to start the bot");
         while (true)
         {
             string ln = Console.ReadLine();
             if (ln == "exit")
             {
                 run = false;
                 break;
             }
             else if(ln == "start bot")
             {
                 isStarted = true;
                 stopWatch.Start();
             }
             chatRoom.Room.SendMessage(ln);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 2
0
 private void EndOpenChat(IAsyncResult res)
 {
     room = session.EndOpenChat (res);
     if (room == null) {
         MessageBox.Show ("Error occured while connecting to chat!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Application.Exit ();
         return;
     }
     room.Client.MessageReceived += Room_Client_MessageReceived;
     CreateForm ();
 }
Ejemplo n.º 3
0
		private static void EndOpenChat(IAsyncResult res)
		{
			try{
			Livecoding.ChatRoom room = session.EndOpenChat (res);
			room.Client.MessageReceived += Room_Client_MessageReceived;;
			while (true) {
				string ln=Console.ReadLine ();
				if (ln == "exit") {
					run=false;
					break;
				}
				room.Room.SendMessage (ln);
			}
			}catch(Exception ex) {
				Console.WriteLine (ex.Message);
			}
		}
Ejemplo n.º 4
0
        private ChatRoom OpenChat(string room)
        {
            string url = PAGE+ "chat/" + room + "/";
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create (url);
            req.UserAgent = UserAgent;
            req.CookieContainer = cookies;
            HttpWebResponse response = (HttpWebResponse)req.GetResponse ();
            if (response.StatusCode == HttpStatusCode.OK) {
                ChatRoom chatRoom = new ChatRoom (this,room);
                using (System.IO.StreamReader sr = new System.IO.StreamReader (response.GetResponseStream ())) {
                    string data = sr.ReadToEnd ();
                    int fInd = data.IndexOf ("window.Chat.init(");
                    //Console.WriteLine (data);
                    if (fInd == -1)
                        return null;
                    Console.WriteLine ("Found start");
                    fInd += "window.Chat.init(".Length;
                    int eInd = data.IndexOf (");", fInd);
                    if (eInd == -1)
                        return null;
                    Console.WriteLine ("Found end");
                    string json = data.Substring (fInd, eInd - fInd - 1);
                    fInd = data.IndexOf ("window.Chat.connect(", eInd);
                    if (fInd == -1)
                        return null;
                    eInd = data.IndexOf (");", fInd);
                    if (eInd == -1)
                        return null;//TODO: exception trowing?
                    string tmp = data.Substring (fInd, eInd - fInd - 1);
                    tmp = tmp.Split (',') [1];
                    tmp = tmp.Split (':') [1].Trim ().Replace ("\"", "");
                    chatRoom.Load (json, tmp);

                }
                chatRoom.Login ();
                return chatRoom;
            }
            Console.WriteLine ("Not OK");
            return null;
        }