// Protocol: GetAchieve
        // Rec Args: None
        // Return: int[win] int[fail]
        public void MsgGetAchieve(Player player, ProtocolBase protoBase)
        {
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("GetAchieve");
            protocolRet.AddInt32(player.data.win);
            protocolRet.AddInt32(player.data.fail);

            player.Send(protocolRet);
            Console.WriteLine("[HandlePlayerMsg.MsgGetAchieve] Receive GetAchieve protocol from " + player.id);
        }
예제 #2
0
        public void MsgAddScore(Player player, ProtocolBase protoBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            string        protoName = protocol.GetString(start, ref start);

            //处理
            player.data.score += 1;
            Console.WriteLine("MsgAddScore " + player.username + " " + player.data.score.ToString());
        }
예제 #3
0
        //处理登录
        public void MsgLogin(Conn conn, ProtocolBase protoBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            string        protoName = protocol.GetString(start, ref start);
            string        username  = protocol.GetString(start, ref start);
            string        password  = protocol.GetString(start, ref start);
            string        strFormat = "[收到登录协议 ]" + conn.GetAddress();

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

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

            protocolLogout.AddString("Logout");
            if (!Player.KickOff(username, protocolLogout))
            {
                protocolRet.AddInt(-1);
                conn.Send(protocolRet);
                return;
            }
            //获取玩家数据
            PlayerData playerData = ServerSQL.instance.GetPlayerData(username);

            if (playerData == null)
            {
                protocolRet.AddInt(-1);
                conn.Send(protocolRet);
                return;
            }
            conn.player      = new Player(username, conn);
            conn.player.data = playerData;
            //事件触发
            ServerTCP.instance.handlePlayerEvent.OnLogin(conn.player);
            //返回
            protocolRet.AddInt(0);
            conn.Send(protocolRet);
            ServerTCP.instance.ShowOnlineSQL(conn.player);
            return;
        }
예제 #4
0
        /// <summary>
        /// Get the room list information.
        /// </summary>
        /// <returns>The room list.</returns>
        public ProtocolBytes GetRoomList()
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetRoomList");
            protocol.AddInt32(roomList.Count);
            foreach (Room room in roomList)
            {
                protocol.AddInt32(room.playerList.Count);
                protocol.AddInt32((int)room.status);
            }

            return(protocol);
        }
예제 #5
0
파일: Scene.cs 프로젝트: fzzx20080212/Ser
        public void UpdateInfo(string id, float x, float y, float z, int score)
        {
            ProtocolBytes protocol = new ProtocolBytes();
            ScenePlayer   p        = GetScenePlayer(id);

            if (p == null)
            {
                return;
            }
            p.x     = x;
            p.y     = y;
            p.z     = z;
            p.score = score;
        }
예제 #6
0
        //登录
        public void MsgLogin(Conn conn, ProtocolBase protocolBase)
        {
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protocolBase;
            string        protoName = protocol.GetString(start, ref start);
            string        id        = protocol.GetString(start, ref start);
            string        pw        = protocol.GetString(start, ref start);
            string        strFormat = "[收到登录协议] " + conn.GetAddr();

            Console.WriteLine(strFormat + " 用户名: " + id + " 密码: " + pw);
            //构建返回协议
            protocol = new ProtocolBytes();
            protocol.AddString("Login");
            //验证
            if (!DataMgr.instance.CheckPassWord(id, pw))
            {
                protocol.AddInt(-1);
                conn.Send(protocol);
                return;
            }
            //是否已经登录
            ProtocolBytes protocolLogout = new ProtocolBytes();

            protocolLogout.AddString("Logout");
            if (!Player.KickOff(id, protocolLogout))
            {
                protocol.AddInt(-2);
                conn.Send(protocol);
                return;
            }
            //获取玩家数据
            PlayerData playerData = DataMgr.instance.GetPlayerData(id);

            conn.player      = new Player(id, conn);
            conn.player.data = playerData;
            if (playerData == null)
            {
                protocol.AddInt(-3);
                conn.Send(protocol);
            }
            else
            {
                //事件触发
                Serv.instance.handlePlayerEvent.OnLogin(conn.player);
                protocol.AddInt(0);
                conn.Send(protocol);
            }
            //返回
            return;
        }
예제 #7
0
        public void MsgCreateRoom(Player player, ProtocolBase protocol)
        {
            ProtocolBytes proto = new ProtocolBytes();

            proto.AddString("CreateRoom");
            if (RoomMgr.instance.CreateRoom(player))
            {
                proto.AddInt(0);
            }
            else
            {
                proto.AddInt(-1);
            }
            player.Send(proto);
        }
        // Protocol: Login
        // Rec Args: string[id] string[pw]
        // Return: int[0-success] int[-1-fail]
        public void MsgLogin(Conn conn, ProtocolBase protoBase)
        {
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            int           start     = 0;
            string        protoName = protocol.GetString(start, ref start);
            string        id        = protocol.GetString(start, ref start);
            string        pw        = protocol.GetString(start, ref start);

            Console.WriteLine("[HandleConnMsg.MsgLogin] Receive Login protocol: id[" + id + "] pw[" + pw + "]");


            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("Login");

            if (!DataMgr.instance.CheckPassword(id, pw))
            {
                protocolRet.AddInt32(-1);
                conn.Send(protocolRet);
                return;
            }

            ProtocolBytes protocolLogout = new ProtocolBytes();

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

            PlayerData playerData = DataMgr.instance.GetPlayerData(id);

            if (playerData == null)
            {
                protocolRet.AddInt32(-1);
                conn.Send(protocolRet);
                return;
            }

            conn.player      = new Player(id, conn);
            conn.player.data = playerData;
            ServNet.instance.handlePlayerEvent.OnLogin(conn.player);

            protocolRet.AddInt32(0);
            conn.Send(protocolRet);
        }
예제 #9
0
        //登出
        public void MsgLogout(Conn conn, ProtocolBase protocolBase)
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("Logout");
            protocol.AddInt(0);
            conn.Send(protocol);
            if (conn.player == null)
            {
                conn.Close();
            }
            else
            {
                conn.player.Logout();
            }
        }
        //删除玩家
        public void DelPlayer(string username)
        {
            lock (list)
            {
                ScenePlayer p = GetScenePlayer(username);
                if (p != null)
                {
                    list.Remove(p);
                }
            }
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("PlayerLeave");
            protocol.AddString(username);
            ServerTCP.instance.Broadcast(protocol);
        }
        //更新信息
        public void UpdateInfo(string username, float x, float y, float z, int score, int kill)
        {
            int           count    = list.Count;
            ProtocolBytes protocol = new ProtocolBytes();
            ScenePlayer   p        = GetScenePlayer(username);

            if (p == null)
            {
                return;
            }
            p.x     = x;
            p.y     = y;
            p.z     = z;
            p.score = score;
            p.kill  = kill;
        }
예제 #12
0
파일: Scene.cs 프로젝트: fzzx20080212/Ser
        //删除玩家
        public void DelPlayer(string id)
        {
            lock (list)
            {
                ScenePlayer p = GetScenePlayer(id);
                if (p != null)
                {
                    list.Remove(p);
                }
            }
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("PlayerLeave");
            protocol.AddString(id);
            ServNet.getInstance().Broadcast(protocol);
        }
예제 #13
0
        public void MsgLogin(Conn conn, ProtocolBase protocolBase)
        {
            int           start         = 0;
            ProtocolBytes protocolBytes = (ProtocolBytes)protocolBase;
            string        name          = protocolBytes.GetString(start, ref start);
            string        id            = protocolBytes.GetString(start, ref start);
            string        pw            = protocolBytes.GetString(start, ref start);

            Console.WriteLine("[登入协议]" + "用户名:" + id + "密码:" + pw);
            protocolBytes = new ProtocolBytes();
            protocolBytes.AddString("Login");
            //验证
            if (!DataMgr.instance.CheckPassWord(id, pw))
            {
                protocolBytes.AddInt(-1);
                conn.Send(protocolBytes);
                return;
            }
            //是否已经登入,如果已登入,强制退出,并且此次登入失效
            ProtocolBytes protocolLogout = new ProtocolBytes();

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

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

            if (playerData == null)
            {
                protocolBytes.AddInt(-1);
                conn.Send(protocolBytes);
                return;
            }

            conn.player      = new Player(id, conn);
            conn.player.data = playerData;
            //事件触发
            ServNet.getInstance().HandlePlayerEvent.OnLogin(conn.player);
            protocolBytes.AddInt(0);
            conn.Send(protocolBytes);
            return;
        }
예제 #14
0
파일: Scene.cs 프로젝트: TLS18/Block-Server
        public void DelPlayer(string id)
        {
            lock (list)
            {
                ScenePlayer p = GetScenePlayer(id);
                if (p != null)
                {
                    list.Remove(p);
                    Console.WriteLine("[场景管理]删除玩家");
                }
            }
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("PlayerLeave");
            protocol.AddString(id);
            Serv.instance.Broadcast(protocol);
        }
예제 #15
0
파일: Scene.cs 프로젝트: TLS18/Block-Server
        public void UpdateInfo(string id, float x, float y, float z, float xScale, int animInfo, string name)
        {
            int           count = list.Count;
            ProtocolBytes bytes = new ProtocolBytes();
            ScenePlayer   p     = GetScenePlayer(id);

            if (p == null)
            {
                return;
            }
            p.x        = x;
            p.y        = y;
            p.z        = z;
            p.xScale   = xScale;
            p.animInfo = animInfo;
            p.name     = name;
        }
예제 #16
0
        //加入房间
        public void MsgEnterRoom(Player player, ProtocolBase protoBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            string        protoName = protocol.GetString(start, ref start);
            int           index     = protocol.GetInt(start, ref start);

            Console.WriteLine("[收到MsgEnterRoom]" + player.username + " " + index);

            protocol = new ProtocolBytes();
            protocol.AddString("EnterRoom");
            //判断房间是否存在
            if (index < 0 || index >= RoomMgr.instance.list.Count)
            {
                Console.WriteLine("MsgEnterRoom index error " + player.username);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }
            Room room = RoomMgr.instance.list[index];

            //判断房间是状态
            if (room.status != Room.Status.Prepare)
            {
                Console.WriteLine("MsgEnterRoom status error " + player.username);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }
            //添加玩家
            if (room.AddPlayer(player))
            {
                room.Broadcast(room.GetRoomInfo());
                protocol.AddInt(0);
                player.tempData.team = 2;
                player.Send(protocol);
            }
            else
            {
                Console.WriteLine("MsgEnterRoom maxPlayer err " + player.username);
                protocol.AddInt(-1);
                player.Send(protocol);
            }
        }
예제 #17
0
        //处理登出
        public void MsgLogout(Conn conn, ProtocolBase protoBase)
        {
            ProtocolBytes protocol = new ProtocolBytes();

            Console.WriteLine("[收到登出协议 ]" + conn.GetAddress() + "\n");
            protocol.AddString("Logout");
            protocol.AddInt(0);
            if (conn.player == null)
            {
                conn.Send(protocol);
                conn.Close();
            }
            else
            {
                conn.Send(protocol);
                conn.player.Logout();
            }
        }
예제 #18
0
        /// <summary>
        /// Get the room information.
        /// </summary>
        /// <returns>The room info.</returns>
        public ProtocolBytes GetRoomInfo()
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetRoomInfo");
            protocol.AddInt32(playerList.Count);
            foreach (Player player in playerList.Values)
            {
                protocol.AddString(player.id);
                protocol.AddInt32(player.tempData.team);
                protocol.AddInt32(player.data.win);
                protocol.AddInt32(player.data.fail);
                int isOwner = player.tempData.isOwner ? 1 : 0;
                protocol.AddInt32(isOwner);
            }

            return(protocol);
        }
