using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using ProtoCSStruct; namespace Account { public static class BindGuestFacebookSvc { public static void OnBindGuestFacebookReq(uint remoteAppID, StructPacket packet) { ref CSBindGuestFacebookReq req = ref packet.GetMessage(); AccountInfoOnAccountServer accountInfo = AccountServerUtils.GetAccountTableOp().GetAccountInfo( 0, req.GuestAccountID.GetString()); if(accountInfo == null) { TraceLog.Error("OnBindGuestFacebookReq accountInfo is null, uid {0} guestAccountID {1} ", req.Uid, req.GuestAccountID); return; } //去http验证 SSBindGuestFacebookHttpCheckReq httpCheckReq = new SSBindGuestFacebookHttpCheckReq(); httpCheckReq.GuestAccountID = req.GuestAccountID; httpCheckReq.AccountInfo = req.Account; uint httpproxyID = HttpProxySelect.GetHttpProxyID(accountInfo.AccountType, accountInfo.AccountID); //发给httpProxy服务器进行第三方验证等操作 AccountServerUtils.GetPacketSender().SendToServerByID(httpproxyID ,(int)SSMsgID.BindGuestFacebookHttpCheckReq, ref httpCheckReq, packet.ObjectID); } public static void OnBindGuestFacebookHttpCheckRes(uint remoteAppID, StructPacket packet) { ref SSBindGuestFacebookHttpCheckRes res = ref packet.GetMessage(); TraceLog.Debug("OnBindGuestFacebookHttpCheckRes begin ret {0} guestAccountID {1}", res.Ret, res.GuestAccountID); AccountInfoOnAccountServer accountInfo = AccountServerUtils.GetAccountTableOp().GetAccountInfo( 0, res.GuestAccountID.GetString()); if (accountInfo == null) { TraceLog.Error("OnBindGuestFacebookHttpCheckRes accountInfo is null, guestAccountID {0} ", res.GuestAccountID); return; } //校验失败了 if(res.Ret != 0) { TraceLog.Debug("OnBindGuestFacebookHttpCheckRes check failed ret {0} guestAccountID {1}, ack to WorldServerID {2}" , res.Ret, res.GuestAccountID, ServerIDUtils.IDToString(accountInfo.WorldServerID)); CSBindGuestFacebookRes csRes = new CSBindGuestFacebookRes(); csRes.Ret = 2001; AccountServerUtils.GetPacketSender().SendToServerByID(accountInfo.WorldServerID, (int)CSMsgID.BindGuestFacebookRes, ref csRes,0/*, accountInfo.GameID*/); return; } TraceLog.Debug("OnBindGuestFacebookHttpCheckRes check success guestAccountID {0}, send bind req to db" ,res.GuestAccountID); //校验成功了,去db操作绑定,将新的facebook帐号和uid写入数据库 SSBindGuestFacebookDbReq dbReq = new SSBindGuestFacebookDbReq(); dbReq.AccountInfo = res.AccountInfo; dbReq.Gender = res.Gender; dbReq.Icon = res.Icon; dbReq.Nick = res.Nick; dbReq.Email = res.Email; //dbReq.Uid = accountInfo.GameID; dbReq.GuestAccountID = res.GuestAccountID; uint iDBServerID = DBServerSelect.GetDBServerID(res.AccountInfo.AccountType, res.AccountInfo.AccountID.GetString()); AccountServerUtils.GetPacketSender().SendToServerByID(iDBServerID, (int)SSMsgID.BindGuestFacebookDbReq, ref dbReq, packet.ObjectID); } public static void OnBindGuestFacebookDbRes(uint remoteAppID, StructPacket packet) { ref SSBindGuestFacebookDbRes dbRes = ref packet.GetMessage(); TraceLog.Debug("OnBindGuestFacebookDbRes begin ret {0} guestAccountID {1}", dbRes.Ret, dbRes.GuestAccountID); AccountInfoOnAccountServer accountInfo = AccountServerUtils.GetAccountTableOp().GetAccountInfo( 0, dbRes.GuestAccountID.GetString()); if (accountInfo == null) { TraceLog.Error("OnBindGuestFacebookDbRes accountInfo is null, guestAccountID {0} ", dbRes.GuestAccountID); return; } CSBindGuestFacebookRes csRes = new CSBindGuestFacebookRes(); //校验失败了 if (dbRes.Ret != 0) { TraceLog.Debug("OnBindGuestFacebookDbRes check failed ret {0} guestAccountID {1}, ack to WorldServerID {2}" , dbRes.Ret, dbRes.GuestAccountID, ServerIDUtils.IDToString(accountInfo.WorldServerID)); csRes.Ret = dbRes.Ret; AccountServerUtils.GetPacketSender().SendToServerByID(accountInfo.WorldServerID, (int)CSMsgID.BindGuestFacebookRes, ref csRes, 0/*accountInfo.GameID*/); return; } //成功,插入帐号表, 旧帐号还是保留,2个帐号对应了同一个uid,都可以登录 TraceLog.Debug("OnBindGuestFacebookDbRes db bind success, uid {0} create new accountInfo type {1} id {2}" , dbRes.Uid, dbRes.AccountInfo.AccountType, dbRes.AccountInfo.AccountID); PlayerSession playerSession = AccountServerUtils.GetPlayerTableOp().GetPlayerSession(packet.ObjectID); if (playerSession == null || string.IsNullOrEmpty(playerSession.taDistinctID))//访客id为空,就accountkey吧 { accountInfo.TaDistinctID = AccountUtils.CalcAccountKey(dbRes.AccountInfo.AccountType, dbRes.AccountInfo.AccountID.GetString()); } else { accountInfo.TaDistinctID = playerSession.taDistinctID; } AccountInfoOnAccountServer newAccountInfo = AccountServerUtils.GetAccountTableOp().CreateAccountInfo( dbRes.AccountInfo.AccountType, dbRes.AccountInfo.AccountID.GetString()); newAccountInfo.Gender = dbRes.Gender; newAccountInfo.AccountToken = dbRes.AccountInfo.AccountToken.GetString(); newAccountInfo.Icon = dbRes.Icon.GetString(); newAccountInfo.Nick = dbRes.Nick.GetString(); newAccountInfo.PlatformType = dbRes.AccountInfo.PlatformType; newAccountInfo.WorldServerID = accountInfo.WorldServerID; //newAccountInfo.GameID = dbRes.Uid; newAccountInfo.Email = dbRes.Email.GetString(); newAccountInfo.IsOnline = true; csRes.Ret = 0; csRes.AccountType = dbRes.AccountInfo.AccountType; csRes.FacebookAccountID = dbRes.AccountInfo.AccountID; csRes.Email = dbRes.Email; csRes.Nick = dbRes.Nick; AccountServerUtils.GetPacketSender().SendToServerByID(accountInfo.WorldServerID, (int)CSMsgID.BindGuestFacebookRes, ref csRes, 0/*accountInfo.GameID*/); } public static void OnUnbindGuestFacebookReq(uint remoteAppID, StructPacket packet) { ref CSUnBindGuestFacebookReq req = ref packet.GetMessage(); AccountInfoOnAccountServer accountInfo = AccountServerUtils.GetAccountTableOp().GetAccountInfo( 0, req.GuestAccountID.GetString()); if (accountInfo == null) { TraceLog.Error("OnUnbindGuestFacebookReq accountInfo is null, uid {0} guestAccountID {1} ", req.Uid, req.GuestAccountID); return; } //去db操作解绑,将新的facebook帐号和uid写入数据库 SSUnbindGuestFacebookDbReq dbReq = new SSUnbindGuestFacebookDbReq(); dbReq.AccountInfo = req.Account; //dbReq.Uid = accountInfo.GameID; dbReq.GuestAccountID = req.GuestAccountID; uint iDBServerID = DBServerSelect.GetDBServerID(req.Account.AccountType, req.Account.AccountID.GetString()); AccountServerUtils.GetPacketSender().SendToServerByID(iDBServerID, (int)SSMsgID.UnbindGuestFacebookDbReq, ref dbReq, packet.ObjectID); } public static void OnUnbindGuestFacebookDbRes(uint remoteAppID, StructPacket packet) { ref SSUnbindGuestFacebookDbRes dbRes = ref packet.GetMessage(); TraceLog.Debug("OnUnbindGuestFacebookDbRes begin ret {0} guestAccountID {1}", dbRes.Ret, dbRes.GuestAccountID); AccountInfoOnAccountServer accountInfo = AccountServerUtils.GetAccountTableOp().GetAccountInfo( 0, dbRes.GuestAccountID.GetString()); if (accountInfo == null) { TraceLog.Error("OnUnbindGuestFacebookDbRes accountInfo is null, guestAccountID {0} ", dbRes.GuestAccountID); return; } CSUnBindGuestFacebookRes csRes = new CSUnBindGuestFacebookRes(); //校验失败了 if (dbRes.Ret != 0) { TraceLog.Debug("OnUnbindGuestFacebookDbRes check failed ret {0} guestAccountID {1}, ack to WorldServerID {2}" , dbRes.Ret, dbRes.GuestAccountID, ServerIDUtils.IDToString(accountInfo.WorldServerID)); csRes.Ret = dbRes.Ret; AccountServerUtils.GetPacketSender().SendToServerByID(accountInfo.WorldServerID, (int)CSMsgID.UnbindGuestFacebookRes, ref csRes,0 /*accountInfo.GameID*/); return; } //成功,删除老的帐号 TraceLog.Debug("OnUnbindGuestFacebookDbRes db bind success, uid {0} accountInfo type {1} id {2}" , dbRes.Uid, dbRes.AccountInfo.AccountType, dbRes.AccountInfo.AccountID); AccountServerUtils.GetAccountTableOp().RemoveAccountInfo( dbRes.AccountInfo.AccountType, dbRes.AccountInfo.AccountID.GetString()); //通知httpserver SSUnbindGuestFacebookNotifyHttp notify = new SSUnbindGuestFacebookNotifyHttp(); notify.AccountInfo = dbRes.AccountInfo; uint httpproxyID = HttpProxySelect.GetHttpProxyID(accountInfo.AccountType, accountInfo.AccountID); AccountServerUtils.GetPacketSender().SendToServerByID(httpproxyID,(int)SSMsgID.UnbindGuestFacebookNotifyHttp, ref notify, 0); csRes.Ret = 0; csRes.AccountType = dbRes.AccountInfo.AccountType; csRes.FacebookAccountID = dbRes.AccountInfo.AccountID; AccountServerUtils.GetPacketSender().SendToServerByID(accountInfo.WorldServerID, (int)CSMsgID.UnbindGuestFacebookRes, ref csRes, 0/*accountInfo.GameID*/); } } }