Example #1
0
        public void DoAccLogin(Conn client, byte[] buff)
        {
            MemoryStream ms  = new MemoryStream(buff);
            Account      acc = Serializer.Deserialize <Account>(ms);

            LogUtil.LogInfo(string.Format("收到登陆消息,账号:{0}  密码:{1}", acc.acc, acc.pwd));

            if (dicAccouts.ContainsKey(acc.acc))
            {
                var tmpAcc = dicAccouts[acc.acc];
                if (tmpAcc.pwd == acc.pwd)
                {
                    client.Send((ushort)MainID.Lobby, (ushort)LobbyID.LoginSuccess, tmpAcc);
                }
                else
                {
                    client.Send((ushort)MainID.Lobby, (ushort)LobbyID.LoginFaiure, "用户密码错误。");
                }
            }
            else
            {
                string  cmd      = string.Format("select * from accounts where acc = '{0}' ", acc.acc);
                var     sqlDatas = SqlManager.Ins.SqlSelect(cmd);
                var     data     = sqlDatas[0];
                Account sendacc  = new Account();
                sendacc.acc      = (string)data["acc"];
                sendacc.pwd      = "";
                sendacc.nickname = "";
                sendacc.id       = (int)data["id"];
                sendacc.roomid   = (int)data["roomid"];
                LogUtil.LogInfo(string.Format("id:{0} roomid:{1}", sendacc.id, sendacc.roomid));
                client.Send((ushort)MainID.Lobby, (ushort)LobbyID.LoginSuccess, sendacc);
            }
        }
Example #2
0
        public void DoAccRegister(Conn client, byte[] buff)
        {
            MemoryStream ms  = new MemoryStream(buff);
            Account      acc = Serializer.Deserialize <Account>(ms);

            LogUtil.LogInfo(string.Format("收到注册消息,账号:{0}  密码:{1}", acc.acc, acc.pwd));

            if (dicAccouts.ContainsKey(acc.acc))
            {
                client.Send((ushort)MainID.Lobby, (ushort)LobbyID.RegisterFailure, "账号创建失败:已存在。");
            }
            else
            {
                string cmd = string.Format("select * from accounts where acc = '{0}' ", acc.acc);
                if (SqlManager.Ins.SqlMatch(cmd))
                {
                    client.Send((ushort)MainID.Lobby, (ushort)LobbyID.RegisterFailure, "账号创建失败:已存在。");
                }
                else
                {
                    //数据库不存在,插入
//                    string cmd1 = string.Format("insert into accounts(acc,pwd) values('{0}','{1}')", acc.acc, acc.pwd);
//                    acc.id = SqlManager.Ins.SqlInsert(cmd1);
//                    dicAccouts.Add(acc.acc, acc);

                    System.Threading.Thread chThread = new System.Threading.Thread(ThradSavePng);
                    chThread.Start(acc);
                }
            }
        }