예제 #19
0
파일: Scene.cs 프로젝트: fzzx20080212/Ser
        public void SendPlayerList(Player player)
        {
            int           count    = list.Count;
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetList");
            protocol.AddInt(count);
            for (int i = 0; i < count; i++)
            {
                ScenePlayer p = list[i];
                protocol.AddString(p.id);
                protocol.AddFloat(p.x);
                protocol.AddFloat(p.y);
                protocol.AddFloat(p.z);
                protocol.AddInt(p.score);
            }
            player.Send(protocol);
        }
예제 #20
0
파일: RoomMgr.cs 프로젝트: fzzx20080212/Ser
        //获取房间列表
        public ProtocolBase GetRoomList()
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetRoomList");
            int count = roomList.Count;

            protocol.AddInt(count);
            lock (roomList)
            {
                foreach (Room room in roomList)
                {
                    protocol.AddInt(room.playerNum);
                    protocol.AddInt((int)room.state);
                }
            }
            return(protocol);
        }
예제 #21
0
        //房间信息
        public ProtocolBytes GetRoomInfo()
        {
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetRoomInfo");
            //房间信息
            protocol.AddInt(list.Count);
            //每个玩家信息
            foreach (Player p in list.Values)
            {
                protocol.AddString(p.username);
                protocol.AddInt(p.data.win);
                protocol.AddInt(p.data.lose);
                int isOwner = p.tempData.isOwner ? 1 : 0;
                protocol.AddInt(isOwner);
            }
            return(protocol);
        }
예제 #22
0
        // Protocol: EnterRoom
        // Rec Args: int[roomindex]
        // Return: int[0-success -1-fail]
        public void MsgEnterRoom(Player player, ProtocolBase protoBase)
        {
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            int           start     = 0;
            string        protoName = protocol.GetString(start, ref start);
            int           index     = protocol.GetInt(start, ref start);

            Console.WriteLine("[HandleRoomMsg.MsgEnterRoom] Receive EnterRoom " + index.ToString() + " protocol from " + player.id);

            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("EnterRoom");

            if (index < 0 || index >= RoomMgr.instance.roomList.Count)
            {
                Console.WriteLine("[HandleRoomMsg.MsgEnterRoom] " + player.id + " enter room fail, index is illegal.");
                protocolRet.AddInt32(-1);
                player.Send(protocolRet);
                return;
            }

            Room room = RoomMgr.instance.roomList [index];

            if (room.status != Room.Status.Preparing)
            {
                Console.WriteLine("[HandleRoomMsg.MsgEnterRoom] " + player.id + " enter room fail, room is not in Preparing Status.");
                protocolRet.AddInt32(-1);
                player.Send(protocolRet);
                return;
            }
            if (room.AddPlayer(player))
            {
                room.Broadcast(room.GetRoomInfo());
                protocolRet.AddInt32(0);
                player.Send(protocolRet);
            }
            else
            {
                Console.WriteLine("[HandleRoomMsg.MsgEnterRoom] " + player.id + " enter room fail, room is full.");
                protocolRet.AddInt32(-1);
                player.Send(protocolRet);
            }
        }
        // Protocol: Logout
        // Rec Args: int[logout reason]
        // Return: int[0-logout normally]
        public void MsgLogout(Conn conn, ProtocolBytes protoBase)
        {
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("Logout");
            protocolRet.AddInt32(0);
            Console.WriteLine("[HandleConnMsg.MsgLogout] Receive Logout protocol.");

            conn.Send(protocolRet);

            if (conn.player != null)
            {
                conn.player.Logout();
            }
            else
            {
                conn.Close();
            }
        }
예제 #24
0
        // Protocol: CreateRoom
        // Rec Args: None
        // Return: int[0-success -1-fail]
        public void MsgCreateRoom(Player player, ProtocolBase protoBase)
        {
            Console.WriteLine("[HandleRoomMsg.MsgCreateRoom] Receive CreateRoom protocol from " + player.id);

            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("CreateRoom");

            if (player.tempData.status != PlayerTempData.Status.None)
            {
                Console.WriteLine("[HandleRoomMsg.MsgCreateRoom] Create room fail, " + player.id + " is not in None Status");
                protocolRet.AddInt32(-1);
                player.Send(protocolRet);
                return;
            }

            RoomMgr.instance.CreateRoom(player);
            protocolRet.AddInt32(0);
            player.Send(protocolRet);
        }
        //列表
        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);
                //protocol.AddString(list[i].roomname);
            }

            return(protocol);
        }
