/* CLOUVION - part Serveur - 03/2004 */ /* by iri - http://www.irizone.net */ typeof wordFile = S;; typeof colorTexte = S;; typeof background = S;; typeof words = [S r1];; typeof clis = [[CLIENT I] r1];; defcom Cregistered = registered S;; defcom CsetWord = setWord S;; defcom Cuser = user S;; fun bycli(elt, p)= let elt -> [cli _] in cli == p;; /* fun [[CLIENT I] Comm] I */ fun broad(elt, p)= let elt -> [cli _] in _DMSsend this cli p;; fun getScoreTop(p)= apply_on_list clis @broad Cregistered [p]; 0;; fun userS(s, i)= if i > (sizelist clis) then s else let nth_list clis i -> [cli score] in let _DMSgetLogin cli -> login in (set s = linebuild s::login::(itoa score)::nil; userS s i+1);; fun logout(cli)= _DMSevent this cli "destroyed" nil nil; let search_in_list clis @bycli cli -> c in if c == nil then 0 else (set clis = remove_from_list clis c; 0); apply_on_list clis @broad Cuser [userS "" 0];; fun cbDestroy (from, user, action, param, others, tag) = let UtoC user -> cli in (_DMSdelClientDMI this cli; logout cli); 0;; fun cbStart(from, user, action, param, others, tag) = if (_DMSclientAlive UtoC user) then (_DMScreateClientDMI this UtoC user linebuild colorTexte::background::nil; 0) else 0;; fun chLogin(from, user, action, param, others, tag) = let UtoC user -> cli in apply_on_list clis @broad Cuser [userS "" 0]; 0;; fun IniDMI (file)= let strextr _getpack _checkpack file -> l in ( set wordFile = getInfo l "wordList"; set colorTexte = getInfo l "colorTexte"; set background = getInfo l "background"; set words = lineextr _getpack _checkpack wordFile; ); _RSregisterfiles this background::nil RSfile|RScontrol; _DMSregister this @logout nil nil; _DMSdefineActions this ["start" @cbStart]:: ["destroy" @cbDestroy]:: ["!chgLogin" @chLogin]:: nil; 0;; fun searchWord()= let (mod rand ((sizelist words)-2))+2 -> pos in nth_list words pos;; fun __register()= let search_in_list clis @bycli DMSsender -> c in if c != nil then nil else set clis = [DMSsender 0]::clis; _DMSsend this DMSsender Cregistered [linebuild (nth_list words 0)::(nth_list words 1)::(itoa sizelist words)::nil]; apply_on_list clis @broad Cuser [userS "" 0]; _DMSevent this DMSsender "in" nil nil; 0;; fun __getWord()= _DMSsend this DMSsender CsetWord [searchWord]; 0;; fun chgScore(ll, cli, new)= if ll == nil then (_showconsole;nil) else let ll -> [[c old] next] in if c == cli then [c new]::next else [c old]::chgScore next cli new;; fun __newScore(new)= _DMSevent this nil "newScore" itoa new nil; set clis = chgScore clis DMSsender new; apply_on_list clis @broad Cuser [userS "" 0]; if (atoi nth_list words 0) < new then let words -> [old [login others]] in (set words = (itoa new)::(_DMSgetLogin DMSsender)::others; _createpack linebuild words _getmodifypack wordFile; getScoreTop linebuild (itoa new)::(_DMSgetLogin DMSsender)::(itoa sizelist words)::nil; _DMSevent this nil "newTopScore" linebuild (_DMSgetLogin DMSsender)::(itoa new)::nil nil; 0) else 0;;