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

栏目: Go · 发布时间: 5年前

内容简介:大家好,我是彬哥,本节给大家讲下LollipopGov1.0.20190102版本游戏服务器邮件功能,抛砖引玉了,主要是针对Go语言游戏服务器邮件功能处理。每天坚持学习1小时Go语言,大家加油,我是彬哥,下期见!如果文章中不同观点、意见请文章下留言或者关注下方订阅号反馈!

大家好,我是彬哥,本节给大家讲下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
LollipopGo开源游戏服务器框架--邮件功能demo

Golang语言社区


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Python 3网络爬虫开发实战

Python 3网络爬虫开发实战

崔庆才 / 人民邮电出版社 / 2018-4 / 99

本书介绍了如何利用Python 3开发网络爬虫,书中首先介绍了环境配置和基础知识,然后讨论了urllib、requests、正则表达式、Beautiful Soup、XPath、pyquery、数据存储、Ajax数据爬取等内容,接着通过多个案例介绍了不同场景下如何实现数据爬取,后介绍了pyspider框架、Scrapy框架和分布式爬虫。 本书适合Python程序员阅读。一起来看看 《Python 3网络爬虫开发实战》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具