Hackscript API

Hack Wars is unique in that its in game crafting takes the form of actual programming — you can effectively play the game without any prior knowledge of programming, but crafting applications can have lucrative financial benefits. As you level up your programmable skills (Attacking,Watches,Banking) , you will be presented with powerful new API ‘s. These can be used to create compiled applications to sell in your store, or perhaps for more dubious purposes.

Helper Functions

When programming Hack Wars applications you can use a few helper methods which cost no money to compile and absorb no CPU load.

Method Required Level Compile Price CPU Usage Description
equal(string s1,string s2) N/A $0 0 Returns a boolean representing whether or not s1 and s2 are equal.
printf(string s,args…) N/A $0 0 Returns the string s with the values of the variables provided in args appended onto it. Usage: printf("Value = %s Name = %s",30.0,"Ben");
rand() N/A $0 0 Returns a random floating point value between 0 and 1.
intValue(float i) N/A $0 0 Given a float it returns the integer value of it.
floatValue(int i) N/A $0 0 Given an int it returns the float value of it.
indexOf(string s1,string s2,int n) N/A $0 0 the index within s1 of the first occurrence ofs2 , starting at the specified index, n.
replaceAll(string s1,string s2,string s3) N/A $0 0 Replaces all instances of s2 in s1 with s3.
setGlobal(int index,variable var) N/A $0 0 Sets the value of one of your 20 global variables. These can be used between scripts, and save with your account. They can take on the value of integer, boolean, string, or float.
getGlobal(int index) N/A $0 0 Fetches the variable stored in the global variable array indicated by index.
parseFloat(string s) N/A $0 0 Attempts to parse a floating point number based on the string input..
parseInt(string s) N/A $0 0 Attempts to parse an integer value from the string provided.
toUpper(string s) N/A $0 0 Returns an upper-case version of the string provided.
toLower(string s) N/A $0 0 Returns a lower case version of the string provided.
isGlobalSet(int index) N/A $0 0 Returns whether the global variable indicated by index is set.
isGetVariableSet(string key) N/A $0 0 Returns whether the resource indicated by key has been set.
isParameterSet(string key) N/A $0 0 Returns whether the resource indicated by key has been set.
isTriggerParameterSet(string key) N/A $0 0 Returns whether the resource indicated by key has been set.

Challenges API

To help a player level up, and to make some cash, Hack Wars offers a series of programming challenges. These challenges have a an API specifically designed to create and solve interesting (and sometimes difficult) challenges. Please note that while writing challenge code you also have access to the Helper Functions.

Method Required Level Compile Price CPU Usage Description
strlen(string s) N/A $0 0 Returns an integer representing the length of a string.
sqrt(float f) N/A $0 0 Returns the square root of the float provided.
abs(float f) N/A $0 0 Returns the absolute value of the float provided.
ln(float) N/A $0 0 Returns the natural logarithm of the float provided.
atan(float) N/A $0 0 Returns the arc-tangent of the floating point number provided.
acos(float) N/A $0 0 Returns the arc-cosine of the floating point number provided.
asin(float) N/A $0 0 Returns the arc-sine of the floating point number provided.
tan(float) N/A $0 0 Returns the tangent of the floating point number provided.
cos(float) N/A $0 0 Returns the cosine of the floating point number provided.
sin(float) N/A $0 0 Returns the sine of the floating point number provided.
getE() N/A $0 0 Returns the mathematical constant e.
getPI() N/A $0 0 Returns the mathematical constant PI.
substr(string s,int start,int finish) N/A $0 0 returns a substring starting and ending with the two indexes provided.
getInputString() N/A $0 0 Returns the next string in the array of strings that has been provided as input to the challenge. Usage varies depending on the type of challenge being performed.
getInputStringCount() N/A $0 0 Returns an int representing the number of strings present in the input string array.
setOutputString(string s) N/A $0 0 Adds a string to the array of strings representing the challenges output. Usage varies depending on the type of challenge being performed.
getInputFloat() N/A $0 0 Returns the next float in the array of floats that has been provided as input to the challenge. Usage varies depending on the type of challenge being performed.
getInputFloatCount() N/A $0 0 Returns an int representing the number of floats present in the input float array.
setOutputFloat(float f) N/A $0 0 Adds a float to the array of floats representing the challenges output. Usage varies depending on the type of challenge being performed.
getInputInt() N/A $0 0 Returns the next int in the array of ints that has been provided as input to the challenge. Usage varies depending on the type of challenge being performed.
getInputIntCount() N/A $0 0 Returns an int representing the number of ints present in the input int array.
setOutputInt(int i) N/A $0 0 Adds an int to the array of ints representing the challenges output. Usage varies depending on the type of challenge being performed.

Attacking API

When you attack an opponent’s computer from a port with an attack program installed on it, an application built from this API is executed. This application has three main entry points:

Initialize: Any code in initialize is executed when the attack first begins. This allows a player to cancel the attack immediately given certain initial parameters — this can be particularly useful when attacks are started automatically by Watches .

Continue: Continue is called each time an attack on an opponent is about to deal damage. This is a good time to decide whether or not an attack should be canceled — perhaps because your CPU is about to overheat.

Finalize: Finalize is called when the port being attacked is in a weakened state, it is at this point that a malicious function, e.g., emptyPettyCash(), showChoices(), destroyWatches(), can be executed.

Method Required Level Compile Price CPU Usage Description
message(string ip,string message) 1 $5 1 Sends a message to the player represented by the IP address provided.
showChoices() 1 $5 1 Prompts the GUI to display a list of malicious actions that can be taken upon finishing an attack.
getSourceIP() 1 $5 1 Returns a string representing the IP address of the computer performing an attack.
getTargetIP() 5 $10 1 Returns a string representing the IP address of the computer being targeted with an attack.
getCPULoad() 10 $10 2 Returns a float representing the current CPU load of the computer performing the attack.
cancelAttack() 10 $50 2 Cancels the attack currently being performed.
changeDailyPay(string ip) 15 $250 5 Used in finalize to automatically set the opponents daily pay target to the IP provided.
installScript() 15 $250 5 Installs a malicious script on the port being attacked (must be called when port being attacked is in a weakened state) .
emptyPettyCash() 15 $250 5 Steals any money in the petty cash of the player being attacked; this only works when the port being attacked is a banking port (must be called when port being attacked is in a weakened state) .
getIterations() 15 $150 2 Returns an int representing how many times the continue function has been called (how many iterations the attack has had) .
getHP() 25 $500 5 Returns a float representing the hit-points of the port performing an attack.
getMaximumCPULoad() 25 $500 2 Returns a float representing the current maximum CPU load for the player running an attack.
getTargetHP() 35 $1500 3 Returns a float representing the hit-points of the port being targeted with an attack.
berserk() 40 $1500 5 Perform a double attack, but also hurt your own port.
deleteLogs() 45 $1000 4 Deletes all the logs associated with your IP in the player’s logging DB.
switchAttack() 50 $1000 10 Switches an attack from targeting the current port to targeting the next port in an array of secondary targets.
checkForWatch() 50 $2000 5 Returns a boolean stating whether or not a watch is observing the port being attacked.
editLogs(string original,string replacement) 55 $1500 4 Replaces all instances of the original string in the opponent's log with the replacement string.
zombie(string ip) 60 $2000 0 Allows a player associated with the string ip to remotely hook into a player’s attack program. This function should be placed in initialize .
isZombie() 60 $500 0 Returns a boolean value indicating whether or not the attack currently taking place is being controlled remotely or not.
checkPettyCash() 60 $750 8 Returns a float representing the amount currently in the petty cash of the player being targeted with this attack.
checkPettyCashTarget() 60 $750 8 Returns a float value specified at runtime. This value can be used to decide, amongst other things, whether or not we should empty the opponent’s petty cash.
freeze() 65 $2500 10 Temporarily disables the port being attacked. This round of an attack deals no damage.
stealFile() 70 $3000 7 Used in finalize, stealFile() automatically takes a file from the opponent's computer (rather than using the file selection dialog).
getTargetCPUCost() 85 $10000 15 Returns a float representing the CPU cost of the port being targeted with an attack.
destroyWatches() 95 $15000 25 Destroys any watches on the opponent’s computer observing the port being attacked (must be called when port being attacked is in a weakened state) .

Banking API

To transfer money between a player’s petty cash and bank, a Banking Application must be installed on a port. Without a banking application a player can’t purchase items or receive money from store sales, other players, or daily pay — this having been said, a banking port can be extremely attractive for opponents to maliciously target.

When programming a banking application the program has three main entry points:

Deposit: Deposit is called when a player is attempting to transfer money from their petty cash to their bank.

