package model import ( "rocommon" "rocommon/util" model2 "roserver/baseserver/model" "roserver/serverproto" ) func init() { serverproto.Handle_GATE_SSUserKickNtf = func(ev rocommon.ProcEvent) { msg := ev.Msg().(*serverproto.SSUserKickNtf) cliSess := model2.GetClientSession(msg.ClientId) if cliSess == nil { return } if msg.Error == int32(serverproto.ErrorCode_ERROR_OK) || msg.Error == int32(serverproto.ErrorCode_ERROR_FAIL) { cliSess.(rocommon.ContextSet).SetContextData("user", nil, "SSUserKickNtf") //cliSess.Close() } else { //发送踢人消息给客户端,客户端关闭连接 ntfMsg := &serverproto.SCKickOutNtf{ Error: msg.Error, BanEndTime: msg.BanEndTime, } cliSess.Send(ntfMsg) cliSess.(rocommon.ContextSet).SetContextData("user", nil, "SSUserKickNtf") //cliSess.Close() } } //登录成功时,返回给gate服务器,用来处理连接超时设置 serverproto.Handle_GATE_SCLoginAck = func(ev rocommon.ProcEvent) { msg := ev.Msg().(*serverproto.SCLoginAck) cliSess := model2.GetClientSession(msg.ClientId) if cliSess == nil { return } msg.ClientId = 0 if msg.Error != int32(serverproto.ErrorCode_ERROR_OK) { cliUser := model2.Session2User(cliSess) cliUser.RemoveConnected() } cliSess.SetSessionOptFlag(true) //cliSess.Send(msg) } //auth验证成功通知gate,并绑定game服务器节点SSUserKickNtf serverproto.Handle_GATE_SSLoginNtf = func(ev rocommon.ProcEvent) { msg := ev.Msg().(*serverproto.SSLoginNtf) //util.DebugF("SSLoginNtf from auth msg=%v", msg) cliSess := model2.GetClientSession(msg.ClientId) if cliSess == nil { return } msgId := LoginReqMsgId cliUser, ret := model2.BindClientToBackend(msg.ConnInfo.LogicNode, cliSess) util.DebugF("SSLoginNtf from auth msg openid=%v msg=%v", cliUser.OpenId, msg) if ret { err := cliUser.ClientDirect2Backend(msg.ConnInfo.LogicNode, msgId, 0, cliUser.LoginData, model2.SERVICE_NODE_TYPE_GAME_STR) if err != nil { util.WarnF("SSLoginNtf bind game node err=%v", err) } //登陆成功发送保存连接信息到auth saveMsg := &serverproto.SSSaveUserConnectInfo{ OpenId: cliUser.OpenId, Platform: cliUser.Platform, ConnInfo: msg.ConnInfo, } saveMsg.ConnInfo.TimeStamp = util.GetTimeSeconds() err = cliUser.Client2Backend(model2.SERVICE_NODE_TYPE_AUTH_STR, saveMsg) if err != nil { util.ErrorF("[SSLoginNtf] send to auth err=%v", err) } } else { //重新选择game节点 gameNodeStr, _ := model2.GetServiceNodeAndSession("", model2.SERVICE_NODE_TYPE_GAME_STR, msg.ClientId>>32) //gameNodeStr := model2.SelectServiceNode(model2.SERVICE_NODE_TYPE_GAME_STR, msg.ClientId>>32) util.WarnF("[SSLoginNtf] bind game node id=%v sid=%v nodeStr=%v", ev.Session().ID(), msg.ClientId>>32, gameNodeStr) cliUser, ret = model2.BindClientToBackend(gameNodeStr, cliSess) if ret { err := cliUser.ClientDirect2Backend(gameNodeStr, msgId, 0, cliUser.LoginData, model2.SERVICE_NODE_TYPE_GAME_STR) if err != nil { util.WarnF("[SSLoginNtf] bind game node err=%v", err) } } else { util.ErrorF("[SSLoginNtf] no game node can use !!!") ackMsg := &serverproto.SCLoginAck{Error: int32(serverproto.ErrorCode_ERROR_SERVER_ERROR)} cliSess.Send(ackMsg) cliSess.(rocommon.ContextSet).SetContextData("user", nil, "SSLoginNtf:Failed") cliSess.Close() return } //登陆成功发送保存连接信息到auth saveMsg := &serverproto.SSSaveUserConnectInfo{ OpenId: cliUser.OpenId, Platform: cliUser.Platform, ConnInfo: msg.ConnInfo, } saveMsg.ConnInfo.TimeStamp = util.GetTimeSeconds() saveMsg.ConnInfo.LogicNode = gameNodeStr err := cliUser.Client2Backend(model2.SERVICE_NODE_TYPE_AUTH_STR, saveMsg) if err != nil { util.ErrorF("[SSLoginNtf] send to auth err=%v", err) } } //绑定battlerecord服务器节点 battleRecordNodeStr := model2.SelectServiceNode(model2.SERVICE_NODE_TYPE_BATTLERECORD_STR, msg.ClientId>>32) if battleRecordNodeStr != "" { model2.BindClientToBackend(battleRecordNodeStr, cliSess) } } }