Programming in Hack Wars

Hack Wars encourages players to program to increase their skills and standing within the game.

Script Editor

To create a new program in Hack Wars, the first step is to find the Script Editor under Applications. The Script Editor allows you to choose which type of script you’d like to create (Banking, Attack, etc.). Each type of script has various components, e.g., a Banking script has Deposit, Withdrawal, and Transfer components. These correspond with actual events that happen while playing the game. For instance, any code you write into the Deposit component will be run when a player attempts to perform a Deposit transaction with their Bank.

http://www.plink-search.com

In the above screen shot, the three ‘events’ of a Banking program are highlighted in green. The ‘Save’ functions are highlighted in yellow—failure to save the program will result in the compiled program having the name “Untitled”. The Test Compile button is highlighted in blue, Compile in red, and in purple is the option to Run a Challenge Script (which will be discussed at another point).

Hack Wars programming is event-driven. There are limitations as to what functions can be run at any given time, depending on the type of program you are making and the ‘event’: functions called in the ‘Finalize’ portion of an Attack script must be functions that can be called when finalizing an attack.

Banking
A banking script has three ‘events’:
  • Deposit: called when a player attempts to make a deposit to his or her bank.
  • Withdrawal: called when a player attempts to withdraw from his or her bank. Restriction: If you are writing a malicious withdraw script, you can only steal as much money as the player has requested to withdraw. This ensures that your bank is secure despite malicious scripts.
  • Transfer: called when a player attempts to make a transfer to another player.
Attack
An attack script has three ‘events’:
  • Initialize: called before the attack actually begins. This allows you to preemptively cancel an attack based on certain parameters. This is also where malicious zombie codes are placed.
  • Continue: called each time the attack is about to deal damage. Restriction: you can also place berserk in continue to deal extra damage. This can be called only once per continue.
  • Finalize: called when an attack has been completed, and the opponent’s port is in a weakened state. To perform a malicious operation, one of the ‘finalize’ methods listed in the Attack API can be called here. Restriction: Only one finalize method may be called in an attack.
FTP
  • Put: called when a player attempts to place a file from their home directory into either the Store or Public FTP directory.
  • Get: called when a player attempts to retrieve a file from their Store or Public FTP directory and replace it on their home computer.
Watch
  • Fire: called when one of the various events that can cause a Watch to fire has taken place, such as an attack, scan, or change in amount of Petty Cash.

A full list of functions that can be called is given in the Hack Wars API section, listed by type of script.

Compiled Programs

Compiling a script requires that a player has attained the level required to call the functions, as listed in the API, and also that the player pays the appropriate amount of money, determined by the functions called within the program and the number of occurrences.

A program is compiled by clicking the appropriate button in the Script Editor. Prior to compiling, it is advisable to Test Compile: this gives the player the compiling cost and tests the code’s validity. If the test compile finds invalid code, the event containing the faulty code is identified. The player’s name is attached to the program upon compiling.

Compiled programs can be installed on a player’s ports in Port Management (see below, section on Installing Programs), sold in stores to other players or installed on an opponent’s port after a successful attack.

While compiling code is restricted based on level, a player of a lower level may still install a program he or she has bought or traded.

De-compiling programs

A player is allowed to de-compile programs they themselves have made by selecting the compiled file in the File Browser (System—Home) and clicking the De-compile button at the top of the window. This will return 90% of the compile cost to the player; also, 90% of the experienced gained from compiling the program will be deducted. An uncompiled version of the script will appear on the player’s hard drive, which can now be edited. This can be useful to merchants who may have a large quantity of files to which they wish to make a change.
Note that once a program has been installed, it cannot be removed, and therefore not de-compiled.

http://www.plink-search.com

In this screen shot the de-compile option is highlighted in purple. Please note that the money returned is 90% of the compile cost, and NOT the price set by the user.

Installing Programs

Programs are installed from within the Port Manager by right-clicking a port under the heading Type and selecting a script to install (highlighted here in red).

http://www.plink-search.com


Syntax

Programming in Hack Wars is close to a programming language called C. This is a very pervasive standard in computing. For those not familiar with this programming language, this section of the manual will give a good overview. Even for experienced programmers, it is good to read through this section to see some of the limitations presented by the Hack Wars programming language.

Types: you can use int, string, float, or boolean, variable types in Hack Wars, here’s an example of a script using all four types:


int a=10;
float b=5.5;
string message="You are being sent a message.";
boolean myBool=true;
if(myBool&&(b>5.0||a<10)){
	message(getSourceIP(),message);
} 

If you placed this script, for instance, in the deposit entry point of a banking application, it would always send you the message “You are being sent a message.” when you attempt to deposit — the deposit would not happen, mind you, since it contains no code to perform this operation.

Assigning Values: To assign a variable to be equal to a value (as demonstrated in the previous code example) use the ‘=’ operator, e.g., int i=5. This is the only way currently available to assign values, ‘++’,'--’,'*=’, etc, are not currently supported. So, for instance, if you had a counter in a loop you would increment it using the following code:


int i=0;
while(i<10){
  i=i+1;
} 

Logical Operators: You have access to the following logical operators in the Hack Wars scripting language:

Meaning Symbol
Greater than >
Less than <
Equal to ==
Greater than equal to >=
Less than equal to <=
And &&
Or ||
Equal ==
Not Equal !=

Program Flow: There are two main ways to direct the logical flow of a program you are creating if statements and while statements. Using an if statement allows you to execute code if a statement evaluates to true, using else allows you to specify code that runs otherwise:


if(5>6){
  message(getSourceIP(),"This should never happen!");
}else{
  message(getSourceIP(),"This should always happen.");
} 

Using a while statement allows you to specify a block of code that will always execute until a condition evaluates to false:


int i=0;
while(i<3){
  message(getSourceIP(),printf("T Minus %s",(3-i)));
  i=i+1;
}
message(getSourceIP(),"Liftoff!");