314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
1
2
3
4
5
6
7 
 | 
  local skynet = require "skynet"
  require "skynet.manager"
  local crab = require "crab.c"
  
  local table_insert = table.insert
  local table_unpack = table.unpack
  local mode, id, dict = ...
 
 | 
10ea6c0f
 
  zhouhaihai
 
屏蔽字 优化
 | 
8
9 
 | 
  local hideCode = utf8.codepoint("*")
  
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
10
11
12
13
14
15
16
17
18 
 | 
  
  local function toutf8(name)
  	local t = {}
  	for _, v in utf8.codes(name) do
  		table_insert(t, v)
  	end
  	return t
  end
  
 
 | 
10ea6c0f
 
  zhouhaihai
 
屏蔽字 优化
 | 
19
20
21
22
23
24
25
26
27
28 
 | 
  local function fix(a, b)
  	for i, v in pairs(a) do
  		if b[i] == hideCode then
  			a[i] = hideCode
  		end
  	end
  	return utf8.char(table_unpack(a))
  end
  
  
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
29
30
31
32
33
34
35
36
37 
 | 
  if mode == "sub" then
  	local CMD = {}
  	dict = tonumber(dict)
  
  	function CMD.check(name)
  		if name:find("%c") then
  			return false
  		end
  		local utftb = toutf8(name)
 
 | 
10ea6c0f
 
  zhouhaihai
 
屏蔽字 优化
 | 
38
39
40 
 | 
  		local utftbU = toutf8(string.upper(name))
  		if crab.filter(dict, utftbU) then
  			return false, fix(utftb, utftbU)
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
41
42
43
44
45
46
47
48
49
50 
 | 
  		end
  		return true
  	end
  
  	skynet.start(function()
  		skynet.dispatch("lua", function(_, _, command, ...)
  			local f = CMD[command]
  			skynet.ret(skynet.pack(f(...)))
  		end)
  
 
 | 
a5486ede
 
  zhouhaihai
 
csvdata 修改为 share...
 | 
51 
 | 
  		skynet.register(string.format(".chated%d", id))
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
52
53
54 
 | 
  	end)
  else
  	skynet.start(function()
 
 | 
a5486ede
 
  zhouhaihai
 
csvdata 修改为 share...
 | 
55
56
57 
 | 
  		local csvdb = require "shared.csvdata"
  		local forbidNames = csvdb["forbid_chatCsv"]
  		if not forbidNames then forbidNames = {} end
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
58
59
60 
 | 
  
  		local words = {}
  		for _, data in ipairs(forbidNames) do
 
 | 
10ea6c0f
 
  zhouhaihai
 
屏蔽字 优化
 | 
61 
 | 
  			local ok, utftb = pcall(toutf8, string.upper(data.name))
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
62
63
64
65
66
67
68 
 | 
  			if ok then table.insert(words, utftb) end
  		end
  		local d = crab.open(words)
  
  		for i = 1, 5 do
  			skynet.newservice(SERVICE_NAME, "sub", i, d)
  		end
 
 | 
65421af2
 
  zhouhaihai
 
内存优化
 | 
69 
 | 
  		skynet.exit()
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
70
71 
 | 
  	end)
  end
 
 |