Commit 03fa19c8 authored by mercury233's avatar mercury233

test geoip

parent 66fd1cd1
......@@ -18,7 +18,16 @@
"welcome": "MyCard YGOPro Server",
"update": "请更新游戏版本",
"stop": false,
"lang": "zh-cn",
"i18n": {
"auto_pick": true,
"default": "zh-cn",
"fallback": "en-us",
"map": {
"CN": "zh-cn",
"HK": "zh-cn",
"TW": "zh-cn"
}
},
"tips": {
"enabled": true,
"get": false
......
......@@ -66,22 +66,6 @@ nconf.myset = (settings, path, val) ->
target[key] = val
return
# ban a user manually and permanently
ban_user = (name) ->
settings.ban.banned_user.push(name)
nconf.myset(settings, "ban:banned_user", settings.ban.banned_user)
bad_ip=0
for room in ROOM_all when room and room.established
for player in room.players
if player and (player.name == name or player.ip == bad_ip)
bad_ip = player.ip
ROOM_bad_ip[bad_ip]=99
settings.ban.banned_ip.push(player.ip)
ygopro.stoc_send_chat_to_room(room, "#{player.name} ${kicked_by_system}", ygopro.constants.COLORS.RED)
player.destroy()
continue
return
try
cppversion = parseInt(fs.readFileSync('ygopro/gframe/game.cpp', 'utf8').match(/PRO_VERSION = ([x\dABCDEF]+)/)[1], '16')
nconf.myset(settings, "version", cppversion)
......@@ -110,6 +94,9 @@ if settings.modules.windbot.enabled
ygopro = require './ygopro.js'
roomlist = require './roomlist.js' if settings.modules.http.websocket_roomlist
if settings.modules.i18n.auto_pick
geoip = require('geoip-country-lite')
# cache users of mycard login
users_cache = {}
......@@ -152,6 +139,22 @@ ROOM_players_banned = []
ROOM_connected_ip = {}
ROOM_bad_ip = {}
# ban a user manually and permanently
ban_user = (name) ->
settings.ban.banned_user.push(name)
nconf.myset(settings, "ban:banned_user", settings.ban.banned_user)
bad_ip=0
for room in ROOM_all when room and room.established
for player in room.players
if player and (player.name == name or player.ip == bad_ip)
bad_ip = player.ip
ROOM_bad_ip[bad_ip]=99
settings.ban.banned_ip.push(player.ip)
ygopro.stoc_send_chat_to_room(room, "#{player.name} ${kicked_by_system}", ygopro.constants.COLORS.RED)
player.destroy()
continue
return
# automatically ban user to use random duel
ROOM_ban_player = (name, ip, reason, countadd = 1)->
bannedplayer = _.find ROOM_players_banned, (bannedplayer)->
......@@ -821,9 +824,19 @@ ygopro.ctos_follow 'PLAYER_INFO', true, (buffer, info, client, server)->
buffer = struct.buffer
client.name = name
client.lang=settings.modules.lang
if name == "P233"
client.lang="en-us"
if not settings.modules.i18n.auto_pick
client.lang=settings.modules.i18n.default
else
geo = geoip.lookup(client.ip)
if not geo
log.warn("fail to locate ip", client.ip)
client.lang=settings.modules.i18n.fallback
else
if lang=settings.modules.i18n.map[geo.country]
client.lang=lang
else
log.info("TMP: not in china", client.ip)
client.lang=settings.modules.i18n.fallback
return false
ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
......
// Generated by CoffeeScript 1.12.1
(function() {
var Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_validate, Room, _, addCallback, ban_user, bunyan, cppversion, crypto, date, defaultconfig, execFile, fs, get_memory_usage, http, http_server, https, https_server, list, load_dialogues, load_tips, log, moment, nconf, net, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, request, requestListener, roomlist, settings, spawn, spawnSync, url, users_cache, wait_room_start, windbot_process, ygopro, zlib;
var Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_validate, Room, _, addCallback, ban_user, bunyan, cppversion, crypto, date, defaultconfig, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, list, load_dialogues, load_tips, log, moment, nconf, net, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, request, requestListener, roomlist, settings, spawn, spawnSync, url, users_cache, wait_room_start, windbot_process, ygopro, zlib;
net = require('net');
......@@ -87,30 +87,6 @@
}
};
ban_user = function(name) {
var bad_ip, j, k, len, len1, player, ref, room;
settings.ban.banned_user.push(name);
nconf.myset(settings, "ban:banned_user", settings.ban.banned_user);
bad_ip = 0;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (room && room.established) {
ref = room.players;
for (k = 0, len1 = ref.length; k < len1; k++) {
player = ref[k];
if (player && (player.name === name || player.ip === bad_ip)) {
bad_ip = player.ip;
ROOM_bad_ip[bad_ip] = 99;
settings.ban.banned_ip.push(player.ip);
ygopro.stoc_send_chat_to_room(room, player.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
player.destroy();
continue;
}
}
}
}
};
try {
cppversion = parseInt(fs.readFileSync('ygopro/gframe/game.cpp', 'utf8').match(/PRO_VERSION = ([x\dABCDEF]+)/)[1], '16');
nconf.myset(settings, "version", cppversion);
......@@ -159,6 +135,10 @@
roomlist = require('./roomlist.js');
}
if (settings.modules.i18n.auto_pick) {
geoip = require('geoip-country-lite');
}
users_cache = {};
if (settings.modules.mycard.enabled) {
......@@ -206,6 +186,30 @@
ROOM_bad_ip = {};
ban_user = function(name) {
var bad_ip, j, k, len, len1, player, ref, room;
settings.ban.banned_user.push(name);
nconf.myset(settings, "ban:banned_user", settings.ban.banned_user);
bad_ip = 0;
for (j = 0, len = ROOM_all.length; j < len; j++) {
room = ROOM_all[j];
if (room && room.established) {
ref = room.players;
for (k = 0, len1 = ref.length; k < len1; k++) {
player = ref[k];
if (player && (player.name === name || player.ip === bad_ip)) {
bad_ip = player.ip;
ROOM_bad_ip[bad_ip] = 99;
settings.ban.banned_ip.push(player.ip);
ygopro.stoc_send_chat_to_room(room, player.name + " ${kicked_by_system}", ygopro.constants.COLORS.RED);
player.destroy();
continue;
}
}
}
}
};
ROOM_ban_player = function(name, ip, reason, countadd) {
var bannedplayer, bantime;
if (countadd == null) {
......@@ -1016,7 +1020,7 @@
});
ygopro.ctos_follow('PLAYER_INFO', true, function(buffer, info, client, server) {
var name, struct;
var geo, lang, name, struct;
name = info.name.split("$")[0];
if (_.any(settings.ban.illegal_id, function(badid) {
var matchs, regexp;
......@@ -1035,9 +1039,21 @@
struct.set("name", name);
buffer = struct.buffer;
client.name = name;
client.lang = settings.modules.lang;
if (name === "P233") {
client.lang = "en-us";
if (!settings.modules.i18n.auto_pick) {
client.lang = settings.modules.i18n["default"];
} else {
geo = geoip.lookup(client.ip);
if (!geo) {
log.warn("fail to locate ip", client.ip);
client.lang = settings.modules.i18n.fallback;
} else {
if (lang = settings.modules.i18n.map[geo.country]) {
client.lang = lang;
} else {
log.info("TMP: not in china", client.ip);
client.lang = settings.modules.i18n.fallback;
}
}
}
return false;
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment