예제 #1
0
파일: ServNet.cs 프로젝트: fzzx20080212/Ser
 public static ServNet getInstance()
 {
     if (instance == null)
     {
         instance = new ServNet();
     }
     return(instance);
 }
예제 #2
0
파일: Player.cs 프로젝트: fzzx20080212/Ser
 //下线
 public bool Logout()
 {
     //事件处理
     //ServNet.getInstance().handlePlayerEvent.OnLogout(this);
     //保存
     if (!DataMgr.instance.SavePlayer(this))
     {
         return(false);
     }
     //下线
     ServNet.getInstance().HandlePlayerEvent.OnLogout(this);
     conn.player = null;
     conn.Close();
     return(true);
 }
예제 #3
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);
        }
예제 #4
0
파일: RoomMgr.cs 프로젝트: fzzx20080212/Ser
        //创建房间
        public bool CreateRoom(Player player)
        {
            if (player.tempData.state == PlayerTempData.State.None)
            {
                Room room = new Room(player);
                room.state = Room.State.Readying;
                room.AddPlayer(player);
                lock (roomList){
                    roomList.Add(room);
                }
                ServNet.getInstance().Broadcast(GetRoomList());
                return(true);
            }

            return(false);
        }
예제 #5
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;
        }
예제 #6
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);
        }
예제 #7
0
        //更新信息
        public void MsgUpdateInfo(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);
            int           score = player.data.score;

            Scene.instance.UpdateInfo(player.id, 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.getInstance().Broadcast(protocolRet);
        }
예제 #8
0
 public ServNet()
 {
     instance = this;
 }
예제 #9
0
 public void MsgKeyUp(Player player, ProtocolBase protocol)
 {
     ServNet.getInstance().Broadcast(protocol);
 }
예제 #10
0
파일: Conn.cs 프로젝트: fzzx20080212/Ser
 //发送协议
 public void Send(ProtocolBase protocol)
 {
     ServNet.getInstance().Send(this, protocol);
 }