segunda-feira, abril 14, 2008

Breaking my head against the Travian wall

I've been fixed on the idea of building an Admin interface for the Travian game. Though out of all my crazy ideas this must have been the one with the MOST trouble. Along with the fact that my JS /DOM was very rusty, I've encountered other difficulties... So from the beginning.

Figuring out how it works:
Travian is build on a mix of php, JS & HTML. The big issue being php, because it's executed server side! Client sends a request. Server reply s with html page. I can't read it, can't access it and the only way I could glimpse it's workarounds would be by monitoring variables being passed to it along with every different call made to the server. Now besides not being the easiest task... it never will grant that I can figure params for hidden evolutions. Because it's not a static game. So I'd only be able to implement a scalable application once I reached the end... and well the hole purpose is to build something that will help me do that. So that made me quit the hole hack trough php idea. The objective is to build an application capable of monitoring action just like any human user would do by reading the page, not modifying it.

So that takes us to the next step. Ok.. I can recognize anchors with a scanner algorithm just as easily as I can with my eyes.... so I'll just have to find a way to process the source. All joyful stupid H. wandered around the house jumping and smoking cigarrets while planning the best way to do it. What language am I using? Am I going to go object oriented and define identities so I can delegate tasks and therefore better organize the application? How about GUI? I don't feel like spending hour costuming it! Javascript? It's cool I can generate tables through DOM and it offers anchors that I can customize by just copying the URLS from the source, I don't even have to worry about logging in as long as I grant that I'm opening the admin window on the the same browser window of the game. Java? Java has a bunch of cool classes for manipulating strings, the own String class, with it's contains and substrings gymnastics and Scanner and Tokenizer. Besides a comfortable Thread manipulation and Timer's... Hum... why don't I mix it all.. I just need a bridge between Java and Javascript so I can pass information around. Well.. I found the bridge, it's a package from netscape and it comes with the plugins jar, somewhere in your JRE. There's not much to know about it, it raps the JS object on a JSObject and sends it to java, while unraping it when it's send back to javascript. Furthermore it's very intuitive, you can even cast it directly to string if it's a text object like in document.body.innerHTML. All very cozy and comfortable. I wrote a window with a bunch of frames, drawn the hole communication and generalist aspects of the application. And I thought ok... now I just need to input the source from the site. And here the trouble started!! You can very easily view any source from any URL with a simple access to: window.document.body.innerHTML but if the URL is out side your “server” then the window becomes a fucking cocoon. You can't access document.body, therefore you can't read the source no fucking way without some other workaround external to plain JS. This is very plain simple conclusion but I lost hours!!! t'ill I realized there was no possible workaround for this. I tried to workaround it in a milion ways, by testing if it had anything to do with a particular propertie, going from window, from frame, from context, getting the calls made by different window object and even tried to schedule a call to an echo function by changing window.onload = setTimeout(“alert(window.document.body.html);”,1000); to make it seem like the window which contained the external URL was asking for this, but couldn't ;P


So now basically I'm stuck at a stupid fetch sorce. I can understand that I can't write to the document. But read it... I call this stupid security! Now to something so simple I'm gonna have to just flush the source right in to Java. Using some sort of bridge to HTTP. I smell servlets. But I know nothing 'bout that.... YET!!! hihihi So...

Don't miss the next chapter 'cause I certainly won't.
God what a bad joke!! LOL
I have two tests tomorrow and an assignment presentation at 11h30 AM. Need sleep.

helga@body: shutdown -h now

Sem comentários :