One of my scripts is a large c++ if/else if/else tree that reads text to decide what do to. One of the hazard of being event driven is that if I get a update, take a action based on that update, and get another update before that action is complete I end up looping the same action for the same event a few times. I get around this by using a hold down that only resets when a text message related to the issued commands is received, but that's isn't the ideal way.
Of course, that only tells me 'a' related command was completed. I do not know if it was the one I was looking for or if I had a few things going, which one it was talking about.
I know the client and the server exchange 'ncom'(new command) and 'comc' (completed command) message with each other. The problem is this information, as far as I know, is not directly communicated to a script.
So my questions are:
1. How does the script command 'sync' work?
2. Is there away to the a client to report the 'ncom' number, packet, it sent to the server that to a script without recompile the client?
I look at the function that reports ports to any script the commands send, 'common/player.c' send_command(), and it know the number and is directly responsible for telling a script a command has been sent; However, it doesn't report the ncom number to the script.
3. Can this be fixxed?
I'd rewrite the functions 'send_command()' & 'script_monitor()'(common/scripts.c) my self, but I don't know the code well enough yet to say if I'd brake anything or not doing it.
That being said, here are my personal updates to them, anyone see anything wrong?
Code: Select all
int send_command(const char *command, int repeat, int must_send) {
static char last_command[MAX_BUF]="";
/**/ //Moved script_monitor() from here.
if (cpl.input_state==Reply_One) {
LOG(LOG_ERROR,"common::send_command","Wont send command '%s' - since in reply mode!",
command);
cpl.count=0;
return 0;
}
/* Does the server understand 'ncom'? If so, special code */
if (csocket.cs_version >= 1021) {
int commdiff=csocket.command_sent - csocket.command_received;
if (commdiff<0) commdiff +=256;
/* if too many unanswered commands, not a must send, and command is
* the same, drop it
*/
if (commdiff>use_config[CONFIG_CWINDOW] && !must_send && !strcmp(command, last_command)) {
if (repeat!=-1) cpl.count=0;
return 0;
#if 0 /* Obnoxious warning message we don't need */
fprintf(stderr,"Wont send command %s - window oversized %d %d\n",
command, csocket.command_sent, csocket.command_received);
#endif
}
else {
SockList sl;
uint8 buf[MAX_BUF];
/* Don't want to copy in administrative commands */
if (!must_send) strcpy(last_command, command);
csocket.command_sent++;
csocket.command_sent &= 0xff; /* max out at 255 */
/**/script_monitor(command,repeat,must_send,csocket.command_send);
SockList_Init(&sl, buf);
SockList_AddString(&sl, "ncom ");
SockList_AddShort(&sl, csocket.command_sent);
SockList_AddInt(&sl, repeat);
SockList_AddString(&sl, command);
SockList_Send(&sl, csocket.fd);
}
} else {
/**/script_monitor(command,repeat,must_send,-1);
cs_print_string(csocket.fd, "command %d %s", repeat,command);
}
if (repeat!=-1) cpl.count=0;
return 1;
}
Code: Select all
void script_monitor(const char *command, int repeat, int must_send,int ncom_packet)
{
int i;
/* For each script... */
for (i=0;i<num_scripts;++i)
{
/* Do we send the command? */
if ( scripts[i].monitor )
{
char buf[1024];
/**/sprintf(buf,"monitor %d %d %d %s\n",repeat ,must_send, ncom_packet), command);
write(scripts[i].out_fd,buf,strlen(buf));
}
}
}