Skip to content
MedicAlert edited this page Oct 9, 2014 · 3 revisions

###Class Purpose:

Exposes low-level APIs from socket in order to connect to a TCP port and send/receive packets in TCP protocol

###Functions:

__init__ (self, IP, PORT, BUFFER, RCONPW, SERVER = socket.socket(socket.AF_INET, socket.SOCK_STREAM))

Description: This function is ran during the initialization (hence the abbreviation "init"). During initialization, the IP address, port number, buffer amount, and RCON password are taken from the parameter. The parameter value of SERVER is set equal to an internal variable called "s"

#For callbacks
variable = TCPBARE(ip, port, 9999, "Jabaltra")
#etc. etc.
  • connect(self)

Description: This function establishes a connection to certain RCON-enabled server. IP Address and Port numbers are sensitive and should be typed with precision. It returns whether or not it succeeded in connecting, and it prints out "Connecting..." as it tries to connect, and it prints out whatever exception is thrown if something went wrong in the connection.

#Referring to variable set to TCPBARE
_isconnected = variable.connect()
print(_isconnected)
# >> Connecting...
# >> OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
# >> Or some other stupid Exception caused by an "O" instead of an "0" ¯\_(ツ)_/¯
# >> False
  • close(self)

Description: This function closes the current TCP connection. It does not return any value.

# Referring to variable set to TCPBARE and connected successfully
variable.close()
# Oh well, that was a great session...
  • auth(self)

Description: Authorizes connection to RCON port with the provided RCON password. MD5 encryption includes the seed and the password. hashlib requires seed+pw to be encoded into a supported type; Data sent to and fore are encoded in bytes by default. Use decode("type") to convert to usable string.

# Referring to variable set to TCPBARE and needs to be auth.
_isauthed = variable.auth()
print(_isauthed)
# >> True
  • send(self, command)

Description: Sends command parameter through the connected socket. Prefixed 0x02 for server response ending in 0x04.Recommended function for sending RCON commands. Also uses read function to return output.

# Referring to variable set to TCPBARE and is connected
_holder = variable.send("exec sv.servername")
print(_holder)
# >> Soviet's Red Fraction
  • debug_send_(self, command="NULL")

Description: NOT INTENDED FOR PRODUCTION USE Same documentation as send function but does not incorporate the prefix character.

#Referring to variable set to TCPBARE and you don't need the prefix (for some reason...)
_debugger = variable.debug_send_(command="exec sv.servername")
print(_debugger)
# >> Soviet's Red Fraction
  • read(self)

Description: **NOT RECOMMENDED FOR EXTERNAL USE. This function is used within the send function to return a seamless output. It returns a variable called data in a string format (ALWAYS). It is up to the user to convert variables they themselves send and receive by themselves

# Referring to variable set to TCPBARE and you have a send function w/o the read
variable.send("exec sv.servername")
_output = variable.read()
print(_output)
# >>Soviet's Red Fraction

""" HOW IT IS IN THE SEND FUNCTION:
#s refers to socket's inherit send function
self.s.send(encodepack)
return self.read()
"""
  • cleanup(self, inputparam)

Description: NOT INTENDED FOR EXTERNAL USE This function removes the appended character that is tacked onto the end of each output (\n\x04). Returns inputparam after removing that appendage.

#Inside variable.read
#Pretend "data" has the string "Soviet's Red Fraction\n\0x04"
data = cleanup(data)
print(data)
# >> Soviet's Red Fraction

"""
Now you may ask, "What's the big deal, you incessent nerd?"
Well, first off, it's not nice calling people names, but the big problem
with that ending is that it disrupts any single outputs that need to be
converted.

So, without cleanup, commands like "exec sv.ranked" (which returns a 1
or a 0) would FAIL when either testing for a bool or an int because
of that \n\0x04

###Importing:

from RCONBase import TCPBARE
#or from RCONBase import*

###Classes

###Files

Clone this wiki locally