Skip to content

Commit

Permalink
Updated mrpg.py to reference ttl instead of tonextlevel, added instal…
Browse files Browse the repository at this point in the history
…l.py to create a sample database file (will need massive changes)
  • Loading branch information
richard4339 committed Apr 22, 2012
1 parent ff911b1 commit 7f4166e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mrpg.py
Expand Up @@ -67,15 +67,15 @@ def rpg(self):
self.db.shutdown("")

class User:
def __init__(self, id, username, char_class, password, level, tonextlevel, hostname):
def __init__(self, id, username, char_class, password, level, ttl, hostname):
self.username = username
self.char_class = char_class
self.password = password
self.level = level
self.tonextlevel = tonextlevel
self.ttl = ttl
self.hostname = hostname
def render(self):
msg = "%s %s %s %i %i %s" % (self.username,self.char_class,self.password, self.level, self.tonextlevel, self.hostname)
msg = "%s %s %s %i %i %s" % (self.username,self.char_class,self.password, self.level, self.ttl, self.hostname)
return msg
class DBPool:
"""
Expand All @@ -97,8 +97,8 @@ def build_user(self, dbentries):
"""
Build user from dbentries
"""
id, username, password, level, tonextlevel, char_class, hostname = dbentries[0]
return User(id, username, char_class, password, level, tonextlevel, hostname)
id, username, password, level, ttl, char_class, hostname = dbentries[0]
return User(id, username, char_class, password, level, ttl, hostname)
def get_user_user(self, username):
"""
Build associated user object
Expand All @@ -108,11 +108,11 @@ def get_user_user(self, username):
self.build_user)
def update_user_time(self, username, time):
time = str(time)
query = 'UPDATE `users` SET tonextlevel = tonextlevel + ' + time + ' where username=?'
query = 'UPDATE `users` SET ttl = ttl + ' + time + ' where username=?'
return self.__dbpool.runQuery(query, (username,))

def register_user(self, reg_username, reg_password, reg_char_class):
query = 'INSERT INTO `users` (id,username,password,level,tonextlevel,char_class,hostname) VALUES (NULL,?,?,NULL,NULL,?,NULL)'
query = 'INSERT INTO `users` (id,username,password,level,ttl,char_class,hostname) VALUES (NULL,?,?,NULL,NULL,?,NULL)'
return self.__dbpool.runQuery(query, (reg_username, reg_password, reg_char_class))


Expand Down
58 changes: 58 additions & 0 deletions scripts/install.py
@@ -0,0 +1,58 @@
#!/usr/bin/env python

# mRPG
# https://github.com/mozor/mRPG
#
# Copyright 2012 Greg (NeWtoz@mozor.net) & Richard (richard@mozor.net);
# This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
# To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to
# Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

import os.path
import os
import shutil
import sqlite3

path = os.getcwd()
print path
db = "mrpg.db"
config = "config.cfg"

if os.path.isfile(db):
print("The database file has already been created.")
else:
open(db, "w").close()
print("The empty database file has been created.")

conn = sqlite3.connect(db)

c = conn.cursor()

# Create Users Table
c.execute('''CREATE TABLE users
(id INTEGER PRIMARY KEY, username TEXT, password TEXT, level NUMERIC, ttl NUMERIC, char_class TEXT, hostname TEXT, online INT, registration_date TEXT DEFAULT CURRENT_TIMESTAMP, last_login TEXT DEFAULT CURRENT_TIMESTAMP)''')

conn.commit()

# Create Items Table
c.execute('''CREATE TABLE items
(id INTEGER PRIMARY KEY, item_name TEXT, item_type TEXT)''')

conn.commit()

# Create Events Table
c.execute('''CREATE TABLE events
(id INTEGER PRIMARY KEY, event_name TEXT, event_type TEXT)''')

conn.commit()

# We can also close the cursor if we are done with it
c.close()

print("The database has been created.")

if os.path.isfile(config):
print("The config file has already been created.")
else:
shutil.copy2("docs/example.cfg", config)
print("Please modify config.cfg before running for the first time.")

0 comments on commit 7f4166e

Please sign in to comment.