|
业务服务器从数据库里读取数据,验证用户名、密码,及通过透明通道向客户端发送会议ID(roomId)、是否主持人、会议名称
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;
string mHYID = "";
string mSFZC = "";
string mHYM = "";
while (loginInfo.Read())
{
pwd = loginInfo.GetString(0);
trueName = loginInfo.GetString(1);
online = loginInfo.GetInt32(2);
mHYID = loginInfo.GetInt32(3).ToString();
mSFZC = loginInfo.GetInt32(4).ToString();
mHYM = loginInfo.GetString(5);
}
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) });
//像客户端发送roomId等信息
string FS = mHYID + ":" + mSFZC + ":" + mHYM;
byte[] bytes = System.Text.Encoding.Default.GetBytes(FS);
AnyChatServerSDK.BRAS_TransBuffer(userID, bytes, bytes.Length);
return 0;
}
else if (online != 0)
{
return 100;
}
else
{
return 200;
}
db.Close();
客户端在frmRoom的
void InitChat()
{
....
SystemSetting.TransBuffer_OnReceive = new TransBufferReceivedHandler(TransBuffer_CallBack);//透明通道传输回调
....
StringBuilder userName = new StringBuilder(30);
int ret = AnyChatCoreSDK.GetUserName(m_myUserID, userName, 30);
myName = userName.ToString();
AnyChatCoreSDK.EnterRoom(m_RoomID, "", 0);
}
public void TransBuffer_CallBack(int userId, IntPtr buf, int len, int userValue)
{
string m_Command = Marshal.PtrToStringAnsi(buf);
try
{
if (m_Command.Length > 3)
{
string[] m_Packet = m_Command.Split(":".ToCharArray());
m_RoomID = int.Parse(m_Packet[0]);
SFZC = int.Parse(m_Packet[1]);
HYM = m_Packet[2];
}
}
catch (Exception ex)
{
}
}
为什么TransBuffer_CallBack函数不执行,不起作用
|
|