/* Speaker Server - DMS - Apr 98 - by Sylvain HUET */ defcom Center=enter S;; defcom Cleave=leave S;; defcom Csound=sound S S;; fun getUdp(i,j)= if i>=j then nil else let _setUDP _envchannel _channel i "" -> c in if c==nil then getUdp i+1 j else [c i];; typeof clis=[[CLIENT S] r1];; typeof spk=[[CLIENT S] r1];; typeof udp=I;; fun clibycli(a,c)=let a->[x _] in x==c;; fun clibyip(a,i)=let a->[_ ip] in !strcmp i ip;; fun broad(x,s)=let x->[c _] in _DMSsend this c s;; fun broadsel(x,z)=let x->[c ip] in let z->[cc s] in if c==cc then nil else _sendUDP ip s;; fun __sound(n,s)= if s==nil || 0==strlen s then nil else let search_in_list spk @clibyip _channelIP _channel ->[c _] in if c==nil then nil else apply_on_list clis @broadsel [c Csound [n s]];; fun who(a,c)=let a->[_ udp] in _DMSsend this c Center [udp];; fun __register(i)= if nil!=search_in_list clis @clibycli DMSsender then nil else let _channelIP DMSsender.chnCLI ->chntry in let if !strcmp chntry "127.0.0.1" then _hostIP else chntry -> chnok in let strcat strcat chnok ":" itoa i -> udp in (apply_on_list clis @broad Center [udp]; apply_on_list clis @who DMSsender; set clis=[DMSsender udp]::clis; _DMSevent this DMSsender "entering" nil nil);; fun logout(cli)= let search_in_list clis @clibycli cli->z in if z==nil then nil else let z->[_ udp] in (set clis=remove_from_list clis z; apply_on_list clis @broad Cleave [udp]; _DMSevent this cli "destroyed" nil nil); let search_in_list spk @clibycli cli->z in if z==nil then nil else set spk=remove_from_list spk z; 0 ;; fun __silent()= let search_in_list clis @clibycli DMSsender ->z in if z==nil then nil else let z->[_ udp] in (set clis=remove_from_list clis z; apply_on_list clis @broad Cleave [udp]; _DMSevent this DMSsender "silent" nil nil);; fun activate(from,cli,action,param,rep)= if !strcmp action "start_server" then (if !_DMScreateClientDMI this cli itoa udp then nil else set spk=[cli _channelIP cli.chnCLI]::spk; 0) else if !strcmp action "start_direct" then (_DMScreateClientDMI this cli nil; 0) else if !strcmp action "start_mute" then (_DMScreateClientDMI this cli ""; 0) else if !strcmp action "destroy" then (_DMSdelClientDMI this cli; logout cli) else nil;; fun IniDMI(file)= _DMSregisterDMI this @activate @logout @logout nil; set udp=let getUdp 3000 4000 ->[_ i] in i ;;