99% chance I ripped it out by mistake ^_^
You'll need to know a bit about how the internet works. I am NOT explaining ports. I'm not going to explain most of the commands I do unless its some internet hackery that you don't need to know as a game server admin.
Writing it in is as simple as a check back against your thing and set the client's admin flag to true, stealth admin-ing is also useless imo, you can see I'm finicky ;) I didn't write in all dash's little bells and whistles, mainly because I see them as useless. I really do hate excess, makes the code sloppy (i hope you can tell i try to keep my code neat, or at least what i think is neat)
RANT: I hate it when people use tabs HATE IT HATE IT HATE IT screws up formatting for those who use a proper hit space 3 times (torque standard, and one I always use, even in my C++ code) plus it screws up sooo much when you're trying to format things properly in tribalIDE growl.[/rant]
Anyway, on to TCPObjects...
The basic TCPObject stuff is chatted about in the script tcpobject.cs, i don't wanna really check if i left everything there so...
The basic console functions are....
Code: Select all
connect( addr )
Purpose:
Use the connect method to request a connection to a remote agent at the address addr.
Syntax
addr – A string containing an address of the form: “A.B.C.D:Portâ€, where A .. B are standard IP numbers between 0 and 255 and Port can be between 1000 and 65536.
Returns
No return value.
Code: Select all
disconnect()
Purpose
Use the disconnect method to close a previously opened connetion without destroying the requesting TCPOpbject.
Returns
No return value.
Notes
This will close any open connection, but not destroy this object. Thus, the object can be used to open a new connection.
Code: Select all
listen( port )
Purpose
Use the listen method to allow this TCPObject to accept connections on the specified port.
Syntax
port – A value between 1000 and 65536.
Returns
No return value.
Code: Select all
send( ... )
Purpose
Use the send method to send any number of parameters, as strings, one at a time to the agent at the other end of the connection.
Syntax
... – Any number of arguments, as strings. Each string is sent separately. i.e. The arguments are not concatenated.
Returns
No return value.
Simple enough.
the basic functions you can code for are as follows:
Code: Select all
function TCPObject::onDNSResolved(%this) { }
function TCPObject::onDNSFailed(%this) { }
function TCPObject::onConnected(%this) { }
function TCPObject::onConnectFailed(%this) { }
function TCPObject::onDisconnect(%this) { }
function TCPObject::onLine(%this, %line) { }
function TCPObject::onConnectRequest(%this,%address,%tag) { }
I expanded the onDisconnect to automatically delete the object, avoid excess cleanup, as if i ever disconnect i'll probably nuke the object, since I never used it for connecting to anything other than the server. I could leave the tcpobject, name it, and use it over and over and delete it if i was done. An example use of this would be reading across a registry that was sorted by a bunch of servers. Instead of rapidly creating and deleting, you could connect to different ips through the same tcpobject as you progressed. but since I'm not doing anything very complex like that (it'd be far more efficient to use some external program for this anyway) i just delete it on disconnect....
Now say instead of my default blank online i set it to echo %line, i could do something fancy liiike...
Code: Select all
new tcpobject(tcpobj);
tcpobj.connect("www.microsoft.com:80");
This should give you two messages. The first being “DNS Resolved†and the second message should be the “Connected†message. You may also receive “DNS Failed†followed by “Connection Failedâ€. These four functions can be used to expand the capabilities of your project by automating connection retries, and handling successful connections.
You should get the echo “Connectedâ€, this will be useful for automatically performing commands on connection such as security handshakes or to make a request for information. I used the domain name, but you can manually input an IP addy if you please. ( IP addresses bypass the DNS stuff, just internet stuff)
Once we have, a connection the fifth function (online) will handle information received from the server. To see how it works we need to send something to the server to get a response to display. Since we are connected to the Microsoft web server, let us see what will happen when we request the root page by sending an HTTP GET command with the TCP Object send function.
The GET / just requests the main page (
http://www.microsoft.com/) - the \r\n though is absolutely key. That is how one calls the Carriage Return, Line Feed pair to the server. That will make the server you are connected to execute the command you just sent. On your screen, you should have seen a lot of text scroll by prefixed by “TCP:†those lines are the html text for the default webpage. Our current functions just echo the lines out prefixed by “TCP:†we could just as easily saved the lines to a file, or parsed each line looking for information, like a net browser would.
Now for the time hackery. My code is a very a simple example of a common TCP connection. It works with the Daytime Protocol on TCP port 13. More specifically, it works with the NIST (National Institute of Standards and Technology -
http://www.boulder.nist.gov) version of this protocol. The NIST code is returned in this format:
JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM
- - JJJJJ is the Modified Julian Date (MJD). The MJD is the last five digits of the Julian Date, which is simply a count of the number of days since January 1, 4713 B.C. To get the Julian Date, add 2.4 million to the MJD.
- YR-MO-DA is the date. It shows the last two digits of the year, the month, and the current day of month.
- HH:MM:SS is the time in hours, minutes, and seconds. The time is always sent as Coordinated Universal Time (UTC). An offset needs to be applied to UTC to obtain local time. For example, Mountain Time in the U. S. is 7 hours behind UTC during Standard Time, and 6 hours behind UTC during Daylight Saving Time.
- TT is a two digit code (00 to 99) that indicates whether the United States is on Standard Time (ST) or Daylight Saving Time (DST). It also indicates when ST or DST is approaching. This code is set to 00 when ST is in effect, or to 50 when DST is in effect. During the month in which the time change actually occurs, this number will decrement every day until the change occurs. For example, during the month of October, the U.S. changes from DST to ST. On October 1, the number will change from 50 to the actual number of days until the time change. It will decrement by 1 every day until the change occurs at 2 a.m. local time when the value is 1. Likewise, the spring change is at 2 a.m. local time when the value reaches 51.
- L is a one-digit code that indicates whether a leap second will be added or subtracted at midnight on the last day of the current month. If the code is 0, no leap second will occur this month. If the code is 1, a positive leap second will be added at the end of the month. This means that the last minute of the month will contain 61 seconds instead of 60. If the code is 2, a second will be deleted on the last day of the month. Leap seconds occur at a rate of about one per year. They are used to correct for irregularity in the earth's rotation. The correction is made just before midnight UTC (not local time).
- H is a health digit that indicates the health of the server. If H=0, the server is healthly. If H=1, then the server is operating properly but its time may be in error by up to 5 seconds. This state should change to fully healthy within 10 minutes. If H=2, then the server is operating properly but its time is known to be wrong by more than 5 seconds. If H=4, then a hardware or software failure has occurred and the amount of the time error is unknown.
- msADV displays the number of milliseconds that NIST advances the time code to partially compensate for network delays. The advance is currently set to 50.0 milliseconds.
- The label UTC(NIST) is contained in every time code. It indicates that you are receiving Coordinated Universal Time (UTC) from the National Institute of Standards and Technology (NIST).
- OTM (on-time marker) is an asterisk (*). The time values sent by the time code refer to the arrival time of the OTM. In other words, if the time code says it is 12:45:45, this means it is 12:45:45 when the OTM arrives.
I don't compensate for most of this, it may be needed for keeping say a computers internal clock proper, but its possible to do most conversions in your head, and I didn't bother with anything more. You could in theory synch it to a local server, but i'm not even going to touch that.
Its also very possible to expand it to access a POP3 mailbox, again useless in practical purposes.
For those of you still reading (congrats) here's some on FileObject.
First FileI/O functions
Code: Select all
expandFilename( filename )
Purpose
Use the expandFilename function to convert a relative path name to a full path name.
Syntax
filename – A string containing the relative or full path and file name of an existing or new file.
Returns
Returns a string containing the expanded path to the specified file.
expandFilename("~/data/sound/testing.wav");
Code: Select all
fileBase( filename )
Purpose
Use the fileBase function to get the name of a file from a relative or full path, not including the file extension.
Syntax
filename – A string containing the relative or full path and file name of an existing or new file.
Returns
Returns an unadorned file name without a path or file extension.
fileBase(“egt/main.csâ€); // will return “mainâ€
Code: Select all
fileExt( filename )
Purpose
Use the fileExt function to get the extension of a file from a relative or full path, not including the file extension.
Syntax
filename – A string containing the relative or full path and file name of an existing or new file.
Returns
Returns a file extension, including the dot (.).
Notes
If asterisks are present in an extension, as passed in filename, they will not be expanded in the return value.
fileExt(“script.csâ€); // will return “.csâ€
Code: Select all
fileName( filename )
Purpose
Use the fileName function to get the filename and extension of a file from a relative or full path, not including the file extension.
Syntax
filename – A string containing the relative or full path and file name of an existing or new file.
Returns
Returns a string containing the full name of a file less any path before the name.
Notes
If asterisks are present in an file name, as passed in filename, they will not be expanded in the return value.
fileName(“egt/main.csâ€); // will return “main.csâ€
Code: Select all
filePath( filename )
Purpose
Use the fileBase function to get all parts of a path up to, but not including the last slash (/).
Syntax
filename – A string containing the relative or full path and file name of an existing or new file.
Returns
Returns a string containing the relative or full path portion of filename.
Notes
If asterisks are present in any part of the path, as passed in filename, they will not be expanded in the return value.
filePath(“common/ui/defaultProfiles.csâ€); // Will return “common/uiâ€
Code: Select all
findFirstFile ( pattern )
Purpose
Use the findFirstFile function to find the first file matching pattern.
Syntax
pattern – A full or partial path, followed by a full or partial filename, or any combination of these two elements.
Returns
Returns a full path to the first file name matching pattern. Returns a NULL string, when no matches are found.
Notes
This function will search all directories in the modpath, as created by setModPaths. Each time this function is called it will reset an internal variable tracking the current position in the file list. So, multiple routines calling this in an overlapping fashion will clobber each other.
findFirstFile(“*.csâ€);
Code: Select all
findNextFile ( pattern )
Purpose
Use the findNextFile function to find the next file matching pattern.
Syntax
pattern – A full or partial path, followed by a full or partial filename, or any combination of these two elements.
Returns
Returns a full path to the next file name matching pattern. Returns a NULL string, when no matches are found.
Notes
This function will search all directories in the modpath, as created by a call to setModPaths. Also, this function requires that findNextFile be called at least with the same pattern, some time prior to calling this function.
findNextFile( “*.cs†);
Code: Select all
getFileCount ( pattern )
Purpose
Use the getFileCount function to determine how many files exist in modpaths that match the specified pattern.
Syntax
pattern – A full or partial path, followed by a full or partial filename, or any combination of these two elements.
Returns
Returns a zero if no matches are found, or a positive integer value specifying how many matches there were.
getFileCount(“*.csâ€);
Code: Select all
getFileCRC( filename )
Purpose
Use the getFileCRC function to calculate the Cyclic-Redundancy-Check (CRC) value for a file as specified by the partial or full path in filename.
Syntax
filename – A string containing the relative or full path and file name of an existing or new file.
Returns
Returns a non-zero positive integer value corresponding to this file's CRC.
Notes
CRC values are useful for checking to see if two same named files are actually the same. If a client file of the same path and name as a file on the server has a differnt CRC from the server version, then the files are NOT the same, otherwise they highly likely to be the same. Although it is theoretically possible for two non-matching files to have matching CRCs, the odds are very much against it.
getFileCRC(“/fps/client/scripts/script/csâ€);
Code: Select all
isFile( filename )
Purpose
Use the isFile function to determine whether the value in filename is in fact an existing file.
Syntax
filename – A string containing the relative or full path and file name of an existing file.
Returns
Returns true if the file exists, false otherwise.
See Also
isWriteableFileName
isFile(“/fps/client/scripts/script.csâ€);
Code: Select all
isWriteableFileName( filename )
Purpose
Use the isWriteableFileName function to determine whether the value in filename is in fact an existing file and it can be written to.
Syntax
filename – A string containing the relative or full path and file name of an existing file.
Returns
Returns true if the file exists and can be written to, false otherwise.
isWriteableFileName(“/fps/client/scripts/script.csâ€);
Using FileObject:
To begin we will look at how we can create a new FileObject
Seems simple enough doesn’t it. But let’s go over each part of the line to ensure we know what is there.
First we have a local variable named %file. This will hold the object reference to the FileObject we create. By using a local variable we limit the scope of our interaction with the FileObject to the current function we are in. The FileObject itself could be accessed globally, if you know the object reference.
Next we have the “new†statement. This tells the game engine to create a new instance of the object type that follows this command; in our case this is the FileObject. The FileObject has parenthesis following the name, this doesn’t mean this is a function, instead it allows you to give you specific instance of a FileObject a name that could be used in place of the object reference.
For example, we could use a global variable, as well as give our FileObject a name for easy reference.
Code: Select all
$file = new FileObject(“myFileâ€);
Using the FileObject
Now that we have our FileObject created. Let’s write some information to the file.
Code: Select all
%file = new FileObject();
%file.OpenForWrite(“game/test.txtâ€);
%file.writeline(“This is the test file.â€);
OK we’ve just seen two new methods the OpenForWrite method and the writeline method. OpenForWrite will open a file if it exists or it will create a new file if it doesn’t. If the file you name already has content, it will be erased. The writeline method does what it says. It writes a single line of text to a file.
If we wish to open an existing file and add to it we will use the OpenForAppend method. This works the same as the OpenForWrite, but doesn’t erase the existing content of a file.
Code: Select all
%file = new FileObject();
%file.OpenForAppend(“game/test.txtâ€);
%file.writeline(“This is the test file.â€);
Next, we may wish to read data from a file. To do so we will use the OpenForRead method. Paired with the OpenForRead method we use the readline method.
Code: Select all
%file = new FileObject();
%file.OpenForRead(“game/test.txtâ€);
%line = %file.readline();
You will see that we added a new variable named %line, we use this to store the return value from the FileObject method readline, which is the current line of the file.
Input Control
Now that we are reading in the file, we want to make sure we don’t try to read past the end of the file. So we use another method named isEOF, which returns a True value if we are at the end of the file.
Code: Select all
%file = new FileObject();
%file.OpenForRead(“game/test.txtâ€);
while( !%file.isEOF() )
{
%line = %file.readline();
echo(%line);
}
Keeping things neat:
Now that we have seen how to open, write, append and read a file… we need to learn what to do when we are done with a file. There are two things you can do. The first is to use the close method.
Code: Select all
%file = new FileObject();
%file.OpenForWrite(“game/test.txtâ€);
%file.writeline(“This is the test file.â€);
%file.close();
Once you have closed the file, you could reuse the FileObject to open a new file in a with a new method. The other option is to destroy the FileObject using the delete method.
Code: Select all
%file = new FileObject();
%file.OpenForWrite(“game/test.txtâ€);
%file.writeline(“This is the test file.â€);
%file.close();
%file.delete();
Covers just bout it all. Gratz if you read it all.
// ishy