示例#1
0
        private void CreateMessage(ByteBuffer buffer)
        {
            int        type = buffer.readInt();
            ByteBuffer buf  = new ByteBuffer(type, header - 4);

            buf.Type = type;
            buf.writeBytes(buffer.getBuffer(), 4, this.header - 4);

            if (type != 1001 && type != 1002)
            {
                if (this.user == null)
                {
                    //用户没登陆
                    this.send(ConstomMessage.getError("用户没登陆"));
                    return;
                }
            }
            MessageNode node;

            node.Type   = type;
            node.buffer = buf;
            node.socket = this;
            node.Method = null;
            Server.addReciveTask(node);
        }
示例#2
0
        public bool addRoom(int roomId, User user, string password)
        {
            Room r = this.rooms[roomId];

            //有房间密码
            if (r.Password != null && r.Password.Length > 0)
            {
                if (password.Length <= 0)
                {
                    ByteBuffer buf = ByteBuffer.CreateByteBufferType(Protcol.通知玩家房间有密码);
                    buf.writeInt(roomId);
                    user.Send(buf);
                    return(false);
                }
                if (!r.Password.Equals(password))
                {
                    user.Send(ConstomMessage.getError("房间密码不对"));
                    return(false);
                }
            }
            bool f = r.AddRoom(user);

            if (!f)
            {
                user.Send(ConstomMessage.getError("房间已满"));
            }
            return(f);
        }
示例#3
0
 public void Run()
 {
     try {
         while (run)
         {
             if (!cqueue.IsEmpty)
             {
                 // lock(this)
                 //{
                 MessageNode node;
                 bool        f = cqueue.TryDequeue(out node);
                 cNode = node;
                 util.core.EventDispatch.dispatchEvent(node.Type, node);
                 debug.logln("===============还有剩余消息:   " + cqueue.Count);
                 //debug.logln(node.socket.name + " < " + (node.socket.user != null ? node.socket.user.ChinaName : "") + " : " + node.Type + " > - 执行第[ " + (++msgCount) + " ]条协议");
                 // }
             }
             //
             Thread.Sleep(1);
         }
     }catch (Exception e)
     {
         debug.log(e.Message);
         debug.logln("==========================================================");
         debug.logln("警告: 发生了严重错误!!! <" + cNode.socket.user.ChinaName + " : " + cNode.Type + ">");
         debug.logln("==========================================================");
         cNode.socket.Close();
         ConstomMessage.SendAllMessage("原因:[" + cNode.socket.user.ChinaName + "]执行了 > " + cNode.Type + " 协议");
         run = false;
     }
 }
示例#4
0
 public void UserTurnGame(User user, int row, int col)
 {
     if (this.GameCheck())
     {
         this.game.GameTurn(user, row, col);
     }
     else
     {
         //debug.logln("this.readyCount: " + this.readyCount + "  ,userLength: " + this.getUsers().Length);
         sendAllMessage(ConstomMessage.getError("房间数据异常,请退出房间,重新进入"));
         this.GameOver();
     }
 }
示例#5
0
        public void addRoom(int roomId, User user, string pwd = null)
        {
            if (user.room != null)
            {
                user.Send(ConstomMessage.getError("你已经在别的房间,请先退出,再加入"));
                return;
            }
            bool f = RoomManager.shareRoomManager().addRoom(roomId, user, pwd);

            if (f)
            {
                UpdateRoomInfomation(user, 1);
            }
        }
示例#6
0
        //用户登陆
        public void do1001(MessageNode node)
        {
            ClientNode client = node.socket;
            ByteBuffer buffer = node.buffer;

            string name = buffer.readString();

            if (g.ContansUser(name))
            {
                client.send(ConstomMessage.getError("该用户已在别处登陆,服务器拒绝登陆!"));
                return;
            }
            if (!FFactory.Exists(Share.USER_SAVE_PATH + name))
            {
                client.send(ConstomMessage.getError("用户名错误!"));
                return;
            }
            User   user = FFactory.ReadObject <User>(Share.USER_SAVE_PATH + name);
            string pwd  = buffer.readString();

            if (!user.Password.Equals(pwd))
            {
                client.send(ConstomMessage.getError("密码错误!"));
            }
            else
            {
                user.BindSocket(client);
                g.addUser(user);

                ByteBuffer buf = new ByteBuffer();
                buf.writeInt(Protcol.用户登陆);
                buf.writeString(user.UserName);
                buf.writeString(user.ChinaName);
                //debug.logln(user.Money, user.Duanwei, user.Image, user.Text);
                buf.writeInt(user.Money);
                buf.writeString(user.Duanwei);
                buf.writeString(user.Image);
                buf.writeString(user.Text);

                client.send(buf);


                GameHall.shareGameHall().addGameHall(user);

                //debug.logln(user.ChinaName + " 登陆成功");

                //user.ReadImageBuffer();//先把图片读出来
            }
        }
示例#7
0
        //注册
        public void do1002(MessageNode node)
        {
            ClientNode client = node.socket;
            ByteBuffer buff   = node.buffer;

            string name = buff.readString();

            if (g.ContansUser(name) || FFactory.Exists(Share.USER_SAVE_PATH + name))
            {
                //存在
                client.send(ConstomMessage.getError("用户名已存在"));
                client = null;
                return;
            }
            string chinaName = buff.readString();
            string sex       = buff.readString();
            int    age       = buff.readInt();
            string pwd       = buff.readString();

            User user = new User(name, chinaName, sex, age, pwd);
            //是否有图片上传
            int im = buff.readInt();

            if (im > 0)
            {
                string imgExt  = buff.readString();
                string imgName = name + this.getImageName() + imgExt;
                user.Image = imgName;
                ByteBuffer imgbs = buff.readBuffer();
                FFactory.SaveObject(Share.USER_SAVE_IMAGE_PATH + imgName, imgbs.getBuffer());
            }
            FFactory.SaveObject(Share.USER_SAVE_PATH + name, user);
            //g.addUser(user);

            debug.logln("用户注册成功 : " + name + " 密码: " + pwd);
            ByteBuffer buf = ByteBuffer.CreateByteBufferType(Protcol.用户注册);

            //buf.writeInt(Protcol.用户注册);
            //buf.writeInt(1);
            client.send(buf);
        }
示例#8
0
        public void setRoomPassword(int roomId, User user, string pwd)
        {
            Room r = this.rooms[roomId];

            if (!user.roomOwner)
            {
                user.Send(ConstomMessage.getError("你不是房主,不能设置密码"));
                return;
            }
            if (r.getRoomState() == 1)
            {
                user.Send(ConstomMessage.getError("游戏正在进行中,不能设置房间密码"));
                return;
            }
            if (!r.Contains(user))
            {
                user.Send(ConstomMessage.getError("警告:只能设置自己所在房间的密码!"));
                return;
            }
            r.Password = pwd;
            user.Send(ConstomMessage.getError("房间密码成功设置为:[" + pwd + "]请牢记"));
        }