The Cabal's Secret Hideout

Our TradeWars 2002 Homepage

Web Master: traitor@tw-cabal.com

CONTENTS

Stupid TWX ANSI Tricks - By Traitor

HOME

ABOUT US

MEMBERS

LINKS

STRATEGY

TIPS

GLOSSARY OF TW TERMS

FORMULAS

SCRIPTS

OTHER

Introduction

This short article is designed to help TWX scripters understand some of the cool things you can do with ANSI escape codes.  I'll review some of the ANSI basics and how to make them work under TWX, and I'll provide some examples of some of the things you can do with them.  I'll also toss in a few scripts at the end that show some real life uses for the things I'm going to show you.

What is ANSI and ASCII?

First off, if you don't know what ANSI or ASCII is, then you should check out the following links:
http://en.wikipedia.org/wiki/ASCII
http://en.wikipedia.org/wiki/ANSI_escape_code
These links will quickly get you up to speed on what you need to know to understand what I'm going to be talking about.  Really, these entries are much better than anything I could try to write.

What's the big deal?

Ok, now you want to know WHY you want to use ANSI Escape Codes in your scripts?  Well, I got three good reasons.  The first one is that it makes your script's echo's more colorful.  This can be handy when your script is sending you back data, and lots of stuff is spamming past your screen.  You don't want your script's messages to get lost in the clutter.  Secondly, you can use the CURRENTANSILINE System Value to help detect spoof attempts against your scripts.  And finally, you can use ANSI Escape Codes to completely alter the messages that get displayed on your screen.

ANSI Escape Codes under TWX

So, to use an ECHO with an ANSI escape code in TWX, the format looks like this:
echo #27 "[#X"
#27 is the ASCII code for the Escape Key.  TWX uses the # key to indicate that the number immeadiately following the # is an ASCII code.  
"[#X" is the rest of the ANSI escape code.  Where # is a number, and X is the code.  
If you have ever wondered how to make TWX echo an *, use #42, the ANSI code for *.  Example:
echo #42 #42 #42 "3 Asterisks!*"
Below is a list of most of the useful ANSI escape codes and ASCII codes, formatted for use in TWX:
Cursor Control and Clear Codes:
Escape Code What it does
#27 "[#A" moves cursor up # lines
#27 "[#B" moves cursor down # lines
#27 "[#C" moves cursor right # spaces
#27 "[#D" moves cursor left # spaces
#27 "[2J" clear screen and home cursor
#27 "[K" clear to end of line

