Exemplo n.º 1
0
    def despatch(self):
        data = ng_db.instance().mine_seek()
        if data != None:
            mine_num = int(data['num'])
            mine_player_num  = len(self._mine_list)
            if mine_player_num > 0:
                every_mine_num  = int(mine_num / mine_player_num)
                remain_num = mine_num - every_mine_num * mine_player_num
                for user_id in self._mine_list:
                    user = self._mine_list[user_id]
                    user["num"] = user["num"] + every_mine_num
                if remain_num > 0:
                    ng_db.instance().remain_add_fish(remain_num)
            else:
                ng_db.instance().remain_add_fish(mine_num)

        now = time.time()
        remove_list = []
        for user_id in self._mine_list:
            user = self._mine_list[user_id]
            if user["start_time"] + MINE_TIME <= now:
                ng_db.instance().user_add_fish(user_id, user["num"])
                self._last_list[user_id] = user["num"]
                remove_list.append(user_id)

        for i in range(len(remove_list)):
            del self._mine_list[remove_list[i]]

        ng_db.instance().recharge_check()
                
        tornado.ioloop.IOLoop.instance().add_timeout(time.time() + 3, self.despatch)
Exemplo n.º 2
0
 def auction_buy(self, user_id, auction_id):
     if not auction_id in self._auction_info:
         return ng_tool.make_result(-1)
     auction = self._auction_info[auction_id]
     user = ng_db.instance().user_get(user_id)
     if user == None:
         return ng_tool.make_result(-2)
     seller_user_id = auction["user_id"]
     if user_id == seller_user_id:
         return ng_tool.make_result(-3)
     cp = self.calc_price(auction["bp"], auction["ep"], auction["duration"],
                          auction["selltime"])
     fee = int(cp * 50 / 1000)
     if cp < fee:
         cp = fee
     if user["fish"] < cp:
         return ng_tool.make_result(-4)
     ng_dress.instance().dress_transfer_app(auction["dress_id"], user_id)
     ng_db.instance().user_add_fish(user_id, -cp)
     sell_price = cp - fee
     ng_db.instance().user_add_fish(seller_user_id, sell_price)
     self.cache_auction_del(auction_id)
     ng_db.instance().auction_delete(auction_id)
     ng_db.instance().follow_delete_all(auction_id)
     return ng_tool.make_result(0)
Exemplo n.º 3
0
 def use_fish(self, user_id, num):
     num = int(num)
     if num <= 0:
         return ng_tool.make_result(-1)
     user = ng_db.instance().user_get(user_id)
     if user == None:
         return ng_tool.make_result(-1)
     if user["fish"] < num:
         return ng_tool.make_result(-2)
     ng_db.instance().user_add_fish(user_id, -num)
     return ng_tool.make_result(0)
Exemplo n.º 4
0
 def auction_cancel(self, user_id, auction_id):
     if not auction_id in self._auction_info:
         return ng_tool.make_result(-1)
     auction = self._auction_info[auction_id]
     if user_id != auction["user_id"]:
         return ng_tool.make_result(-2)
     dress_id = auction["dress_id"]
     self.cache_auction_del(auction_id)
     ng_db.instance().auction_delete(auction_id)
     ng_db.instance().follow_delete_all(auction_id)
     ng_dress.instance().dress_transfer_app(dress_id, user_id)
     return ng_tool.make_result(0)
Exemplo n.º 5
0
 def dress_transfer(self, user_id, dress_id, address):
     if not dress_id in self._dress_info:
         return ng_tool.make_result(-1)
     new_user = ng_db.instance().user_get_by_address(address)
     if new_user == None:
         return ng_tool.make_result(-2)
     new_user_id = new_user["user_id"]
     if user_id == new_user_id:
         return ng_tool.make_result(-3)
     dress = self._dress_info[dress_id]
     if dress["user_id"] != user_id:
         return ng_tool.make_result(-4)
     self.cache_dress_transfer(dress_id, new_user_id)
     ng_db.instance().dress_modify(dress_id, {"user_id" : new_user_id})
     return ng_tool.make_result(0)
Exemplo n.º 6
0
 def login(self, address, wif, name, gas):
     res = ng_db.instance().user_login(address, wif, name, gas)
     user_id = res["user_id"]
     token = self.make_token()
     self._users[user_id] = res
     self._users[user_id]["token"] = token
     return user_id, token
