toddw123 / RotMG_Clientless

Compatible with version X16.0.0
MIT License
11 stars 4 forks source link

php script for your accounts.js to settings.xml #31

Closed toddw123 closed 7 years ago

toddw123 commented 7 years ago

I was getting pretty annoyed with trying to swap out different accounts in my settings.xml file for testing, i was just looking at my accounts.js file from muledump and then copy/pasting the info over. But it just gets annoying to do it, especially if you are trying to set up more then 2 or 3 accounts!

Anyways, i actually do php programming for my job. I know some people like to give php a bad time and say its awful blah blah blah but in all my years of programming, and all my years of programming php, ive never run into something that made me think php was complete garbage. Quite the opposite really. Anytime i learn something new in php im usually pretty amazed at how versatile and all-inclusive php is. I also love that it was built using C/C++, which is then reflected in php's syntax. This is what made it so easy for me to pick up since i already knew c/c++.

But let me get back on track here sorry, i get distracted sometimes when talking about php just because i cant understand the undeserved hate it seems to get by the web developing community. So, php, i normally dont touch the stuff unless im at work anymore but on some occasions when i need to put together a quick tool to do something ill use php because its so easy to just open up a basic text editor and write down a few lines of code and its done. No need to go set up a huge project and all the build config. No need to find out which libraries i need to include to use functions x/y/z. No need to wait for it to compile every time i make a change. Etc etc the list could go on.

I finally sat down and put together this quick little php script that will read in your muledump's accounts.js file and convert it to the proper settings.xml format. Its set up where it also rotates the <Server> value (you could change it pretty easily if you didnt want that). So, without further ado i give you the php script:

<?php

    $accountsjs = "PATH_TO_ACCOUNTS_JS_FILE";
    // Remove any servers you might not want used, or leave as is to use all of them
    $servers = array( "USWest", "USWest2", "USWest3", "USMidWest", "USMidWest2", "USSouth", "USSouth2", "USSouth3", "USSouthWest", "USNorthWest", "USEast", "USEast2", "USEast3", "EUWest", "EUWest2", "EUEast", "EUNorth", "EUNorth2", "EUSouth", "EUSouthWest", "AsiaSouthEast", "AsiaEast" );
    if ( file_exists( $accountsjs ) && is_readable( $accountsjs )) {
        $js = file_get_contents( $accountsjs );
        if(!preg_match_all( "/'([^'\n]+)'/", $js, $matches )) die( 'failed to find any account info' );
        echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Config>\n\t<BuildVersion>27.7</BuildVersion>\n\t<MinorVersion>X11</MinorVersion>\n";
        $email = '';
        foreach ( $matches[1] as $i => $match) {
            if ( stripos( $match, "@" ) !== FALSE ) {
                $email = $match;
            }
            else if ( !empty( $email ))
            {
                echo <<<XML
    <Client>
        <Server>{$servers[ $i / 2 % count( $servers ) ]}</Server>
        <GUID>{$email}</GUID>
        <Password>{$match}</Password>
    </Client>

XML;
                $email = '';
            }
        }
        echo "</Config>\n";
    }

?>
ebf34e12952930cf commented 7 years ago

i did it with regex, replace '(.+)': '(.+)', with <Client><Server>enter server</Server><GUID>$1</GUID><Password>$2</Password></Client>. doesnt give you random servers though

toddw123 commented 7 years ago

Yeah essentially what the script does as its using regex on the accounts.js file and then outputting the xml. What did you use to do the regex with? do you have a command-line tool or something like that? reason i used php was ease-of-use basically.

ebf34e12952930cf commented 7 years ago

copy pasted all account lines from MD, then ran that replace in notepad++

toddw123 commented 7 years ago

oh neat i didnt know notepad++ had that feature. I use Sublime Text 3 when im not doing C++ stuff, im sure it has something like that too but ive never looked into it.