diff --git a/server/hallserver/listener/handlermgr.go b/server/hallserver/listener/handlermgr.go index 6a104baf..d0b09256 100644 --- a/server/hallserver/listener/handlermgr.go +++ b/server/hallserver/listener/handlermgr.go @@ -22,6 +22,8 @@ func (this *HandlerMgr) Init() { cs.RegHandlerId(int(cs.CMMessageIdE__CMJoinRoom), constant.ROOM_MGR_HANDLER_ID) cs.RegHandlerId(int(cs.CMMessageIdE__CMSearchRoom), constant.ROOM_MGR_HANDLER_ID) cs.RegHandlerId(int(cs.CMMessageIdE__CMGetCurrentRoom), constant.ROOM_MGR_HANDLER_ID) + cs.RegHandlerId(int(cs.CMMessageIdE__CMEnterObserver), constant.ROOM_MGR_HANDLER_ID) + cs.RegHandlerId(int(cs.CMMessageIdE__CMLeaveObserver), constant.ROOM_MGR_HANDLER_ID) cs.RegHandlerId(int(cs.CMMessageIdE__CMDisbandRoom), constant.ROOM_HANDLER_ID) cs.RegHandlerId(int(cs.CMMessageIdE__CMLeaveRoom), constant.ROOM_HANDLER_ID) diff --git a/server/hallserver/room/room.go b/server/hallserver/room/room.go index 742a36e5..c15178d4 100644 --- a/server/hallserver/room/room.go +++ b/server/hallserver/room/room.go @@ -37,10 +37,7 @@ type room struct { gameStartNotifyMsg *cs.SMRoomGameStartNotify } -func (this *room) init(roomId string, - roomIdx int64, - owner common.Player, - msg *cs.CMCreateRoom) { +func (this *room) init(roomId string, roomIdx int64, owner common.Player, msg *cs.CMCreateRoom) { this.roomId = roomId this.roomIdx = roomIdx this.config.mapId = msg.GetMapId() @@ -123,7 +120,7 @@ func (this *room) canJoin(member common.Player, msg *cs.CMJoinRoom) bool { if t != nil && t.getMemberNum() >= constant.ROOM_MAX_TEAM_MEMBER_NUM { return false } - return false + return true } func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool { @@ -138,7 +135,33 @@ func (this *room) join(hum common.Player, msg *cs.CMJoinRoom) bool { } else { t.addMember(m) } - return false + this.autoStartCountdown() + return true +} + +func (this *room) autoStartCountdown() { + if this.getTeamNum() != this.config.maxTeamNum { + return + } + var secondsRemaining int32 = 15 + timer := f5.GetTimer() + timer.SetInterval(1000, func(e int32, args *q5.Args) { + if e == q5.TIMER_EXEC_EVENT { + if this.getTeamNum() != this.config.maxTeamNum { + timer.DeleteRunningTimer() + return + } + if secondsRemaining > 0 { + this.AutoStartGameCountdownNotify(secondsRemaining) + } + if secondsRemaining == 0 { + this.notifyGameStart() + timer.DeleteRunningTimer() + return + } + secondsRemaining-- + } + }) } func (this *room) fillMFRoom(hum common.Player, pb *cs.MFRoom) { @@ -162,7 +185,7 @@ func (this *room) fillMFRoom(hum common.Player, pb *cs.MFRoom) { this.owner.fillMFMember(pb.Owner) } -func (this *room) fillMFCurrentRoom(hum common.Player, pb *cs.MFCurrentRoom) { +func (this *room) fillMFCurrentRoom(hum common.Player, pb *cs.MFCurrentRoom, observerTeam *team) { pb.RoomId = proto.String(this.roomId) pb.MapId = proto.Int32(this.config.mapId) pb.ZoneId = proto.Int32(this.config.zoneId) @@ -187,6 +210,12 @@ func (this *room) fillMFCurrentRoom(hum common.Player, pb *cs.MFCurrentRoom) { t.fillMFTeam(pbT) q5.AppendSlice(&pb.TeamList, pbT) } + + if observerTeam != nil && observerTeam.room != nil { + pbT2 := &cs.MFTeam{} + observerTeam.fillMFTeam(pbT2) + pb.ObserverTeam = pbT2 + } } func (this *room) OnPlayerOffline(hum common.Player) { @@ -214,23 +243,25 @@ func (this *room) CMLeaveRoom(hdr *f5.MsgHdr, msg *cs.CMLeaveRoom) { hum := hdr.Context.(common.Player) m := this.getMember(hum.GetAccountId()) if m != nil && this.roomState == ROOM_INIT_STATE { + var removeMemberAccountId string if this.isOwner(hum) { nextOwner := this.getNextOwner() if nextOwner == nil { this.doDisband(ROOM_DISBAND_NO_NEXT_OWNER_REASON) return } else { - this.removeMember(this.owner.hum.GetAccountId()) + removeMemberAccountId = this.owner.hum.GetAccountId() this.owner = nextOwner } } else { - this.removeMember(hum.GetAccountId()) + removeMemberAccountId = hum.GetAccountId() } notifyMsg := &cs.SMRoomLeaveNotify{} q5.NewSlice(¬ifyMsg.AccountIds, 0, 1) q5.AppendSlice(¬ifyMsg.AccountIds, m.hum.GetAccountId()) this.broadcastMsg(notifyMsg) this.notifyRoomInfo(hum) + this.removeMember(removeMemberAccountId) } } @@ -279,7 +310,18 @@ func (this *room) CMKickoutTeam(hdr *f5.MsgHdr, msg *cs.CMKickoutTeam) { m := this.getMember(hum.GetAccountId()) t := this.getTeamByUuid(msg.GetTeamUuid()) if m == this.owner && t != nil && t != m.team && this.roomState == ROOM_INIT_STATE { + membersPtr := make([]*member, 0, t.members.Size()) + t.members.ForEach( + func(data interface{}) bool { + if mPtr, ok := data.(*member); ok { + membersPtr = append(membersPtr, mPtr) + } + return true + }) notifyMsg := &cs.SMRoomKickoutNotify{} + for _, m2 := range membersPtr { + notifyMsg.AccountIds = append(notifyMsg.AccountIds, m2.hum.GetAccountId()) + } this.broadcastMsg(notifyMsg) t.unInit() this.notifyRoomInfo(hum) @@ -307,22 +349,6 @@ func (this *room) CMCloseNotify(hdr *f5.MsgHdr, msg *cs.CMCloseNotify) { } } -func (this *room) CMEnterObserver(hdr *f5.MsgHdr, msg *cs.CMEnterObserver) { - //hum := hdr.Context.(common.Player) - //m := this.getMember(hum.GetAccountId()) - // if this.isOwner(hum) { - // t := this.owner.team - // } -} - -func (this *room) CMLeaveObserver(hdr *f5.MsgHdr, msg *cs.CMLeaveObserver) { - //hum := hdr.Context.(common.Player) - //m := this.getMember(hum.GetAccountId()) - // if this.isOwner(hum) { - // t := this.owner.team - // } -} - func (this *room) broadcastMsg(msg proto.Message) { for _, m := range this.members { if m.hum.GetRoom() == this { @@ -386,13 +412,19 @@ func (this *room) GetRoomState() int32 { return this.roomState } +func (this *room) AutoStartGameCountdownNotify(seconds int32) { + notifyMsg := &cs.SMAutoStartGameCountdownNotify{} + notifyMsg.Seconds = proto.Int32(seconds) + this.broadcastMsg(notifyMsg) +} + func (this *room) notifyGameStart() { if this.gameStartNotifyMsg == nil { this.genGameStartNotifyMsg() } for _, m := range this.members { - if m.state == MEMBER_READY_STATE && - m.hum.GetRoom() == this && + // m.state == MEMBER_READY_STATE && + if m.hum.GetRoom() == this && !m.closeGameStartNotify { m.hum.SendMsg(this.gameStartNotifyMsg) } @@ -447,6 +479,7 @@ func (this *room) genGameStartNotifyMsg() { } func (this *room) canStart() bool { + return true alreadyNum := 0 for _, t := range this.teamUuidHash { if t.hasAlreadMember() { diff --git a/server/hallserver/room/roommgr.go b/server/hallserver/room/roommgr.go index c774642a..f10546a9 100644 --- a/server/hallserver/room/roommgr.go +++ b/server/hallserver/room/roommgr.go @@ -11,16 +11,12 @@ import ( "q5" ) -type TeamInfo struct { - TeamUUID string `json:"team_uuid"` - MemberList []memberInfo `json:"member_list"` -} - type roomMgr struct { cs.MsgHandlerImpl - currRoomId int32 - idHash map[string]*room - roomList q5.ListHead + currRoomId int32 + idHash map[string]*room + roomList q5.ListHead + observerTeam *team } func (this *roomMgr) Init() { @@ -81,12 +77,16 @@ func (this *roomMgr) CMCreateRoom(hdr *f5.MsgHdr, msg *cs.CMCreateRoom) { this.roomList.AddTail(&m.entry) rspMsg.RoomId = proto.String(m.roomId) + rspMsg.Room = new(cs.MFRoom) + m.fillMFRoom(hum, rspMsg.Room) + teamInfo := &TeamInfo{} err := json.Unmarshal([]byte(msg.GetTeamInfo()), teamInfo) - if err != nil { - f5.GetSysLog().Info(err.Error()) - } else { - this.SaveTeamLeader(m, msg.GetTeamUuid(), teamInfo) + if err == nil { + t := m.getTeamByUuid(msg.GetTeamUuid()) + if t != nil { + t.SaveTeamLeader(teamInfo) + } } hum.SendMsg(rspMsg) @@ -120,6 +120,21 @@ func (this *roomMgr) CMJoinRoom(hdr *f5.MsgHdr, msg *cs.CMJoinRoom) { hum.SendMsg(&rspMsg) return } + + r.join(hum, msg) + r.notifyRoomInfo(hum) + + if len(msg.GetTeamInfo()) > 0 { + teamInfo := &TeamInfo{} + err := json.Unmarshal([]byte(msg.GetTeamInfo()), teamInfo) + if err == nil { + t := r.getTeamByUuid(msg.GetTeamUuid()) + t.SaveTeamLeader(teamInfo) + } + } + + rspMsg.Room = new(cs.MFRoom) + r.fillMFRoom(hum, rspMsg.Room) hum.SendMsg(&rspMsg) } @@ -146,6 +161,7 @@ func (this *roomMgr) CMSearchRoom(hdr *f5.MsgHdr, msg *cs.CMSearchRoom) { } return true }) + rspMsg.SinceId = proto.Int64(sinceId) hum.SendMsg(&rspMsg) } @@ -154,8 +170,7 @@ func (this *roomMgr) CMGetCurrentRoom(hdr *f5.MsgHdr, msg *cs.CMGetCurrentRoom) rspMsg := &cs.SMGetCurrentRoom{} if hum.GetRoom() != nil && hum.GetRoom().GetRoomState() == ROOM_INIT_STATE { rspMsg.Room = new(cs.MFCurrentRoom) - - hum.GetRoom().(*room).fillMFCurrentRoom(hum, rspMsg.Room) + hum.GetRoom().(*room).fillMFCurrentRoom(hum, rspMsg.Room, this.observerTeam) hum.SendMsg(rspMsg) return } @@ -167,23 +182,80 @@ func (this *roomMgr) RemoveRoomMember(hdr *f5.MsgHdr) { if hum != nil { if roomPtr, ok := hum.GetRoom().(*room); ok { roomPtr.removeMember(hum.GetAccountId()) - } - } -} - -func (this *roomMgr) SaveTeamLeader(r *room, teamUUID string, teamInfo *TeamInfo) { - t := r.getTeamByUuid(teamUUID) - for _, mInfo := range teamInfo.MemberList { - if mInfo.IsLeader == 1 { - t.tmpTeamLeader = &memberInfo{ - AccountID: mInfo.AccountID, - Name: mInfo.Name, - Avatar: mInfo.Avatar, - AvatarFrame: mInfo.AvatarFrame, - HeroId: mInfo.HeroId, - IsLeader: mInfo.IsLeader, - State: mInfo.State, + if len(roomPtr.teamUuidHash) <= 0 { + roomPtr.unInit() } } } } + +func (this *roomMgr) CMEnterObserver(hdr *f5.MsgHdr, msg *cs.CMEnterObserver) { + hum := hdr.Context.(common.Player) + rspMsg := cs.SMEnterObserver{} + + roomPtr, ok := hum.GetRoom().(*room) + if !ok || roomPtr == nil { + rspMsg.Errcode = proto.Int32(1) + rspMsg.Errmsg = proto.String("room is empty") + hum.SendMsg(&rspMsg) + return + } + + if !roomPtr.isOwner(hum) { + rspMsg.Errcode = proto.Int32(2) + rspMsg.Errmsg = proto.String("not owner") + hum.SendMsg(&rspMsg) + return + } + + if this.observerTeam != nil && this.observerTeam.room != nil { + rspMsg.Errcode = proto.Int32(3) + rspMsg.Errmsg = proto.String("exists observer team") + hum.SendMsg(&rspMsg) + return + } + + t := roomPtr.owner.team + delete(roomPtr.teamUuidHash, t.teamUuid) + delete(roomPtr.teamIdHash, t.teamId) + this.observerTeam = roomPtr.owner.team + + hum.SendMsg(&rspMsg) + roomPtr.notifyRoomInfo(hum) +} + +func (this *roomMgr) CMLeaveObserver(hdr *f5.MsgHdr, msg *cs.CMLeaveObserver) { + hum := hdr.Context.(common.Player) + rspMsg := cs.SMLeaveObserver{} + + roomPtr, ok := hum.GetRoom().(*room) + if !ok { + rspMsg.Errcode = proto.Int32(1) + rspMsg.Errmsg = proto.String("room is empty") + hum.SendMsg(&rspMsg) + return + } + + if !roomPtr.isOwner(hum) { + rspMsg.Errcode = proto.Int32(2) + rspMsg.Errmsg = proto.String("not owner") + hum.SendMsg(&rspMsg) + return + } + + if roomPtr.getTeamNum() >= roomPtr.config.maxTeamNum { + rspMsg.Errcode = proto.Int32(3) + rspMsg.Errmsg = proto.String("teams is full") + hum.SendMsg(&rspMsg) + return + } + + t := roomPtr.owner.team + roomPtr.addTeam(t) + roomPtr.autoStartCountdown() + + this.observerTeam = nil + + hum.SendMsg(&rspMsg) + roomPtr.notifyRoomInfo(hum) +} diff --git a/server/hallserver/room/team.go b/server/hallserver/room/team.go index c7494c16..189de1a6 100644 --- a/server/hallserver/room/team.go +++ b/server/hallserver/room/team.go @@ -6,6 +6,12 @@ import ( "q5" ) +// TeamInfo from client data +type TeamInfo struct { + TeamUUID string `json:"team_uuid"` + MemberList []memberInfo `json:"member_list"` +} + type memberInfo struct { AccountID string `json:"account_id"` Name string `json:"name"` @@ -32,12 +38,17 @@ func (this *team) init(room *room, teamId int32, teamUuid string) { } func (this *team) unInit() { + deleteMembers := make([]*member, 0, this.members.Size()) this.members.ForEach( func(data interface{}) bool { - m := data.(*member) - m.unInit() + if mPtr, ok := data.(*member); ok { + deleteMembers = append(deleteMembers, mPtr) + } return true }) + for _, m := range deleteMembers { + m.unInit() + } delete(this.room.teamUuidHash, this.teamUuid) delete(this.room.teamIdHash, this.teamId) this.room = nil @@ -127,6 +138,25 @@ func (this *team) getOwnerCandidate() *member { return ownerCandidate } +func (this *team) SaveTeamLeader(teamInfo *TeamInfo) { + if this.tmpTeamLeader != nil { + return + } + for _, mInfo := range teamInfo.MemberList { + if mInfo.IsLeader == 1 { + this.tmpTeamLeader = &memberInfo{ + AccountID: mInfo.AccountID, + Name: mInfo.Name, + Avatar: mInfo.Avatar, + AvatarFrame: mInfo.AvatarFrame, + HeroId: mInfo.HeroId, + IsLeader: mInfo.IsLeader, + State: mInfo.State, + } + } + } +} + func newTeam(room *room, teamId int32, teamUuid string, leader *member) *team { t := new(team) t.init(room, teamId, teamUuid) diff --git a/server/mailserver/api/enter.go b/server/mailserver/api/enter.go new file mode 100644 index 00000000..6a9d4e3e --- /dev/null +++ b/server/mailserver/api/enter.go @@ -0,0 +1,28 @@ +package api + +import ( + "github.com/gin-gonic/gin" + "main/global" + "main/mail" +) + +type ApiGroup struct { + Mail MailApi +} + +var ApiGroupApp = new(ApiGroup) + +func GetMailMgr() *mail.MailMgr { + mailMgrPtr, ok := global.GetMailMgr().(*mail.MailMgr) + if !ok { + return nil + } + return mailMgrPtr +} + +func errorResponse(errCode int, err error) gin.H { + return gin.H{ + "errcode": errCode, + "errmsg": err.Error(), + } +} diff --git a/server/mailserver/api/mail.go b/server/mailserver/api/mail.go new file mode 100644 index 00000000..af13e2ce --- /dev/null +++ b/server/mailserver/api/mail.go @@ -0,0 +1,123 @@ +package api + +import ( + "fmt" + "github.com/gin-gonic/gin" + "net/http" +) + +type MailApi struct { +} + +// 获取我的邮件列表 +type getMailsReq struct { + SessionId string `form:"session_id" binding:"required"` + AccountId string `form:"account_id" binding:"required"` + MailType int32 `form:"mailtype"` + MailSubType int32 `form:"mailsubtype"` +} + +func (api *MailApi) GetMailList(c *gin.Context) { + var req getMailsReq + if err := c.ShouldBindQuery(&req); err != nil { + c.JSON(http.StatusBadRequest, errorResponse(400, err)) + return + } + + mailMgr := GetMailMgr() + if mailMgr == nil { + err := fmt.Errorf("mailMgr is null") + c.JSON(http.StatusBadRequest, errorResponse(400, err)) + return + } + + mails := mailMgr.GetMails(req.AccountId) + c.JSON(http.StatusOK, gin.H{ + "errcode": 0, + "errmsg": "success", + "maillist": mails, + }) +} + +// 设置邮件标记 +type markMailReq struct { + SessionId string `form:"session_id" binding:"required"` + AccountId string `form:"account_id" binding:"required"` + MailIds string `form:"mail_ids" binding:"required"` + Flag string `form:"flag" binding:"required"` +} + +func (api *MailApi) MarkMail(c *gin.Context) { + var req markMailReq + if err := c.ShouldBindQuery(&req); err != nil { + c.JSON(http.StatusBadRequest, errorResponse(100, err)) + return + } + if req.Flag != "read" { + c.JSON(http.StatusBadRequest, errorResponse(400, fmt.Errorf("flag is not `read`"))) + return + } + + c.JSON(http.StatusOK, gin.H{ + "errcode": 0, + "errmsg": "success", + }) +} + +// 获取未读邮件数 +type getUnreadMailCountReq struct { + SessionId string `form:"session_id" binding:"required"` + AccountId string `form:"account_id" binding:"required"` +} + +func (api *MailApi) GetUnreadMailCount(c *gin.Context) { + var req getUnreadMailCountReq + if err := c.ShouldBindQuery(&req); err != nil { + c.JSON(http.StatusBadRequest, errorResponse(400, err)) + return + } + + c.JSON(http.StatusOK, gin.H{ + "errcode": 0, + "errmsg": "success", + }) +} + +// 领取邮件附件 +type GetMailAttachmentReq struct { + SessionId string `form:"session_id" binding:"required"` + AccountId string `form:"account_id" binding:"required"` +} + +func (api *MailApi) GetMailAttachment(c *gin.Context) { + var req GetMailAttachmentReq + if err := c.ShouldBindQuery(&req); err != nil { + c.JSON(http.StatusBadRequest, errorResponse(400, err)) + return + } + + c.JSON(http.StatusOK, gin.H{ + "errcode": 0, + "errmsg": "success", + }) +} + +// 删除邮件 +type DeleteMailsReq struct { + SessionId string `form:"session_id" binding:"required"` + AccountId string `form:"account_id" binding:"required"` + MailIds string `form:"mail_ids" binding:"required"` +} + +func (api *MailApi) DeleteMails(c *gin.Context) { + var req DeleteMailsReq + if err := c.ShouldBindQuery(&req); err != nil { + c.JSON(http.StatusBadRequest, errorResponse(400, err)) + return + } + + c.JSON(http.StatusOK, gin.H{ + "errcode": 0, + "errmsg": "success", + }) +} diff --git a/server/mailserver/app/app.go b/server/mailserver/app/app.go new file mode 100644 index 00000000..1bfc0f0e --- /dev/null +++ b/server/mailserver/app/app.go @@ -0,0 +1,103 @@ +package app + +import ( + "crypto/md5" + "encoding/hex" + "f5" + "fmt" + "main/constant" + "math/rand" + "mt" + "sync" + "time" +) + +type app struct { + initCb func() + unInitCb func() + sessionLock sync.Mutex + sessionHash map[string]string + accountIdHash map[string]string +} + +func (this *app) GetPkgName() string { + return "mailserver" +} + +func (this *app) GetHttpListenPort() int32 { + return 3000 +} + +func (this *app) Run(initCb func(), unInitCb func()) { + this.initCb = initCb + this.unInitCb = unInitCb + f5.Run(this) +} + +func (this *app) Init() { + f5.LoadMetaTable(mt.Table) + this.registerDataSources() + this.sessionHash = make(map[string]string) + this.accountIdHash = make(map[string]string) + this.initCb() +} + +func (this *app) UnInit() { + this.unInitCb() +} + +func (this *app) Update() { +} + +func (this *app) registerDataSources() { + f5.GetGoStyleDb().RegisterDataSource( + constant.MAIL_DB, + mt.Table.MailDb.GetById(0).GetHost(), + mt.Table.MailDb.GetById(0).GetPort(), + mt.Table.MailDb.GetById(0).GetUser(), + mt.Table.MailDb.GetById(0).GetPasswd(), + mt.Table.MailDb.GetById(0).GetDatabase(), + 30) +} + +func (this *app) AddSession(accountId string) string { + this.sessionLock.Lock() + defer this.sessionLock.Unlock() + uuid := f5.GetApp().NewUuid() + str := fmt.Sprintf("%s%d%s%d", accountId, uuid, randStringBytes(12), time.Now().Unix()) + md5New := md5.New() + strByte := []byte(str) + md5New.Write(strByte) + md5String := hex.EncodeToString(md5New.Sum(nil)) + token := accountId + "|" + md5String + this.sessionHash[accountId] = token + return token +} + +const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + +func randStringBytes(n int) string { + b := make([]byte, n) + for i := range b { + b[i] = letterBytes[rand.Intn(len(letterBytes))] + } + return string(b) +} + +func (this *app) GetSessionAccountId(accountId string) string { + this.sessionLock.Lock() + defer this.sessionLock.Unlock() + if session, ok := this.sessionHash[accountId]; ok { + return session + } else { + return "nil" + } +} + +func (this *app) RemoveSession(accountId string) { + this.sessionLock.Lock() + defer this.sessionLock.Unlock() + if _, ok := this.sessionHash[accountId]; ok { + delete(this.sessionHash, accountId) + } +} diff --git a/server/mailserver/app/export.go b/server/mailserver/app/export.go new file mode 100644 index 00000000..668918d5 --- /dev/null +++ b/server/mailserver/app/export.go @@ -0,0 +1,12 @@ +package app + +import ( + "main/constant" + "main/global" +) + +var _app = new(app) + +func init() { + global.RegModule(constant.APP_MODULE_IDX, _app) +} diff --git a/server/mailserver/common/types.go b/server/mailserver/common/types.go new file mode 100644 index 00000000..3dba6342 --- /dev/null +++ b/server/mailserver/common/types.go @@ -0,0 +1,13 @@ +package common + +type App interface { + Run(func(), func()) + AddSession(accountId string) string + GetSessionAccountId(accountId string) string + RemoveSession(accountId string) +} + +type Player interface{} +type PlayerMgr interface{} +type Mail interface{} +type MailMgr interface{} diff --git a/server/mailserver/constant/constant.go b/server/mailserver/constant/constant.go new file mode 100644 index 00000000..ef876b16 --- /dev/null +++ b/server/mailserver/constant/constant.go @@ -0,0 +1,29 @@ +package constant + +const ( + MAX_PACKET_LEN = 1024 * 64 +) + +const ( + MAIL_DB = "maildb" +) + +const ( + APP_MODULE_IDX = iota + ROUTER_MODULE_IDX + PLAYER_MGR_MODULE_IDX + MAIL_MGR_MODULE_IDX + MAX_MODULE_IDX +) + +const ( + GAMEID = "2006" + EMAIL_URL_DEV = "gamemail-test.kingsome.cn" + EMAIL_KEY = "520d8eeb8cf1d833a42c820432c020b2fd60f4b7|" + EMAIL_URL_DEV +) + +// mail +const ( + MAIL_TYPE_PLAYER = 1 + MAIL_TYPE_GROUP = 2 +) diff --git a/server/mailserver/cs/cs.auto_gen.go b/server/mailserver/cs/cs.auto_gen.go new file mode 100644 index 00000000..6050da55 --- /dev/null +++ b/server/mailserver/cs/cs.auto_gen.go @@ -0,0 +1,42 @@ +package cs + +import ( + "f5" + proto "github.com/golang/protobuf/proto" +) + +type CsNetMsgHandler f5.NetMsgHandler[MsgHandler]; + +type MsgHandlerImpl struct { +} + +var handlers [2000]*CsNetMsgHandler + +func GetNetMsgHandler(msgId uint16) *CsNetMsgHandler { + handler := handlers[msgId] + return handler +} + +func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) { + handler.Cb(hdr, msgHandler) +} + +func RegHandlerId(msgId int, handlerId int) { + handler := handlers[msgId] + handler.HandlerId = handlerId +} + +func ParsePb(msgId uint16, data []byte) interface{} { + handler := handlers[msgId] + if handler == nil { + return nil + } + return handler.ParseCb(data) +} + +type MsgHandler interface { +} + +func init() { + +} \ No newline at end of file diff --git a/server/mailserver/cs/go.sum b/server/mailserver/cs/go.sum new file mode 100644 index 00000000..88e5c542 --- /dev/null +++ b/server/mailserver/cs/go.sum @@ -0,0 +1,23 @@ +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/server/mailserver/doc/mail.getMailList.http b/server/mailserver/doc/mail.getMailList.http new file mode 100644 index 00000000..6ccbd760 --- /dev/null +++ b/server/mailserver/doc/mail.getMailList.http @@ -0,0 +1,3 @@ +### GET mails +GET localhost:3000/api/mails?session_id=a&account_id=a +Accept: application/json diff --git a/server/mailserver/global/global.go b/server/mailserver/global/global.go new file mode 100644 index 00000000..3377694d --- /dev/null +++ b/server/mailserver/global/global.go @@ -0,0 +1,67 @@ +package global + +import ( + "fmt" + "main/common" + "main/constant" + "q5" +) + +var modules [constant.MAX_MODULE_IDX]q5.Module +var initOrders = []int32{ + constant.ROUTER_MODULE_IDX, + constant.PLAYER_MGR_MODULE_IDX, + constant.MAIL_MGR_MODULE_IDX, +} + +var app common.App +var playerMgr common.PlayerMgr +var mailMgr common.MailMgr + +func GetApp() common.App { + return app +} + +func GetMailMgr() common.MailMgr { + return mailMgr +} + +func RegModule(idx int32, m q5.Module) { + fmt.Printf("RegModule module %d\n", idx) + modules[idx] = m + switch idx { + case constant.APP_MODULE_IDX: + { + app = m.(common.App) + } + case constant.ROUTER_MODULE_IDX: + { + } + case constant.PLAYER_MGR_MODULE_IDX: + { + playerMgr = m.(common.PlayerMgr) + } + case constant.MAIL_MGR_MODULE_IDX: + { + mailMgr = m.(common.MailMgr) + } + default: + { + panic("unknow module") + } + } +} + +func InitModules() { + for _, val := range initOrders { + fmt.Printf("init module %d\n", val) + modules[val].Init() + } +} + +func UnInitModules() { + for _, val := range initOrders { + fmt.Printf("unInit module %d", val) + modules[val].UnInit() + } +} diff --git a/server/mailserver/go.mod b/server/mailserver/go.mod new file mode 100644 index 00000000..fc20023b --- /dev/null +++ b/server/mailserver/go.mod @@ -0,0 +1,61 @@ +module mailsever + +go 1.20 + +require q5 v1.0.0 + +require f5 v1.0.0 + +require mt v1.0.0 + +require mtb v1.0.0 // indirect + +require main v1.0.0 + +require ( + github.com/gin-gonic/gin v1.9.1 + gorm.io/driver/mysql v1.5.1 + gorm.io/gorm v1.25.4 +) + +require ( + github.com/bytedance/sonic v1.10.1 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.15.4 // indirect + github.com/go-sql-driver/mysql v1.7.1 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/gomodule/redigo v1.8.3 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + golang.org/x/arch v0.5.0 // indirect + golang.org/x/crypto v0.13.0 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +replace q5 => ../../third_party/q5 + +replace f5 => ../../third_party/f5 + +replace mt => ./mt + +replace mtb => ./mtb + +replace main => ./ diff --git a/server/mailserver/go.sum b/server/mailserver/go.sum new file mode 100644 index 00000000..7243945c --- /dev/null +++ b/server/mailserver/go.sum @@ -0,0 +1,107 @@ +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc= +github.com/bytedance/sonic v1.10.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= +github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.15.4 h1:zMXza4EpOdooxPel5xDqXEdXG5r+WggpvnAKMsalBjs= +github.com/go-playground/validator/v10 v10.15.4/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= +github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/gomodule/redigo v1.8.3 h1:HR0kYDX2RJZvAup8CsiJwxB4dTCSC0AaUq6S4SiLwUc= +github.com/gomodule/redigo v1.8.3/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= +github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y= +golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= +gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= +gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw= +gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/server/mailserver/initialize/enter.go b/server/mailserver/initialize/enter.go new file mode 100644 index 00000000..e33ad00a --- /dev/null +++ b/server/mailserver/initialize/enter.go @@ -0,0 +1,13 @@ +package initialize + +import ( + _ "main/app" + . "main/global" + _ "main/mail" + _ "main/player" + _ "main/router" +) + +func Init() { + GetApp().Run(InitModules, UnInitModules) +} diff --git a/server/mailserver/mail/export.go b/server/mailserver/mail/export.go new file mode 100644 index 00000000..914ab465 --- /dev/null +++ b/server/mailserver/mail/export.go @@ -0,0 +1,12 @@ +package mail + +import ( + "main/constant" + "main/global" +) + +var _mailMgr = new(MailMgr) + +func init() { + global.RegModule(constant.MAIL_MGR_MODULE_IDX, _mailMgr) +} diff --git a/server/mailserver/mail/mail.go b/server/mailserver/mail/mail.go new file mode 100644 index 00000000..7769ec0d --- /dev/null +++ b/server/mailserver/mail/mail.go @@ -0,0 +1,71 @@ +package mail + +import ( + "strconv" + "strings" +) + +type Attachments struct { + ItemId int `json:"itemid"` + ItemNum int `json:"itemnum"` +} + +type Mail struct { + Gameid int `json:"-"` + MailId int64 `json:"mailid"` + From string `json:"from"` + To string `json:"to"` + Subject string `json:"subject"` + Content string `json:"content"` + Flag int `json:"flags"` + SendTime int `json:"sendtime"` + Expiretime int `json:"expiretime"` + Mailtype int `json:"mailtype"` + Mailsubtype int `json:"mailsubtype"` + Usertype int `json:"-"` + Createtime int `json:"-"` + Ext string `json:"ext"` + ATT []*Attachments `json:"attachments"` +} + +func (m *Mail) Init() { + +} + +func newMail() *Mail { + m := new(Mail) + m.Init() + return m +} + +func (m *Mail) ParseAttachments(attachmentsStr string) { + if len(attachmentsStr) <= 0 { + return + } + attachmentStrList := strings.Split(attachmentsStr, "|") + m.ATT = make([]*Attachments, 0, len(attachmentStrList)) + for _, attachmentStr := range attachmentStrList { + parts := strings.Split(attachmentStr, ":") + if len(parts) != 2 { + continue + } + itemID, err := strconv.Atoi(parts[0]) + if err != nil { + continue + } + itemNum, err := strconv.Atoi(parts[1]) + if err != nil { + continue + } + attachment := &Attachments{ + ItemId: itemID, + ItemNum: itemNum, + } + m.ATT = append(m.ATT, attachment) + } +} + +func (m *Mail) FillMutableXObject() {} +func (m *Mail) GMFillMutableXObject() {} +func (m *Mail) HasAttachment() {} +func (m *Mail) IsReadableMail() {} diff --git a/server/mailserver/mail/maildbmgr.go b/server/mailserver/mail/maildbmgr.go new file mode 100644 index 00000000..59d8c7d1 --- /dev/null +++ b/server/mailserver/mail/maildbmgr.go @@ -0,0 +1,62 @@ +package mail + +import ( + "f5" + "fmt" + "main/constant" + "q5" +) + +var LoadRound uint32 = 0 + +func (mm *MailMgr) LoadFromDB() { + // LoadRound++ + // f5.GetSysLog().Info("LoadFromDB Start round:%d", LoadRound) + + lastIdx := int64(0) + // unixSec := time.Now().Unix() + unixSec := 0 + limit := 1000 + + done := false + for !done { + sql := fmt.Sprintf("SELECT idx, gameid, mailid, _from, _to, subject, content, mailtype, mailsubtype, sendtime, expiretime, attachments, createtime, ext, usertype FROM mailbox WHERE idx > %d AND deleted=0 AND expiretime > %d limit %d", lastIdx, unixSec, limit) + f5.GetGoStyleDb().SyncSelectCustomQuery( + constant.MAIL_DB, + sql, + func(err error, rows *f5.DataSet) { + if err != nil { + f5.GetSysLog().Info("LoadFromDB Error:%v \n", err) + panic(err) + } + empty := true + for rows.Next() { + empty = false + + m := newMail() + m.Gameid = q5.ToInt(*rows.GetByName("gameid")) + m.MailId = q5.ToInt64(*rows.GetByName("mailid")) + m.From = q5.ToString(*rows.GetByName("_from")) + m.To = q5.ToString(*rows.GetByName("_to")) + m.Subject = q5.ToString(*rows.GetByName("subject")) + m.Content = q5.ToString(*rows.GetByName("content")) + m.Mailtype = q5.ToInt(*rows.GetByName("mailtype")) + m.Mailsubtype = q5.ToInt(*rows.GetByName("mailsubtype")) + m.Usertype = q5.ToInt(*rows.GetByName("usertype")) + m.SendTime = q5.ToInt(*rows.GetByName("sendtime")) + m.Expiretime = q5.ToInt(*rows.GetByName("expiretime")) + m.Createtime = q5.ToInt(*rows.GetByName("createtime")) + // parse ATT + m.ParseAttachments(q5.ToString(*rows.GetByName("attachments"))) + + mm.AddMail(m) + lastIdx = q5.ToInt64(*rows.GetByName("idx")) + } + if empty { + done = true + } + }, + ) + } + // f5.GetSysLog().Info("LoadFromDB Finished round:%d, mails:%d", LoadRound, len(mm.allMailHash)) +} diff --git a/server/mailserver/mail/mailmgr.go b/server/mailserver/mail/mailmgr.go new file mode 100644 index 00000000..21cb39ed --- /dev/null +++ b/server/mailserver/mail/mailmgr.go @@ -0,0 +1,41 @@ +package mail + +import ( + "f5" + "main/common" + "q5" +) + +type MailMgr struct { + allMailHash map[int64]*Mail + gameMailHash map[int]map[int64]*Mail + playerMailHash map[string]map[int64]*Mail + currReqId int64 + lastFetchMailTick int64 + accountHash map[string]*common.Player +} + +func (mm *MailMgr) Init() { + mm.allMailHash = make(map[int64]*Mail) + mm.gameMailHash = make(map[int]map[int64]*Mail) + mm.playerMailHash = make(map[string]map[int64]*Mail) + mm.FetchMailFromDB() +} + +func (mm *MailMgr) UnInit() { +} + +func (mm *MailMgr) FetchMailFromDB() { + timer := f5.GetTimer() + timer.SetInterval(1000, func(e int32, args *q5.Args) { + if e == q5.TIMER_EXEC_EVENT { + mm.LoadFromDB() + } + }) +} + +func (mm *MailMgr) GetAccountObject(accountId string) *common.Player { + return nil + //p := itr = account_hash_.find(accountid); + //return itr != account_hash_.end() ? itr->second : nullptr +} diff --git a/server/mailserver/mail/mailstore.go b/server/mailserver/mail/mailstore.go new file mode 100644 index 00000000..b900606c --- /dev/null +++ b/server/mailserver/mail/mailstore.go @@ -0,0 +1,45 @@ +package mail + +import "main/constant" + +func (mm *MailMgr) AddMail(m *Mail) { + //unixSec := int(time.Now().Unix()) + //if m.Expiretime < unixSec { + // return + //} + if _, exists := mm.allMailHash[m.MailId]; exists { + return + } + + mailId := m.MailId + mm.allMailHash[mailId] = m + if m.Mailtype == constant.MAIL_TYPE_GROUP { + if mm.gameMailHash[m.Gameid] == nil { + mm.gameMailHash[m.Gameid] = make(map[int64]*Mail) + } + mm.gameMailHash[m.Gameid][mailId] = m + return + } + + if m.Mailtype == constant.MAIL_TYPE_PLAYER { + if mm.playerMailHash[m.To] == nil { + mm.playerMailHash[m.To] = make(map[int64]*Mail) + } + mm.playerMailHash[m.To][mailId] = m + return + } +} + +func (mm *MailMgr) GetMails(accountId string) []*Mail { + gameId := 2006 + mails, exists := mm.gameMailHash[gameId] + if !exists { + return nil + } + + mailList := make([]*Mail, 0, len(mails)) + for _, mailData := range mails { + mailList = append(mailList, mailData) + } + return mailList +} diff --git a/server/mailserver/main.go b/server/mailserver/main.go new file mode 100644 index 00000000..ac0e77e9 --- /dev/null +++ b/server/mailserver/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "main/initialize" +) + +func main() { + initialize.Init() +} diff --git a/server/mailserver/makefile b/server/mailserver/makefile new file mode 100644 index 00000000..44df683a --- /dev/null +++ b/server/mailserver/makefile @@ -0,0 +1,17 @@ +compile: + @. /etc/profile + + @export GOPROXY=https://goproxy.io + @go build -gcflags=all="-N -l" -o ../../bin/mailserver/bin + @echo "compile done" + +debug: + @. /etc/profile + + @export GOPROXY=https://goproxy.io + @go build -gcflags=all="-N -l" -ldflags "-X q5.optDebug=1" -o ../../bin/mailserver/bin + @echo "compile done" + +clean: + @rm -f ../../bin/mailserver/bin + @echo "clean done" diff --git a/server/mailserver/middleware/auth.go b/server/mailserver/middleware/auth.go new file mode 100644 index 00000000..3727533d --- /dev/null +++ b/server/mailserver/middleware/auth.go @@ -0,0 +1,27 @@ +package middleware + +import ( + "github.com/gin-gonic/gin" + . "main/global" + "net/http" + "strings" +) + +func Auth() gin.HandlerFunc { + return func(c *gin.Context) { + token := c.Request.Header.Get("Authorization") + strArr := strings.Split(token, "|") + authToken := GetApp().GetSessionAccountId(strArr[0]) + if token == "" || token != authToken { + c.JSON(http.StatusUnauthorized, gin.H{ + "code": 1, + "message": "未登录或非法访问", + }) + /* + response.FailWithDetailed(gin.H{"reload": true}, "未登录或非法访问", c)*/ + c.Abort() + return + } + c.Next() + } +} diff --git a/server/mailserver/middleware/cors.go b/server/mailserver/middleware/cors.go new file mode 100644 index 00000000..bce6048e --- /dev/null +++ b/server/mailserver/middleware/cors.go @@ -0,0 +1,24 @@ +package middleware + +import ( + "github.com/gin-gonic/gin" + "net/http" +) + +func Cors() gin.HandlerFunc { + return func(c *gin.Context) { + method := c.Request.Method + //origin := c.Request.Header.Get("Origin") + //if origin != "" { + c.Header("Access-Control-Allow-Origin", "*") // 可将将 * 替换为指定的域名 + c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") + c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization") + c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type") + c.Header("Access-Control-Allow-Credentials", "true") + //} + if method == "OPTIONS" { + c.AbortWithStatus(http.StatusNoContent) + } + c.Next() + } +} diff --git a/server/mailserver/model/mail/mail.go b/server/mailserver/model/mail/mail.go new file mode 100644 index 00000000..34a279e6 --- /dev/null +++ b/server/mailserver/model/mail/mail.go @@ -0,0 +1,8 @@ +package mail + +type emailReq struct { + Mailtype int `binding:"required" json:"mailtype"` + Usertype int `json:"usertype"` + Attachments string `json:"attachments"` + Ext string `json:"ext"` +} diff --git a/server/mailserver/model/system/announcement.go b/server/mailserver/model/system/announcement.go new file mode 100644 index 00000000..95dd90ed --- /dev/null +++ b/server/mailserver/model/system/announcement.go @@ -0,0 +1,15 @@ +package system + +type Annc struct { + Idx uint64 `json:"idx" ` + Title string `json:"title" binding:"required" ` + Version string `json:"version" binding:"required" ` + Model uint `json:"model" binding:"required" ` + Type uint `json:"type" binding:"required"` + IsEffect uint `json:"is_effect"` + Content string `json:"content" binding:"required" ` +} + +func (this Annc) TableName() string { + return "t_announcement" +} diff --git a/server/mailserver/model/system/audit.go b/server/mailserver/model/system/audit.go new file mode 100644 index 00000000..f8c33db5 --- /dev/null +++ b/server/mailserver/model/system/audit.go @@ -0,0 +1,12 @@ +package system + +type Audit struct { + Idx uint `json:"idx" ` + Version string `json:"version" binding:"required" ` + Model uint `json:"model" binding:"required" ` + IsAuditing uint `json:"is_auditing" ` +} + +func (this Audit) TableName() string { + return "t_audit" +} diff --git a/server/mailserver/model/system/sys_user.go b/server/mailserver/model/system/sys_user.go new file mode 100644 index 00000000..df2d8749 --- /dev/null +++ b/server/mailserver/model/system/sys_user.go @@ -0,0 +1,12 @@ +package system + +type SysUser struct { + Idx uint64 `json:"idx"` + Username string `gorm:"uniqueIndex;comment:用户登录名" json:"username"` + Password string `gorm:"comment:用户登录密码" json:"password"` + Roles []string `json:"roles" gorm:"-"'` +} + +func (SysUser) TableName() string { + return "t_user" +} diff --git a/server/mailserver/mt/Config.go b/server/mailserver/mt/Config.go new file mode 100644 index 00000000..a7fdaed8 --- /dev/null +++ b/server/mailserver/mt/Config.go @@ -0,0 +1,15 @@ +package mt + +import ( + "f5" + "mtb" +) + +type Config struct { + mtb.Config +} + +type ConfigTable struct { + f5.IdMetaTable[Config] + selfConf *Config +} diff --git a/server/mailserver/mt/MailCluster.go b/server/mailserver/mt/MailCluster.go new file mode 100644 index 00000000..9d821836 --- /dev/null +++ b/server/mailserver/mt/MailCluster.go @@ -0,0 +1,34 @@ +package mt + +import ( + "f5" + "mtb" +) + +type MailCluster struct { + mtb.MailCluster +} + +type MailClusterTable struct { + f5.IdMetaTable[MailCluster] + selfConf *MailCluster +} + +func (this *MailCluster) Init1() { + +} + +func (this *MailClusterTable) GetListenPort() int32 { + return this.selfConf.GetListenPort() +} + +func (this *MailClusterTable) GetHttpListenPort() int32 { + return this.selfConf.GetHttpListenPort() +} + +func (this *MailClusterTable) PostInit1() { + this.selfConf = this.GetById(int64(f5.GetApp().GetInstanceId())) + if this.selfConf == nil { + panic("mailserver集群无法读取本服配置") + } +} diff --git a/server/mailserver/mt/MailDb.go b/server/mailserver/mt/MailDb.go new file mode 100644 index 00000000..32067b75 --- /dev/null +++ b/server/mailserver/mt/MailDb.go @@ -0,0 +1,17 @@ +package mt + +import ( + "f5" + "mtb" +) + +type MailDb struct { + mtb.MailDb +} + +type MailDbTable struct { + f5.IdMetaTable[MailDb] +} + +func (this *MailDb) Init1() { +} diff --git a/server/mailserver/mt/export.go b/server/mailserver/mt/export.go new file mode 100644 index 00000000..c1b1d13d --- /dev/null +++ b/server/mailserver/mt/export.go @@ -0,0 +1,28 @@ +package mt + +import ( + "f5" +) + +type table struct { + MailCluster *MailClusterTable + MailDb *MailDbTable + Config *ConfigTable +} + +var Table = f5.New(func(this *table) { + this.MailCluster = f5.New(func(this *MailClusterTable) { + this.FileName = "../config/mailserver.cluster.json" + this.PrimKey = "instance_id" + }) + + this.MailDb = f5.New(func(this *MailDbTable) { + this.FileName = "../config/maildb.mysql.json" + this.PrimKey = "" + }) + + this.Config = f5.New(func(this *ConfigTable) { + this.FileName = "../config/config.json" + this.PrimKey = "" + }) +}) diff --git a/server/mailserver/mt/go.mod b/server/mailserver/mt/go.mod new file mode 100644 index 00000000..53d319d6 --- /dev/null +++ b/server/mailserver/mt/go.mod @@ -0,0 +1,14 @@ +module mt + +go 1.20 + +require q5 v1.0.0 +require f5 v1.0.0 +require mtb v1.0.0 + +require ( +) + +replace q5 => ../../../third_party/q5 +replace f5 => ../../../third_party/f5 +replace mtb => ../mtb \ No newline at end of file diff --git a/server/mailserver/mtb/go.mod b/server/mailserver/mtb/go.mod new file mode 100644 index 00000000..5e8b3f91 --- /dev/null +++ b/server/mailserver/mtb/go.mod @@ -0,0 +1,16 @@ +module mtb + +go 1.20 + +require q5 v1.0.0 + +require f5 v1.0.0 + +require ( + github.com/golang/protobuf v1.5.0 + google.golang.org/protobuf v1.31.0 +) + +replace q5 => ../../../third_party/q5 + +replace f5 => ../../../third_party/f5 diff --git a/server/mailserver/mtb/go.sum b/server/mailserver/mtb/go.sum new file mode 100644 index 00000000..88e5c542 --- /dev/null +++ b/server/mailserver/mtb/go.sum @@ -0,0 +1,23 @@ +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/server/mailserver/mtb/mtb.auto_gen.go b/server/mailserver/mtb/mtb.auto_gen.go new file mode 100644 index 00000000..0c3fbc2c --- /dev/null +++ b/server/mailserver/mtb/mtb.auto_gen.go @@ -0,0 +1,123 @@ +package mtb + +import ( + "f5" +) + +type MailCluster struct { + instance_id int32 + listen_port int32 + http_listen_port int32 + + _flags1_ uint64 + _flags2_ uint64 +} + +type MailDb struct { + host string + port int32 + user string + passwd string + database string + + _flags1_ uint64 + _flags2_ uint64 +} + +type Config struct { + gameapi_url string + + _flags1_ uint64 + _flags2_ uint64 +} + +func (this *MailCluster) GetInstanceId() int32 { + return this.instance_id +} + +func (this *MailCluster) HasInstanceId() bool { + return (this._flags1_ & (uint64(1) << 1)) > 0 +} + +func (this *MailCluster) GetListenPort() int32 { + return this.listen_port +} + +func (this *MailCluster) HasListenPort() bool { + return (this._flags1_ & (uint64(1) << 2)) > 0 +} + +func (this *MailCluster) GetHttpListenPort() int32 { + return this.http_listen_port +} + +func (this *MailCluster) HasHttpListenPort() bool { + return (this._flags1_ & (uint64(1) << 3)) > 0 +} + +func (this *MailDb) GetHost() string { + return this.host +} + +func (this *MailDb) HasHost() bool { + return (this._flags1_ & (uint64(1) << 1)) > 0 +} + +func (this *MailDb) GetPort() int32 { + return this.port +} + +func (this *MailDb) HasPort() bool { + return (this._flags1_ & (uint64(1) << 2)) > 0 +} + +func (this *MailDb) GetUser() string { + return this.user +} + +func (this *MailDb) HasUser() bool { + return (this._flags1_ & (uint64(1) << 3)) > 0 +} + +func (this *MailDb) GetPasswd() string { + return this.passwd +} + +func (this *MailDb) HasPasswd() bool { + return (this._flags1_ & (uint64(1) << 4)) > 0 +} + +func (this *MailDb) GetDatabase() string { + return this.database +} + +func (this *MailDb) HasDatabase() bool { + return (this._flags1_ & (uint64(1) << 5)) > 0 +} + +func (this *Config) GetGameapiUrl() string { + return this.gameapi_url +} + +func (this *Config) HasGameapiUrl() bool { + return (this._flags1_ & (uint64(1) << 1)) > 0 +} + + +func (this *MailCluster) LoadFromKv(kv map[string]interface{}) { + f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv) + f5.ReadMetaTableField(&this.listen_port, "listen_port", &this._flags1_, 2, kv) + f5.ReadMetaTableField(&this.http_listen_port, "http_listen_port", &this._flags1_, 3, kv) +} + +func (this *MailDb) LoadFromKv(kv map[string]interface{}) { + f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv) + f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv) + f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv) + f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv) + f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv) +} + +func (this *Config) LoadFromKv(kv map[string]interface{}) { + f5.ReadMetaTableField(&this.gameapi_url, "gameapi_url", &this._flags1_, 1, kv) +} diff --git a/server/mailserver/player/export.go b/server/mailserver/player/export.go new file mode 100644 index 00000000..5dd96525 --- /dev/null +++ b/server/mailserver/player/export.go @@ -0,0 +1,12 @@ +package player + +import ( + "main/constant" + "main/global" +) + +var _playerMgr = new(playerMgr) + +func init() { + global.RegModule(constant.PLAYER_MGR_MODULE_IDX, _playerMgr) +} diff --git a/server/mailserver/player/player.go b/server/mailserver/player/player.go new file mode 100644 index 00000000..05acce7e --- /dev/null +++ b/server/mailserver/player/player.go @@ -0,0 +1,40 @@ +package player + +import "main/mail" +import "main/ss" + +type player struct { + accountId string + sessionId string + registerTime int + readMailHash map[int64]*mail.Mail + deletedMailHash map[int64]*mail.Mail +} + +func (p *player) init() { + p.readMailHash = make(map[int64]*mail.Mail) + p.deletedMailHash = make(map[int64]*mail.Mail) +} + +func (p *player) IsUnreadMail(mailId int64) bool { + m := p.readMailHash[mailId] + return m == nil +} + +func (p *player) IsDeletedMail(mailId int64) bool { + m := p.deletedMailHash[mailId] + return m != nil +} + +func (p *player) MarkMail(mailIds string) {} +func (p *player) DeleteMails(mailIds string) {} +func (p *player) AddToReadList(mailIds string) {} +func (p *player) GetAttachment(mailIds string) {} + +func (p *player) Deserialize(accountPB ss.MFAccountData) {} + +func (p *player) Serialize(accountPB ss.MFAccountData) { + +} + +func (p *player) SaveToDB() {} diff --git a/server/mailserver/player/playermgr.go b/server/mailserver/player/playermgr.go new file mode 100644 index 00000000..a08f34bf --- /dev/null +++ b/server/mailserver/player/playermgr.go @@ -0,0 +1,19 @@ +package player + +type playerMgr struct { + accountIdHash map[string]*player +} + +func (pm *playerMgr) Init() { + pm.accountIdHash = make(map[string]*player) +} + +func (pm *playerMgr) UnInit() { +} + +func (pm *playerMgr) GetPlayer(accountId string) *player { + if p, exists := pm.accountIdHash[accountId]; exists { + return p + } + return nil +} diff --git a/server/mailserver/proto/cs_msgid.proto b/server/mailserver/proto/cs_msgid.proto new file mode 100644 index 00000000..e1e007d5 --- /dev/null +++ b/server/mailserver/proto/cs_msgid.proto @@ -0,0 +1,4 @@ +syntax = "proto2"; +package cs; +option go_package = ".;cs"; + diff --git a/server/mailserver/proto/cs_proto.proto b/server/mailserver/proto/cs_proto.proto new file mode 100644 index 00000000..e1e007d5 --- /dev/null +++ b/server/mailserver/proto/cs_proto.proto @@ -0,0 +1,4 @@ +syntax = "proto2"; +package cs; +option go_package = ".;cs"; + diff --git a/server/mailserver/proto/mt.proto b/server/mailserver/proto/mt.proto new file mode 100644 index 00000000..9b764f9d --- /dev/null +++ b/server/mailserver/proto/mt.proto @@ -0,0 +1,24 @@ +package mt; + +option go_package = ".;mt"; + +message MailCluster +{ + optional int32 instance_id = 1; + optional int32 listen_port = 2; + optional int32 http_listen_port = 3; +} + +message MailDb +{ + optional string host = 1; + optional int32 port = 2; + optional string user = 3; + optional string passwd = 4; + optional string database = 5; +} + +message Config +{ + optional string gameapi_url = 1; +} diff --git a/server/mailserver/proto/protoc-gen.bat b/server/mailserver/proto/protoc-gen.bat new file mode 100644 index 00000000..61b25a95 --- /dev/null +++ b/server/mailserver/proto/protoc-gen.bat @@ -0,0 +1,2 @@ +protoc --go_out=..\cs .\cs_*.proto +protoc --go_out=..\ss .\ss_*.proto diff --git a/server/mailserver/proto/ss_msgid.proto b/server/mailserver/proto/ss_msgid.proto new file mode 100644 index 00000000..a50b6c9e --- /dev/null +++ b/server/mailserver/proto/ss_msgid.proto @@ -0,0 +1,4 @@ +syntax = "proto2"; +package ss; +option go_package = ".;ss"; + diff --git a/server/mailserver/proto/ss_proto.proto b/server/mailserver/proto/ss_proto.proto new file mode 100644 index 00000000..5ee7e794 --- /dev/null +++ b/server/mailserver/proto/ss_proto.proto @@ -0,0 +1,37 @@ +syntax = "proto2"; +package ss; +option go_package = ".;ss"; + + +//行数据 +message MFRow +{ + repeated string values = 1; //数据 +} + +//数据集 +message MFDataSet +{ + repeated MFRow rows = 1; //行数据 +} + + +message MFReadMail +{ + optional int64 mail_id = 1; //mail id + optional int32 read_time = 2; //读取时间 + optional int32 expire_time = 3; //消息过期时间 +} + +message MFDeletedMail +{ + optional int64 mail_id = 1; //mail id + optional int32 delete_time = 2; //删除时间 + optional int32 expire_time = 3; //消息过期时间 +} + +message MFAccountData +{ + repeated MFReadMail read_mail_list = 1; //已读取消息 + repeated MFDeletedMail deleted_mail_list = 2; //已删除消息 +} diff --git a/server/mailserver/router/export.go b/server/mailserver/router/export.go new file mode 100644 index 00000000..4c2a87fa --- /dev/null +++ b/server/mailserver/router/export.go @@ -0,0 +1,12 @@ +package router + +import ( + "main/constant" + "main/global" +) + +var _routerMgr = new(routerMgr) + +func init() { + global.RegModule(constant.ROUTER_MODULE_IDX, _routerMgr) +} diff --git a/server/mailserver/router/mail.go b/server/mailserver/router/mail.go new file mode 100644 index 00000000..af99b367 --- /dev/null +++ b/server/mailserver/router/mail.go @@ -0,0 +1,18 @@ +package router + +import ( + "github.com/gin-gonic/gin" + "main/api" +) + +type MailRoute struct{} + +func (r *MailRoute) InitMailRouter(pubRouter *gin.RouterGroup) { + mailRouter := pubRouter.Group("/") + mailAPI := api.ApiGroupApp.Mail + mailRouter.GET("mails", mailAPI.GetMailList) + mailRouter.GET("markMail", mailAPI.MarkMail) + mailRouter.GET("getUnreadMailCount", mailAPI.GetUnreadMailCount) + mailRouter.GET("getMailAttachment", mailAPI.GetMailAttachment) + mailRouter.GET("deleteMails", mailAPI.DeleteMails) +} diff --git a/server/mailserver/router/routermgr.go b/server/mailserver/router/routermgr.go new file mode 100644 index 00000000..f88a6c61 --- /dev/null +++ b/server/mailserver/router/routermgr.go @@ -0,0 +1,24 @@ +package router + +import ( + "f5" + "github.com/gin-gonic/gin" +) + +type routerMgr struct { + mail MailRoute +} + +func (rm *routerMgr) Init() { + router := f5.GetApp().GetGinEngine() + router.Use(gin.Logger()) + + pubRouterGroup := router.Group("api") + rm.mail.InitMailRouter(pubRouterGroup) + + f5.GetSysLog().Info("routerMgr.init") +} + +func (rm *routerMgr) UnInit() { + +} diff --git a/server/mailserver/ss/go.sum b/server/mailserver/ss/go.sum new file mode 100644 index 00000000..88e5c542 --- /dev/null +++ b/server/mailserver/ss/go.sum @@ -0,0 +1,23 @@ +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/server/mailserver/ss/ss.auto_gen.go b/server/mailserver/ss/ss.auto_gen.go new file mode 100644 index 00000000..b6de6518 --- /dev/null +++ b/server/mailserver/ss/ss.auto_gen.go @@ -0,0 +1,41 @@ +package ss + +import ( + "f5" +) + +type SsNetMsgHandler f5.NetMsgHandler[MsgHandler] + +type MsgHandlerImpl struct { +} + +var handlers [2000]*SsNetMsgHandler + +func GetNetMsgHandler(msgId uint16) *SsNetMsgHandler { + handler := handlers[msgId] + return handler +} + +func DispatchMsg(handler *SsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) { + handler.Cb(hdr, msgHandler) +} + +func RegHandlerId(msgId int, handlerId int) { + handler := handlers[msgId] + handler.HandlerId = handlerId +} + +func ParsePb(msgId uint16, data []byte) interface{} { + handler := handlers[msgId] + if handler == nil { + return nil + } + return handler.ParseCb(data) +} + +type MsgHandler interface { +} + +func init() { + +}