home *** CD-ROM | disk | FTP | other *** search
/ Treasure Hunt 2001 PRESSKIT / TH2001_PRESSKIT.iso / demo / scol_install / Partition / comm / comutron1.pkg < prev    next >
Encoding:
Text File  |  2000-10-17  |  12.6 KB  |  507 lines

  1. /* Comutron1.pkg */
  2.  
  3. typeof server=Srv;; 
  4. typeof serverenv=Env;; 
  5. typeof Serverenv=Env;; 
  6. typeof roomenv=Env;; 
  7. typeof APIchn=Chn;; 
  8. typeof MainChn=Chn;; 
  9. typeof Lines=[Chn r1];; 
  10. typeof SLines=[S r1];; 
  11. typeof mainw=ObjWin;; 
  12. typeof address=ObjText;; 
  13. typeof connectbtn=ObjButton;; 
  14. typeof mainstatus=ObjText;; 
  15. typeof mainmenu=ObjMenu;; 
  16. typeof filemenu=ObjMenu;; 
  17. typeof littlefont=ObjFont;; 
  18. typeof mediumfont=ObjFont;; 
  19. typeof bigfont=ObjFont;; 
  20. typeof searchdns=ObjCheck;; 
  21. typeof nickname=ObjText;; 
  22. typeof chatroom=ObjCheck;; 
  23. typeof book=[S r1];; 
  24.  
  25. var NickName="Nick";; 
  26. var packsusers=["Comm/recon.bmp" 3 0]:: ["Comm/recoff.bmp" 3 0]:: ["Comm/playon.bmp" 3 0]
  27.              ::["Comm/playoff.bmp" 3 0]:: ["Comm/playmute.bmp" 3 0]:: ["locked/lib/const.pkg" 7 0]
  28.              ::["Comm/comapi.pkg" 2 0]:: ["Comm/comapi2.pkg" 1 0]:: ["Comm/comapi3.pkg" 3 0]
  29.              ::["Comm/comchat.pkg" 20 0]:: ["Comm/comclient.pkg" 2 0]:: ["Comm/comphone.pkg" 7 0]
  30.              ::["Comm/comroomenv.pkg" 5 0]:: ["Comm/comutron1.pkg" 12 0]:: ["Comm/stdlib.pkg" 2 0]
  31.              ::["Comm/comroom.scol" 1 0]:: ["Comm/scolcomm1.scol" 1 0]::["Comm/redirect.pkg" 1 0]:: nil;; 
  32. var scriptserver="_load \"comm/comclient.pkg\"\n_connected";; 
  33. /*var scriptuser="_load \"locked/lib/const.pkg\"\n_load \"comm/stdlib.pkg\"\n_load \"comm/comutron1.pkg\"\nMain NIL NIL 0\nclientonly \n_connected\n";;*/
  34. var scriptuser="_load \"locked/lib/const.pkg\"\n_load \"comm/stdlib.pkg\"\n_load \"comm/redirect.pkg\"\nmain ";;
  35. var PortComutron=1290;; 
  36. var Address="";; 
  37. var ChatRoom=0;; 
  38. var APIconnect=0;; 
  39.  
  40. defcom loadscr=_load S;; 
  41. defcom mainscr=main S I;; 
  42. defcom status=status S;; 
  43. defcom Cpublic=public S I;; 
  44.  
  45. var _clientonly=0;; 
  46.  
  47. fun cutlist(l,n,s)= 
  48.   if l==nil || n==0 then nil 
  49.   else let l-> [a nxt] in 
  50.   if !strcmp a s then cutlist nxt n s 
  51.   else [a cutlist nxt n-1 s];; 
  52.  
  53. fun rebuildbook(l)= 
  54.   if l==nil then nil 
  55.   else [hd hd l rebuildbook tl l] ;; 
  56.  
  57. fun initbookmarks()= 
  58.   set book=rebuildbook strextr _getpack _checkpack "commark.txt" ;; 
  59.  
  60. fun buildbook(l)= if l==nil then nil 
  61. else [hd l:: nil buildbook tl l] ;; 
  62.  
  63. fun savebookmark()= 
  64.   _fooS strbuild buildbook book; 
  65.   _storepack strbuild buildbook book "commark.txt"; 
  66.   0 ;; 
  67.  
  68. proto Contact=fun [S] I;; 
  69.  
  70. fun MenuGoto (obj,t)= 
  71.   Contact t; 
  72.   0 
  73. };; 
  74.  
  75. fun createback(menu,l) = 
  76.   if l==nil then menu 
  77.   else let l -> [name nxt] in 
  78.     ( 
  79.       _CBmenu (_APPitem _channel menu ME_ENABLED name) @MenuGoto name; 
  80.       createback menu nxt
  81.     ) ;; 
  82.  
  83. proto _addbook=fun [u0 u1] I;; 
  84. proto _removebook=fun [u0 u1] I;; 
  85. proto MenuQuit=fun [u0 u1] I;; 
  86.  
  87. fun createmenus()= 
  88.   let _CRmenu MainChn mainw -> root in 
  89.   ( 
  90.     let _APPpopup MainChn root "File"->filemenu in 
  91.     _CBmenu (_APPitem MainChn filemenu ME_ENABLED "Quit") @MenuQuit 0; 
  92.     createback (_APPpopup MainChn root "Goto History") SLines; 
  93.     let _APPpopup MainChn root "BookMark" -> bookm in 
  94.     (
  95.       _CBmenu (_APPitem MainChn bookm ME_ENABLED "Add Bookmark") @_addbook 0;
  96.       _CBmenu (_APPitem MainChn bookm ME_ENABLED "Remove") @_removebook 0; 
  97.       _APPitem MainChn bookm ME_SEPARATOR ""; 
  98.       createback bookm book 
  99.     ); 
  100.     if mainmenu!=nil then _DSmenu mainmenu 
  101.     else nil; 
  102.     set mainmenu=root 
  103.   ) ;; 
  104.  
  105. fun _addbook(t,x)= 
  106.   let _GETtext address ->s in 
  107.     if s==nil || (strlen s)<1 then 0 
  108.     else 
  109.     (
  110.       set book=[s cutlist book 40 s]; 
  111.       savebookmark; 
  112.       createmenus; 
  113.       0
  114.     );; 
  115.  
  116. fun _removebook(t,x)= 
  117.   set book=cutlist book 40 _GETtext address; 
  118.   savebookmark; createmenus; 
  119.   0;; 
  120.  
  121. fun cutbypoints(l)= 
  122.   if l==nil then [nil nil] 
  123.   else let l -> [a nxt] in 
  124.   if a==': then [nil l] 
  125.   else let cutbypoints nxt -> [x y] in 
  126.     [[a x] y];; 
  127.  
  128. fun isIP(l)= 
  129.   if l==nil then 1 
  130.   else let l -> [a nxt] in 
  131.   if a!='. && (a<'0 || a>'9) then 0 
  132.   else isIP nxt;; 
  133.  
  134. fun isPORT(l)= 
  135.   if l==nil then 1 
  136.   else let l-> [a nxt] in if a<'0 || a>'9 then 0 else isPORT nxt;; 
  137.  
  138. fun mainwpaint (obj,r)= 
  139.   _fooS "MainWindowPaint"; 0 
  140. };; 
  141.  
  142. fun mainwdestroy (obj,r)= 
  143.   _fooS "MainWindowDestroy"; 
  144.   _closemachine 
  145. };; 
  146.  
  147. fun MenuQuit (obj,r)= 
  148.   _closemachine 
  149. };; 
  150.  
  151. fun _status (s)= 
  152.   _ADDtext mainstatus s; 
  153.   LimitText mainstatus 200 10; 
  154. };; 
  155.  
  156. fun IsPort (s)= 
  157.   let (strlen s)-> len in 
  158.   { 
  159.     while (len>0 && (nth_char s (len-1)!=':)) do 
  160.     {
  161.       if ((nth_char s (len-1))==':) then 
  162.       { 
  163.         set len=0; 
  164.         1 
  165.       } 
  166.       else 
  167.       { 
  168.         set len=len-1; 
  169.         0 
  170.       } 
  171.     } 
  172.   } 
  173. };; 
  174.  
  175. fun cmpline(x,c)=
  176.   if x==c then 1 
  177.   else 0;; 
  178.  
  179. fun cmplineIP(x,c)= 
  180.   _status strcat strcat strcat (_channelIP x) " * " c "\n"; 
  181.   if (!strcmp (_channelIP x) c) then 1 
  182.   else 0; 
  183. };;  
  184.  
  185. typeof videoready=S;; 
  186. typeof video=Video;; 
  187. var vx=160;; 
  188. var vy=120;;
  189.  
  190.  
  191. var quality=20;; 
  192. var videoinit=0;; 
  193. var globalframe=0;;
  194.  
  195. fun GetVideo (obj,i,s)= 
  196.   _JCompInit quality;
  197.   set globalframe=globalframe+1;
  198.   let (_c15to32 s)->ss2 in 
  199.   set videoready=_JComp ss2 vx vy 
  200. ;; 
  201.  
  202. fun initvideo ()= 
  203. _fooS "INITVIDEO";
  204.   if (videoinit<=0) then 
  205.   { 
  206.     _fooS "INITVIDEOSTART";
  207. /*    _JCompInit quality; */
  208.     let (atoi _getress "videocapture") -> temp in
  209.     let if temp==nil || temp==-1 then 0 else temp -> vid in
  210.         set video=_CRcapWindow _channel nil vid 100 300 vx vy 1 1000000; 
  211.     if (video!=nil) then _SETcapVideoStart video @GetVideo 0 
  212.     else nil; 
  213.     set videoinit=1
  214.   } 
  215.   else set videoinit=videoinit+1
  216. ;; 
  217.  
  218. fun stopvideo ()= 
  219.   set videoinit=videoinit-1; 
  220.   if (videoinit==0) then _DScapWindow video
  221.   else 
  222.   {
  223.     if (videoinit<0) then set videoinit=0 else 0;
  224.     nil
  225.   };
  226.   0;; 
  227.  
  228. fun _delline (chn)= 
  229.   _fooS "Deleting from list!"; 
  230.   set Lines=deletelist Lines chn; 
  231.   _killchannel chn;   
  232. /*  if _clientonly==1 then _closemachine 
  233.   else nil; */
  234. };; 
  235.  
  236. fun searchline(IP)= 
  237.   search_in_list Lines @cmplineIP IP; 
  238. };; 
  239.  
  240. fun ConnectTo (obj,r)= 
  241.   set Address=_GETtext address; 
  242.   let cutbypoints strtolist Address -> [a b] in 
  243.   { 
  244.   let (if isIP a then listtostr a 
  245.        else 
  246.        (
  247.          _status _fooS strcatn ["looking up host "[listtostr a ["\n" nil]]];
  248.          _gethostbyname listtostr a))-> adip in 
  249.          { 
  250.            if (IsPort listtostr b)==nil then 
  251.            { 
  252.              set adip=strcat strcat adip ":" itoa PortComutron;
  253.              0 
  254.            } 
  255.            else 
  256.            { 
  257.              set adip=strcat strcat adip ":" listtostr tl b;
  258.              0 
  259.            }; 
  260.            _status strcat strcat strcat strcat "Trying " Address " (" adip ")...\n"; 
  261.            _openchannel adip "" Serverenv; 
  262.          } 
  263.        } 
  264.      };; 
  265.               
  266. fun findline (line,ip)= 
  267.   if line==nil then 0 
  268.   else let line->[ch next] in 
  269.     let _channelIP ch->ip2 in 
  270.       if !strcmp ip ip2 then 1 
  271.       else findline next ip;; 
  272.               
  273. fun Contact (Address)= 
  274.   _fooS "Contact...";
  275.   if (findline Lines (_channelIP _channel))!=nil then 
  276.     let cutbypoints strtolist Address -> [a b] in 
  277.     let 
  278.     (
  279.       if isIP a then listtostr a 
  280.       else 
  281.       (
  282.         _status _fooS strcatn ["looking up host "[listtostr a ["\n" nil]]]; 
  283.         _gethostbyname listtostr a
  284.       )
  285.     )-> adip in 
  286.     { 
  287.       if (IsPort listtostr b)==nil then 
  288.       { 
  289.         set adip=strcat strcat adip ":" itoa PortComutron; 
  290.         0 
  291.       } 
  292.       else 
  293.       { 
  294.         set adip=strcat strcat adip ":" listtostr tl b; 
  295.         0 
  296.       }; 
  297.       _status strcat strcat strcat strcat "Trying " Address " (" adip ")...\n"; 
  298.       _openchannel adip "" Serverenv; 
  299.       _SETtext address adip; 
  300.       0 
  301.     } 
  302.   else (_fooS "Can't contact: Line Allready connected";0)
  303. };; 
  304.  
  305. fun _AddLine (name,chn)= 
  306.   set Lines=chn::Lines; 
  307.   set SLines=(_channelIP chn)::SLines; 
  308.   createmenus; 
  309.   0 
  310. };; 
  311.  
  312. fun ChatRoomCB (obj,r,i)= 
  313.   set ChatRoom=i; 
  314.   if (ChatRoom==0) then 
  315.   { 
  316.     _closeserver server; 
  317.     _setenv _channel Serverenv; 
  318.     set serverenv=Serverenv; 
  319.     set server=_setserver Serverenv 1290 "_load \"locked/stdsrv.pkg\""; 
  320.     set scriptserver="_load \"comm/comclient.pkg\"\n_connected"; 
  321.     _status "Room Mode disabled.\n"; 
  322.   } 
  323.   else 
  324.   {  
  325.     _closeserver server; 
  326.     _load "comm/comroomenv.pkg"; 
  327.     set roomenv=_envchannel _channel; 
  328.     set serverenv=roomenv; 
  329.     set server=_setserver roomenv 1290 "_load \"locked/stdsrv.pkg\"" ; 
  330.     set scriptserver="_connected"; 
  331.     _status "Room Mode enabled.\n"; 
  332.   } 
  333. };; 
  334.  
  335. fun InitWindows ()= 
  336.   _fooS "InitWindows"; 
  337.   set littlefont=_CRfont _channel atoi loc "LITFONTSZ" 0 0 loc "LITFONT"; 
  338.   set mediumfont=_CRfont _channel atoi loc "MEDFONTSZ" 0 0 loc "MEDFONT"; 
  339.   set bigfont=_CRfont _channel atoi loc "BIGFONTSZ" 0 FF_WEIGHT loc "BIGFONT"; 
  340.   set mainw=_CRwindow _channel nil 512 10 315 165 WN_MENU+WN_MINBOX+WN_SIZEBOX+WN_MINIMIZE+WN_HIDDEN "Commutron"; 
  341.   _CBwinPaint mainw @mainwpaint 0; 
  342.   _CBwinDestroy mainw @mainwdestroy 0; 
  343.   set address=_CReditText _channel mainw 160 5 150 25 ET_DOWN|ET_AHSCROLL ""; 
  344.   set connectbtn=_CRbutton _channel mainw 5 5 150 25 0 "Connect to :"; 
  345.   _CBbutton connectbtn @ConnectTo 0; 
  346.   set mainstatus=_CRtext _channel mainw 5 60 305 80 ET_DOWN|ET_AVSCROLL|ET_VSCROLL "Comutron started\n"; 
  347.   _AFFfontText mainstatus littlefont; 
  348.   _AFFfontButton connectbtn bigfont; 
  349.   _AFFfontText address mediumfont; 
  350.   initbookmarks; createmenus; 
  351.   _CRtext _channel mainw 5 32 150 22 ET_BORDER "Your name :"; 
  352.   set nickname=_CReditText _channel mainw 160 30 150 25 ET_DOWN|ET_AHSCROLL "NickName"; 
  353.   _AFFfontText nickname mediumfont; 
  354.   _PAINTwindow mainw; 
  355.   _fooS "End InitWindows"; 
  356.   0 
  357. };; 
  358.  
  359. fun Main (port,nick,serv)= 
  360. {  
  361.   startloc "Comm/comm"; 
  362.   set MainChn=_channel; 
  363.   if port!=nil then 
  364.   {   
  365.     set PortComutron=port 
  366.   } 
  367.   else 
  368.   { 
  369.     set port=atoi _getress "PortComutron"; 
  370.     if port!=nil then 
  371.     { 
  372.       set PortComutron=port 
  373.     } 
  374.     else 0 
  375.   }; 
  376.   _fooS "ComPort OK"; 
  377.   if nick!=nil then 
  378.   { 
  379.     set NickName=nick; 
  380.     0 
  381.   } 
  382.   else 
  383.   { 
  384.     set nick=_getress "DefaultName"; 
  385.     if nick==nil then set nick=_getpack _checkpack "pseudo.txt" 
  386.     else nil; 
  387.     if nick!=nil then 
  388.     { 
  389.       set NickName=nick; 
  390.       0 
  391.     } 
  392.     else 0
  393.   }; 
  394.   _fooS "ComNick OK"; 
  395.   set Serverenv=_envchannel _channel; 
  396.   set serverenv=Serverenv; 
  397.   set server=_setserver serverenv PortComutron "_load \"locked/stdsrv.pkg\""; 
  398.   if (server==nil) then 
  399.   {  
  400.     set _clientonly=1; 
  401.     _fooS "Not Server"; 
  402.     initbookmarks; 
  403.     InitWindows; 
  404.     _SETtext nickname NickName; 
  405.     0 
  406.   } 
  407.   else 
  408.   { 
  409.     _fooS "Server"; 
  410.     initbookmarks; 
  411.     InitWindows; 
  412.     _SETtext nickname NickName; 
  413.     _scriptc _masterchannel mkscript Cpublic ["Commutron" PortComutron]; 
  414.     0 
  415.   }; 
  416.   if (serv==1) then 
  417.   { 
  418.     _closeserver server; 
  419.     _load "comroomenv.pkg"; 
  420.     set roomenv=_envchannel _channel; 
  421.     set serverenv=roomenv; 
  422.     set server=_setserver roomenv 1290 "_load \"locked/stdsrv.pkg\"" ; 
  423.     set scriptserver="_connected"; 
  424.     _status "Room Mode enabled.\n"; 
  425.     0 
  426.   } 
  427.   else 0; 
  428.   
  429.   set scriptuser=strcatn scriptuser::"\""::(_hostIP)::"\""::"\n"::nil;
  430.   
  431.   _JCompInit quality; 
  432.  
  433.   _fooS "End Main"; 
  434.   0 
  435. };; 
  436.  
  437. defcom ChatStart = ChatStart S;; 
  438. defcom skip=skip;; 
  439. defcom InitChat = InitChat S I;; 
  440.  
  441. fun __ChatACK (nick)= 
  442.   _status strcat strcat strcat nick " on IP " _channelIP _channel " opens a new chat window."; 
  443.   _load "comm/comphone.pkg"; 
  444.   _load "comm/comchat.pkg"; 
  445.   _script mkscript InitChat [nick ChatRoom]; 
  446.   0 
  447. };; 
  448.  
  449. fun __ChatNACK (nick,message)= 
  450.   _DLGMessageBox _channel nil loc "REFUSED" strloc loc "REFUSED2" nick::(_channelIP _channel)::nil 0; 
  451.   _status message;   
  452.   _delline _channel; 
  453.   _closechannel;  
  454.   0 
  455. };; 
  456.  
  457. fun _connected ()= 
  458.   _on _channel skip []; 
  459.   _SETfocus mainw; 
  460.   _status "Connection.\n"; 
  461.   _on _channel ChatStart [_GETtext nickname]; 
  462.   _AddLine _channelIP _channel _channel; 
  463. };; 
  464.  
  465. fun _closed ()= 
  466. {  
  467.   _status "Deconnection.\n"; 
  468. };;
  469.  
  470.  
  471. fun __redirect (ip)=
  472.   if (!strcmp _fooS _channelIP _channel "127.0.0.1")||(!strcmp _channelIP _channel _fooS _hostIP) then Contact ip else nil;
  473.   _closechannel;;
  474.  
  475. fun APIContact (Address)= 
  476.   __redirect Address
  477. /*
  478.   if (IsPort Address) then { 0 } 
  479.   else 
  480.   { 
  481.     set Address=strcat strcat Address ":" itoa PortComutron;
  482.     0 
  483.   }; 
  484.   _status strcat strcat "API Trying " Address " ...\n"; 
  485.   set APIconnect=1; _openchannel Address "_load \"comm/comapi2.pkg\"\nAPIcnx\n" _envchannel _channel;  
  486.   0 */
  487. };;  
  488.  
  489.