private ErrorCode UserAskReconnectGame(CSGSInfo csgsInfo, uint gcNetID, string name, string passwd) { UserNetInfo netinfo = new UserNetInfo(csgsInfo.m_n32GSID, gcNetID); if (this.ContainsUser(netinfo)) { return(ErrorCode.InvalidNetState); } //需要从消息获取 const int sdkID = 0; UserCombineKey sUserCombineKey = new UserCombineKey(name, sdkID); if (!this.allUserName2GuidMap.TryGetValue(sUserCombineKey, out ulong guid)) { return(ErrorCode.NullUser); } CSUser pcUser = this.GetUser(guid); if (null == pcUser) { return(ErrorCode.NullUser); } GCToCS.Login login = new GCToCS.Login(); pcUser.OnOnline(netinfo, login, false, false, true); return(ErrorCode.Success); }
protected override void OnRealEstablish() { CSGSInfo csgsInfo = CS.instance.GetGSInfoByNSID(this.id); if (csgsInfo != null) { Logger.Info($"GS({csgsInfo.m_n32GSID}) Connected"); } }
private ErrorCode OnMsgFromGSReportGCMsg(byte[] data, int offset, int size, int transID, int msgID, uint gcNetID) { GSToCS.ReportGCMsg reportGCMsg = new GSToCS.ReportGCMsg(); reportGCMsg.MergeFrom(data, offset, size); CSGSInfo csgsInfo = CS.instance.GetGSInfoByNSID(this.id); return(CS.instance.InvokeGCMsg(csgsInfo, msgID, gcNetID, data, offset, size)); }
public ErrorCode PostMsgToGCAskReturn(CSGSInfo csgsInfo, uint gcNetID, int askProtocalID, ErrorCode errorCode) { GSToGC.AskRet msg = new GSToGC.AskRet { Askid = askProtocalID, Errorcode = ( int )errorCode }; return(CS.instance.PostMsgToGS(csgsInfo, msg, ( int )GSToGC.MsgID.EMsgToGcfromGsGcaskRet, gcNetID)); }
private ErrorCode OnMsgToGstoCsfromGcAskChangeheaderId(CSGSInfo csgsInfo, uint gcNetID, byte[] data, int offset, int size) { CSUser pcUser = this.CheckAndGetUserByNetInfo(csgsInfo, gcNetID); GCToCS.AskChangeheaderId pMsg = new GCToCS.AskChangeheaderId(); pMsg.MergeFrom(data, offset, size); pcUser.AskChangeHeaderId(pMsg.Newheaderid); return(ErrorCode.Success); }
public ErrorCode Invoke(CSGSInfo csgsInfo, int msgID, uint gcNetID, byte[] data, int offset, int size) { if (this.gcMsgHandlers.TryGetValue(msgID, out GCMsgHandler handler)) { return(handler.Invoke(csgsInfo, gcNetID, data, offset, size)); } Logger.Warn($"invalid msg:{msgID}."); return(ErrorCode.InvalidMsgProtocalID); }
public CSUser CheckAndGetUserByNetInfo(CSGSInfo csgsInfo, uint gcNetID) { CSUser user = this.GetUser(csgsInfo, gcNetID); if (null == user) { Logger.Error($"could not find gcNetID:{gcNetID}"); return(null); } user.ResetPingTimer(); return(user); }
private ErrorCode PostMsgToGC(IMessage msg, int msgID) { CSGSInfo csgsInfo = CS.instance.GetGSInfoByGSID(( uint )this.userNetInfo.gsID); if (null == csgsInfo) { Logger.Warn($"GS({this.userNetInfo.gsID}) not found."); return(ErrorCode.NullGateServer); } CS.instance.PostMsgToGS(csgsInfo, msg, msgID, this.userNetInfo.gcNetID); return(ErrorCode.Success); }
private ErrorCode OnMsgToGstoCsfromGcAskReconnectGame(CSGSInfo csgsInfo, uint gcNetID, byte[] data, int offset, int size) { GCToCS.ReconnectToGame pReconnectToGame = new GCToCS.ReconnectToGame(); pReconnectToGame.MergeFrom(data, offset, size); ErrorCode errorCode = this.UserAskReconnectGame(csgsInfo, gcNetID, pReconnectToGame.Name, pReconnectToGame.Passwd); if (ErrorCode.Success != errorCode) { this.PostMsgToGCAskReturn(csgsInfo, gcNetID, ( int )GCToCS.MsgNum.EMsgToGstoCsfromGcAskReconnectGame, errorCode); } return(errorCode); }
private ErrorCode OnMsgToGstoCsfromGcAskLogin(CSGSInfo csgsInfo, uint gcNetID, byte[] data, int offset, int size) { GCToCS.Login login = new GCToCS.Login(); login.MergeFrom(data, offset, size); Logger.Log($"--new login({login.Name})--"); ErrorCode errorCode = this.UserAskLogin(csgsInfo, gcNetID, login); if (ErrorCode.Success != errorCode) { this.PostMsgToGCAskReturn(csgsInfo, gcNetID, ( int )GCToCS.MsgNum.EMsgToGstoCsfromGcAskLogin, errorCode); } return(ErrorCode.Success); }
private ErrorCode MsgHandleInit(byte[] data, int offset, int size, int transID, int msgID, uint gcNetID) { GSToCS.AskRegiste msg = new GSToCS.AskRegiste(); msg.MergeFrom(data, offset, size); //找到位置号 int gsPos = -1; CSGSInfo csgsInfo = null; for (int i = 0; i < CS.instance.csKernelCfg.un32MaxGSNum; i++) { if (msg.Gsid != CS.instance.csKernelCfg.gsInfoList[i].m_n32GSID) { continue; } csgsInfo = CS.instance.csKernelCfg.gsInfoList[i]; gsPos = i; break; } if (null == csgsInfo) { this.Close(); return(ErrorCode.InvalidGSID); } if (csgsInfo.m_szUserPwd != msg.Usepwd) { this.Close(); return(ErrorCode.InvalidUserPwd); } // 加入GS long time = TimeUtils.utcTime; csgsInfo.m_eGSNetState = ServerNetState.Free; csgsInfo.m_n32NSID = this.id; this.logicID = csgsInfo.m_n32GSID; csgsInfo.m_tLastConnMilsec = time; csgsInfo.m_sListenIP = msg.Ip; csgsInfo.m_n32ListenPort = msg.Port; CS.instance.gsNetInfoList[gsPos].pcGSInfo = csgsInfo; csgsInfo.m_n64MsgReceived++; csgsInfo.m_n64DataReceived += msg.CalculateSize(); csgsInfo.m_un32ConnTimes++; csgsInfo.m_tLastConnMilsec = time; csgsInfo.m_tLastPingMilSec = time; this.SetInited(true, true); return(ErrorCode.Success); }
private ErrorCode OnMsgToGstoCsfromGcAskChangeNickName(CSGSInfo csgsInfo, uint gcNetID, byte[] data, int offset, int size) { CSUser user = this.CheckAndGetUserByNetInfo(csgsInfo, gcNetID); GCToCS.ChangeNickName pMsg = new GCToCS.ChangeNickName(); pMsg.MergeFrom(data, offset, size); ErrorCode errorCode = ErrorCode.Success; do { if (pMsg.Newnickname.Length < 3) { errorCode = ErrorCode.NickNameTooShort; } if (this.allNickNameSet.Contains(pMsg.Newnickname)) { errorCode = ErrorCode.NickNameCollision; break; } if (!user.CheckIfEnoughPay(PayType.Diamond, 20)) { errorCode = ErrorCode.DiamondNotEnough; break; } } while (false); if (errorCode != ErrorCode.Success) { return(user.PostMsgToGCAskRetMsg(( int )GCToCS.MsgNum.EMsgToGstoCsfromGcAskChangeNickName, errorCode)); } user.userDbData.ChangeUserDbData(UserDBDataType.Diamond, ( long )-20); user.PostMsgToGCNotifyNewNickname(user.guid, pMsg.Newnickname); this.ChangeUserNickName(user, pMsg.Newnickname); foreach (KeyValuePair <ulong, UserRelationshipInfo> kv in user.userDbData.friendListMap) { CSUser piUser = this.GetUser(kv.Value.guididx); if (null != piUser && piUser.userPlayingStatus == UserPlayingStatus.Playing) { piUser.SynUserSNSList(user.guid, RelationShip.Friends); } } user.SynCurDiamond(); //todo //CSSGameLogMgr::GetInstance().AddGameLog( eLog_ChangeUseName, user.GetGUID(), user.GetUserDBData().sPODUsrDBData.un8UserLv, user.GetUserDBData().sPODUsrDBData.un16VipLv ); return(ErrorCode.Success); }
private ErrorCode KickOutOldUser() { if (!this.userNetInfo.IsValid()) { return(ErrorCode.Success); } this.PostMsgToGC_NetClash(); CSGSInfo piGSInfo = CS.instance.GetGSInfoByGSID(( uint )this.userNetInfo.gsID); if (null != piGSInfo) { CS.instance.PostMsgToGS_KickoutGC(piGSInfo, this.userNetInfo.gcNetID); } this.OnOffline(); return(ErrorCode.Success); }
protected override void OnClose() { CSGSInfo csgsInfo = CS.instance.GetGSInfoByNSID(this.id); if (csgsInfo == null) { return; } Logger.Info($"GS({csgsInfo.m_n32GSID}) DisConnected"); int pos = ( int )(csgsInfo.m_n32GSID - CS.instance.csKernelCfg.un32GSBaseIdx); csgsInfo.m_eGSNetState = ServerNetState.Closed; csgsInfo.m_n32NSID = 0; csgsInfo.m_tLastConnMilsec = 0; CS.instance.gsNetInfoList[pos].tConnMilsec = 0; CS.instance.gsNetInfoList[pos].pcGSInfo = null; }
private ErrorCode OnMsgToCsfromGsUserOffLine(byte[] data, int offset, int size, int transID, int msgID, uint gcNetID) { GSToCS.UserOffLine sMsp = new GSToCS.UserOffLine(); sMsp.MergeFrom(data, offset, size); CSGSInfo csgsInfo = CS.instance.GetGSInfoByNSID(this.id); CSUser pUser = CS.instance.userMgr.GetUser(csgsInfo, ( uint )sMsp.Usernetid); if (null != pUser) { //todo //if ( pUser.GetUserBattleInfoEx().GetBattleState() == eBattleState_Free ) CS.instance.userMgr.RemoveUser(pUser); pUser.OnOffline(); } return(ErrorCode.Success); }
private ErrorCode OnMsgFromGSAskPing(byte[] data, int offset, int size, int transID, int msgID, uint gcNetIDID) { GSToCS.Asking askPing = new GSToCS.Asking(); askPing.MergeFrom(data, offset, size); CSToGS.AskPing msg = new CSToGS.AskPing { Time = askPing.Time }; CSGSInfo csgsInfo = CS.instance.GetGSInfoByNSID(this.id); if (csgsInfo == null) { return(ErrorCode.GSNotFound); } this.owner.TranMsgToSession(csgsInfo.m_n32NSID, msg, ( int )CSToGS.MsgID.EMsgToGsfromCsAskPingRet, 0, 0); return(ErrorCode.Success); }
private ErrorCode OnMsgToGstoCsfromGcAskComleteUserInfo(CSGSInfo csgsInfo, uint gcNetID, byte[] data, int offset, int size) { CSUser csUser = this.GetUser(csgsInfo, gcNetID); if (null == csUser) { Logger.Error($"could not find user({csgsInfo.m_n32NSID})"); return(ErrorCode.NullUser); } csUser.ResetPingTimer(); ErrorCode errorCode = ErrorCode.Success; do { GCToCS.CompleteInfo completeInfo = new GCToCS.CompleteInfo(); completeInfo.MergeFrom(data, offset, size); if (string.IsNullOrEmpty(completeInfo.Nickname)) { errorCode = ErrorCode.NickNameNotAllowed; break; } //长度是否合法 if (completeInfo.Nickname.Length > Consts.DEFAULT_NICK_NAME_LEN) { errorCode = ErrorCode.NickNameNotAllowed; break; } //昵称是否合法 if (CS.instance.csCfg.CheckInvalidWorld(completeInfo.Nickname)) { errorCode = ErrorCode.NickNameNotAllowed; break; } //是否和ai昵称冲突 if (CS.instance.csCfg.CheckAIRobotName(completeInfo.Nickname)) { errorCode = ErrorCode.NickNameCollision; break; } //是否存在相同昵称 if (this.allNickNameSet.Contains(completeInfo.Nickname)) { errorCode = ErrorCode.NickNameCollision; break; } csUser.userDbData.ChangeUserDbData(UserDBDataType.Sex, completeInfo.Sex); csUser.userDbData.ChangeUserDbData(UserDBDataType.HeaderId, completeInfo.Headid); this.ChangeUserNickName(csUser, completeInfo.Nickname); csUser.SynUser_UserBaseInfo(); csUser.PostCSNotice(); //todo //DBPosterUpdateUser( csUser );//存盘// string log = $"{csUser.userDbData.szUserName}{LOG_SIGN}{completeInfo.Headid}{completeInfo.Nickname}"; //todo //CSSGameLogMgr::GetInstance().AddGameLog( eLog_HeadUse, mystream.str(), 0 ); } while (false); if (ErrorCode.Success != errorCode) { this.PostMsgToGCAskReturn(csgsInfo, gcNetID, ( int )GCToCS.MsgNum.EMsgToGstoCsfromGcAskComleteUserInfo, errorCode); } return(errorCode); }
private ErrorCode UserAskLogin(CSGSInfo csgsInfo, uint gcNetID, GCToCS.Login login) { if (string.IsNullOrEmpty(login.Name) || login.Name.Length > Consts.DEFAULT_NAME_LEN) { return(ErrorCode.InvalidUserName); } UserNetInfo netinfo = new UserNetInfo(csgsInfo.m_n32GSID, gcNetID); if (this.ContainsUser(netinfo)) { return(ErrorCode.InvalidNetState); } ErrorCode errorCode = ErrorCode.Success; UserCombineKey sUserCombineKey = new UserCombineKey(login.Name, login.Sdk); if (this.allUserName2GuidMap.TryGetValue(sUserCombineKey, out ulong guid)) { //老玩家 //如果还在内存里 CSUser user = this.GetUser(guid); if (null != user) { bool bFlag = this.CheckIfInGuideBattle(user); if (bFlag) { Logger.Warn("新手引导玩家不允许顶号"); return(ErrorCode.GuideUserForbit); } user.OnOnline(netinfo, login, false, false); return(ErrorCode.Success); } //异步查询玩家数据 CSToDB.QueryUserReq queryUser = new CSToDB.QueryUserReq { Logininfo = login.ToByteString().ToStringUtf8(), Gsid = csgsInfo.m_n32GSID, Gcnetid = ( int )gcNetID, Csid = ( int )CS.instance.csKernelCfg.unCSId, Objid = ( long )guid }; errorCode = this.QueryUserAsync(queryUser).Result; } else { //新玩家,产生GUID guid = this.CombineGUID(); CSUser pcUser = new CSUser(); UserDBData userDbData = new UserDBData(); userDbData.usrDBData.un64ObjIdx = guid; userDbData.szUserName = login.Name; userDbData.szUserPwd = login.Passwd; userDbData.usrDBData.userPlatform = ( UserPlatform )login.Sdk; userDbData.usrDBData.tRegisteUTCMillisec = TimeUtils.utcTime; //加入全局表 this.allUserName2GuidMap.Add(sUserCombineKey, guid); pcUser.LoadDBData(userDbData); //todo //pcUser.userBattleInfoEx.mDebugName = login.Name; ErrorCode nRet = this.AddUser(pcUser); if (nRet != 0) { return(nRet); } pcUser.OnOnline(netinfo, login, true, true); this.InsertNewUserToMysql(login, pcUser); } //todo //log //{ // string mystream = string.Empty; // mystream << login.name() << LOG_SIGN; // mystream << login.sdk() << LOG_SIGN; // mystream << login.platform() << LOG_SIGN; // mystream << login.equimentid() << LOG_SIGN; // mystream << login.ipaddress(); // CSSGameLogMgr::GetInstance().AddGameLog( eLog_Login, guid, mystream.str() ); //} return(errorCode); }
private ErrorCode OnMsgFromGSAskRegiste(CSGSInfo csgsInfo, byte[] data, int offset, int size) { GSToCS.AskRegiste sMsg = new GSToCS.AskRegiste(); sMsg.MergeFrom(data, offset, size); // 找到位置号 int gsPos = -1; CSGSInfo pcGSInfo = null; for (int i = 0; i < CS.instance.csKernelCfg.un32MaxGSNum; i++) { if (sMsg.Gsid != CS.instance.csKernelCfg.gsInfoList[i].m_n32GSID) { continue; } pcGSInfo = CS.instance.csKernelCfg.gsInfoList[i]; gsPos = i; break; } ErrorCode n32Registe = ErrorCode.Success; if (null == pcGSInfo) { n32Registe = ErrorCode.InvalidGSID; } if (ErrorCode.Success == n32Registe) { if (pcGSInfo.m_szUserPwd != sMsg.Usepwd) { n32Registe = ErrorCode.InvalidUserPwd; } } long tCurUTCMilsec = TimeUtils.utcTime; if (ErrorCode.Success == n32Registe) { pcGSInfo.m_eGSNetState = ServerNetState.Free; pcGSInfo.m_n32NSID = csgsInfo.m_n32NSID; pcGSInfo.m_tLastConnMilsec = tCurUTCMilsec; pcGSInfo.m_sListenIP = sMsg.Ip; pcGSInfo.m_n32ListenPort = sMsg.Port; CS.instance.gsNetInfoList[gsPos].pcGSInfo = pcGSInfo; pcGSInfo.m_n64MsgReceived++; pcGSInfo.m_n64DataReceived += sMsg.CalculateSize(); pcGSInfo.m_un32ConnTimes++; pcGSInfo.m_tLastConnMilsec = tCurUTCMilsec; pcGSInfo.m_tLastPingMilSec = tCurUTCMilsec; Logger.Info($"Gate Server with GSID {pcGSInfo.m_n32GSID} registed at net session {gsPos}, total conn times {pcGSInfo.m_un32ConnTimes}"); } CSToGS.AskRegisteRet sAskRegisteRet = new CSToGS.AskRegisteRet(); sAskRegisteRet.Registe = ( int )n32Registe; sAskRegisteRet.Curtime = tCurUTCMilsec; if (ErrorCode.Success == n32Registe) { sAskRegisteRet.Ssbaseid = CS.instance.csKernelCfg.un32SSBaseIdx; for (int i = 0; i < CS.instance.csKernelCfg.un32MaxSSNum; i++) { CSSSInfo csssInfo = CS.instance.csKernelCfg.ssInfoList[i]; CSToGS.AskRegisteRet.Types.SSInfo pSSInfo = new CSToGS.AskRegisteRet.Types.SSInfo { Ssid = csssInfo.m_n32SSID, Ip = csssInfo.m_sListenIP, Port = csssInfo.m_n32ListenPort, Netstate = ( int )csssInfo.m_eSSNetState }; sAskRegisteRet.Ssinfo.Add(pSSInfo); } } CS.instance.PostMsgToGS(csgsInfo, sAskRegisteRet, ( int )CSToGS.MsgID.EMsgToGsfromCsAskRegisteRet, 0); if (ErrorCode.Success != n32Registe) { CS.instance.netSessionMgr.DisconnectOne(csgsInfo.m_n32NSID); } return(ErrorCode.Success); }
public CSUser GetUser(CSGSInfo csgsInfo, uint gcNetID) { UserNetInfo userNetInfo = new UserNetInfo(csgsInfo.m_n32GSID, gcNetID); return(this.GetUser(userNetInfo)); }