Added support for HI command (C can now see UUID)
authorJohn Hodge <[email protected]>
Tue, 14 Sep 2010 03:32:17 +0000 (11:32 +0800)
committerJohn Hodge <[email protected]>
Tue, 14 Sep 2010 03:32:17 +0000 (11:32 +0800)
src/link/C/c_link.c
src/link/C/c_link.h

index 39dda6b..6aa5709 100755 (executable)
@@ -61,8 +61,9 @@ int main( int argc, char * argv[] ) {
        char attItem[MAXITEMLEN], defItem[MAXITEMLEN], bluffItem[MAXITEMLEN];\r
        char didYouInstigate[MAXBOOLLEN];\r
        char winner[MAXRESULTLEN];\r
+       char uuid[UUIDLEN];  \r
        int pointChange;\r
-       void *thisInstance;\r
+       void *thisInstance = NULL;\r
 \r
        ATTACKTYPE attack;\r
        ITEMTYPE defence;\r
@@ -71,27 +72,30 @@ int main( int argc, char * argv[] ) {
           I can't use the UUID, because python doesn't pass it to me! */\r
        me = rand();\r
        \r
-       // TODO: Get the UUID passed by python\r
-       // Currently, just pass an empty string to the initialise function\r
-       thisInstance = Initialise( "" );\r
-       \r
        scanf( "%s", command );\r
        \r
        while (strcasecmp("BYE",command) != 0) {\r
                \r
-               if (strcasecmp("ATTACK", command) == 0) {\r
+               if (strcasecmp("HI", command) == 0) {\r
+                       scanf( "%s", uuid );\r
+                       thisInstance = Initialise( uuid );\r
+               }\r
+               else if (strcasecmp("ATTACK", command) == 0) {\r
                        scanf( "%s", foeName );\r
+                       if( !thisInstance )     break;\r
                        attack = Attack( thisInstance, foeName );\r
                        printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);\r
                \r
                } else if (strcasecmp("DEFEND", command) == 0) {\r
                        scanf( "%s %s", foeName, bluffItem );\r
+                       if( !thisInstance )     break;\r
                        defence = Defend(thisInstance, foeName, stringToItem(bluffItem));\r
                        printf("DEFENDING %s\n", ITEMNAMES[defence]);\r
                \r
                } else if (strcasecmp("RESULTS", command) == 0) {\r
                        /* (foeName, isInstigatedByYou, winner, attItem, defItem, bluffItem, pointDelta) */\r
                        scanf( "%s %s %s %s %s %s %d", foeName, didYouInstigate, winner, attItem, defItem, bluffItem, &pointChange );\r
+                       if( !thisInstance )     break;\r
                        Results(thisInstance, foeName, (strcasecmp("True",didYouInstigate)==0), stringToResult(winner),\r
                                        stringToItem(attItem), stringToItem(defItem), stringToItem(bluffItem), pointChange);\r
                        printf("OK\n");\r
@@ -104,7 +108,8 @@ int main( int argc, char * argv[] ) {
                scanf( "%s", command );\r
        }\r
        \r
-       Cleanup(thisInstance);\r
+       if( !thisInstance )\r
+               Cleanup(thisInstance);\r
        \r
        return 0;\r
 }\r
index 5953acb..12bedb2 100755 (executable)
@@ -14,6 +14,7 @@
 #define MAXITEMLEN             10\r
 #define MAXRESULTLEN    10\r
 #define MAXBOOLLEN             6\r
+#define UUIDLEN        37      // xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12) + 1 null\r
 \r
 /********** Type definitions **********/\r
 \r

UCC git Repository :: git.ucc.asn.au