Ejemplo n.º 1
0
    def main(self):

        config_data = ConfigUtils()
        if not config_data.validate():
            print "Error- invalid data in config file"
            logging.error("Error- invalid data in config file")

            sys.exit(1)

        self.supported_machines_list = config_data.supported_machines
        self.max_machines_limit = config_data.max_machines

        # Set up the listening socket
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        host = socket.gethostname()  # local
        try:
            s.bind((host, config_data.port))
        except socket.error as err:
            print "Error: socket error\n" + err.message
            logging.error("Error: socket error\n" + err.message)
            sys.exit(1)
        print "Server is listening on port {p}...".format(p=config_data.port)

        s.listen(30)

        # accept connections in a loop
        while True:
            (connection, address) = s.accept()
            print "Got connection"
            self.connection_lock.acquire()

            if len(self.connections) >= config_data.max_clients:
                try:
                    connection.send("Sorry, too many clients connected")
                    logging.error("Sorry, too many clients connected")
                    connection.close()
                except:
                    print "Error on closing connection"
                    logging.error("Error on closing connection")
            else:
                connection.send("Connection succeeded")
                logging.info("Connection succeeded")
                self.connections.add(connection)
                self.client_connections_map[connection] = self.clients_id_rise
                self.clients_id_rise += 1
                self.connection_lock.release()
                threading.Thread(target=self.receive, args=[connection]).start()
Ejemplo n.º 2
0
def refresh_datatable(serverid):
    filedict = {"Data": []}
    config = ConfigUtils()
    for root, dirs, files in os.walk(config.get("root_path") + "/Download/" + serverid):
        for file in files:
            try:
                if file.index(".gz") > 0:
                    continue
                if file.index("hashCode") > 0:
                    continue
            except:
                pass
            filename = root + "/" + file
            f = open(filename, "r")
            content = f.read()
            g =gzip.GzipFile(filename="", mode="wb", compresslevel=9, fileobj=open(filename+".gz", "wb"), mtime=0)
            g.write(content)
            g.close()
            zfile = open(filename+".gz", "rb")
            m = hashlib.md5()
            m.update(zfile.read())
            md5 = m.hexdigest()
            zfile.close()
            index = -1
            try:
                index = filename.index("DataTable")
                filetype = "DataTable"
            except ValueError:
                try:
                    index = filename.index("Dictionary")
                    filetype = "Dictionary"
                except ValueError:
                    continue
            finally:
                name = filename[index:].replace("\\", "/")
            if index < 0:
                continue
            filedict["Data"].append({"Name": name, "Hash": md5, "Type": filetype})
            f.close()
    f = open("".join((config.get("root_path"), "Download/", serverid, "/hashCode.txt")), "w")
    s = json.dumps(filedict)
    f.write(s)
    print s
    return s
Ejemplo n.º 3
0
import redis
import json
from xml.dom import minidom
from ConfigUtils import ConfigUtils

configs = ConfigUtils()
if configs.get("redis_pwd"):
    RedisClient = redis.Redis(host=configs.get("redis_host"),
                              port=configs.get("redis_port"),
                              db=0,
                              password=configs.get("redis_pwd"))
else:
    RedisClient = redis.Redis(host=configs.get("redis_host"),
                              port=configs.get("redis_port"),
                              db=0)
GameResourceVersionKey = "Game_Resource_Version"
GameVersionKey = "Game_Version_Info"
GameServerKey = "Game_Server_Host"
DataFilePath = configs.get("root_path") + "data/"


def get_resource_data():
    resource_data = {}
    version_data = {}
    server_list = RedisClient.hgetall(GameServerKey)
    if len(server_list) == 0 or not server_list["UpdateServer"] \
            or not server_list["CheckServerListUri"] or not server_list["LoginUri"]:
        server_list = load_game_server()
    resource_data["UpdateServer"] = server_list["UpdateServer"]
    resource_data["CheckServerListUri"] = server_list["CheckServerListUri"]
    resource_data["LoginUri"] = server_list["LoginUri"]
Ejemplo n.º 4
0
import db_manager, commands
from ConfigUtils import ConfigUtils
from pb2py import CLServerCommand_pb2, LCServerCommand_pb2
import RequestSender

db = db_manager.DBManager()
conf = ConfigUtils()
Database = conf.get('game_db')
Table = "configs"


def get_configs(serverid):
    m_conn = db.get_db(Database)
    m_conn.select_db(Database)
    m_cursor = m_conn.cursor()
    retlist = []
    m_cursor.execute("select * from " + Table + " order by Name")
    for config in m_cursor.fetchall():
        retlist.append((config[0], config[1]))
    m_cursor.close()
    m_conn.close()
    return retlist


def edit_configs(request):
    m_conn = db.get_db(Database)
    m_cursor = m_conn.cursor()
    keys = request.getlist('keys[]')
    values = request.getlist('values[]')
    for field, value in request.items():
        if field == 'keys[]':
Ejemplo n.º 5
0
 def __init__(self):
     self.configs = ConfigUtils()
     db = DBManager()
     self.conn = db.get_db(self.configs.get("master_db"))
     self.cursor = self.conn.cursor()
Ejemplo n.º 6
0
 def __init__(self):
     self.configs = ConfigUtils()
     self.__conn = MySQLdb.Connect(
         host=self.configs.get("mysql_host"),
         user=self.configs.get("mysql_user"),
         passwd=self.configs.get("mysql_password"))