Commit 03c475778c5e28b6500cb3d64b1fe100e354aa68
1 parent
5dfa463a
Exists in
master
提交
Showing
2 changed files
with
58 additions
and
0 deletions
Show diff stats
src/HttpServer/logic/function.go
| ... | ... | @@ -1303,3 +1303,43 @@ func PrivateChat(message string, uuid int, taruid int) (int, string) { |
| 1303 | 1303 | } |
| 1304 | 1304 | return 0, "" |
| 1305 | 1305 | } |
| 1306 | + | |
| 1307 | +func GetRandChatMessage() string { | |
| 1308 | + return "小赤佬" | |
| 1309 | +} | |
| 1310 | + | |
| 1311 | +func HandleRandWorldChat() { | |
| 1312 | + length, err := redishandler.GetRedisClient().LLen(redis.WORLD_CHAT_INFO_KEY) | |
| 1313 | + if err == nil { | |
| 1314 | + if length >= CHATLIMITNUM { | |
| 1315 | + //需要先把多余的聊天记录删除 | |
| 1316 | + delcnt := length - CHATLIMITNUM | |
| 1317 | + for i := 0; i < delcnt; i++ { | |
| 1318 | + _, err = redishandler.GetRedisClient().RPop(redis.WORLD_CHAT_INFO_KEY) | |
| 1319 | + if err != nil { | |
| 1320 | + logger.Error("WorldChat failed err=%v", err) | |
| 1321 | + } | |
| 1322 | + } | |
| 1323 | + } | |
| 1324 | + } | |
| 1325 | + | |
| 1326 | + //构建新的结构 | |
| 1327 | + var chats QueryChatMessageData | |
| 1328 | + chats.Message = GetRandChatMessage() | |
| 1329 | + chats.Uuid = -1 | |
| 1330 | + chats.Chattime = int(time.Now().Unix()) | |
| 1331 | + | |
| 1332 | + chats.Headurl = "" | |
| 1333 | + chats.Nickname = "" | |
| 1334 | + chats.Sex = 1 | |
| 1335 | + | |
| 1336 | + savestr, err := json.Marshal(&chats) | |
| 1337 | + if err != nil { | |
| 1338 | + logger.Error("WorldChat err=%v", err) | |
| 1339 | + } | |
| 1340 | + | |
| 1341 | + err = redishandler.GetRedisClient().LPush(redis.WORLD_CHAT_INFO_KEY, string(savestr)) | |
| 1342 | + if err != nil { | |
| 1343 | + logger.Error("WorldChat err=%v", err) | |
| 1344 | + } | |
| 1345 | +} | ... | ... |
src/HttpServer/logic/httpserver.go
| ... | ... | @@ -10,14 +10,32 @@ import ( |
| 10 | 10 | "mysql" |
| 11 | 11 | "os" |
| 12 | 12 | "strconv" |
| 13 | + "time" | |
| 13 | 14 | |
| 14 | 15 | //"log" |
| 15 | 16 | "net/http" |
| 16 | 17 | ) |
| 17 | 18 | |
| 19 | +var gLastChatTime = 0 | |
| 20 | + | |
| 18 | 21 | //定时处理倒计时 |
| 19 | 22 | func StartHttpTicker() { |
| 23 | + ticker := time.NewTicker(time.Second * time.Duration(60)) | |
| 24 | + | |
| 25 | + go func() { | |
| 26 | + for range ticker.C { | |
| 27 | + nowtime := int(time.Now().Unix()) | |
| 28 | + hour := time.Now().Hour() | |
| 29 | + if hour >= 6 && hour <= 10 { | |
| 30 | + if nowtime-gLastChatTime >= 20*60 { | |
| 31 | + gLastChatTime = nowtime | |
| 32 | + HandleRandWorldChat() | |
| 33 | + } | |
| 20 | 34 | |
| 35 | + } | |
| 36 | + | |
| 37 | + } | |
| 38 | + }() | |
| 21 | 39 | } |
| 22 | 40 | |
| 23 | 41 | func StartHttpServe() { | ... | ... |