private void OnReqFire(UserToken token, SocketModel model) { ReqFire req = SerializeUtil.Deserialize <ReqFire>(model.message); AccountData acc = CacheManager.instance.GetAccount(token.accountid); if (acc == null) { return; } Battle battle = CacheManager.instance.GetBattle(acc.battleid, acc.battleType); Tank t = battle.GetTank(token.accountid); if (t != null && t.hp > 0) { //校验两次攻击间隔 if (Time.time * 0.001f - t.lastFireTime < 1) { return; } t.lastFireTime = Time.time * 0.001f; NotifyFire notify = new NotifyFire(); notify.id = token.accountid; notify.pos = req.pos; notify.rot = req.rot; MsgSender.SendOther <NotifyFire>(battle.accounts, token, (int)MsgID.NotifyFire, notify); } }
void Write() { while (true) { Queue <UserToken> offelineTokens = CacheManager.instance.offlineTokens; for (int i = 0; i < offelineTokens.Count; i++) { UserToken token = offelineTokens.Dequeue(); Console.WriteLine(string.Format(token.accountid + "Disconnet...")); AccountData user = CacheManager.instance.GetAccount(token.accountid); if (user == null) { return; } //if (string.IsNullOrEmpty(token.accountid)) continue; CacheManager.instance.WriteAccountAll(token.accountid); //移除坦克 AccountData acc = CacheManager.instance.GetAccount(token.accountid); if (acc == null) { return; } Room room = CacheManager.instance.GetMatch(acc.roomid); if (room != null) { room.RemoveAccount(acc.account); } Battle battle = CacheManager.instance.GetBattle(acc.battleid, acc.battleType); if (battle != null) { battle.RemoveTank(acc.account); battle.RemoveAccount(acc.account); } //移除账号 CacheManager.instance.RemoveAccount(token.accountid); //移除账号所有物品和装备 CacheManager.instance.RemoveAccountItem(token.accountid); CacheManager.instance.RemoveAccountEquip(token.accountid); NotifyOffline notify = new NotifyOffline(); notify.id = token.accountid; MsgSender.SendOther <NotifyOffline>(CacheManager.instance.GetAllAccount(), token, (int)MsgID.NotifyOffline, notify); token.accountid = null; } Thread.Sleep(10); } }
/// <summary> /// 客户端断开连接 /// </summary> /// <param name="token"></param> /// <param name="error"></param> public void ClientClose(UserToken token, string error) { Console.WriteLine(string.Format(token.accountid + "Disconnet...")); CacheManager.instance.RemoveToken(token); CacheManager.instance.RemoveTank(token.accountid); NotifyOffline notify = new NotifyOffline(); notify.id = token.accountid; MsgSender.SendOther <NotifyOffline>(CacheManager.instance.GetAllTokens(), token, (int)MsgID.NotifyOffline, notify); }
private void OnReqMove(UserToken token, SocketModel model) { ReqMove req = SerializeUtil.Deserialize <ReqMove>(model.message); //保存坦克的实时坐标 AccountData acc = CacheManager.instance.GetAccount(token.accountid); if (acc == null) { return; } Battle battle = CacheManager.instance.GetBattle(acc.battleid, acc.battleType); if (battle == null) { return; } Tank t = battle.GetTank(token.accountid); if (t != null && t.hp > 0) { ////校验两帧的移动距离 //float deltaTime = Time.time * 0.001f - t.lastMoveTime; //float distance = deltaTime * 5; //float reqDistance = Luna3D.Vector3.Distance(Tools.ToLunaVec3(req.pos), t.lastPos); //if (reqDistance > distance + 0.2f) return; //t.lastMoveTime = Time.time * 0.001f; //修改缓存 t.pos = new Vector3(req.pos.x, 0, req.pos.z); t.rot = Tools.ToLunaVec3(req.rot); t.lastPos = t.pos; //给别人发通知 NotifyMove notify = new NotifyMove(); notify.id = token.accountid; notify.pos = Tools.ToVec_3(t.pos); notify.rot = req.rot; MsgSender.SendOther <NotifyMove>(battle.accounts, token, (int)MsgID.NotifyMove, notify); } }