kippykip

OSExclusive.py

Mar 22nd, 2015
339
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. OSExclusive.py
  3. Kicks a player when they join a team if they're using a client
  4. other than OpenSpades. They can still spectate.
  5.  
  6. Based on detectclient.py by noway421 (Good work man :D)
  7. Modified by Kippykip
  8. """
  9.  
  10. from pyspades.constants import *
  11. from pyspades.loaders import Loader
  12. from pyspades.bytes import ByteReader, ByteWriter
  13. from twisted.internet.reactor import callLater
  14. from commands import name, add, get_player, join_arguments, InvalidPlayer
  15. from collections import namedtuple
  16. import itertools
  17.  
  18. id_iter = itertools.count(31)  # http://github.com/yvt/openspades/commit/aa62a0
  19.  
  20. S_VANILLAKICK = 'This server is OpenSpades exclusive!' #Here's the adjustable message
  21.  
  22. class HandShakeInit(Loader):
  23.     id = id_iter.next()
  24.  
  25.     def read(self, reader):
  26.         pass
  27.  
  28.     def write(self, writer):
  29.         writer.writeByte(self.id, True)
  30.         writer.writeInt(42, True)
  31.  
  32.  
  33. class HandShakeReturn(Loader):
  34.     id = id_iter.next()
  35.  
  36.     challenge_passed = -1
  37.  
  38.     def read(self, reader):
  39.         tmp = reader.readInt(True)
  40.         if tmp == 42:
  41.             self.challenge_passed = 1
  42.         else:
  43.             self.challenge_passed = 0
  44.  
  45.     def write(self, writer):
  46.         writer.writeByte(self.id, True)
  47.  
  48.  
  49. class VersionGet(Loader):
  50.     id = id_iter.next()
  51.  
  52.     def read(self, reader):
  53.         pass
  54.  
  55.     def write(self, writer):
  56.         writer.writeByte(self.id, True)
  57.  
  58.  
  59. class VersionSend(Loader):
  60.     id = id_iter.next()
  61.  
  62.     client = ord('-')
  63.     version_major = -1
  64.     version_minor = -1
  65.     version_revision = -1
  66.     version_info = 'None'
  67.  
  68.     def read(self, reader):
  69.         self.client = reader.readByte(True)
  70.         self.version_major = reader.readByte(True)
  71.         self.version_minor = reader.readByte(True)
  72.         self.version_revision = reader.readByte(True)
  73.         self.version_info = reader.readString()
  74.  
  75.     def write(self, writer):
  76.         writer.writeByte(self.id, True)
  77.  
  78.  
  79. def apply_script(protocol, connection, config):
  80.  
  81.     class DetectclientConnection(connection):
  82.         def loader_received(self, loader):
  83.             if self.player_id is not None:
  84.                 if self.hp:  # atleast player spawned
  85.                     data = ByteReader(loader.data)
  86.                     packet_id = data.readByte(True)
  87.                     if packet_id == HandShakeReturn.id:
  88.                         handshake_return = HandShakeReturn()
  89.                         handshake_return.read(data)
  90.                         self.on_handshake_answer()
  91.                         return None
  92.                     elif packet_id == VersionSend.id:
  93.                         version_send = VersionSend()
  94.                         version_send.read(data)
  95.                         self.on_version_answer(version_send)
  96.                         return None
  97.             return connection.loader_received(self, loader)
  98.  
  99.         def on_spawn(self, pos):
  100.             self.protocol.send_contained(HandShakeInit(), save=True)
  101.             self.handshake_timer = callLater(1.4, self.handshake_timeout)
  102.             return connection.on_spawn(self, pos)
  103.  
  104.         def handshake_timeout(self):
  105.             # just assume it's vanilla
  106.             info = namedtuple(
  107.                 'Info',
  108.                 'client, version_major, version_minor, ' +
  109.                 'version_revision, version_info')
  110.             info.client = ord('a')
  111.             info.version_major = 0
  112.             info.version_minor = 75
  113.             info.version_revision = 0
  114.             info.version_info = 'Windows'
  115.             self.on_version_get(info)
  116.  
  117.         def on_handshake_answer(self):
  118.             if self.handshake_timer.active():
  119.                 self.handshake_timer.cancel()
  120.             self.protocol.send_contained(VersionGet(), save=True)
  121.  
  122.         def on_version_answer(self, info):
  123.             self.on_version_get(info)
  124.         def on_version_get(self, info):
  125.             if chr(info.client) != 'o':                                         #If you're not on OpenSpades (a = Ace Of Spades classic, o = OpenSpades)
  126.                 victim = get_player(self.protocol, '#' + str(self.player_id))   #Get the player by its ID
  127.                 victim.kick(reason = S_VANILLAKICK)                             #Kick them with the adjustable reason (S_VANILLAKICK) way above^^
  128.     class DetectclientProtocol(protocol):
  129.         def __init__(self, *arg, **kw):
  130.             return protocol.__init__(self, *arg, **kw)
  131.  
  132.     return DetectclientProtocol, DetectclientConnection
RAW Paste Data