Skip to content

Instantly share code, notes, and snippets.

@smithtrenton
Last active August 23, 2023 11:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smithtrenton/fbbcd451ceeaeb356ad6 to your computer and use it in GitHub Desktop.
Save smithtrenton/fbbcd451ceeaeb356ad6 to your computer and use it in GitHub Desktop.
import socket
import struct
import ctypes
import re
import smtplib
import math
import traceback
from urllib.request import urlopen
# Force an email?
FORCE = False
# Email constants
# NOTE: If using Gmail, then you will need to use an app-password:
# https://support.google.com/mail/answer/185833?hl=en
EMAIL_SENDER = '' # email address to send from
EMAIL_PASSWORD = '' # password to email address to send from
EMAIL_RECIPIENTS = [] # email addresses to send to
EMAIL_SERVER = 'smtp.gmail.com' # smtp server to send email through
EMAIL_PORT = 587 # smtp port to send email through
def send_email(to, subject, msg):
server = smtplib.SMTP(EMAIL_SERVER, EMAIL_PORT)
server.ehlo()
server.starttls()
server.ehlo()
server.login(EMAIL_SENDER, EMAIL_PASSWORD)
body = '\r\n'.join(['TO: %s' % ', '.join(to),
'FROM: %s' % EMAIL_SENDER,
'SUBJECT: %s' % subject,
'', msg])
try:
server.sendmail(EMAIL_RECIPIENTS, to, body)
print ('email sent')
except:
print ('error sending email')
server.quit()
# Version check constants
HTTP = 'http://'
RS3HOST = 'world1.runescape.com'
OSRSHOST = 'oldschool1.runescape.com'
EXT = '/k=3/jav_config.ws'
PORT = 43594
def get_rs3_version(start_version):
build = int(start_version - math.floor(start_version) * 10)
version = int(start_version)
page = urlopen(HTTP + RS3HOST + EXT)
src = page.read()
page.close()
pmap = re.search(B'\sparam=([\d]+)=([\S]{32})\s', src)
if pmap:
key = pmap.group(2)
if len(key) == 32:
#print('param : key = ' + str(pmap.group(1)) + ' : ' + str(key))
while (version < 1000):
if version != start_version:
build = 1
while (build < 3):
#print('checking ' + str(version) + ' ' + str(build))
sock = socket.create_connection((RS3HOST, PORT))
if sock:
sock.send(struct.pack('>bbiiBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBb',
15, 41, version, build, key[0], key[1], key[2], key[3], key[4], key[5],
key[6], key[7], key[8], key[9], key[10], key[11], key[12], key[13],
key[14], key[15], key[16], key[17], key[18], key[19], key[20], key[21],
key[22], key[23], key[24], key[25], key[26], key[27], key[28], key[29],
key[30], key[31], 0))
rec = sock.recv(1)
if rec:
res = struct.unpack('b', rec)[0]
if res != 6:
print('RS3 Version: ' + str(version) + " build " + str(build))
return float('{0}.{1}'.format(version, build))
build += 1
version += 1
return struct.pack('ii', -1, -1)
def get_osrs_version(version):
while (version < 1000):
#print('checking ' + str(version))
sock = socket.create_connection((OSRSHOST, PORT))
if sock:
sock.send(struct.pack('>bi', 15, version))
rec = sock.recv(1)
if rec:
res = struct.unpack('b', rec)[0]
if res != 6:
print('OSRS Version: ' + str(version))
return version
version += 1
def main():
try:
old_rs3 = None
old_osrs = None
msg = ''
try:
with open('rs3version') as rs3_file, open('osrsversion') as osrs_file:
print('opened version files')
old_rs3 = float(rs3_file.read())
old_osrs = int(osrs_file.read())
print('loaded versions: rs3({0}) osrs({1})'.format(old_rs3, old_osrs))
except:
print('files do not exist, will create them')
print('starting version detection at rs3:{0} and osrs:{1}'.format(old_rs3 or 1.1, old_osrs or 1))
rs3 = get_rs3_version(old_rs3 or 1.1)
osrs = get_osrs_version(old_osrs or 1)
if old_rs3 != rs3 or FORCE:
msg += 'RS3: {0}\n'.format(rs3)
if old_osrs != osrs or FORCE:
msg += 'OSRS: {0}\n'.format(osrs)
if len(msg) > 0:
msg = 'RuneScape update detected! \n{0}'.format(msg)
print('sending email:\n{0}'.format(msg))
try:
send_email(EMAIL_RECIPIENTS, 'RS Update', msg)
except Exception as e:
print('Failed to send email: {0}'.format(e))
if 'RS3' in msg:
print('storing rs3 version')
with open('rs3version', 'w') as f:
f.write(str(rs3))
if 'OSRS' in msg:
print('storing osrs version')
with open('osrsversion', 'w') as f:
f.write(str(osrs))
else:
print('no update detected')
except Exception as e:
print('Failed during update: {0}'.format(e))
traceback.print_tb(e.__traceback__)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment