handler_from_service_msg.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //@Author : KaiShin
  2. //@Time : 2021/11/2
  3. package handler
  4. import (
  5. "call_center/call/rpc/internal/core"
  6. "call_center/call/rpc/internal/interaction"
  7. "call_center/call/rpc/pb"
  8. "call_center/public/exception"
  9. "fmt"
  10. "log"
  11. )
  12. func FromServiceMsg(server *core.Server, streamId string, msg *pb.CommandMsg, interDb interaction.InterDb) error {
  13. // 客服连接请求
  14. chatMsg := msg.GetChatMsg()
  15. clientId := chatMsg.ClientId
  16. player := server.GetPlayer(clientId)
  17. // log.Println("Recv, 客服回复玩家<", clientId, ">:", chatMsg.Input)
  18. var err error = nil
  19. exception.Try(func() {
  20. if player == nil {
  21. // 玩家不存在
  22. errStr := fmt.Sprintf("<serviceMsgHandler> 玩家id{%v}不存在", clientId)
  23. exception.Throw(errStr)
  24. }
  25. // 客服回复玩家
  26. err = server.MsgToClient(player.Stream, chatMsg.Input, streamId)
  27. if err != nil {
  28. log.Println("<serviceMsgHandler> err:", err)
  29. exception.Throw(err)
  30. }
  31. // 推送日志
  32. interDb.ChatLogToDb(player, clientId, streamId, chatMsg.Input, false)
  33. //// 发送成功确认信息
  34. //err = server.MsgToService(serviceStream, "success")
  35. //if err != nil {
  36. // exception.Throw(err)
  37. //}
  38. }).Catch(func(e exception.Exception) {
  39. log.Println("<serviceMsgHandler> err:", e)
  40. err = e.(error)
  41. }).Finally(func() {
  42. })
  43. return err
  44. }