~ubuntu-branches/ubuntu/maverick/crossfire-client/maverick

« back to all changes in this revision

Viewing changes to common/script.c

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2007-04-13 21:15:44 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070413211544-vjo6zesj6g0wgmwf
Tags: 1.10.0-1
* New upstream release
* Install the README, README-dev and TODO files specific to the GTK2
  client to the corresponding package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
const char *rcsid_common_script_c =
2
 
    "$Id: script.c,v 1.20 2006/02/26 10:08:35 ryo_saeba Exp $";
 
2
    "$Id: script.c 5010 2006-10-07 18:29:47Z qal21 $";
3
3
/*
4
4
    Crossfire client, a client program for the crossfire program.
5
5
 
115
115
*/
116
116
 
117
117
#ifndef WIN32
118
 
#include <ctype.h>
119
118
#include <errno.h>
120
119
#include <sys/types.h>
121
120
#include <sys/socket.h>
122
121
#include <sys/wait.h>
123
122
#include <signal.h>
 
123
#else
 
124
#include <windows.h>
124
125
#endif
 
126
#include <ctype.h>
125
127
 
126
128
#include <client.h>
127
129
#include <external.h>
186
188
   DWORD dwBytesRead;
187
189
   BOOL rc;
188
190
 
189
 
   FlushFileBuffers(fd);
 
191
   FlushFileBuffers(fd);
190
192
   rc = ReadFile(fd, buf, len, &dwBytesRead, NULL);
191
193
   if (rc == FALSE)
192
194
      return(-1);
200
202
   DWORD dwBytesWritten;
201
203
   BOOL rc;
202
204
 
203
 
   rc = WriteFile(fd, buf, len, &dwBytesWritten, NULL);
 
205
   rc = WriteFile(fd, buf, len, &dwBytesWritten, NULL);
204
206
   FlushFileBuffers(fd);
205
207
   if (rc == FALSE)
206
208
      return(-1);
632
634
   }
633
635
}
634
636
 
635
 
void script_watch(const char *cmd, char *data, int len, enum CmdFormat format)
 
637
void script_watch(const char *cmd, uint8 *data, int len, enum CmdFormat format)
636
638
{
637
639
   int i;
638
640
   int w;
700
702
                           be+=sprintf(buf+be," resists %d %d\n",c,GetShort_String(data));
701
703
                           data+=2; len-=2;
702
704
                        } else if (c >= CS_STAT_SKILLINFO && c < (CS_STAT_SKILLINFO+CS_NUM_SKILLS)) {
703
 
                           be+=sprintf(buf+be," skill %d %d %lld\n",c,*data,GetInt64_String(data+1));
 
705
                           be+=sprintf(buf+be," skill %d %d %" FMT64 "\n",c,*data,GetInt64_String(data+1));
704
706
                           data+=9; len-=9;
705
707
                        } else switch (c) {
706
708
                           case CS_STAT_HP:
746
748
                              be+=sprintf(buf+be," exp %d\n",GetInt_String(data));
747
749
                              data+=4; len-=4; break;
748
750
                           case CS_STAT_EXP64:
749
 
                              be+=sprintf(buf+be," exp %lld\n",GetInt64_String(data));
 
751
                              be+=sprintf(buf+be," exp %" FMT64 "\n",GetInt64_String(data));
750
752
                              data+=8; len-=8; break;
751
753
                           case CS_STAT_LEVEL:
752
754
                              be+=sprintf(buf+be," level %d\n",GetShort_String(data));
902
904
   /* Send the message */
903
905
   write(scripts[i].out_fd,"scripttell ",11);
904
906
   write(scripts[i].out_fd,params,strlen(params));
905
 
   write(scripts[i].out_fd,"\n",1);
 
907
   write(scripts[i].out_fd,"\n",1);
906
908
}
907
909
 
908
910
static int script_by_name(const char *name)
947
949
   CloseHandle(scripts[i].process);
948
950
#endif
949
951
   free(scripts[i].name);
950
 
   if ( scripts[i].params ) free(scripts[i].params);
 
952
   free(scripts[i].params);
951
953
   for(w=0;w<scripts[i].num_watch;++w) free(scripts[i].watch[w]);
952
 
   if ( scripts[i].watch ) free(scripts[i].watch);
 
954
   free(scripts[i].watch);
953
955
 
954
956
#ifndef WIN32
955
957
   waitpid(-1,NULL,WNOHANG);
1148
1150
            char buf[1024];
1149
1151
            int s;
1150
1152
 
1151
 
            sprintf(buf,"request stat xp %d %lld",cpl.stats.level,cpl.stats.exp);
 
1153
            sprintf(buf,"request stat xp %d %" FMT64 ,cpl.stats.level,cpl.stats.exp);
1152
1154
            write(scripts[i].out_fd,buf,strlen(buf));
1153
1155
            for(s=0;s<MAX_SKILL;++s) {
1154
 
               sprintf(buf," %d %lld",cpl.stats.skill_level[s],cpl.stats.skill_exp[s]);
 
1156
               sprintf(buf," %d %" FMT64 ,cpl.stats.skill_level[s],cpl.stats.skill_exp[s]);
1155
1157
               write(scripts[i].out_fd,buf,strlen(buf));
1156
1158
            }
1157
1159
            write(scripts[i].out_fd,"\n",1);
1327
1329
         if ( strncmp(c,"mark",4)==0 ) {
1328
1330
            int tag;
1329
1331
            SockList sl;
1330
 
            char buf[MAX_BUF];
 
1332
            uint8 buf[MAX_BUF];
1331
1333
 
1332
1334
            c+=4;
1333
1335
 
1343
1345
         else if ( strncmp(c,"lock",4)==0 ) {
1344
1346
            int tag,locked;
1345
1347
            SockList sl;
1346
 
            char buf[MAX_BUF];
 
1348
            uint8 buf[MAX_BUF];
1347
1349
 
1348
1350
            c+=4;
1349
1351
 
1374
1376
      while ( (*param!='\0') && (*param!=' ')) param++;
1375
1377
      if (*param==' '){
1376
1378
         *param='\0';
1377
 
         *param++;
 
1379
         param++;
1378
1380
      } else
1379
1381
         param=NULL;
 
1382
 
1380
1383
      if (!handle_local_command(c, param)){
1381
1384
         char buf[1024];
1382
1385
         sprintf(buf,"Script %s malfunction; localcmd not understood",scripts[i].name);