예제 #26
0
        public void MsgUpdateRot(Player player, ProtocolBase protocol)
        {
            int           start = 0;
            ProtocolBytes proto = (ProtocolBytes)protocol;
            string        name  = proto.GetString(start, ref start);
            float         x     = proto.GetFloat(start, ref start);
            float         y     = proto.GetFloat(start, ref start);
            float         z     = proto.GetFloat(start, ref start);

            float w = proto.GetFloat(start, ref start);
            //广播
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("UpdateRot");
            protocolRet.AddString(player.id);
            protocolRet.AddFloat(x);
            protocolRet.AddFloat(y);
            protocolRet.AddFloat(z);
            protocolRet.AddFloat(w);
            ServNet.getInstance().Broadcast(protocolRet);
        }
예제 #27
0
        //设置名字
        public void MsgEditName(Player player, ProtocolBase protocolBase)
        {
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protocolBase;
            string        protoName = protocol.GetString(start, ref start);
            string        Cname     = protocol.GetString(start, ref start);

            //处理
            player.data.name = Cname;
            protocol         = new ProtocolBytes();
            protocol.AddString("EditName");
            if (DataMgr.instance.SavePlayer(player))
            {
                protocol.AddInt(0);
            }
            else
            {
                protocol.AddInt(-1);
            }
            player.Send(protocol);
        }
예제 #28
0
파일: Scene.cs 프로젝트: TLS18/Block-Server
        public void SendPlayerList(Player player)
        {
            Console.WriteLine("发送玩家信息");
            int           count    = list.Count;
            ProtocolBytes protocol = new ProtocolBytes();

            protocol.AddString("GetList");
            protocol.AddInt(count);
            for (int i = 0; i < count; i++)
            {
                ScenePlayer p = list[i];
                protocol.AddString(p.id);
                protocol.AddFloat(p.x);
                protocol.AddFloat(p.y);
                protocol.AddFloat(p.z);
                protocol.AddFloat(p.xScale);
                protocol.AddInt(p.animInfo);
                protocol.AddString(p.name);
            }
            player.Send(protocol);
        }
예제 #29
0
        //创建房间
        public void MsgCreateRoom(Player player, ProtocolBase protoBase)
        {
            int           start     = 0;
            ProtocolBytes protocol  = new ProtocolBytes();
            string        protoName = protocol.GetString(start, ref start);

            //Room.instance.roomname = protocol.GetString(start, ref start);
            protocol.AddString("CreateRoom");
            //条件检测
            if (player.tempData.status != PlayerTempData.Status.None)
            {
                Console.WriteLine("MsgCreateRoom Fail " + player.username);
                protocol.AddInt(-1);
                player.Send(protocol);
                return;
            }
            RoomMgr.instance.CreateRoom(player);
            protocol.AddInt(0);
            player.Send(protocol);
            player.tempData.team = 1;
            Console.WriteLine("MsgCreateRoom Ok " + player.username);
        }
예제 #30
0
        //同步玩家单元
        public void MsgUpdateUnitInfo(Player player, ProtocolBase protoBase)
        {
            //获取数值
            int           start     = 0;
            ProtocolBytes protocol  = (ProtocolBytes)protoBase;
            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);

            //获取房间
            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.GetTimeStamp();
            //广播
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("UpdateUnitInfo");
            protocolRet.AddString(player.username);
            protocolRet.AddFloat(posX);
            protocolRet.AddFloat(posY);
            protocolRet.AddFloat(posZ);
            protocolRet.AddFloat(rotX);
            protocolRet.AddFloat(rotY);
            protocolRet.AddFloat(rotZ);
            room.Broadcast(protocolRet);
        }