| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package proto
- import (
- "context"
- "bet24.com/log"
- "bet24.com/servers/micros/common"
- "github.com/smallnest/rpcx/client"
- )
- const ServiceName = "game"
- var consulAddr = common.Default_Consul_Addr
- func getClient() client.XClient {
- return common.GetClientPool().GetClient(ServiceName, consulAddr)
- }
- type Request struct {
- Name string
- }
- type Response struct {
- Data string
- }
- func SetConsulAddr(addr string) {
- consulAddr = addr
- }
- func SayHello(name string) string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request{
- Name: name,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "SayHello", args, reply)
- if err != nil {
- log.Debug("game failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- log.Debug("SayHello return %s", reply.Data)
- return reply.Data
- }
- func GetGame(gameId int) *GameInfo {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GetGame{
- GameID: gameId,
- }
- reply := &Response_GetGame{}
- err := xclient.Call(context.Background(), "GetGame", args, reply)
- if err != nil {
- log.Debug("game.GetGame failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return nil
- }
- return reply.Info
- }
- func GetGameJson(userId int, userIp string, partnerId, versionCode int) string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GetGameJson{
- UserId: userId,
- UserIp: userIp,
- PartnerId: partnerId,
- VersionCode: versionCode,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetGameJson", args, reply)
- if err != nil {
- log.Debug("game.GetGameJson failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return reply.Data
- }
- return reply.Data
- }
- // 获取游戏地址
- func GetGameAddr(userId int) string {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GetGameAddr{
- UserId: userId,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetGameAddr", args, reply)
- if err != nil {
- log.Debug("game.GetGameAddr failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return reply.Data
- }
- return reply.Data
- }
- // 游戏轮询
- func GamePolling(addr string, players int) {
- xclient := getClient()
- //defer xclient.Close()
- args := &Request_GamePolling{
- Addr: addr,
- Players: players,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "GamePolling", args, reply)
- if err != nil {
- log.Debug("game.GamePolling failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return
- }
- return
- }
- // GetReviewGame
- func GetReviewGame(ip string, partnerId, versionCode int) string {
- xclient := getClient()
- args := &Request_IsInReview{
- UserIp: ip,
- PartnerId: partnerId,
- VersionCode: versionCode,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetReviewGame", args, reply)
- if err != nil {
- log.Debug("game.GamePolling failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- return reply.Data
- }
- func GetGameList() []GameInfo {
- xclient := getClient()
- args := &Request{}
- reply := &Response_GetGameList{}
- err := xclient.Call(context.Background(), "GetGameList", args, reply)
- if err != nil {
- log.Debug("game.GamePolling failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- }
- return reply.List
- }
- func GetGameNameByGameId(gameId int) string {
- g := GetGame(gameId)
- if g == nil {
- return ""
- }
- return g.EnglishName
- }
- // 根据IP地址获取国家地区地理位置
- func GetCountryAndRegion(ipAddress string) (country, region string) {
- xClient := getClient()
- args := &Request_GetCountryAndRegion{
- IpAddress: ipAddress,
- }
- reply := &Response_GetCountryAndRegion{}
- err := xClient.Call(context.Background(), "GetCountryAndRegion", args, reply)
- if err != nil {
- log.Debug("game.GamePolling failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return
- }
- country = reply.Country
- region = reply.Region
- return
- }
|