示例#1
0
        //获取积分
        //返回 : int分数
        public void MsgGetScore(Player player, ProtocolBase protoBase)
        {
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("GetScore");
            protocolRet.AddInt(player.data.score);
            player.Send(protocolRet);
            Console.WriteLine("MsgGetScore " + player.id + player.data.score);
        }
示例#2
0
        public ProtocolBytes GetRoomInfo()
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetRoomInfo");
            //房间信息
            protocol.AddInt(list.Count);
            foreach (Player py in list.Values)
            {
                protocol.AddString(py.id);
                protocol.AddInt(py.tempData.team);
                protocol.AddInt(py.data.win);
                protocol.AddInt(py.data.fail);
                int isOwner = py.tempData.isOwner ? 1 : 0;
                protocol.AddInt(isOwner);
            }
            return(protocol);
        }
示例#3
0
        public void MsgUpdateUnitInfo(Player player, ProtocolBase protocolBase)
        {
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protocolBase;
            string        protoName = protocol.GetString(start, ref start);
            float         posx      = protocol.GetFloat(start, ref start);
            float         posy      = protocol.GetFloat(start, ref start);
            float         posz      = protocol.GetFloat(start, ref start);
            float         rotx      = protocol.GetFloat(start, ref start);
            float         roty      = protocol.GetFloat(start, ref start);
            float         rotz      = protocol.GetFloat(start, ref start);

            float gunRot  = protocol.GetFloat(start, ref start);
            float gunRoll = protocol.GetFloat(start, ref start);

            //获取房间
            if (player.tempData.status != PlayerTempData.Status.Fight)
            {
                return;
            }
            Room room = player.tempData.room;

            player.tempData.posX           = posx;
            player.tempData.posY           = posy;
            player.tempData.posZ           = posz;
            player.tempData.lastUpdateTime = Sys.Getimetamp();

            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("UpdateUnitInfo");
            protocolRet.AddString(player.id);
            protocolRet.AddFloat(posx);
            protocolRet.AddFloat(posy);
            protocolRet.AddFloat(posz);
            protocolRet.AddFloat(rotx);
            protocolRet.AddFloat(roty);
            protocolRet.AddFloat(rotz);

            protocolRet.AddFloat(gunRot);
            protocolRet.AddFloat(gunRoll);
            room.Broadcast(protocolRet);
        }
        //登录
        //Login 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.GettPlayerData(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);
            conn.Send(protocolRet);
            return;
        }
示例#5
0
        //更新信息
        public void MsgUpdateInfo(Player player, ProtocolBase protoBase)
        {
            //获取分数
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            string        protoname = protocol.GetString(start, ref start);
            float         x         = protocol.GetFloat(start, ref start);
            float         y         = protocol.GetFloat(start, ref start);
            float         z         = protocol.GetFloat(start, ref start);
            int           score     = protocol.GetInt(start, ref start);

            Scene.Scener.instance.UpdateInfo(protoname, x, y, z, score);

            //广播
            ProtocolBytes protocolret = new ProtocolBytes();

            protocolret.AddString("UpdateInfo");
            protocolret.AddString(player.id);
            protocolret.AddFloat(x);
            protocolret.AddFloat(y);
            protocolret.AddFloat(z);
            protocolret.AddInt(score);
            ServNet.instance.Broadcast(protocolret);
        }
        //返回协议 : 0-正常下线
        public void MsgLogout(Conn conn, ProtocolBase protoBase)
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("Logout");
            protocol.AddInt(0);
            if (conn.player == null)
            {
                conn.Send(protocol);
                conn.Close();
            }
            else
            {
                conn.Send(protocol);
                conn.player.Logout();
            }
        }
示例#7
0
        public ProtocolBytes GetRoomList()
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetRoomList");

            //数量
            int count = list.Count;

            protocol.AddInt(count);
            for (int i = 0; i < count; i++)
            {
                Room room = list[i];
                protocol.AddInt(room.list.Count);
                protocol.AddInt((int)room.status);
            }
            return(protocol);
        }
示例#8
0
        //创建
        public void MsgCreateRoom(Player player, ProtocolBase protoBase)
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("CreateRoom");
            //条件检测
            if (player.tempData.status != PlayerTempData.Status.None)
            {
                protocol.AddInt(-1);
                player.Send(protocol);
                Console.WriteLine("MsgCreateRoom Fail" + player.id);
                return;
            }
            RoomMgr.instance.CreateRoom(player);
            protocol.AddInt(0);
            player.Send(protocol);
            Console.WriteLine("MsgCreateRoom ok" + player.id);
        }
示例#9
0
        //加入
        public void MsgEnterRoom(Player player, ProtocolBase proto)
        {
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)proto;
            string        protoName = protocol.GetString(start, ref start);
            int           index     = protocol.GetInt(start, ref start);

            Console.WriteLine("[收到 MsetenterRoom] " + player.id + "" + index);

            protocol = new ProtocolBytes();
            protocol.AddString("EnterRoom");

            if (index < 0 || index >= RoomMgr.instance.list.Count)
            {
                Console.WriteLine("MsgEnterRoom Index error" + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }
            Room room = RoomMgr.instance.list[index];

            //判断房间状态
            if (room.status != Room.Status.Prepare)
            {
                Console.WriteLine("MsgEnterRoom statuserr" + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }
            if (room.AddPlayer(player))
            {
                room.Broadcast(room.GetRoomInfo());
                protocol.AddInt(0);
                player.Send(protocol);
            }
            else
            {
                Console.WriteLine("MsgEnterRoom maxPlayer erro " + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
            }
        }
示例#10
0
        //start
        public void MsgStartFight(Player player, ProtocolBase protoBase)
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("StartFight");

            if (player.tempData.status != PlayerTempData.Status.Room)
            {
                Console.WriteLine("MsgStartFight status err " + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }

            if (!player.tempData.isOwner)
            {
                Console.WriteLine("MsgStartFight owner err " + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }

            Room room = player.tempData.room;

            if (!room.CanStart())
            {
                Console.WriteLine("MsgStartFight Canstart err " + player.id);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }

            protocol.AddInt(0);
            player.Send(protocol);
            room.StartFight();
        }
示例#11
0
        //离开
        public void MsgLeaveRoom(Player player, ProtocolBase protoBase)
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("LeaveRoom");
            //条件检测
            if (player.tempData.status != PlayerTempData.Status.Room)
            {
                protocol.AddInt(-1);
                player.Send(protocol);
                Console.WriteLine("MsgLeaveRoom status err" + player.id);
                return;
            }
            protocol.AddInt(0);
            player.Send(protocol);
            Room room = player.tempData.room;

            RoomMgr.instance.LeaveRoom(player);

            if (room != null)
            {
                room.Broadcast(room.GetRoomInfo());
            }
        }