]> code.citadel.org Git - citadel.git/blobdiff - citadel/citadelapi.c
* Added a CtdlGotoRoom() function to the CitadelAPI.
[citadel.git] / citadel / citadelapi.c
index 4ada1e108dde2f1099aa8d51b189639614e2b6a4..5f01e34f93144338d481a8edaace73a16c0af905 100644 (file)
@@ -6,6 +6,9 @@
 #include <string.h>
 #include <errno.h>
 #include "citadel.h"
+#include "serv_info.h"
+#include "ipc.h"
+#include "citadelapi.h"
 
 
 struct CtdlInternalList {
@@ -16,11 +19,10 @@ struct CtdlInternalList {
 
 struct CtdlServerHandle CtdlAppHandle;
 struct CtdlServInfo CtdlAppServInfo;
+struct CtdlRoomInfo CtdlCurrentRoom;
 int CtdlErrno = 0;
 
-void CtdlMain();
-
-void logoff(exitcode) {
+void logoff(int exitcode) {
        exit(exitcode);
        }
 
@@ -77,7 +79,7 @@ void CtdlInternalExtract(char *dest, char *source, int parmnum)
        }
 
 /*
- * CtdlInternalExtractInt()  -  CtdlInternalExtract an int parm w/o supplying a buffer
+ * CtdlInternalExtractInt()  -  Extract an int parm w/o supplying a buffer
  */
 int CtdlInternalExtractInt(char *source, int parmnum)
 {
@@ -88,7 +90,7 @@ int CtdlInternalExtractInt(char *source, int parmnum)
        }
 
 /*
- * CtdlInternalExtractLong()  -  CtdlInternalExtract an long parm w/o supplying a buffer
+ * CtdlInternalExtractLong()  -  Extract an long parm w/o supplying a buffer
  */
 long CtdlInternalExtractLong(char *source, long int parmnum)
 {
@@ -123,9 +125,9 @@ long CtdlInternalExtractLong(char *source, long int parmnum)
  * 
  */
 
-main(argc, argv)
-int argc;
-char *argv[]; {
+int
+main(int argc, char *argv[])
+{
        int a;
        char buf[256];
 
@@ -138,9 +140,11 @@ char *argv[]; {
        if (argc < 3) exit(1);
 
        /* Zeroing out the server handle neatly sets the values of
-        * CtdlAppHandle to sane default values
+        * CtdlAppHandle to sane default values.  This also holds true
+        * for the CtdlCurrentRoom.
         */
        bzero(&CtdlAppHandle, sizeof(struct CtdlServerHandle));
+       bzero(&CtdlCurrentRoom, sizeof(struct CtdlRoomInfo));
 
        /* Now parse the command-line arguments fed to us by the server */
        for (a=0; a<argc; ++a) switch(a) {
@@ -168,7 +172,7 @@ char *argv[]; {
 
        /* Set up the server environment to our liking */
 
-       CtdlInternalGetServInfo(&CtdlAppServInfo, 0);
+       CtdlInternalGetServInfo(&CtdlAppServInfo);
 
        sprintf(buf, "IDEN 0|5|006|CitadelAPI Client");
        serv_puts(buf);
@@ -189,12 +193,8 @@ char *argv[]; {
                serv_gets(buf);
                }
 
-       sprintf(buf, "GOTO %s", CtdlAppHandle.InitialRoom);
-       serv_puts(buf);
-       serv_gets(buf);
-       if (buf[0] != '2') {
-               serv_puts("GOTO _BASEROOM_");
-               serv_gets(buf);
+       if (CtdlGotoRoom(CtdlAppHandle.InitialRoom) != 0) {
+               CtdlGotoRoom("_BASEROOM_");
                }
 
        /* Now do the loop. */
@@ -206,7 +206,7 @@ char *argv[]; {
        }
 
 
-int CtdlGetLastError() {
+int CtdlGetLastError(void) {
        return CtdlErrno;
        }
 
@@ -335,7 +335,7 @@ int CtdlGetUserAccessLevel(char *WhichUser) {
 int CtdlSetUserAccessLevel(int NewValue, char *WhichUser) {
        char buf[256];
 
-       if ( (NewValue < 1) || (NewValue > 6) ) {
+       if ( (NewValue < 0) || (NewValue > 6) ) {
                return(ERROR + ILLEGAL_VALUE);
                }
 
@@ -398,3 +398,21 @@ int CtdlForEachUser(int (*CallBack)(char *EachUser))  {
 
        return(0);
        }
+
+
+
+/*
+ * Goto a different room
+ */
+int CtdlGotoRoom(char *RoomName) {
+       char buf[256];
+
+       sprintf(buf, "GOTO %s", RoomName);
+       serv_puts(buf);
+       serv_gets(buf);
+       if (buf[0] != '2') {
+               CtdlErrno = atoi(buf);
+               return(CtdlErrno);
+               }
+       extract(&CtdlCurrentRoom.RoomName, &buf[4], 0);
+       }