⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugin.pas

📁 絮语2007视频聊天软件源程序.仅供参考
💻 PAS
字号:
unit plugin;

interface

uses

  Windows,Sysutils,classes,inifiles,menus,structureunt;
  
type
  Tplug=class
      constructor Create;
      destructor  Destroy;override;
    private
      pluglist:array of Tpluginfo;
      procedure searchplug;
      function getplugnametoid(s:String):integer;
      function getpluginfoex(s:string):Tpluginfo; overload;
      function getpluginfoex(n:integer):Tpluginfo; overload;
      procedure pluginclick(sender:tobject);
    public
      procedure addpluglist(tmpmenu:tmenuitem);
      procedure pluginrequest_accept(userid,s:string;bool:boolean);
  end;

implementation
uses udpcores,shareunit,constunt;
//------------------------------------------------------------------------------
// 返回插件
//------------------------------------------------------------------------------
function Tplug.getplugnametoid(s:String):integer;
var i:integer;
begin
result:=0;
for i:=low(pluglist) to high(pluglist) do
 if pluglist[i].PlugInName=s then
    begin
    result:=i+1;
    break;
    end;
end;

function tplug.getpluginfoex(n:integer):Tpluginfo;
begin
result:=pluglist[n];
end;

function tplug.getpluginfoex(s:string):Tpluginfo;
var n:integer;
begin
n:=getplugnametoid(s);
if n>0 then result:=getpluginfoex(n-1);
end;

//------------------------------------------------------------------------------
// 载入游戏
//------------------------------------------------------------------------------
procedure tplug.pluginrequest_accept(userid,s:string;bool:boolean);
var x,y,path,params:string;
    tmp:Tpluginfo;
    myinfo,youinfo:userinfo;
begin
if getplugnametoid(s)>0 then
   begin
    path:=extractfilepath(application_name);
    myinfo:=udpcore.user.getuserinfoex(0);
    youinfo:=udpcore.user.getuserinfoex(userid);
    tmp:=getpluginfoex(s);
    if bool then
       begin
       x:=path+'plugin\'+tmp.ClientExeName;
       params:=tmp.ClientParam;
       end else begin
       x:=path+'plugin\'+tmp.ServerExeName;
       params:=tmp.ServerParam;
       end;
    y:=changefileext(extractfilename(x),'');
    if pos('%myip',params)>0 then x:=x+' '+myinfo.localip;
    if pos('%myuin',params)>0 then x:=x+' '+myinfo.md5name;
    if pos('%mynick',params)>0 then x:=x+' '+myinfo.uname;
    if pos('%yourip',params)>0 then x:=x+' '+youinfo.localip;
    if pos('%youruin',params)>0 then x:=x+' '+youinfo.md5name;
    if pos('%yournick',params)>0 then x:=x+' '+youinfo.uname;

    if findwindow(nil,pchar(y))=0 then winexec(pchar(x),1);
    if not bool then
       begin
       params:='';
       makeparamsex(params,'msgid',xy_game);
       makeparamsex(params,'funid',xy_request);
       makeparamsex(params,'gamename',s);
       makeparamsex(params,'messageex','邀请加入 '+s+' 游戏?');
       makeparamsex(params,'userid',myinfo.userid);
       makeparamsex(params,'uname',myinfo.uname);
       makeparamsex(params,'md5name',myinfo.md5name);
       udpcore.sendtoip(youinfo.localip,params);
       end;
   end;
end;

//------------------------------------------------------------------------------
// 载入游戏插件列表
//------------------------------------------------------------------------------
procedure Tplug.searchplug;
var path:string;
    i,p:integer;
    memos:tstringlist;
begin
path:=extractfilepath(application_name);
memos:=tstringlist.create;
try
findfile(path+'plugin\',memos,false);
if memos.count>0 then
 begin
  for i:=1 to memos.count do
  if lowercase(extractfileext(memos.strings[i-1]))='.ini' then
    begin
    p:=high(pluglist)+1;
    setlength(pluglist,p+1);
    with tinifile.Create(memos.strings[i-1]) do
      try
      pluglist[p].PlugInName:=readstring('info','PlugInName','');
      pluglist[p].ServerExeName:=readstring('info','ServerExeName','');
      pluglist[p].ServerParam:=readstring('info','ServerParam','');
      pluglist[p].ClientExeName:=readstring('info','ClientExeName','');
      pluglist[p].ClientParam:=readstring('info','ClientParam','');
      finally
      free;
      end;
    end;
 end;
finally
freeandnil(memos);
end;
end;


//------------------------------------------------------------------------------
//plug click
//------------------------------------------------------------------------------
procedure tplug.pluginclick(sender:tobject);
var s:string;
begin
s:=tmenuitem(sender).hint;
pluginrequest_accept(cur_seluser,s,false);
end;

//------------------------------------------------------------------------------
// 将plug 列表加入到指定 menu
//------------------------------------------------------------------------------
procedure tplug.addpluglist(tmpmenu:tmenuitem);
var tmp:tmenuitem;
    i:integer;
begin
if high(pluglist)>0 then
for i:=high(pluglist) downto low(pluglist) do
  begin //添加插件菜单...
  tmp:=tmenuitem.create(nil);
  tmp.hint:=pluglist[i].PlugInName;
  tmp.caption:=pluglist[i].PlugInName;
  tmp.OnClick:=pluginclick;
  tmpmenu.add(tmp);
  end;
end;

//------------------------------------------------------------------------------
// 创建 plug
//------------------------------------------------------------------------------
constructor Tplug.Create;
begin
 searchplug;
end;

//------------------------------------------------------------------------------
// 释放 plug
//------------------------------------------------------------------------------
destructor Tplug.Destroy;
begin
  pluglist:=nil;
  inherited Destroy;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -