|
static int id = 1;
// 用户身份验证回调函数定义
// 根据函数返回值决定是否验证身份成功,当返回0时,必须分配一个唯一的userid
public static int OnVerifyUserCallBack(string userName, string password, ref int userID, ref int userLevel, IntPtr nickName, int len, int userValue)
{
SQLiteHelper db = new SQLiteHelper();
SQLiteDataReader loginInfo = db.Read("select loginPwd,nickName,online,HYID,SFZC,HYM from userInfo where loginName = @loginName", new SQLiteParameter("@loginName", userName));
String pwd = "";
String trueName = "";
int online = 0;
while (loginInfo.Read())
{
pwd = loginInfo.GetString(0);
trueName = loginInfo.GetString(1);
online = loginInfo.GetInt32(2);
}
db.Close();
if ((pwd).Equals(password) && online == 0)
{
userID = id;
id = id + 1;
// 返回一个用户的昵称,若为空,则核心服务器会用userName来替代
//byte[] toBytes = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("gb2312"), Encoding.UTF8.GetBytes(trueName));
// Marshal.Copy(toBytes, 0, nickName, toBytes.Length);
db.Exc("Update userInfo set online = @userId where loginName = @loginName", new SQLiteParameter[] { new SQLiteParameter("@userId", userID), new SQLiteParameter("@loginName", userName) });
return 0;
}
else if (online != 0)
{
return 100;
}
else
{
return 200;
}
// 用户登录成功回调函数定义
public static void OnUserLoginActionCallBack(int userId, string userName, int level, string addr, int userValue)
{
if (OnUserLoginActionReceived != null)
{
OnUserLoginActionReceived(userId, userName, level, addr, userValue);
SQLiteHelper db = new SQLiteHelper();
SQLiteDataReader loginInfo = db.Read("select HYID,SFZC,HYM from userInfo where loginName = @loginName", new SQLiteParameter("@loginName", userName));
int mHYID = -1;
int mSFZC = -1;
String mHYM = "";
while (loginInfo.Read())
{
mHYID = loginInfo.GetInt32(0);
mSFZC = loginInfo.GetInt32(1);
mHYM = loginInfo.GetString(2);
}
db.Close();
SQLiteHelper db1 = new SQLiteHelper();
SQLiteDataReader loginInfo1 = db1.Read("select loginName from userInfo where HYID = @HYID and SFZC=1", new SQLiteParameter("@HYID", mHYID));
string muserName = "";
while (loginInfo1.Read())
{
muserName = loginInfo1.GetString(0);
}
db1.Close();
string FS = mHYID.ToString() + ":" + mSFZC.ToString() + ":" + mHYM + ":" + muserName;
byte[] bytes = System.Text.Encoding.Default.GetBytes(FS);
int ret = AnyChatServerSDK.BRAS_TransBuffer(userId, bytes, bytes.Length);
}
}
// 返回一个用户的昵称,若为空,则核心服务器会用userName来替代
//byte[] toBytes = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("gb2312"), Encoding.UTF8.GetBytes(trueName));
// Marshal.Copy(toBytes, 0, nickName, toBytes.Length);
想显示昵称,把这个注释去掉之后,后面登录成功回调函数里访问数据库就不行了,while (loginInfo.Read())里面的不执行,Marshal.Copy(toBytes, 0, nickName, toBytes.Length)这句怎么改啊,没有这句后面执行都正常
|
|