Exemplo n.º 7
0
 def __init__(self):
     self.TX_MIN_FEE = 5000000
     self._auction_info = {}
     self._user_auction = {}
     self._auction_sorts = []
     res = ng_db.instance().auction_get()
     for auction in res:
         user_id = auction["user_id"]
         self.cache_auction_add(user_id, auction)
     self._follow_user_auction = {}
     self._follow_auction_user = {}
     res = ng_db.instance().follow_get()
     for follow in res:
         user_id = follow["user_id"]
         auction_id = follow["auction_id"]
         self.cache_follow_add(user_id, auction_id)
Exemplo n.º 8
0
 def __init__(self):
     self._dress_info = {}
     self._user_dress = {}
     res = ng_db.instance().dress_get()
     for dress in res:
         user_id = dress["user_id"]
         self.cache_dress_add(user_id, dress)
Exemplo n.º 9
0
    def auction_start(self, user_id, dress_id, bp, ep, duration):
        bp = int(bp)
        ep = int(ep)
        duration = int(duration)
        dress = ng_dress.instance().cache_dress_get(dress_id)
        if dress == None or dress["user_id"] != user_id:
            return ng_tool.make_result(-1)
        user = ng_db.instance().user_get(user_id)
        if user == None:
            return ng_tool.make_result(-2)
        if bp < 0 or ep < 0 or bp < ep:
            return ng_tool.make_result(-3)
        if ep < self.TX_MIN_FEE:
            return ng_tool.make_result(-3)

        auction = ng_db.instance().auction_create(dress_id,
                                                  dress["dress_type"], user_id,
                                                  user["name"], bp, ep,
                                                  duration)
        self.cache_auction_add(user_id, auction)
        ng_dress.instance().dress_transfer_app(dress_id, "admin")
        return ng_tool.make_result(0)
Exemplo n.º 10
0
 def auction_follow(self, user_id, auction_id, follow):
     if not auction_id in self._auction_info:
         return ng_tool.make_result(-1)
     auction = self._auction_info[auction_id]
     user = ng_db.instance().user_get(user_id)
     if user == None:
         return ng_tool.make_result(-2)
     has_followed = self.cache_follow_has(user_id, auction_id)
     if not has_followed and follow == "1":
         auction["follow"] = auction["follow"] + 1
         ng_db.instance().acution_modify(auction_id,
                                         {"follow": auction["follow"]})
         self.cache_follow_add(user_id, auction_id)
         ng_db.instance().follow_create(user_id, auction_id)
     elif has_followed and follow == "0":
         auction["follow"] = auction["follow"] - 1
         ng_db.instance().acution_modify(auction_id,
                                         {"follow": auction["follow"]})
         self.cache_follow_del(user_id, auction_id)
         ng_db.instance().follow_delete(user_id, auction_id)
     return ng_tool.make_result(0)
Exemplo n.º 11
0
 def modify_data(self, user_id, param):
     param = json.loads(param)
     ng_db.instance().user_modify_data(user_id, param)
     return ng_tool.make_result(0)
Exemplo n.º 12
0
 def view_data(self, user_id):
     user_data = ng_db.instance().user_get_data(user_id)
     if user_data == None:
         return ng_tool.make_result(-1)
     return ng_tool.make_result(0, user_data)
Exemplo n.º 13
0
 def view(self, user_id):
     user = ng_db.instance().user_get(user_id)
     if user == None:
         return ng_tool.make_result(-1)
     return ng_tool.make_result(0, user)
Exemplo n.º 14
0
 def dress_modify(self, dress_id, dress_type):
     if not dress_id in self._dress_info:
         return ng_tool.make_result(-1)
     self._dress_info[dress_id]["dress_type"] = dress_type
     ng_db.instance().dress_modify(dress_id, {"dress_type" : dress_type})
     return ng_tool.make_result(0)
Exemplo n.º 15
0
 def dress_transfer_app(self, dress_id, user_id):
     if not dress_id in self._dress_info:
         return
     self.cache_dress_transfer(dress_id, user_id)
     ng_db.instance().dress_modify(dress_id, {"user_id" : user_id})
Exemplo n.º 16
0
 def refund_reamin(self):
     ng_db.instance().remain_refund()
     tornado.ioloop.IOLoop.instance().add_timeout(time.time() + 3600, self.refund_reamin)
Exemplo n.º 17
0
 def dress_create(self, user_id, dress_type):
     dress = ng_db.instance().dress_create(user_id, dress_type)
     self.cache_dress_add(user_id, dress)
     return ng_tool.make_result(0, dress)