LollipopGo开源游戏服务器框架--邮件功能demo

Golang语言社区 · · 1134 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

      大家好,我是彬哥,本节给大家讲下LollipopGov1.0.20190102版本游戏服务器邮件功能,抛砖引玉了,主要是针对Go语言游戏服务器邮件功能处理。


邮件
//------------------------------------------------------------------------------

var EmailDatatmp map[int]*player.EmailST
var ItemListtmp map[int]*player.ItemST
var PaoMaDeng map[int]*player.MsgST
var iicounmsg int = 3
var iicounemail int = 6

func init() {
    EmailDatatmp = make(map[int]*player.EmailST)
    ItemListtmp = make(map[int]*player.ItemST)
    PaoMaDeng = make(map[int]*player.MsgST)

    if true {
        data := new(player.EmailST)
        data.ID = 1
        data.Name = "测试邮件1"
        data.Sender = "test1"
        data.Type = 1
        data.Time = int(util.GetNowUnix_LollipopGo())
        data.Content = "测试邮件内容1"
        data.IsAdd_ons = false
        data.IsOpen = false
        data.IsGet = false
        EmailDatatmp[data.ID] = data
    }

    if true {
        data := new(player.EmailST)
        data.ID = 2
        data.Name = "测试邮件2"
        data.Sender = "test2"
        data.Type = 4
        data.Time = int(util.GetNowUnix_LollipopGo())
        data.Content = "测试邮件内容2"
        data.IsAdd_ons = false
        data.IsOpen = false
        data.IsGet = false
        EmailDatatmp[data.ID] = data
    }

    if true {
        data := new(player.EmailST)
        data.ID = 3
        data.Name = "测试邮件3"
        data.Sender = "test3"
        data.Type = 1
        data.Time = int(util.GetNowUnix_LollipopGo())
        data.Content = "测试邮件内容3"
        data.IsAdd_ons = true
        data.IsOpen = false
        data.IsGet = false

        if true {
            dataitem := new(player.ItemST)
            dataitem.ID = 1
            dataitem.Icon = ""
            dataitem.Name = "M卡"
            dataitem.Itype = 1
            dataitem.Num = 10
            ItemListtmp[dataitem.ID] = dataitem
        }

        data.ItemList = ItemListtmp
        EmailDatatmp[data.ID] = data
    }

    if true {
        data := new(player.EmailST)
        data.ID = 4
        data.Name = "测试邮件4"
        data.Sender = "test4"
        data.Type = 4
        data.Time = int(util.GetNowUnix_LollipopGo())
        data.Content = "测试邮件内容1"
        data.IsAdd_ons = false
        data.IsOpen = false
        data.IsGet = true
        EmailDatatmp[data.ID] = data
    }

    if true {
        data := new(player.EmailST)
        data.ID = 5
        data.Name = "测试邮件5"
        data.Sender = "test5"
        data.Type = 1
        data.Time = int(util.GetNowUnix_LollipopGo())
        data.Content = "测试邮件内容1"
        data.IsAdd_ons = false
        data.IsOpen = true
        data.IsGet = true
        EmailDatatmp[data.ID] = data
    }

    if true {
        data := new(player.EmailST)
        data.ID = 6
        data.Name = "测试邮件6"
        data.Sender = "test6"
        data.Type = 4
        data.Time = int(util.GetNowUnix_LollipopGo())
        data.Content = "测试邮件内容3"
        data.IsAdd_ons = true
        data.IsOpen = true
        data.IsGet = true

        if true {
            dataitem := new(player.ItemST)
            dataitem.ID = 1
            dataitem.Icon = ""
            dataitem.Name = "M卡"
            dataitem.Itype = 1
            dataitem.Num = 10
            ItemListtmp[dataitem.ID] = dataitem
        }

        data.ItemList = ItemListtmp
        EmailDatatmp[data.ID] = data
    }
    //--------------------------------------------------------------------------
    // DefaultMsg    map[string]*player.MsgST    // 默认跑马灯消息
    if true {
        data := new(player.MsgST)
        data.MsgID = 1
        data.MsgType = player.MsgType1
        data.MsgDesc = "系统消息:充值998,送B站24K纯金哥斯拉"
        PaoMaDeng[data.MsgID] = data
    }
    if true {
        data := new(player.MsgST)
        data.MsgID = 2
        data.MsgType = player.MsgType2
        data.MsgDesc = "恭喜【XXX玩家】在XX比赛中获得xxx奖励"
        PaoMaDeng[data.MsgID] = data
    }
    if true {
        data := new(player.MsgST)
        data.MsgID = 3
        data.MsgType = player.MsgType3
        data.MsgDesc = "恭喜【XXX玩家】在兑换中心成功兑换SSS"
        PaoMaDeng[data.MsgID] = data
    }
    return
}

