mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-10-30 16:27:54 +00:00
The game now allows you in, and pulled Jumble's ssl, ban, and chat changes.
This commit is contained in:
parent
5f431480d2
commit
5018215e74
4 changed files with 90 additions and 32 deletions
|
@ -1,6 +1,6 @@
|
|||
from direct.directnotify import DirectNotifyGlobal
|
||||
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequest
|
||||
import datetime
|
||||
import time
|
||||
from direct.fsm.FSM import FSM
|
||||
from direct.distributed.PyDatagram import PyDatagram
|
||||
from direct.distributed.MsgTypes import *
|
||||
|
@ -22,9 +22,9 @@ class BanFSM(FSM):
|
|||
self.accountId = None
|
||||
self.avName = None
|
||||
|
||||
def performBan(self, bannedUntil):
|
||||
executeHttpRequest('accounts/ban/', Id=self.accountId, Release=bannedUntil,
|
||||
Reason=self.comment)
|
||||
def performBan(self, duration):
|
||||
executeHttpRequest('ban', username=self.accountId, start=int(time.time()),
|
||||
duration=duration, reason=self.comment, bannedby='todo')
|
||||
|
||||
def ejectPlayer(self):
|
||||
av = self.air.doId2do.get(self.avId)
|
||||
|
@ -49,15 +49,9 @@ class BanFSM(FSM):
|
|||
if not self.accountId:
|
||||
return
|
||||
|
||||
date = datetime.date.today()
|
||||
if simbase.config.GetBool('want-bans', True):
|
||||
if self.duration == 0:
|
||||
bannedUntil = "0000-00-00" # Terminated.
|
||||
else:
|
||||
bannedUntil = date + datetime.timedelta(days=self.duration)
|
||||
|
||||
self.performBan(self.duration)
|
||||
self.duration = None
|
||||
self.performBan(bannedUntil)
|
||||
|
||||
def getAvatarDetails(self):
|
||||
av = self.air.doId2do.get(self.avId)
|
||||
|
@ -143,4 +137,4 @@ def ban(reason, duration):
|
|||
if reason not in ('hacking', 'language', 'other'):
|
||||
return "'%s' is not a valid reason." % reason
|
||||
simbase.air.banManager.ban(target.doId, duration, reason)
|
||||
return "Banned %s from the game server!" % target.getName()
|
||||
return "Banned %s from the game server!" % target.getName()
|
|
@ -773,9 +773,34 @@ class ToontownRPCHandler(ToontownRPCHandlerBase):
|
|||
oldFields = {'setWishNameState': 'PENDING'}
|
||||
return self.rpc_updateObject(
|
||||
avId, 'DistributedToonUD', newFields, oldFields=oldFields)
|
||||
|
||||
|
||||
@rpcmethod(accessLevel=MODERATOR)
|
||||
def rpc_setChatSettings(self, accId, chatSettings):
|
||||
def rpc_getChatSettings(self, accId):
|
||||
"""
|
||||
Summary:
|
||||
Retrieves the chat settings of the account associated with the provided
|
||||
[accId].
|
||||
|
||||
Parameters:
|
||||
[int accId] = The ID of the account whose chat settings
|
||||
are to be retreived.
|
||||
|
||||
Example response:
|
||||
On success: [uint8[sp+, tf]]
|
||||
On failure: False
|
||||
"""
|
||||
dclassName, fields = self.rpc_queryObject(int(accId))
|
||||
if dclassName == 'Account':
|
||||
if 'CHAT_SETTINGS' in fields:
|
||||
return fields['CHAT_SETTINGS']
|
||||
# The chat settings haven't been set yet, so we'll
|
||||
# want to do that now.
|
||||
self.rpc_setChatSettings(accId)
|
||||
return [1, 1]
|
||||
return False
|
||||
|
||||
@rpcmethod(accessLevel=MODERATOR)
|
||||
def rpc_setChatSettings(self, accId, speedChatPlus = 1, trueFriends = 1):
|
||||
"""
|
||||
Summary:
|
||||
Sets the chat settings of the account associated with the provided
|
||||
|
@ -791,4 +816,5 @@ class ToontownRPCHandler(ToontownRPCHandlerBase):
|
|||
On success: True
|
||||
On failure: False
|
||||
"""
|
||||
return self.rpc_updateObject(accId, 'AccountUD', {'CHAT_SETTINGS': chatSettings})
|
||||
return self.rpc_updateObject(accId, 'AccountUD', {'CHAT_SETTINGS':
|
||||
[int(speedChatPlus), int(trueFriends)]})
|
|
@ -1,22 +1,31 @@
|
|||
import json
|
||||
import os
|
||||
import requests
|
||||
import json, os, sys
|
||||
import urllib, urllib2, cookielib, socket
|
||||
from panda3d.core import *
|
||||
|
||||
|
||||
req_version = (2,7,9)
|
||||
cur_version = sys.version_info
|
||||
if cur_version < req_version:
|
||||
print 'Your version of python is too old. Please upgrade to 2.7.9.'
|
||||
sys.exit()
|
||||
|
||||
username = os.environ['ttsUsername']
|
||||
password = os.environ['ttsPassword']
|
||||
distribution = 'qa'
|
||||
|
||||
accountServerEndpoint = 'http://www.toontownstride.com/api/'
|
||||
session = requests.Session()
|
||||
csrf_query = session.get(accountServerEndpoint + 'login/')
|
||||
csrf = session.cookies.get_dict().get('csrftoken', '')
|
||||
request = session.post(
|
||||
accountServerEndpoint + 'login/',
|
||||
data={'username': username, 'password': password, 'csrfmiddlewaretoken': csrf})
|
||||
accountServerEndpoint = 'https://toontownstride.com/api/'
|
||||
|
||||
data = urllib.urlencode({'username': username, 'password': password, 'distribution': distribution})
|
||||
cookie_jar = cookielib.LWPCookieJar()
|
||||
cookie = urllib2.HTTPCookieProcessor(cookie_jar)
|
||||
opener = urllib2.build_opener(cookie)
|
||||
req = urllib2.Request(accountServerEndpoint + 'login', data,
|
||||
headers={"Content-Type" : "application/x-www-form-urlencoded"})
|
||||
req.get_method = lambda: "POST"
|
||||
_response = opener.open(req).read()
|
||||
|
||||
try:
|
||||
response = json.loads('{'+request.text.split('{', 1)[1]) # so that we ignore the csrf token
|
||||
response = json.loads(_response)
|
||||
except ValueError:
|
||||
print "Couldn't verify account credentials."
|
||||
else:
|
||||
|
@ -27,4 +36,4 @@ else:
|
|||
os.environ['TTS_GAMESERVER'] = response['gameserver']
|
||||
|
||||
# Start the game:
|
||||
import toontown.toonbase.ToontownStart
|
||||
import toontown.toonbase.ToontownStart
|
|
@ -16,6 +16,7 @@ from panda3d.core import *
|
|||
import hashlib, hmac, json
|
||||
import anydbm, math, os
|
||||
import urllib2, time, urllib
|
||||
import cookielib, socket
|
||||
|
||||
def rejectConfig(issue, securityIssue=True, retarded=True):
|
||||
print
|
||||
|
@ -72,16 +73,21 @@ minAccessLevel = config.GetInt('min-access-level', 100)
|
|||
def executeHttpRequest(url, **extras):
|
||||
# TO DO: THIS IS QUITE DISGUSTING
|
||||
# MOVE THIS TO ToontownInternalRepository (this might be interesting for AI)
|
||||
##### USE PYTHON 2.7.9 ON PROD WITH SSL AND CLOUDFLARE #####
|
||||
_data = {}
|
||||
if len(extras.items()) != 0:
|
||||
for k, v in extras.items():
|
||||
_data[k] = v
|
||||
signature = hashlib.sha512(json.dumps(_data) + apiSecret).hexdigest()
|
||||
data = urllib.urlencode({'data': json.dumps(_data), 'hmac': signature})
|
||||
req = urllib2.Request('http://www.toontownstride.com/api/' + url, data)
|
||||
cookie_jar = cookielib.LWPCookieJar()
|
||||
cookie = urllib2.HTTPCookieProcessor(cookie_jar)
|
||||
opener = urllib2.build_opener(cookie)
|
||||
req = urllib2.Request('https://toontownstride.com/api/' + url, data,
|
||||
headers={"Content-Type" : "application/x-www-form-urlencoded"})
|
||||
req.get_method = lambda: "POST"
|
||||
try:
|
||||
return urllib2.urlopen(req).read()
|
||||
return opener.open(req).read()
|
||||
except:
|
||||
return None
|
||||
|
||||
|
@ -182,7 +188,7 @@ class DeveloperAccountDB(AccountDB):
|
|||
'notAfter': 0},
|
||||
callback)
|
||||
|
||||
class RemoteAccountDB(AccountDB):
|
||||
class RemoteAccountDB:
|
||||
# TO DO FOR NAMES:
|
||||
# CURRENTLY IT MAKES n REQUESTS FOR EACH AVATAR
|
||||
# IN THE FUTURE, MAKE ONLY 1 REQUEST
|
||||
|
@ -190,6 +196,8 @@ class RemoteAccountDB(AccountDB):
|
|||
# ^ done, check before removing todo note
|
||||
notify = directNotify.newCategory('RemoteAccountDB')
|
||||
|
||||
def __init__(self, csm):
|
||||
self.csm = csm
|
||||
|
||||
def addNameRequest(self, avId, name, accountID = None):
|
||||
username = avId
|
||||
|
@ -248,13 +256,34 @@ class RemoteAccountDB(AccountDB):
|
|||
raise ValueError('Invalid hash.')
|
||||
|
||||
token = json.loads(token.decode('base64')[::-1].decode('rot13'))
|
||||
|
||||
except:
|
||||
resp = {'success': False}
|
||||
callback(resp)
|
||||
return resp
|
||||
|
||||
return AccountDB.lookup(self, token, callback)
|
||||
return self.account_lookup(token, callback)
|
||||
|
||||
def account_lookup(self, data, callback):
|
||||
data['success'] = True
|
||||
data['accessLevel'] = max(data['accessLevel'], minAccessLevel)
|
||||
data['accountId'] = int(data['accountId'])
|
||||
|
||||
callback(data)
|
||||
return data
|
||||
|
||||
def storeAccountID(self, userId, accountId, callback):
|
||||
r = executeHttpRequest('associateuser', username=str(userId), accountId=str(accountId))
|
||||
try:
|
||||
r = json.loads(r)
|
||||
print r
|
||||
if r['success']:
|
||||
callback(True)
|
||||
else:
|
||||
self.notify.warning('Unable to associate user %s with account %d, got the return message of %s!' % (userId, accountId, r['error']))
|
||||
callback(False)
|
||||
except:
|
||||
self.notify.warning('Unable to associate user %s with account %d!' % (userId, accountId))
|
||||
callback(False)
|
||||
|
||||
|
||||
# --- FSMs ---
|
||||
|
|
Loading…
Reference in a new issue