Advertisement

08.17.2007 at 01:17PM PDT, ID: 22770759
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.2

Can anyone translate C, C++ into PERL?

Asked by dr34m3rs in Perl Programming Language, C Programming Language, C# Programming Language

Tags:

Ok this is fairly simple, but I don't know C++ so I am not sure the specifics here, hence why I am asking for help! I am fair with PERL and want this for a website, so PERL is perfect if anyone could help me with this...

This C / C++ code is from EveMON source code ( http://evemon.battleclinic.com/snaps/ ) file 2007-08-16_rev_1091.zip

All it does is connect to the EVE server to tell the server status and how many players are currently playing (should be simple right?)

I have tried this in PERL and have gotten to the point where I can connect to the server, but I am having trouble with the "encoding" and "decoding" of it all...

Here is the C / C++ snippet from path_to_local_source_/EVEMon.Common/EveServer.cs:

/// <summary>
        /// Called when we have data from TQ
        /// </summary>
        /// <param name="ar"></param>
        private void ConnectCallback(IAsyncResult ar)
        {
            TcpClient conn = (TcpClient)ar.AsyncState;
            if (ar.IsCompleted && conn.Connected)
            {
                m_status = Status.Online;
                try
                {
                    NetworkStream stream = conn.GetStream();
                    byte[] data = {0x23, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00,
                        0x00, 0x14, 0x06, 0x04, 0xE8, 0x99, 0x02, 0x00,
                        0x05, 0x8B, 0x00, 0x08, 0x0A, 0xCD, 0xCC, 0xCC,
                        0xCC, 0xCC, 0xCC, 0x00, 0x40, 0x05, 0x49, 0x0F,
                        0x10, 0x05, 0x42, 0x6C, 0x6F, 0x6F, 0x64};
                    stream.Write(data, 0, data.Length);
                    byte[] response = new byte[256];
                    int bytes = stream.Read(response, 0, 256);

                    m_users = 0;
                    if (bytes > 21)
                    {
                        // Amended usercount checks, info from clef on iRC
                        // [16:01] <clef> BradStone: for the moment, take that byte[19] ... if it is 1, 8 or 9, the usercount is 0.
                        // [16:01] <clef> BradStone: if it is 4, the next 32bit are the usercount. 5 -> 16bit. 6 -> 8bit.
                        int usersBytes = 4 - (response[19]-3);
                        if (usersBytes > 0 && usersBytes < 5)
                        {
                            int multiplyer = 1;
                            for (int i=0;i<usersBytes;i++)
                            {
                                m_users = response[20+i] * multiplyer;
                                multiplyer *= 256;
                            }
                        }
                    }

                    string str = new System.Text.ASCIIEncoding().GetString(response);

                    Match m = m_re.Match(str);
                    if (m.Success)
                    {
                        m_status = Status.Starting;
                        m_countdown = Convert.ToInt32(m.Groups[1].Value) - 1;
                        m_tmrCountdown.Enabled = true;
                    }
                    conn.EndConnect(ar);
                }
                catch (Exception)
                {
                    m_status = Status.Offline;
                    m_users = 0;
                }
            }
            else
            {
                m_status = Status.Offline;
                m_users = 0;
            }

            // Close the connection
            conn.Close();

            // Everything checked, lets see if we need to update something ...
            setInformationText();
            if (m_status != m_lastStatus)
            {
                if (ServerStatusChanged != null)
                {
                    ServerStatusChanged(m_instance, new EveServerEventArgs(m_balloonText, m_balloonIcon));
                }
                m_lastStatus = m_status;
            }
            if (ServerStatusUpdated != null)
            {
                ServerStatusUpdated(m_instance, new EveServerEventArgs(m_statusText));
            }

            // switch off the semaphore
            m_checkingServer = false;
        }

        private void checkServerStatus(object source, EventArgs e)
        {
            // Check the semaphore to see if we're mid check
            if (m_checkingServer == true)
            {
                return;
            }

            // check to see if we are recovering from loss of connection (timer was set to 30 seconds)
            if (m_tmrCheck.Interval == 30000)
            {
                // network is back - set timer to correct value.
                m_tmrCheck.Interval = m_settings.StatusUpdateInterval * 60000;
            }

            // check that we have a network connection
            if (!InternetCS.IsConnectedToInternet(m_settings.ConnectivityURL))
            {
               // switch on the semaphore
               m_checkingServer = true;

                // oops, we've lost the network - reset timer to 30 seconds
                m_tmrCheck.Interval = 30000;
                m_statusText = "// TQ Server Status Unknown";
                if (ServerStatusUpdated != null)
                {
                    ServerStatusUpdated(m_instance, new EveServerEventArgs(m_statusText));
                }
                // switch off the semaphore
                m_checkingServer = false;
                return;
            }

            TcpClient conn = new TcpClient();
            try
            {
                // Set default port and ip - also perform final validation
                int serverPort = 26000;
                System.Net.IPAddress serverAddress = System.Net.IPAddress.Parse("87.237.38.200");

                // If the user selected port is valid use that one, maybe they hand edited the xml file and bypassed input validation
                if (int.TryParse(m_settings.CustomTQPort, out serverPort) && System.Net.IPAddress.TryParse(m_settings.CustomTQAddress, out serverAddress))
                {
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        System.Diagnostics.Debug.WriteLine("DEBUG: TQ check connecting to [" + serverAddress.ToString() + ":" + serverPort.ToString() + "]");
                    }

                    conn.BeginConnect(serverAddress.ToString(), serverPort, ConnectCallback, conn);
                }
                else
                    throw new Exception("Invalid TQ server IP or port"); // Shouldn't ever get here
            }
            catch (Exception)
            {
                conn.Close();
                m_status = Status.Offline;
                m_users = 0;
                // switch off the semaphore - the check failed
                m_checkingServer = false;
            }
        }











