コード例 #1
0
        //心跳
        public static ProtocolBase GetHeatBeatProtocol()
        {
            ProtocolPbprotobuf protocol = new ProtocolPbprotobuf();

            protocol.SetName("HeatBeat");
            return(protocol);
        }
コード例 #2
0
        //登录
        //@协议参数id,pw; @返回协议:-1失败,0成功
        public void MsgLogin(Conn conn, ProtocolBase protocolBase)
        {
            ProtocolPbprotobuf protocol  = (ProtocolPbprotobuf)protocolBase;
            string             protoName = protocol.GetName();
            string             id        = protocol.buf.Login.Id;
            string             pw        = protocol.buf.Login.Pw;
            string             strFormat = "[收到登录协议] : " + conn.GetAdress();

            Console.WriteLine(strFormat + " 用户名: " + id + " 密码: " + pw);

            //构建返回协议
            ProtocolPbprotobuf protocolRet = new ProtocolPbprotobuf();

            //验证
            if (!DataMgr.DataMgr.instance.CheckPassword(id, pw))
            {
                protocolRet.SetResponse(ProtocolPbprotobuf.QueryName.Login.ToString(),
                                        -1, "login fail");
                conn.Send(protocolRet);
                return;
            }
            Console.WriteLine("存在账户");
            //是否已登录
            ProtocolPbprotobuf protocolLogout = new ProtocolPbprotobuf();

            protocolLogout.SetName(ProtocolPbprotobuf.QueryName.Logout.ToString());
            if (!Player.KickOff(id, protocolLogout))     //不查询,直接踢
            {
                protocolRet.SetResponse(ProtocolPbprotobuf.QueryName.Login.ToString(),
                                        -1,
                                        "踢人失败 T_T");
                conn.Send(protocolRet);
            }
            //获取玩家数据
            PlayerData playerData = DataMgr.DataMgr.instance.GetPlayerData(id);

            if (playerData == null)
            {
                protocolRet.SetResponse(ProtocolPbprotobuf.QueryName.Login.ToString(),
                                        1,                // (int)Code.NoPlayer,
                                        "get PlayerData fail T_T");
                conn.Send(protocolRet);
                return;
            }
            Console.WriteLine("存在角色");
            conn._player      = new Player(id, conn);
            conn._player.data = playerData;
            //事件触发
            ServNet.ServNet._instance.HandlePlayerEvent.OnLogin(conn._player);
            //返回
            protocolRet.SetPlayerData(id, playerData.partIndex);
            protocolRet.SetResponse(ProtocolPbprotobuf.QueryName.Login.ToString(), 0, "login success");
            conn.Send(protocolRet);
            return;
        }
コード例 #3
0
        //发送列表
        public void SendPlayerList(Player player)
        {
            int count = _list.Count;
            ProtocolPbprotobuf protocol = new ProtocolPbprotobuf();

            protocol.SetName(ProtocolPbprotobuf.QueryName.GetList.ToString());
            for (int i = 0; i < count; i++)
            {
                ScenePlayer p = _list[i];
                protocol.buf.PlayerInfos[p.id] = new PlayerInfo()
                {
                    Id       = p.id,
                    NickName = "",
                    Pos      = new Pos()
                    {
                        X = p.x, Y = p.y, Z = p.z
                    }
                };
                player.Send(protocol);
            }
        }
コード例 #4
0
        //更新信息
        public void MsgUpdateInfo(Player player, ProtocolBase protocolBase)
        {
            ProtocolPbprotobuf protocol  = new ProtocolPbprotobuf();
            string             protoName = protocol.GetName();

            foreach (var value in protocol.buf.PlayerInfos.Values)
            {
                Scene.Scene.instance.UpdateInfo(value.Id, value.Pos.X, value.Pos.Y, value.Pos.Z);
                //广播
                ProtocolPbprotobuf protocolRet = new ProtocolPbprotobuf();
                protocolRet.SetName(ProtocolPbprotobuf.QueryName.UpdateInfo.ToString());
                protocolRet.buf.PlayerInfos[value.Id] = new PlayerInfo()
                {
                    Id       = value.Id,
                    NickName = "",
                    Pos      = new Pos()
                    {
                        X = value.Pos.X, Y = value.Pos.Y, Z = value.Pos.Z
                    }
                };
                ServNet.ServNet._instance.Broadcast(protocolRet);
            }
        }