<commit_before># redpill.py PSO2Proxy plugin
# For use with redpill.py flask webapp and website for packet logging and management
import sqlite

dbLocation = '/var/pso2-www/redpill/redpill.db'

#TODO<commit_msg>Add whitelist to redpill plugin<commit_after># redpill.py PSO2Proxy plugin
# For use with redpill.py flask webapp and website for packet logging and management
import sqlite, plugins

dbLocation = '/var/pso2-www/redpill/redpill.db'
enabled = False

if enabled:
	@plugins.onStartHook
	def redpillInit():
		print("[Redpill] Redpill initilizing with database %s." % dbLocation)

	@plugins.packetHook(0x11, 0x0)
	def loginPacketHook(context, packet):
		username = packet[0x8:0x48].decode('utf-8')
		username = username.rstrip('\0')
		if not user_exists(username):
			context.loseConnection()
			print("[Redpill] %s is not in the whitelist database. Hanging up." % username)

	@plugins.onConnectionHook
	def registerClient(client):
		pass

	@plugins.onConnectionLossHook
	def archivePackets(client):
		pass

	def getConn():
		conn = sqlite3.connect(dbLocation)
		conn.row_factory = sqlite3.Row
		return conn

	def user_exists(username):
		con = getConn()
		with con:
			cur = con.cursor()
			cur.execute("select * from users where username = ? COLLATE NOCASE", (username, ))
			check = cur.fetchone()
			if check == None:
				return False
			else:
				return True
{'fraction_non_alphanumeric': 0.10445580715850986, 'fraction_numerical': 0.013148283418553688, 'mean_word_length': 4.48, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7116065', 'n_tokens_mistral': 499, 'n_tokens_neox': 454, 'n_words': 127}