handler_service_reply.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. pb2 "call_center/db/rpc/pb"
  9. "call_center/public/exception"
  10. "fmt"
  11. )
  12. func ServiceReply(server *core.Server, serverId string, msg *pb.CommandMsg, interDb interaction.InterDb) error {
  13. var err error
  14. exception.Try(func() {
  15. toPlayerId := msg.CmdStr
  16. player := server.GetPlayer(toPlayerId)
  17. if player == nil {
  18. // 玩家不存在
  19. exception.Throw(fmt.Sprintf("<serviceReplyHandler> player not exist, id:%v", toPlayerId))
  20. }
  21. res := server.OnPlayerQuitWaitQueue(server, player)
  22. if res == nil {
  23. // 玩家不在等待队列中
  24. exception.Throw(fmt.Sprintf("<serviceReplyHandler> player not in wait queue, id:%v", toPlayerId))
  25. }
  26. // 建立连接
  27. err := server.OnConfirmConn(server, serverId, toPlayerId)
  28. if err != nil {
  29. exception.Throw(err)
  30. }
  31. // 记录日志
  32. interDb.ChatRecordToDb(player, serverId, toPlayerId, pb2.EDbRecordState_E_DB_RECORD_STATE_REPLY)
  33. }).Catch(func(e exception.Exception) {
  34. err = e.(error)
  35. }).Finally(func() {
  36. })
  37. return err
  38. }