wiki from old repository authored by Merlin's avatar Merlin
Terminal Command Overview
====
# Whats in a Terminal Command
* You can see what every Terminal Command requires by looking at the TerminalCommand abstract in the model.terminal package in GameShared
* execute()
* Every command requires a execute method. This is for doing what ever the command needs done
* formatString()
* This is for formatting the result however you need. Some commands may not use this method
* getDescription()
* This method is for forcing every command to have a description variable in it for the "man" command
* getIdentifier()
* This method is for forcing every command to have a identifier variable that holds what user needs to type in the terminal to execute the command
# Two types of Commands
* Client Side Commands
* Commands that don't require information from other servers or the datasource
* Server Side Commands
* Commands that need to query the database for information on the player or players
# Client Side Commands
* Goes in the GameClient in the model.terminal package
* The client side commands are executed in the sendMessage method in the TerminalTable Class in the view.screens.terminal package
* Some commands don't have their execute method called due to their simplicity
* Example of this is the clear command
# Server Side Commands
* Goes in the GameServer in the model.terminal package
* These commands need to use the gateways to access the database
# How the commands are stored
* The TerminalManager singleton contains a HashMap that is built using reflection in the buildHashMap method()
* There are two instances of the HashMap, one on the client and one on the server
![buildhashmap](uploads/46f499b6471516743d1157f7a0f260a9/buildhashmap.png)
The buildHashMap() method used to add the commands to the hashmap
# Sequence of how a command is executed
* When we initially get the command from the user input on the client side we check to see if the command is in the Client HashMap
* If it is in the Client side HashMap we just call the execute method on the command
* There are some exceptions. Right now those are "clear" and "date". For these we have if statements that catch them. This is explained further down.
* If it is not in the client side HashMap then we call the CommandSendTerminalText command that starts the message sequence to the server.
* It will eventually hit the CommandReceivedTerminalText command that will check the server side HashMap for the command
* Some of the commands will have arguments
* We strip the argument from the command identifier, store it as a String, and pass it into the execute
* We then check if the command is in the server HashMap
* If it is, we run its execute method
* We pass in the argument String and the playerID into the execute method
* Some commands don't need either the argument or the playerID
* You just don't use either if you don't need it
* All the execute methods return a string
* Some commands don't display anything on the terminal so they just return empty strings
* Example of this is the "cd" command. If you haven't been to the map, it returns a string that says you haven't visited that map. If you have visited the map, it just teleports you, returning an empty string
![getterminal](uploads/fd05de47eaf3207a7ea4987fa911cb24/getterminal.png)
The getTerminalCommandObject() method that returns the TerminalCommand object
Adding a Command
====
* You need to decide if you are creating a Client Side or Server Side Command
* Then you create the command in the appropriate package and have it extend the TerminalCommand Abstract
* You can then just have eclipse fill in the method signatures for you
* Make sure you create the description and identifier variables with the appropriate contents