Beispiel #1
0
    //登录
    //协议参数:str用户名,str密码
    //返回协议:-1表示失败 0表示成功
    public void MsgLogin(Conn conn, ProtocolBase protoBase)
    {
        //获取数值
        int           start     = 0;
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        string        protoName = protocol.GetString(start, ref start);
        string        id        = protocol.GetString(start, ref start);
        string        pw        = protocol.GetString(start, ref start);
        string        strFormat = "[收到登录协议]" + conn.GetAdress();

        Console.WriteLine(strFormat + " 用户名:" + id + " 密码:" + pw);
        //构建返回协议
        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("Login");
        //验证
        if (!DataMgr.instance.CheckPassWord(id, pw))
        {
            protocolRet.AddInt(-1);
            conn.Send(protocolRet);
            return;
        }
        //是否已经登录
        ProtocolBytes protocolLogout = new ProtocolBytes();

        protocolLogout.AddString("Logout");
        if (!Player.KickOff(id, protocolLogout))
        {
            protocolRet.AddInt(-1);
            conn.Send(protocolRet);
            return;
        }

        //获取玩家数据
        PlayerData playerData = DataMgr.instance.GetPlayerData(id);

        if (playerData == null)
        {
            protocolRet.AddInt(-1);
            conn.Send(protocolRet);
            return;
        }
        conn.player      = new Player(id, conn);
        conn.player.data = playerData;
        //事件触发
        ServNet.instance.handlePlayerEvent.OnLogin(conn.player);

        //返回
        protocolRet.AddInt(0);
        protocolRet.AddIntList(playerData.CardList);
        protocolRet.AddIntList(playerData.BattleCardList);
        conn.Send(protocolRet);
        return;
    }
Beispiel #2
0
    public void MsgSetMyBattleCardList(Player player, ProtocolBase protoBase)
    {
        int           start     = 0;
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        string        protoName = protocol.GetString(start, ref start);
        List <int>    MyPlayerBattleCardList = protocol.GetIntList(start, ref start);
        bool          isScuss = DataMgr.instance.SetBattleCardList(player.id, MyPlayerBattleCardList);

        Console.WriteLine("MyPlayerBattleCardList :" + MyPlayerBattleCardList.Count);
        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("SetMyBattleCardList");
        if (isScuss)
        {
            protocolRet.AddInt(0);
            player.data.BattleCardList = MyPlayerBattleCardList;
        }
        else
        {
            protocolRet.AddInt(-1);
        }

        protocolRet.AddIntList(MyPlayerBattleCardList);

        player.conn.Send(protocolRet);
    }
Beispiel #3
0
    public void SetMyBattleCardList()
    {
        ProtocolBytes protocol = new ProtocolBytes();

        protocol.AddString("SetMyBattleCardList");
        Debug.Log("发送 " + protocol.GetDesc());
        protocol.AddIntList(MyPlayer.Instance.data.BattleCardList);
        NetMgr.srvConn.Send(protocol, OnSetMyBattleCardListBack);
    }
Beispiel #4
0
    public void MsgSerachEnemy(Player player, ProtocolBase protoBase)
    {
        int           start     = 0;
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        string        protoName = protocol.GetString(start, ref start);

        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("SerachEnemy");
        protocolRet.AddString("Test");
        List <int> EnemyBattleCardList = new List <int>()
        {
            5, 6, 7, 8, 9, 10
        };

        protocolRet.AddIntList(EnemyBattleCardList);

        player.conn.Send(protocolRet);
    }