Ejemplo n.º 1
0
        public byte[] Init(Stream inputStream, string httpMethod, string user_id)
        {
            byte[] bytes = new byte[inputStream.Length];
            inputStream.Read(bytes, 0, bytes.Length);

            inputStream.Seek(0, SeekOrigin.Begin);

            object obj = SerializationHelper.Deserialize(NetMessageDef.ResponseGetRole, bytes);

            protos.Login.RequestCreateRole requestCreateRole = obj as protos.Login.RequestCreateRole;

            protos.ReturnMessage.ResDefaultInfo resInfo = new protos.ReturnMessage.ResDefaultInfo();

            if (string.IsNullOrEmpty(requestCreateRole.user_name))
            {
                resInfo.results = 0;
                resInfo.details = "昵称不能为空";
            }

            Model.Users mUser = new BLL.Users().GetModel(user_id);

            if (mUser != null)
            {
                mUser.UserName  = requestCreateRole.user_name;
                resInfo.results = 2;
                resInfo.details = "创建角色成功";
            }
            else
            {
                resInfo.results = 0;
                resInfo.details = "账号不存在";
            }

            return(SerializationHelper.Serialize(new MuffinMsg(NetMessageDef.ResponseReturnDefaultInfo, resInfo)));
        }
Ejemplo n.º 2
0
        public byte[] Init(Stream inputStream, string httpMethod, uint user_id)
        {
            byte[] bytes = new byte[inputStream.Length];
            inputStream.Read(bytes, 0, bytes.Length);

            //设置当前流的位置为流的开始
            inputStream.Seek(0, SeekOrigin.Begin);

            object obj = SerializationHelper.Deserialize(NetMessageDef.RequestLogin, bytes);

            protos.Login.RequestLogin requestLogin = new protos.Login.RequestLogin();

            protos.ReturnMessage.ResDefaultInfo resInfo = new protos.ReturnMessage.ResDefaultInfo();

            if (string.IsNullOrEmpty(requestLogin.account))
            {
                resInfo.results = 0;
                resInfo.details = "账号不能为空";
            }
            else if (string.IsNullOrEmpty(requestLogin.password))
            {
                resInfo.results = 0;
                resInfo.details = "密码不能为空";
            }

            Model.Users userModle = new BLL.Users().GetModel(requestLogin.account, requestLogin.password);
            if (userModle != null)
            {
                resInfo.results = 1;
                resInfo.details = userModle.ID.ToString();
            }
            else
            {
                resInfo.results = 0;
                resInfo.details = "账号或密码错误";
            }

            return(SerializationHelper.Serialize(new MuffinMsg(NetMessageDef.ResponseReturnDefaultInfo, resInfo)));
        }
Ejemplo n.º 3
0
        public byte[] Init(Stream inputStream, string httpMethod, uint user_id)
        {
            byte[] bytes = new byte[inputStream.Length];

            inputStream.Read(bytes, 0, bytes.Length);
            //设置当前流的位置为流的开始
            inputStream.Seek(0, SeekOrigin.Begin);

            object obj = SerializationHelper.Deserialize(NetMessageDef.RequestCreateAccount, bytes);

            protos.Login.RequestCreateAccount requestCreateAccount = obj as protos.Login.RequestCreateAccount;

            protos.ReturnMessage.ResDefaultInfo resInfo = new protos.ReturnMessage.ResDefaultInfo();

            if (string.IsNullOrEmpty(requestCreateAccount.account))
            {
                resInfo.results = 0;
                resInfo.details = "账号不能为空";
            }
            else if (string.IsNullOrEmpty(requestCreateAccount.password))
            {
                resInfo.results = 0;
                resInfo.details = "密码不能为空";
            }

            if (new BLL.Users().ExistsAcc(requestCreateAccount.account))
            {
                resInfo.results = 0;
                resInfo.details = "账号已存在";
            }
            else
            {
                Model.Users newUser = new Model.Users();
                newUser.UserAccount   = requestCreateAccount.account;
                newUser.UserPassworld = requestCreateAccount.password;
                newUser.RegTime       = DateTime.Now;
                newUser.LoginTime     = DateTime.Now;
                newUser.Endurance     = 100;
                newUser.Exp           = 0;
                newUser.Gold          = 1000;
                newUser.Head          = "";
                newUser.Lv            = 1;
                newUser.UserName      = "";
                newUser.Vip           = 0;
                newUser.Wing          = 0;


                if (new BLL.Users().Add(newUser) > 0)
                {
                    resInfo.results = 2;
                    resInfo.details = "注册成功";
                }
                else
                {
                    resInfo.results = 0;
                    resInfo.details = "注册失败";
                }
            }

            return(SerializationHelper.Serialize(new MuffinMsg(NetMessageDef.ResponseReturnDefaultInfo, resInfo)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 序列化成proto
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static byte[] Serialize(MuffinMsg msg)
        {
            switch (msg.cmdId)
            {
            case NetMessageDef.RequestLogin:
            {
                protos.Login.RequestLogin request = msg.pBObject as protos.Login.RequestLogin;
                MemoryStream memStream            = new MemoryStream();
                ProtoBuf.Serializer.Serialize <protos.Login.RequestLogin>(memStream, request);
                byte[] x = memStream.ToArray();
                memStream.Close();
                return(x);
            }

            case NetMessageDef.RequestCreateAccount:
            {
                protos.Login.RequestCreateAccount request = msg.pBObject as protos.Login.RequestCreateAccount;
                MemoryStream memStream = new MemoryStream();
                ProtoBuf.Serializer.Serialize <protos.Login.RequestCreateAccount>(memStream, request);
                byte[] x = memStream.ToArray();
                memStream.Close();
                return(x);
            }

            case NetMessageDef.RequestGetRole:
            {
                protos.Login.RequestGetRole request = msg.pBObject as protos.Login.RequestGetRole;
                MemoryStream memStream = new MemoryStream();
                ProtoBuf.Serializer.Serialize <protos.Login.RequestGetRole>(memStream, request);
                byte[] x = memStream.ToArray();
                memStream.Close();
                return(x);
            }

            case NetMessageDef.ResponseGetRole:
            {
                protos.Login.ResponseGetRole request = msg.pBObject as protos.Login.ResponseGetRole;
                MemoryStream memStream = new MemoryStream();
                ProtoBuf.Serializer.Serialize <protos.Login.ResponseGetRole>(memStream, request);
                byte[] x = memStream.ToArray();
                memStream.Close();
                return(x);
            }

            case NetMessageDef.ResponseReturnDefaultInfo:
            {
                protos.ReturnMessage.ResDefaultInfo request = msg.pBObject as protos.ReturnMessage.ResDefaultInfo;
                MemoryStream memStream = new MemoryStream();
                ProtoBuf.Serializer.Serialize <protos.ReturnMessage.ResDefaultInfo>(memStream, request);
                byte[] x = memStream.ToArray();
                memStream.Close();
                return(x);
            }

            case NetMessageDef.RequestGetFriendList:
            {
                protos.friend.ReqGetFriendList request = msg.pBObject as protos.friend.ReqGetFriendList;
                MemoryStream memStream = new MemoryStream();
                ProtoBuf.Serializer.Serialize <protos.friend.ReqGetFriendList>(memStream, request);
                byte[] x = memStream.ToArray();
                memStream.Close();
                return(x);
            }

            case NetMessageDef.ResponseFriendList:
            {
                protos.friend.ResFriendList request = msg.pBObject as protos.friend.ResFriendList;
                MemoryStream memStream = new MemoryStream();
                ProtoBuf.Serializer.Serialize <protos.friend.ResFriendList>(memStream, request);
                byte[] x = memStream.ToArray();
                memStream.Close();
                return(x);
            }

            default:
            {
                Console.WriteLine("MuffinMsg.Serialize: unhandled cmdId->" + msg.cmdId.ToString());
                return(null);
            }
            }
        }