Пример #1
0
        // Format for command procedures:
        // private static void Cmd<cmdname>(string sender, string command, string[] parameters, mcPage page) { code... }

        #region "Numerics"
        #region "000 Series"
        private static void Cmd001(string prefix, string command, string[] parameters, mcPage page)
        {
            string[] userhost;
            //<- :devel.rburchell.org 001 w-mirc :Welcome to the Symmetic IRC Network [email protected]
            page.Server.ServerName             = prefix;                 /* this is a good time to find the real name */
            page.Server.ServerPage.MyNode.Text = page.Server.ServerName;
            page.Server.ServerPage.Text        = page.Server.ServerName; /* and make sure the node matches 8) */
            //split param 3 to get network name..
            userhost = parameters[1].Split(' ');

            if (System.IO.File.Exists(".\\networks\\" + userhost[3] + "\\network.dat"))
            {
                page.MessageInfo("Network " + userhost[3] + " is a known network.");
                /* We have a networks file. */
                mcNetwork NewNetwork = mcNetwork.GetNetwork(userhost[3]);
                page.Server.IRCSend("NICK " + NewNetwork.Nickname);
                /* assume that user/real is already valid. */
                //todo: add this to the list of servers?
                //page.Server.ServerSocket.RemoteHost
                foreach (string str in NewNetwork.Perform)
                {
                    if (str[0] != '#')
                    {
                        /* the "P" is stripped automagically */
                        page.MessageInfo("Doing PERFORM " + str);
                        page.Server.IRCSend(str);
                    }
                }
            }
            else
            {
                page.MessageInfo("Network " + userhost[3] + " is not a known network.");
            }
        }
Пример #2
0
        /*
         * saves a network object to disk.
         * really i could have implemented this as object serialisation,
         * but i can learn that later and do it then.
         */
        public static int SaveNetwork(mcNetwork aNetwork)
        {
            System.IO.StreamWriter fd;
            // string line; // Commented so C# will stfu.

            try
            {
                fd = new System.IO.StreamWriter("networks\\" + aNetwork.NetworkName + "\\network.dat");
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occured while trying to write network file " + aNetwork.NetworkName + ": " + ex.ToString(), "Error!");
                return 0;
            }

            try
            {
                fd.WriteLine("N {0}", aNetwork.Nickname);
                fd.WriteLine("U {0}", aNetwork.Username);
                fd.WriteLine("R {0}", aNetwork.Realname);
                if (aNetwork.ConnectOnStartup) fd.WriteLine("s");
                foreach (string server in aNetwork.Servers)
                {
                    fd.WriteLine("S {0}", server);
                }
                foreach (string line in aNetwork.Perform)
                {
                    if (line[0] == '#')
                    {
                        // Just as C programmers never printf(string), we never
                        // write the string directly either.
                        fd.WriteLine("{0}", line);
                    }
                    else
                    {
                        fd.WriteLine("P {0}", line);
                    }
                }
                foreach (string buddy in aNetwork.Buddies)
                {
                    fd.Write("B {0}", buddy);
                }
            }
            finally
            {
                fd.Close();
            }

            return 0;
        }
Пример #3
0
        /* Parses a network file, and returns a mcNetwork network object. */
        public static mcNetwork GetNetwork(string NetworkName)
        {
            mcNetwork NewNetwork = new mcNetwork();
            System.IO.StreamReader fd;
            string line;
            string temp;
            string[] parts;

            try
            {
                fd = new System.IO.StreamReader("networks\\" + NetworkName + "\\network.dat");
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occured while trying to read network " + NetworkName + ": " + ex.ToString(), "Error!");
                return null;
            }

            NewNetwork.NetworkName = NetworkName;

            try
            {
                while (true)
                {
                    /* no, this does actually end ;) */
                    line = fd.ReadLine();
                    if (line == null)
                        break;

                    parts = line.Split(' ');

                    switch (line[0])
                    {
                        case 'N':
                            /* nickname token */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'N' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Nickname = parts[1];
                            break;
                        case 'U':
                            /* username token */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'U' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Username = parts[1];
                            break;
                        case 'R':
                            /* realname token */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'R' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Realname = String.Join(" ", parts, 1, parts.Length - 1);
                            break;
                        case 's':
                            /* connect on startup */
                            /* optional token- if it's here, we're supposed to connect on startup. */
                            NewNetwork.ConnectOnStartup = true;
                            break;
                        case 'S':
                            /* a server/port combination */
                            NewNetwork.Servers.Add(parts[1]);
                            break;
                        case '#':
                            /* perform comment */
                            NewNetwork.Perform.Add(line);
                            break;
                        case 'P':
                            /* perform line */
                            temp = String.Join(" ", parts, 1, parts.Length - 1);
                            NewNetwork.Perform.Add(temp);
                            break;
                        case 'B':
                            /* buddy line */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'U' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Buddies.Add(parts[1]);
                            break;
                    }
                }
                return NewNetwork;
            }
            finally
            {
                fd.Close();
            }
        }
