<commit_before>/**
 * Created by <NAME> on 2015/1/5.
 */
var handlerMgr = require("./../handlerMgr");
var consts = require("../../../util/consts");
var pomelo = require('pomelo');
var util = require('../../../util/util');
var rival_vs_title_json = require('../../../../config/rival_vs_title');
var async = require('async');

handlerMgr.handler(consts.TYPE_MSG.TYPE_RANK_INFO_FOR_PVP, function (msg, session, next) {
    var channel = msg.channel;
    var version = msg.version;
    var device_guid = msg.deviceid;
    var type = msg.type;
    var expend_tracks = 0;
    var pvp_switch = 1;
    var server_msg;
    var is_exist = false;
    var championship_id = util.getWeek(new Date());
    var rank_pvp_wrapper = pomelo.app.get("rank_pvp_wrapper");
    async.waterfall([
            function (callback) {
                switch (type) {
                    case "set":
                    {
                        var rank_info = {
                            channel: channel,
                            version: version,
                            nickname: msg.nickname,
                            device_guid: device_guid,
                            area: msg.area,
                            phone_number: msg.phone_number,
                            championship_id: championship_id,
                            car: 28,
                            car_lv: 0,
                            racer: 0,
                            racer_lv: 0,
                            strength: 280,
                            score: 0,
                            score_weekly: 0,
                            total_race: 0,
                            total_win: 0,
                            //  reversed , to avoid cheat
                            blocked: 0
                        };
                        rank_pvp_wrapper.set_rank_info(device_guid, rank_info,function(reply){});
                        is_exist = true;
                        callback(null, rank_info);
                        break;
                    }
                    case "get":
                    {
                        rank_pvp_wrapper.get_rank_info(device_guid, function (rank_info) {
                            if (rank_info) {
                                is_exist = true;
                                rank_info = JSON.parse(rank_info);
                                //  set car and drive
                                rank_info.car = msg.car;
                                rank_info.racer = msg.driver;
                            }
                            callback(null, rank_info);
                            if(rank_info){
                                rank_pvp_wrapper.set_rank_info(device_guid, rank_info,function(reply){});
                            }
                        });
                        break;
                    }
                    case "update":
                    {
                        rank_pvp_wrapper.update_rank_info(device_guid, msg.area, msg.phone_number, msg.nickname,function (rank_info) {
                            if(rank_info){
                                is_exist = true;
                            }
                            callback(null, rank_info);
                        });
                        break;
                    }
                }
            },
            function (rank_info, callback) {
                var activity_wrapper = pomelo.app.get('activity_wrapper');
                var activity = {};
                activity_wrapper.get(channel, version, function (activity_json) {
                    for (var v in activity_json) {
                        if (consts.TYPE_ACTIVITY.TYPE_PVP == parseInt(activity_json[v].type)) {
                            activity = activity_json[v];
                        }
                    }
                    expend_tracks = activity.expend_tracks;
                    server_msg = activity.server_msg;
                    var version_fix_flag = rank_pvp_wrapper.compare_version(version);
                    pvp_switch = activity.switch;
                    var degree;
                    var degree_title;
                    var buff_desc;
                    var buff_data;
                    var degree_next;<commit_msg>update true/false for 0/1<commit_after>/**
 * Created by <NAME> on 2015/1/5.
 */
var handlerMgr = require("./../handlerMgr");
var consts = require("../../../util/consts");
var pomelo = require('pomelo');
var util = require('../../../util/util');
var rival_vs_title_json = require('../../../../config/rival_vs_title');
var async = require('async');

handlerMgr.handler(consts.TYPE_MSG.TYPE_RANK_INFO_FOR_PVP, function (msg, session, next) {
    var channel = msg.channel;
    var version = msg.version;
    var device_guid = msg.deviceid;
    var type = msg.type;
    var expend_tracks = 0;
    var pvp_switch = 1;
    var server_msg;
    var is_exist = 0;
    var championship_id = util.getWeek(new Date());
    var rank_pvp_wrapper = pomelo.app.get("rank_pvp_wrapper");
    async.waterfall([
            function (callback) {
                switch (type) {
                    case "set":
                    {
                        var rank_info = {
                            channel: channel,
                            version: version,
                            nickname: msg.nickname,
                            device_guid: device_guid,
                            area: msg.area,
                            phone_number: msg.phone_number,
                            championship_id: championship_id,
                            car: 28,
                            car_lv: 0,
                            racer: 0,
                            racer_lv: 0,
                            strength: 280,
                            score: 0,
                            score_weekly: 0,
                            total_race: 0,
                            total_win: 0,
                            //  reversed , to avoid cheat
                            blocked: 0
                        };
                        rank_pvp_wrapper.set_rank_info(device_guid, rank_info,function(reply){});
                        is_exist = 1;
                        callback(null, rank_info);
                        break;
                    }
                    case "get":
                    {
                        rank_pvp_wrapper.get_rank_info(device_guid, function (rank_info) {
                            if (rank_info) {
                                is_exist = 1;
                                rank_info = JSON.parse(rank_info);
                                //  set car and drive
                                rank_info.car = msg.car;
                                rank_info.racer = msg.driver;
                            }
                            callback(null, rank_info);
                            if(rank_info){
                                rank_pvp_wrapper.set_rank_info(device_guid, rank_info,function(reply){});
                            }
                        });
                        break;
                    }
                    case "update":
                    {
                        rank_pvp_wrapper.update_rank_info(device_guid, msg.area, msg.phone_number, msg.nickname,function (rank_info) {
                            if(rank_info){
                                is_exist = 1;
                            }
                            callback(null, rank_info);
                        });
                        break;
                    }
                }
            },
            function (rank_info, callback) {
                var activity_wrapper = pomelo.app.get('activity_wrapper');
                var activity = {};
                activity_wrapper.get(channel, version, function (activity_json) {
                    for (var v in activity_json) {
                        if (consts.TYPE_ACTIVITY.TYPE_PVP == parseInt(activity_json[v].type)) {
                            activity = activity_json[v];
                        }
                    }
                    expend_tracks = activity.expend_tracks;
                    server_msg = activity.server_msg;
                    var version_fix_flag = rank_pvp_wrapper.compare_version(version);
                    pvp_switch = activity.switch;
                    var degree;
                    var degree_title;
                    var buff_desc;
                    var buff_data;
                    var degree_next;
{'fraction_non_alphanumeric': 0.08392919939045833, 'fraction_numerical': 0.005626538506622905, 'mean_word_length': 0.9207564160288159, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4555476', 'n_tokens_mistral': 2119, 'n_tokens_neox': 1984, 'n_words': 386}