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!");