Ejemplo n.º 1
0
        //心跳
        public static ProtocolBase GetHeatBeatProtocol()
        {
            ProtocolPbprotobuf protocol = new ProtocolPbprotobuf();

            protocol.SetName("HeatBeat");
            return(protocol);
        }
Ejemplo n.º 2
0
        //注册
        //@协议参数,用户名,密码 @返回协议:-1表示失败,0表示成功
        public void MsgRegister(Conn conn, ProtocolBase protocolBase)
        {
            ProtocolPbprotobuf protocol  = (ProtocolPbprotobuf)protocolBase;
            string             protoName = protocol.GetName();
            string             protoType = protocol.GetTypeStr();
            string             id        = protocol.buf.Register.Id;
            string             pw        = protocol.buf.Register.Pw;
            string             strFormat = "[收到注册协议] : " + conn.GetAdress();

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

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

            if (DataMgr.DataMgr.instance.Register(id, pw))
            {
                protocolRet.SetResponse(ProtocolPbprotobuf.QueryName.Register.ToString(),
                                        0, "Register success");
            }
            else
            {
                protocolRet.SetResponse(ProtocolPbprotobuf.QueryName.Register.ToString(),
                                        -1, "Register fail");
            }
            //创建角色
            // DataMgr.DataMgr.instance.CreatePlayer(id);  考虑一下
            //返回协议给客户端
            conn.Send(protocolRet);
        }
Ejemplo n.º 3
0
        //测试用:获取分数
        //返回协议:int 分数
        public void MsgGetScore(Player player, ProtocolBase protocolBase)
        {
            ProtocolPbprotobuf protocolRet = new ProtocolPbprotobuf();

            protocolRet.SetResponse("GetScore", 0, "", player.data.score);
            player.Send(protocolRet);
            Console.WriteLine("MsgGetScore : " + player.id + ":" + player.data.score);
        }
Ejemplo n.º 4
0
        public void MsgCreatePlayer(Conn conn, ProtocolBase protocolBase)
        {
            ProtocolPbprotobuf protocol  = (ProtocolPbprotobuf)protocolBase;
            string             id        = protocol.buf.PlayerData.Id;
            string             Partindex = protocol.buf.PlayerData.PartIndex;

            Console.WriteLine("id : " + id + " partIndex : " + Partindex);
        }
Ejemplo n.º 5
0
        //测试用:增加分数功能
        public void MsgAddScore(Player player, ProtocolBase protocolBase)
        {
            ProtocolPbprotobuf protocol  = (ProtocolPbprotobuf)protocolBase;
            string             protoName = protocol.GetName();

            //处理
            player.data.score += 1;
            Console.WriteLine("MsgAddScore : " + player.id + " : " + player.data.score.ToString());
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        //更新信息
        public void UpdateInfo(string id, float x, float y, float z)
        {
            int count = _list.Count;
            ProtocolPbprotobuf protocol = new ProtocolPbprotobuf();
            ScenePlayer        p        = GetScenePlayer(id);

            if (p == null)
            {
                return;
            }
            p.x = x;
            p.y = y;
            p.z = z;
        }
Ejemplo n.º 8
0
        //删除Scene角色
        public void DelPlayer(string id)
        {
            lock (_list){
                ScenePlayer p = GetScenePlayer(id);
                if (p != null)
                {
                    _list.Remove(p);
                }
            }
            ProtocolPbprotobuf protocol = new ProtocolPbprotobuf();

            protocol.SetResponse(ProtocolPbprotobuf.QueryName.PlayerLeave.ToString(), 0, id);
            ServNet.ServNet._instance.Broadcast(protocol);
        }
Ejemplo n.º 9
0
 public static void test_client_1()
 {
     test_client.test_client client = new test_client.test_client();
     client.Connection();
     // Console.ReadKey();
     // client.Send("atom");
     // Console.ReadKey();
     while (true)
     {
         Console.ReadKey();
         ProtocolPbprotobuf protocol = new ProtocolPbprotobuf();
         protocol.buf.Query = "HeatBeat";
         client.Send(protocol);
     }
 }
Ejemplo n.º 10
0
        //登出功能
        //返回协议:0正常下线
        public void MsgLogout(Conn conn, ProtocolBase protocolBase)
        {
            ProtocolPbprotobuf protocolRet = new ProtocolPbprotobuf();

            protocolRet.SetResponse(ProtocolPbprotobuf.QueryName.Logout.ToString(), code: 0, msg: "Logout");
            if (conn._player == null)
            {
                conn.Send(protocolRet);
                conn.Close();
            }
            else
            {
                conn.Send(protocolRet);
                conn._player.Logout();
            }
        }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
            }
        }