Hello all c# experts.
I am making a college project on jabber in c#.
I was making a jabber bot to clear affiliations in jabber chatrooms.I took a reference from a Bot who can Clear Banned users only.
I modified it to clear members,moderators and owners by separate controls instead of just banned affiliations.
The problem i am facing is with timers.
Here is the complete code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using agsXMPP;
using agsXMPP.Xml.Dom;
namespace ZEDBUZZ_BAN_LIST_REMOVED
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] ban, mem, admin, owner;
XmppClientConnection CoderBoyz = new XmppClientConnection();
private void button1_Click(object sender, EventArgs e)
{
CoderBoyz.Server = "nimbuzz.com";
CoderBoyz.ConnectServer = "o.nimbuzz.com";
CoderBoyz.Open(textBox1.Text, textBox2.Text, "Nimbuzz_MIDP761254");
CoderBoyz.OnLogin += connected;
CoderBoyz.OnAuthError += failed;
CoderBoyz.OnError += error;
CoderBoyz.OnClose += dc;
CoderBoyz.OnReadXml += new XmlHandler(XmlReadban);
CoderBoyz.OnReadXml += new XmlHandler(XmlReadmem);
CoderBoyz.OnReadXml += new XmlHandler(XmlReadadmin);
CoderBoyz.OnReadXml += new XmlHandler(XmlReadowner);
}
public void connected(object sender)
{
if (base.InvokeRequired == true)
{
base.BeginInvoke(new ObjectHandler(connected), new object[] { sender });
}
else
{
textBox1.BackColor = Color.Green;
textBox2.BackColor = Color.Green;
}
}
public void failed(object sender, Element e)
{
if (base.InvokeRequired == true)
{
base.BeginInvoke(new XmppElementHandler(failed), new object[] { sender, e });
}
else
{
textBox1.BackColor = Color.Red;
textBox2.BackColor = Color.Red;
timer1.Stop();
timer2.Stop();
timer3.Stop();
timer4.Stop();
timer5.Stop();
timer6.Stop();
timer7.Stop();
timer8.Stop();
timer9.Stop();
timer10.Stop();
timer11.Stop();
timer12.Stop();
}
}
public void error(object sender, Exception ex)
{
if (base.InvokeRequired)
{
base.BeginInvoke(new ErrorHandler(error), new object[] { sender, ex });
}
else
{
textBox1.BackColor = Color.Red;
textBox2.BackColor = Color.Red;
timer1.Stop();
timer2.Stop();
timer3.Stop();
timer4.Stop();
timer5.Stop();
timer6.Stop();
timer7.Stop();
timer8.Stop();
timer9.Stop();
timer10.Stop();
timer11.Stop();
timer12.Stop();
}
}
public void dc(object sender)
{
if (base.InvokeRequired == true)
{
base.BeginInvoke(new ObjectHandler(dc), new object[] { sender });
}
else
{
textBox1.BackColor = Color.Red;
textBox2.BackColor = Color.Red;
timer1.Stop();
timer2.Stop();
timer3.Stop();
timer4.Stop();
timer5.Stop();
timer6.Stop();
timer7.Stop();
timer8.Stop();
timer9.Stop();
timer10.Stop();
timer11.Stop();
timer12.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
timer2.Stop();
timer3.Stop();
timer4.Stop();
timer5.Stop();
timer6.Stop();
timer7.Stop();
timer8.Stop();
timer9.Stop();
timer10.Stop();
timer11.Stop();
timer12.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
CoderBoyz.Send("<iq type='get' to='" + textBox3.Text + "@conference.nimbuzz.com' id='qip_1026'><query xmlns='http://jabber.org/protocol/muc#admin'><item affiliation='outcast' /></query></iq>");
}
public void XmlReadban(object sender, string xml)
{
if (base.InvokeRequired)
{
base.BeginInvoke(new XmlHandler(XmlReadban), new object[] { sender, xml });
}
else
{
try
{
xml = xml.Replace("\"", "'");
try
{
if (xml.IndexOf("<query xmlns='http://jabber.org/protocol/muc#admin'>") >= 0)
{
if (xml.IndexOf("affiliation='outcast'") >= 0)
{
xml = xml.Substring(xml.IndexOf("<item jid='") + 11);
xml = xml.Replace("' affiliation='outcast' /></query></iq>", "").Replace("' affiliation='outcast' />", "");
xml = xml.Replace("role='participant' />", "");
ban = Microsoft.VisualBasic.Strings.Split(xml, "<item jid='", -1, Microsoft.VisualBasic.CompareMethod.Binary);
{
for (var t = ban.GetLowerBound(0); t <= ban.GetUpperBound(0); t++)
{
listBox1.Items.Add(ban[t]);
groupBox3.Text = "√" + listBox1.Items.Count + "√:BANNED";
}
}
}
}
}
catch { }
}
catch { }
}
}
private void timer1_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox1.Items)
{
try
{
CoderBoyz.Send("<iq type='set' to='" + textBox3.Text + "@conference.nimbuzz.com'><query xmlns='http://jabber.org/protocol/muc#admin'><item jid='" + textBox4.Text + "' affiliation='none'/></query></iq>");
}
catch { }
}
}
private void timer2_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox1.Items)
{
try
{
textBox4.Text = current.ToString();
}
catch { }
}
}
private void timer3_Tick(object sender, EventArgs e)
{
listBox1.Items.Remove(textBox4.Text);
}
private void button4_Click(object sender, EventArgs e)
{
timer1.Start();
timer1.Interval = 4000;
timer2.Start();
timer2.Interval = 4000;
timer3.Start();
timer3.Interval = 4000;
}
private void button8_Click(object sender, EventArgs e)
{
CoderBoyz.Send("<iq type='get' to='" + textBox3.Text + "@conference.nimbuzz.com' id='qip_1026'><query xmlns='http://jabber.org/protocol/muc#admin'><item affiliation='member' /></query></iq>");
}
public void XmlReadmem(object sender, string xml)
{
if (base.InvokeRequired)
{
base.BeginInvoke(new XmlHandler(XmlReadmem), new object[] { sender, xml });
}
else
{
try
{
xml = xml.Replace("\"", "'");
try
{
if (xml.IndexOf("<query xmlns='http://jabber.org/protocol/muc#admin'>") >= 0)
{
if (xml.IndexOf("affiliation='member'") >= 0)
{
xml = xml.Substring(xml.IndexOf("<item jid='") + 11);
xml = xml.Replace("' affiliation='member' /></query></iq>", "").Replace("' affiliation='member' />", "");
xml = xml.Replace("role='participant' />", "");
mem = Microsoft.VisualBasic.Strings.Split(xml, "<item jid='", -1, Microsoft.VisualBasic.CompareMethod.Binary);
{
for (var i = mem.GetLowerBound(0); i <= mem.GetUpperBound(0); i++)
{
listBox1.Items.Add(mem[i]);
groupBox3.Text = "√" + listBox2.Items.Count + "√:MEMBERS";
}
}
}
}
}
catch { }
}
catch { }
}
}
private void timer4_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox2.Items)
{
try
{
CoderBoyz.Send("<iq type='set' to='" + textBox6.Text + "@conference.nimbuzz.com'><query xmlns='http://jabber.org/protocol/muc#admin'><item jid='" + textBox6.Text + "' affiliation='none'/></query></iq>");
}
catch { }
}
}
private void timer5_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox2.Items)
{
try
{
textBox6.Text = current.ToString();
}
catch { }
}
}
private void timer6_Tick(object sender, EventArgs e)
{
listBox2.Items.Remove(textBox6.Text);
}
private void button5_Click(object sender, EventArgs e)
{
Timer4.Start();
Timer4.Interval = 4000;
Timer5.Start();
Timer5.Interval = 4000;
Timer6.Start();
Timer6.Interval = 4000; }
private void button9_Click(object sender, EventArgs e)
{
CoderBoyz.Send("<iq type='get' to='" + textBox3.Text + "@conference.nimbuzz.com' id='qip_1026'><query xmlns='http://jabber.org/protocol/muc#admin'><item affiliation='admin' /></query></iq>");
}
public void XmlReadadmin(object sender, string xml)
{
if (base.InvokeRequired)
{
base.BeginInvoke(new XmlHandler(XmlReadadmin), new object[] { sender, xml });
}
else
{
try
{
xml = xml.Replace("\"", "'");
try
{
if (xml.IndexOf("<query xmlns='http://jabber.org/protocol/muc#admin'>") >= 0)
{
if (xml.IndexOf("affiliation='admin'") >= 0)
{
xml = xml.Substring(xml.IndexOf("<item jid='") + 11);
xml = xml.Replace("' affiliation='admin' /></query></iq>", "").Replace("' affiliation='admin' />", "");
xml = xml.Replace("role='participant' />", "");
admin = Microsoft.VisualBasic.Strings.Split(xml, "<item jid='", -1, Microsoft.VisualBasic.CompareMethod.Binary);
{
for (var f = admin.GetLowerBound(0); f <= admin.GetUpperBound(0); f++)
{
listBox3.Items.Add(admin[f]);
groupBox3.Text = "√" + listBox1.Items.Count + "√:ADMINS";
}
}
}
}
}
catch { }
}
catch { }
}
}
private void timer7_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox3.Items)
{
try
{
CoderBoyz.Send("<iq type='set' to='" + textBox3.Text + "@conference.nimbuzz.com'><query xmlns='http://jabber.org/protocol/muc#admin'><item jid='" + textBox7.Text + "' affiliation='none'/></query></iq>");
}
catch { }
}
}
private void timer8_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox3.Items)
{
try
{
textBox7.Text = current.ToString();
}
catch { }
}
}
private void timer9_Tick(object sender, EventArgs e)
{
listBox3.Items.Remove(textBox7.Text);
}
private void button6_Click(object sender, EventArgs e)
{
Timer7.Start();
Timer7.Interval = 4000;
Timer8.Start();
Timer8.Interval = 4000;
Timer9.Start();
Timer9.Interval = 4000;
}
private void button10_Click(object sender, EventArgs e)
{
CoderBoyz.Send("<iq type='get' to='" + textBox3.Text + "@conference.nimbuzz.com' id='qip_1026'><query xmlns='http://jabber.org/protocol/muc#admin'><item affiliation='owner' /></query></iq>");
}
public void XmlReadowner(object sender, string xml)
{
if (base.InvokeRequired)
{
base.BeginInvoke(new XmlHandler(XmlReadowner), new object[] { sender, xml });
}
else
{
try
{
xml = xml.Replace("\"", "'");
try
{
if (xml.IndexOf("<query xmlns='http://jabber.org/protocol/muc#admin'>") >= 0)
{
if (xml.IndexOf("affiliation='owner'") >= 0)
{
xml = xml.Substring(xml.IndexOf("<item jid='") + 11);
xml = xml.Replace("' affiliation='owner' /></query></iq>", "").Replace("' affiliation='owner' />", "");
xml = xml.Replace("role='participant' />", "");
owner = Microsoft.VisualBasic.Strings.Split(xml, "<item jid='", -1, Microsoft.VisualBasic.CompareMethod.Binary);
{
for (var d = owner.GetLowerBound(0); d <= owner.GetUpperBound(0); d++)
{
listBox4.Items.Add(owner[d]);
groupBox3.Text = "√" + listBox1.Items.Count + "√:OWNERS";
}
}
}
}
}
catch { }
}
catch { }
}
}
private void timer10_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox4.Items)
{
try
{
CoderBoyz.Send("<iq type='set' to='" + textBox3.Text + "@conference.nimbuzz.com'><query xmlns='http://jabber.org/protocol/muc#admin'><item jid='" + textBox8.Text + "' affiliation='none'/></query></iq>");
}
catch { }
}
}
private void timer11_Tick(object sender, EventArgs e)
{
foreach (object current in this.listBox4.Items)
{
try
{
textBox8.Text = current.ToString();
}
catch { }
}
}
private void timer12_Tick(object sender, EventArgs e)
{
listBox4.Items.Remove(textBox8.Text);
}
private void button7_Click(object sender, EventArgs e)
{
timer10.Start();
timer10.Interval = 4000;
timer11.Start();
timer11.Interval = 4000;
timer12.Start();
timer12.Interval = 4000;
}
}
}
---------------------end------------------------
The underlined are the errors that i am getting.