user_center_func.go 18.7 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6
package rpc

import (
	"encoding/json"
	"git.hilo.cn/hilo-common/mylogrus"
	"git.hilo.cn/hilo-common/protocol/userProxy"
chenweijian's avatar
chenweijian committed
7
	"git.hilo.cn/hilo-common/utils"
hujiebin's avatar
hujiebin committed
8
	"google.golang.org/protobuf/proto"
hujiebin's avatar
hujiebin committed
9
	"time"
hujiebin's avatar
hujiebin committed
10 11 12 13 14 15 16 17 18 19 20
)

func SendFruitMachine(date string, round uint32) error {
	msg := &userProxy.FruitMachine{
		Date:  date,
		Round: round,
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := broadcast(MsgFruitMachine, buffer)

		//记录socket,注意闭包问题
iamhujiebin's avatar
iamhujiebin committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
		go func(userId uint64, msg *userProxy.FruitMachine, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgFruitMachine, userId, string(buf[:]), rspUids, err)
		}(0, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendFruitMachine send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendFruitMachine send success")
		}
	} else {
		return err
	}
	return nil
}

func SendFruitMachineToUser(date string, round uint32, userIds []uint64) error {
	msg := &userProxy.FruitMachine{
		Date:  date,
		Round: round,
	}
	if buffer, err := proto.Marshal(msg); err == nil {
44
		rspUids, err := multicast(userIds, MsgFruitMachine, buffer, time.Duration(5))
iamhujiebin's avatar
iamhujiebin committed
45 46

		//记录socket,注意闭包问题
hujiebin's avatar
hujiebin committed
47 48 49
		go func(userId uint64, msg *userProxy.FruitMachine, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgFruitMachine, userId, string(buf[:]), rspUids, err)
hujiebin's avatar
hujiebin committed
50
		}(uint64(len(userIds)), msg, rspUids, err)
hujiebin's avatar
hujiebin committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendFruitMachine send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendFruitMachine send success")
		}
	} else {
		return err
	}
	return nil
}

func SendGlobalRocketNotice(groupId string, period string, round uint32, stage uint32, fromUserId uint64, topUserIcon string, nick string, code string, avatar string) error {
	msg := &userProxy.GlobalRocketNotice{
		GroupId:     groupId,
		Period:      period,
		Round:       round,
		Stage:       stage,
		TopUserIcon: topUserIcon,
		Nick:        nick,
		Code:        code,
		Avatar:      avatar,
	}

	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := broadcast(MsgTypeGlobalRocketNotice, buffer)

		//记录socket,注意闭包问题
		go func(userId uint64, msg *userProxy.GlobalRocketNotice, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgTypeGlobalRocketNotice, userId, string(buf[:]), rspUids, err)
		}(fromUserId, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc GlobalRocketNotice send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc GlobalRocketNotice send success")
		}
	} else {
		return err
	}
	return nil
}
96

hujiebin's avatar
hujiebin committed
97
// 发送钻石变化通知
98
func SendDiamondChange(userId uint64, diamond, pinkDiamond uint32) error {
hujiebin's avatar
hujiebin committed
99
	msg := &userProxy.DiamondChange{
100 101
		RemainDiamond:     diamond,
		RemainPinkDiamond: pinkDiamond,
hujiebin's avatar
hujiebin committed
102 103 104
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := multicast([]uint64{userId}, MsgDiamondChange, buffer)
hujiebin's avatar
hujiebin committed
105 106 107 108 109 110 111 112
		// 记录socket
		// 有err||uid不在线才入库
		if err != nil || len(rspUids) > 0 {
			go func(userId uint64, msg *userProxy.DiamondChange, rspUids []uint64, err error) {
				buf, _ := json.Marshal(msg)
				AddRpcLog(MsgDiamondChange, userId, string(buf[:]), rspUids, err)
			}(userId, msg, rspUids, err)
		}
113

hujiebin's avatar
hujiebin committed
114 115 116 117 118 119
		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendDiamondChange send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendDiamondChange send success")
		}
120
	} else {
hujiebin's avatar
hujiebin committed
121
		return err
122 123 124
	}
	return nil
}
hujiebin's avatar
hujiebin committed
125 126 127

// 发送游戏横幅
// param winUserId:胜利的用户id
hujiebin's avatar
hujiebin committed
128
// param gameType 0:slot 5:luckybox 6:fruit
hujiebin's avatar
hujiebin committed
129
// param gameId 7:slot 8:candy 5:luckybox 6:fruit
iamhujiebin's avatar
iamhujiebin committed
130
func SendGlobalGameBanner(winUserId uint64, diamond uint64, avatar string, gameId uint64, gameType uint32) error {
chenweijian's avatar
chenweijian committed
131
	defer utils.CheckGoPanic()
hujiebin's avatar
hujiebin committed
132 133 134 135 136 137 138 139 140
	bannerUrl := ""
	switch gameType {
	case 0:
		bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_slot.png"
	case 5:
		bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_luckybox.png"
	case 6:
		bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_fruit.png"
	}
hujiebin's avatar
hujiebin committed
141
	if gameId == uint64(8) {
hujiebin's avatar
hujiebin committed
142
		bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_candy.png"
hujiebin's avatar
hujiebin committed
143
	}
hujiebin's avatar
hujiebin committed
144 145 146
	if gameId == uint64(17) {
		bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_race.png"
	}
hujiebin's avatar
hujiebin committed
147
	msg := &userProxy.GlobalGameBanner{
iamhujiebin's avatar
iamhujiebin committed
148
		GameId:    gameId,
hujiebin's avatar
hujiebin committed
149 150 151 152 153
		GameType:  gameType,
		UserId:    winUserId,
		Avatar:    avatar,
		Diamond:   diamond,
		BannerUrl: bannerUrl,
hujiebin's avatar
hujiebin committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := broadcast(MsgTypeGlobalGameBanner, buffer)

		//记录socket,注意闭包问题
		go func(userId uint64, msg *userProxy.GlobalGameBanner, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgTypeGlobalGameBanner, userId, string(buf[:]), rspUids, err)
		}(winUserId, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendGlobalGameBanner send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendGlobalGameBanner send success")
		}
	} else {
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248

func SendJoinGroup(userId uint64, externalId string, groupId string) error {
	msg := &userProxy.JoinGroup{GroupId: groupId, ExternalId: externalId}
	if buffer, err := proto.Marshal(msg); err == nil {
		userIds := []uint64{userId}
		rspUids, err := multicast(userIds, MsgTypeJoinGroup, buffer)

		//记录socket,注意闭包问题
		go func(userIds []uint64, msg *userProxy.JoinGroup, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLogs(MsgTypeJoinGroup, userIds, string(buf[:]), rspUids, err)
		}(userIds, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendJoinGroup send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendJoinGroup send success")
		}
	} else {
		return err
	}
	return nil
}

func SendConfigChange(operUserId uint64, configType uint32) error {
	msg := &userProxy.ConfigChange{
		Type: configType,
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := broadcast(MsgTypeConfigChange, buffer)

		//记录socket,注意闭包问题
		go func(configType uint32, msg *userProxy.ConfigChange, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgTypeConfigChange, operUserId, string(buf[:]), rspUids, err)
		}(configType, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendConfigChange send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendConfigChange send success")
		}
	} else {
		return err
	}
	return nil
}

