314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
1
2
3
4
5
6
7
8
9
10 
 | 
  local skynet = require "skynet"
  local harbor = require "skynet.harbor"
  local json = require("shared.json")
  local redisproxy = require("shared.redisproxy")
  
  require "shared.init"
  require "utils.init"
  require "RedisKeys"
  require "skynet.manager"
  
 
 | 
875e5071
 
  zhouhaihai
 
服务名称修改
 | 
11 
 | 
  
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
12
13
14
15
16 
 | 
  local ipairs = ipairs
  local table_insert = table.insert
  local tarr2tab = table.array2Table
  local string_format = string.format
  
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
17 
 | 
  
 
 | 
875e5071
 
  zhouhaihai
 
服务名称修改
 | 
18 
 | 
  local CHECK_MAIL_STATUS_INTERVAL 	= 100 * 60
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 
 | 
  local function mailQuene()
  	local delayEmail = tonum(redisproxy:hget("autoincrement_set", "delay_email"))
  	if delayEmail == 0 then
  		return
  	end
  	local begin = math.max(delayEmail - 100, 1)
  	local mails = redisproxy:pipelining(function (red)
  		for id = begin, delayEmail do
  			red:hgetall(string.format("delayEmail:%s", id))
  		end
  	end)
  	if not mails then
  		return
  	end
  	local now = skynet.timex()
  	local mailList = {}
  	for index, data in ipairs(mails) do
  		if next(data) then
  			local email = tarr2tab(data)
  			if tonum(email.startTime) <= now then
  				table_insert(mailList, email)
  
  				if #mailList > 100 then
  					break
  				end
  			end
  		end
  	end
  	if #mailList == 0 then
  		return
  	end
  	redisproxy:pipelining(function (red)
  		for _, email in ipairs(mailList) do
  			red:del(string_format("delayEmail:%s", email.id))
  		end
  	end)
  	table.sort(mailList, function(a, b)
  		return tonum(a.id) < tonum(b.id)
  	end)
  	for _, email in ipairs(mailList) do
  		local gid = redisproxy:hincrby("autoincrement_set", "email", 1)
  		if email.mid then
  			redisproxy:hmset(string_format("globalEmail:%s", gid), 
  				"id", gid,
 
 | 
ca128b32
 
  zhouhaihai
 
邮件时间bug
 | 
63 
 | 
  				"createtime", email.startTime,
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
64 
 | 
  				"title", email.title,
 
 | 
eb4b0152
 
  zhouhaihai
 
邮件增加 stitle
 | 
65 
 | 
  				"stitle", email.stitle,
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
66
67
68
69 
 | 
  				"content", email.content,
  				"attachments", email.attachments,
  				"endtime", email.endTime,
  				"mid", email.mid,
 
 | 
ca128b32
 
  zhouhaihai
 
邮件时间bug
 | 
70 
 | 
  				"timestamp", now
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
71
72
73
74 
 | 
  			)
  		else
  			redisproxy:hmset(string_format("globalEmail:%s", gid), 
  				"id", gid,
 
 | 
ca128b32
 
  zhouhaihai
 
邮件时间bug
 | 
75 
 | 
  				"createtime", email.startTime,
 
 | 
d9cb65a9
 
  zhouhaihai
 
bug
 | 
76 
 | 
  				"title", email.title,
 
 | 
eb4b0152
 
  zhouhaihai
 
邮件增加 stitle
 | 
77 
 | 
  				"stitle", email.stitle,
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
78
79
80 
 | 
  				"content", email.content,
  				"attachments", email.attachments,
  				"endtime", email.endTime,
 
 | 
ca128b32
 
  zhouhaihai
 
邮件时间bug
 | 
81 
 | 
  				"timestamp", now
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
82
83
84
85
86
87
88
89
90
91
92
93 
 | 
  			)
  		end
  	end
  	redisproxy:hset("autoincrement_set", "emailTimestamp", now)
  end
  
  -- @desc: 定时邮件队列检测
  local function check_mail_queue()
  	pcall(mailQuene)
  	skynet.timeout(CHECK_MAIL_STATUS_INTERVAL, check_mail_queue)
  end
  
 
 | 
c384626d
 
  zhouhaihai
 
好友
 | 
94
95 
 | 
  
  
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
96 
 | 
  local CMD = {}
 
 | 
c384626d
 
  zhouhaihai
 
好友
 | 
97 
 | 
  
 
 | 
875e5071
 
  zhouhaihai
 
服务名称修改
 | 
98
99 
 | 
  
  -- 服务器缓存50条消息
 
 | 
c384626d
 
  zhouhaihai
 
好友
 | 
100
101
102
103
104
105
106
107
108
109 
 | 
  local cacheWorldMsg = {}
  local CACHE_WORLD_MSG_COUNT = 50
  function CMD.sendWorldMsg(channel, msg)
  	cacheWorldMsg[channel] = cacheWorldMsg[channel] or {}
  	table.insert(cacheWorldMsg[channel], msg)
  	for i = #cacheWorldMsg[channel] - CACHE_WORLD_MSG_COUNT, 1, -1 do
  		table.remove(cacheWorldMsg[channel], i)
  	end
  end
  
 
 | 
c384626d
 
  zhouhaihai
 
好友
 | 
110
111
112
113
114 
 | 
  function CMD.getWorldMsg(channel)
  	local msgs = cacheWorldMsg[channel] or {}
  	return msgs
  end
  
 
 | 
875e5071
 
  zhouhaihai
 
服务名称修改
 | 
115 
 | 
  
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
116
117
118
119
120
121 
 | 
  function CMD.start()
  	check_mail_queue()
  end
  
  local function __init__()
  	skynet.dispatch("lua", function(_, _, command, ...)
 
 | 
c384626d
 
  zhouhaihai
 
好友
 | 
122
123
124
125
126
127
128
129 
 | 
  		local f = CMD[command]
  		if f then
  			if command == "sendWorldMsg" then
  				skynet.ignoreret()
  				f(...)
  			else
  				skynet.ret(skynet.pack(f(...)))
  			end
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
130
131 
 | 
  		end
  	end)
 
 | 
a5486ede
 
  zhouhaihai
 
csvdata 修改为 share...
 | 
132
133 
 | 
  	redisd = skynet.localname(".redis")
  	skynet.register(".globald")
 
 | 
875e5071
 
  zhouhaihai
 
服务名称修改
 | 
134 
 | 
  
 
 | 
314bc5df
 
  zhengshouren
 
提交服务器初始代码
 | 
135
136
137 
 | 
  end
  
  skynet.start(__init__)
 
 |