You are not logged on | Login | Register  
Script for uploading server bots

 
YouDieNow

I got tired of having to constantly upload my bot to the server through my browser everytime i make a change: Hit the back button, choose the file, turn off opensource, click the button, etc...takes at least an entire 7 seconds. So I wrote a script to do it for me. Now I just run the script when I want to upload, and it's done in one second flat. It's also much faster for me, because before I would run a script that compiled several tcl files into one before i uploaded the bot through my browser. So now I've combined both scripts into one. it's much easier and faster. I figured i'd share it with you guys in case anyone else has a use for it too.

There are three procedures to the upload script.
First, call the proc login with your email and password as arguments. This sends the login info to the website, the site sends back a cookie which includes a session id.
Then, call the proc upload_bot with three args: the name of the bot, the path of the script, and a boolean specifying opensource or not. upload_bot then uses the proc writebody which puts the form data in a temporary file and uploads the info to the server.

Here it is:


package require http 2.4


proc upload_bot {botname filename opensource} {
global COOKIE
if {$opensource} {
writebody [list process editbot] [list nickname $botname] [list file $filename] [list opensource 1]
} else {
writebody [list process editbot] [list nickname $botname] [list file $filename]
}
set postbody [open post.txt]
set token [::http::geturl http://www.dominategame.com/process.php -type "multipart/form-data; boundary=---------------------------7d32762682c" -querychannel $postbody -headers [list Cookie $COOKIE]]
close $postbody
file delete post.txt

upvar #0 $token state
if {[string last {editbotsuccess} $state(meta)] > -1} {
puts "Upload Successful"
} else {
puts "Upload Failed"
vwait forever
}
::http::cleanup $token
return
}

proc writebody {args} {
set token [open post.txt w]
foreach i $args {
puts $token "-----------------------------7d32762682c"
set name [lindex $i 0]
if {$name == "file"} {
puts $token "Content-Disposition: form-data; name=\"$name\"; filename=\"[lindex $i 1]\""
puts $token "Content-Type: text/plain"
puts $token ""
set file [open [lindex $i 1]]
puts $token [read $file]
close $file
} else {
puts $token "Content-Disposition: form-data; name=\"$name\""
puts $token ""
puts $token [lindex $i 1]
}
}
puts $token "-----------------------------7d32762682c--"
puts $token ""
close $token
}


proc login {email password} {
global COOKIE
set query [::http::formatQuery process login redirect "" email $email password $password]
set token [::http::geturl http://www.dominategame.com/process.php -query $query]
set data [::http::data $token]
upvar #0 $token state
set start [expr [string last "Set-Cookie \{dominate" $state(meta)] + 12]
set end [expr [string first ";\}" $state(meta) $start] - 1]
set COOKIE [string range $state(meta) $start $end]
::http::cleanup $token
}




login your@email.com password
upload_bot botname script.tcl 0



 
jaybird

Nice job YDN. I'll let you know how it goes. When I finish the obfuscate proc, I post as well.

 
chingiss3

Nice work, Emiel (ofcourse), YDN and the rest of you writing wonderful bots.

I'll hitch hike into this discussion and ask: How do you efficiently DEBUG your scripts.

We see a lot of bots existing from the game which means a bug, is there any way the programmers get some feedback and tracing ? maybe through the chat window (with a debug flag turned on)

And last, Emiel, wouldn't it better to set a default: FALSE for the open source option ? I mean we most frequently do test uploads.

 
chingiss3

and one more thing, i tried to delete a test bot i've written and it remains in the list. any ideas ?

 
YouDieNow

Talk to Jay about his testing harness he wrote some time ago. It allows you to change all the different game variables. It's pretty cool. The only thing built into the game that you can use to debug is the "error" command. It displays the message to the bot owner in the box at the bottom left corner of the game window.

The list of bots in the game app updates like every hour, so that won't reflect any deleted or new bots immediately, though updates are immediate.

 
chingiss3

That's great. I noticed the usage of #error but didn't know where to expect the text :)
I wrote a bot named Zohar1, deleted it, it doesn't appear in my 'show all bots' but it appears and can be selected in the robot list in the game.

  Reply to this discussion

Copernica is a software for e-mail marketing, profile enrichment, websites and short text messages campaigns.