/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct PlugFileTransfer = [ PFT_instance : PInstance, PFT_netcomm : NetComm, PFT_bSecure : I ]mkPlugFileTransfer;; fun deleteOb(inst, constr)= 0;; fun cbReceivedMessage(inst, netstr, userstr, cmd, message, arg, constr)= if (strcmp cmd strtoweb (getPluginInstanceName inst)) then nil else ( netGetFile netstr userstr if (constr.PFT_bSecure) then (iComFlagDefault|iComFlagAES) else nil (strcat strtoweb (getPluginInstanceName inst) "_file") message; SendPluginEvent inst "Request file" message nil; ); 0;; fun cbReceivedPrivateMessage(inst, netstr, userstr, cmd, message, arg, constr)= if (strcmp cmd strtoweb (getPluginInstanceName inst)) then nil else ( netGetFile netstr userstr if (constr.PFT_bSecure) then (iComFlagDefault|iComFlagAES) else nil (strcat strtoweb (getPluginInstanceName inst) "_file") message; SendPluginEvent inst "Request file" message nil; ); 0;; fun cbGetFile(inst, netstr, userstr, cmd, data, path, constr)= if (strcmp cmd (strcat strtoweb (getPluginInstanceName inst) "_file")) then nil else ( _storepack data path; SendPluginEvent inst "Received file" path nil; ); 0;; fun cbSendFile(inst, from, action, param, reply, constr)= if ((_checkpack param) == nil) then nil else ( if (constr.PFT_bSecure) then netSendBroadMessageSecure constr.PFT_netcomm strtoweb (getPluginInstanceName inst) param 0 else netSendBroadMessage constr.PFT_netcomm strtoweb (getPluginInstanceName inst) param 0; ); 0;; fun cbSendPrivateFile(inst, from, action, param, reply, constr)= let strfind " " param 0 -> pos in let atoi substr param 0 pos -> uid in let netGetUserById constr.PFT_netcomm uid -> userstr in let substr param (pos + 1) ((strlen param) - pos) -> path in if ((_checkpack path) == nil) then nil else ( if (constr.PFT_bSecure) then netSendPrivateMessageSecure constr.PFT_netcomm userstr strtoweb (getPluginInstanceName inst) path else netSendPrivateMessage constr.PFT_netcomm userstr strtoweb (getPluginInstanceName inst) path; ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "secure") -> secure in let if secure == nil then 1 else secure -> secure in let mkPlugFileTransfer [inst netcomOS3D secure] -> constr in ( setPluginInstanceCbNetUserMessage inst mkfun7 @cbReceivedMessage constr; setPluginInstanceCbNetUserPrivateMessage inst mkfun7 @cbReceivedPrivateMessage constr; setPluginInstanceCbNetGetFile inst mkfun7 @cbGetFile constr; PluginRegisterAction inst "Send file" mkfun6 @cbSendFile constr; PluginRegisterAction inst "Send private file" mkfun6 @cbSendPrivateFile constr; setPluginInstanceCbDel inst mkfun2 @deleteOb constr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;