Commit c7ebd49dc62d1123ec474f1c9a3edb8558612c1a
1 parent
ded79c55
Exists in
master
提交新街口
Showing
4 changed files
with
112 additions
and
0 deletions
Show diff stats
src/HttpServer/logic/datadef.go
... | ... | @@ -724,3 +724,29 @@ type UserData struct { |
724 | 724 | LoginDay int |
725 | 725 | } |
726 | 726 | |
727 | +//--------------------------------------------------------------------------------------------------------------------- | |
728 | +//聊天相关 | |
729 | +type ChatInfoDesc struct { | |
730 | + Uuid int `json:"uuid"` | |
731 | + Headurl string `json:"headurl"` | |
732 | + Nickname string `json:"nickname"` | |
733 | + Sex int `json:"sex"` //1男0女 | |
734 | + ChatTime int `json:"chattime"` | |
735 | + Message string `json:"message"` | |
736 | + | |
737 | +} | |
738 | + | |
739 | +//聊天单个页签信息 | |
740 | +type ChatRoomInfo struct { | |
741 | + Chats []ChatInfoDesc `json:"chats"` | |
742 | + Pos int `json:"pos"` | |
743 | + Isnew int `json:"isnew"` //是否有新聊天 | |
744 | +} | |
745 | + | |
746 | +type ChatRoomInfos []ChatRoomInfo | |
747 | + | |
748 | +type ChatMessagesInfo struct { | |
749 | + World ChatRoomInfo `json:"world"` | |
750 | + Team ChatRoomInfo `json:"team"` | |
751 | + Private ChatRoomInfos `json:"privete"` | |
752 | +} | |
727 | 753 | \ No newline at end of file | ... | ... |
src/HttpServer/logic/httpserver.go
... | ... | @@ -51,6 +51,7 @@ func startServerHttpServe() { |
51 | 51 | //------------------------------------------------------------- |
52 | 52 | http.HandleFunc("/catcafe/ClearData", ClearData) //情况账号的测试接口 |
53 | 53 | http.HandleFunc("/catcafe/AddWhiteList", AddWhiteList) //情况账号的测试接口 |
54 | + http.HandleFunc("/catcafe/AddGoldAndLove", AddGoldAndLove) //情况账号的测试接口 | |
54 | 55 | http.HandleFunc("/catcafe/QueryAllAccount", QueryAllAccount) //查询所有账号的等级信息等数据 |
55 | 56 | //------------------------------------------------------------- |
56 | 57 | http.HandleFunc("/catcafe/login", UserLogin) //游客登录 |
... | ... | @@ -183,6 +184,65 @@ func QueryAllAccount(w http.ResponseWriter, r *http.Request) { |
183 | 184 | } |
184 | 185 | |
185 | 186 | |
187 | +func AddGoldAndLove(w http.ResponseWriter, r *http.Request) { | |
188 | + | |
189 | + query := r.URL.Query() | |
190 | + suuid := query.Get("uuid") | |
191 | + sgold := query.Get("gold") | |
192 | + slove := query.Get("love") | |
193 | + uuid,_ := strconv.Atoi(suuid) | |
194 | + gold,_ := strconv.Atoi(sgold) | |
195 | + love,_ := strconv.Atoi(slove) | |
196 | + logger.Info("ClearData , uuid:%v,gold:%v,love:%v", suuid,sgold,slove) | |
197 | + if suuid == "" { | |
198 | + fmt.Fprint(w, "uuid is nil,please check") | |
199 | + return | |
200 | + } | |
201 | + var wilteist []int | |
202 | + rkey := "CATCAFE_REDIS_CAN_RESETDATA_LIST" | |
203 | + vv,err := redishandler.GetRedisClient().HGetAllKeys(rkey) | |
204 | + if err != nil { | |
205 | + fmt.Fprint(w,"获取白名单失败!,请检查") | |
206 | + } | |
207 | + | |
208 | + for _,val := range vv { | |
209 | + bytestr := string(val.([]byte)) | |
210 | + bytenum,_ := strconv.Atoi(bytestr) | |
211 | + wilteist = append(wilteist,bytenum) | |
212 | + | |
213 | + } | |
214 | + logger.Info("AddGoldAndLove white list wilteist=%v",wilteist) | |
215 | + isinwhitelist := false | |
216 | + for _,val := range wilteist { | |
217 | + if val == uuid { | |
218 | + isinwhitelist = true | |
219 | + break | |
220 | + } | |
221 | + } | |
222 | + | |
223 | + if !isinwhitelist { | |
224 | + //不在白名单 | |
225 | + fmt.Fprint(w, "你要加金币的数据不在白名单内,请联系管理员") | |
226 | + return | |
227 | + } | |
228 | + | |
229 | + //加金币 | |
230 | + err = mysql.DoAddGold(uuid,gold,love) | |
231 | + if err != nil { | |
232 | + fmt.Fprint(w, "加金币失败了,错误码%v",err) | |
233 | + } | |
234 | + | |
235 | + //清楚redis | |
236 | + rediskey1 := "cat:cafe:userext:where:user_id:" + suuid | |
237 | + err = redishandler.GetRedisClient().Delete(rediskey1) | |
238 | + if err != nil { | |
239 | + fmt.Fprint(w, "加金币失败了,错误码%v",err) | |
240 | + } | |
241 | + | |
242 | + //将id从白名单删除 | |
243 | + redishandler.GetRedisClient().HDel(rkey,suuid) | |
244 | +} | |
245 | + | |
186 | 246 | func AddWhiteList(w http.ResponseWriter, r *http.Request) { |
187 | 247 | |
188 | 248 | query := r.URL.Query() | ... | ... |
src/common/redis/def.go
... | ... | @@ -21,4 +21,11 @@ const ( |
21 | 21 | USER_INVITEWORK_RELATION = "CATCAFE_USER_INVITEWORK_RELATION" //玩家被邀请打工记录表 |
22 | 22 | USER_BACKUP_DATA = "CATCAFE_USER_BACKUP_DATA" //玩家数据保存的备份 |
23 | 23 | USER_NEW_DATA_KEY = "cat:cafe:data_new:where:data_uid:" //玩家数据保存的新的key |
24 | + | |
25 | + USER_CHAT_ISNEW = "CATCAFE_USER_CHAT_ISNEW" //hset field为uuid 存在表示有新消息了不用再去计算 否则需要挨个去判断 | |
26 | + WORLD_CHAT_INFO_KEY = "CATCAFE_WORLD_CHAT_INFO_KEY" //存储的是世界聊天 list结构 最新的消息在最头部 | |
27 | + USER_CHAT_TEAM_LASTGET_KEY ="CATCAFE_USER_CHAT_TEAM_LASTGET_KEY" // 结构是hset field是uuid value是存储的是最后一次获取工会聊天的时间戳,用于和工会聊天最新一条消息做对比,如果时间比最新一条小则有新的消息 | |
28 | + USER_CHAT_TEAM_INFO_KEY = "CATCAFE_USER_CHAT_TEAM_INFO_KEY" // 加teamid 存储的是队伍聊天的信息 list结构 最新的消息在最头部 | |
29 | + USER_CHAT_PRIVATE_LASTGET_KEY = "CATCAFE_USER_CHAT_PRIVATE_LASTGET_KEY" // hset key加自己的uuid field为目标的uuid value为时间戳 | |
30 | + USER_CHAT_PRIVATE_INFO_KEY = "CATCAFE_USER_CHAT_PRIVATE_INFO_KEY" //list key需要加上自己的uuid 存储的是和自己相关的所有聊天信息 | |
24 | 31 | ) | ... | ... |
src/mysql/dbmysql.go
... | ... | @@ -83,6 +83,25 @@ func TestClearData(uid int) (int,error) { |
83 | 83 | return value,nil |
84 | 84 | } |
85 | 85 | |
86 | +func DoAddGold(uuid,gold,love int) error { | |
87 | + for i:=0;i<10;i++ { | |
88 | + tablename := "b_base_data_0" + strconv.Itoa(i) | |
89 | + cmd := "update " + tablename + "set coin = " + strconv.Itoa(gold) + " where user_id= " + strconv.Itoa(uuid) | |
90 | + err := ExcuteCmd(cmd) | |
91 | + if err != nil { | |
92 | + logger.Error("DoAddGold err=%v,cmd=%v",err,cmd) | |
93 | + return err | |
94 | + } | |
95 | + cmd = "update " + tablename + "set love_exp = " + strconv.Itoa(love) + " where user_id= " + strconv.Itoa(uuid) | |
96 | + err = ExcuteCmd(cmd) | |
97 | + if err != nil { | |
98 | + logger.Error("DoAddGold err=%v,cmd=%v",err,cmd) | |
99 | + return err | |
100 | + } | |
101 | + } | |
102 | + return nil | |
103 | +} | |
104 | + | |
86 | 105 | func DoClearData(uuid int) error{ |
87 | 106 | //先删除十张分表的数据 |
88 | 107 | for i:=0;i<10;i++ { | ... | ... |