Withdraw: Withdraw is called when a player is attempting to transfer money from their bank to their petty cash (funds must be available in the petty cash to perform purchases).

Transfer: Transfer is called when a player attempts to transfer money from themselves to another player.

Method Required Level Compile Price CPU Usage Description
lowerDeposit(string ip,float amount) 1 $10 1 Deposits the amount specified into the bank of the player represented by the IP provided. lowerDeposit() takes the highest percentage in service charges and gives the least experience.
withdraw(string ip,float amount) 1 $10 1 Withdraws the amount specified into the petty cash of the player represented by the IP provided.
lowerTransfer(string targetIP,float amount) 1 $10 1 Transfers the amount specified to the petty cash of the player represented by the IP provided. lowerTransfer() takes the highest percentage in service charges and gives the least experience.
message(string ip,string message) 1 $10 1 Sends a message to the player represented by the IP address provided.
getAmount() 1 $10 1 Returns a float representing the amount that it has been requested be transfered, withdrawn, or deposited. Malicious programs may sometimes ignore this value (this value, however, represents an upper bound on how much can be withdrawn from the bank) .
getSourceIP() 1 $10 1 Returns a string representing the IP of the computer attempting to perform the banking operation.
getTargetIP() 1 $10 1 Returns a string representing the IP of the computer to which a money transfer request has been submitted. (used by the various transfer methods).
getMaliciousIP() 15 $1500 2 Returns the IP address of a computer that has hijacked this banking application. It is up to the programmer of the malicious application to decide how to act upon this information.
mediumDeposit(string ip,float amount) 25 $1500 5 Deposits the amount specified into the bank of the player represented by the IP provided. mediumDeposit() takes a lower percentage in service charges and gives more experience.
mediumTransfer(string ip,float amount) 25 $1500 5 Transfers the amount specified to the petty cash of the player represented by the IP provided. mediumTransfer() takes a lower percentage in service charges and gives more experience.
checkPettyCash() 25 $1500 5 Returns a float representing the amount currently in the petty cash of the player being targeted with this attack.
checkPettyCashTarget() 25 $1500 5 Returns a float value specified at runtime. This value can be used to decide, amongst other things, whether or not we should empty the opponent’s petty cash.
higherDeposit(string ip,float amount) 75 $6000 10 Deposits the amount specified into the bank of the player represented by the IP provided. higherDeposit() takes a lower percentage in service charges and gives more experience.
higherTransfer(string ip,float amount) 75 $6000 10 Transfers the amount specified to the petty cash of the player represented by the IP provided. higherTransfer() takes a lower percentage in service charges and gives more experience.
greaterDeposit(string ip,float amount) 95 $9000 20 Deposits the amount specified into the bank of the player represented by the IP provided. greaterDeposit() takes a lower percentage in service charges and gives more experience.
greaterTransfer(string ip,float amount) 95 $9000 20 Transfers the amount specified to the petty cash of the player represented by the IP provided. greaterTransfer() takes a lower percentage in service charges and gives more experience.

FTP API

When a player attempts to transfer files between their store and between other players, an FTP program is used. FTP is not a skill that can be leveled up, and consists of a relatively small API — this having been said, intelligently deployed malicious FTP programs can be a good way to steal sought after applications and fire walls. An FTP port must be installed to operate your personal store. FTP programs have two main entry points.

Put: Put is called when a player is attempting to move a file from their home directory to their shop or to any public directory.


Get: Get is called when a player is attempting to move a file from their store or any public directory to their home directory.

Method Required Level Compile Price CPU Usage Description
put(string ip) N/A $500 2 Put takes a string as input representing the computer that a file should be transferred to (the file and the target directory are given at runtime).
get(string ip) N/A $500 2 Get takes a string as input representing the computer that a file should be transferred to (the file and the target directory are given at runtime).
message(string ip,string message) N/A $500 2 Sends a message to the player represented by the IP address provided.
getTargetIP() N/A $500 2 Returns a string representing the IP address of the computer that it has been requested an FTP action be taken upon.
getMaliciousIP() N/A $5000 2 Returns the IP address of a computer that has hijacked this FTP application. It is up to the programmer of the malicious application to decide how to act upon this information.
getFileName() N/A $10000 2 Returns a string representing the name of the file being transfered.
getFileType() N/A $50000 2 Returns a string representing the type of file being transfered (one of: compiled, script, firewall, image, or text) .
getFilePrice() N/A $100000 2 Returns a float representing the asking price of the file being transfered. |

