If QQClient.Ready Then
QQClient.Stop()
End If
QQClient.ServerIP = e.Form.Controls("tbxIp").text '指定服务器IP地址
QQClient.ServerPort = e.Form.Controls("tbxPort").text '指定服务器登录端口
QQClient.UserName = e.Form.Controls("tbxName").text
QQClient.Password = e.Form.Controls("tbxPassword").text
If QQClient.Start() = True '如果登录成功
Dim msg As String = "恭喜,OpenQQ登录成功!"
If QQClient.ServerMessage > "" Then '如果服务器返回了欢迎信息
msg = msg & QQClient.ServerMessage
End If
PopMessage(msg,"提示",PopiconEnum.Infomation,5)
Else '如果登录失败,显示服务器返回错误信息
PopMessage("QQClient登录失败,原因:" & vbcrlf & QQClient.ServerMessage,"提示",PopiconEnum.Error,5)
End If
e.Form.Close()
这是客户端代码
下面是服务器代码:
'======================启动OpenQQService
If QQServer.Ready Then
QQServer.Stop
End If
QQServer.ServerIp = Functions.Execute("Get","OpenQQService",0) '指定IP地址
QQServer.ServerPort = Functions.Execute("Get","OpenQQService",1) '指定登录端口
QQServer.HeartbeatInterval = Functions.Execute("Get","OpenQQService",4) '指定心跳时间
QQServer.HeartbeatTimeout = Functions.Execute("Get","OpenQQService",3) '指定心跳超时时间
QQServer.PortRange = Functions.Execute("Get","OpenQQService",2) '指定随机端口范围
QQServer.Start()
下面是登录监听代码:
Dim dr As DataRow
dr = DataTables("Users").Find("userid = '" & e.UserName & "'")
If dr Is Nothing Then '判断此用户不存在
e.Message = "用户Id错误!" '返回给登录者的提示信息
Return
End If
If dr("OpenQQ密码") <> e.Password Then '如果密码错误
e.Message = "登录密码错误!" '返回给登录者的提示信息
Return
End If
e.Success = True '允许用户登录
'添加所有同事为好友
For Each dr2 As DataRow In DataTables("Users").DataRows
Dim nm As String = dr2("userid")
If nm <> e.UserName Then '如果不是登录者本人
e.Buddies.Add(nm)
End If
Next
下面是接收消息代码:
Output.Show(e.Message)
Dim s() As String=e.Message.split("@")
If s(0)="T" Then
Dim result() As String=s(1).Split("|")
Dim name As String=result(0)
Dim dr As DataRow=DataTables("Users").Find("name='" & name & "'")
If dr IsNot Nothing Then
dr(result(1))=result(2)
End If
dr.save()
dr.Load()
End If