/***************************************************************/ /* */ /* PBSRV.PKG */ /* */ /* plug-in PhotoPaintBall */ /* server */ /* */ /* version 5 : Loïc Berthelot, dec 2000 */ /* */ /* nouvelle version 4.5 : Loïc Berthelot nov 2000 */ /* */ /* Photo3 Plugin - DMS - march 00 - by Sylvain HUET */ /* rev September 2001 - by Franck OHAYON & Sebastien DENEUX */ /* */ /***************************************************************/ /* note seb : je quitte un c3d3, je suis deco pour le c3d3 cas ds avatar : g un ob a moi sur le serveur representant mon avatar, il est detruit autres cas : l'ob sur le serveur est le meme pour tout le monde, il n'est pas detruit d'ou : OB_CBclientDestroyed o @ClientDeleted; ObCbDestroy o @pb_destroy; */ /***************************************************************/ /* */ /* */ /* DATA STRUCT : */ /* typeof class : S */ /* typeof usersList : [User r1] */ /* */ /* */ /* BODY - COMMUNICATIONS WITH CLIENTS */ /* cbUpdateclass */ /* shoot */ /* shooted */ /* _ammo */ /* ammo */ /* _load */ /* load */ /* _infos */ /* infos */ /* _spinachDamage */ /* spinachDamage */ /* printMsg */ /* */ /* */ /* BODY : */ /* is_in_list */ /* newOb */ /* typeof missingFiles : [S r1] */ /* _checkItem */ /* _registerItems */ /* IniPlug */ /* */ /* */ /***************************************************************/ /********************************************************************************/ /********************************************************************************/ /** **/ /** D A T A S T R U C T **/ /** **/ /********************************************************************************/ /********************************************************************************/ typeof class=S;; typeof usersList = [User r1];; var AVPOSITION = 13;; /* MODIF */ typeof ListStateOb = [[S I] r1];; /* [(ObName o) state] */ /* MODIF */ /******************************************************************************* Function to research the name of Ob in the Avatar State List a -> [S I] : an element of the ListStateOb name -> S : then name of Ob <- I : *******************************************************************************/ fun searchbyObname (a,name) = let a -> [Obname _] in !strcmp Obname name ;; fun ClientDeleted(o,cli) = /*_DLGMessageBox _channel nil "CLIENT DELETED " "" 0;*/ set usersList = remove_from_list usersList (CtoU cli); set ListStateOb = removef_from_list ListStateOb @searchbyObname ObName o; 0 ;; /********************************************************************************/ /********************************************************************************/ /** **/ /** B O D Y - COMMUNICATIONS WITH CLIENTS **/ /** **/ /********************************************************************************/ /********************************************************************************/ fun cbUpdateClass(ui, cli, action, param) = ObUpdateClass CtoU cli class ;; fun shoot(ui, cli, action, param) = UsendMessage ui UtoC UgetUser ui "shoot" param ;; fun shooted(ui, cli, action, param) = UsendMessage ui nil "shooted" param ;; /* MODIF */ /******************************************************************************* Each time an avatar is born or dead we update the Avatar State List ui -> UI : cli -> CLIENT : action -> nil : param -> [[S I] r1] : ListStateOb <- *******************************************************************************/ fun AvState (ui, cli, action, param) = /* give to avatar a new position */ let lineextr param -> [name [state [tel _ ]]] in /*_DLGMessageBox _channel nil "SRV AvState Valeurs" strcat state tel 0;*/ let lineextr param -> [name [state [tel _ ]]] in if (atoi tel) == 0 then ( let PLUGparams thisplug -> params in let getInfos params "positions" -> ListPosition in ( if ListPosition == nil then nil else let mod rand sizelist ListPosition -> randPos in let nth_list ListPosition randPos -> pos in ObPlaceAvatar UgetUser ui pos; ); ) else nil; let lineextr param -> [name [state [tel _ ]]] in ( let ( search_in_list ListStateOb @searchbyObname name ) -> f in ( /* Update of State of Avatar in the List */ mutate f <- [ _ (atoi state)]; /* Send to All clients the update */ UsendMessage ui nil "AvState" linebuild name::state::nil; 1 ) ) ;; /* MODIF */ /******************************************************************************* Transform Avatar State List in a List list -> [[S I] r1] : ListStateOb <- [S r1] : new sort of list *******************************************************************************/ fun ListAvState (list) = if list == nil then nil else let list -> [[ a0 a1 ] next ] in a0::(itoa a1)::(ListAvState next) ;; /* MODIF */ /******************************************************************************* send to client the Avatar State List ui -> UI : cli -> CLIENT : action -> nil : param -> nil : <- *******************************************************************************/ fun reception (ui, cli, action, param) = UsendMessage ui (UtoC UgetUser ui) "ListAvState" linebuild ListAvState ListStateOb ;; fun _ammo (u, tuple) = let tuple -> [ui param] in UsendMessage ui (UtoC u) "ammo" param ;; fun ammo (ui, cli, action, param) = let remove_from_list usersList (UgetUser ui) -> users in apply_on_list users @_ammo [ui param] ;; /******************************************************************************* Send message to client to inform what gun an avatar has u -> USERS : tuple -> [UI S] : UserI & the index of the gun <- *******************************************************************************/ /*fun _load (u, tuple) = let tuple ->[ui param] in UsendMessage ui (UtoC u) "load" param ;;*/ /******************************************************************************* Send message to client to inform what gun an avatar has ui -> UI : cli -> CLIENT : action -> nil : param -> S : the index of the gun <- *******************************************************************************/ fun load (ui, cli, action, param) = UsendMessage ui nil "load" param /*test SD*/ /*let remove_from_list usersList (UgetUser ui) -> users in apply_on_list users @_load [ui param]*/ ;; fun _infos (u, tuple) = let tuple -> [ui param] in UsendMessage ui (UtoC u) "infos" param ;; fun infos (ui, cli, action, param) = let remove_from_list usersList (UgetUser ui) -> users in apply_on_list users @_infos [ui param] ;; /******************************************************************************* Send message to client to inform an avatar has taken the spinash box u -> USERS : tuple -> [UI S] : UserI & the string "this avatar hes taken spinash" <- *******************************************************************************/ fun _spinachDamage (u, tuple) = let tuple -> [ui param] in UsendMessage ui (UtoC u) "spinachDamage" param ;; /******************************************************************************* Send message to client to inform an avatar has taken the spinash box ui -> UI : cli -> CLIENT : action -> nil : param -> S : the string "this avatar hes taken spinash" <- *******************************************************************************/ fun spinachDamage (ui, cli, action, param) = apply_on_list usersList @_spinachDamage [ui param] ;; /******************************************************************************* Send message to client to inform an avatar has taken the spinash box ui -> UI : cli -> CLIENT : action -> nil : param -> S : the message an avatar wants to say to all the others <- *******************************************************************************/ fun printMsg (ui, cli, action, param) = UsendMessage ui nil action param ;; /********************************************************************************/ /********************************************************************************/ /** **/ /** B O D Y **/ /** **/ /********************************************************************************/ /********************************************************************************/ fun is_in_list (list, el) = if (list == nil) then 0 else let list -> [fst nxt] in if (el == fst) then 1 else is_in_list nxt el ;; /* MODIF */ /******************************************************************************* check if client is already in the list list -> [[S I] r1] : ListStateOb el -> S : name of Ob <- I : this name is or is not in the ListStateOb *******************************************************************************/ fun is_in_list2 (list, el) = if (list == nil) then 0 else let list -> [[fst _] nxt] in if (el == fst) then 1 else is_in_list2 nxt el ;; /*seb*/ fun pb_destroy (o) = /*_DLGMessageBox _channel nil "TEST SERVER DESTROY" "" 0;*/ set ListStateOb = removef_from_list ListStateOb @searchbyObname ObName o; 0 ;; /**********************************************/ /* newOb [Ob] I */ /* */ /* instance entry */ /* */ /**********************************************/ fun newOb(o)= /*_DLGMessageBox _channel nil "TEST NEW OB" "" 0;*/ OB_CBclientDestroyed o @ClientDeleted; /*seb*/ ObCbDestroy o @pb_destroy; /*seb*/ let UgetUser ObUi o -> newUser in if (is_in_list usersList newUser) then nil else set usersList = newUser::usersList; /* Creation of the Avatar State List */ let ObName o -> nameOb in if (is_in_list2 ListStateOb nameOb) then nil else set ListStateOb = [nameOb 0]::ListStateOb; UcbMessage ObUi o ["updateClass" @cbUpdateClass]::["shoot" @shoot]::["shooted" @shooted]::["reception" @reception]::["AvState" @AvState]:: /* MODIF */ ["load" @load]::["ammo" @ammo]::["infos" @infos]:: ["printDialogueMsg" @printMsg]::["printPlayersMsg" @printMsg]:: ["spinachDamage" @spinachDamage]::nil; 1 ;; typeof missingFiles = [S r1];; fun _checkItem (file) = if ((_checkpack file) != nil) then nil else ( set missingFiles = listcat missingFiles file::"\n"::nil; ) ;; /*******************************************/ /* _registerItems */ /* */ /*******************************************/ fun _registerItems (filesList) = if (filesList == nil) then 1 else let filesList -> [fstFile nxtFiles] in ( _checkItem fstFile; _RSregister this fstFile RSfile|RScontrol fstFile; _registerItems nxtFiles; ) ;; /*********************************************/ /* */ /* INITIALISATION */ /* */ /*********************************************/ fun IniPlug2(file)= defines_init; _registerItems defines_getResFiles; if (missingFiles == nil) then nil else defines_warningMissingFiles missingFiles; PlugRegister class @newOb nil; 0 ;; fun pro () = let BigToAsc BigInvn BigFromAsc _getpack _checkpack "dms/3d/plugins/paintballav/paintballav.conf" BigFromAsc "8c03389264ea20e9" -> s in let if (strlen s)!=9 then nil else [htoi substr s 1 4 htoi substr s 5 4] -> [datedebut periode] in if periode==nil then (_adderror strcatn (_loc this "PRO_MODULE" nil)::" "::class::" : "::(_loc this "PRO_INVALID_MSG" nil)::nil;0) else if periode==0 then 1 else let ((time>>1)&0x3fffffff)/43200-datedebut -> x in if x<0 then (_adderror strcatn (_loc this "PRO_MODULE" nil)::" "::class::" : "::(_loc this "PRO_INVALID_MSG" nil)::nil;0) else if x<=periode then (_addwarning strcatn (_loc this "PRO_MODULE" nil)::" "::class::" : "::(_loc this "PRO_LIMITED_MSG" (itoa (periode-x))::nil)::nil;1) else (_adderror strcatn (_loc this "PRO_MODULE" nil)::" "::class::" : "::(_loc this "PRO_ENDLIMITED_MSG" nil)::nil;0) ;; fun IniPlug(file)= set class=getInfo strextr _getpack _checkpack file "name"; if pro then IniPlug2 file else PlugRegisterPro class ;;