Advertisement
KirillMysnik

Untitled

Nov 8th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. #!python3
  2. from ccp.constants import CommunicationMode
  3. from ccp.transmit import SRCDSClient
  4.  
  5.  
  6. class TestPluginClient(SRCDSClient):
  7.     def _message_receive_callback(self, message):
  8.         print("MESSAGE ACCEPTED: {}".format(message))
  9.         super()._message_receive_callback(message)
  10.  
  11.     def on_connection_abort(self):
  12.         print("Connection was aborted")
  13.  
  14.     def on_connected(self):
  15.         print("Connection established, setting mode to REQUEST-BASED...")
  16.         self.set_mode(CommunicationMode.REQUEST_BASED)
  17.  
  18.     def on_comm_accepted(self):
  19.         self.prompt_message()
  20.  
  21.     def on_data_received(self, data):
  22.         if data == b"OK":
  23.             print("Message was delivered successfully!")
  24.         else:
  25.             print("Failed to deliver the message")
  26.  
  27.         self.prompt_message()
  28.  
  29.     def on_comm_error(self):
  30.         print("Something went wrong on the other side...")
  31.  
  32.     def on_protocol_error(self):
  33.         print("There was a misunderstanding between CCP package we use and "
  34.               "CCP package SRCDS uses")
  35.  
  36.     def on_comm_end(self):
  37.         print("Communication has ended without errors.")
  38.  
  39.     def on_nobody_home(self):
  40.         print("Receiving plugin has been unloaded (or was not loaded at all)")
  41.  
  42.     def prompt_message(self):
  43.         message = input("Enter the message (leave empty to quit): ")
  44.         if not message:
  45.             self.stop()
  46.  
  47.         else:
  48.             self.send_data(message.encode('utf-8'))
  49.  
  50.  
  51. test_plugin_client = TestPluginClient(('127.0.0.1', 28080), 'ccp_admin_chat')
  52. test_plugin_client.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement