示例#1
0
    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);
        }
    }
示例#2
0
    /// <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);
    }
示例#3
0
    void OnNotifyOffline(SocketModel model)
    {
        NotifyOffline notify = SerializeUtil.Deserialize <NotifyOffline>(model.message);

        //销毁坦克
        OtherTank tank = TankManager.instance.GetTank(notify.id) as OtherTank;

        if (tank != null)
        {
            tank.Destory();
        }

        //移除坦克对象
        TankManager.instance.RemoveTank(tank);
    }