public void ReqLogin(MsgPack pack) { RequestLogin data = pack.Msg.RequestLogin; //账号是否上线 NetMsg netMsg = new NetMsg { cmd = (int)Command.ResponseLogin }; if (_cacheSvc.IsAcctOnline(data.Acct)) { //己上线:返回错误信息 netMsg.err = (int)ErrorCode.AcctIsOnline; } else { //账号不在线 || 账号是否已经存在 PlayerData playerData = _cacheSvc.GetPlayerData(data.Acct, data.Pass); if (playerData == null) { //账号存在,密码错误 netMsg.err = (int)ErrorCode.WrongPass; } else { #region 计算离线玩家体力值 int power = playerData.Power; long timeNow = _timeSvc.GetNowTime(); long milliseconds = timeNow - playerData.Time; int addPower = (int)(milliseconds / (1000 * 60 * PeRoot.PowerAddSpace)) * PeRoot.PowerAddCount; if (addPower > 0) { int powerMax = PeRoot.GetPowerLimit(playerData.Level); if (playerData.Power < powerMax) { playerData.Power += addPower; if (playerData.Power > powerMax) { playerData.Power = powerMax; } } } if (power != playerData.Power) { _cacheSvc.UpdatePlayerData(playerData.Id, playerData); } #endregion netMsg.ResponseLogin = new ResponseLogin { PlayerData = playerData }; //缓存账号数据 _cacheSvc.AcctOnLine(data.Acct, pack.Session, playerData); } } pack.Session.SendMsg(netMsg); }
private void CalcPowerAdd(int timeId) { PeRoot.Log("All Online Player Calc Power Incress...."); NetMsg netMsg = new NetMsg { cmd = (int)Command.PshPower }; netMsg.PshPower = new PshPower(); Dictionary <ServerSession, PlayerData> onLineDictionary = _cacheSvc.GetOnLine(); foreach (var item in onLineDictionary) { PlayerData playerData = item.Value; ServerSession session = item.Key; int powerMax = PeRoot.GetPowerLimit(playerData.Level); if (playerData.Power >= powerMax) { continue; } else { playerData.Power += PeRoot.PowerAddCount; playerData.Time = _timeSvc.GetNowTime(); if (playerData.Power > powerMax) { playerData.Power = powerMax; } } if (!_cacheSvc.UpdatePlayerData(playerData.Id, playerData)) { netMsg.err = (int)ErrorCode.UpdateDbError; } else { netMsg.PshPower.Power = playerData.Power; session.SendMsg(netMsg); } } }