📄 usermodel.pas
字号:
unit usermodel;
interface
uses SysUtils,windows,model;
type
tusermodel=class(Tmodel)
private
procedure search_user(params:string);
procedure online_status(params:string);
procedure getfirendinfo(params:string);
procedure changefirendinfo(params:string);
public
procedure process(params:string);override;
end;
implementation
uses shareunit,constunt,udpcores,structureunt;
//------------------------------------------------------------------------------
// 处理对方发来的搜索消息,处理对方回应的搜索消息
//------------------------------------------------------------------------------
procedure tusermodel.search_user(params:string);
var operid,msg:string;
tmp:userinfo;
begin
operid:=getparamitem(params,'operation');
case strtointdef(operid,xy_unknow) of
xy_finder:
begin
tmp:=udpcore.user.getuserinfoex(0);
makeparamsex(msg,'msgid',xy_user);
makeparamsex(msg,'funid',xy_search);
makeparamsex(msg,'operation',xy_responses);
makeparamsex(msg,'md5name',tmp.md5name);
makeparamsex(msg,'userid',tmp.userid);
makeparamsex(msg,'uname',tmp.uname);
makeparamsex(msg,'tel',tmp.tel);
makeparamsex(msg,'dept',tmp.dept);
makeparamsex(msg,'business',tmp.business);
makeparamsex(msg,'checkup',tmp.checkup);
udpcore.sendtoip(getparamitem(params,'fromip'),
getparamitem(params,'fromport'),msg);
end;
xy_responses:
begin
expandmemo.Add(params);
postmessage(search_hwnd,refresh_status,xy_adding,0);
end;
xy_adding:
begin
tmp:=udpcore.user.getuserinfoex(0);
if tmp.checkup=0 then
begin
expandmemo.Add(params);
udpcore.user.adduser(params);
postmessage(main_hwnd,refresh_status,xy_refresh_user_status,0);
msg:='';
makeparamsex(msg,'msgid',xy_showadmsgform);
makeparamsex(msg,'msgtext','用户 '+getparamitem(params,'uname')+' 已经成功将您添加为好友!');
makeparamsex(msg,'autoclose',true);
expandmemo.add(msg);
postmessage(main_hwnd,refresh_status,xy_showadmsgform,0);
end;
if tmp.checkup=1 then
begin
msg:='';
makeparamsex(msg,'msgid',xy_showpromptform);
makeparamsex(msg,'msgtext','身份验证-请求加为好友');
makeparamsex(msg,'paramsex',params);
expandmemo.add(msg);
postmessage(main_hwnd,refresh_status,xy_showpromptform,0);
end;
end;
xy_passing:
begin
udpcore.user.adduser(params);
expandmemo.Add(params);
postmessage(main_hwnd,refresh_status,xy_refresh_user_status,0);
msg:='';
makeparamsex(msg,'msgid',xy_showadmsgform);
makeparamsex(msg,'msgtext','您已经成功将 '+getparamitem(params,'uname')+' 添加为好友!');
makeparamsex(msg,'autoclose',true);
expandmemo.add(msg);
postmessage(main_hwnd,refresh_status,xy_showadmsgform,0);
end;
xy_refuseing:
begin
msg:='';
makeparamsex(msg,'msgid',xy_showadmsgform);
makeparamsex(msg,'msgtext','用户 '+getparamitem(params,'uname')+' 拒绝了您的请求,不允许添加为好友!');
makeparamsex(msg,'autoclose',true);
expandmemo.add(msg);
postmessage(main_hwnd,refresh_status,xy_showadmsgform,0);
end;
xy_unknow:logmemo.add('unknow:'+params);
end;
end;
procedure tusermodel.online_status(params:string);
var operid,msg,firendid:string;
tmp,myinfo:userinfo;
begin
operid:=getparamitem(params,'operation');
firendid:=getparamitem(params,'md5name');
if udpcore.user.checkuser(firendid) then
begin
tmp:=udpcore.user.getuserinfoex(firendid);
tmp.status:=strtoint(getparamitem(params,'status'));
udpcore.user.modifyuser(firendid,tmp);
myinfo:=udpcore.user.getuserinfoex(0);
expandmemo.Add(params);
case strtointdef(operid,xy_unknow) of
xy_login:
begin
makeparamsex(msg,'msgid',xy_user);
makeparamsex(msg,'funid',xy_status);
makeparamsex(msg,'operation',xy_responses);
makeparamsex(msg,'md5name',myinfo.md5name);
makeparamsex(msg,'status',myinfo.status);
udpcore.sendtoip(getparamitem(params,'fromip'),msg);
if showupdownhint then
begin
msg:='';
makeparamsex(msg,'msgid',xy_showadmsgform);
makeparamsex(msg,'msgtext','用户 '+tmp.uname+' 上线了!');
makeparamsex(msg,'autoclose',true);
expandmemo.add(msg);
postmessage(main_hwnd,refresh_status,xy_showadmsgform,0);
end;
end;
xy_responses:
begin
//---------------
end;
xy_logout:
begin
if showupdownhint then
begin
msg:='';
makeparamsex(msg,'msgid',xy_showadmsgform);
makeparamsex(msg,'msgtext','用户 '+tmp.uname+' 下线了!');
makeparamsex(msg,'autoclose',true);
expandmemo.add(msg);
postmessage(main_hwnd,refresh_status,xy_showadmsgform,0);
end;
end;
end;
postmessage(main_hwnd,refresh_status,xy_refresh_user_status,0);
end;
end;
procedure tusermodel.getfirendinfo(params:string);
var msg:string;
tmp:userinfo;
begin
tmp:=udpcore.user.getuserinfoex(0);
makeparamsex(msg,'msgid',xy_user);
makeparamsex(msg,'funid',xy_infor);
makeparamsex(msg,'md5pic',tmp.md5pic);
makeparamsex(msg,'md5name',tmp.md5name);
makeparamsex(msg,'tel',tmp.tel);
makeparamsex(msg,'dept',tmp.dept);
makeparamsex(msg,'business',tmp.business);
makeparamsex(msg,'mytext',tmp.mytext);
udpcore.sendtoip(getparamitem(params,'fromip'),getparamitem(params,'fromport'),msg);
end;
procedure tusermodel.changefirendinfo(params:string);
var tmp:userinfo;
firendid:string;
begin
firendid:=getparamitem(params,'md5name');
tmp:=udpcore.user.getuserinfoex(firendid);
tmp.md5pic:=getparamitem(params,'md5pic');
tmp.tel:=getparamitem(params,'tel');
tmp.dept:=getparamitem(params,'dept');
tmp.business:=getparamitem(params,'business');
tmp.mytext:=getparamitem(params,'mytext');
udpcore.user.modifyuser(firendid,tmp);
if tmp.dlghwnd<>0 then
postmessage(tmp.dlghwnd,refresh_status,xy_infor,0);
end;
//------------------------------------------------------------------------------
// 处理所有用户有关的消息
//------------------------------------------------------------------------------
procedure tusermodel.process(params:string);
var funid:string;
begin
funid:=getparamitem(params,'funid');
case strtointdef(funid,xy_unknow) of
xy_search:search_user(params);
xy_status:online_status(params);
xy_detail:getfirendinfo(params);
xy_infor:changefirendinfo(params);
xy_unknow:logmemo.add('unknow:'+params);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -