[Crossfire-wiki] [Crossfire DokuWiki] page changed: client_side_scripting:client_scripting_interface-basic_howto

no-reply_wiki at metalforge.org no-reply_wiki at metalforge.org
Fri Aug 23 19:41:17 CDT 2013


A page in your DokuWiki was added or changed. Here are the details:

Date        : 2013/08/23 19:41
User        : partmedia
Edit Summary: Fix some C example code

@@ -41,10 +41,12 @@
  Learn to say hello
  
  Here we go for the first script. We will do quite simple things. We will ask our character to say "hello world" around. The script will be written in C because we simply need to choose a language. The script is quite simple:
  
-   int main(){
-        printf("issue 1 1 say hello world\n");
+   #include <stdio.h>
+   
+   int main() {
+       puts("issue 1 1 say Hello world!\n");
    }
  
  
  Name it first.c, compile it and launch it in your command shell:
@@ -80,22 +82,26 @@
  What to do next? As you can see, our script doesn't wait very long after issuing commands. And it doesn't get information from the client at all. In fact it just //hopes// it is really speaking to the client. We are going to write a simple script which will __issue__ a command to the client and then gets the result. We are going to spy!\\ 
  \\ 
  Use the following script and run it in client. Ensure you ran the client in a console or you won't see any result!
  
+   #include <stdbool.h>
    #include <stdio.h>
    
-   int main (){
-         char buf[200];
-         int len;
-         printf ("monitor\n");
-         fflush (stdout);
-         for(;;){               
-                 len=read(0,buf,200);
-                 if(len)
-                         write(2,buf,len);               
-                 else
-                         exit(-1);
-         }
+   #define LENGTH 200
+   
+   int main() {
+       char buffer[LENGTH];
+   
+       // Ask the client for a copy of all commands sent to the server.
+       fprintf(stdout, "monitor\n");
+       fflush(stdout);
+   
+       // Read the commands and print to standard error.
+       while (fgets(buffer, LENGTH, stdin) != NULL) {
+           fputs(buffer, stderr);
+       }
+   
+       return 0;
    }
  
  Now move a bit in the game. A few steps are enough! Look at your console, you should see something like this:
  


IP-Address  : 99.126.98.223
Old Revision: http://wiki.metalforge.net/doku.php/client_side_scripting:client_scripting_interface-basic_howto?rev=1375810588
New Revision: http://wiki.metalforge.net/doku.php/client_side_scripting:client_scripting_interface-basic_howto

-- 
This mail was generated by DokuWiki at
http://wiki.metalforge.net/



More information about the crossfire-wiki mailing list