My test seems to be hanging after the ->send(); which is why the eval statement is in there. I am not very experienced with socket programming so I'm sure it's something I'm missing...    My test code so far:

#!/usr/bin/perl

$host = "87.237.38.200";
$port = "26000";
$method = "tcp";

$|=1;
print "Connecting... \n\n";

@DATA = ("23", "00", "00", "00", "7E", "00", "00", "00",
                  "00", "14", "06", "04", "E8", "99", "02", "00",
                  "05", "8B", "00", "08", "0A", "CD", "CC", "CC",
                  "CC", "CC", "CC", "00", "40", "05", "49", "0F",
                  "10", "05", "42", "6C", "6F", "6F", "64");

use IO::Socket;
$remote = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "$host", PeerPort => "$port");

if($remote)
{
      $|=1;
      print "Connected to $host on port $port.\n\n";
      
      foreach $hex (@DATA)
      {
            chomp $hex;
            
            $hex =~ s/([a-fA-F0-9]{2})/chr(hex $1)/eg;
            
            $send .= $hex;
      }
      eval {
      $len = length($send);
      
      $remote->recv($buffer, 1000);
      
      $|=1;
      print "RECEIVED: $buffer\n\n";
      
      $remote->send($send, $len);
      
      $|=1;
      print "SENT: $send\n\n";
      
      $remote->recv($buffer, 1000);
      
      print "RECEIVED: $buffer\n\n";
      }; print $@ if $@;
}
else
{
      $|=1;
      print "Unable to connect to $host on port $port\n\n";
}

close($remote) or die "Unable to close remote";Start Free Trial
[+][-]08.17.2007 at 01:31PM PDT, ID: 19720101

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.17.2007 at 01:32PM PDT, ID: 19720108

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.17.2007 at 01:35PM PDT, ID: 19720141

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.17.2007 at 01:36PM PDT, ID: 19720152

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.17.2007 at 01:37PM PDT, ID: 19720156

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.18.2007 at 10:16AM PDT, ID: 19723092

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 07:30AM PDT, ID: 19730607

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 01:51PM PDT, ID: 19733635

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 01:53PM PDT, ID: 19733643

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 02:41PM PDT, ID: 19733965

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 02:44PM PDT, ID: 19733980

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 03:05PM PDT, ID: 19734142

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.20.2007 at 09:08PM PDT, ID: 19735472

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 02:00PM PDT, ID: 19741518

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 10:44PM PDT, ID: 19743880

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.22.2007 at 06:54AM PDT, ID: 19746097

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Perl Programming Language, C Programming Language, C# Programming Language
Tags: perl
Sign Up Now!
Solution Provided By: mkatmonkey
Participating Experts: 2
Solution Grade: A
 
 
[+][-]08.22.2007 at 10:36PM PDT, ID: 19751771

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 05:18AM PDT, ID: 19761387

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.24.2007 at 05:25AM PDT, ID: 19761429

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628