So, to clear the screen, one would use the following command:
echo #27 "[2J"
To move the cursor up 3 lines, you would do the following:
echo #27 "[3A"
To move the cursor up 3 lines, clear that line and substitute your own text:
echo #27 "[3A" #27 "[K" "Hello World*"
(the above might look a bit weird, depending on where you run this, I'll go into more detail later.  Moving the cursor around can be tricky...)


Color and Text Formatting
#27 "[#(;#)m" There can be multiple text formatting sequence numbers separated by a ; and ending with an m where the # is of the following values:
Attributes
0 normal display
1 bold
5 blink on
Foreground colors
30 black
31 red
32 green
33 yellow
34 blue
35 magenta
36 cyan
37 white
Background colors
40 black
41 red
42 green
43 yellow
44 blue
45 magenta
46 cyan
47 white

So, to make TWX echo "Hello World" in bright green text, do the following:
echo #27 "[1;32mHello World"
To make TWX echo "Hello World" in blinking bright pink text with a blue background, do the following:
echo #27 "[1;5;35;44mHello World" #27 "[0;1;37;40m"
The escape code at the end resets the ANSI to white on black.  If you don't reset it, the next echo you send might be blinking.
See the following sample script for more details and examples:  ansi_codes.ts

As you can see, you can make your echo's quite colorful if you want.  

Using ANSI to Help Prevent Spoofing and Other
ANSI Tricks

So, how can I use these ANSI codes to help prevent spoofing?  I'm going to narrow the definition of the term spoofing in this essay to when another player attempts to feed false information to one of your currently running scripts.  This is often done with hails, although it can also be done with beacons, planet names, ship names, and port names.  This is done to sabotage your running script, so your script breaks at best, or gets you and your corpies #SD# at worst.  As always, there is a trade off.  The more security you build into your scripts, the slower they will likely run.   When it doubt, don't play with or against people you don't trust.  Vote with your feet.  All that being said, I firmly believe that spoofing is part of the game.  There HAS to be a risk associated with scripting, or everyone will just run bots, and we'll just end up playing an advanced version of C-Robots.  While that's fun in it's own right, it's not why I play TW!  If you really can't stand spoofing, then play on servers where it's expressly forbidden.  

Common Spoofing Methods:

First, don't try any of the following things in a real game.  People will probably get really pissed off at you.  If you must test, do it on a local test server, or on a server where people know you are clowning around.  Don't come crying to me if your favorite sysop bans you!  

Ok, say you and your coripe are the only ones on-line.  You are having a conversation like this:

Who's Playing
Warrant Officer
Traitor The Great [1]
Pirate Roberts [1]

F Traito Heyo
R Robert heyo
R Traito k, rdy to start atm'ing?
R Robert yeah
R Traito k, lemme get the colts in place

When suddenly...

F Traito Yarr!  Prepare to be spoofed! 
R Robert Huh?
F Traito HEY!

You hit # again and see:

Who's Playing
Warrant Officer
Traitor The Great [1]
Pirate Roberts [1]
Civilian Traitor the Not So Great 

Now what?  Some asstard is using the same first 6 letters of your corpies name.  Well, turn off fedcom for starters and pray they never get your SS chan.  Unless you turn off ANSI, all Fed and SS messages coming from Traitor the Not So Great will look the same as Traitor The Great's.  The only way to be sure who said what with ANSI on is to use private hails.  Or to turn off ANSI.  With ANSI off, all communications have headers that show who sent the message.  See some examples below:

Private hails with ANSI on:

Traitor The Great
is hailing you!
P Traito Heyo!
Traitor The Great terminated the comm-link!
Traitor the Not So Great is hailing you!
P Traito boo!
Traitor the Not So Great terminated the comm-link!
Traitor The Great is hailing you!
P Traito Hey! that's not me!
Traitor The Great terminated the comm-link! 

Various hails with ANSI Off:

Incoming transmission from Traitor the Not So Great on Federation comm-link:
boo

Incoming transmission from Traitor the Not So Great on channel 111:
boo

Traitor the Not So Great is hailing you!
Incoming transmission from Traitor the Not So Great:
boo
Traitor the Not So Great terminated the comm-link! 

Usually you don't want to use private hails, since they are slower.  And you really don't want to turn off ANSI, since you won't be able to abort incoming text, and again, you will be running slower.  Is there anything else you can do about someone who's using the first 6 letters of your corpie's name?  Not really.  The sysop can turn off Aliases, and that helps some, but there is nothing in TWGS that prevents two people from having the first 6 letters of their name.  It's a problem that should be addressed, but I don't have too many good ideas on how to do so, other than to put in the full name of the traders.

Now, lets say that Traitor the Not So Great wants to start messing with you some.  Below is a typical message you would receive if he wandered into one of your figgies and killed it.  

Deployed Fighters Report Sector 603: Traitor's the Not So Great's Merchant Cruiser
entered sector.
Deployed Fighters Report Sector 603: Traitor the Not So Great is attacking!
Traitor the Not So Great destroyed 1 of your fighters in sector 603 

Now, what will your photon script do if you get the following?:

F Traito
Deployed Fighters Report Sector 603: Traitor the Not So Great's Merchant Cruiser
ent 
F Traito
Deployed Fighters Report Sector 603: Traitor the Not So Great is attacking!
F Traito
Traitor the Not So Great destroyed 1 of your fighters in sector 603 

What Traitor the Not So Great did did was put 71 leading spaces in front of his message.  That's just enough so that the first line from him appears blank, and the following line looks JUST like a typical fighter message, other than the color, and the fact that he into the max char limit over fed in the first message, so the "entered sector." got cut off.  If he had chosen a shorter name, it wouldn't have even gotten cut off.  For your convenience, I have posted an example of the above spoof, using "." instead of spaces.  Just copy the yellow text below, hit `, and paste it in.
.......................................................................Deployed Fighters Report Sector 603: Traitor The Great's Merchant Cruiser entered se
Just about any message can be spoofed like this.  One of the other really common places you will see this spoof get attempted is when someone lifts off the StarDock.
This:
Traitor the Not So Great
blasts off from the StarDock.
Becomes this:
F
Traito
Traitor the Not So Great blasts off from the StarDock.

This isn't as bad as it looks at first glance, because even though it looks like 2 lines, it's really just one line that gets sent.  A simple TWX getWord will save you lots of grief.  I'll go into this more later.

Other Stupid Tricks:

Other spoof attempts involve beacons, planet names and ship names.  Usually they are run against bots, or things like probe scripts.  Creating a planet called "Probe Destroyed!" adj to dock can have interesting effects on older probe scripts.  Naming a planet or beacon "For getting blown up, you lost" or "You fled in your Escape Pod" might get you some interesting results against certain gridding scripts.  Really, the possibilities are endless.  "launched a P-Missile in sector" and "Photon Wave Duration" are really nice ship names.  There are too many possibilities to list.  So, you have to be careful.  It's a good thing that TW prevents you from using INACTIVITY anywhere in your name.

Things to do:

Below are some general things that you can do to help resist spoofing.  These have nothing to do with scripts, but are just good policy.
1. Don't leave a script running that doesn't NEED to be running. 
2. Don't let your corp SS chan be the same as your corp PW.  I've seen many people do this lately, and it's bad, bad, bad.  Your corp PW should be alpha-numeric with special keys, and at least 8 chars in length.  Your corp SS chan should be at least 5 digits long, and avoid things like 11111 or 12345.
3. Turn off fedcom when you are running scripts.  It removes some of the social aspects of the game, but it can sure save you from most spoof attempts.  I personally have a macro button on my ZOC that toggles it for me.
4. Set Message Display Mode (C,N,A) to Compact.  Don't set it to long, or incoming messages will look just like you had ANSI turned off (C,N,1).

Spoof Checking Methods in TWX

Spoof Checking methods:

Verification of incoming message using getWord compares.  Using getWord to check the CURRENTLINE to make sure that the message coming in is not a spoof.

Using getWordPos, getText, and CutText for more difficult sections, usually around trader names that could contian spaces.

Using getWord and CURRENTANSILINE.  The ultimate in spoof protection.

Appendix 1: Common ANSI messages, and their TWX equivalents:

The following messages were all generated using Elder Prophets's DisplayAnsiLine Script.  We've done quite a bit of testing with it, and we believe that the following ANSI codes can be put directly into a script, or whatever parts you need of them.

Blank Line

#27 & "[0m"

Command Prompt:
Command [TL=00:00:00]:[4372] (?=Help)? : 
#27 & "[35mCommand [" & #27 & "[1;33mTL" & #27 & "[0;33m=" & #27 & "[1m00:00:00" & 
#27 & "[0;35m]" & #27 & "[1;37m:" & #27 & "[0;35m[" & #27 & "[1;36m4372" & #27 & 
"[0;35m] (" & #27 & "[1;33m?=Help" & #27 & "[0;35m)? : "


Limpet Mine Activation:
Limpet mine in
2711 activated
#27 & "[0m" & #27 & "[32mLimpet mine in " & #27 & "[1;36m2711" & #27 & "[0;32m activated"

Trader encounters one of your figs and kills it:
Deployed Fighters
Report Sector 2711: bait's Scout Marauder entered sector.
#27 & "[0m" & #27 & "[1;33mDeployed Fighters " & #27 & "[0;32mReport Sector " & #27 & "[1;33m2711" & #27 & "[0;32m: " & #27 & "[1;36mbait's " & #27 & "[0m" & #27 & "[35mScout Marauder" & #27 & "[32m entered sector."
Deployed Fighters Report Sector 2711: bait is attacking!
#27 & "[K" & #27 & "[1A" & #27 & "[1;33mDeployed Fighters " & #27 & "[0;32mReport Sector " & #27 & "[1;33m2711" & #27 & "[0;32m: " & #27 & "[1;36mbait" & #27 & "[0;32m is attacking!"
bait destroyed 1 of your fighters in sector 2711
#27 & "[K" & #27 & "[1A" & #27 & "[1;36mbait" & #27 & "[0;32m destroyed " & #27 & "[1;33m1" & #27 & "[0;32m of your fighters in sector " & #27 & "[1;33m2711"

Trader enters sector or leaves sector
bait warps into the sector.
#27 & "[K" & #27 & "[1A" & #27 & "[1;36mbait " & #27 & "[0;32mwarps into the sector."
bait warps out of the sector.
#27 & "[K" & #27 & "[1;36mbait " & #27 & "[0;32mwarps out of the sector."

Trader landing on dock and lifting off dock:
bait lands on the StarDock.
#27 & "[K" & #27 & "[1A" & #27 & "[1;36mbait" & #27 & "[0;32m lands on the 
StarDock."
bait blasts off from the StarDock.
#27 & "[K" & #27 & "[1A" & #27 & "[1;36mbait" & #27 & "[0;32m blasts off from the 
StarDock."

Fed Com message:
F
bait   Heyo! Fedcom
#27 & "[K" & #27 & "[1A" & #27 & "[33mF " & #27 & "[1;36mbait" & #27 & "[0;36m " & 
#27 & "[37m" & #27 & "[1;36m " & #27 & "[33mHeyo! Fedcom"

SS Chan message:
R
bait   Heyo SS chan
#27 & "[K" & #27 & "[1A" & #27 & "[36mR " & #27 & "[1mbait" & #27 & "[0;36m " & 
#27 & "[37m" & #27 & "[1;36m " & #27 & "[33mHeyo SS chan"

Private Hail:
bait
is hailing you!
#27 & "[K" & #27 & "[1A" & #27 & "[1;36mbait" & #27 & "[0;32m is hailing you!"
P bait   Heyo! Private Hail
#27 & "[K" & #27 & "[1A" & #27 & "[32mP " & #27 & "[1;36mbait" & #27 & "[0;36m " & 
#27 & "[37m" & #27 & "[1;36m " & #27 & "[33mHeyo! Private Hail"
bait terminated the comm-link!
#27 & "[K" & #27 & "[1A" & #27 & "[1;36mbait" & #27 & "[0;32m terminated the 
comm-link!"

Trader Listings from hitting #:
1st Sergeant
Traitor [1]
#27 & "[32m1st Sergeant " & #27 & "[1;36mTraitor" & #27 & "[0;34m [" & #27 & 
"[1;36m1" & #27 & "[0;34m]"
Robber bait
#27 & "[0m" & #27 & "[1;31mRobber " & #27 & "[36mbait" & #27 & "[0;34m"

Attack:
<Attack>
#27 & "[0m" & #27 & "[1;5;31m<Attack>"

Back to Top

Copyright 2002 - 2005, Chris Kent aka Traitor.  All rights reserved.  See About.html for more info.