//获取玩家区服数据
var mysql = require('mysql');
var mysqlcn = require('../../terry/mysqlcn.js');
var query = mysqlcn.query;
var qs = require('querystring');
var encryption = require('../ordinary/encryption.js');
var http = require('http');

var express = require('express');
var router = express.Router();


var server_query_info = function(args,res){
    var sql = "SELECT * FROM services";
    query(sql,function(qerr,vals,fields_){
        if (qerr==null){
            len = vals.length
            var data = new Array()
            for (var i = 0;i < vals.length; ++i){
                console.log("查询服务器id:%s",vals[i].id);
                // get_player_uid(vals[i],channel,account,vals[i].id,add_server);
                data[i] = {
                    "server_id": vals[i].id,
                    "server_name": vals[i].name,
                }
				console.log("写入查询服务器id:%s",vals[i].id);
            }
            var returndata = JSON.stringify({
                'code': 0,
                'msg': "",
                'data': data,
            });
            console.log("查找mysql玩家角色服务器列表:%s",returndata);
            res.send(returndata);
        }else{
            console.log("打开mysql库中服务器列表失败");
            try{
                res.send(JSON.stringify({ 'status':'400','msg':'稍后请求'}));
            }
            catch(e){}
        }
    });
}

//获取服务器列表
router.get('/server_query_info', function(req, res) {
    try{
        console.log("[服务器列表查询] get server_query_info,host:%s, ip:%s,time:%s",req.hostname,req.ip,new Date());
		server_query_info(req.query,res);
	 }catch(err){
		 console.log(err);
		 var info = JSON.stringify({ 'state':'0'});
		 res.send(info);
     }
})

module.exports = router;
