[SCRIPT] Statistics in a flat-file db.

Intended for use on live public servers.
4 posts Page 1 of 1 First unread post
Architektor_kun
League Participant
League Participant
Posts: 8
Joined: Tue Feb 26, 2013 1:32 pm


So, i just made a script, which stores all players, who ever visited your server, and their amount of kills. I know flat-file db is ugly, and it also may have tons of bugs. You can parse this file to your website to make a real-time top100,500,15,10,etc.

So, here is the script itself, report bugs in thread please(and yeah, you need to create empty file data.txt in your server folder manually):
upd. Oh guys sorry, script seems to work improperly :< Ill fix it soon
db.py
Code: Select all

from pyspades.constants import *

def apply_script(protocol, connection, config):
  class DbConnection(connection):
    def on_login(self, name):
      name_exist = 0
      lnum = 0
      nick = name.split()
      if len(nick) > 1:
        nick = '_'.join(nick)
        print nick
      else:
        nick = ''.join(nick)
      with open('data.txt', 'r') as db:
        for line in db:
          lnum += 1
          if lnum > 1:
            namesplitted = line.split()
            truename = namesplitted[0]
            if truename == str(nick):      
              name_exist = 1
              print str(name).upper() + ' logged in. Name exist is database.'
      with open('data.txt', 'a') as db:
        if not name_exist:
          db.write('\n'+str(nick)+' 0')
          print 'New player '+ str(nick).upper() + ' added to databse.'
      connection.on_login(self,name)
    def on_kill(self,killer,type, grenade):
      if killer is not None and self.team is not killer.team and self != killer:
        lnum2 = 0
        knick = killer.name.split()
        if len(knick) > 1:
          knick = '_'.join(knick)
        else:
          knick = ''.join(knick)
      if killer is not None and self.team is not killer.team and self != killer:
        with open('data.txt', 'r') as db:
          for line in db:
            lnum2 += 1
            if lnum2 > 1:
              namesplitted = line.split()
              nick = namesplitted[0]
              kills = namesplitted[1]
              i = int(kills)
              if nick == str(nick):
                del namesplitted[1]
                i += 1
                namesplitted.insert(1,str(i))
                print namesplitted
                x = ' '.join(namesplitted)
                print x
                break
          with open('data.txt', 'r') as db:
            old = db.read()
            print knick+' '+kills
            new = old.replace(knick+' '+kills, x)
            print new
          with open('data.txt', 'w') as db:
            db.write(new)
      connection.on_kill(self,killer,type,grenade)
         
  return protocol, DbConnection
[BP]Mininao
Deuce
Posts: 13
Joined: Thu Dec 27, 2012 12:13 pm


Looks nice !
I'll give it a try Blue_BigSmile
Blitz
Deuced Up
Posts: 37
Joined: Wed Feb 27, 2013 4:26 am


I really expected to see this script working but it doesn't work... :(

can U plz fix it? I rly want to use this script :q
learn_more
Coder
Coder
Posts: 891
Joined: Sun Mar 24, 2013 9:59 pm


Blitz wrote:
I really expected to see this script working but it doesn't work... :(

can U plz fix it? I rly want to use this script :q
maybe you should tell what doesnt work?

or un-lazy and fix it yourself...
4 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 0 guests