func SendGroupChatNotice(fromUserId uint64, userIds []uint64, senderExtId string, senderCode string, senderSex uint32, senderAvatar string,
	text string, groupId, groupName, groupCode, groupAvatar string, userInNum uint32) error {
	msg := &userProxy.GroupSendNotice{
		SenderExtId:  senderExtId,
		SenderCode:   senderCode,
		SenderSex:    senderSex,
		SenderAvatar: senderAvatar,
		Text:         text,
		GroupName:    groupName,
		GroupCode:    groupCode,
		GroupAvatar:  groupAvatar,
		UserInNum:    userInNum,
		GroupId:      groupId,
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := multicast(userIds, MsgTypeGroupChatNotice, buffer)

		//记录socket,注意闭包问题
		go func(userId uint64, msg *userProxy.GroupSendNotice, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgTypeGroupChatNotice, userId, string(buf[:]), rspUids, err)
		}(fromUserId, msg, rspUids, err)

		if err != nil {
hujiebin's avatar
hujiebin committed
249
			mylogrus.MyLog.Errorf("grpc SendGroupChatNotice send fail,userId:%v", fromUserId)
hujiebin's avatar
hujiebin committed
250 251
			return err
		} else {
hujiebin's avatar
hujiebin committed
252
			mylogrus.MyLog.Infof("grpc SendGroupChatNotice send success,userId:%v", fromUserId)
hujiebin's avatar
hujiebin committed
253 254 255 256 257 258
		}
	} else {
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
259 260

// 羊羊匹配成功
hujiebin's avatar
hujiebin committed
261
// Deprecated: missing Params
hujiebin's avatar
hujiebin committed
262 263 264 265 266
func SendSheepMatchSuccess(matchId, myUserId, otherUserId uint64, nick1, nick2, avatar1, avatar2 string, gameIds ...uint64) error {
	gameId := uint64(0)
	if len(gameIds) > 0 {
		gameId = gameIds[0]
	}
hujiebin's avatar
hujiebin committed
267
	msg := &userProxy.SheepMatchSuccess{
hujiebin's avatar
hujiebin committed
268 269 270
		MatchId:   matchId,
		User:      &userProxy.User{Id: myUserId, Nick: nick1, Avatar: avatar1},
		OtherUser: &userProxy.User{Id: otherUserId, Nick: nick2, Avatar: avatar2},
hujiebin's avatar
hujiebin committed
271
		GameId:    gameId,
hujiebin's avatar
hujiebin committed
272 273
	}
	if buffer, err := proto.Marshal(msg); err == nil {
hujiebin's avatar
hujiebin committed
274
		userIds := []uint64{myUserId}
hujiebin's avatar
hujiebin committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
		rspUids, err := multicast(userIds, MsgTypeSheepGameMatchSuccess, buffer)

		//记录socket,注意闭包问题
		go func(userIds []uint64, msg *userProxy.SheepMatchSuccess, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLogs(MsgTypeSheepGameMatchSuccess, userIds, string(buf[:]), rspUids, err)
		}(userIds, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendSheepMatchSuccess send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendSheepMatchSuccess send success")
		}
	} else {
		return err
	}
	return nil
}

hujiebin's avatar
hujiebin committed
295
// 羊羊匹配成功
hujiebin's avatar
hujiebin committed
296
func SendSheepMatchSuccessV2(matchId, myUserId, otherUserId uint64, nick1, nick2, avatar1, avatar2 string, gameId uint64, channelId, token string, agoraId, otherAgoraId uint32, provider int) error {
hujiebin's avatar
hujiebin committed
297
	msg := &userProxy.SheepMatchSuccess{
hujiebin's avatar
hujiebin committed
298 299 300 301 302 303 304 305 306
		MatchId:      matchId,
		User:         &userProxy.User{Id: myUserId, Nick: nick1, Avatar: avatar1},
		OtherUser:    &userProxy.User{Id: otherUserId, Nick: nick2, Avatar: avatar2},
		GameId:       gameId,
		ChannelId:    channelId,
		Token:        token,
		AgoraId:      agoraId,
		OtherAgoraId: otherAgoraId,
		Provider:     uint32(provider),
hujiebin's avatar
hujiebin committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		userIds := []uint64{myUserId}
		rspUids, err := multicast(userIds, MsgTypeSheepGameMatchSuccess, buffer)

		//记录socket,注意闭包问题
		go func(userIds []uint64, msg *userProxy.SheepMatchSuccess, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLogs(MsgTypeSheepGameMatchSuccess, userIds, string(buf[:]), rspUids, err)
		}(userIds, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendSheepMatchSuccess send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendSheepMatchSuccess send success")
		}
	} else {
		return err
	}
	return nil
}

hujiebin's avatar
hujiebin committed
330
// 羊羊游戏结果
hujiebin's avatar
hujiebin committed
331
func SendSheepGameResult(matchId, winId, userId1, userId2 uint64, nick1, nick2, avatar1, avatar2 string, isAiMap map[uint64]bool, gameIds ...uint64) error {
hujiebin's avatar
hujiebin committed
332 333 334
	if isAiMap == nil {
		isAiMap = make(map[uint64]bool)
	}
hujiebin's avatar
hujiebin committed
335 336 337 338 339 340 341
	var players []*userProxy.SheepGamePlayer
	players = append(players, &userProxy.SheepGamePlayer{IsWin: winId == userId1, User: &userProxy.User{
		Id: userId1, Nick: nick1, Avatar: avatar1,
	}})
	players = append(players, &userProxy.SheepGamePlayer{IsWin: winId == userId2, User: &userProxy.User{
		Id: userId2, Nick: nick2, Avatar: avatar2,
	}})
hujiebin's avatar
hujiebin committed
342 343 344 345 346 347
	if !players[0].IsWin {
		players[0], players[1] = players[1], players[0]
	}
	for i := range players {
		players[i].Rank = int32(i) + 1
	}
hujiebin's avatar
hujiebin committed
348 349 350 351
	gameId := uint64(0)
	if len(gameIds) > 0 {
		gameId = gameIds[0]
	}
hujiebin's avatar
hujiebin committed
352 353 354
	msg := &userProxy.SheepGameResult{
		MatchId: matchId,
		Players: players,
hujiebin's avatar
hujiebin committed
355
		GameId:  gameId,
hujiebin's avatar
hujiebin committed
356 357
	}
	if buffer, err := proto.Marshal(msg); err == nil {
hujiebin's avatar
hujiebin committed
358
		var userIds []uint64
hujiebin's avatar
hujiebin committed
359
		if !isAiMap[userId1] {
hujiebin's avatar
hujiebin committed
360 361
			userIds = append(userIds, userId1)
		}
hujiebin's avatar
hujiebin committed
362
		if !isAiMap[userId2] {
hujiebin's avatar
hujiebin committed
363 364
			userIds = append(userIds, userId2)
		}
hujiebin's avatar
hujiebin committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
		rspUids, err := multicast(userIds, MsgTypeSheepGameResult, buffer)

		//记录socket,注意闭包问题
		go func(userIds []uint64, msg *userProxy.SheepGameResult, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLogs(MsgTypeSheepGameResult, userIds, string(buf[:]), rspUids, err)
		}(userIds, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendSheepGameResult send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendSheepGameResult send success")
		}
	} else {
		return err
	}
	return nil
}
chenweijian's avatar
chenweijian committed
384 385

// cp邀请
chenweijian's avatar
chenweijian committed
386
func SendCpInviteNotice(userId uint64, code, name, avatar, content, extId string) error {
chenweijian's avatar
chenweijian committed
387
	defer utils.CheckGoPanic()
chenweijian's avatar
chenweijian committed
388
	msg := &userProxy.CpInvite{
chenweijian's avatar
chenweijian committed
389
		User: &userProxy.User{Id: userId, Code: code, Nick: name, Avatar: avatar, ExternalId: extId},
chenweijian's avatar
chenweijian committed
390 391
		Msg:  content,
	}
chenweijian's avatar
chenweijian committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
	if buffer, err := proto.Marshal(msg); err == nil {
		userIds := []uint64{userId}
		rspUids, err := multicast(userIds, MsgTypeCpInvite, buffer)

		//记录socket,注意闭包问题
		go func(userIds []uint64, msg *userProxy.CpInvite, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLogs(MsgTypeCpInvite, userIds, string(buf[:]), rspUids, err)
		}(userIds, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendCpInviteNotice send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendCpInviteNotice send success")
		}
	} else {
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
413 414

// cp升级
hujiebin's avatar
hujiebin committed
415
func SendCpUpgrade(nick1, nick2, avatar1, avatar2 string, cpLevel uint32, groupId string) error {
hujiebin's avatar
hujiebin committed
416 417 418 419
	msg := &userProxy.CpUpgrade{
		User1:   &userProxy.User{Nick: nick1, Avatar: avatar1},
		User2:   &userProxy.User{Nick: nick2, Avatar: avatar2},
		CpLevel: cpLevel,
hujiebin's avatar
hujiebin committed
420
		GroupId: groupId,
hujiebin's avatar
hujiebin committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := broadcast(MsgTypeCpUpgrade, buffer)

		//记录socket,注意闭包问题
		go func(userId uint64, msg *userProxy.CpUpgrade, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgTypeCpUpgrade, userId, string(buf[:]), rspUids, err)
		}(0, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendCpUpgrade send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendCpUpgrade send success")
		}
	} else {
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
442 443

// svip升级
hujiebin's avatar
hujiebin committed
444
func SendSvipUpgrade(nick, avatar string, svipLevel uint32, txGroupId string) error {
hujiebin's avatar
hujiebin committed
445 446 447
	msg := &userProxy.SvipUpgrade{
		User:      &userProxy.User{Nick: nick, Avatar: avatar},
		SvipLevel: svipLevel,
hujiebin's avatar
hujiebin committed
448
		GroupId:   txGroupId,
hujiebin's avatar
hujiebin committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := broadcast(MsgTypeSvipUpgrade, buffer)

		//记录socket,注意闭包问题
		go func(userId uint64, msg *userProxy.SvipUpgrade, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgTypeSvipUpgrade, userId, string(buf[:]), rspUids, err)
		}(0, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendSvipUpgrade send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendSvipUpgrade send success")
		}
	} else {
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
470 471

// 发送socket的麦位变化
hujiebin's avatar
hujiebin committed
472
func SendSocketMicChange(seqId string, userId uint64, micUserExternalId, txGroupId string, i uint32, lock, forbid, micForbid bool, agoraId uint32, micUserData *userProxy.MicUserData) error {
hujiebin's avatar
hujiebin committed
473
	var msg = &userProxy.GroupMicChange{
hujiebin's avatar
hujiebin committed
474
		SeqId:      seqId,
hujiebin's avatar
hujiebin committed
475 476 477 478 479
		GroupId:    txGroupId,
		I:          i,
		Lock:       lock,
		Forbid:     forbid,
		MicForbid:  micForbid,
hujiebin's avatar
hujiebin committed
480
		ExternalId: micUserExternalId,
hujiebin's avatar
hujiebin committed
481
		AgoraId:    agoraId,
hujiebin's avatar
hujiebin committed
482
		Timestamp:  time.Now().UnixNano(),
hujiebin's avatar
hujiebin committed
483
		User:       micUserData,
hujiebin's avatar
hujiebin committed
484
	}
hujiebin's avatar
hujiebin committed
485
	n := 0
hujiebin's avatar
hujiebin committed
486 487
	if buffer, err := proto.Marshal(msg); err == nil {
		userIds := []uint64{userId}
hujiebin's avatar
hujiebin committed
488 489 490
		var rspUids []uint64
		for {
			n++
491
			rspUids, err = multicast(userIds, MsgTypeGroupMicChange, buffer, time.Duration(10))
hujiebin's avatar
hujiebin committed
492 493 494 495 496
			if n >= 3 || len(rspUids) <= 0 {
				break
			}
			time.Sleep(time.Millisecond * 200)
		}
hujiebin's avatar
hujiebin committed
497

hujiebin's avatar
hujiebin committed
498 499 500 501 502 503 504 505
		// 记录socket
		// 有err||uid不在线才入库
		if err != nil || len(rspUids) > 0 {
			go func(userId uint64, msg *userProxy.GroupMicChange, rspUids []uint64, err error) {
				buf, _ := json.Marshal(msg)
				AddRpcLog(MsgTypeGroupMicChange, userId, string(buf[:]), rspUids, err)
			}(userId, msg, rspUids, err)
		}
hujiebin's avatar
hujiebin committed
506 507

		if err != nil {
hujiebin's avatar
hujiebin committed
508
			mylogrus.MyLog.Errorf("grpc SendSocketMicChange send fail,seqId:%v,retry:%v,data:%v,err:%v", seqId, n, *msg, err)
hujiebin's avatar
hujiebin committed
509 510
			return err
		} else {
hujiebin's avatar
hujiebin committed
511
			mylogrus.MyLog.Infof("grpc SendSocketMicChange send success,seqId:%v,retry:%v,data:%v", seqId, n, *msg)
hujiebin's avatar
hujiebin committed
512 513 514 515 516 517
		}
	} else {
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
518 519

// 游戏大厅匹配成功
hujiebin's avatar
hujiebin committed
520
func SendLobbyMatchSuccess(myUserId, otherUserId uint64, nick1, nick2, avatar1, avatar2 string, gameId uint64, txGroupId string, mode int, gameCode string) error {
hujiebin's avatar
hujiebin committed
521 522 523 524 525 526
	msg := &userProxy.LobbyMatchSuccess{
		GameId:    gameId,
		GroupId:   txGroupId,
		Mode:      uint64(mode),
		User:      &userProxy.User{Id: myUserId, Nick: nick1, Avatar: avatar1},
		OtherUser: &userProxy.User{Id: otherUserId, Nick: nick2, Avatar: avatar2},
hujiebin's avatar
hujiebin committed
527
		GameCode:  gameCode,
hujiebin's avatar
hujiebin committed
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
	}
	if buffer, err := proto.Marshal(msg); err == nil {
		userIds := []uint64{myUserId}
		rspUids, err := multicast(userIds, MsgTypeLobbyMatchSuccess, buffer)

		//记录socket,注意闭包问题
		go func(userIds []uint64, msg *userProxy.LobbyMatchSuccess, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLogs(MsgTypeLobbyMatchSuccess, userIds, string(buf[:]), rspUids, err)
		}(userIds, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc LobbyMatchSuccess send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc LobbyMatchSuccess send success")
		}
	} else {
		return err
	}
	return nil
}
hujiebin's avatar
hujiebin committed
550 551 552 553 554 555 556 557 558 559

// h5游戏静音
func SendH5GameMute(userId uint64) error {
	msg := &userProxy.H5GameVoiceMute{}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := multicast([]uint64{userId}, MsgTypeH5GameMute, buffer)

		//记录socket,注意闭包问题
		go func(userId uint64, msg *userProxy.H5GameVoiceMute, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
hujiebin's avatar
hujiebin committed
560
			AddRpcLog(MsgTypeH5GameMute, userId, string(buf[:]), rspUids, err)
hujiebin's avatar
hujiebin committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
		}(userId, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendH5GameMute send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendH5GameMute send success")
		}
	} else {
		return err
	}
	return nil
}

// h5游戏开音
func SendH5GameUnMute(userId uint64) error {
	msg := &userProxy.H5GameVoiceUnMute{}
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := multicast([]uint64{userId}, MsgTypeH5GameUnMute, buffer)

		//记录socket,注意闭包问题
		go func(userId uint64, msg *userProxy.H5GameVoiceUnMute, rspUids []uint64, err error) {
			buf, _ := json.Marshal(msg)
			AddRpcLog(MsgTypeH5GameUnMute, userId, string(buf[:]), rspUids, err)
		}(userId, msg, rspUids, err)

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendH5GameUnMute send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendH5GameUnMute send success")
		}
	} else {
		return err
	}
	return nil
}
chenweijian's avatar
chenweijian committed
598

chenweijian's avatar
chenweijian committed
599
// 发送退房通知 原因1.被拉黑;2.被踢出
chenweijian's avatar
chenweijian committed
600 601
func SendQuitRoom(userId uint64, reason uint32, txGroupId string) error {
	msg := &userProxy.QuitRoom{Reason: reason, GroupId: txGroupId}
chenweijian's avatar
chenweijian committed
602 603 604 605 606
	if buffer, err := proto.Marshal(msg); err == nil {
		rspUids, err := multicast([]uint64{userId}, MsgTypeQuitRoom, buffer)
		// 记录socket
		// 有err||uid不在线才入库
		if err != nil || len(rspUids) > 0 {
chenweijian's avatar
chenweijian committed
607
			go func(userId uint64, msg *userProxy.QuitRoom, rspUids []uint64, err error) {
chenweijian's avatar
chenweijian committed
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
				buf, _ := json.Marshal(msg)
				AddRpcLog(MsgTypeQuitRoom, userId, string(buf[:]), rspUids, err)
			}(userId, msg, rspUids, err)
		}

		if err != nil {
			mylogrus.MyLog.Errorf("grpc SendQuitRoom send fail")
			return err
		} else {
			mylogrus.MyLog.Info("grpc SendQuitRoom send success")
		}
	} else {
		return err
	}
	return nil
}