示例#1
0
        private void tReadSock_Tick(object sender, EventArgs e)
        {
            if (Sck.Connected == false)
            {
                return;
            }
            if (sckRecvCB != null)
            {
                return;
            }
            sckPacket pck = new sckPacket(Sck);

            sckRecvCB = new AsyncCallback(sckRecv);
            Sck.BeginReceive(pck.buf, 0, pck.buf.Length, SocketFlags.None, sckRecvCB, pck);
        }
示例#2
0
        private void sckRecv(IAsyncResult prm)
        {
            sckPacket pck = (sckPacket)prm.AsyncState; sckRecvCB = null;
            string    l   = Byte2Str(pck.buf); //Log(l);

            for (int a = 0; a < 6; a++)
            {
                if (l.Substring(l.Length - 1) == "\r")
                {
                    l = l.Substring(0, l.Length - 1);
                }
                if (l.Substring(l.Length - 1) == "\n")
                {
                    l = l.Substring(0, l.Length - 1);
                }
            }
            if (l.IndexOf("PING :") != -1)
            {
                string tmp = Split(Split(l, "PING :", 1), "\r\n", 0);
                SckSend("PONG " + tmp);
                Log("Ping (" + tmp + ")");
            }
            if (l.IndexOf(" MODE " + Nick + " ") != -1)
            {
                SckSend("JOIN #" + txtChan.Text);
                Log("Joining #" + txtChan.Text + "...");
            }
            if (l.IndexOf(Nick + " #" + Chan + " :End of /NAMES list.") != -1)
            {
                Log("Connection established.");
            }
            if (l.IndexOf(" JOIN #" + Chan) != -1)
            {
                string sNick = l.Substring(1);
                sNick = sNick.Substring(0, sNick.IndexOf("!~"));
                SckSend(Pre + "Good evening, " + sNick + ".");
            }
            if (l.IndexOf(Pre) != -1)
            {
                l = Split(l, Pre, 1);
                string ll = l.ToLower();
                if (ll.Length >= 7)
                {
                    if (ll.Substring(0, 7) == "!learn ")
                    {
                        l = l.Substring(7);
                        if (l.IndexOf(" == ") != -1)
                        {
                            string LearnCall = Split(l, " == ", 0).ToLower();
                            string LearnVal  = Split(l, " == ", 1);
                            if ((LearnCall == "toxirc") || (LearnCall == "url") ||
                                (LearnCall == "forum"))
                            {
                                SckSend(Pre + "Not permitted.");
                                Log("Illegal definition attempt");
                            }
                            else
                            {
                                if (LearnDB.IndexOf("\r\n" + LearnCall + " == ") != -1)
                                {
                                    string LearnDB1 = Split(LearnDB, "\r\n" + LearnCall + " == ", 0);
                                    string LearnDB2 = Split(LearnDB, "\r\n" + LearnCall + " == ", 1);
                                    LearnDB2 = LearnDB2.Substring(LearnDB2.IndexOf("\r\n"));
                                    LearnDB  = LearnDB1 + LearnDB2;
                                }
                                LearnDB += LearnCall + " == " + LearnVal + "\r\n";
                                //SckSend(Pre + "Action completed.");
                                FileWrite("learndb.txt", LearnDB);
                                Log("Defined " + LearnCall);
                            }
                        }
                        else
                        {
                            SckSend(Pre + "Parameter missing!");
                            Log("Definition failed.");
                        }
                    }
                }
                if (ll.Length >= 1)
                {
                    if (ll.Substring(0, 1) == "?")
                    {
                        string FetchCall = l.Substring(1).ToLower(), FetchVal;
                        if (LearnDB.IndexOf("\r\n" + FetchCall + " == ") != -1)
                        {
                            FetchVal = Split(Split(LearnDB, "\r\n" + FetchCall + " == ", 1), "\r\n", 0);
                            SckSend(Pre + FetchCall + " >> " + FetchVal);
                            Log("  Read " + FetchCall);
                        }
                        else
                        {
                            SckSend(Pre + "I have no definition for <" + FetchCall + ">");
                            Log("-Read " + FetchCall);
                        }
                    }
                }
            }
        }