Watch API

Unlike the previous API ‘s a watch program is not installed directly on a port. Rather, a watch is given a parameter representing which port to observe and installed independently with the watch handler . When a player is not online their computer is still vulnerable to attack, watches can be used to configure an automated defense system. Watches can also be used to provide additional feedback about the state of a player’s computer. Watches can currently be configured to observe two main events: changes in the amount of money in a player’s petty cash, and changes in the hit-points of a port being observed. A watch can be configured with an array of secondary observed ports that represent additional ports that actions can be applied to (fetching fire walls, turning off port) . Watch programs have one main entry point.

Fire: This function is called when the money in a player’s petty cash reaches a certain amount, or when a port’s hit-points go below a certain value.

Method Required Level Compile Price CPU Usage Description
getTargetIP() 1 $50 1 Returns a string representing the IP address of the player that caused this watch to fire.
getPort() 1 $50 1 Returns the port that this watch is observing.
getSourceIP() 1 $50 1 Returns a string representing the IP address of the player that has this watch installed.
getTargetPort() 1 $50 1 Returns an int representing port number on the opponent’s computer that caused this watch to fire.
message(string ip,string message) 1 $50 1 Sends a message to the player represented by the IP address provided.
logMessage(string message) 1 $50 1 Puts a message in your logging database.
sendFacebookMessage(string message) 1 $50 1 Puts a message in your Facebook profile.
getTransactionAmount() 5 $250 1 Returns the amount of money that caused a petty cash watch to fire.
checkFireWall(string firewall) 5 $100 2 Takes a string as input representing the type of fire wall to check for, one of: nofirewall, basicfirewall, mediumfirewall, greaterfirewall, basicattackingfirewall, mediumattackingfirewall, greaterattackingfirewall, ultimateattackingfirewall. Returns a boolean representing whether or not this type of fire wall is installed on the port being observed.
switchAnyFireWall() 10 $500 5 Checks the secondary array of ports being observed by this watch for any fire wall. This fire wall is moved to the primary port that caused this watch to fire.
getCPULoad() 10 $250 2 Returns the current CPU load of the computer that had this watch fire.
checkForFireWall(string firewall) 15 $250 3 Given a string representing a fire wall constant (see checkFireWall()) , returns an int representing the number of a secondary port being observed by this watch that has the given fire wall installed on it (returns -1 otherwise)
switchFireWall(int port) 15 $250 3 Takes an int as input representing a port number in the array of secondary ports being observed. The fire wall on this secondary port is switched onto the port that caused this watch to fire.
getMaximumCPULoad() 20 $1000 2 Returns the maximum CPU Load of the computer that had this watch fire.
getSearchFireWall() 20 $500 2 Returns a string constant, specified by the user, that represents a fire wall that should be searched for by checkForFireWall() , see checkFireWall() for constants.
checkPettyCash() 25 $1000 4 Returns a float representing the amount in the petty cash of the player’s computer that had this watch fire.
isTriggered() 35 $1000 2 Returns whether or not this watch actually fired or whether it was caused by a trigger event (either in HTTP or in a game).
getTriggerParameter(string key) 35 $1000 2 Returns the variable associated with the key sent along with triggerWatch().
transferMoney(string ip,float amount) 40 $2000 5 Transfers the amount indicated to the player represented by the IP.
sendEmail(string message) 35 $1000 5 Sends you an email with the message provided. This function takes $100 to run.
scan(string ip) 45 $2500 5 Scan takes an IP as input and performs a scan on the target.
attack(int playerport,string opponentIP, int opponentPort) 50 $10000 10 Launches an attack from the port indicated against the player and port provided.
counterattack(int port) 50 $10000 10 Starts a counter attack against the player’s port that caused this watch to fire (The port provided is used to mount the attack.)
cancelAttack(int port) 50 $10000 4 Cancels an attack taking place on the port indicated.
zombieAttack(string zombieIP,int zombiePort,string opponentIP, int opponentPort) 55 $15000 10 Launches an attack from the zombie and port indicated against the opponent represented by the IP and port.
counterattackBank(int port) 60 $15000 12 Starts an attack against the opponent’s default banking port (The port provided is used to mount the attack.)
counterattackAttack(int port) 60 $15000 12 Starts a counter attack against the opponent’s default attacking port (The port provided is used to mount the attack.)
getDefaultBank() 60 $15000 2 Returns an int representing the port that a player currently has set as their default bank.
getDefaultAttack 60 $15000 2 Returns the default attacking port associated with this computer.
getDefaultFTP() 60 $15000 2 Returns an int representing the port that a player currently has set as their default FTP.
getDefaultHTTP() 60 $15000 2 Returns an int representing the port that a player currently has set as their default HTTP.
shutDownWatch(int number) 65 $2000 8 Turns off the watch represented by number.
turnOnWatch(int number) 65 $2000 8 Turns on the watch represented by number.
shutDownPort(int port) 75 $10000 15 Takes an int as input representing the port number of a port in the array being observed. This port is turned off .
heal() 75 $10000 15 Heals the port that is being observed by this watch (same price as manual healing) .
shutDownPorts() 80 $25000 20 Attempts to shutdown all the ports in the array of secondary observed ports associated with this watch.
turnOnPort(int port) 75 $10000 15 Takes an int as input representing the port number of a port in the array being observed. An attempt is made to turn this port on.
turnOnPorts() 80 $25000 20 Attempts to turn on all the ports in the array of secondary observed ports associated with this watch.
depositPettyCash(int amount) 95 $100000 25 Automatically deposits money equal to amount from the player’s petty cash into their bank, as a defensive measure.