func TimeMsgNotice(conn *websocket.Conn, Conndata *rpc.Client) {
    //return
    // if GL_type != "8894" {
    //  return
    // }
    good_conn := conn
    for {
        select {
        case <-time.After(time.Second * 30):
            {
                data := GetEmailDataFromDB(Conndata)
                fmt.Println("GetEmailDataFromDB------:", data)
                if len(data) > 0 {
                    iicounemail++
                    EmailNoticeFunc(good_conn)
                }
                // iicounmsg++
                // MsgNoticeFuncbak(conn)
                // EmailNoticeFunc(conn)
            }
        }
    }
}

//------------------------------------------------------------------------------
// 获取数据的数据 from DB
func GetEmailDataFromDB(Conndata *rpc.Client) map[int]*player.EmailST {
    args := 1
    var reply map[int]*player.EmailST
    // 异步调用【结构的方法】
    if Conndata != nil {
        divCall := Conndata.Go("Arith.GetPlayerEmailDataGM", args, &reply, nil)
        replyCall := <-divCall.Done
        _ = replyCall.Reply
    } else {
        fmt.Println("ConnRPC == nil")
    }
    return reply
}

func EmailNoticeFunc(conn *websocket.Conn) {

    EmailDatatmpbak := make(map[int]*player.EmailST)
    if true {
        data := new(player.EmailST)
        data.ID = iicounemail
        data.Name = "邮件通知"
        data.Sender = "admin"
        data.Type = 1
        data.Time = int(util.GetNowUnix_LollipopGo())
        data.Content = "通知内容"
        data.IsAdd_ons = false
        data.IsOpen = true
        data.IsGet = true
        EmailDatatmpbak[data.ID] = data
    }

    data_send := &Proto2.G_Broadcast_NoticePlayerEmail{
        Protocol:  Proto.G_GameGlobal_Proto,
        Protocol2: Proto2.G_Broadcast_NoticePlayerEmailProto2,
        EmailData: EmailDatatmpbak,
    }

    fmt.Println("邮件通知:", data_send)
    PlayerSendToServer(conn, data_send)
    return
}

// 全服通知
func MsgNoticeFuncbak(conn *websocket.Conn) {
    PaoMaDengbak := make(map[int]*player.MsgST)
    if true {
        data := new(player.MsgST)
        data.MsgID = iicounmsg
        data.MsgType = player.MsgType1
        data.MsgDesc = "系统消息:充值998,送B站24K纯金哥斯拉"
        PaoMaDengbak[data.MsgID] = data
    }

    data_send := &Proto2.G_Broadcast_MsgNoticePlayer{
        Protocol:  Proto.G_GameGlobal_Proto,
        Protocol2: Proto2.G_Broadcast_MsgNoticePlayerProto2,
        OpenID:    "6412121cbb2dc2cb9e460cfee7046be2",
        MsgData:   PaoMaDengbak,
    }

    fmt.Println("消息通知:", data_send)
    PlayerSendToServer(conn, data_send)

    return
}

//------------------------------------------------------------------------------

      每天坚持学习1小时Go语言,大家加油,我是彬哥,下期见!如果文章中不同观点、意见请文章下留言或者关注下方订阅号反馈!


社区交流群:221273219
Golang语言社区论坛 :
www.Golang.Ltd
LollipopGo游戏服务器地址:
https://github.com/Golangltd/LollipopGo
社区视频课程课件GIT地址:
https://github.com/Golangltd/codeclass


Golang语言社区

有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:Golang语言社区

查看原文:LollipopGo开源游戏服务器框架--邮件功能demo

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1134 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传