ToorChat/libtoorchat.py

42 lines
1.1 KiB
Python
Raw Normal View History

2012-10-20 22:38:28 +00:00
class ToorChatProtocol():
''' This is a class to allow for easy of use with anything to do with messaging '''
def __init__(self, device):
self.PACKET_START = "\xFF\xDE\xAD\xFF"
self.PACKET_END = "\xFF\xBE\xEF\xFF"
self.device = device
2012-10-20 22:45:01 +00:00
def send_message(self, message = "", user = None):
2012-10-20 22:38:28 +00:00
''' This is used to send a simple message over the toorchat protocol '''
msg = ToorChatMessage(message, user)
2012-10-20 22:45:01 +00:00
self.device.RFxmit(msg.to_string())
2012-10-20 22:38:28 +00:00
@classmethod
def get_packet_start(cls):
return "\xFF\xDE\xAD\xFF"
@classmethod
def get_packet_end(cls):
return "\xFF\xBE\xEF\xFF"
class ToorChatMessage():
''' This is a simple Message object wrapper to make things cleaner '''
def __init__(self, message = "", user = None):
self.start = ToorChatProtocol.get_packet_start()
self.xid = self.get_random_xid()
if user != None:
self.user = user
else:
self.user = "\x00"*32
self.data = message
self.end = ToorChatProtocol.get_packet_end()
2012-10-20 22:45:01 +00:00
def get_random_xid(self):
return "44444444"
2012-10-20 22:38:28 +00:00
def __str__(self):
return self.start + self.xid + self.user + self.data + self.end
def to_string(self):
return self.__str__()