HTTP API

HTTP programs have 3 main entry points.

Enter: This function is called when someone goes to your site.

Exit: This function is called when someone leaves your site.

Submit: This function is called when someone submits a form on your site.

Method Required Level Compile Price CPU Usage Description
getVisitorIP() 1 $10 1 Returns a string representing the IP address of the player that visited your site.
getHostIP() 1 $10 1 Returns a string representing the IP address of the player that hosting the site.
message(string ip,string message) 1 $10 1 Sends a message to player represented by ip.
logMessage(string message) 1 $50 1 Puts a message into your log database.
popUp(string message) 5 $250 2 Popups a message on a visitors screen.
getParameter(string name) 20 $100 1 Gets a variable from a form on your site. Name is gotten from the form. ie. <input type="text" name="var">. To get this parameter you would use getParameter("var");
triggerWatch(int number, string key1,variable var1 ... keyN,variable varN) 30 $1000 3 Triggers the watch indicated passing along the variables provided associating them with the keys (in a watch these can be fetched using getTriggerParameter()).
replaceContent(string key,string content) 30 $250 1 In your web-page content you can place the tag <?some_key?>. You can dynamically replace the content of this tag using replaceContent(). In this case replaceContent("some_key","my new content") would replace the instance of "<?some_key?>" with "my new content". The key can, of course, take on any value.
turnOnWatch(int number) 30 $1000 3 Turns on the watch associated with the number provided.
fetchGetVariable(string key) 35 $500 1 You can indicate variables in the URL of the web-page you are going to, e.g., hackstock.hw?ip=132&name=ben. These consist of key value pairs, where, for instance, 'name' and 'ip' are keys and '132' and 'ben' are values. Using fetchGetVariable() you can fetch the values by providing a key.
hideStore() 40 $1500 6 Stop the current visitor to your web-site from seeing your store.

File IO

Like the other helper functions, File IO can be used in all types of scripts (excluding challenges). File IO is particularly powerful in association with HTTP programs -- it having been designed with complex in-game websites in mind. File IO is a pay feature.

Note: that file operations can only be performed on files of the type text on your HD, also an attempt will be made to auto-generate files that cannot be found.
Method Required Level Compile Price CPU Usage Description
clearFile(string file) N/A $0 0 Clears the contents of the text file pointed to by the filename (the full path is parsed).
readFile(string file) N/A $0 0 Reads the entire contents of a file in as a string.
readLine(string file,int line) N/A $0 0 Reads in a line of text from the file provided. 'line' represents the line of the file to read in.
countLines(string file) N/A $0 0 Returns an integer representing the number of lines in a text file.
writeLine(string file,string data) N/A $0 0 Writes the data provided on a new line at the end of the file.
writeFile(string file,string data) N/A $0 0 Writes the data to the file, over-writing any data that was already there.
fileExists(string file) N/A $0 0 Returns a boolean indicating whether or not the file indicated exists.
char(int c) N/A $0 0 Can be used to print out non-printable characters to a string, e.g., newline: "ben"+char(10)