Пример #4
0
        /*
         * saves a network object to disk.
         * really i could have implemented this as object serialisation,
         * but i can learn that later and do it then.
         */
        public static int SaveNetwork(mcNetwork aNetwork)
        {
            System.IO.StreamWriter fd;
            // string line; // Commented so C# will stfu.

            try
            {
                fd = new System.IO.StreamWriter("networks\\" + aNetwork.NetworkName + "\\network.dat");
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occured while trying to write network file " + aNetwork.NetworkName + ": " + ex.ToString(), "Error!");
                return 0;
            }

            try
            {
                fd.WriteLine("N {0}", aNetwork.Nickname);
                fd.WriteLine("U {0}", aNetwork.Username);
                fd.WriteLine("R {0}", aNetwork.Realname);
                if (aNetwork.ConnectOnStartup) fd.WriteLine("s");
                foreach (string server in aNetwork.Servers)
                {
                    fd.WriteLine("S {0}", server);
                }
                foreach (string line in aNetwork.Perform)
                {
                    if (line[0] == '#')
                    {
                        // Just as C programmers never printf(string), we never
                        // write the string directly either.
                        fd.WriteLine("{0}", line);
                    }
                    else
                    {
                        fd.WriteLine("P {0}", line);
                    }
                }
                foreach (string buddy in aNetwork.Buddies)
                {
                    fd.Write("B {0}", buddy);
                }
            }
            finally
            {
                fd.Close();
            }

            return 0;
        }
Пример #5
0
        /* Parses a network file, and returns a mcNetwork network object. */
        public static mcNetwork GetNetwork(string NetworkName)
        {
            mcNetwork NewNetwork = new mcNetwork();
            System.IO.StreamReader fd;
            string line;
            string temp;
            string[] parts;

            try
            {
                fd = new System.IO.StreamReader("networks\\" + NetworkName + "\\network.dat");
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occured while trying to read network " + NetworkName + ": " + ex.ToString(), "Error!");
                return null;
            }

            NewNetwork.NetworkName = NetworkName;

            try
            {
                while (true)
                {
                    /* no, this does actually end ;) */
                    line = fd.ReadLine();
                    if (line == null)
                        break;

                    parts = line.Split(' ');

                    switch (line[0])
                    {
                        case 'N':
                            /* nickname token */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'N' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Nickname = parts[1];
                            break;
                        case 'U':
                            /* username token */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'U' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Username = parts[1];
                            break;
                        case 'R':
                            /* realname token */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'R' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Realname = String.Join(" ", parts, 1, parts.Length - 1);
                            break;
                        case 's':
                            /* connect on startup */
                            /* optional token- if it's here, we're supposed to connect on startup. */
                            NewNetwork.ConnectOnStartup = true;
                            break;
                        case 'S':
                            /* a server/port combination */
                            NewNetwork.Servers.Add(parts[1]);
                            break;
                        case '#':
                            /* perform comment */
                            NewNetwork.Perform.Add(line);
                            break;
                        case 'P':
                            /* perform line */
                            temp = String.Join(" ", parts, 1, parts.Length - 1);
                            NewNetwork.Perform.Add(temp);
                            break;
                        case 'B':
                            /* buddy line */
                            if (parts.Length < 2)
                            {
                                System.Windows.Forms.MessageBox.Show("Malformed 'U' token in network file " + NetworkName + ", aborting read effort.", "Error!");
                                return null;
                            }
                            NewNetwork.Buddies.Add(parts[1]);
                            break;
                    }
                }
                return NewNetwork;
            }
            finally
            {
                fd.Close();
            }
        }