home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / announce / Announce.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-08  |  3.7 KB  |  162 lines

  1. /************************************************/
  2.                                              /***/
  3. #define REVISION "1.0"                         /***/
  4. #define REVDATE  "16.02.96"                     /***/
  5. #define PROGNAME "Announce"                     /***/
  6. #define NAME     "Announce"                     /***/
  7. #define AUTHOR   "Joe Cool"                     /***/
  8.                                              /***/
  9. /************************************************/
  10.  
  11. #include <exec/types.h>
  12. #include <exec/ports.h>
  13. #include <exec/memory.h>
  14. #include <dos/dos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/alib_protos.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include "aedoor.h"
  23. #include "semis.h"
  24. static const char VersionTag[] = "\0$VER: "PROGNAME" "REVISION" ("REVDATE")";
  25. #define ws WriteStr
  26.  
  27. void Start(int node);
  28. char *Nodes_get(void);
  29. char *Mainline(void);
  30. char *handleget(void);
  31. char *timenow (VOID);
  32.  
  33. void main(int argc, char *argv[])
  34. {
  35.     int    Node=0;
  36. if(argc<2)
  37. {
  38.     printf("Sorry, %s must be called from S!X or /X\n",argv[0]);
  39.     exit(0);
  40. }
  41.  
  42. Node=atoi(argv[1]);
  43. Register(Node);
  44.  
  45. XIM_Msg->Command=140;                    
  46. CheckMessage();
  47. SetTaskPri(FindTask(0),atol(XIM_Msg->String));
  48.  
  49. Start(Node);
  50. ShutDown();
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57. void Start(Node)
  58. {
  59.     char    buffer[255],
  60.             time[40],
  61.             handle[50];
  62.     long    counter=0;
  63.     BOOL    node[10],
  64.             logon=FALSE,
  65.             logoff=FALSE;
  66.     APTR    Singles[32];
  67.     struct SinglePort *Singleport=NULL;
  68.     struct MultiPort *MPort=NULL;
  69.     BPTR    fileptr=NULL;
  70.  
  71.  
  72.     ws("",1);
  73.     ws("Announce V1.0 ©1996 Joe Cool",1);
  74.  
  75.     strcpy (time,timenow());
  76.     SendStrDataCmd(177,"JoeAnnounce",0);
  77.     SendStrDataCmd(DT_NAME,"",1);
  78.     strcpy(handle,XIM_Msg->String);
  79.  
  80.     SendStrDataCmd(BB_MAINLINE,"",1);
  81.     strcpy(buffer,XIM_Msg->String);
  82.     if (!strcmp("annon",buffer)) logon=TRUE;
  83.     if (!strcmp("annoff",buffer)) logoff=TRUE;
  84.     
  85.  
  86.     
  87.     GetDT(531,"\0");
  88.     MPort=(struct MultiPort *)XIM_Msg->Semi;
  89.  
  90.  
  91.         
  92.     strcpy(buffer,Nodes_get());    
  93.     for (counter=0;counter<10;counter++)
  94.         if (buffer[counter]=='X') node[counter]=TRUE; else node[counter]=FALSE; 
  95.     node[Node]=FALSE;
  96.     
  97.     for (counter=0;counter<10;counter++)
  98.     {
  99.         ObtainSemaphore((struct SignalSemaphore *)MPort);
  100.         Singles[counter]=MPort->MyNode[counter].s;
  101.         ReleaseSemaphore((struct SignalSemaphore *)MPort);
  102.  
  103.         if (node[counter]) 
  104.         {
  105.             ObtainSemaphore((struct SignalSemaphore *)Singles[counter]);
  106.             Singleport=(struct SinglePort *)Singles[counter];
  107.             ReleaseSemaphore((struct SignalSemaphore *)Singles[counter]);
  108.     
  109.             if (Singleport->Status!=22 && ((logoff) || (logon)))
  110.             {
  111.                 sprintf(buffer,"bbs:node%d/OLM.Message.txt",counter);
  112.                 fileptr = Open( buffer, MODE_READWRITE );
  113.                 Seek( fileptr, 0, OFFSET_END );
  114.                 if (logoff) sprintf(buffer,"(%s) %s logged off!\n",time,handle);
  115.                 if (logon) sprintf(buffer,"(%s) %s logged into Node %d!\n",time,handle,Node);
  116.                 FPuts(fileptr,buffer);
  117.                 FPuts(fileptr,"\n");
  118.                 Close(fileptr);
  119.             }
  120.         }
  121.     }
  122.  
  123. }
  124. char *Nodes_get(void)
  125. {
  126.     SendStrDataCmd(ACTIVE_NODES,"",0);
  127.     return(XIM_Msg->String);
  128. }
  129. char *Mainline(void)
  130. {
  131.     SendStrDataCmd(BB_MAINLINE,"",0);
  132.     return(XIM_Msg->String);
  133. }
  134. char *timenow()
  135. {
  136. struct timerequest *TimerIO;
  137. struct MsgPort *TimerMP;
  138. LONG error;
  139. ULONG hrs,secs,mins;
  140. char buffer[50];
  141.  
  142. TimerMP = CreatePort(0,0);
  143. if(!TimerMP) return(NULL);
  144. TimerIO = (struct timerequest *)CreateExtIO(TimerMP,sizeof(struct timerequest));
  145. if (!TimerIO) return(NULL);
  146. error=OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)TimerIO,0L);
  147. if (error) return (NULL);
  148. TimerIO->tr_node.io_Command = TR_GETSYSTIME;
  149. DoIO((struct IORequest *) TimerIO);
  150. secs=TimerIO->tr_time.tv_secs;
  151. mins=secs/60;
  152. hrs=mins/60;
  153. secs=secs%60;
  154. mins=mins%60;
  155. hrs=hrs%24;
  156. CloseDevice((struct IORequest *) TimerIO);
  157. DeleteExtIO((struct IORequest *) TimerIO);
  158. DeletePort(TimerMP);
  159. sprintf(buffer,"%2.2d:%2.2d:%2.2d",hrs,mins,secs);
  160. return(buffer);
  161. }
  162.