Example #1
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();//先把图片读出来
            }
        }
Example #2
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);
        }