Skip to content

Commit

Permalink
v1.5.1: fix !pasetnextmap, !pamap, !papublic. randnum can be used eve…
Browse files Browse the repository at this point in the history
…n if dictionnary is not used for !papublic
  • Loading branch information
Courgette authored and markweirath committed Oct 28, 2009
1 parent fa23ea4 commit 53b7946
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
5 changes: 3 additions & 2 deletions extplugins/conf/poweradminurt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@
<set name="g_password">secret</set>
<!-- if randnum is greater than 0, then randnum numbers will be added to the password -->
<set name="randnum">0</set>
<!-- dicfile must be a text file containing one password per line -->
<set name="dicfile">dicfile.txt</set>
<!-- dicfile must be a text file containing one password per line.
Note: @conf is the directory where b3.xml is located -->
<set name="dicfile">@conf/dicfile.txt</set>
</settings>

<pamatch_plugins_disable>
Expand Down
3 changes: 3 additions & 0 deletions extplugins/dicfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
secret
war
youknow
44 changes: 29 additions & 15 deletions extplugins/poweradminurt.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,24 @@
# /!\ REQUIRES B3 v1.2.1 /!\
# * add !pamap which works with partial map names
# * update !pasetnextmap to work with partial map names
# 27/10/2009 - 1.5.1 - Courgette
# * debug !pamap and !pasetnextmap
# * debug dictionnary use for !papublic
# * !papublic can now use randnum even if dictionnary is not used

__version__ = '1.4.3'
__version__ = '1.5.1'
__author__ = 'xlr8or'

import b3, time, thread, threading, re
import b3.events
import b3.plugin
import b3.cron
from b3.functions import soundex, levenshteinDistance

import os
import random
import string
import traceback

#--------------------------------------------------------------------------------------------------
class PoweradminurtPlugin(b3.plugin.Plugin):
Expand Down Expand Up @@ -405,34 +412,40 @@ def LoadMoonMode(self):

def LoadPublicMode(self):
# PUBLIC MODE SETUP
try:
self.randnum = self.config.getint('publicmode','randnum')
except:
self.randnum = 0

try:
self.pass_lines = None
padic = self.config.getboolean('publicmode','usedic')
if padic:
self.randnum = self.config.getint('publicmode','randnum')
padicfile = self.config.get('publicmode','dicfile')
padicfile = self.config.getpath('publicmode','dicfile')
self.debug('trying to use password dictionnary %s' % padicfile)
if os.path.exists(padicfile):
stinfo = os.stat(padicfile)
if stinfo.st_size > self._max_dic_size:
self.warn('The dictionary file is too big. Switching to default.')
self.warning('The dictionary file is too big. Switching to default.')
else:
dicfile = open(padicfile)
text = dicfile.read().strip()
dicfile.close()
if text == "":
self.warn('Dictionary file is empty. Switching to default.')
self.warning('Dictionary file is empty. Switching to default.')
else:
self.pass_lines = text.splitlines()
self.debug('Using dictionary password.')
else:
self.warn('Dictionary is enabled but the file doesn\'t exists. Switching to default.')
self.warning('Dictionary is enabled but the file doesn\'t exists. Switching to default.')
except:
traceback.print_exc()
self.debug('Cannot load dictionary config. Using default')

try:
self._papublic_password = self.config.get('publicmode', 'g_password')
if self._papublic_password is None:
self.warn('Can\'t setup papublic command because there is no password set in config')
self.warning('Can\'t setup papublic command because there is no password set in config')
except:
self._papublic_password = None
self.debug('Can\'t setup papublic command because there is no password set in config')
Expand Down Expand Up @@ -1114,22 +1127,23 @@ def cmd_papublic(self, data, client, cmd=None):
self.console.setCvar( 'g_password', '' )
self.console.say('^7public mode: ^2ON')
elif data == 'off':
newpassword = self._papublic_password
if self.pass_lines is not None:
i = random.randint(0,len(self.pass_lines)-1)
self._papublic_password = self.pass_lines[i]
newpassword = self.pass_lines[i]

for i in range(0,self.randnum):
self._papublic_password += str(random.randint(1,9))
self.debug('Private password set to: %s' % self._papublic_password)
for i in range(0,self.randnum):
newpassword += str(random.randint(1,9))

self.debug('Private password set to: %s' % newpassword)

if self._papublic_password is None:
if newpassword is None:
client.message('^4ERROR :^7 can\'t set public mode off because there is no password specified in the config file')
return False
else:
self.console.setCvar( 'g_password', '%s' % (self._papublic_password) )
self.console.setCvar( 'g_password', '%s' % (newpassword) )
self.console.say('^7public mode: ^9OFF')
client.message('^7password is \'^4%s^7\''% (self._papublic_password))
client.message('^7password is \'^4%s^7\''% (newpassword))
client.message('^7type ^5!mapreload^7 to apply change')
self.console.write('bigtext "^7Server going ^3PRIVATE^7 soon !!"')
return True
Expand Down

0 comments on commit 53b7946

Please sign in to comment.