From: <Blu...@us...> - 2009-12-19 20:59:38
|
Revision: 327 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=327&view=rev Author: BlueWolf_ Date: 2009-12-19 20:59:27 +0000 (Sat, 19 Dec 2009) Log Message: ----------- A login-error will now go through {"error": {...}} instead of login. Added a callback so the app can now block users or bots Modified Paths: -------------- trunk/server/core/callback.py trunk/server/core/parser.py trunk/server/core/server.py Modified: trunk/server/core/callback.py =================================================================== --- trunk/server/core/callback.py 2009-12-18 19:33:06 UTC (rev 326) +++ trunk/server/core/callback.py 2009-12-19 20:59:27 UTC (rev 327) @@ -153,11 +153,11 @@ def check_login(self, usr, pwd): """ This is used to verify the user's login. Return the real - username* when it's correct and False else if it's not. This function will - return False by default. + username* when it's correct and False when it's not. This + function will return False by default. * This is in case you decide to not make the username case - intensive + intensive. Now the clients knows the real username usr: The username @@ -169,3 +169,32 @@ """ return False + + def may_login(self, username, ip, bot, bots): + """ + This is called after (a succesfull) callback.check_login. Use + this to block certain users or IP's or block an additional bot + when the users reached the limit of connected bots. + + Return True when the user (or bot) may log in and False when it + may not. This will send an "not allowed" error. If you wish to + send an other error, return the error. An example may be: + * "login not allowed" + * "bot limit reached" + * "login blocked" + This function will return True by default. + + username: + The username for this user + ip: + The IP-adress this user has + bot: + If it wants to log in as a bot (True/False) + bots: + List with the cids of all active active bots for this + user. + + This is a placeholder. If you want to catch this event, + overwrite this in your own callback. + """ + return True Modified: trunk/server/core/parser.py =================================================================== --- trunk/server/core/parser.py 2009-12-18 19:33:06 UTC (rev 326) +++ trunk/server/core/parser.py 2009-12-19 20:59:27 UTC (rev 327) @@ -60,7 +60,7 @@ # Decrypt the password pwd = rsa.decrypt(msg['pwd'], client['rsa']) - # Double sha, so n one can insert a "raw" sha + # Double sha, so no one can insert "raw" sha pwd = hashlib.sha1(pwd).hexdigest() if msg['for'] == 'VP': @@ -70,13 +70,34 @@ if username == False: # No login, bad user! - data.send("login", { - "succeed": False, - "reason": "bad login" - }) - return; + data.send("error", {"reason":"bad login"}) + return + + + + # Find out how many bots this user has running + bots = [] + for id, client in self.clients.items(): + if client['status'] == 'VP' and \ + client['user'] == username and \ + client['bot'] == True: + bots.append(id) + + # Check if the user may log in + may_login = self.callback.may_login(username, + data.get_ip(), msg['bot'], bots) + + if may_login != True: # User may not login + if may_login == False: + reason = "login not allowed" + else: + reason = may_login + data.send("error", {"reason":reason}) + return + + if msg['bot'] == False: # Just an ordinary user # Check if the user is already logged in @@ -96,10 +117,10 @@ client['status'] = "VP" data.send("login", { - "succeed": True, "username": username, "cid": cid }) else: # Client is bot pass #TODO + Modified: trunk/server/core/server.py =================================================================== --- trunk/server/core/server.py 2009-12-18 19:33:06 UTC (rev 326) +++ trunk/server/core/server.py 2009-12-19 20:59:27 UTC (rev 327) @@ -331,6 +331,13 @@ try: self.__sock.send(data + chr(1)) except: pass + + def get_ip(self): + """ + Get the client's IP-adress + """ + + return self.__sock.getpeername()[0] class ConnectionError(Exception): pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |