home *** CD-ROM | disk | FTP | other *** search
- /* Comchat.pkg */
-
- defcom ChatACK = ChatACK S;;
- defcom NewUser = NewUser S I S;;
- defcom DelUser = DelUser S I S;;
- defcom Hear = Hear S;;
- defcom Info = Info S S;;
- defcom ComClose= ComClose;;
- defcom ComConnected= ComConnected S;;
-
- var RedirectText=0;;
- var RedirectAudio=0;;
- var RedirectEvents=0;;
-
- var sendvideo=0;;
-
- typeof thischn=Chn;;
- typeof thisenv=Env;;
- typeof SendFileF=fun [ObjButton I] I;;
-
- var servernick="";;
- var serverIP="";;
- var MyNick="";;
- var Nusers=0;;
- var IsAServer=0;;
- var PhoneASK=0;;
- var FileSend=0;;
-
- struct TPlayer = [ PlayerChannel : Chn, PlayerNick : S , PlayerID : I , PlayerIP : S ] Const_Player ;;
- typeof Players=[TPlayer r1];;
- typeof CurrentUser=TPlayer;; typeof Chatw=ObjWin;;
- typeof chattext=ObjText;;
- typeof chatinput=ObjText;;
- typeof userlist=ObjBox;;
- typeof userinfo=ObjButton;;
- typeof sendfile=ObjButton;; typeof connect=ObjButton;;
- typeof VideoBMP=ObjBitmap;;
- typeof Videobmp=ObjBitmap;;
-
- fun AddPlayer(player)=
- {
- set Players=player::Players;
- };;
-
- fun PlayerNickcmp (player,nick)=
- if !(strcmp player.PlayerNick nick) then 1 else 0;;
-
- fun PlayerIPcmp (player,IP)=
- if !(strcmp player.PlayerIP IP) then 1 else 0;;
-
- fun PlayerIDcmp (player,ID)=
- if player.PlayerID==ID then 1 else 0;;
-
- fun PlayerChcmp (player,ch)=
- if player.PlayerChannel==ch then 1 else 0;;
-
- fun GetPlayerByNick (s)=
- searchlist Players @PlayerNickcmp s;;
-
- fun GetPlayerByChannel (s)=
- searchlist Players @PlayerChcmp s;;
-
- fun GetPlayerByID (s)=
- searchlist Players @PlayerIDcmp s;;
-
- fun GetPlayerByIP (s)=
- searchlist Players @PlayerIPcmp s;;
-
- fun DelPlayerByID(id)=
- deletelist Players GetPlayerByID id;;
-
- fun DelPlayerByIP(ip)=
- deletelist Players GetPlayerByIP ip;;
-
- fun DelPlayerByNick(n)=
- deletelist Players GetPlayerByNick n;;
-
- fun DelPlayerByChannel(ch)=
- deletelist Players GetPlayerByChannel ch;;
-
- fun UpdateCurrentUser ()=
- {
- let _GETcombo userlist->[rang nick] in
- {
- set CurrentUser=GetPlayerByNick nick;
- }
- };;
-
- fun LedOn ()=
- 0
- ;;
-
- fun LedOff ()=
- 0
- ;;
-
- fun print(s)=
- _ADDtext chattext s;
- LimitText chattext 1000 14
- ;;
-
- fun ComAPIplug ()=
- _load "comm/comapi3.pkg";
- _script "APIengage"
- ;;
-
- fun __Hear (s)=
- let GetPlayerByChannel _channel -> player in print strloc loc "HEAR" player.PlayerNick::s::nil;
- if (RedirectText==1) then
- {
- _on APIchn Hear [s];
- 0
- }
- else 0
- ;;
-
- fun __Info (s1,s2)=
- {
- let GetPlayerByChannel _channel -> player in
- print strcat strcat strcat s1 player.PlayerNick s2 "\n";
- if (RedirectText==1) then
- {
- _on APIchn Info [s1 s2];
- 0
- }
- else 0
- };;
-
- fun updatesendbutton ()=
- {
- if (Nusers>1 || FileSend==1) then
- {
- if (sendfile!=nil) then
- {
- _DSbutton sendfile;
- set sendfile=nil;
- 0
- }
- else 0
- }
- else
- {
- if (sendfile==nil) then
- {
- set sendfile=_CRbutton _channel Chatw 310 60 100 20 0 loc "SENDFILE";
- _CBbutton sendfile SendFileF 0;
- 0
- }
- else 0
- }
- };;
-
- fun __NewUser (nick,ID,IP)=
- {
- print strloc loc "JOIN" nick::IP::(_channelIP _channel)::nil;
- AddPlayer Const_Player [_channel nick ID IP];
- set Nusers=Nusers+1;
- _ADDcombo userlist 0 nick;
- if (RedirectEvents==1) then
- {
- _on APIchn NewUser [nick ID IP];
- 0
- }
- else 0;
- updatesendbutton;
- };;
-
- fun __DelUser (nick,ID,IP)=
- {
- print strloc loc "LEAVE" nick::IP::(_channelIP _channel)::nil;
- DelPlayerByNick nick;
- set Nusers=Nusers-1;
- _SDELcombo userlist nick;
- if (RedirectEvents==1) then
- {
- _on APIchn DelUser [nick ID IP];
- 0
- }
- else 0;
- updatesendbutton;
- };;
-
- fun Chatwdestroy (obj,r)=
- {
- _delline thischn;
- if (APIchn!=nil) then
- {
- _on APIchn ComClose [];
- 0
- }
- else 0;
-
- _killchannel thischn;
- _killchannel APIchn;
- stopvideo;
- };;
-
- fun ProcessInput (text)=
- {
- print strloc loc "PROMPT" text::nil;
- _on thischn Hear [text];
- };;
-
- fun textinputCB (obj,u)=
- {
- let _GETtext obj -> text in
- {
- if (nth_char text ((strlen text)-1))==10 then
- {
- _DELline obj 0;
- _DELline obj 0;
- ProcessInput text;
- obj
- }
- else
- {
- obj
- }
- }
- };;
-
- fun GetUserInfos (obj,r)=
- {
- UpdateCurrentUser;
- if (CurrentUser!=nil) then
- {
- print (strloc loc "INFO1" CurrentUser.PlayerNick::CurrentUser.PlayerIP::nil);
- print (strloc loc "INFO2" (itoa CurrentUser.PlayerID)::(_channelIP CurrentUser.PlayerChannel)::nil);
- }
- else
- {
- print (loc "INFOERR");
- }
- };;
-
- typeof FilePerso=TPlayer;;
- typeof FileP=P;;
- typeof FileW=W;;
- typeof FileF=File;;
- typeof FileN=S;;
- typeof FileO=S;;
- typeof FileSize=I;;
- typeof FileSizeGot=I;;
- typeof FileChn=Chn;;
-
- var BlockSize=256;;
-
- defcom ProposeFile = ProposeFile S S I S I;;
- defcom AcceptFile = AcceptFile S I S;;
- defcom FileBlock = FileBlock S I S S;;
- defcom FileLast = FileLast S I S S;;
- defcom FileAbort = FileAbort S I S;;
- defcom FileAck = FileAck S I S;;
-
- typeof ProgressBar=ObjBitmap;;
-
- fun Chatwpaint (obj,r)=
- {
- UpdateStatus;
- _BLTbitmap Chatw ProgressBar 310 60;
- _BLTbitmap Chatw Videobmp 310 115
- };;
-
- fun InitFileProgress ()=
- {
- _DSbutton sendfile;
- set ProgressBar=_CRbitmap _channel 100 20;
- _DRAWrectangle ProgressBar 0 0 100 20 DRAW_SOLID 1 0 DRAW_SOLID (255+(255<<8)+(255<<16));
- _BLTbitmap Chatw ProgressBar 310 60;
- 0
- };;
-
- fun UpdateFileProgress ()=
- {
- if (FileSize!=0) then
- {
- _DRAWrectangle ProgressBar 2 2 ((96*FileSizeGot)/FileSize) 16 DRAW_SOLID 1 0 DRAW_SOLID (255);
- 0
- }
- else 0;
- _BLTbitmap Chatw ProgressBar 310 60;
- 0
- };;
-
- fun GetFileBlock ()=
- {
- let _FILERead FileF BlockSize -> block in
- {
- set FileSizeGot=FileSizeGot+strlen block;
- UpdateFileProgress;
- if (_FILETell FileF) >= FileSize then
- {
- [block 1]
- }
- else
- {
- [block 0]
- }
- }
- };;
-
- fun SaveFileBlock (block)=
- {
- set FileSizeGot=FileSizeGot+strlen block;
- UpdateFileProgress;
- _appendpack block FileW;
- };;
-
- fun CloseFileProgress ()=
- {
- set FileSend=0;
- _DSbitmap ProgressBar;
- set ProgressBar=nil;
- set sendfile=_CRbutton _channel Chatw 310 60 100 20 0 loc "SENDFILE";
- _AFFfontButton sendfile mediumfont;
- _CBbutton sendfile SendFileF 0;
- 0
- };;
-
- fun __FileAbort (nick,id,file)=
- {
- if (FileChn==_channel) && (FileSend==1) then
- {
- set FileSend=0;
- if (FileF!=nil) then
- {
- _FILEClose FileF;
- set FileF=nil;
- 0
- }
- else 0;
- CloseFileProgress ;
- 0
- }
- else
- {
- print loc "FILEABORT";
- 0
- }
- };;
-
- fun __AcceptFile (nick,id,file)=
- {
- if (FileChn==_channel) && (FileSend==1) then
- {
- set FileF=_FILEOpen FileChn FileP;
- if (FileF==nil) then
- {
- print loc "FILEERR";
- _on FileChn FileAbort [FilePerso.PlayerNick FilePerso.PlayerID FileN];
- CloseFileProgress ;
- 0
- }
- else
- {
- print loc "FILEACC";
- set FileSize=_FILESize FileF;
- let GetFileBlock -> [block ended] in
- if (ended==1) then
- {
- _on FileChn FileLast [nick id file block];
- _status "!File UpLoaded succesfully\n";
- _fooS "First FileBlock Is Last One...";
- CloseFileProgress ;
- 0
- }
- else
- {
- _on FileChn FileBlock [nick id file block];
- _fooS "First FileBlock";
- UpdateFileProgress;
- 0
- }
- }
- }
- else
- {
- print loc "FILEABORT";
- 0
- }
- };;
-
- fun __FileLast (nick,id,file,block)=
- {
- if (FileChn==_channel) && (FileSend==1) then
- {
- let SaveFileBlock block -> error in
- if (error!=0) then
- {
- _on _channel FileAbort [nick id file];
- print strloc loc "FILESVERR" file::nil;
- set FileSend=0;
- _FILEClose FileF;
- set FileF=nil;
- CloseFileProgress ;
- 0
- }
- else
- {
- print loc "FILEDOWN";
- set FileSend=0;
- if (FileF!=nil) then
- {
- _FILEClose FileF;
- set FileF=nil;
- 0
- }
- else 0;
- CloseFileProgress ;
- 0
- }
- }
- else
- {
- print "FILEABORT";
- CloseFileProgress ;
- 0
- }
- };;
-
- fun __FileBlock (nick,id,file,block)=
- {
- if (FileChn==_channel) && (FileSend==1) then
- {
- let SaveFileBlock block -> error in
- if (error==1) then
- {
- _on _channel FileAbort [nick id file];
- print strloc loc "FILESVERR" file::nil;
- set FileSend=0;
- if (FileF!=nil) then
- {
- _FILEClose FileF;
- set FileF=nil;
- 0
- }
- else 0;
- CloseFileProgress ;
- 0
- }
- else
- {
- _on _channel FileAck [nick id file];
- _fooS "ACKing";
- 0
- }
- }
- else
- {
- print loc "FILEABORT";
- CloseFileProgress ;
- 0
- }
- };;
-
- fun __FileAck (nick,id,file)=
- {
- if (FileChn==_channel) && (FileSend==1) then
- {
- let GetFileBlock -> [block ended] in
- if (ended==1) then
- {
- _on FileChn FileLast [nick id file block];
- _fooS "FILE LAST";
- set FileSend=0;
- updatesendbutton;
- CloseFileProgress;
- print loc "FILEOK";
- 0
- }
- else
- {
- _on FileChn FileBlock [nick id file block];
- _fooS "FILE BLOCK";
- UpdateFileProgress;
- }
- }
- else
- {
- print "FILEABORT";
- 0
- }
- };;
-
- fun SaveFile (obj,u,filename)=
- {
- if (filename!=nil) then
- {
- set FileW=filename;
- set FileN=_GetFileNameFromW filename;
- if ((_createpack "" FileW)!=0) then
- {
- print loc "FILEERR";
- _on FileChn FileAbort [FilePerso.PlayerNick FilePerso.PlayerID FileN];
- CloseFileProgress ;
- 0
- }
- else
- {
- _on FileChn AcceptFile [FilePerso.PlayerNick FilePerso.PlayerID FileN];
- print strloc loc "FILEDOWNLING" FilePerso.PlayerNick::FileO::FileN::nil;
- InitFileProgress;
- }
- }
- else
- {
- _on FileChn FileAbort [FilePerso.PlayerNick FilePerso.PlayerID FileN];
- CloseFileProgress ;
- 0
- }
- };;
-
- fun __ProposeFile (nick,to,id,file,size)=
- {
- if FileSend then
- {
- print strloc loc "FILEPROPERR" nick::file::nil;
- _on _channel FileAbort [nick id file];
- }
- else
- {
- set FilePerso = GetPlayerByNick nick;
- set FileChn=_channel;
- set FileSize=size;
- set FileSizeGot=0;
- if (FilePerso==nil) then
- {
- print strloc loc "FILEPROPERR" nick::file::nil;
- _on FileChn FileAbort [nick id file];
- 0
- }
- else
- {
- print strloc loc "FILEPROP" nick::file::nil;
- InitFileProgress ;
- _DLGrflsave (_DLGSaveFile _channel Chatw file "" "") @SaveFile 0;
- set FileSend=1;
- set FileO=file;
- 0
- }
- }
- };;
-
- fun OpenFile (obj,u,filename)=
- {
- if (filename!=nil) then
- {
- set FileP=filename;
- set FileN=_GetFileNameFromP filename;
- set FileChn=_channel;
- set FileSize=_FILESize _FILEOpen _channel FileP;
- set FileSizeGot=0;
- _on FileChn ProposeFile [MyNick FilePerso.PlayerNick FilePerso.PlayerID FileN FileSize];
- print strloc loc "PROPOSING" FileN::FilePerso.PlayerNick::nil;
- }
- else
- {
- CloseFileProgress ;
- 0
- }
- };;
-
- fun SendFile (obj,r)=
- {
- if (FileSend!=0) then 0
- else
- {
- set FileSend=1;
- UpdateCurrentUser;
- InitFileProgress ;
- set FilePerso=CurrentUser;
- _DLGrflopen (_DLGOpenFile _channel Chatw "" "" "") @OpenFile 0;
- 0
- }
- };;
-
- fun Connect (obj,r)=
- {
- UpdateCurrentUser;
- print strloc loc "NEW" CurrentUser.PlayerNick::CurrentUser.PlayerIP::nil;
- Contact CurrentUser.PlayerIP;
- 0
- };;
-
- defcom GetPhone = GetPhone;;
- defcom PhoneOK=PhoneOK;;
- defcom PhoneDENY=PhoneDENY;;
- defcom ReleasePhone = ReleasePhone;;
-
- var AskPhone=0;;
-
- fun PhoneClick (obj,r,x,y,but)=
- {
- if (x>=420) && (x<=450) && (y>=50) && (y<=80) && (AskPhone==0) && playing>=0 then
- {
- set AskPhone=1;
- _on thischn GetPhone [];
- }
- else if (x>=420) && (x<=450) && (y>=10) && (y<=40) then
- if playing==-1 then
- unmute
- else
- mute
- else 0;
- UpdateStatus
- };;
-
- fun __GetPhone ()=
- {
- _on _channel PhoneOK [];
- };;
-
- fun __PhoneOK ()=
- {
- if (AskPhone==1) then
- {
- _fooS "Phone Is OK";
- set AskPhone=2;
- Record;
- }
- else
- 0;
- };;
-
- fun __ReleasePhone ()=
- {
- _fooS "ReleasePhone";
- 0
- };;
-
- fun __PhoneDENY ()=
- {
- _fooS "PhoneDeny";
- if (AskPhone==1) then
- {
- set AskPhone=0;
- PauseRecord ;
- }
- else if AskPhone==2 then
- {
- set AskPhone=0;
- PauseRecord ;
- }
- else 0
- };;
-
- fun PhoneUnclick (obj,r,x,y,but)=
- {
- _fooS "UNCLICK";
- if (AskPhone==2) then
- {
- _fooS "PHONE";
- set AskPhone=0;
- PauseRecord ;
- _on thischn ReleasePhone [];
- 0
- }
- else if (AskPhone==1) then
- {
- set AskPhone=0;
- PauseRecord ;
- _on thischn ReleasePhone [];
- }
- else
- {
- PauseRecord ;
- 0
- }
- };;
-
- defcom HaveVideo=HaveVideo I I I S I;;
- defcom HadVideo=HadVideo;;
-
- var videosend=0;;
- var localframe=0;;
-
- var tempv="";;
-
- fun __HadVideo ()=
- {
- if (videoready==nil || sendvideo==0 || localframe==globalframe) then {_on thischn HadVideo []; nil}
- else
- {
- set localframe=globalframe;
- set tempv=strdup videoready;
- let tempv->s2 in
- let strlen s2 -> len in
- {
- while (len!=0) do
- {
- _fooS "Sending Video";
- if (len>256) then
- {
- let substr s2 0 256 -> sb in
- _on thischn HaveVideo [quality vx vy sb 0];
- set s2=substr s2 256 len;
- set len=len-256;
- }
- else
- {
- _on thischn HaveVideo [quality vx vy s2 1];
- set videosend=videosend+1;
- set len=0;
- }
- }
- }
- }
- };;
-
- typeof CurrentFrame=S;;
-
- fun __HaveVideo (q,w,h,vid,EndTrame)=
- {
- if vid!=nil then
- if EndTrame==1 then
- {
- set CurrentFrame=strcat CurrentFrame vid;
- _SETbitmap VideoBMP _InvertCapBitmap (_c32to15 (_JDecomp CurrentFrame h w q)) w;
- _BLTbitmap Chatw VideoBMP 310 115;
- _on thischn HadVideo [];
- set CurrentFrame=nil;
- }
- else
- {
- set CurrentFrame=strcat CurrentFrame vid;
- }
- else
- {
- _on thischn HadVideo [];
- nil;
- }
- };;
-
- typeof Chatmenu=ObjMenu;;
- typeof Linksmenu=ObjMenu;;
-
- fun SendVideoCheck (o,u,i)=
- /* _fooS "SendvideoCheckBox :"; _fooI i;*/
- set sendvideo=i;;
-
- fun InitChatWindow ()=
- {
- set SendFileF=@SendFile;
- set Chatw=_CRwindow _channel nil 400 100 490 250 (WN_MENU+WN_MINBOX) strloc loc "TITLE" servernick::(_channelIP _channel)::nil;
- set mainobj=Chatw;
- _CBwinPaint Chatw @Chatwpaint 0;
- _CBwinDestroy Chatw @Chatwdestroy 0;
- _CBwinClick Chatw @PhoneClick 0;
- _CBwinUnclick Chatw @PhoneUnclick 0;
- set chatinput=_CReditText _channel Chatw 5 230 300 20 ET_DOWN|ET_AHSCROLL|ET_AVSCROLL "";
- _CBtext chatinput @textinputCB 0;
- set chattext =_CRtext _channel Chatw 5 5 300 220 ET_DOWN|ET_AVSCROLL|ET_VSCROLL|ET_BORDER "";
- set userlist=_CRcombo _channel Chatw 310 5 100 210 CB_NOEDIT|CB_AHSCROLL "";
- set userinfo=_CRbutton _channel Chatw 310 35 100 20 0 loc "GETINFOS";
- _CBbutton userinfo @GetUserInfos 0;
- set sendfile=_CRbutton _channel Chatw 310 60 100 20 0 loc "SENDFILE";
- _CBbutton sendfile @SendFile 0;
- set connect=_CRbutton _channel Chatw 310 85 100 20 0 loc "CHAT";
- _CBbutton connect @Connect 0;
- _AFFfontText chattext mediumfont;
- _AFFfontText chatinput mediumfont;
- _AFFfontButton userinfo mediumfont;
- _AFFfontButton sendfile mediumfont;
- _AFFfontButton connect mediumfont;
- set Chatmenu=_CRmenu _channel Chatw;
- set Linksmenu=_APPpopup _channel Chatmenu loc "LINKS";
- set VideoBMP=_CRbitmap _channel vx vy;
- set Videobmp=_LDjpeg _channel _checkpack loc "JPGVID";
- _BLTbitmap Chatw Videobmp 310 115;
- let _CBcheck (_CRcheck _channel Chatw 415 85 100 30 0 loc "SENDVID") @SendVideoCheck 0 -> ck in
- _SETcheck ck (set sendvideo=(if (strcmp _getress "VideoCamera" "Yes") then 0 else 1));
- _PAINTwindow Chatw;
- };;
-
- fun LinksMenu (obj,link)=
- {
- print strloc loc "NEWL" link::nil;
- Contact link;
- };;
-
- fun __AddLink (name,link)=
- {
- _CBmenu (_APPitem _channel Linksmenu ME_ENABLED name ) @LinksMenu link;
- };;
-
- fun InitChat (nick,room)=
- {
- set servernick=nick;
- set serverisroom=room;
- set serverIP=_channelIP _channel;
- set MyNick=_GETtext nickname;
- _status strcat strcat "Chating with " nick ".\n";
- set thischn=_channel;
- set thisenv=_envchannel _channel;
- _status "Module Loaded\n";
- PHONEInit;
- _on _channel ChatACK [MyNick];
- InitChatWindow;
- initvideo;
- _on _channel HaveVideo [quality vx vy nil 1];
- _on _channel NewUser [MyNick 0 _hostIP];
- 0
- };;
-
- fun __ChatACK (nick)=0;;
-
- fun _connected ()=
- {
- _status "Connected.\n"
- };;
-
- fun _closed ()=
- {
- _status strcat strcat strcat strcat "Disconnected from " servernick " (" serverIP ").\n";
- _delline _channel;
- stopvideo;
- };;
-
- fun __GetAudio (audio)=
- if (RedirectAudio<2) then
- if (force_record==0) then
- if (playing==0) then
- {
- if (sizelist Alist)<5 then nil
- else startplaysnd;
- set Alist=AddAudio Alist audio;
- 0
- }
- else
- {
- set Alist=AddAudio Alist audio;
- 0
- }
- else if (playing==0) then 0
- else
- {
- set Alist=AddAudio Alist audio;
- 0
- }
- else 0;
- if (RedirectAudio>0) then
- {
- _on APIchn GetAudio [audio];
- 0
- }
- else 0;;
-
-